]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/QT/MPR3DWidget.cxx
yet another refactoring
[cpPlugins.git] / lib / cpExtensions / QT / MPR3DWidget.cxx
diff --git a/lib/cpExtensions/QT/MPR3DWidget.cxx b/lib/cpExtensions/QT/MPR3DWidget.cxx
new file mode 100644 (file)
index 0000000..f86992d
--- /dev/null
@@ -0,0 +1,140 @@
+#include <cpExtensions/QT/MPR3DWidget.h>
+#include <cpExtensions/Visualization/ImageOutlineActor.h>
+#include <cpExtensions/Visualization/MeshActor.h>
+#include <cpExtensions/Visualization/WindowLevelImageActor.h>
+
+#include <vtkImageData.h>
+#include <vtkPlane.h>
+#include <vtkPolyData.h>
+
+// -------------------------------------------------------------------------
+cpExtensions::QT::MPR3DWidget::
+MPR3DWidget( QWidget* parent, Qt::WindowFlags f )
+  : Superclass( parent, f ),
+    m_ImageName( "" )
+{
+}
+
+// -------------------------------------------------------------------------
+cpExtensions::QT::MPR3DWidget::
+~MPR3DWidget( )
+{
+  for( auto a = this->m_Actors.begin( ); a != this->m_Actors.end( ); ++a )
+    delete *a;
+  this->m_Actors.clear( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::MPR3DWidget::
+Clear( )
+{
+  this->RemoveViewProps( );
+  this->m_ImageName = "";
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::MPR3DWidget::
+SetImage( vtkImageData* image, const std::string& name )
+{
+  if( name == "" )
+    return;
+  if( this->m_ImageName != "" )
+    this->Clear( );
+  this->m_ImageName = name;
+
+  for( unsigned int o = 0; o < 3; ++o )
+  {
+    this->m_WLActors[ o ] = vtkSmartPointer< TWLActor >::New( );
+    this->m_WLActors[ o ]->SetImage( image );
+    this->m_WLActors[ o ]->SetOrientation( o );
+
+    this->m_OLActors[ o ] = vtkSmartPointer< TOLActor >::New( );
+    this->m_OLActors[ o ]->SetBounds(
+      o, image->GetBounds( )[ o << 1 ], image->GetBounds( )
+      );
+
+    this->AddViewProp( this->m_WLActors[ o ], this->m_ImageName );
+    this->AddAuxViewProp( this->m_OLActors[ o ], this->m_ImageName );
+    this->ResetCamera( );
+
+  } // rof
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::MPR3DWidget::
+Add( vtkDataSet* data, const std::string& name )
+{
+  auto image = dynamic_cast< vtkImageData* >( data );
+  auto pdata = dynamic_cast< vtkPolyData* >( data );
+  if( image != NULL )
+  {
+    /* TODO
+       if( this->m_ImageName != "" )
+       {
+       }
+       else
+       this->SetImage( image, name );
+    */
+  }
+  else if( pdata != NULL )
+  {
+    TActor* actor = new TActor( );
+    actor->SetMesh( pdata );
+    this->m_Actors.push_back( actor );
+    this->AddViewProp( actor->GetActor( ), name );
+    this->Render( );
+    if( this->m_ImageName == "" )
+      this->ResetCamera( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+cpExtensions::QT::MPR3DWidget::
+TWLActor* cpExtensions::QT::MPR3DWidget::
+GetImageActor( int o )
+{
+  return( this->m_WLActors[ o % 3 ] );
+}
+
+// -------------------------------------------------------------------------
+const cpExtensions::QT::MPR3DWidget::
+TWLActor* cpExtensions::QT::MPR3DWidget::
+GetImageActor( int o ) const
+{
+  return( this->m_WLActors[ o % 3 ] );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::MPR3DWidget::
+SetSliceNumber( int orientation, int slice )
+{
+  int o = orientation % 3;
+  this->m_WLActors[ o ]->SetSliceNumber( slice );
+  this->m_OLActors[ o ]->SetBounds(
+    o,
+    this->m_WLActors[ o ]->GetSlicePlane( )->GetOrigin( )[ o ],
+    this->m_WLActors[ o ]->GetImage( )->GetBounds( )
+    );
+  this->Render( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::MPR3DWidget::
+SetSlicesNumbers( int x, int y, int z )
+{
+  int s[] = { x, y, z };
+  for( int o = 0; o < 3; ++o )
+  {
+    this->m_WLActors[ o ]->SetSliceNumber( s[ o ] );
+    this->m_OLActors[ o ]->SetBounds(
+      o,
+      this->m_WLActors[ o ]->GetSlicePlane( )->GetOrigin( )[ o ],
+      this->m_WLActors[ o ]->GetImage( )->GetBounds( )
+      );
+
+  } // rof
+  this->Render( );
+}
+
+// eof - $RCSfile$