From: Leonardo Florez-Valencia Date: Fri, 27 May 2016 14:52:30 +0000 (-0500) Subject: Ortho normal bases added. X-Git-Tag: v0.1~155 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=34c0133b046bbde76d6c82458d6637072bd20052;p=cpPlugins.git Ortho normal bases added. --- diff --git a/lib/cpPlugins/Mesh.cxx b/lib/cpPlugins/Mesh.cxx index 2854840..f0e29f5 100644 --- a/lib/cpPlugins/Mesh.cxx +++ b/lib/cpPlugins/Mesh.cxx @@ -5,7 +5,14 @@ #include #include +#include +#include #include +#include +#include +#include + +#define cpPlugins_Mesh_MAX_POLYS 65535 // ------------------------------------------------------------------------- void cpPlugins::Mesh:: @@ -129,14 +136,40 @@ _CreateVTKActor( ) const const_cast< vtkPolyData* >( this->GetVTK< vtkPolyData >( ) ); if( mesh != NULL ) { - std::cout << "Mesh: " << mesh << std::endl; - /* TODO - vtkImageSliceMapper* mapper = vtkImageSliceMapper::New( ); - vtkImageActor* actor = vtkImageActor::New( ); - mapper->SetInputData( image ); - actor->SetMapper( mapper ); - this->m_Actor = actor; - */ + unsigned long nPolys = mesh->GetNumberOfPolys( ); + if( nPolys >= cpPlugins_Mesh_MAX_POLYS ) + { + auto normals = vtkPolyDataNormals::New( ); + auto stripper = vtkStripper::New( ); + auto mapper = vtkPolyDataMapper::New( ); + auto actor = vtkQuadricLODActor::New( ); + + double r[ 2 ]; + mesh->GetScalarRange( r ); + + normals->SetInputData( mesh ); + normals->SetFeatureAngle( 60.0 ); + stripper->SetInputConnection( normals->GetOutputPort( ) ); + mapper->SetInputConnection( stripper->GetOutputPort( ) ); + mapper->UseLookupTableScalarRangeOff( ); + mapper->SetScalarRange( r[ 0 ], r[ 1 ] ); + actor->SetMapper( mapper ); + actor->DeferLODConstructionOff( ); + this->m_Actor = actor; + mapper->Delete( ); + stripper->Delete( ); + normals->Delete( ); + } + else + { + auto mapper = vtkPolyDataMapper::New( ); + mapper->SetInputData( mesh ); + auto actor = vtkActor::New( ); + actor->SetMapper( mapper ); + this->m_Actor = actor; + mapper->Delete( ); + + } // fi } // fi } diff --git a/lib/cpPlugins/OrthoNormalBase.cxx b/lib/cpPlugins/OrthoNormalBase.cxx new file mode 100644 index 0000000..4ad0255 --- /dev/null +++ b/lib/cpPlugins/OrthoNormalBase.cxx @@ -0,0 +1,39 @@ +#include +#include + +// ------------------------------------------------------------------------- +void cpPlugins::OrthoNormalBase:: +SetITK( itk::LightObject* o ) +{ + // Do nothing since itk::Matrix does not belong to LightObject hierarchy. +} + +// ------------------------------------------------------------------------- +void cpPlugins::OrthoNormalBase:: +SetVTK( vtkObjectBase* o ) +{ + auto matrix = dynamic_cast< vtkMatrix4x4* >( o ); + if( matrix != NULL ) + this->Superclass::SetVTK( matrix ); +} + +// ------------------------------------------------------------------------- +cpPlugins::OrthoNormalBase:: +OrthoNormalBase( ) + : Superclass( ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::OrthoNormalBase:: +~OrthoNormalBase( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPlugins::OrthoNormalBase:: +_CreateVTKActor( ) const +{ +} + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/OrthoNormalBase.h b/lib/cpPlugins/OrthoNormalBase.h new file mode 100644 index 0000000..46983dc --- /dev/null +++ b/lib/cpPlugins/OrthoNormalBase.h @@ -0,0 +1,49 @@ +#ifndef __CPPLUGINS__ORTHONORMALBASE__H__ +#define __CPPLUGINS__ORTHONORMALBASE__H__ + +#include + +namespace cpPlugins +{ + /** + */ + class cpPlugins_EXPORT OrthoNormalBase + : public DataObject + { + public: + typedef OrthoNormalBase Self; + typedef DataObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( OrthoNormalBase, DataObject ); + cpPlugins_Id_Macro( OrthoNormalBase, Object ); + + public: + virtual void SetITK( itk::LightObject* o ) ITK_OVERRIDE; + virtual void SetVTK( vtkObjectBase* o ) ITK_OVERRIDE; + + template< class _TMatrix > + inline void SetITK( const _TMatrix& m ); + + protected: + OrthoNormalBase( ); + virtual ~OrthoNormalBase( ); + + virtual void _CreateVTKActor( ) const ITK_OVERRIDE; + + private: + // Purposely not implemented + OrthoNormalBase( const Self& ); + Self& operator=( const Self& ); + }; + +} // ecapseman + +#include + +#endif // __CPPLUGINS__ORTHONORMALBASE__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/OrthoNormalBase.hxx b/lib/cpPlugins/OrthoNormalBase.hxx new file mode 100644 index 0000000..9b9e4e7 --- /dev/null +++ b/lib/cpPlugins/OrthoNormalBase.hxx @@ -0,0 +1,23 @@ +#ifndef __CPPLUGINS__ORTHONORMALBASE__HXX__ +#define __CPPLUGINS__ORTHONORMALBASE__HXX__ + +#include + +// ------------------------------------------------------------------------- +template< class _TMatrix > +void cpPlugins::OrthoNormalBase:: +SetITK( const _TMatrix& m ) +{ + vtkMatrix4x4* matrix = vtkMatrix4x4::New( ); + matrix->Identity( ); + for( unsigned int i = 0; i < 4; ++i ) + if( i < _TMatrix::RowDimensions ) + for( unsigned int j = 0; j < 4; ++j ) + if( j < _TMatrix::ColumnDimensions ) + matrix->SetElement( i, j, m[ i ][ j ] ); + this->m_VTKObject = matrix; +} + +#endif // __CPPLUGINS__ORTHONORMALBASE__HXX__ + +// eof - $RCSfile$