1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File : VISU_Extractor.cxx
26 #include "VISU_Extractor.hxx"
27 #include "VISU_PipeLineUtils.hxx"
28 #include "VISU_ConvertorUtils.hxx"
29 #include "VISU_MeshValue.hxx"
33 #include <vtkObjectFactory.h>
34 #include <vtkUnstructuredGrid.h>
35 #include <vtkPointData.h>
36 #include <vtkCellData.h>
38 #include <vtkInformation.h>
39 #include <vtkInformationVector.h>
43 //----------------------------------------------------------------------------
44 vtkStandardNewMacro(VISU_Extractor);
46 //----------------------------------------------------------------------------
50 myGaussMetric(VISU::AVERAGE_METRIC)
55 //----------------------------------------------------------------------------
61 //----------------------------------------------------------------------------
64 ::SetScalarMode(int theScalarMode)
66 if(myScalarMode != theScalarMode){
67 myScalarMode = theScalarMode;
72 //----------------------------------------------------------------------------
81 //----------------------------------------------------------------------------
84 ::SetGaussMetric(VISU::TGaussMetric theGaussMetric)
86 if(myGaussMetric != theGaussMetric){
87 myGaussMetric = theGaussMetric;
92 //----------------------------------------------------------------------------
101 //----------------------------------------------------------------------------
102 template<typename TValueType>
104 Module2Scalars(vtkDataArray *theInputDataArray,
105 TValueType* theOutputPtr,
106 vtkIdType theNbOfTuples)
108 vtkIdType aNbComp = theInputDataArray->GetNumberOfComponents();
109 std::vector<vtkFloatingPointType> anArray(aNbComp < 3? 3: aNbComp);
110 for(vtkIdType aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++){
111 theInputDataArray->GetTuple(aTupleId, &anArray[0]);
112 vtkFloatingPointType aVector[3] = {anArray[0], anArray[1], anArray[2]};
113 vtkFloatingPointType aScalar = sqrt(aVector[0]*aVector[0] +
114 aVector[1]*aVector[1] +
115 aVector[2]*aVector[2]);
116 *theOutputPtr = TValueType(aScalar);
122 //----------------------------------------------------------------------------
123 template<typename TValueType>
125 Component2Scalars(vtkDataArray *theInputDataArray,
126 TValueType* theInputPtr,
127 TValueType* theOutputPtr,
128 vtkIdType theNbOfTuples,
129 vtkIdType theComponentId)
131 vtkIdType aNbComp = theInputDataArray->GetNumberOfComponents();
132 for(vtkIdType aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++){
133 *theOutputPtr = *(theInputPtr + theComponentId);
134 theInputPtr += aNbComp;
140 //----------------------------------------------------------------------------
141 template<typename TDataSetAttributesType> void
142 ExecuteScalars(vtkIdType theNbOfTuples,
143 vtkIdType theScalarMode,
144 VISU::TGaussMetric theGaussMetric,
145 TDataSetAttributesType* theInputData,
146 TDataSetAttributesType* theOutputData)
148 if(theNbOfTuples < 1)
151 vtkDataArray* aFieldArray = NULL;
152 switch( theGaussMetric ) {
153 case VISU::AVERAGE_METRIC: aFieldArray = theInputData->GetArray("VISU_FIELD"); break;
154 case VISU::MINIMUM_METRIC: aFieldArray = theInputData->GetArray("VISU_FIELD_GAUSS_MIN"); break;
155 case VISU::MAXIMUM_METRIC: aFieldArray = theInputData->GetArray("VISU_FIELD_GAUSS_MAX"); break;
160 vtkIdType anInputDataType = aFieldArray->GetDataType();
161 vtkDataArray *anOutputScalars = vtkDataArray::CreateDataArray(anInputDataType);
162 anOutputScalars->SetNumberOfComponents(1);
163 anOutputScalars->SetNumberOfTuples(theNbOfTuples);
165 void *anInputPtr = aFieldArray->GetVoidPointer(0);
166 void *anOutputPtr = anOutputScalars->GetVoidPointer(0);
168 if(theScalarMode == 0){
169 switch(anInputDataType){
170 vtkTemplateMacro3(Module2Scalars,
172 (VTK_TT *)(anOutputPtr),
178 switch(anInputDataType){
179 vtkTemplateMacro5(Component2Scalars,
181 (VTK_TT *)(anInputPtr),
182 (VTK_TT *)(anOutputPtr),
190 theOutputData->SetScalars(anOutputScalars);
191 anOutputScalars->Delete();
195 //---------------------------------------------------------------
198 ::RequestData(vtkInformation *theRequest,
199 vtkInformationVector **theInputVector,
200 vtkInformationVector *theOutputVector)
202 vtkDataSet *anInput = VISU::GetInput( theInputVector, 0 );
203 vtkDataSet *anOutput = VISU::GetOutput( theOutputVector );
205 anOutput->CopyStructure( anInput );
207 vtkPointData *anInputPointData = anInput->GetPointData();
208 vtkPointData *anOutputPointData = anOutput->GetPointData();
209 anOutputPointData->PassData( anInputPointData );
210 if ( VISU::IsDataOnPoints( anInput ) ) {
211 int aNbElems = anInput->GetNumberOfPoints();
212 if ( anInputPointData->GetAttribute( vtkDataSetAttributes::VECTORS ) )
213 ExecuteScalars( aNbElems, myScalarMode, myGaussMetric, anInputPointData, anOutputPointData );
216 vtkCellData *anInputCellData = anInput->GetCellData();
217 vtkCellData *anOutputCellData = anOutput->GetCellData();
218 anOutputCellData->PassData( anInputCellData );
219 if ( VISU::IsDataOnCells( anInput ) ) {
220 int aNbElems = anInput->GetNumberOfCells();
221 if ( anInputCellData->GetAttribute( vtkDataSetAttributes::VECTORS ) )
222 ExecuteScalars( aNbElems, myScalarMode, myGaussMetric, anInputCellData, anOutputCellData );