]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/CursorActors.cxx
Cast image filter added. ROI filter modified.
[cpPlugins.git] / lib / cpExtensions / Visualization / CursorActors.cxx
1 #include <cpExtensions/Visualization/CursorActors.h>
2 #include <cpExtensions/Visualization/LineSource.h>
3
4 #include <vtkActor.h>
5 #include <vtkPolyDataMapper.h>
6
7 // -------------------------------------------------------------------------
8 cpExtensions::Visualization::CursorActors::
9 Self* cpExtensions::Visualization::CursorActors::
10 New( )
11 {
12   return( new Self( ) );
13 }
14
15 // -------------------------------------------------------------------------
16 void cpExtensions::Visualization::CursorActors::
17 Modified( )
18 {
19   for( unsigned int i = 0; i < 2; ++i )
20   {
21     if( this->m_Lines[ i ].GetPointer( ) != NULL )
22     {
23       this->m_Lines[ i ]->Modified( );
24       this->m_Mappers[ i ]->Modified( );
25       this->m_Actors[ i ]->Modified( );
26
27     } // fi
28
29   } // rof
30   this->Superclass::Modified( );
31 }
32
33 // -------------------------------------------------------------------------
34 void cpExtensions::Visualization::CursorActors::
35 SetImageBounds( double* bounds )
36 {
37   this->m_Bounds[ 0 ] = bounds[ 0 ];
38   this->m_Bounds[ 1 ] = bounds[ 1 ];
39   this->m_Bounds[ 2 ] = bounds[ 2 ];
40   this->m_Bounds[ 3 ] = bounds[ 3 ];
41   this->m_Bounds[ 4 ] = bounds[ 4 ];
42   this->m_Bounds[ 5 ] = bounds[ 5 ];
43 }
44
45 // -------------------------------------------------------------------------
46 void cpExtensions::Visualization::CursorActors::
47 SetImageOrientation( int orientation )
48 {
49   this->m_Orientation = orientation % 3;
50 }
51
52 // -------------------------------------------------------------------------
53 void cpExtensions::Visualization::CursorActors::
54 SetCursor( double* pos, bool neg )
55 {
56   static const double _eps = 1e-3;
57   double pnts[ 4 ][ 3 ];
58   if( this->m_Orientation == 0 )
59   {
60     pnts[ 0 ][ 1 ] = this->m_Bounds[ 2 ];
61     pnts[ 1 ][ 1 ] = this->m_Bounds[ 3 ];
62     pnts[ 0 ][ 2 ] = pnts[ 1 ][ 2 ] = pos[ 2 ];
63
64     pnts[ 2 ][ 1 ] = pnts[ 3 ][ 1 ] = pos[ 1 ];
65     pnts[ 2 ][ 2 ] = this->m_Bounds[ 4 ];
66     pnts[ 3 ][ 2 ] = this->m_Bounds[ 5 ];
67
68     pnts[ 0 ][ 0 ] = pnts[ 1 ][ 0 ] =
69       pnts[ 2 ][ 0 ] = pnts[ 3 ][ 0 ] =
70       pos[ 0 ] + ( double( neg? -1: 1 ) * _eps );
71   }
72   else if( this->m_Orientation == 1 )
73   {
74     pnts[ 0 ][ 0 ] = pnts[ 1 ][ 0 ] = pos[ 0 ];
75     pnts[ 0 ][ 2 ] = this->m_Bounds[ 4 ];
76     pnts[ 1 ][ 2 ] = this->m_Bounds[ 5 ];
77
78     pnts[ 2 ][ 0 ] = this->m_Bounds[ 0 ];
79     pnts[ 3 ][ 0 ] = this->m_Bounds[ 1 ];
80     pnts[ 2 ][ 2 ] = pnts[ 3 ][ 2 ] = pos[ 2 ];
81
82     pnts[ 0 ][ 1 ] = pnts[ 1 ][ 1 ] =
83       pnts[ 2 ][ 1 ] = pnts[ 3 ][ 1 ] =
84       pos[ 1 ] + ( double( neg? -1: 1 ) * _eps );
85   }
86   else if( this->m_Orientation == 2 )
87   {
88     pnts[ 0 ][ 0 ] = this->m_Bounds[ 0 ];
89     pnts[ 1 ][ 0 ] = this->m_Bounds[ 1 ];
90     pnts[ 0 ][ 1 ] = pnts[ 1 ][ 1 ] = pos[ 1 ];
91
92     pnts[ 2 ][ 0 ] = pnts[ 3 ][ 0 ] = pos[ 0 ];
93     pnts[ 2 ][ 1 ] = this->m_Bounds[ 2 ];
94     pnts[ 3 ][ 1 ] = this->m_Bounds[ 3 ];
95
96     pnts[ 0 ][ 2 ] = pnts[ 1 ][ 2 ] =
97       pnts[ 2 ][ 2 ] = pnts[ 3 ][ 2 ] =
98       pos[ 2 ] + ( double( neg? -1: 1 ) * _eps );
99
100   } // fi
101
102   this->m_Lines[ 0 ]->SetPoint1( pnts[ 0 ] );
103   this->m_Lines[ 0 ]->SetPoint2( pnts[ 1 ] );
104   this->m_Lines[ 1 ]->SetPoint1( pnts[ 2 ] );
105   this->m_Lines[ 1 ]->SetPoint2( pnts[ 3 ] );
106   this->Modified( );
107 }
108
109 // -------------------------------------------------------------------------
110 vtkProperty* cpExtensions::Visualization::CursorActors::
111 GetProperty( unsigned int i )
112 {
113   return( this->m_Actors[ i % 2 ]->GetProperty( ) );
114 }
115
116 // -------------------------------------------------------------------------
117 const vtkProperty* cpExtensions::Visualization::CursorActors::
118 GetProperty( unsigned int i ) const
119 {
120   return( this->m_Actors[ i % 2 ]->GetProperty( ) );
121 }
122
123 // -------------------------------------------------------------------------
124 void cpExtensions::Visualization::CursorActors::
125 SetVisibility( int v )
126 {
127   this->m_Actors[ 0 ]->SetVisibility( v );
128   this->m_Actors[ 1 ]->SetVisibility( v );
129 }
130
131 // -------------------------------------------------------------------------
132 void cpExtensions::Visualization::CursorActors::
133 VisibilityOn( )
134 {
135   this->m_Actors[ 0 ]->VisibilityOn( );
136   this->m_Actors[ 1 ]->VisibilityOn( );
137 }
138
139 // -------------------------------------------------------------------------
140 void cpExtensions::Visualization::CursorActors::
141 VisibilityOff( )
142 {
143   this->m_Actors[ 0 ]->VisibilityOff( );
144   this->m_Actors[ 1 ]->VisibilityOff( );
145 }
146
147 // -------------------------------------------------------------------------
148 cpExtensions::Visualization::CursorActors::
149 CursorActors( )
150   : Superclass( )
151 {
152   this->m_Bounds[ 0 ] = this->m_Bounds[ 1 ] = this->m_Bounds[ 2 ] =
153     this->m_Bounds[ 3 ] = this->m_Bounds[ 4 ] = this->m_Bounds[ 5 ] =
154     double( 0 );
155
156   for( unsigned int i = 0; i < 2; ++i )
157   {
158     this->m_Lines[ i ] = vtkSmartPointer< LineSource >::New( );
159     this->m_Mappers[ i ] = vtkSmartPointer< vtkPolyDataMapper >::New( );
160     this->m_Actors[ i ] = vtkSmartPointer< vtkActor >::New( );
161     this->m_Mappers[ i ]->SetInputConnection(
162       this->m_Lines[ i ]->GetOutputPort( )
163       );
164     this->m_Actors[ i ]->SetMapper( this->m_Mappers[ i ] );
165     this->AddItem( this->m_Actors[ i ] );
166
167   } // rof
168 }
169
170 // -------------------------------------------------------------------------
171 cpExtensions::Visualization::CursorActors::
172 ~CursorActors( )
173 {
174 }
175
176 // eof - $RCSfile$