1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : VISU_Extractor.cxx
26 #include "VISU_Extractor.hxx"
27 #include "VISU_PipeLineUtils.hxx"
31 #include <vtkObjectFactory.h>
32 #include <vtkUnstructuredGrid.h>
33 #include <vtkFloatArray.h>
34 #include <vtkPointData.h>
35 #include <vtkCellData.h>
41 vtkStandardNewMacro(VISU_Extractor);
43 VISU_Extractor::VISU_Extractor()
48 VISU_Extractor::~VISU_Extractor()
51 void VISU_Extractor::SetScalarMode(int theScalarMode)
53 if(myScalarMode != theScalarMode){
54 myScalarMode = theScalarMode;
59 template<typename TypeData> void
60 execute(int theNbElems,
62 TypeData* theInputData,
63 TypeData* theOutputData)
67 vtkDataArray* aFieldArray = theInputData->GetArray("VISU_FIELD");
68 if(vtkFloatArray *aFloatArray = dynamic_cast<vtkFloatArray*>(aFieldArray)){
69 int aNbComp = aFloatArray->GetNumberOfComponents();
70 std::vector<vtkFloatingPointType> anArray(aNbComp < 3? 3: aNbComp);
72 vtkFloatArray *aScalars = vtkFloatArray::New();
73 aScalars->SetNumberOfTuples(theNbElems);
74 aScalars->SetNumberOfComponents(1);
77 for(int anId = 0; anId < theNbElems; anId++){
78 aFloatArray->GetTuple(anId,&anArray[0]);
79 vtkFloatingPointType aVector[3] = {anArray[0], anArray[1], anArray[2]};
80 vtkFloatingPointType aScalar = sqrt(aVector[0]*aVector[0] + aVector[1]*aVector[1] + aVector[2]*aVector[2]);
81 aScalars->SetTuple1(anId,aScalar);
84 for(int anId = 0; anId < theNbElems; anId++){
85 aFloatArray->GetTuple(anId,&anArray[0]);
86 aScalars->SetTuple1(anId,anArray[theScalarMode - 1]);
89 theOutputData->SetScalars(aScalars);
94 void VISU_Extractor::Execute(){
95 vtkDataSet *input = this->GetInput(), *output = this->GetOutput();
96 output->CopyStructure(input);
97 output->GetPointData()->CopyAllOff();
98 output->GetCellData()->CopyAllOff();
99 if(input->GetPointData()->GetNumberOfArrays()){
100 output->GetPointData()->CopyVectorsOn();
101 int aNbElems = input->GetNumberOfPoints();
102 vtkPointData *inData = input->GetPointData(), *outData = output->GetPointData();
103 if(inData->GetAttribute(vtkDataSetAttributes::VECTORS))
104 execute(aNbElems,myScalarMode,inData,outData);
106 output->GetPointData()->CopyScalarsOn();
107 outData->PassData(inData);
108 outData->AddArray(inData->GetArray("VISU_FIELD"));
110 output->GetCellData()->CopyVectorsOn();
111 int aNbElems = input->GetNumberOfCells();
112 vtkCellData *inData = input->GetCellData(), *outData = output->GetCellData();
113 if(inData->GetAttribute(vtkDataSetAttributes::VECTORS))
114 execute(aNbElems,myScalarMode,inData,outData);
116 output->GetCellData()->CopyScalarsOn();
117 outData->PassData(inData);
118 outData->AddArray(inData->GetArray("VISU_FIELD"));