From: apo Date: Thu, 1 May 2008 15:30:53 +0000 (+0000) Subject: To introduce common purpose ELNO related VTK filters X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=34ce3077b23dccce09dee7a5210128ccbac79504;p=modules%2Fvisu.git To introduce common purpose ELNO related VTK filters --- diff --git a/src/PIPELINE/Makefile.am b/src/PIPELINE/Makefile.am index a686ea8c..7b51bbe4 100644 --- a/src/PIPELINE/Makefile.am +++ b/src/PIPELINE/Makefile.am @@ -64,10 +64,6 @@ salomeinclude_HEADERS= \ VISU_SphereWidget.hxx \ VISU_WidgetCtrl.hxx \ VISU_ScalarMapOnDeformedShapePL.hxx \ - VISU_OpenGLElnoMapper.hxx \ - VISU_ElnoWarpVector.cxx \ - VISU_ElnoGeometryFilter.hxx \ - VISU_ElnoMapperHolder.hxx \ VISU_ElnoScalarMapPL.hxx \ VISUPipeline.hxx @@ -109,6 +105,8 @@ dist_libVisuPipeLine_la_SOURCES= \ VISU_ScalarMapOnDeformedShapePL.cxx \ VISU_OpenGLElnoMapper.cxx \ VISU_ElnoGeometryFilter.cxx \ + VISU_ElnoDisassembleFilter.cxx \ + VISU_ElnoExtractScalars.cxx \ VISU_ElnoMapperHolder.cxx \ VISU_ElnoScalarMapPL.cxx \ VISU_ElnoWarpVector.cxx diff --git a/src/PIPELINE/VISUPipeLine.cxx b/src/PIPELINE/VISUPipeLine.cxx index f072a6a6..79d4cae4 100644 --- a/src/PIPELINE/VISUPipeLine.cxx +++ b/src/PIPELINE/VISUPipeLine.cxx @@ -48,6 +48,9 @@ #include "VISU_ElnoGeometryFilter.hxx" #include "VISU_OpenGLElnoMapper.hxx" +#include "VISU_ElnoDisassembleFilter.hxx" +#include "VISU_ElnoExtractScalars.hxx" + #include #include @@ -245,6 +248,14 @@ main(int argc, char** argv) vtkUnstructuredGrid* anUnstructuredGrid = anUnstructuredGridIDMapper->GetUnstructuredGridOutput(); VISU::WriteToFile( anUnstructuredGrid, "/data/apo/elno_from_id_mapper.vtk" ); + VISU_ElnoDisassembleFilter* aDisassembleFilter = VISU_ElnoDisassembleFilter::New(); + aDisassembleFilter->SetInput( anUnstructuredGrid ); + VISU::WriteToFile( aDisassembleFilter->GetOutput(), "/data/apo/elno_from_disassemble.vtk" ); + + VISU_ElnoExtractScalars* anExtractScalars = VISU_ElnoExtractScalars::New(); + anExtractScalars->SetInput( aDisassembleFilter->GetOutput() ); + VISU::WriteToFile( anExtractScalars->GetOutput(), "/data/apo/elno_from_scalars.vtk" ); + vtkCutter *aCutter = vtkCutter::New(); aCutter->SetInput( anUnstructuredGrid ); diff --git a/src/PIPELINE/VISU_ElnoDisassembleFilter.cxx b/src/PIPELINE/VISU_ElnoDisassembleFilter.cxx new file mode 100644 index 00000000..f103f634 --- /dev/null +++ b/src/PIPELINE/VISU_ElnoDisassembleFilter.cxx @@ -0,0 +1,191 @@ +// 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_ElnoDisassembleFilter.hxx" +#include "VISU_PipeLineUtils.hxx" +#include "VISU_ElnoMeshValue.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro( VISU_ElnoDisassembleFilter ); + + +//---------------------------------------------------------------------------- +VISU_ElnoDisassembleFilter::VISU_ElnoDisassembleFilter() +{ + 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_ElnoDisassembleFilter::~VISU_ElnoDisassembleFilter() +{} + + +//---------------------------------------------------------------------------- +namespace +{ + template < int points_type, int elno_type > + int Execute2( vtkUnstructuredGrid *theInput, + vtkUnstructuredGrid *theOutput, + vtkDataArray *theElnoDataArray, + vtkDataArray *theElnoDataMapper ) + { + 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_POINTS_DATA" ); + + 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 ); + aPts[ aPntId ] = anOutputPointsArray->InsertNextTupleValue( aCoords ); + + aPointData->CopyData( anInputPointData, aCurrentPntId, aPts[ aPntId ] ); + + TElnoDataType* anElnoData = aGetElnoNodeData( aCellId, aPntId ); + anElnoPointsDataArray->SetTupleValue( aPts[ aPntId ], anElnoData ); + } + } + + theOutput->SetPoints( aPoints ); + + theOutput->SetCells( theInput->GetCellTypesArray(), + theInput->GetCellLocationsArray(), + aConnectivity ); + + theOutput->GetCellData()->PassData( theInput->GetCellData() ); + + aPointData->AddArray( anElnoPointsDataArray ); + anElnoPointsDataArray->Delete(); + + return 1; + } + + + //---------------------------------------------------------------------------- + template < int points_type > + int Execute( vtkUnstructuredGrid *theInput, + vtkUnstructuredGrid *theOutput, + vtkDataArray *theElnoDataArray, + vtkDataArray *theElnoDataMapper ) + { + switch( theElnoDataArray->GetDataType() ){ + case VTK_DOUBLE: + return Execute2< points_type, VTK_DOUBLE >( theInput, theOutput, theElnoDataArray, theElnoDataMapper ); + case VTK_FLOAT: + return Execute2< points_type, VTK_FLOAT >( theInput, theOutput, theElnoDataArray, theElnoDataMapper ); + case VTK_INT: + return Execute2< points_type, VTK_INT >( theInput, theOutput, theElnoDataArray, theElnoDataMapper ); + case VTK_LONG: + return Execute2< points_type, VTK_LONG >( theInput, theOutput, theElnoDataArray, theElnoDataMapper ); + default: + break; + } + + return 0; + } + + + //---------------------------------------------------------------------------- +} + + +//---------------------------------------------------------------------------- +int VISU_ElnoDisassembleFilter::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 ); + vtkDataArray *anElnoDataMapper = this->GetInputArrayToProcess( 1, inputVector ); + + vtkPoints *aPoints = anInput->GetPoints(); + switch( aPoints->GetDataType() ){ + case VTK_DOUBLE: + return ::Execute< VTK_DOUBLE >( anInput, anOutput, anElnoDataArray, anElnoDataMapper ); + case VTK_FLOAT: + return ::Execute< VTK_FLOAT >( anInput, anOutput, anElnoDataArray, anElnoDataMapper ); + case VTK_INT: + return ::Execute< VTK_INT >( anInput, anOutput, anElnoDataArray, anElnoDataMapper ); + case VTK_LONG: + return ::Execute< VTK_LONG >( anInput, anOutput, anElnoDataArray, anElnoDataMapper ); + default: + break; + } + + return 0; +} + + +//---------------------------------------------------------------------------- diff --git a/src/PIPELINE/VISU_ElnoDisassembleFilter.hxx b/src/PIPELINE/VISU_ElnoDisassembleFilter.hxx new file mode 100644 index 00000000..730f3c55 --- /dev/null +++ b/src/PIPELINE/VISU_ElnoDisassembleFilter.hxx @@ -0,0 +1,43 @@ +// 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_ElnoDisassembleFilter_H +#define VISU_ElnoDisassembleFilter_H + +#include + +class VISU_ElnoDisassembleFilter : public vtkUnstructuredGridAlgorithm +{ +public: + typedef vtkUnstructuredGridAlgorithm Superclass; + + static VISU_ElnoDisassembleFilter *New(); + +protected: + VISU_ElnoDisassembleFilter(); + ~VISU_ElnoDisassembleFilter(); + + int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); + +private: + VISU_ElnoDisassembleFilter(const VISU_ElnoDisassembleFilter&); // Not implemented. + void operator=(const VISU_ElnoDisassembleFilter&); // Not implemented. +}; + +#endif diff --git a/src/PIPELINE/VISU_ElnoExtractScalars.cxx b/src/PIPELINE/VISU_ElnoExtractScalars.cxx new file mode 100644 index 00000000..6af5b7b9 --- /dev/null +++ b/src/PIPELINE/VISU_ElnoExtractScalars.cxx @@ -0,0 +1,146 @@ +// 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_ElnoExtractScalars.hxx" +#include "VISU_PipeLineUtils.hxx" +#include "VISU_ElnoMeshValue.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro( VISU_ElnoExtractScalars ); + + +//---------------------------------------------------------------------------- +VISU_ElnoExtractScalars::VISU_ElnoExtractScalars() +{ + this->SetInputArrayToProcess( 0, // idx + 0, // port + 0, // connection + vtkDataObject::FIELD_ASSOCIATION_POINTS, // field association + "ELNO_POINTS_DATA" ); // name + + myScalarMode = 1; +} + + +//---------------------------------------------------------------------------- +VISU_ElnoExtractScalars::~VISU_ElnoExtractScalars() +{} + + +//---------------------------------------------------------------------------- +namespace +{ + template < int elno_type > + int Execute( vtkUnstructuredGrid *theInput, + vtkUnstructuredGrid *theOutput, + vtkDataArray *theElnoPointsDataArray, + vtkIdType theScalarMode ) + { + typedef typename VISU::TL::TEnum2VTKArrayType< elno_type >::TResult TElnoDataArray; + typedef typename VISU::TL::TEnum2VTKBasicType< elno_type >::TResult TElnoDataType; + + TElnoDataArray* anElnoPointsDataArray = TElnoDataArray::SafeDownCast( theElnoPointsDataArray ); + vtkIdType aNbComp = anElnoPointsDataArray->GetNumberOfComponents(); + vtkIdType aNbTuples = anElnoPointsDataArray->GetNumberOfTuples(); + + TElnoDataArray* anElnoPointScalars = TElnoDataArray::New(); + anElnoPointScalars->SetNumberOfComponents( 1 ); + anElnoPointScalars->SetNumberOfTuples( aNbTuples ); + anElnoPointScalars->SetName( "ELNO_POINT_SCALARS" ); + + std::vector< TElnoDataType > anElnoDataValues( aNbComp ); // To reserve a temproary value holder + vtkIdType aNbDim = std::min( 3, aNbComp ); + + for ( vtkIdType aTupleId = 0; aTupleId < aNbTuples; aTupleId++ ) { + anElnoPointsDataArray->GetTupleValue( aTupleId, &anElnoDataValues[ 0 ] ); + + TElnoDataType anElnoValue = 0; + if ( theScalarMode > 0 ) { + anElnoValue = anElnoDataValues[ theScalarMode - 1 ]; + } else { + for ( vtkIdType aDimId = 0; aDimId < aNbDim; aDimId++ ) + anElnoValue += anElnoDataValues[ aDimId ] * anElnoDataValues[ aDimId ]; + + anElnoValue = TElnoDataType( sqrt( anElnoValue ) ); + } + + anElnoPointScalars->SetTupleValue( aTupleId, &anElnoValue ); + } + + theOutput->CopyStructure( theInput ); + + theOutput->GetCellData()->PassData( theInput->GetCellData() ); + theOutput->GetPointData()->PassData( theInput->GetPointData() ); + + theOutput->GetPointData()->SetScalars( anElnoPointScalars ); + anElnoPointScalars->Delete(); + + return 1; + } + + + //---------------------------------------------------------------------------- +} + + +//---------------------------------------------------------------------------- +int VISU_ElnoExtractScalars::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 *anElnoPointsDataArray = this->GetInputArrayToProcess( 0, inputVector ); + + switch( anElnoPointsDataArray->GetDataType() ){ + case VTK_DOUBLE: + return ::Execute< VTK_DOUBLE >( anInput, anOutput, anElnoPointsDataArray, myScalarMode ); + case VTK_FLOAT: + return ::Execute< VTK_FLOAT >( anInput, anOutput, anElnoPointsDataArray, myScalarMode ); + case VTK_INT: + return ::Execute< VTK_INT >( anInput, anOutput, anElnoPointsDataArray, myScalarMode ); + case VTK_LONG: + return ::Execute< VTK_LONG >( anInput, anOutput, anElnoPointsDataArray, myScalarMode ); + default: + break; + } + + return 0; +} + + +//---------------------------------------------------------------------------- diff --git a/src/PIPELINE/VISU_ElnoExtractScalars.hxx b/src/PIPELINE/VISU_ElnoExtractScalars.hxx new file mode 100644 index 00000000..fba4ac27 --- /dev/null +++ b/src/PIPELINE/VISU_ElnoExtractScalars.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_ElnoExtractScalars_H +#define VISU_ElnoExtractScalars_H + +#include + +class VISU_ElnoExtractScalars : public vtkUnstructuredGridAlgorithm +{ +public: + typedef vtkUnstructuredGridAlgorithm Superclass; + + static VISU_ElnoExtractScalars *New(); + + //! Specify value to scale displacement. + void SetScalarMode( vtkIdType theValue ); + vtkIdType GetScalarMode(); + +protected: + VISU_ElnoExtractScalars(); + ~VISU_ElnoExtractScalars(); + + int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); + vtkIdType myScalarMode; + +private: + VISU_ElnoExtractScalars(const VISU_ElnoExtractScalars&); // Not implemented. + void operator=(const VISU_ElnoExtractScalars&); // Not implemented. +}; + +#endif diff --git a/src/PIPELINE/VISU_ElnoGeometryFilter.cxx b/src/PIPELINE/VISU_ElnoGeometryFilter.cxx index b2ad9009..a15bc29c 100755 --- a/src/PIPELINE/VISU_ElnoGeometryFilter.cxx +++ b/src/PIPELINE/VISU_ElnoGeometryFilter.cxx @@ -151,8 +151,7 @@ namespace input->GetCellPoints( aCellId, aNbPts, aPts ); for ( vtkIdType aPntId = 0; aPntId < aNbPts; aPntId++ ) { - vtkIdType aCurrentPntId = aPts[ aPntId ]; - TElnoDataType* anElnoData = aGetElnoNodeData( aCellId, aCurrentPntId ); + TElnoDataType* anElnoData = aGetElnoNodeData( aCellId, aPntId ); TElnoDataType anElnoValue = 0; if ( theScalarMode > 0 ) { diff --git a/src/PIPELINE/VISU_ElnoWarpVector.cxx b/src/PIPELINE/VISU_ElnoWarpVector.cxx index f47cf5d5..eda7deaf 100644 --- a/src/PIPELINE/VISU_ElnoWarpVector.cxx +++ b/src/PIPELINE/VISU_ElnoWarpVector.cxx @@ -98,8 +98,9 @@ namespace vtkPoints *anInputPoints = theInput->GetPoints(); vtkPoints *aPoints = anInputPoints->New( anInputPoints->GetDataType() ); - vtkIdType aNbPoints = aConnectivity->GetNumberOfConnectivityEntries(); - aPoints->SetNumberOfPoints( aNbPoints ); + vtkIdType aNbCells = aConnectivity->GetNumberOfCells(); + vtkIdType aNbPoints = aConnectivity->GetNumberOfConnectivityEntries() - aNbCells; + aPoints->Allocate( aNbPoints ); typedef typename VISU::TL::TEnum2VTKArrayType< points_type >::TResult TVTKDataArray; typedef typename VISU::TL::TEnum2VTKBasicType< points_type >::TResult TPointsDataType; @@ -117,7 +118,7 @@ namespace TPointsDataType aCoords[ 3 ]; vtkIdType aCurrentPntId = aPts[ aPntId ]; anInputPointsArray->GetTupleValue( aCurrentPntId, aCoords ); - TElnoDataType* anElnoData = aGetElnoNodeData( aCellId, aCurrentPntId ); + TElnoDataType* anElnoData = aGetElnoNodeData( aCellId, aPntId ); for ( vtkIdType aDimId = 0; aDimId < aNbDim; aDimId++ ) aCoords[ aDimId ] += TPointsDataType( aScaleFactor * anElnoData[ aDimId ] );