2 #include "VISU_Extractor.hxx"
4 #include <vtkObjectFactory.h>
5 #include <vtkScalars.h>
6 #include <vtkVectors.h>
7 #include <vtkUnstructuredGridReader.h>
10 static int MYDEBUG = 1;
12 static int MYDEBUG = 0;
15 VISU_Extractor::VISU_Extractor(){
19 VISU_Extractor::~VISU_Extractor() {}
20 VISU_Extractor* VISU_Extractor::New(){
21 vtkObject* ret = vtkObjectFactory::CreateInstance("VISU_Extractor");
22 if(ret) return (VISU_Extractor*)ret;
23 return new VISU_Extractor;
25 void VISU_Extractor::Extract(vtkUnstructuredGridReader* theReader,
26 const string& theFieldName, int theScalarMode,
27 int theNbComp, const VISU::TEntity& theEntity)
29 myScalarMode = theScalarMode;
33 theReader->SetScalarsName(theFieldName.c_str());
35 theReader->SetVectorsName(theFieldName.c_str());
36 SetInput(theReader->GetOutput());
39 template<typename TypeData> void
40 execute(int theNbComp, int theScalarMode, TypeData* theInputData, TypeData* theOutputData){
41 vtkVectors *inVectors = theInputData->GetVectors();
42 if ( !inVectors || theNbComp < 1 )
44 vtkScalars *newScalars = vtkScalars::New();
45 newScalars->SetNumberOfScalars(theNbComp);
46 for (int ptId = 0; ptId < theNbComp; ptId++) {
48 inVectors->GetVector(ptId,v);
49 if ( theScalarMode < 1 || theScalarMode > 3)
50 s = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
52 s = v[theScalarMode - 1];
53 newScalars->SetScalar(ptId, s);
55 theOutputData->SetScalars(newScalars);
58 void VISU_Extractor::Execute(){
59 vtkDataSet *input = this->GetInput(), *output = this->GetOutput();
60 output->CopyStructure(input);
61 output->GetPointData()->CopyAllOff();
62 output->GetCellData()->CopyAllOff();
63 if(myEntity == VISU::NODE_ENTITY){
64 output->GetPointData()->CopyVectorsOn();
65 int nbComp = input->GetNumberOfPoints();
66 vtkPointData *inData = input->GetPointData(), *outData = output->GetPointData();
68 execute(nbComp,myScalarMode,inData,outData);
70 output->GetPointData()->CopyScalarsOn();
71 outData->PassData(inData);
73 output->GetCellData()->CopyVectorsOn();
74 int nbComp = input->GetNumberOfCells();
75 vtkCellData *inData = input->GetCellData(), *outData = output->GetCellData();
77 execute(nbComp,myScalarMode,inData,outData);
79 output->GetCellData()->CopyScalarsOn();
80 outData->PassData(inData);