1 #include <cpExtensions/Visualization/CursorActors.h>
2 #include <cpExtensions/Visualization/LineSource.h>
5 #include <vtkPolyDataMapper.h>
7 // -------------------------------------------------------------------------
8 cpExtensions::Visualization::CursorActors::
9 Self* cpExtensions::Visualization::CursorActors::
12 return( new Self( ) );
15 // -------------------------------------------------------------------------
16 void cpExtensions::Visualization::CursorActors::
19 for( unsigned int i = 0; i < 2; ++i )
21 if( this->m_Lines[ i ].GetPointer( ) != NULL )
23 this->m_Lines[ i ]->Modified( );
24 this->m_Mappers[ i ]->Modified( );
25 this->m_Actors[ i ]->Modified( );
30 this->Superclass::Modified( );
33 // -------------------------------------------------------------------------
34 void cpExtensions::Visualization::CursorActors::
35 SetImageBounds( double* bounds )
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 ];
45 // -------------------------------------------------------------------------
46 void cpExtensions::Visualization::CursorActors::
47 SetImageOrientation( int orientation )
49 this->m_Orientation = orientation % 3;
52 // -------------------------------------------------------------------------
53 void cpExtensions::Visualization::CursorActors::
54 SetCursor( double* pos, bool neg )
56 static const double _eps = 1e-3;
57 double pnts[ 4 ][ 3 ];
58 if( this->m_Orientation == 0 )
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 ];
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 ];
68 pnts[ 0 ][ 0 ] = pnts[ 1 ][ 0 ] =
69 pnts[ 2 ][ 0 ] = pnts[ 3 ][ 0 ] =
70 pos[ 0 ] + ( double( neg? -1: 1 ) * _eps );
72 else if( this->m_Orientation == 1 )
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 ];
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 ];
82 pnts[ 0 ][ 1 ] = pnts[ 1 ][ 1 ] =
83 pnts[ 2 ][ 1 ] = pnts[ 3 ][ 1 ] =
84 pos[ 1 ] + ( double( neg? -1: 1 ) * _eps );
86 else if( this->m_Orientation == 2 )
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 ];
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 ];
96 pnts[ 0 ][ 2 ] = pnts[ 1 ][ 2 ] =
97 pnts[ 2 ][ 2 ] = pnts[ 3 ][ 2 ] =
98 pos[ 2 ] + ( double( neg? -1: 1 ) * _eps );
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 ] );
109 // -------------------------------------------------------------------------
110 vtkProperty* cpExtensions::Visualization::CursorActors::
111 GetProperty( unsigned int i )
113 return( this->m_Actors[ i % 2 ]->GetProperty( ) );
116 // -------------------------------------------------------------------------
117 const vtkProperty* cpExtensions::Visualization::CursorActors::
118 GetProperty( unsigned int i ) const
120 return( this->m_Actors[ i % 2 ]->GetProperty( ) );
123 // -------------------------------------------------------------------------
124 void cpExtensions::Visualization::CursorActors::
125 SetVisibility( int v )
127 this->m_Actors[ 0 ]->SetVisibility( v );
128 this->m_Actors[ 1 ]->SetVisibility( v );
131 // -------------------------------------------------------------------------
132 void cpExtensions::Visualization::CursorActors::
135 this->m_Actors[ 0 ]->VisibilityOn( );
136 this->m_Actors[ 1 ]->VisibilityOn( );
139 // -------------------------------------------------------------------------
140 void cpExtensions::Visualization::CursorActors::
143 this->m_Actors[ 0 ]->VisibilityOff( );
144 this->m_Actors[ 1 ]->VisibilityOff( );
147 // -------------------------------------------------------------------------
148 cpExtensions::Visualization::CursorActors::
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 ] =
156 for( unsigned int i = 0; i < 2; ++i )
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( )
164 this->m_Actors[ i ]->SetMapper( this->m_Mappers[ i ] );
165 this->AddItem( this->m_Actors[ i ] );
170 // -------------------------------------------------------------------------
171 cpExtensions::Visualization::CursorActors::