1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "VISU_ElnoAssembleFilter.hxx"
21 #include "VISU_PipeLineUtils.hxx"
22 #include "VISU_ElnoMeshValue.hxx"
24 #include <vtkCellData.h>
25 #include <vtkInformation.h>
26 #include <vtkInformationVector.h>
27 #include <vtkObjectFactory.h>
28 #include <vtkPointData.h>
29 #include <vtkUnstructuredGrid.h>
30 #include <vtkPoints.h>
31 #include <vtkCellArray.h>
34 //----------------------------------------------------------------------------
35 vtkStandardNewMacro( VISU_ElnoAssembleFilter );
38 //----------------------------------------------------------------------------
39 VISU_ElnoAssembleFilter::VISU_ElnoAssembleFilter()
41 this->SetInputArrayToProcess( 0, // idx
44 vtkDataObject::FIELD_ASSOCIATION_POINTS, // field association
45 "ELNO_POINT_COORDS" ); // name
47 this->myIsRestorePoints = false;
51 //----------------------------------------------------------------------------
52 VISU_ElnoAssembleFilter::~VISU_ElnoAssembleFilter()
56 //----------------------------------------------------------------------------
57 void VISU_ElnoAssembleFilter::SetElnoAssembleState( bool theIsRestorePoints )
59 if ( myIsRestorePoints == theIsRestorePoints )
62 myIsRestorePoints = theIsRestorePoints;
66 //----------------------------------------------------------------------------
69 //----------------------------------------------------------------------------
70 template < int points_type, int elno_type >
71 int Execute2( vtkPointSet *theInput,
72 vtkPointSet *theOutput,
73 vtkDataArray *theElnoPointCoords )
75 theOutput->CopyStructure( theInput );
77 vtkCellData *aCellData = theOutput->GetCellData();
78 aCellData->PassData( theInput->GetCellData() );
80 vtkPointData *aPointData = theOutput->GetPointData();
81 aPointData->PassData( theInput->GetPointData() );
83 vtkPoints *anInputPoints = theInput->GetPoints();
84 vtkPoints *aPoints = anInputPoints->New( elno_type );
85 vtkIdType aNbPoints = theInput->GetNumberOfPoints();
86 aPoints->SetNumberOfPoints( aNbPoints );
88 typedef typename VISU::TL::TEnum2VTKArrayType< elno_type >::TResult TPointsDataArray;
89 typedef typename VISU::TL::TEnum2VTKBasicType< elno_type >::TResult TPointsDataType;
90 TPointsDataArray* anOutputPointsArray = TPointsDataArray::SafeDownCast( aPoints->GetData() );
92 TPointsDataArray* anElnoPointCoords = TPointsDataArray::SafeDownCast( theElnoPointCoords );
94 for ( vtkIdType aPointId = 0; aPointId < aNbPoints; aPointId++ ) {
95 TPointsDataType aCoords[ 3 ];
96 anElnoPointCoords->GetTupleValue( aPointId, aCoords );
97 anOutputPointsArray->SetTupleValue( aPointId, aCoords );
100 theOutput->SetPoints( aPoints );
106 //----------------------------------------------------------------------------
107 template < int points_type >
108 int Execute( vtkPointSet *theInput,
109 vtkPointSet *theOutput,
110 vtkDataArray *theElnoPointCoords )
112 switch( theElnoPointCoords->GetDataType() ){
114 return Execute2< points_type, VTK_DOUBLE >( theInput, theOutput, theElnoPointCoords );
116 return Execute2< points_type, VTK_FLOAT >( theInput, theOutput, theElnoPointCoords );
118 return Execute2< points_type, VTK_INT >( theInput, theOutput, theElnoPointCoords );
120 return Execute2< points_type, VTK_LONG >( theInput, theOutput, theElnoPointCoords );
129 //----------------------------------------------------------------------------
133 //----------------------------------------------------------------------------
134 int VISU_ElnoAssembleFilter::RequestData( vtkInformation *vtkNotUsed(request),
135 vtkInformationVector **inputVector,
136 vtkInformationVector *outputVector )
138 // get the info objects
139 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
140 vtkInformation *outInfo = outputVector->GetInformationObject(0);
142 // get the input and ouptut
143 vtkPointSet *anInput = vtkPointSet::SafeDownCast( inInfo->Get( vtkDataObject::DATA_OBJECT() ) );
144 vtkPointSet *anOutput = vtkPointSet::SafeDownCast( outInfo->Get( vtkDataObject::DATA_OBJECT() ) );
146 vtkDataArray *anElnoPointCoords = this->GetInputArrayToProcess( 0, inputVector );
148 if ( !myIsRestorePoints || !anElnoPointCoords ) {
149 anOutput->ShallowCopy( anInput );
153 vtkPoints *aPoints = anInput->GetPoints();
154 switch( aPoints->GetDataType() ){
156 return ::Execute< VTK_DOUBLE >( anInput, anOutput, anElnoPointCoords );
158 return ::Execute< VTK_FLOAT >( anInput, anOutput, anElnoPointCoords );
160 return ::Execute< VTK_INT >( anInput, anOutput, anElnoPointCoords );
162 return ::Execute< VTK_LONG >( anInput, anOutput, anElnoPointCoords );
171 //----------------------------------------------------------------------------