]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/ImageSliceActors.cxx
...
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageSliceActors.cxx
1 #include <cpExtensions/Visualization/ImageSliceActors.h>
2 #include <cpExtensions/Visualization/ImageOutlineActor.h>
3 #include <cpExtensions/Visualization/LUTImageActor.h>
4 #include <cpExtensions/Visualization/WindowLevelImageActor.h>
5
6 #include <vtkImageData.h>
7 #include <vtkPlane.h>
8
9 // -------------------------------------------------------------------------
10 cpExtensions::Visualization::ImageSliceActors::
11 Self* cpExtensions::Visualization::ImageSliceActors::
12 New( )
13 {
14   return( new Self( ) );
15 }
16
17 // -------------------------------------------------------------------------
18 vtkImageData* cpExtensions::Visualization::ImageSliceActors::
19 GetImage( )
20 {
21   if( this->m_WindowLevelImageActor.GetPointer( ) != NULL )
22     return( this->m_WindowLevelImageActor->GetImage( ) );
23   else
24     return( NULL );
25 }
26
27 // -------------------------------------------------------------------------
28 const vtkImageData* cpExtensions::Visualization::ImageSliceActors::
29 GetImage( ) const
30 {
31   if( this->m_WindowLevelImageActor.GetPointer( ) != NULL )
32     return( this->m_WindowLevelImageActor->GetImage( ) );
33   else
34     return( NULL );
35 }
36
37 // -------------------------------------------------------------------------
38 cpExtensions::Visualization::
39 WindowLevelImageActor* cpExtensions::Visualization::ImageSliceActors::
40 GetWindowLevelImageActor( )
41 {
42   return( this->m_WindowLevelImageActor.GetPointer( ) );
43 }
44
45 // -------------------------------------------------------------------------
46 const cpExtensions::Visualization::
47 WindowLevelImageActor* cpExtensions::Visualization::ImageSliceActors::
48 GetWindowLevelImageActor( ) const
49 {
50   return( this->m_WindowLevelImageActor.GetPointer( ) );
51 }
52
53 // -------------------------------------------------------------------------
54 cpExtensions::Visualization::
55 LUTImageActor* cpExtensions::Visualization::ImageSliceActors::
56 GetLUTImageActor( )
57 {
58   return( this->m_LUTImageActor.GetPointer( ) );
59 }
60
61 // -------------------------------------------------------------------------
62 const cpExtensions::Visualization::
63 LUTImageActor* cpExtensions::Visualization::ImageSliceActors::
64 GetLUTImageActor( ) const
65 {
66   return( this->m_LUTImageActor.GetPointer( ) );
67 }
68
69 // -------------------------------------------------------------------------
70 cpExtensions::Visualization::
71 ImageOutlineActor* cpExtensions::Visualization::ImageSliceActors::
72 GetImageOutlineActor( )
73 {
74   return( this->m_ImageOutlineActor.GetPointer( ) );
75 }
76
77 // -------------------------------------------------------------------------
78 const cpExtensions::Visualization::
79 ImageOutlineActor* cpExtensions::Visualization::ImageSliceActors::
80 GetImageOutlineActor( ) const
81 {
82   return( this->m_ImageOutlineActor.GetPointer( ) );
83 }
84
85 // -------------------------------------------------------------------------
86 int cpExtensions::Visualization::ImageSliceActors::
87 GetOrientation( ) const
88 {
89   if( this->m_WindowLevelImageActor.GetPointer( ) != NULL )
90     return( this->m_WindowLevelImageActor->GetOrientation( ) );
91   else
92     return( 0 );
93 }
94
95 // -------------------------------------------------------------------------
96 void cpExtensions::Visualization::ImageSliceActors::
97 SetImage( vtkImageData* image, int orientation )
98 {
99   this->m_WindowLevelImageActor =
100     vtkSmartPointer< WindowLevelImageActor >::New( );
101   this->m_WindowLevelImageActor->SetImage( image );
102   this->m_WindowLevelImageActor->SetOrientation( orientation );
103   this->m_ImageOutlineActor = vtkSmartPointer< ImageOutlineActor >::New( );
104   this->m_LUTImageActor = NULL;
105
106   // Put an initial slice
107   int ext[ 6 ];
108   image->GetExtent( ext );
109   this->SetSliceNumber(
110     ext[ this->m_WindowLevelImageActor->GetOrientation( ) << 1 ]
111     );
112
113   // Update collection
114   this->RemoveAllItems( );
115   this->AddItem( this->m_ImageOutlineActor );
116   this->AddItem( this->m_WindowLevelImageActor );
117 }
118
119 // -------------------------------------------------------------------------
120 unsigned int cpExtensions::Visualization::ImageSliceActors::
121 AddLUTImage( vtkImageData* image )
122 {
123   if( this->GetImage( ) != NULL )
124   {
125     if( this->m_LUTImageActor.GetPointer( ) == NULL )
126     {
127       this->m_LUTImageActor = vtkSmartPointer< LUTImageActor >::New( );
128       this->m_LUTImageActor->SetOrientation( this->GetOrientation( ) );
129       this->AddItem( this->m_LUTImageActor );
130
131     } // fi
132     this->m_LUTImageActor->AddImage( image );
133     return( this->m_LUTImageActor->GetNumberOfImages( ) );
134   }
135   else
136     return( 0 );
137 }
138
139 // -------------------------------------------------------------------------
140 int cpExtensions::Visualization::ImageSliceActors::
141 GetSliceNumber( ) const
142 {
143   return( this->m_WindowLevelImageActor->GetSliceNumber( ) );
144 }
145
146 // -------------------------------------------------------------------------
147 void cpExtensions::Visualization::ImageSliceActors::
148 SetSliceNumber( int slice )
149 {
150   this->m_WindowLevelImageActor->SetSliceNumber( slice );
151   if( this->m_LUTImageActor.GetPointer( ) != NULL )
152     this->m_LUTImageActor->SetSliceNumber( slice );
153
154   double bounds[ 6 ];
155   this->m_WindowLevelImageActor->GetImage( )->GetBounds( bounds );
156   int o = this->m_WindowLevelImageActor->GetOrientation( );
157   double p = this->m_WindowLevelImageActor->GetSlicePlane( )->GetOrigin( )[ o ];
158   this->m_ImageOutlineActor->SetBounds( o, p, bounds );
159 }
160
161 // -------------------------------------------------------------------------
162 cpExtensions::Visualization::ImageSliceActors::
163 ImageSliceActors( )
164   : Superclass( )
165 {
166 }
167
168 // -------------------------------------------------------------------------
169 cpExtensions::Visualization::ImageSliceActors::
170 ~ImageSliceActors( )
171 {
172 }
173
174 // eof - $RCSfile$