]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISU_Extractor.cxx
Salome HOME
MPV: Merge V1_2d
[modules/visu.git] / src / PIPELINE / VISU_Extractor.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //  File   : VISU_Extractor.cxx
24 //  Module : VISU
25
26 #include "VISU_Extractor.hxx"   
27 #include "VISU_PipeLineUtils.hxx"
28
29 #include <sstream>      
30
31 #include <vtkObjectFactory.h>
32 #include <vtkUnstructuredGrid.h>
33 #include <vtkFloatArray.h>
34 #include <vtkPointData.h>
35 #include <vtkCellData.h>
36
37 using namespace std;
38
39 #ifdef _DEBUG_
40 static int MYDEBUG = 0;
41 #else
42 static int MYDEBUG = 0;
43 #endif
44
45
46 vtkStandardNewMacro(VISU_Extractor);
47
48 VISU_Extractor::VISU_Extractor(){
49   myScalarMode = 0;
50 }
51
52 VISU_Extractor::~VISU_Extractor(){
53 }
54
55 void VISU_Extractor::SetScalarMode(int theScalarMode){
56   if(myScalarMode != theScalarMode){
57     myScalarMode = theScalarMode;
58     Modified();
59   }
60 }
61
62
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 ) 
67     return; 
68   vtkFloatArray *newScalars = vtkFloatArray::New();
69   ostringstream aName;
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++) {
75     float v[3], s;
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]);
79     else
80       s = v[theScalarMode - 1];
81     newScalars->SetTuple1(ptId, s);
82   }
83   theOutputData->SetScalars(newScalars);
84   //theOutputData->SetActiveScalars(newScalars->GetName());
85   newScalars->Delete();
86 }
87
88
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);
100     else
101       output->GetPointData()->CopyScalarsOn();
102     outData->PassData(inData);
103   }else{
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);
109     else
110       output->GetCellData()->CopyScalarsOn();
111     outData->PassData(inData);
112   }
113 }