]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Sat, 4 Jun 2016 02:17:25 +0000 (21:17 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Sat, 4 Jun 2016 02:17:25 +0000 (21:17 -0500)
12 files changed:
lib/cpExtensions/QT/SimpleMPRWidget.cxx
lib/cpExtensions/QT/SimpleMPRWidget.h
lib/cpPlugins/DataObject.cxx
lib/cpPlugins/DataObject.h
lib/cpPlugins/Mesh.cxx
lib/cpPlugins/Mesh.h
lib/cpPlugins/OrthoNormalBase.cxx
lib/cpPlugins/OrthoNormalBase.h
lib/cpPlugins/OrthoNormalBase.hxx
lib/cpPlugins/ProcessObject.cxx
lib/cpPlugins/ProcessObject.h
lib/cpPlugins/ProcessObject.hxx

index a020fb9e3d7e0c80207922e3827ae2016e131279..7e338bc0b77c486e8f2c813f3f20383b838e0580 100644 (file)
@@ -6,6 +6,28 @@
 #include <vtkRenderer.h>
 #include <vtkRenderWindow.h>
 
+// -------------------------------------------------------------------------
+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 );
   }
index 35307a4e69de730cbaac427b30cba4db524ac655..04ed994898f710f698a629205ffbead51c8b759e 100644 (file)
@@ -8,6 +8,8 @@
 #include <map>
 #include <set>
 #include <QWidget>
+#include <vtkInteractorStyleTrackballCamera.h>
+#include <vtkRenderWindowInteractor.h>
 #include <vtkProp.h>
 #include <vtkSmartPointer.h>
 #include <cpExtensions/Visualization/ImageSliceActors.h>
@@ -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( );
index 06806b56fd483ec689154d733c05fd710802bd6d..9e6bdca57a55264d986a3a8d719f0143048df8dd 100644 (file)
@@ -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( );
+  */
 }
 
 // -------------------------------------------------------------------------
index 998a91487697e7cfd65faa8f98400753cfa9c059..95cf3dd80c88a443e1ba3e047d73b87c83739259 100644 (file)
@@ -2,9 +2,11 @@
 #define __CPPLUGINS__DATAOBJECT__H__
 
 #include <cpPlugins/Object.h>
+#include <vtkProp.h>
+#include <vtkSmartPointer.h>
 
 // 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
index f0e29f50b31054eb8a7fd34558b92640a6e14d62..f06aae0348568315170abdf49d668a8ba5a60980 100644 (file)
@@ -5,15 +5,51 @@
 #include <itkTriangleCell.h>
 #include <itkPolygonCell.h>
 
-#include <vtkActor.h>
-#include <vtkPolyDataNormals.h>
-#include <vtkPolyData.h>
-#include <vtkPolyDataMapper.h>
-#include <vtkQuadricLODActor.h>
-#include <vtkStripper.h>
-
 #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$
index 1c70abac75e1ab6786937ebfa28b239458c1c544..d0416f773c20cc9ea90e6c57743d7b9cd89c86f3 100644 (file)
@@ -3,8 +3,13 @@
 
 #include <cpPlugins/DataObject.h>
 
-// Some forward declarations
-class vtkObject;
+#include <vtkActor.h>
+#include <vtkPolyDataNormals.h>
+#include <vtkPolyData.h>
+#include <vtkPolyDataMapper.h>
+#include <vtkQuadricLODActor.h>
+#include <vtkStripper.h>
+#include <vtkSmartPointer.h>
 
 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
index e45545de90a132aeb6e3a5fca646ee86fcd61a49..9bbb18b585256cb6bc938d45cdbb14ce265e75e2 100644 (file)
@@ -1,6 +1,5 @@
 #include <cpPlugins/OrthoNormalBase.h>
 
-#include <vtkAxesActor.h>
 #include <vtkMatrix4x4.h>
 
 // -------------------------------------------------------------------------
@@ -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
 }
index 46983dcf107538179553f713bcf2df5a990c1141..d1ef29e48cb3542bfada3f9cb1c9038d2d762107 100644 (file)
@@ -2,6 +2,16 @@
 #define __CPPLUGINS__ORTHONORMALBASE__H__
 
 #include <cpPlugins/DataObject.h>
+#include <vtkActor.h>
+#include <vtkAxes.h>
+#include <vtkPolyDataMapper.h>
+#include <vtkActor.h>
+#include <vtkCellArray.h>
+#include <vtkPoints.h>
+#include <vtkPolyData.h>
+#include <vtkPolyDataMapper.h>
+
+#include <vtkSmartPointer.h>
 
 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
index 9b9e4e75a5a2193fa6c758e93aeff47406da6fb5..e21a3c8d11418c1f5e9ee62d8711219bdd34f713 100644 (file)
@@ -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$
index 74f4433a3568732f4a49bf6e04ee86d5c9a6bc71..12c9bb6c42f2e1885399c3caa78a69da1c5d11ec 100644 (file)
@@ -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 )
index 1f888a9db864f9efcdbba1e48e3cefdf1489a43d..1345e3b543bd150d158ff1d3a1a0fd12254794c5 100644 (file)
@@ -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 );
 
index f0f2cd0d7c17a763b82637d14ab2aa6f33cfa6a9..93d62bb483e0faf92ff5b3961dc51a6ab09ead4b 100644 (file)
@@ -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::