--- /dev/null
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+
+#include "VISU_ElnoAssembleFilter.hxx"
+#include "VISU_PipeLineUtils.hxx"
+#include "VISU_ElnoMeshValue.hxx"
+
+#include <vtkCellData.h>
+#include <vtkInformation.h>
+#include <vtkInformationVector.h>
+#include <vtkObjectFactory.h>
+#include <vtkPointData.h>
+#include <vtkUnstructuredGrid.h>
+#include <vtkPoints.h>
+#include <vtkCellArray.h>
+
+
+//----------------------------------------------------------------------------
+vtkStandardNewMacro( VISU_ElnoAssembleFilter );
+
+
+//----------------------------------------------------------------------------
+VISU_ElnoAssembleFilter::VISU_ElnoAssembleFilter()
+{
+ this->SetInputArrayToProcess( 0, // idx
+ 0, // port
+ 0, // connection
+ vtkDataObject::FIELD_ASSOCIATION_POINTS, // field association
+ "ELNO_POINT_COORDS" ); // name
+}
+
+
+//----------------------------------------------------------------------------
+VISU_ElnoAssembleFilter::~VISU_ElnoAssembleFilter()
+{}
+
+
+//----------------------------------------------------------------------------
+namespace
+{
+ //----------------------------------------------------------------------------
+ template < int points_type, int elno_type >
+ int Execute2( vtkPointSet *theInput,
+ vtkPointSet *theOutput,
+ vtkDataArray *theElnoPointCoords )
+ {
+ theOutput->CopyStructure( theInput );
+
+ vtkCellData *aCellData = theOutput->GetCellData();
+ aCellData->PassData( theInput->GetCellData() );
+
+ vtkPointData *aPointData = theOutput->GetPointData();
+ aPointData->PassData( theInput->GetPointData() );
+
+ vtkPoints *anInputPoints = theInput->GetPoints();
+ vtkPoints *aPoints = anInputPoints->New( elno_type );
+ vtkIdType aNbPoints = theInput->GetNumberOfPoints();
+ aPoints->SetNumberOfPoints( aNbPoints );
+
+ typedef typename VISU::TL::TEnum2VTKArrayType< elno_type >::TResult TPointsDataArray;
+ typedef typename VISU::TL::TEnum2VTKBasicType< elno_type >::TResult TPointsDataType;
+ TPointsDataArray* anOutputPointsArray = TPointsDataArray::SafeDownCast( aPoints->GetData() );
+
+ TPointsDataArray* anElnoPointCoords = TPointsDataArray::SafeDownCast( theElnoPointCoords );
+
+ for ( vtkIdType aPointId = 0; aPointId < aNbPoints; aPointId++ ) {
+ TPointsDataType aCoords[ 3 ];
+ anElnoPointCoords->GetTupleValue( aPointId, aCoords );
+ anOutputPointsArray->SetTupleValue( aPointId, aCoords );
+ }
+
+ theOutput->SetPoints( aPoints );
+
+ return 1;
+ }
+
+
+ //----------------------------------------------------------------------------
+ template < int points_type >
+ int Execute( vtkPointSet *theInput,
+ vtkPointSet *theOutput,
+ vtkDataArray *theElnoPointCoords )
+ {
+ switch( theElnoPointCoords->GetDataType() ){
+ case VTK_DOUBLE:
+ return Execute2< points_type, VTK_DOUBLE >( theInput, theOutput, theElnoPointCoords );
+ case VTK_FLOAT:
+ return Execute2< points_type, VTK_FLOAT >( theInput, theOutput, theElnoPointCoords );
+ case VTK_INT:
+ return Execute2< points_type, VTK_INT >( theInput, theOutput, theElnoPointCoords );
+ case VTK_LONG:
+ return Execute2< points_type, VTK_LONG >( theInput, theOutput, theElnoPointCoords );
+ default:
+ break;
+ }
+
+ return 0;
+ }
+
+
+ //----------------------------------------------------------------------------
+}
+
+
+//----------------------------------------------------------------------------
+int VISU_ElnoAssembleFilter::RequestData( vtkInformation *vtkNotUsed(request),
+ vtkInformationVector **inputVector,
+ vtkInformationVector *outputVector )
+{
+ // get the info objects
+ vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
+ vtkInformation *outInfo = outputVector->GetInformationObject(0);
+
+ // get the input and ouptut
+ vtkPointSet *anInput = vtkPointSet::SafeDownCast( inInfo->Get( vtkDataObject::DATA_OBJECT() ) );
+ vtkPointSet *anOutput = vtkPointSet::SafeDownCast( outInfo->Get( vtkDataObject::DATA_OBJECT() ) );
+
+ vtkDataArray *anElnoPointCoords = this->GetInputArrayToProcess( 0, inputVector );
+
+ vtkPoints *aPoints = anInput->GetPoints();
+ switch( aPoints->GetDataType() ){
+ case VTK_DOUBLE:
+ return ::Execute< VTK_DOUBLE >( anInput, anOutput, anElnoPointCoords );
+ case VTK_FLOAT:
+ return ::Execute< VTK_FLOAT >( anInput, anOutput, anElnoPointCoords );
+ case VTK_INT:
+ return ::Execute< VTK_INT >( anInput, anOutput, anElnoPointCoords );
+ case VTK_LONG:
+ return ::Execute< VTK_LONG >( anInput, anOutput, anElnoPointCoords );
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+
+//----------------------------------------------------------------------------
0, // connection
vtkDataObject::FIELD_ASSOCIATION_CELLS, // field association
"ELNO_COMPONENT_MAPPER" ); // name
+
+ this->myShrinkFactor = -1.0;
}
{}
+//----------------------------------------------------------------------------
+void VISU_ElnoDisassembleFilter::SetShrinkFactor( vtkFloatingPointType theValue )
+{
+ if ( VISU::CheckIsSameValue( theValue, myShrinkFactor ) )
+ return;
+
+ myShrinkFactor = theValue;
+ this->Modified();
+}
+
+
+//----------------------------------------------------------------------------
+vtkFloatingPointType VISU_ElnoDisassembleFilter::GetShrinkFactor()
+{
+ return myShrinkFactor;
+}
+
+
//----------------------------------------------------------------------------
namespace
{
- template < int points_type, int elno_type >
- int Execute2( vtkUnstructuredGrid *theInput,
- vtkUnstructuredGrid *theOutput,
- vtkDataArray *theElnoDataArray,
- vtkDataArray *theElnoDataMapper )
+ //----------------------------------------------------------------------------
+ template < int points_type, class TPointsDataArray, int elno_type, class TElnoDataArray >
+ void SimpleExecute( vtkCellArray *theConnectivity,
+ vtkPointData *theInputPointData,
+ vtkPointData *theOutputPointData,
+ TPointsDataArray *theInputPointsArray,
+ TPointsDataArray *theOutputPointsArray,
+ VISU::TGetElnoNodeData< elno_type >& theGetElnoNodeData,
+ TElnoDataArray* theElnoPointDataArray,
+ TPointsDataArray *theElnoPointCoords )
{
- VISU::TGetElnoNodeData< elno_type > aGetElnoNodeData( theElnoDataArray, theElnoDataMapper );
-
- vtkCellArray *aConnectivity = vtkCellArray::New();
- aConnectivity->DeepCopy( theInput->GetCells() );
-
- vtkPoints *anInputPoints = theInput->GetPoints();
- vtkPoints *aPoints = anInputPoints->New( anInputPoints->GetDataType() );
- vtkIdType aNbCells = aConnectivity->GetNumberOfCells();
- vtkIdType aNbPoints = aConnectivity->GetNumberOfConnectivityEntries() - aNbCells;
- aPoints->Allocate( aNbPoints );
-
- typedef typename VISU::TL::TEnum2VTKArrayType< points_type >::TResult TPointsDataArray;
typedef typename VISU::TL::TEnum2VTKBasicType< points_type >::TResult TPointsDataType;
- TPointsDataArray* anInputPointsArray = TPointsDataArray::SafeDownCast( anInputPoints->GetData() );
- TPointsDataArray* anOutputPointsArray = TPointsDataArray::SafeDownCast( aPoints->GetData() );
-
- vtkPointData *anInputPointData = theInput->GetPointData();
- vtkPointData *aPointData = theOutput->GetPointData();
- aPointData->Allocate( aNbPoints );
-
- typedef typename VISU::TL::TEnum2VTKArrayType< elno_type >::TResult TElnoDataArray;
typedef typename VISU::TL::TEnum2VTKBasicType< elno_type >::TResult TElnoDataType;
- TElnoDataArray* anElnoPointsDataArray = TElnoDataArray::New();
- anElnoPointsDataArray->SetNumberOfComponents( aGetElnoNodeData.getNbComp() );
- anElnoPointsDataArray->SetNumberOfTuples( aNbPoints );
- anElnoPointsDataArray->SetName( "ELNO_POINT_DATA" );
- TPointsDataArray* aPointCoords = TPointsDataArray::New();
- aPointCoords->SetNumberOfComponents( 3 );
- aPointCoords->SetNumberOfTuples( aNbPoints );
- aPointCoords->SetName( "ELNO_POINT_COORDS" );
+ theConnectivity->InitTraversal();
+ vtkIdType aNbPts = 0, *aPts = 0;
+ for ( vtkIdType aCellId = 0; theConnectivity->GetNextCell( aNbPts, aPts ); aCellId++ ) {
+ for ( vtkIdType aPntId = 0; aPntId < aNbPts; aPntId++ ) {
+ TPointsDataType aCoords[ 3 ];
+ vtkIdType aCurrentPntId = aPts[ aPntId ];
+ theInputPointsArray->GetTupleValue( aCurrentPntId, aCoords );
+
+ aPts[ aPntId ] = theOutputPointsArray->InsertNextTupleValue( aCoords );
+ vtkIdType aNewPntId = aPts[ aPntId ];
- aConnectivity->InitTraversal();
+ theElnoPointCoords->SetTupleValue( aNewPntId, aCoords );
+
+ theOutputPointData->CopyData( theInputPointData, aCurrentPntId, aNewPntId );
+
+ TElnoDataType* anElnoData = theGetElnoNodeData( aCellId, aPntId );
+ theElnoPointDataArray->SetTupleValue( aNewPntId, anElnoData );
+ }
+ }
+ }
+
+
+ //----------------------------------------------------------------------------
+ template < int points_type, class TPointsDataArray, int elno_type, class TElnoDataArray >
+ void ShrunkExecute( vtkCellArray *theConnectivity,
+ vtkPointData *theInputPointData,
+ vtkPointData *theOutputPointData,
+ TPointsDataArray *theInputPointsArray,
+ TPointsDataArray *theOutputPointsArray,
+ VISU::TGetElnoNodeData< elno_type >& theGetElnoNodeData,
+ TElnoDataArray* theElnoPointDataArray,
+ TPointsDataArray *theElnoPointCoords,
+ vtkFloatingPointType theShrinkFactor )
+ {
+ typedef typename VISU::TL::TEnum2VTKBasicType< points_type >::TResult TPointsDataType;
+ typedef typename VISU::TL::TEnum2VTKBasicType< elno_type >::TResult TElnoDataType;
+
+ theConnectivity->InitTraversal();
vtkIdType aNbPts = 0, *aPts = 0;
- for ( vtkIdType aCellId = 0; aConnectivity->GetNextCell( aNbPts, aPts ); aCellId++ ) {
+ for ( vtkIdType aCellId = 0; theConnectivity->GetNextCell( aNbPts, aPts ); aCellId++ ) {
- TPointsDataType aCenter[ 3 ] = { TPointsDataType(),
- TPointsDataType(),
- TPointsDataType() };
+ TPointsDataType aCenter[ 3 ] = { TPointsDataType(), TPointsDataType(), TPointsDataType() };
for ( vtkIdType aPntId = 0; aPntId < aNbPts; aPntId++ ) {
TPointsDataType aCoords[ 3 ];
- anInputPointsArray->GetTupleValue( aPts[ aPntId ], aCoords );
+ theInputPointsArray->GetTupleValue( aPts[ aPntId ], aCoords );
aCenter[ 0 ] += aCoords[ 0 ];
aCenter[ 1 ] += aCoords[ 1 ];
for ( vtkIdType aPntId = 0; aPntId < aNbPts; aPntId++ ) {
TPointsDataType aCoords[ 3 ];
vtkIdType aCurrentPntId = aPts[ aPntId ];
- anInputPointsArray->GetTupleValue( aCurrentPntId, aCoords );
+ theInputPointsArray->GetTupleValue( aCurrentPntId, aCoords );
TPointsDataType aNewCoords[ 3 ];
- static vtkFloatingPointType SHRINK_FACTOR = 0.999;
aNewCoords[ 0 ] = aCenter[ 0 ] +
- TPointsDataType( SHRINK_FACTOR * ( aCoords[ 0 ] - aCenter[ 0 ] ) );
+ TPointsDataType( theShrinkFactor * ( aCoords[ 0 ] - aCenter[ 0 ] ) );
aNewCoords[ 1 ] = aCenter[ 1 ] +
- TPointsDataType( SHRINK_FACTOR * ( aCoords[ 1 ] - aCenter[ 1 ] ) );
+ TPointsDataType( theShrinkFactor * ( aCoords[ 1 ] - aCenter[ 1 ] ) );
aNewCoords[ 2 ] = aCenter[ 2 ] +
- TPointsDataType( SHRINK_FACTOR * ( aCoords[ 2 ] - aCenter[ 2 ] ) );
+ TPointsDataType( theShrinkFactor * ( aCoords[ 2 ] - aCenter[ 2 ] ) );
- aPts[ aPntId ] = anOutputPointsArray->InsertNextTupleValue( aNewCoords );
+ aPts[ aPntId ] = theOutputPointsArray->InsertNextTupleValue( aNewCoords );
vtkIdType aNewPntId = aPts[ aPntId ];
- aPointCoords->SetTupleValue( aNewPntId, aCoords );
+ theElnoPointCoords->SetTupleValue( aNewPntId, aCoords );
- aPointData->CopyData( anInputPointData, aCurrentPntId, aNewPntId );
+ theOutputPointData->CopyData( theInputPointData, aCurrentPntId, aNewPntId );
- TElnoDataType* anElnoData = aGetElnoNodeData( aCellId, aPntId );
- anElnoPointsDataArray->SetTupleValue( aNewPntId, anElnoData );
+ TElnoDataType* anElnoData = theGetElnoNodeData( aCellId, aPntId );
+ theElnoPointDataArray->SetTupleValue( aNewPntId, anElnoData );
}
}
+ }
+
+
+ //----------------------------------------------------------------------------
+ template < int points_type, int elno_type >
+ int Execute2( vtkUnstructuredGrid *theInput,
+ vtkUnstructuredGrid *theOutput,
+ vtkDataArray *theElnoDataArray,
+ vtkDataArray *theElnoDataMapper,
+ vtkFloatingPointType theShrinkFactor )
+ {
+ VISU::TGetElnoNodeData< elno_type > aGetElnoNodeData( theElnoDataArray, theElnoDataMapper );
+
+ vtkCellArray *aConnectivity = vtkCellArray::New();
+ aConnectivity->DeepCopy( theInput->GetCells() );
+
+ vtkPoints *anInputPoints = theInput->GetPoints();
+ vtkPoints *aPoints = anInputPoints->New( anInputPoints->GetDataType() );
+ vtkIdType aNbCells = aConnectivity->GetNumberOfCells();
+ vtkIdType aNbPoints = aConnectivity->GetNumberOfConnectivityEntries() - aNbCells;
+ aPoints->Allocate( aNbPoints );
+
+ typedef typename VISU::TL::TEnum2VTKArrayType< points_type >::TResult TPointsDataArray;
+ TPointsDataArray* anInputPointsArray = TPointsDataArray::SafeDownCast( anInputPoints->GetData() );
+ TPointsDataArray* anOutputPointsArray = TPointsDataArray::SafeDownCast( aPoints->GetData() );
+ vtkPointData *anInputPointData = theInput->GetPointData();
+ vtkPointData *anOutputPointData = theOutput->GetPointData();
+ anOutputPointData->Allocate( aNbPoints );
+
+ typedef typename VISU::TL::TEnum2VTKArrayType< elno_type >::TResult TElnoDataArray;
+ TElnoDataArray* anElnoPointDataArray = TElnoDataArray::New();
+ anElnoPointDataArray->SetNumberOfComponents( aGetElnoNodeData.getNbComp() );
+ anElnoPointDataArray->SetNumberOfTuples( aNbPoints );
+ anElnoPointDataArray->SetName( "ELNO_POINT_DATA" );
+
+ TPointsDataArray* anElnoPointCoords = TPointsDataArray::New();
+ anElnoPointCoords->SetNumberOfComponents( 3 );
+ anElnoPointCoords->SetNumberOfTuples( aNbPoints );
+ anElnoPointCoords->SetName( "ELNO_POINT_COORDS" );
+
+ if ( theShrinkFactor > 0.0 ) {
+ ShrunkExecute< points_type, TPointsDataArray, elno_type, TElnoDataArray >
+ ( aConnectivity,
+ anInputPointData,
+ anOutputPointData,
+ anInputPointsArray,
+ anOutputPointsArray,
+ aGetElnoNodeData,
+ anElnoPointDataArray,
+ anElnoPointCoords,
+ theShrinkFactor );
+ } else {
+ SimpleExecute< points_type, TPointsDataArray, elno_type, TElnoDataArray >
+ ( aConnectivity,
+ anInputPointData,
+ anOutputPointData,
+ anInputPointsArray,
+ anOutputPointsArray,
+ aGetElnoNodeData,
+ anElnoPointDataArray,
+ anElnoPointCoords );
+ }
+
theOutput->SetPoints( aPoints );
theOutput->SetCells( theInput->GetCellTypesArray(),
aCellData->RemoveArray( "ELNO_COMPONENT_MAPPER" );
aCellData->RemoveArray( "ELNO_FIELD" );
- aPointData->AddArray( anElnoPointsDataArray );
- anElnoPointsDataArray->Delete();
+ anOutputPointData->AddArray( anElnoPointDataArray );
+ anElnoPointDataArray->Delete();
- aPointData->AddArray( aPointCoords );
- aPointCoords->Delete();
+ anOutputPointData->AddArray( anElnoPointCoords );
+ anElnoPointCoords->Delete();
return 1;
}
int Execute( vtkUnstructuredGrid *theInput,
vtkUnstructuredGrid *theOutput,
vtkDataArray *theElnoDataArray,
- vtkDataArray *theElnoDataMapper )
+ vtkDataArray *theElnoDataMapper,
+ vtkFloatingPointType theShrinkFactor )
{
switch( theElnoDataArray->GetDataType() ){
case VTK_DOUBLE:
- return Execute2< points_type, VTK_DOUBLE >( theInput, theOutput, theElnoDataArray, theElnoDataMapper );
+ return Execute2< points_type, VTK_DOUBLE >
+ ( theInput, theOutput, theElnoDataArray, theElnoDataMapper, theShrinkFactor );
case VTK_FLOAT:
- return Execute2< points_type, VTK_FLOAT >( theInput, theOutput, theElnoDataArray, theElnoDataMapper );
+ return Execute2< points_type, VTK_FLOAT >
+ ( theInput, theOutput, theElnoDataArray, theElnoDataMapper, theShrinkFactor );
case VTK_INT:
- return Execute2< points_type, VTK_INT >( theInput, theOutput, theElnoDataArray, theElnoDataMapper );
+ return Execute2< points_type, VTK_INT >
+ ( theInput, theOutput, theElnoDataArray, theElnoDataMapper, theShrinkFactor );
case VTK_LONG:
- return Execute2< points_type, VTK_LONG >( theInput, theOutput, theElnoDataArray, theElnoDataMapper );
+ return Execute2< points_type, VTK_LONG >
+ ( theInput, theOutput, theElnoDataArray, theElnoDataMapper, theShrinkFactor );
default:
break;
}
vtkPoints *aPoints = anInput->GetPoints();
switch( aPoints->GetDataType() ){
case VTK_DOUBLE:
- return ::Execute< VTK_DOUBLE >( anInput, anOutput, anElnoDataArray, anElnoDataMapper );
+ return ::Execute< VTK_DOUBLE >( anInput, anOutput, anElnoDataArray, anElnoDataMapper, myShrinkFactor );
case VTK_FLOAT:
- return ::Execute< VTK_FLOAT >( anInput, anOutput, anElnoDataArray, anElnoDataMapper );
+ return ::Execute< VTK_FLOAT >( anInput, anOutput, anElnoDataArray, anElnoDataMapper, myShrinkFactor );
case VTK_INT:
- return ::Execute< VTK_INT >( anInput, anOutput, anElnoDataArray, anElnoDataMapper );
+ return ::Execute< VTK_INT >( anInput, anOutput, anElnoDataArray, anElnoDataMapper, myShrinkFactor );
case VTK_LONG:
- return ::Execute< VTK_LONG >( anInput, anOutput, anElnoDataArray, anElnoDataMapper );
+ return ::Execute< VTK_LONG >( anInput, anOutput, anElnoDataArray, anElnoDataMapper, myShrinkFactor );
default:
break;
}