POV-Ray and Post Processing

154 views
Skip to first unread message

Jacob Brendle

unread,
Sep 17, 2016, 11:00:59 AM9/17/16
to ProjectChrono
Hello,

I have created a program that is a type of combination of the demo_VEH_WheeledJSON, and the demo_VEH_Steering controller. I would like to use POV-Ray to get a post processed rendering of the simulation. I followed the example of demo_postprocess in order to get my program to output .pov files and a .ini file.

The problem that I'm having is that I cannot include the loop that follows:

while (mphysicalSystem.GetChTime() < 1.5) {
mphysicalSystem.DoStepDynamics(0.01);
GetLog() << "time= " << mphysicalSystem.GetChTime() << "\n";

pov_exporter.ExportData();
}

When that loops is included, the program stops for 1.5 seconds, and then the vehicle implodes, as all the parts are trying to catch up to where they are supposed to be after that amount of time. If I take out that loop, the program constantly only writes to the files my_state0000.pov and my_state0000.dat, and it overwrites them over and over.

I am wondering if anyone has any recommendations as to how to fix this problem?

Thanks,
Jacob Brendle

PS: I have included a copy of my c++ code.
my_project.cpp

MICHAEL TAYLOR

unread,
Sep 17, 2016, 10:23:47 PM9/17/16
to ProjectChrono
Jacob,

As a starting point, did you try running demo_VEH_SteeringController as is with "bool povray_output = true;" on line 106?  This should produce a single state output file for the simulation and 1 povray output file for each time step.  I'm guessing that this is what you are looking for.

Based on what I see, it appears that your code is trying to step the dynamics of the system 1.5s extra during each normal step in time that the simulation would have otherwise taken.  The XXX.Advance functions handle the time advance for each cosimulated system in Chrono::vehicle at the end of the simulation loop (e.g. lines 406-412 in demo_VEH_SteeringController.cpp).

Let me know if this does not help.

Mike

Radu Serban

unread,
Sep 18, 2016, 4:35:40 AM9/18/16
to projec...@googlegroups.com

Hi Jacob,

To follow up on this: indeed, for Chrono::Vehicle I opted to implement an alternative way for POV-Ray rendering.  Unlike the approach in Chrono::Postprocess, where a POV-Ray script is generated for each desired frame, with the approach adopted in Chrono::Vehicle, you generate one data file for each desired frame.  These data files can then be processed (one at a time or in batch) by a single, common POV-Ray script.  This approach is more flexible and more scalable.

Note that we plan on eventually redesigning the POV-Ray support in Chrono::Postprocess.

Coming back to Chrono::Vehicle,  rendering with POV-Ray is a topic that is currently not properly documented anywhere, so let me try to fill in some of this gap here.

What you need to do is simply invoke the utility function WriteShapesPovray(), once for each desired render frame, passing it a file name that encodes the frame number.  Because the way the POV-Ray script is written (see below), I suggest you generate these file names such that the resulting data files are all placed in a sub-directory POVRAY of the output folder (just like it's done in our demos).   Running the simulation will then generate one data file per render frame.  These are ASCII output files that are actually independent of POV-Ray (they simply contain system body states, joint information, and information of the visual assets at the particular simulation time for which they were generated).

With Chrono::Vehicle, in the directory src/demos/vehicle, we distribute a POV-Ray script (renderZ.pov) that can be used (maybe with some minor modifications) to render the scene using one of the above data files, or else a sequence of such data files.   To use it, copy it from the Chrono source directory to the output directory, at the same level as the POVRAY directory that contains the output data files.  Then make any required modifications to the script.  With one exception, most of these are at the top of the script (under the section "OPTIONS").  You can experiment with them, but the more important ones are:

  • fnum -- the frame number that you want rendered.
    You can either specify a single value, or else assume it is passed as an argument to the script (possibly as a range) and therefore available in the variable 'frame_number'.  The latter allows you to do batch rendering.
  • datafile -- modify this to reflect where the data files were generated and what pattern you used for their filename.
    As provided, the script assumes the data files are available in the directory POVRAY and that their name are of the form data_***.dat, where *** represents the frame number.   This is consistent with how these data files are generated in our demos.
  • camera settings -- 'cam_perspective' false uses orthographic projection (default is perspective); 'cam_loc' is the (fixed) camera location; 'cam_lookat' is the (fixed) point that gives the camera direction.
    NOTE: if you want the camera settings to change at each frame, based on the corresponding vehicle position (e.g. to have a camera following the vehicle, or pointing at the vehicle as it moves), you will have to overwrite the above settings further down in the script (look for the "CAMERA" section around line 588).  Modify the sample commented code snippets there.
Note that POV-Ray uses a left-handed frames with (default) Y up.  On the other hand, Chrono uses right-handed frames and, moreover, all Chrono::Vehicle models impose Z up (i.e. gravity in the -Z direction).  The renderZ.pov script has code to perform all required conversions.  As such, when you specify camera settings, use a right-handed frame with Z up (i.e., work in the same reference frame as the one in which the vehicle itself was defined for Chrono::Vehicle).

Using meshes (provided through Wavefront OBJ files) as visualization assets adds a bit more complication.  If you want to use some of the meshes we already provide with Chrono, in addition to the above steps, you also need to copy the proper POV-Ray snippets (*.inc files) for the appropriate vehicle model (in the Chrono::Vehicle data directory) and place them next to the renderZ.pov script in the output directory.   For the HMMWV vehicle as an example, grab all the files in data/vehicle/hmmwv/POV-Ray.   Assuming MESH visualization was enabled in your program, the renderZ.pov script will look for the specific *.inc files and render the meshes.
However, if you want to use your own meshes, the process is quite a bit more complicated as you'd need to generate these POV-Ray *.inc files separately...

I realize this work flow is not that streamlined and requires a bit of tweaking and user intervention.  As I mentioned, when we get a chance we will work on improving this through Chrono::Postprocess.


Finally, as Mike mentioned, the time stepping of a vehicle system is performed through the wrapper Advance() functions, so there's no need (indeed, it's an error) to also explicitly call DoStepDynamics() on the underlying ChSystem of a vehicle object.   That is done in ChVehicle::Advance().


I hope this helps and that you manage to generate the renderings you want.  Do not hesitate to ask for further clarifications. 

Regards,
--Radu

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To post to this group, send email to projec...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jacob Brendle

unread,
Sep 23, 2016, 1:12:49 PM9/23/16
to ProjectChrono
renderZ.pov worked for me, however to render all of the .dat files, I needed to write a renderZ.ini file.

Thanks for the help,
Jake
Reply all
Reply to author
Forward
0 new messages