From f47059eb39b5c9eef5cd2ee1b6c013cd75eff97f Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Fri, 3 Jun 2016 21:17:25 -0500 Subject: [PATCH] ... --- lib/cpExtensions/QT/SimpleMPRWidget.cxx | 41 +++++++++++++++- lib/cpExtensions/QT/SimpleMPRWidget.h | 23 +++++++++ lib/cpPlugins/DataObject.cxx | 21 +++++---- lib/cpPlugins/DataObject.h | 7 ++- lib/cpPlugins/Mesh.cxx | 62 ++++++++++++++++++++++--- lib/cpPlugins/Mesh.h | 23 ++++++++- lib/cpPlugins/OrthoNormalBase.cxx | 54 +++++++++++++++++++-- lib/cpPlugins/OrthoNormalBase.h | 45 ++++++++++++++++++ lib/cpPlugins/OrthoNormalBase.hxx | 18 +++++++ lib/cpPlugins/ProcessObject.cxx | 24 ---------- lib/cpPlugins/ProcessObject.h | 12 +++-- lib/cpPlugins/ProcessObject.hxx | 24 ++++++++++ 12 files changed, 300 insertions(+), 54 deletions(-) diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.cxx b/lib/cpExtensions/QT/SimpleMPRWidget.cxx index a020fb9..7e338bc 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.cxx +++ b/lib/cpExtensions/QT/SimpleMPRWidget.cxx @@ -6,6 +6,28 @@ #include #include +// ------------------------------------------------------------------------- +cpExtensions::QT::SimpleMPRWidget::_3DInteractorStyle* +cpExtensions::QT::SimpleMPRWidget::_3DInteractorStyle:: +New( ) +{ + return( new _3DInteractorStyle( ) ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::QT::SimpleMPRWidget::_3DInteractorStyle:: +OnKeyPress( ) +{ + vtkRenderWindowInteractor* i = this->Interactor; + std::string key = i->GetKeySym( ); + if( key == "r" || key == "R" ) + { + this->CurrentRenderer->ResetCamera( ); + i->Render( ); + + } // fi +} + // ------------------------------------------------------------------------- cpExtensions::QT::SimpleMPRWidget:: SimpleMPRWidget( QWidget* parent ) @@ -19,7 +41,6 @@ SimpleMPRWidget( QWidget* parent ) this->m_VTK[ 1 ] = this->m_UI->VTK_Y; this->m_VTK[ 2 ] = this->m_UI->VTK_Z; this->m_VTK[ 3 ] = this->m_UI->VTK_3D; - for( unsigned int i = 0; i < 4; ++i ) { this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( ); @@ -27,6 +48,11 @@ SimpleMPRWidget( QWidget* parent ) AddRenderer( this->m_Renderers[ i ] ); } // rof + vtkSmartPointer< _3DInteractorStyle > style = + vtkSmartPointer< _3DInteractorStyle >::New( ); + this->m_VTK[ 3 ]->GetRenderWindow( )-> + GetInteractor( )->SetInteractorStyle( style ); + style->SetCurrentRenderer( this->m_Renderers[ 3 ] ); // Connect slots QObject::connect( @@ -214,9 +240,20 @@ AddMeshActor( vtkProp3D* actor, const std::string& name ) { if( actor != NULL ) { + std::cout << name << " " << actor << std::endl; + this->m_Renderers[ 3 ]->AddViewProp( actor ); this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); this->m_NamedActors[ name ].insert( actor ); + std::cout << "Size: " << this->m_NamedActors.size( ) << " " << this->m_NamedActors[ name ].size( ) << std::endl; + + + double bounds[ 6 ]; + this->m_Renderers[ 3 ]->ComputeVisiblePropBounds( bounds ); + std::cout + << bounds[ 0 ] << " " << bounds[ 1 ] << " " + << bounds[ 2 ] << " " << bounds[ 3 ] << " " + << bounds[ 4 ] << " " << bounds[ 5 ] << std::endl; } // fi } @@ -228,7 +265,7 @@ AddActor( vtkProp* actor, const std::string& name ) auto ia = dynamic_cast< vtkImageActor* >( actor ); if( ia == NULL ) { - auto ma = dynamic_cast< vtkActor* >( actor ); + auto ma = dynamic_cast< vtkProp3D* >( actor ); if( ma != NULL ) this->AddMeshActor( ma, name ); } diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.h b/lib/cpExtensions/QT/SimpleMPRWidget.h index 35307a4..04ed994 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.h +++ b/lib/cpExtensions/QT/SimpleMPRWidget.h @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include #include @@ -49,6 +51,27 @@ namespace cpExtensions typedef std::map< std::string, TActors > TNamedActors; typedef cpExtensions::Visualization::ImageSliceActors TSliceActors; + protected: + /** + */ + class _3DInteractorStyle + : public vtkInteractorStyleTrackballCamera + { + public: + vtkTypeMacro( + _3DInteractorStyle, vtkInteractorStyleTrackballCamera + ); + + public: + static _3DInteractorStyle* New( ); + + virtual void OnChar( ) { } + virtual void OnKeyDown( ) { } + virtual void OnKeyUp( ) { } + virtual void OnKeyRelease( ) { } + virtual void OnKeyPress( ); + }; + public: explicit SimpleMPRWidget( QWidget* parent = 0 ); virtual ~SimpleMPRWidget( ); diff --git a/lib/cpPlugins/DataObject.cxx b/lib/cpPlugins/DataObject.cxx index 06806b5..9e6bdca 100644 --- a/lib/cpPlugins/DataObject.cxx +++ b/lib/cpPlugins/DataObject.cxx @@ -69,26 +69,29 @@ DisconnectFromPipeline( ) vtkProp* cpPlugins::DataObject:: GetVTKActor( ) { - if( this->m_Actor == NULL ) + if( this->m_Actor.GetPointer( ) == NULL ) this->_CreateVTKActor( ); - return( this->m_Actor ); + return( this->m_Actor.GetPointer( ) ); } // ------------------------------------------------------------------------- const vtkProp* cpPlugins::DataObject:: GetVTKActor( ) const { - if( this->m_Actor == NULL ) + if( this->m_Actor.GetPointer( ) == NULL ) this->_CreateVTKActor( ); - return( this->m_Actor ); + return( this->m_Actor.GetPointer( ) ); } // ------------------------------------------------------------------------- cpPlugins::DataObject:: DataObject( ) : Superclass( ), - m_Source( NULL ), - m_Actor( NULL ) + m_Source( NULL ) + /* TODO + , + m_Actor( NULL ) + */ { } @@ -96,8 +99,10 @@ DataObject( ) cpPlugins::DataObject:: ~DataObject( ) { - if( this->m_Actor != NULL ) - this->m_Actor->Delete( ); + /* TODO + if( this->m_Actor != NULL ) + this->m_Actor->Delete( ); + */ } // ------------------------------------------------------------------------- diff --git a/lib/cpPlugins/DataObject.h b/lib/cpPlugins/DataObject.h index 998a914..95cf3dd 100644 --- a/lib/cpPlugins/DataObject.h +++ b/lib/cpPlugins/DataObject.h @@ -2,9 +2,11 @@ #define __CPPLUGINS__DATAOBJECT__H__ #include +#include +#include // Some forward declarations -class vtkProp; +// TODO: class vtkProp; namespace cpPlugins { @@ -51,7 +53,8 @@ namespace cpPlugins protected: ProcessObject* m_Source; - mutable vtkProp* m_Actor; + // TODO: mutable vtkProp* m_Actor; + mutable vtkSmartPointer< vtkProp > m_Actor; }; } // ecapseman diff --git a/lib/cpPlugins/Mesh.cxx b/lib/cpPlugins/Mesh.cxx index f0e29f5..f06aae0 100644 --- a/lib/cpPlugins/Mesh.cxx +++ b/lib/cpPlugins/Mesh.cxx @@ -5,15 +5,51 @@ #include #include -#include -#include -#include -#include -#include -#include - #define cpPlugins_Mesh_MAX_POLYS 65535 +// ------------------------------------------------------------------------- +void cpPlugins::Mesh::MeshActor:: +SetMesh( vtkPolyData* mesh ) +{ + this->Normals = NULL; + this->Stripper = NULL; + this->Mapper = NULL; + this->LODActor = NULL; + this->Actor = NULL; + if( mesh != NULL ) + { + unsigned long nPolys = mesh->GetNumberOfPolys( ); + if( nPolys >= cpPlugins_Mesh_MAX_POLYS ) + { + this->Normals = vtkSmartPointer< vtkPolyDataNormals >::New( ); + this->Stripper = vtkSmartPointer< vtkStripper >::New( ); + this->Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); + this->LODActor = vtkSmartPointer< vtkQuadricLODActor >::New( ); + + double r[ 2 ]; + mesh->GetScalarRange( r ); + + this->Normals->SetInputData( mesh ); + this->Normals->SetFeatureAngle( 60.0 ); + this->Stripper->SetInputConnection( this->Normals->GetOutputPort( ) ); + this->Mapper->SetInputConnection( this->Stripper->GetOutputPort( ) ); + this->Mapper->UseLookupTableScalarRangeOff( ); + this->Mapper->SetScalarRange( r[ 0 ], r[ 1 ] ); + this->LODActor->SetMapper( this->Mapper ); + this->LODActor->DeferLODConstructionOff( ); + } + else + { + this->Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); + this->Actor = vtkSmartPointer< vtkActor >::New( ); + this->Mapper->SetInputData( mesh ); + this->Actor->SetMapper( this->Mapper ); + + } // fi + + } // fi +} + // ------------------------------------------------------------------------- void cpPlugins::Mesh:: SetITK( itk::LightObject* o ) @@ -132,6 +168,17 @@ cpPlugins::Mesh:: void cpPlugins::Mesh:: _CreateVTKActor( ) const { + this->m_MeshActor.SetMesh( + const_cast< vtkPolyData* >( this->GetVTK< vtkPolyData >( ) ) + ); + if( this->m_MeshActor.LODActor.GetPointer( ) != NULL ) + this->m_Actor = this->m_MeshActor.LODActor.GetPointer( ); + else if( this->m_MeshActor.Actor.GetPointer( ) != NULL ) + this->m_Actor = this->m_MeshActor.Actor.GetPointer( ); + else + this->m_Actor = NULL; + + /* TODO vtkPolyData* mesh = const_cast< vtkPolyData* >( this->GetVTK< vtkPolyData >( ) ); if( mesh != NULL ) @@ -172,6 +219,7 @@ _CreateVTKActor( ) const } // fi } // fi + */ } // eof - $RCSfile$ diff --git a/lib/cpPlugins/Mesh.h b/lib/cpPlugins/Mesh.h index 1c70aba..d0416f7 100644 --- a/lib/cpPlugins/Mesh.h +++ b/lib/cpPlugins/Mesh.h @@ -3,8 +3,13 @@ #include -// Some forward declarations -class vtkObject; +#include +#include +#include +#include +#include +#include +#include namespace cpPlugins { @@ -19,6 +24,17 @@ namespace cpPlugins typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; + struct MeshActor + { + vtkSmartPointer< vtkPolyDataNormals > Normals; + vtkSmartPointer< vtkStripper > Stripper; + vtkSmartPointer< vtkPolyDataMapper > Mapper; + vtkSmartPointer< vtkQuadricLODActor > LODActor; + vtkSmartPointer< vtkActor > Actor; + + void SetMesh( vtkPolyData* mesh ); + }; + public: itkNewMacro( Self ); itkTypeMacro( Mesh, DataObject ); @@ -41,6 +57,9 @@ namespace cpPlugins // Purposely not implemented Mesh( const Self& ); Self& operator=( const Self& ); + + protected: + mutable MeshActor m_MeshActor; }; } // ecapseman diff --git a/lib/cpPlugins/OrthoNormalBase.cxx b/lib/cpPlugins/OrthoNormalBase.cxx index e45545d..9bbb18b 100644 --- a/lib/cpPlugins/OrthoNormalBase.cxx +++ b/lib/cpPlugins/OrthoNormalBase.cxx @@ -1,6 +1,5 @@ #include -#include #include // ------------------------------------------------------------------------- @@ -38,11 +37,56 @@ _CreateVTKActor( ) const { auto matrix = const_cast< vtkMatrix4x4* >( this->GetVTK< vtkMatrix4x4 >( ) ); - if( matrix != NULL ) + if( matrix != NULL ) { - auto actor = vtkAxesActor::New( ); - actor->SetUserMatrix( matrix ); - this->m_Actor = actor; + this->m_BaseActor.SetBase( matrix ); + this->m_Actor = this->m_BaseActor.Actor.GetPointer( ); + /* TODO + double o[ 3 ], x[ 3 ], y[ 3 ], z[ 3 ]; + + o[ 0 ] = matrix->GetElement( 0, 3 ); + o[ 1 ] = matrix->GetElement( 1, 3 ); + o[ 2 ] = matrix->GetElement( 2, 3 ); + + x[ 0 ] = matrix->GetElement( 0, 0 ) + o[ 0 ]; + x[ 1 ] = matrix->GetElement( 1, 0 ) + o[ 1 ]; + x[ 2 ] = matrix->GetElement( 2, 0 ) + o[ 2 ]; + + y[ 0 ] = matrix->GetElement( 0, 1 ) + o[ 0 ]; + y[ 1 ] = matrix->GetElement( 1, 1 ) + o[ 1 ]; + y[ 2 ] = matrix->GetElement( 2, 1 ) + o[ 2 ]; + + z[ 0 ] = matrix->GetElement( 0, 2 ) + o[ 0 ]; + z[ 1 ] = matrix->GetElement( 1, 2 ) + o[ 1 ]; + z[ 2 ] = matrix->GetElement( 2, 2 ) + o[ 2 ]; + + static vtkPoints* points = vtkPoints::New( ); + points->InsertNextPoint( o ); + points->InsertNextPoint( x ); + points->InsertNextPoint( y ); + points->InsertNextPoint( z ); + + static vtkCellArray* lines = vtkCellArray::New( ); + lines->InsertNextCell( 2 ); lines->InsertCellPoint( 0 ); lines->InsertCellPoint( 1 ); + lines->InsertNextCell( 2 ); lines->InsertCellPoint( 0 ); lines->InsertCellPoint( 2 ); + lines->InsertNextCell( 2 ); lines->InsertCellPoint( 0 ); lines->InsertCellPoint( 3 ); + + static vtkPolyData* base = vtkPolyData::New( ); + base->SetPoints( points ); + base->SetLines( lines ); + + static vtkPolyDataMapper* mapper = vtkPolyDataMapper::New( ); + mapper->SetInputData( base ); + + static vtkActor* actor = vtkActor::New( ); + actor->SetMapper( mapper ); + this->m_Actor = actor; + */ + /* + this->m_AxesActor = vtkSmartPointer< vtkAxesActor >::New( ); + this->m_AxesActor->SetUserMatrix( matrix ); + this->m_Actor = this->m_AxesActor.GetPointer( ); + */ } // fi } diff --git a/lib/cpPlugins/OrthoNormalBase.h b/lib/cpPlugins/OrthoNormalBase.h index 46983dc..d1ef29e 100644 --- a/lib/cpPlugins/OrthoNormalBase.h +++ b/lib/cpPlugins/OrthoNormalBase.h @@ -2,6 +2,16 @@ #define __CPPLUGINS__ORTHONORMALBASE__H__ #include +#include +#include +#include +#include +#include +#include +#include +#include + +#include namespace cpPlugins { @@ -16,6 +26,35 @@ namespace cpPlugins typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; + struct BaseActor + { + vtkSmartPointer< vtkPolyData > Axes; + vtkSmartPointer< vtkPolyDataMapper > Mapper; + vtkSmartPointer< vtkActor > Actor; + + void SetBase( vtkMatrix4x4* matrix ) + { + this->Axes = vtkSmartPointer< vtkPolyData >::New( ); + this->Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); + this->Actor = vtkSmartPointer< vtkActor >::New( ); + + vtkSmartPointer< vtkPoints > points = vtkSmartPointer< vtkPoints >::New( ); + points->InsertNextPoint( 0, 0, 0 ); + points->InsertNextPoint( 1, 0, 0 ); + points->InsertNextPoint( 0, 1, 0 ); + points->InsertNextPoint( 0, 0, 1 ); + vtkSmartPointer< vtkCellArray > lines = vtkSmartPointer< vtkCellArray >::New( ); + lines->InsertNextCell( 2 ); lines->InsertCellPoint( 0 ); lines->InsertCellPoint( 1 ); + lines->InsertNextCell( 2 ); lines->InsertCellPoint( 0 ); lines->InsertCellPoint( 2 ); + lines->InsertNextCell( 2 ); lines->InsertCellPoint( 0 ); lines->InsertCellPoint( 3 ); + this->Axes->SetPoints( points ); + this->Axes->SetLines( lines ); + + this->Mapper->SetInputData( this->Axes ); + this->Actor->SetMapper( this->Mapper ); + } + }; + public: itkNewMacro( Self ); itkTypeMacro( OrthoNormalBase, DataObject ); @@ -28,6 +67,9 @@ namespace cpPlugins template< class _TMatrix > inline void SetITK( const _TMatrix& m ); + template< class _TMatrix, class _TVector > + inline void SetITK( const _TMatrix& m, const _TVector& v ); + protected: OrthoNormalBase( ); virtual ~OrthoNormalBase( ); @@ -38,6 +80,9 @@ namespace cpPlugins // Purposely not implemented OrthoNormalBase( const Self& ); Self& operator=( const Self& ); + + protected: + mutable BaseActor m_BaseActor; }; } // ecapseman diff --git a/lib/cpPlugins/OrthoNormalBase.hxx b/lib/cpPlugins/OrthoNormalBase.hxx index 9b9e4e7..e21a3c8 100644 --- a/lib/cpPlugins/OrthoNormalBase.hxx +++ b/lib/cpPlugins/OrthoNormalBase.hxx @@ -18,6 +18,24 @@ SetITK( const _TMatrix& m ) this->m_VTKObject = matrix; } +// ------------------------------------------------------------------------- +template< class _TMatrix, class _TVector > +void cpPlugins::OrthoNormalBase:: +SetITK( const _TMatrix& m, const _TVector& v ) +{ + vtkMatrix4x4* matrix = vtkMatrix4x4::New( ); + matrix->Identity( ); + for( unsigned int i = 0; i < 3; ++i ) + if( i < _TMatrix::RowDimensions ) + for( unsigned int j = 0; j < 3; ++j ) + if( j < _TMatrix::ColumnDimensions ) + matrix->SetElement( i, j, m[ i ][ j ] ); + for( unsigned int i = 0; i < 3; ++i ) + if( i < _TVector::Dimension ) + matrix->SetElement( i, 3, v[ i ] ); + this->m_VTKObject = matrix; +} + #endif // __CPPLUGINS__ORTHONORMALBASE__HXX__ // eof - $RCSfile$ diff --git a/lib/cpPlugins/ProcessObject.cxx b/lib/cpPlugins/ProcessObject.cxx index 74f4433..12c9bb6 100644 --- a/lib/cpPlugins/ProcessObject.cxx +++ b/lib/cpPlugins/ProcessObject.cxx @@ -118,30 +118,6 @@ GetInput( const std::string& id ) const return( NULL ); } -// ------------------------------------------------------------------------- -cpPlugins:: -DataObject* cpPlugins::ProcessObject:: -GetOutput( const std::string& id ) -{ - auto i = this->m_Outputs.find( id ); - if( i != this->m_Outputs.end( ) ) - return( dynamic_cast< DataObject* >( i->second.GetPointer( ) ) ); - else - return( NULL ); -} - -// ------------------------------------------------------------------------- -const cpPlugins:: -DataObject* cpPlugins::ProcessObject:: -GetOutput( const std::string& id ) const -{ - auto i = this->m_Outputs.find( id ); - if( i != this->m_Outputs.end( ) ) - return( dynamic_cast< const DataObject* >( i->second.GetPointer( ) ) ); - else - return( NULL ); -} - // ------------------------------------------------------------------------- bool cpPlugins::ProcessObject:: SetInputPort( const std::string& id, const OutputPort& port ) diff --git a/lib/cpPlugins/ProcessObject.h b/lib/cpPlugins/ProcessObject.h index 1f888a9..1345e3b 100644 --- a/lib/cpPlugins/ProcessObject.h +++ b/lib/cpPlugins/ProcessObject.h @@ -48,14 +48,18 @@ namespace cpPlugins DataObject* GetInput( const std::string& id ); const DataObject* GetInput( const std::string& id ) const; - DataObject* GetOutput( const std::string& id ); - const DataObject* GetOutput( const std::string& id ) const; + + template< class _TType = DataObject > + inline _TType* GetOutput( const std::string& id ); + + template< class _TType = DataObject > + inline const _TType* GetOutput( const std::string& id ) const; template< class _TType > - _TType* GetInputData( const std::string& name ); + inline _TType* GetInputData( const std::string& name ); template< class _TType > - _TType* GetOutputData( const std::string& name ); + inline _TType* GetOutputData( const std::string& name ); bool SetInputPort( const std::string& id, const OutputPort& port ); diff --git a/lib/cpPlugins/ProcessObject.hxx b/lib/cpPlugins/ProcessObject.hxx index f0f2cd0..93d62bb 100644 --- a/lib/cpPlugins/ProcessObject.hxx +++ b/lib/cpPlugins/ProcessObject.hxx @@ -1,6 +1,30 @@ #ifndef __CPPLUGINS__PROCESSOBJECT__HXX__ #define __CPPLUGINS__PROCESSOBJECT__HXX__ +// ------------------------------------------------------------------------- +template< class _TType > +_TType* cpPlugins::ProcessObject:: +GetOutput( const std::string& id ) +{ + auto i = this->m_Outputs.find( id ); + if( i != this->m_Outputs.end( ) ) + return( dynamic_cast< _TType* >( i->second.GetPointer( ) ) ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +template< class _TType > +const _TType* cpPlugins::ProcessObject:: +GetOutput( const std::string& id ) const +{ + auto i = this->m_Outputs.find( id ); + if( i != this->m_Outputs.end( ) ) + return( dynamic_cast< const _TType* >( i->second.GetPointer( ) ) ); + else + return( NULL ); +} + // ------------------------------------------------------------------------- template< class _TType > _TType* cpPlugins::ProcessObject:: -- 2.45.1