From: apo Date: Wed, 30 Apr 2008 15:47:29 +0000 (+0000) Subject: Introduction of the ELNO related VTK WarpVector filter X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=083699a2a12d4aea51340495bf234520f9ce35ea;p=modules%2Fvisu.git Introduction of the ELNO related VTK WarpVector filter --- diff --git a/src/CONVERTOR/Makefile.am b/src/CONVERTOR/Makefile.am index 448bbdca..30a5a876 100644 --- a/src/CONVERTOR/Makefile.am +++ b/src/CONVERTOR/Makefile.am @@ -28,6 +28,7 @@ lib_LTLIBRARIES = libVisuConvertor.la salomeinclude_HEADERS= \ VISU_TypeList.hxx \ + VISU_VTKTypeList.hxx \ VISU_IDMapper.hxx \ VISU_ConvertorDef.hxx \ VISU_Structures.hxx \ @@ -35,6 +36,7 @@ salomeinclude_HEADERS= \ VISU_ConvertorDef_impl.hxx \ VISU_Structures_impl.hxx \ VISU_MeshValue.hxx \ + VISU_ElnoMeshValue.hxx \ VISU_PointCoords.hxx \ VISU_Convertor_impl.hxx \ VISU_ConvertorUtils.hxx \ diff --git a/src/CONVERTOR/VISU_Convertor_impl.cxx b/src/CONVERTOR/VISU_Convertor_impl.cxx index e9ecb27b..c908ab0b 100644 --- a/src/CONVERTOR/VISU_Convertor_impl.cxx +++ b/src/CONVERTOR/VISU_Convertor_impl.cxx @@ -85,18 +85,12 @@ namespace //--------------------------------------------------------------- + inline void - PrintCells(int& theStartId, - vtkCellArray* theConnectivity, - const VISU::TConnect& theVector) + PrintCells( vtkCellArray* theConnectivity, + const VISU::TConnect& theVector) { - vtkIdList *anIdList = vtkIdList::New(); - int kEnd = theVector.size(); - anIdList->SetNumberOfIds(kEnd); - for(int k = 0; k < kEnd; k++) - anIdList->SetId(k,theVector[k]); - theConnectivity->InsertNextCell(anIdList); - anIdList->Delete(); + theConnectivity->InsertNextCell( theVector.size(), &theVector[ 0 ] ); } @@ -124,7 +118,7 @@ namespace aCellTypesArray->SetNumberOfTuples(aNbCells); for(vtkIdType anID = 0; anID < aNbCells; anID++){ - PrintCells(anID,aConnectivity,anArray[anID]); + PrintCells( aConnectivity, anArray[ anID ] ); aCellTypesArray->SetValue(anID,(unsigned char)theGeom); } @@ -219,7 +213,7 @@ namespace VISU::TSubMeshID::const_iterator aSubMeshIDIter = aSubMeshID.begin(); for(; aSubMeshIDIter != aSubMeshID.end(); aSubMeshIDIter++, aCellId++){ vtkIdType anID = *aSubMeshIDIter; - PrintCells(aCellId, aConnectivity, anArray[anID]); + PrintCells( aConnectivity, anArray[ anID ] ); aCellTypesArray->SetValue(aCellId, (unsigned char)aVGeom); vtkIdType anObjID = aSubMesh.GetElemObjID(anID); anElemObj2VTKID[anObjID] = aCellId; @@ -284,7 +278,7 @@ namespace VISU::TCell2Connect::const_iterator anIter = aCell2Connect.begin(); for(vtkIdType anId = 0, aConnId = 0; anIter != aCell2Connect.end(); anIter++){ const VISU::TConnect& anArray = aCell2Connect[anId]; - PrintCells(aConnId,aConnectivity,anArray); + PrintCells( aConnectivity, anArray ); aCellTypesArray->SetValue(anId,(unsigned char)aVGeom); aConnId += aNbNodes; anId++; @@ -294,7 +288,7 @@ namespace for(vtkIdType anId = 0, aConnId = 0; anIter != aSubMeshID.end(); anIter++){ vtkIdType aSubId = *anIter; const VISU::TConnect& anArray = aCell2Connect[aSubId]; - PrintCells(aConnId,aConnectivity,anArray); + PrintCells( aConnectivity, anArray ); aCellTypesArray->SetValue(anId,(unsigned char)aVGeom); aConnId += aNbNodes; anId++; diff --git a/src/CONVERTOR/VISU_ElnoMeshValue.hxx b/src/CONVERTOR/VISU_ElnoMeshValue.hxx new file mode 100644 index 00000000..3548f2e1 --- /dev/null +++ b/src/CONVERTOR/VISU_ElnoMeshValue.hxx @@ -0,0 +1,78 @@ +// 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 +// +// +// File : VISU_ElnoMeshValue.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_ElnoMeshValue_HeaderFile +#define VISU_ElnoMeshValue_HeaderFile + +#include "VISU_VTKTypeList.hxx" + +/*! + \file VISU_ElnoMeshValue.hxx + \brief The file contains declarations for the acess to the specific ELNO MED data +*/ + +namespace VISU +{ + //--------------------------------------------------------------- + template< int elno_type > + struct TGetElnoNodeData + { + typedef typename TL::TEnum2VTKArrayType< elno_type >::TResult TVTKDataArray; + typedef typename TL::TEnum2VTKBasicType< elno_type >::TResult TDataType; + TVTKDataArray *myElnoDataArray; + vtkIntArray *myElnoDataMapper; + int myElemInfo[3]; + + + //---------------------------------------------------------------------------- + TGetElnoNodeData( vtkDataArray *theElnoDataArray, + vtkIntArray *theElnoDataMapper ) + : myElnoDataArray( TVTKDataArray::SafeDownCast( theElnoDataArray ) ) + , myElnoDataMapper( theElnoDataMapper ) + {} + + + //---------------------------------------------------------------------------- + TDataType* + operator () ( vtkIdType theCellId, vtkIdType theLocalPntId ) + { + myElnoDataMapper->GetTupleValue( theCellId, myElemInfo ); + return myElnoDataArray->GetPointer( myElemInfo[ 0 ] ); + } + + + //---------------------------------------------------------------------------- + int + getNbComp() + { + myElnoDataMapper->GetTupleValue( 0, myElemInfo ); + return myElemInfo[ 1 ]; + } + }; + + + //--------------------------------------------------------------- +} + +#endif diff --git a/src/CONVERTOR/VISU_MeshValue.cxx b/src/CONVERTOR/VISU_MeshValue.cxx index ac4bc0f4..42c3eb3d 100644 --- a/src/CONVERTOR/VISU_MeshValue.cxx +++ b/src/CONVERTOR/VISU_MeshValue.cxx @@ -29,7 +29,7 @@ #include "VISU_ConvertorUtils.hxx" #include "VISU_PointCoords.hxx" -#include "VISU_TypeList.hxx" +#include "VISU_VTKTypeList.hxx" #include #include @@ -113,76 +113,6 @@ namespace VISU } - namespace TL - { - //---------------------------------------------------------------------------- - typedef TList > > > > > > > > > - TVTKBasicTypeList; - - - //---------------------------------------------------------------------------- - typedef TList > > > > > > > > > - TVTKArrayTypeList; - - - typedef TList, - TList, - TList, - TList, - TList, - TList, - TList, - TList, - TList, - TList, - TNullType> > > > > > > > > > - TVTKBasicEnumList; - - - //---------------------------------------------------------------------------- - template - struct TEnum2VTKBasicType - { - typedef typename TTypeAt >::value >::TResult TResult; - }; - - //---------------------------------------------------------------------------- - template - struct TEnum2VTKArrayType - { - typedef typename TTypeAt >::value >::TResult TResult; - }; - - //---------------------------------------------------------------------------- - template - struct TVTKBasicType2Enum - { - typedef typename TTypeAt::value >::TResult TResult; - }; - - } - - //---------------------------------------------------------------------------- template void diff --git a/src/CONVERTOR/VISU_TypeList.hxx b/src/CONVERTOR/VISU_TypeList.hxx index 1a09efc3..a2eda5b7 100644 --- a/src/CONVERTOR/VISU_TypeList.hxx +++ b/src/CONVERTOR/VISU_TypeList.hxx @@ -20,77 +20,122 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // -// File : VISU_ColoredPrs3dCache_i.hh +// File : VISU_TypeList.hxx // Author : Oleg UVAROV // Module : VISU #ifndef VISU_TypeList_HeaderFile #define VISU_TypeList_HeaderFile + +//---------------------------------------------------------------------------- namespace VISU { + //---------------------------------------------------------------------------- namespace TL { //---------------------------------------------------------------------------- - template + struct TNullType {}; + + + //---------------------------------------------------------------------------- + template < class T, class U > struct TList { typedef T THead; typedef U TTail; }; - template + template < int v > struct TInt2Type { enum { value = v }; }; - struct TNullType {}; - + //---------------------------------------------------------------------------- - template + template < class TypeList, unsigned int index > struct TTypeAt; - template - struct TTypeAt, 0> + template < class THead, class TTail > + struct TTypeAt< TList< THead, TTail >, 0 > { typedef THead TResult; }; - template - struct TTypeAt, index> + template < class THead, class TTail, unsigned int index > + struct TTypeAt< TList< THead, TTail >, index > { - typedef typename TTypeAt::TResult TResult; + typedef typename TTypeAt< TTail, index - 1 >::TResult TResult; }; + //---------------------------------------------------------------------------- - template + template < class TypeList, class T > struct TIndexOf; - template - struct TIndexOf + template < class T > + struct TIndexOf< TNullType, T > { enum { value = -1 }; }; - template - struct TIndexOf, T> + template < class T, class TTail > + struct TIndexOf< TList< T, TTail >, T > { enum { value = 0 }; }; - template - struct TIndexOf, T> + template < class THead, class TTail, class T > + struct TIndexOf< TList< THead, TTail >, T > { private: - enum { temp = TIndexOf::value }; + enum { temp = TIndexOf< TTail, T >::value }; public: enum { value = temp == -1? -1 : 1 + temp }; }; + + //---------------------------------------------------------------------------- + template + < + class T01 = TNullType, class T02 = TNullType, class T03 = TNullType, class T04 = TNullType, class T05 = TNullType, + class T06 = TNullType, class T07 = TNullType, class T08 = TNullType, class T09 = TNullType, class T10 = TNullType, + class T11 = TNullType, class T12 = TNullType, class T13 = TNullType, class T14 = TNullType, class T15 = TNullType, + class T16 = TNullType, class T17 = TNullType, class T18 = TNullType, class T19 = TNullType, class T20 = TNullType, + class T21 = TNullType, class T22 = TNullType, class T23 = TNullType, class T24 = TNullType, class T25 = TNullType, + class T26 = TNullType, class T27 = TNullType, class T28 = TNullType, class T29 = TNullType, class T30 = TNullType, + class T31 = TNullType, class T32 = TNullType, class T33 = TNullType, class T34 = TNullType, class T35 = TNullType, + class T36 = TNullType, class T37 = TNullType, class T38 = TNullType, class T39 = TNullType, class T40 = TNullType + > + struct TSequence + { + private: + typedef typename TSequence< T02, T03, T04, T05, T06, T07, T08, T09, T10, + T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, + T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, + T31, T32, T33, T34, T35, T36, T37, T38, T39, T40 + >::TResult + TailResult; + public: + typedef TList< T01, TailResult > TResult; + }; + + + //---------------------------------------------------------------------------- + template<> + struct TSequence<> + { + typedef TNullType TResult; + }; + + //---------------------------------------------------------------------------- } + + + //---------------------------------------------------------------------------- } #endif diff --git a/src/CONVERTOR/VISU_VTKTypeList.hxx b/src/CONVERTOR/VISU_VTKTypeList.hxx new file mode 100644 index 00000000..f210f652 --- /dev/null +++ b/src/CONVERTOR/VISU_VTKTypeList.hxx @@ -0,0 +1,120 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// 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 +// +// +// File : VISU_VTKTypeList.hxx +// Author : Oleg UVAROV +// Module : VISU + +#ifndef VISU_VTKTypeList_HeaderFile +#define VISU_VTKTypeList_HeaderFile + +#include "VISU_TypeList.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +//---------------------------------------------------------------------------- +namespace VISU +{ + //---------------------------------------------------------------------------- + namespace TL + { + //---------------------------------------------------------------------------- + typedef TSequence< char, + unsigned char, + short, + unsigned short, + int, + unsigned int, + long, + unsigned long, + float, + double >::TResult TVTKBasicTypeList; + + + //---------------------------------------------------------------------------- + typedef TSequence< vtkCharArray, + vtkUnsignedCharArray, + vtkShortArray, + vtkUnsignedShortArray, + vtkIntArray, + vtkUnsignedIntArray, + vtkLongArray, + vtkUnsignedLongArray, + vtkFloatArray, + vtkDoubleArray >::TResult TVTKArrayTypeList; + + + //---------------------------------------------------------------------------- + typedef TSequence< TInt2Type< VTK_CHAR >, + TInt2Type< VTK_UNSIGNED_CHAR >, + TInt2Type< VTK_SHORT >, + TInt2Type< VTK_UNSIGNED_SHORT >, + TInt2Type< VTK_INT >, + TInt2Type< VTK_UNSIGNED_INT >, + TInt2Type< VTK_LONG >, + TInt2Type< VTK_UNSIGNED_LONG >, + TInt2Type< VTK_FLOAT >, + TInt2Type< VTK_DOUBLE > >::TResult TVTKBasicEnumList; + + + //---------------------------------------------------------------------------- + template< unsigned int type_enum > + struct TEnum2VTKBasicType + { + typedef typename TTypeAt< TVTKBasicTypeList, TIndexOf< TVTKBasicEnumList, TInt2Type< type_enum > >::value >::TResult TResult; + }; + + + //---------------------------------------------------------------------------- + template< unsigned int type_enum > + struct TEnum2VTKArrayType + { + typedef typename TTypeAt< TVTKArrayTypeList, TIndexOf< TVTKBasicEnumList, TInt2Type< type_enum > >::value >::TResult TResult; + }; + + + //---------------------------------------------------------------------------- + template< class T > + struct TVTKBasicType2Enum + { + typedef typename TTypeAt< TVTKBasicEnumList, TIndexOf< TVTKBasicTypeList, T >::value >::TResult TResult; + }; + + + //---------------------------------------------------------------------------- + } + + + //---------------------------------------------------------------------------- +} + +#endif diff --git a/src/PIPELINE/Makefile.am b/src/PIPELINE/Makefile.am index 7a26914c..a686ea8c 100644 --- a/src/PIPELINE/Makefile.am +++ b/src/PIPELINE/Makefile.am @@ -65,10 +65,11 @@ salomeinclude_HEADERS= \ VISU_WidgetCtrl.hxx \ VISU_ScalarMapOnDeformedShapePL.hxx \ VISU_OpenGLElnoMapper.hxx \ - VISUPipeline.hxx \ + VISU_ElnoWarpVector.cxx \ VISU_ElnoGeometryFilter.hxx \ VISU_ElnoMapperHolder.hxx \ - VISU_ElnoScalarMapPL.hxx + VISU_ElnoScalarMapPL.hxx \ + VISUPipeline.hxx dist_libVisuPipeLine_la_SOURCES= \ VISU_MapperHolder.cxx \ @@ -109,7 +110,8 @@ dist_libVisuPipeLine_la_SOURCES= \ VISU_OpenGLElnoMapper.cxx \ VISU_ElnoGeometryFilter.cxx \ VISU_ElnoMapperHolder.cxx \ - VISU_ElnoScalarMapPL.cxx + VISU_ElnoScalarMapPL.cxx \ + VISU_ElnoWarpVector.cxx libVisuPipeLine_la_CPPFLAGS= \ diff --git a/src/PIPELINE/VISUPipeLine.cxx b/src/PIPELINE/VISUPipeLine.cxx index befed7be..d660d7b4 100644 --- a/src/PIPELINE/VISUPipeLine.cxx +++ b/src/PIPELINE/VISUPipeLine.cxx @@ -38,12 +38,15 @@ #include "VISU_StreamLinesPL.hxx" #include "VISU_GaussPointsPL.hxx" #include "VISU_ScalarMapOnDeformedShapePL.hxx" -#include "VISU_OpenGLElnoMapper.hxx" #include "VISU_Plot3DPL.hxx" + #include "VISU_ScalarBarActor.hxx" #include "VISU_OpenGLPointSpriteMapper.hxx" #include "VTKViewer_GeometryFilter.h" + +#include "VISU_ElnoWarpVector.hxx" #include "VISU_ElnoGeometryFilter.hxx" +#include "VISU_OpenGLElnoMapper.hxx" // VTK includes #include @@ -231,15 +234,24 @@ main(int argc, char** argv) anEntity, theFieldName, aTimeStamp); + + VISU_ElnoWarpVector* anElnoWarpVector = VISU_ElnoWarpVector::New(); + anElnoWarpVector->SetInput( anUnstructuredGridIDMapper->GetUnstructuredGridOutput() ); VISU_ElnoGeometryFilter *aGeometryFilter = VISU_ElnoGeometryFilter::New(); aGeometryFilter->SetScalarMode(aComponentNumber); - aGeometryFilter->SetInput( anUnstructuredGridIDMapper->GetUnstructuredGridOutput() ); - aGeometryFilter->Update(); - + aGeometryFilter->SetInput( anElnoWarpVector->GetOutput() ); + + // To calculate and apply default scale factor + { + vtkFloatingPointType aScale = VISU_DeformedShapePL::GetScaleFactor( anElnoWarpVector->GetOutput() ); + vtkFloatingPointType* aRange = aGeometryFilter->GetRange(); + aScale /= aRange[1]; + anElnoWarpVector->SetScaleFactor( aScale ); + } + VISU_OpenGLElnoMapper* aMapper = VISU_OpenGLElnoMapper::New(); - aMapper->SetInput( aGeometryFilter->GetOutput() ); - + aMapper->SetInput( aGeometryFilter->GetOutput() ); VISU_LookupTable* aMapperTable( VISU_LookupTable::New() ); aMapperTable->SetHueRange(0.667, 0.0); diff --git a/src/PIPELINE/VISU_ElnoGeometryFilter.cxx b/src/PIPELINE/VISU_ElnoGeometryFilter.cxx index dc8c48f5..8f05a18d 100755 --- a/src/PIPELINE/VISU_ElnoGeometryFilter.cxx +++ b/src/PIPELINE/VISU_ElnoGeometryFilter.cxx @@ -54,8 +54,8 @@ VISU_ElnoGeometryFilter::VISU_ElnoGeometryFilter() myElnoData = NULL; myElnoMapper = NULL; myScalarMode = 0; - myMinMax[0] = 0.; - myMinMax[1] = 1.; + myMinMax[0] = -VTK_DOUBLE_MAX; + myMinMax[1] = VTK_DOUBLE_MAX; } //---------------------------------------------------------------------------------------------- VISU_ElnoGeometryFilter::~VISU_ElnoGeometryFilter() @@ -661,6 +661,8 @@ void VISU_ElnoGeometryFilter::UnstructuredGridExecute(vtkDataSet *dataSetInput, Strips->Delete(); //Compute Min and Max + myMinMax[0] = -VTK_DOUBLE_MAX; + myMinMax[1] = VTK_DOUBLE_MAX; switch(myElnoData->GetDataType()){ vtkTemplateMacro3(BuildMinMax, static_cast(aElnoScalars->GetVoidPointer(0)), @@ -702,6 +704,7 @@ vtkIdType VISU_ElnoGeometryFilter::GetScalarMode() const{ //---------------------------------------------------------------------------------------------- double* VISU_ElnoGeometryFilter::GetRange(){ + this->Update(); // To perform automatic update if neccesary return myMinMax; } diff --git a/src/PIPELINE/VISU_ElnoWarpVector.cxx b/src/PIPELINE/VISU_ElnoWarpVector.cxx new file mode 100644 index 00000000..78825732 --- /dev/null +++ b/src/PIPELINE/VISU_ElnoWarpVector.cxx @@ -0,0 +1,240 @@ +// 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_ElnoWarpVector.hxx" +#include "VISU_PipeLineUtils.hxx" +#include "VISU_ElnoMeshValue.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro( VISU_ElnoWarpVector ); + + +//---------------------------------------------------------------------------- +VISU_ElnoWarpVector::VISU_ElnoWarpVector() +{ + this->myScaleFactor = 1.0; + + this->SetInputArrayToProcess( 0, // idx + 0, // port + 0, // connection + vtkDataObject::FIELD_ASSOCIATION_CELLS, // field association + "ELNO_FIELD" ); // name + + this->SetInputArrayToProcess( 1, // idx + 0, // port + 0, // connection + vtkDataObject::FIELD_ASSOCIATION_CELLS, // field association + "ELNO_COMPONENT_MAPPER" ); // name +} + + +//---------------------------------------------------------------------------- +VISU_ElnoWarpVector::~VISU_ElnoWarpVector() +{} + + +//---------------------------------------------------------------------------- +void VISU_ElnoWarpVector::SetScaleFactor( vtkFloatingPointType theValue ) +{ + if ( VISU::CheckIsSameValue( theValue, this->myScaleFactor ) ) + return; + + this->myScaleFactor = theValue; + this->Modified(); +} + + +//---------------------------------------------------------------------------- +vtkFloatingPointType VISU_ElnoWarpVector::GetScaleFactor() +{ + return this->myScaleFactor; +} + + +//---------------------------------------------------------------------------- +namespace +{ + template < int points_type, int elno_type > + int ElnoWarpVectorExecute2( VISU_ElnoWarpVector *self, + vtkUnstructuredGrid *theInput, + vtkUnstructuredGrid *theOutput, + vtkDataArray *theElnoDataArray, + vtkIntArray *theElnoDataMapper ) + { + VISU::TGetElnoNodeData< elno_type > aGetElnoNodeData( theElnoDataArray, theElnoDataMapper ); + typedef typename VISU::TL::TEnum2VTKBasicType< elno_type >::TResult TElnoDataType; + + TElnoDataType aScaleFactor = TElnoDataType( self->GetScaleFactor() ); + vtkIdType aNbDim = std::min( 3, aGetElnoNodeData.getNbComp() ); + + vtkCellArray *aConnectivity = vtkCellArray::New(); + aConnectivity->DeepCopy( theInput->GetCells() ); + + vtkPoints *anInputPoints = theInput->GetPoints(); + vtkPoints *aPoints = anInputPoints->New( anInputPoints->GetDataType() ); + vtkIdType aNbPoints = aConnectivity->GetNumberOfConnectivityEntries(); + aPoints->SetNumberOfPoints( aNbPoints ); + + typedef typename VISU::TL::TEnum2VTKArrayType< points_type >::TResult TVTKDataArray; + typedef typename VISU::TL::TEnum2VTKBasicType< points_type >::TResult TPointsDataType; + TVTKDataArray* anInputPointsArray = TVTKDataArray::SafeDownCast( anInputPoints->GetData() ); + TVTKDataArray* anOutputPointsArray = TVTKDataArray::SafeDownCast( aPoints->GetData() ); + + vtkPointData *anInputPointData = theInput->GetPointData(); + vtkPointData *aPointData = theOutput->GetPointData(); + aPointData->Allocate( aNbPoints ); + + aConnectivity->InitTraversal(); + vtkIdType aNbPts = 0, *aPts = 0; + for ( vtkIdType aCellId = 0; aConnectivity->GetNextCell( aNbPts, aPts ); aCellId++ ) { + for ( vtkIdType aPntId = 0; aPntId < aNbPts; aPntId++ ) { + TPointsDataType aCoords[ 3 ]; + vtkIdType aCurrentPntId = aPts[ aPntId ]; + anInputPointsArray->GetTupleValue( aCurrentPntId, aCoords ); + TElnoDataType* anElnoData = aGetElnoNodeData( aCellId, aCurrentPntId ); + + for ( vtkIdType aDimId = 0; aDimId < aNbDim; aDimId++ ) + aCoords[ aDimId ] += TPointsDataType( aScaleFactor * anElnoData[ aDimId ] ); + + aPts[ aPntId ] = anOutputPointsArray->InsertNextTupleValue( aCoords ); + aPointData->CopyData( anInputPointData, aCurrentPntId, aPts[ aPntId ] ); + } + } + + theOutput->SetPoints( aPoints ); + + theOutput->SetCells( theInput->GetCellTypesArray(), + theInput->GetCellLocationsArray(), + aConnectivity ); + + theOutput->GetCellData()->PassData( theInput->GetCellData() ); + + return 1; + } + + + //---------------------------------------------------------------------------- + template < int points_type > + int ElnoWarpVectorExecute( VISU_ElnoWarpVector *self, + vtkUnstructuredGrid *theInput, + vtkUnstructuredGrid *theOutput, + vtkDataArray *theElnoDataArray, + vtkIntArray *theElnoDataMapper ) + { + switch( theElnoDataArray->GetDataType() ){ + case VTK_DOUBLE: + return ElnoWarpVectorExecute2< points_type, VTK_DOUBLE >( self, + theInput, + theOutput, + theElnoDataArray, + theElnoDataMapper ); + case VTK_FLOAT: + return ElnoWarpVectorExecute2< points_type, VTK_FLOAT >( self, + theInput, + theOutput, + theElnoDataArray, + theElnoDataMapper ); + case VTK_INT: + return ElnoWarpVectorExecute2< points_type, VTK_INT >( self, + theInput, + theOutput, + theElnoDataArray, + theElnoDataMapper ); + case VTK_LONG: + return ElnoWarpVectorExecute2< points_type, VTK_LONG >( self, + theInput, + theOutput, + theElnoDataArray, + theElnoDataMapper ); + default: + break; + } + + return 0; + } + + + //---------------------------------------------------------------------------- +} + + +//---------------------------------------------------------------------------- +int VISU_ElnoWarpVector::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 + vtkUnstructuredGrid *anInput = + vtkUnstructuredGrid::SafeDownCast( inInfo->Get( vtkDataObject::DATA_OBJECT() ) ); + vtkUnstructuredGrid *anOutput = + vtkUnstructuredGrid::SafeDownCast( outInfo->Get( vtkDataObject::DATA_OBJECT() ) ); + + vtkDataArray *anElnoDataArray = this->GetInputArrayToProcess( 0, inputVector ); + vtkIntArray *anElnoDataMapper = + vtkIntArray::SafeDownCast( this->GetInputArrayToProcess( 1, inputVector ) ); + + vtkPoints *aPoints = anInput->GetPoints(); + switch( aPoints->GetDataType() ){ + case VTK_DOUBLE: + return ::ElnoWarpVectorExecute< VTK_DOUBLE >( this, + anInput, + anOutput, + anElnoDataArray, + anElnoDataMapper ); + case VTK_FLOAT: + return ::ElnoWarpVectorExecute< VTK_FLOAT >( this, + anInput, + anOutput, + anElnoDataArray, + anElnoDataMapper ); + case VTK_INT: + return ::ElnoWarpVectorExecute< VTK_INT >( this, + anInput, + anOutput, + anElnoDataArray, + anElnoDataMapper ); + case VTK_LONG: + return ::ElnoWarpVectorExecute< VTK_LONG >( this, + anInput, + anOutput, + anElnoDataArray, + anElnoDataMapper ); + default: + break; + } + + return 0; +} + + +//---------------------------------------------------------------------------- diff --git a/src/PIPELINE/VISU_ElnoWarpVector.hxx b/src/PIPELINE/VISU_ElnoWarpVector.hxx new file mode 100644 index 00000000..3047a726 --- /dev/null +++ b/src/PIPELINE/VISU_ElnoWarpVector.hxx @@ -0,0 +1,48 @@ +// 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 + +#ifndef VISU_ElnoWarpVector_H +#define VISU_ElnoWarpVector_H + +#include + +class VISU_ElnoWarpVector : public vtkUnstructuredGridAlgorithm +{ +public: + typedef vtkUnstructuredGridAlgorithm Superclass; + + static VISU_ElnoWarpVector *New(); + + //! Specify value to scale displacement. + void SetScaleFactor( vtkFloatingPointType theValue ); + vtkFloatingPointType GetScaleFactor(); + +protected: + VISU_ElnoWarpVector(); + ~VISU_ElnoWarpVector(); + + int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); + vtkFloatingPointType myScaleFactor; + +private: + VISU_ElnoWarpVector(const VISU_ElnoWarpVector&); // Not implemented. + void operator=(const VISU_ElnoWarpVector&); // Not implemented. +}; + +#endif