1 #include <cpExtensions/QT/MPR3DWidget.h>
2 #include <cpExtensions/Visualization/ImageOutlineActor.h>
3 #include <cpExtensions/Visualization/MeshActor.h>
4 #include <cpExtensions/Visualization/WindowLevelImageActor.h>
6 #include <vtkImageData.h>
8 #include <vtkPolyData.h>
10 // -------------------------------------------------------------------------
11 cpExtensions::QT::MPR3DWidget::
12 MPR3DWidget( QWidget* parent, Qt::WindowFlags f )
13 : Superclass( parent, f ),
18 // -------------------------------------------------------------------------
19 cpExtensions::QT::MPR3DWidget::
22 for( auto a = this->m_Actors.begin( ); a != this->m_Actors.end( ); ++a )
24 this->m_Actors.clear( );
27 // -------------------------------------------------------------------------
28 void cpExtensions::QT::MPR3DWidget::
31 this->RemoveViewProps( );
32 this->m_ImageName = "";
35 // -------------------------------------------------------------------------
36 void cpExtensions::QT::MPR3DWidget::
37 SetImage( vtkImageData* image, const std::string& name )
41 if( this->m_ImageName != "" )
43 this->m_ImageName = name;
45 for( unsigned int o = 0; o < 3; ++o )
47 this->m_WLActors[ o ] = vtkSmartPointer< TWLActor >::New( );
48 this->m_WLActors[ o ]->SetImage( image );
49 this->m_WLActors[ o ]->SetOrientation( o );
51 this->m_OLActors[ o ] = vtkSmartPointer< TOLActor >::New( );
52 this->m_OLActors[ o ]->SetBounds(
53 o, image->GetBounds( )[ o << 1 ], image->GetBounds( )
56 this->AddViewProp( this->m_WLActors[ o ], this->m_ImageName );
57 this->AddAuxViewProp( this->m_OLActors[ o ], this->m_ImageName );
63 // -------------------------------------------------------------------------
64 void cpExtensions::QT::MPR3DWidget::
65 Add( vtkDataSet* data, const std::string& name )
67 auto image = dynamic_cast< vtkImageData* >( data );
68 auto pdata = dynamic_cast< vtkPolyData* >( data );
72 if( this->m_ImageName != "" )
76 this->SetImage( image, name );
79 else if( pdata != NULL )
81 TActor* actor = new TActor( );
82 actor->SetMesh( pdata );
83 this->m_Actors.push_back( actor );
84 this->AddViewProp( actor->GetActor( ), name );
86 if( this->m_ImageName == "" )
92 // -------------------------------------------------------------------------
93 cpExtensions::QT::MPR3DWidget::
94 TWLActor* cpExtensions::QT::MPR3DWidget::
95 GetImageActor( int o )
97 return( this->m_WLActors[ o % 3 ] );
100 // -------------------------------------------------------------------------
101 const cpExtensions::QT::MPR3DWidget::
102 TWLActor* cpExtensions::QT::MPR3DWidget::
103 GetImageActor( int o ) const
105 return( this->m_WLActors[ o % 3 ] );
108 // -------------------------------------------------------------------------
109 void cpExtensions::QT::MPR3DWidget::
110 SetSliceNumber( int orientation, int slice )
112 int o = orientation % 3;
113 this->m_WLActors[ o ]->SetSliceNumber( slice );
114 this->m_OLActors[ o ]->SetBounds(
116 this->m_WLActors[ o ]->GetSlicePlane( )->GetOrigin( )[ o ],
117 this->m_WLActors[ o ]->GetImage( )->GetBounds( )
122 // -------------------------------------------------------------------------
123 void cpExtensions::QT::MPR3DWidget::
124 SetSlicesNumbers( int x, int y, int z )
126 int s[] = { x, y, z };
127 for( int o = 0; o < 3; ++o )
129 this->m_WLActors[ o ]->SetSliceNumber( s[ o ] );
130 this->m_OLActors[ o ]->SetBounds(
132 this->m_WLActors[ o ]->GetSlicePlane( )->GetOrigin( )[ o ],
133 this->m_WLActors[ o ]->GetImage( )->GetBounds( )