]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/QT/MPR3DWidget.cxx
yet another refactoring
[cpPlugins.git] / lib / cpExtensions / QT / MPR3DWidget.cxx
1 #include <cpExtensions/QT/MPR3DWidget.h>
2 #include <cpExtensions/Visualization/ImageOutlineActor.h>
3 #include <cpExtensions/Visualization/MeshActor.h>
4 #include <cpExtensions/Visualization/WindowLevelImageActor.h>
5
6 #include <vtkImageData.h>
7 #include <vtkPlane.h>
8 #include <vtkPolyData.h>
9
10 // -------------------------------------------------------------------------
11 cpExtensions::QT::MPR3DWidget::
12 MPR3DWidget( QWidget* parent, Qt::WindowFlags f )
13   : Superclass( parent, f ),
14     m_ImageName( "" )
15 {
16 }
17
18 // -------------------------------------------------------------------------
19 cpExtensions::QT::MPR3DWidget::
20 ~MPR3DWidget( )
21 {
22   for( auto a = this->m_Actors.begin( ); a != this->m_Actors.end( ); ++a )
23     delete *a;
24   this->m_Actors.clear( );
25 }
26
27 // -------------------------------------------------------------------------
28 void cpExtensions::QT::MPR3DWidget::
29 Clear( )
30 {
31   this->RemoveViewProps( );
32   this->m_ImageName = "";
33 }
34
35 // -------------------------------------------------------------------------
36 void cpExtensions::QT::MPR3DWidget::
37 SetImage( vtkImageData* image, const std::string& name )
38 {
39   if( name == "" )
40     return;
41   if( this->m_ImageName != "" )
42     this->Clear( );
43   this->m_ImageName = name;
44
45   for( unsigned int o = 0; o < 3; ++o )
46   {
47     this->m_WLActors[ o ] = vtkSmartPointer< TWLActor >::New( );
48     this->m_WLActors[ o ]->SetImage( image );
49     this->m_WLActors[ o ]->SetOrientation( o );
50
51     this->m_OLActors[ o ] = vtkSmartPointer< TOLActor >::New( );
52     this->m_OLActors[ o ]->SetBounds(
53       o, image->GetBounds( )[ o << 1 ], image->GetBounds( )
54       );
55
56     this->AddViewProp( this->m_WLActors[ o ], this->m_ImageName );
57     this->AddAuxViewProp( this->m_OLActors[ o ], this->m_ImageName );
58     this->ResetCamera( );
59
60   } // rof
61 }
62
63 // -------------------------------------------------------------------------
64 void cpExtensions::QT::MPR3DWidget::
65 Add( vtkDataSet* data, const std::string& name )
66 {
67   auto image = dynamic_cast< vtkImageData* >( data );
68   auto pdata = dynamic_cast< vtkPolyData* >( data );
69   if( image != NULL )
70   {
71     /* TODO
72        if( this->m_ImageName != "" )
73        {
74        }
75        else
76        this->SetImage( image, name );
77     */
78   }
79   else if( pdata != NULL )
80   {
81     TActor* actor = new TActor( );
82     actor->SetMesh( pdata );
83     this->m_Actors.push_back( actor );
84     this->AddViewProp( actor->GetActor( ), name );
85     this->Render( );
86     if( this->m_ImageName == "" )
87       this->ResetCamera( );
88
89   } // fi
90 }
91
92 // -------------------------------------------------------------------------
93 cpExtensions::QT::MPR3DWidget::
94 TWLActor* cpExtensions::QT::MPR3DWidget::
95 GetImageActor( int o )
96 {
97   return( this->m_WLActors[ o % 3 ] );
98 }
99
100 // -------------------------------------------------------------------------
101 const cpExtensions::QT::MPR3DWidget::
102 TWLActor* cpExtensions::QT::MPR3DWidget::
103 GetImageActor( int o ) const
104 {
105   return( this->m_WLActors[ o % 3 ] );
106 }
107
108 // -------------------------------------------------------------------------
109 void cpExtensions::QT::MPR3DWidget::
110 SetSliceNumber( int orientation, int slice )
111 {
112   int o = orientation % 3;
113   this->m_WLActors[ o ]->SetSliceNumber( slice );
114   this->m_OLActors[ o ]->SetBounds(
115     o,
116     this->m_WLActors[ o ]->GetSlicePlane( )->GetOrigin( )[ o ],
117     this->m_WLActors[ o ]->GetImage( )->GetBounds( )
118     );
119   this->Render( );
120 }
121
122 // -------------------------------------------------------------------------
123 void cpExtensions::QT::MPR3DWidget::
124 SetSlicesNumbers( int x, int y, int z )
125 {
126   int s[] = { x, y, z };
127   for( int o = 0; o < 3; ++o )
128   {
129     this->m_WLActors[ o ]->SetSliceNumber( s[ o ] );
130     this->m_OLActors[ o ]->SetBounds(
131       o,
132       this->m_WLActors[ o ]->GetSlicePlane( )->GetOrigin( )[ o ],
133       this->m_WLActors[ o ]->GetImage( )->GetBounds( )
134       );
135
136   } // rof
137   this->Render( );
138 }
139
140 // eof - $RCSfile$