2 // #include "MEDCouplingFieldDouble.hxx"
3 #include "MEDFileField.hxx"
4 #include "MEDCouplingUMesh.hxx"
5 #include "MEDCouplingCMesh.hxx"
6 #include "MEDCouplingCurveLinearMesh.hxx"
7 #include "MEDFileMesh.hxx"
8 #include "MEDFileFieldRepresentationTree.hxx"
12 #include <vtkCPDataDescription.h>
13 #include <vtkCPInputDataDescription.h>
14 #include <vtkCPPythonScriptPipeline.h>
15 #include <vtkCPProcessor.h>
16 #include "vtkDataSet.h"
19 using namespace MEDCoupling;
22 void Visualization::CatalystInitialize(const std::string& script)
26 Processor = vtkCPProcessor::New();
27 Processor->Initialize();
31 Processor->RemoveAllPipelines();
33 // Add in the Python script
34 vtkCPPythonScriptPipeline* pipeline = vtkCPPythonScriptPipeline::New();
35 char *c = const_cast<char*>(script.c_str());
36 pipeline->Initialize(c);
37 Processor->AddPipeline(pipeline);
42 void Visualization::CatalystFinalize()
49 /* uuuuuuuh ... maybe cleaning vtkDataSet
59 void Visualization::CatalystCoProcess(vtkDataSet *VTKGrid, double time,
60 unsigned int timeStep)
62 vtkCPDataDescription* dataDescription = vtkCPDataDescription::New();
63 // specify the simulation time and time step for Catalyst
64 dataDescription->AddInput("input");
65 dataDescription->SetTimeData(time, timeStep);
67 if(Processor->RequestDataDescription(dataDescription) != 0)
69 // Make a map from input to our VTK grid so that
70 // Catalyst gets the proper input dataset for the pipeline.
71 dataDescription->GetInputDescriptionByName("input")->SetGrid(VTKGrid);
72 // Call Catalyst to execute the desired pipelines.
73 Processor->CoProcess(dataDescription);
75 dataDescription->Delete();
78 void Visualization::ConvertToVTK(MEDCoupling::MEDCouplingFieldDouble* field, vtkDataSet *VTKGrid)
81 MEDCoupling::MEDCouplingFieldDouble *f = field;
82 MEDCoupling::MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New());
83 ff->setFieldNoProfileSBT(f);
84 MCAuto<MEDFileFieldMultiTS> fmts(MEDFileFieldMultiTS::New());
85 fmts->pushBackTimeStep(ff);
86 MCAuto<MEDFileFields> fs(MEDFileFields::New());
89 MEDCouplingMesh *m(f->getMesh());
90 MCAuto<MEDFileMesh> mm;
91 if(dynamic_cast<MEDCouplingUMesh *>(m))
93 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
94 mmu->setMeshAtLevel(0,dynamic_cast<MEDCouplingUMesh *>(m));
95 mm=DynamicCast<MEDFileUMesh,MEDFileMesh>(mmu);
97 else if(dynamic_cast<MEDCouplingCMesh *>(m))
99 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
100 mmc->setMesh(dynamic_cast<MEDCouplingCMesh *>(m));
101 mm=DynamicCast<MEDFileCMesh,MEDFileMesh>(mmc);
103 else if(dynamic_cast<MEDCouplingCurveLinearMesh *>(m))
105 // MCAuto<MEDFileCLMesh> mmc(MEDFileCLMesh::New());
106 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
107 mmc->setMesh(dynamic_cast<MEDCouplingCurveLinearMesh *>(m));
108 //mm=DynamicCast<MEDCouplingCurveLinearMesh,MEDFileMesh>(mmc);
112 MCAuto<MEDFileMeshes> ms(MEDFileMeshes::New());
114 MEDFileFieldRepresentationTree Tree;
115 Tree.loadInMemory(fs,ms);
116 std::string meshName;
119 double tmp3(f->getTime(tmp1,tmp2));
120 vtkDataSet *ret(Tree.buildVTKInstance(true,tmp3,meshName,TK));
124 Visualization::Visualization()
130 // ajouter en parametre le fichier python qui contient le pipeline
131 // enlever le const s'il gene
132 void Visualization::run(MEDCoupling::MEDCouplingFieldDouble* field, const std::string& pathPipeline)
135 MPI_Comm_rank(MPI_COMM_WORLD,&proc_id);
138 std::cerr << "Description n° " << proc_id << ": NULL pointer" << std::endl;
140 std::cerr << "Description n° " << proc_id << ":"
141 << field->getDescription() << std::endl;
144 CatalystInitialize(pathPipeline);
146 vtkDataSet *VTKGrid = 0;
147 ConvertToVTK(field, VTKGrid);
149 // Time information for CatalystCoProcess
152 double time = field->getTime(iteration, order);
154 CatalystCoProcess(VTKGrid, time, iteration);