2 #include "MEDFileField.hxx"
3 #include "MEDCouplingUMesh.hxx"
4 #include "MEDCouplingCMesh.hxx"
5 #include "MEDCouplingCurveLinearMesh.hxx"
6 #include "MEDFileMesh.hxx"
7 #include "MEDFileFieldRepresentationTree.hxx"
11 #include <vtkCPDataDescription.h>
12 #include <vtkCPInputDataDescription.h>
13 #include <vtkCPPythonScriptPipeline.h>
14 #include <vtkCPProcessor.h>
15 #include "vtkDataSet.h"
16 #include "vtkCellData.h"
18 #include <vtkSmartPointer.h>
19 #include <vtkXMLUnstructuredGridWriter.h>
20 #include <vtkUnstructuredGrid.h>
22 using namespace MEDCoupling;
25 void Visualization::CatalystInitialize(const std::string& script)
30 Processor = vtkCPProcessor::New();
31 Processor->Initialize();
35 Processor->RemoveAllPipelines();
37 // Add in the Python script
38 vtkCPPythonScriptPipeline* pipeline = vtkCPPythonScriptPipeline::New();
39 char *c = const_cast<char*>(script.c_str());
40 pipeline->Initialize(c);
41 Processor->AddPipeline(pipeline);
46 void Visualization::CatalystFinalize()
57 void Visualization::CatalystCoProcess(vtkDataSet *VTKGrid, double time,
58 unsigned int timeStep)
60 vtkCPDataDescription* dataDescription = vtkCPDataDescription::New();
61 // specify the simulation time and time step for Catalyst
62 dataDescription->AddInput("input");
63 dataDescription->SetTimeData(time, timeStep);
65 if(Processor->RequestDataDescription(dataDescription) != 0)
67 // Make a map from input to our VTK grid so that
68 // Catalyst gets the proper input dataset for the pipeline.
69 dataDescription->GetInputDescriptionByName("input")->SetGrid(VTKGrid);
70 // Call Catalyst to execute the desired pipelines.
71 Processor->CoProcess(dataDescription);
73 dataDescription->Delete();
76 void Visualization::ConvertToVTK(MEDCoupling::MEDCouplingFieldDouble* field, vtkDataSet *&VTKGrid)
77 //vtkDataSet * Visualization::ConvertToVTK(MEDCoupling::MEDCouplingFieldDouble* field)
79 MEDCoupling::MEDCouplingFieldDouble *f = field;
80 MEDCoupling::MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New());
81 ff->setFieldNoProfileSBT(f);
82 MCAuto<MEDFileFieldMultiTS> fmts(MEDFileFieldMultiTS::New());
83 fmts->pushBackTimeStep(ff);
84 MCAuto<MEDFileFields> fs(MEDFileFields::New());
87 MEDCouplingMesh *m(f->getMesh());
88 MCAuto<MEDFileMesh> mm;
89 if(dynamic_cast<MEDCouplingUMesh *>(m))
91 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
92 mmu->setMeshAtLevel(0,dynamic_cast<MEDCouplingUMesh *>(m));
93 mmu->forceComputationOfParts();
94 mm=DynamicCast<MEDFileUMesh,MEDFileMesh>(mmu);
96 else if(dynamic_cast<MEDCouplingCMesh *>(m))
98 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
99 mmc->setMesh(dynamic_cast<MEDCouplingCMesh *>(m));
100 mm=DynamicCast<MEDFileCMesh,MEDFileMesh>(mmc);
102 else if(dynamic_cast<MEDCouplingCurveLinearMesh *>(m))
104 // MCAuto<MEDFileCLMesh> mmc(MEDFileCLMesh::New());
105 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
106 mmc->setMesh(dynamic_cast<MEDCouplingCurveLinearMesh *>(m));
107 //mm=DynamicCast<MEDCouplingCurveLinearMesh,MEDFileMesh>(mmc);
114 MCAuto<MEDFileMeshes> ms(MEDFileMeshes::New());
116 ms->getMeshesNames();
119 MPI_Comm_rank(MPI_COMM_WORLD,&proc_id);
121 MEDFileFieldRepresentationTree Tree;
122 Tree.loadInMemory(fs,ms);
124 Tree.changeStatusOfAndUpdateToHaveCoherentVTKDataSet(0,true);
125 Tree.changeStatusOfAndUpdateToHaveCoherentVTKDataSet(1,false);
126 Tree.activateTheFirst();//"TS0/Fluid domain/ComSup0/TempC@@][@@P0"
127 std::string meshName;
130 double tmp3(f->getTime(tmp1,tmp2));
131 vtkDataSet *ret(Tree.buildVTKInstance(false,tmp3,meshName,TK));
135 Visualization::Visualization()
141 // ajouter en parametre le fichier python qui contient le pipeline
142 // enlever le const s'il gene
143 void Visualization::run(MEDCoupling::MEDCouplingFieldDouble* field, const std::string& pathPipeline)
146 MPI_Comm_rank(MPI_COMM_WORLD,&proc_id);
148 vtkDataSet *VTKGrid = 0;
149 ConvertToVTK(field, VTKGrid);
151 const char *fileName = pathPipeline.c_str();
152 CatalystInitialize(fileName);
153 CatalystCoProcess(VTKGrid, 0.0, 0);