Commit 9cf59f6a authored by Nicolas Van der Noot's avatar Nicolas Van der Noot

mbsyscopy updated

parent 4cca9263
......@@ -55,4 +55,17 @@ cdef class CyMbsVtkOutputter:
self.thisptr.SetFrameStep(fs)
def PrintFiles(self, animfile):
self.thisptr.PrintFiles(animfile)
\ No newline at end of file
self.thisptr.PrintFiles(animfile)
def InitPvd(self):
self.thisptr.InitPvd()
def WriteDisplayFiles(self, double tsim, np.ndarray[double, ndim=1] q, fs, step):
# If it's time to print
if not step%fs:
self.thisptr.WriteDisplayFiles(tsim, &q[1])
def FinalizePvd(self):
self.thisptr.FinalizePvd()
......@@ -44,7 +44,7 @@ MbsVtkOutputter::MbsVtkOutputter(std::string mbs_file){
}
/*! \brief destructor
*/filename
*/
MbsVtkOutputter::~MbsVtkOutputter(){
delete[] joint_vec;
delete world_3d;
......@@ -71,7 +71,7 @@ void MbsVtkOutputter::SetOutputFilename(std::string name){
output_name = name;
}
void MbsVtkOutputter::SetFrameStep(int fs){filename
void MbsVtkOutputter::SetFrameStep(int fs){
frame_step = fs;
}
......@@ -89,56 +89,44 @@ void MbsVtkOutputter::PrintFiles(std::string anim_filename){
// get the number of joint
int nb_joints = world_3d->GetNbJoints(MBS_ID);
//re-init file counter
outfileCounter=1;
// open the ParaView’s native data file format (PVD)
std::ostringstream pvdname;
pvdname << output_dir << "/" << output_name << ".pvd";
ofstream fpvd(pvdname.str().c_str(), ios::trunc);
// initialize the pvd file
fpvd << "<?xml version=\"1.0\"?>" << endl;
fpvd << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\">"<< endl;
fpvd << "<Collection>"<< endl;
InitPvd(fpvd);
// loop
for(int i=0; i<anim_reader->getNbStep(); i+=frame_step)
{
// increment file counter
outfileCounter++;
// fill Q values by reading the anim
anim_reader->FillQIndex(i, nb_joints, joint_vec);
// update joints
world_3d->UpdateJoints(MBS_ID, nb_joints, joint_vec);
// set the filename
std::ostringstream filename;
filename << "./" << output_name << outfileCounter << ".vtu";
// set the filepath
std::ostringstream filepath;
filepath << output_dir << "/" << output_name << outfileCounter << ".vtu";
world_renderer->SetOutputPath(filepath.str());
WriteDisplayFiles(anim_reader->getTime(i), joint_vec, fpvd);
// write the vtp file
world_3d->Update();
// update the pvd file
fpvd<< "<DataSet timestep=\""<<anim_reader->getTime(i)<<"\" group=\"\" part=\"0\" file=\""<< filename.str() <<"\"/>" << endl;
}
// finalyze the pvd file
fpvd<< "</Collection>"<< endl;
fpvd<< "</VTKFile>";
fpvd.close();
FinalizePvd(fpvd);
// Freeing
delete anim_reader;
}
void MbsVtkOutputter::InitPvd(ofstream& fpvd ){
// initialize the file
fpvd << "<?xml version=\"1.0\"?>" << endl;
fpvd << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\">"<< endl;
fpvd << "<Collection>"<< endl;
//re-init file counter
outfileCounter=1;
}
/*! \brief Write the header of the *.pvd file.
*
*/
......@@ -148,26 +136,22 @@ void MbsVtkOutputter::InitPvd(){
pvdname << output_dir << "/" << output_name << ".pvd";
ofstream fpvd(pvdname.str().c_str(), ios::trunc);
// initialize the file
fpvd << "<?xml version=\"1.0\"?>" << endl;
fpvd << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\">"<< endl;
fpvd << "<Collection>"<< endl;
InitPvd(fpvd);
// Close the file
fpvd.close();
//re-init file counter
outfileCounter=1;
}
/*! \brief Write the current configuration.
/*! \brief Write the current configuration and update the pvd information to
* the given file stream.
*
* \param[in] tsim the simulation time
*
* \param[in] q a pointer to the current joint configuration, index start at 1.
* \param[in] q a pointer to the current joint configuration, index start at 0.
*
*/
void MbsVtkOutputter::WriteDisplayFiles(double tsim,double *q){
void MbsVtkOutputter::WriteDisplayFiles(double tsim,double *q, ofstream& fpvd){
// set the filename
std::ostringstream filename;
filename << "./" << output_name << outfileCounter << ".vtu";
......@@ -177,17 +161,13 @@ void MbsVtkOutputter::WriteDisplayFiles(double tsim,double *q){
world_renderer->SetOutputPath(filepath.str());
// Update the pvd file
std::ostringstream pvdname;
pvdname << output_dir << "/" << output_name << ".pvd";
ofstream fpvd(pvdname.str().c_str(), ios::app);
fpvd<< "<DataSet timestep=\""<< tsim <<"\" group=\"\" part=\"0\" file=\""<< filename.str() <<"\"/>" << endl;
fpvd.close();
// get the number of joint
int nb_joints = world_3d->GetNbJoints(MBS_ID);
// update joints
world_3d->UpdateJoints(MBS_ID, nb_joints, &q[1]);
world_3d->UpdateJoints(MBS_ID, nb_joints, q);
// write the vtp file
world_3d->Update();
......@@ -196,6 +176,38 @@ void MbsVtkOutputter::WriteDisplayFiles(double tsim,double *q){
outfileCounter++;
}
/*! \brief Write the current configuration.
*
* \param[in] tsim the simulation time
*
* \param[in] q a pointer to the current joint configuration, index start at 0.
*
*/
void MbsVtkOutputter::WriteDisplayFiles(double tsim,double *q){
// Open the pvd file
std::ostringstream pvdname;
pvdname << output_dir << "/" << output_name << ".pvd";
ofstream fpvd(pvdname.str().c_str(), ios::app);
WriteDisplayFiles(tsim,q, fpvd);
fpvd.close();
}
/*! \brief Write the closing tag to the pvd file for the given
* file stream
*
*/
void MbsVtkOutputter::FinalizePvd(ofstream& fpvd ){
// Finalize the file
fpvd<< "</Collection>"<< endl;
fpvd<< "</VTKFile>";
}
/*! \brief Closing operation on the contents of the *.pvd file.
*
*/
......@@ -206,8 +218,8 @@ void MbsVtkOutputter::FinalizePvd(){
ofstream fpvd(pvdname.str().c_str(), ios::app);
// Finalize the file
fpvd<< "</Collection>"<< endl;
fpvd<< "</VTKFile>";
FinalizePvd(fpvd);
// Close the file
fpvd.close();
}
......@@ -41,11 +41,14 @@ class MbsVtkOutputter{
void PrintFiles(std::string anim_filename);
void InitPvd();
void InitPvd(std::ofstream& fpvd);
void WriteDisplayFiles(double tsim, double *q);
void WriteDisplayFiles(double tsim, double *q, std::ofstream& fpvd);
void FinalizePvd();
void FinalizePvd(std::ofstream& fpvd );
private:
/// array to store the value of the joint value
......
......@@ -42,6 +42,8 @@ class VtkWorldRenderer : public MbsWorldRenderer
virtual void AddDepthTexture(int new_depth_x_width, int new_depth_y_width){}
virtual void AddViewPointRenderer(MbsViewPointRenderer* rdr){};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// specific to VTK output
vtkSmartPointer<vtkAppendFilter> appendFilter;
......
......@@ -442,10 +442,10 @@ void mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data)
mbs_dirdyn_save(dd, mbs_data, mbs_data->tsim);
// release memory
free(f_anim);
free(f);
free(respath);
free(animpath);
free(f_anim);
free(f);
free(respath);
free(animpath);
free(path_growing);
}
else{
......
......@@ -370,6 +370,15 @@ void MbsShape3D::Render(MbsViewPoint *viewpoint)
shRenderer->Update(model_mat, MVP, M_inv_trans, world_3d, shiny_mat, specular_mat, transparency);
}
/*! \brief update the shape visualization without updating the view
* (useful for Paraview/VTK rendering since it does not account
* for viewpoints)
*/
void MbsShape3D::Render()
{
shRenderer->Update(model_mat, MVP, M_inv_trans, world_3d, shiny_mat, specular_mat, transparency);
}
}
#endif
......@@ -61,7 +61,8 @@ class MbsShape3D
// call the shape renderer associated to this shape
void Render(MbsViewPoint *viewpoint);
void Render();
void ShadowDepth(int index){shRenderer->ShadowDepth(index);}
/// set the shiny material value
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment