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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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>
40 vtkStandardNewMacro(VISU_Extractor);
42 VISU_Extractor::VISU_Extractor(){
46 VISU_Extractor::~VISU_Extractor(){
49 void VISU_Extractor::SetScalarMode(int theScalarMode){
50 if(myScalarMode != theScalarMode){
51 myScalarMode = theScalarMode;
57 template<typename TypeData> void
58 execute(int theNbComp, int theScalarMode, TypeData* theInputData, TypeData* theOutputData){
59 vtkDataArray *inVectors = theInputData->GetVectors();
60 if ( !inVectors || theNbComp < 1 )
62 vtkFloatArray *newScalars = vtkFloatArray::New();
64 aName<<inVectors->GetName(); aName<<", "; aName<<theScalarMode;
65 newScalars->SetName(aName.str().c_str());
66 newScalars->SetNumberOfComponents(1);
67 newScalars->SetNumberOfTuples(theNbComp);
68 for (int ptId = 0; ptId < theNbComp; ptId++) {
70 inVectors->GetTuple(ptId,v);
71 if ( theScalarMode < 1 || theScalarMode > 3)
72 s = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
74 s = v[theScalarMode - 1];
75 newScalars->SetTuple1(ptId, s);
77 theOutputData->SetScalars(newScalars);
78 //theOutputData->SetActiveScalars(newScalars->GetName());
83 void VISU_Extractor::Execute(){
84 vtkDataSet *input = this->GetInput(), *output = this->GetOutput();
85 output->CopyStructure(input);
86 output->GetPointData()->CopyAllOff();
87 output->GetCellData()->CopyAllOff();
88 if(input->GetPointData()->GetNumberOfArrays()){
89 output->GetPointData()->CopyVectorsOn();
90 int nbComp = input->GetNumberOfPoints();
91 vtkPointData *inData = input->GetPointData(), *outData = output->GetPointData();
92 if(inData->GetAttribute(vtkDataSetAttributes::VECTORS))
93 execute(nbComp,myScalarMode,inData,outData);
95 output->GetPointData()->CopyScalarsOn();
96 outData->PassData(inData);
98 output->GetCellData()->CopyVectorsOn();
99 int nbComp = input->GetNumberOfCells();
100 vtkCellData *inData = input->GetCellData(), *outData = output->GetCellData();
101 if(inData->GetAttribute(vtkDataSetAttributes::VECTORS))
102 execute(nbComp,myScalarMode,inData,outData);
104 output->GetCellData()->CopyScalarsOn();
105 outData->PassData(inData);