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