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 static int MYDEBUG = 0;
42 static int MYDEBUG = 0;
46 vtkStandardNewMacro(VISU_Extractor);
48 VISU_Extractor::VISU_Extractor(){
52 VISU_Extractor::~VISU_Extractor(){
55 void VISU_Extractor::SetScalarMode(int theScalarMode){
56 if(myScalarMode != theScalarMode){
57 myScalarMode = theScalarMode;
63 template<typename TypeData> void
64 execute(int theNbComp, int theScalarMode, TypeData* theInputData, TypeData* theOutputData){
65 vtkDataArray *inVectors = theInputData->GetVectors();
66 if ( !inVectors || theNbComp < 1 )
68 vtkFloatArray *newScalars = vtkFloatArray::New();
70 aName<<inVectors->GetName(); aName<<", "; aName<<theScalarMode;
71 newScalars->SetName(aName.str().c_str());
72 newScalars->SetNumberOfComponents(1);
73 newScalars->SetNumberOfTuples(theNbComp);
74 for (int ptId = 0; ptId < theNbComp; ptId++) {
76 inVectors->GetTuple(ptId,v);
77 if ( theScalarMode < 1 || theScalarMode > 3)
78 s = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
80 s = v[theScalarMode - 1];
81 newScalars->SetTuple1(ptId, s);
83 theOutputData->SetScalars(newScalars);
84 //theOutputData->SetActiveScalars(newScalars->GetName());
89 void VISU_Extractor::Execute(){
90 vtkDataSet *input = this->GetInput(), *output = this->GetOutput();
91 output->CopyStructure(input);
92 output->GetPointData()->CopyAllOff();
93 output->GetCellData()->CopyAllOff();
94 if(input->GetPointData()->GetNumberOfArrays()){
95 output->GetPointData()->CopyVectorsOn();
96 int nbComp = input->GetNumberOfPoints();
97 vtkPointData *inData = input->GetPointData(), *outData = output->GetPointData();
98 if(inData->GetAttribute(vtkDataSetAttributes::VECTORS))
99 execute(nbComp,myScalarMode,inData,outData);
101 output->GetPointData()->CopyScalarsOn();
102 outData->PassData(inData);
104 output->GetCellData()->CopyVectorsOn();
105 int nbComp = input->GetNumberOfCells();
106 vtkCellData *inData = input->GetCellData(), *outData = output->GetCellData();
107 if(inData->GetAttribute(vtkDataSetAttributes::VECTORS))
108 execute(nbComp,myScalarMode,inData,outData);
110 output->GetCellData()->CopyScalarsOn();
111 outData->PassData(inData);