namespace
{
//----------------------------------------------------------------------------
- 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,
- TElnoDataArray* theElnoPointVectors,
- TPointsDataArray *theElnoPointCoords )
+ template < int points_type, int elno_type >
+ struct TExecute2
{
- typedef typename VISU::TL::TEnum2VTKBasicType< points_type >::TResult TPointsDataType;
- typedef typename VISU::TL::TEnum2VTKBasicType< elno_type >::TResult TElnoDataType;
-
- // To reserve a temproary value holder
- vtkIdType aNbComp = std::max( 3, theGetElnoNodeData.getNbComp() );
- std::vector< TElnoDataType > anElnoDataValues( aNbComp );
-
- 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 ];
-
- theElnoPointCoords->SetTupleValue( aNewPntId, aCoords );
-
- theOutputPointData->CopyData( theInputPointData, aCurrentPntId, aNewPntId );
-
- TElnoDataType* anElnoData = theGetElnoNodeData( aCellId, aPntId );
- theElnoPointDataArray->SetTupleValue( aNewPntId, anElnoData );
+ vtkUnstructuredGrid *myInput;
+ vtkUnstructuredGrid *myOutput;
+ vtkDataArray *myElnoDataArray;
+ vtkDataArray *myElnoDataMapper;
+ vtkFloatingPointType myShrinkFactor;
- theElnoPointDataArray->GetTupleValue( aNewPntId, &anElnoDataValues[ 0 ] );
- theElnoPointVectors->SetTupleValue( aNewPntId, &anElnoDataValues[ 0 ] );
- }
- }
- }
-
-
- //----------------------------------------------------------------------------
- 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,
- TElnoDataArray* theElnoPointVectors,
- TPointsDataArray *theElnoPointCoords,
- vtkFloatingPointType theShrinkFactor )
- {
+ typedef typename VISU::TL::TEnum2VTKArrayType< points_type >::TResult TPointsDataArray;
typedef typename VISU::TL::TEnum2VTKBasicType< points_type >::TResult TPointsDataType;
- typedef typename VISU::TL::TEnum2VTKBasicType< elno_type >::TResult TElnoDataType;
-
- // To reserve a temproary value holder
- vtkIdType aNbComp = std::max( 3, theGetElnoNodeData.getNbComp() );
- std::vector< TElnoDataType > anElnoDataValues( aNbComp );
-
- theConnectivity->InitTraversal();
- vtkIdType aNbPts = 0, *aPts = 0;
- for ( vtkIdType aCellId = 0; theConnectivity->GetNextCell( aNbPts, aPts ); aCellId++ ) {
- TPointsDataType aCenter[ 3 ] = { TPointsDataType(), TPointsDataType(), TPointsDataType() };
+ typedef typename VISU::TL::TEnum2VTKArrayType< elno_type >::TResult TElnoDataArray;
+ typedef typename VISU::TL::TEnum2VTKBasicType< elno_type >::TResult TElnoDataType;
- for ( vtkIdType aPntId = 0; aPntId < aNbPts; aPntId++ ) {
- TPointsDataType aCoords[ 3 ];
- theInputPointsArray->GetTupleValue( aPts[ aPntId ], aCoords );
+ VISU::TGetElnoNodeData< elno_type > myGetElnoNodeData;
+ vtkCellArray *myConnectivity;
+ vtkPointData *myInputPointData;
+ vtkPointData *myOutputPointData;
+ TPointsDataArray *myInputPointsArray;
+ TPointsDataArray *myOutputPointsArray;
+ TElnoDataArray* myElnoPointDataArray;
+ TElnoDataArray* myElnoPointVectors;
+ TPointsDataArray *myElnoPointCoords;
+ vtkIntArray* myInputPointsMapper;
+ vtkIntArray* myOutputPointsMapper;
+
+ //----------------------------------------------------------------------------
+ TExecute2( vtkUnstructuredGrid *theInput,
+ vtkUnstructuredGrid *theOutput,
+ vtkDataArray *theElnoDataArray,
+ vtkDataArray *theElnoDataMapper,
+ vtkFloatingPointType theShrinkFactor )
+ : myGetElnoNodeData( theElnoDataArray, theElnoDataMapper )
+ , myInput( theInput )
+ , myOutput( theOutput )
+ , myElnoDataArray( theElnoDataArray )
+ , myElnoDataMapper( theElnoDataMapper )
+ , myShrinkFactor( theShrinkFactor )
+ {
+ myConnectivity = vtkCellArray::New();
+ myConnectivity->DeepCopy( theInput->GetCells() );
+
+ vtkPoints *anInputPoints = theInput->GetPoints();
+ vtkPoints *aPoints = anInputPoints->New( anInputPoints->GetDataType() );
+ vtkIdType aNbCells = myConnectivity->GetNumberOfCells();
+ vtkIdType aNbPoints = myConnectivity->GetNumberOfConnectivityEntries() - aNbCells;
+ aPoints->Allocate( aNbPoints );
+
+ myInputPointsArray = TPointsDataArray::SafeDownCast( anInputPoints->GetData() );
+ myOutputPointsArray = TPointsDataArray::SafeDownCast( aPoints->GetData() );
+
+ myInputPointData = theInput->GetPointData();
+ myOutputPointData = theOutput->GetPointData();
+ myOutputPointData->Allocate( aNbPoints );
+
+ vtkCellData *anInputCellData = theInput->GetCellData();
+ vtkDataArray* aVectors = anInputCellData->GetVectors();
+
+ myElnoPointDataArray = TElnoDataArray::New();
+ myElnoPointDataArray->SetName( "VISU_FIELD" );
+ myElnoPointDataArray->SetNumberOfComponents( myGetElnoNodeData.getNbComp() );
+ myElnoPointDataArray->SetNumberOfTuples( aNbPoints );
+
+ myElnoPointVectors = TElnoDataArray::New();
+ myElnoPointVectors->SetName( aVectors->GetName() );
+ myElnoPointVectors->SetNumberOfComponents( 3 );
+ myElnoPointVectors->SetNumberOfTuples( aNbPoints );
+
+ myElnoPointCoords = TPointsDataArray::New();
+ myElnoPointCoords->SetName( "ELNO_POINT_COORDS" );
+ myElnoPointCoords->SetNumberOfComponents( 3 );
+ myElnoPointCoords->SetNumberOfTuples( aNbPoints );
+
+ vtkDataArray* anArray = myInputPointData->GetArray( "VISU_POINTS_MAPPER" );
+ myInputPointsMapper = vtkIntArray::SafeDownCast( anArray );
+
+ myOutputPointsMapper = vtkIntArray::New();
+ myOutputPointsMapper->SetName( myInputPointsMapper->GetName() );
+ myOutputPointsMapper->SetNumberOfComponents( myInputPointsMapper->GetNumberOfComponents() );
+ myOutputPointsMapper->SetNumberOfTuples( aNbPoints );
+
+ if ( theShrinkFactor > 0.0 )
+ this->ShrinkExecute();
+ else
+ this->SimpleExecute();
+
+ theOutput->SetPoints( aPoints );
+
+ theOutput->SetCells( theInput->GetCellTypesArray(),
+ theInput->GetCellLocationsArray(),
+ myConnectivity );
+
+ myConnectivity->Delete();
+
+ vtkCellData *anOutputCellData = theOutput->GetCellData();
+ anOutputCellData->PassData( anInputCellData );
+
+ anOutputCellData->RemoveArray( "ELNO_COMPONENT_MAPPER" );
+ anOutputCellData->RemoveArray( "ELNO_FIELD" );
+ anOutputCellData->RemoveArray( "VISU_FIELD" );
+ anOutputCellData->SetVectors( NULL );
+
+ //anOutputPointData->PassData( anInputPointData );
+
+ myOutputPointData->AddArray( myElnoPointDataArray );
+ myElnoPointDataArray->Delete();
+
+ myOutputPointData->SetVectors( myElnoPointVectors );
+ myElnoPointVectors->Delete();
+
+ myOutputPointData->AddArray( myElnoPointCoords );
+ myElnoPointCoords->Delete();
+
+ myOutputPointData->AddArray( myOutputPointsMapper );
+ myOutputPointsMapper->Delete();
+ }
- aCenter[ 0 ] += aCoords[ 0 ];
- aCenter[ 1 ] += aCoords[ 1 ];
- aCenter[ 2 ] += aCoords[ 2 ];
+ //----------------------------------------------------------------------------
+ void SimpleExecute()
+ {
+ // To reserve a temproary value holder
+ vtkIdType aNbComp = std::max( 3, myGetElnoNodeData.getNbComp() );
+ std::vector< TElnoDataType > anElnoDataValues( aNbComp );
+
+ std::vector< int > anPointsMapperValues( myInputPointsMapper->GetNumberOfComponents() );
+
+ myConnectivity->InitTraversal();
+ vtkIdType aNbPts = 0, *aPts = 0;
+ for ( vtkIdType aCellId = 0; myConnectivity->GetNextCell( aNbPts, aPts ); aCellId++ ) {
+ for ( vtkIdType aPntId = 0; aPntId < aNbPts; aPntId++ ) {
+ TPointsDataType aCoords[ 3 ];
+ vtkIdType aCurrentPntId = aPts[ aPntId ];
+ myInputPointsArray->GetTupleValue( aCurrentPntId, aCoords );
+
+ aPts[ aPntId ] = myOutputPointsArray->InsertNextTupleValue( aCoords );
+ vtkIdType aNewPntId = aPts[ aPntId ];
+
+ myElnoPointCoords->SetTupleValue( aNewPntId, aCoords );
+
+ myOutputPointData->CopyData( myInputPointData, aCurrentPntId, aNewPntId );
+
+ TElnoDataType* anElnoData = myGetElnoNodeData( aCellId, aPntId );
+ myElnoPointDataArray->SetTupleValue( aNewPntId, anElnoData );
+
+ myElnoPointDataArray->GetTupleValue( aNewPntId, &anElnoDataValues[ 0 ] );
+ myElnoPointVectors->SetTupleValue( aNewPntId, &anElnoDataValues[ 0 ] );
+
+ myInputPointsMapper->GetTupleValue( aCurrentPntId, &anPointsMapperValues[ 0 ] );
+ myOutputPointsMapper->SetTupleValue( aNewPntId, &anPointsMapperValues[ 0 ] );
+ }
}
+ }
- aCenter[ 0 ] /= aNbPts;
- aCenter[ 1 ] /= aNbPts;
- aCenter[ 2 ] /= aNbPts;
-
- for ( vtkIdType aPntId = 0; aPntId < aNbPts; aPntId++ ) {
- TPointsDataType aCoords[ 3 ];
- vtkIdType aCurrentPntId = aPts[ aPntId ];
- theInputPointsArray->GetTupleValue( aCurrentPntId, aCoords );
-
- TPointsDataType aNewCoords[ 3 ];
-
- aNewCoords[ 0 ] = aCenter[ 0 ] +
- TPointsDataType( theShrinkFactor * ( aCoords[ 0 ] - aCenter[ 0 ] ) );
- aNewCoords[ 1 ] = aCenter[ 1 ] +
- TPointsDataType( theShrinkFactor * ( aCoords[ 1 ] - aCenter[ 1 ] ) );
- aNewCoords[ 2 ] = aCenter[ 2 ] +
- TPointsDataType( theShrinkFactor * ( aCoords[ 2 ] - aCenter[ 2 ] ) );
-
- aPts[ aPntId ] = theOutputPointsArray->InsertNextTupleValue( aNewCoords );
- vtkIdType aNewPntId = aPts[ aPntId ];
-
- theElnoPointCoords->SetTupleValue( aNewPntId, aCoords );
-
- theOutputPointData->CopyData( theInputPointData, aCurrentPntId, aNewPntId );
-
- TElnoDataType* anElnoData = theGetElnoNodeData( aCellId, aPntId );
- theElnoPointDataArray->SetTupleValue( aNewPntId, anElnoData );
-
- theElnoPointDataArray->GetTupleValue( aNewPntId, &anElnoDataValues[ 0 ] );
- theElnoPointVectors->SetTupleValue( aNewPntId, &anElnoDataValues[ 0 ] );
+ //----------------------------------------------------------------------------
+ void ShrinkExecute()
+ {
+ // To reserve a temproary value holder
+ vtkIdType aNbComp = std::max( 3, myGetElnoNodeData.getNbComp() );
+ std::vector< TElnoDataType > anElnoDataValues( aNbComp );
+
+ std::vector< int > anPointsMapperValues( myInputPointsMapper->GetNumberOfComponents() );
+
+ myConnectivity->InitTraversal();
+ vtkIdType aNbPts = 0, *aPts = 0;
+ for ( vtkIdType aCellId = 0; myConnectivity->GetNextCell( aNbPts, aPts ); aCellId++ ) {
+
+ TPointsDataType aCenter[ 3 ] = { TPointsDataType(), TPointsDataType(), TPointsDataType() };
+
+ for ( vtkIdType aPntId = 0; aPntId < aNbPts; aPntId++ ) {
+ TPointsDataType aCoords[ 3 ];
+ myInputPointsArray->GetTupleValue( aPts[ aPntId ], aCoords );
+
+ aCenter[ 0 ] += aCoords[ 0 ];
+ aCenter[ 1 ] += aCoords[ 1 ];
+ aCenter[ 2 ] += aCoords[ 2 ];
+ }
+
+ aCenter[ 0 ] /= aNbPts;
+ aCenter[ 1 ] /= aNbPts;
+ aCenter[ 2 ] /= aNbPts;
+
+ for ( vtkIdType aPntId = 0; aPntId < aNbPts; aPntId++ ) {
+ TPointsDataType aCoords[ 3 ];
+ vtkIdType aCurrentPntId = aPts[ aPntId ];
+ myInputPointsArray->GetTupleValue( aCurrentPntId, aCoords );
+
+ TPointsDataType aNewCoords[ 3 ];
+
+ aNewCoords[ 0 ] = aCenter[ 0 ] +
+ TPointsDataType( myShrinkFactor * ( aCoords[ 0 ] - aCenter[ 0 ] ) );
+ aNewCoords[ 1 ] = aCenter[ 1 ] +
+ TPointsDataType( myShrinkFactor * ( aCoords[ 1 ] - aCenter[ 1 ] ) );
+ aNewCoords[ 2 ] = aCenter[ 2 ] +
+ TPointsDataType( myShrinkFactor * ( aCoords[ 2 ] - aCenter[ 2 ] ) );
+
+ aPts[ aPntId ] = myOutputPointsArray->InsertNextTupleValue( aNewCoords );
+ vtkIdType aNewPntId = aPts[ aPntId ];
+
+ myElnoPointCoords->SetTupleValue( aNewPntId, aCoords );
+
+ myOutputPointData->CopyData( myInputPointData, aCurrentPntId, aNewPntId );
+
+ TElnoDataType* anElnoData = myGetElnoNodeData( aCellId, aPntId );
+ myElnoPointDataArray->SetTupleValue( aNewPntId, anElnoData );
+
+ myElnoPointDataArray->GetTupleValue( aNewPntId, &anElnoDataValues[ 0 ] );
+ myElnoPointVectors->SetTupleValue( aNewPntId, &anElnoDataValues[ 0 ] );
+
+ myInputPointsMapper->GetTupleValue( aCurrentPntId, &anPointsMapperValues[ 0 ] );
+ myOutputPointsMapper->SetTupleValue( aNewPntId, &anPointsMapperValues[ 0 ] );
+ }
}
}
- }
+ };
//----------------------------------------------------------------------------
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 );
-
- vtkCellData *anInputCellData = theInput->GetCellData();
- vtkDataArray* aVectors = anInputCellData->GetVectors();
-
- typedef typename VISU::TL::TEnum2VTKArrayType< elno_type >::TResult TElnoDataArray;
- TElnoDataArray* anElnoPointDataArray = TElnoDataArray::New();
- anElnoPointDataArray->SetNumberOfComponents( aGetElnoNodeData.getNbComp() );
- anElnoPointDataArray->SetNumberOfTuples( aNbPoints );
- anElnoPointDataArray->SetName( "VISU_FIELD" );
-
- TElnoDataArray* anElnoPointVectors = TElnoDataArray::New();
- anElnoPointVectors->SetNumberOfComponents( 3 );
- anElnoPointVectors->SetNumberOfTuples( aNbPoints );
- anElnoPointVectors->SetName( aVectors->GetName() );
-
- 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,
- anElnoPointVectors,
- anElnoPointCoords,
- theShrinkFactor );
- } else {
- SimpleExecute< points_type, TPointsDataArray, elno_type, TElnoDataArray >
- ( aConnectivity,
- anInputPointData,
- anOutputPointData,
- anInputPointsArray,
- anOutputPointsArray,
- aGetElnoNodeData,
- anElnoPointDataArray,
- anElnoPointVectors,
- anElnoPointCoords );
- }
-
- theOutput->SetPoints( aPoints );
-
- theOutput->SetCells( theInput->GetCellTypesArray(),
- theInput->GetCellLocationsArray(),
- aConnectivity );
-
- vtkCellData *anOutputCellData = theOutput->GetCellData();
- anOutputCellData->PassData( anInputCellData );
-
- anOutputCellData->RemoveArray( "ELNO_COMPONENT_MAPPER" );
- anOutputCellData->RemoveArray( "ELNO_FIELD" );
- anOutputCellData->RemoveArray( "VISU_FIELD" );
- anOutputCellData->SetVectors( NULL );
-
- anOutputPointData->PassData( anInputPointData );
-
- anOutputPointData->AddArray( anElnoPointDataArray );
- anElnoPointDataArray->Delete();
-
- anOutputPointData->SetVectors( anElnoPointVectors );
- anElnoPointVectors->Delete();
-
- anOutputPointData->AddArray( anElnoPointCoords );
- anElnoPointCoords->Delete();
-
+ TExecute2< points_type, elno_type >( theInput,
+ theOutput,
+ theElnoDataArray,
+ theElnoDataMapper,
+ theShrinkFactor );
+
return 1;
}