X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FMesh.cxx;h=2866967ae73376e7a4a508aa911ab5a1274e3f0b;hb=dba64a6906e88d6023b2e6c9632da9fd41bfeb53;hp=8a184c92471917b24ec2747856b51fd0dfc8362d;hpb=1740a32cbb99c4abd76ee0c0e5e45e0df3a8e800;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/Mesh.cxx b/lib/cpPlugins/Interface/Mesh.cxx index 8a184c9..2866967 100644 --- a/lib/cpPlugins/Interface/Mesh.cxx +++ b/lib/cpPlugins/Interface/Mesh.cxx @@ -1,72 +1,76 @@ #include -#include - -#include -#include +#include // ------------------------------------------------------------------------- -cpPlugins::Interface::Mesh:: -Mesh( ) - : Superclass( ), - m_Mapper( NULL ) +void cpPlugins::Interface::Mesh:: +SetVTK( vtkObject* mesh ) { + if( dynamic_cast< vtkPolyData* >( mesh ) != NULL ) + this->m_VTKObject = mesh; + else + this->m_VTKObject = NULL; + this->m_Mapper = NULL; + this->m_Actor = NULL; + this->Modified( ); } // ------------------------------------------------------------------------- -cpPlugins::Interface::Mesh:: -~Mesh( ) +void cpPlugins::Interface::Mesh:: +CreateVTKActor( ) { - if( this->m_Mapper != NULL ) this->m_Mapper->Delete( ); + vtkPolyData* pd = this->GetVTK< vtkPolyData >( ); + if( + pd != NULL && + ( + this->m_Mapper.GetPointer( ) == NULL || + this->m_Actor.GetPointer( ) == NULL + ) + ) + { + double range[ 2 ]; + pd->GetScalarRange( range ); + + this->m_Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); + this->m_Actor = vtkSmartPointer< vtkActor >::New( ); + this->m_Mapper->SetInputData( pd ); + this->m_Mapper->UseLookupTableScalarRangeOff( ); + this->m_Mapper->SetScalarRange( + range[ 0 ], ( ( range[ 1 ] - range[ 0 ] ) * 0.75 ) + range[ 0 ] + ); + this->m_Actor->SetMapper( this->m_Mapper ); + this->Modified( ); + + } // fi } // ------------------------------------------------------------------------- -std::string cpPlugins::Interface::Mesh:: -GetClassName( ) const +vtkActor* cpPlugins::Interface::Mesh:: +GetVTKActor( ) { - return( "cpPlugins::Interface::Mesh" ); + return( this->m_Actor ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::Mesh:: -SetDataObject( itk::DataObject* dobj ) +const vtkActor* cpPlugins::Interface::Mesh:: +GetVTKActor( ) const { - this->Superclass::SetDataObject( dobj ); - - // WARNING: Only 2 and 3 dimensions at this moment - using namespace cpPlugins::Extensions; - typedef DataStructures::QuadEdgeMesh< float, 2 > _TF2; - typedef DataStructures::QuadEdgeMesh< double, 2 > _TD2; - typedef DataStructures::QuadEdgeMesh< float, 3 > _TF3; - typedef DataStructures::QuadEdgeMesh< double, 3 > _TD3; - - if ( dynamic_cast< _TF2* >( dobj ) ) this->_Map< _TF2 >( ); - else if( dynamic_cast< _TD2* >( dobj ) ) this->_Map< _TD2 >( ); - else if( dynamic_cast< _TF3* >( dobj ) ) this->_Map< _TF3 >( ); - else if( dynamic_cast< _TD3* >( dobj ) ) this->_Map< _TD3 >( ); + return( this->m_Actor ); } // ------------------------------------------------------------------------- -vtkMapper* cpPlugins::Interface::Mesh:: -GetVTKMapper( ) const +cpPlugins::Interface::Mesh:: +Mesh( ) + : Superclass( ), + m_Mapper( NULL ), + m_Actor( NULL ) { - return( this->m_Mapper ); } // ------------------------------------------------------------------------- -template< class M > -void cpPlugins::Interface::Mesh:: -_Map( ) +cpPlugins::Interface::Mesh:: +~Mesh( ) { - typedef - cpPlugins::Extensions::Visualization::OpenGLMeshMapper< M > - _TMapper; - - if( this->m_Mapper != NULL ) this->m_Mapper->Delete( ); - M* mesh = dynamic_cast< M* >( this->Superclass::GetDataObject( ) ); - _TMapper* mapper = _TMapper::New( ); - mapper->SetInputData( mesh ); - this->m_Mapper = mapper; } // eof - $RCSfile$