1 #include <plugins/Widgets/SplineWidget.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Mesh.h>
4 #include <cpExtensions/Visualization/WindowLevelImageActor.h>
6 #include <vtkImageData.h>
7 #include <vtkRenderer.h>
8 #include <vtkSplineWidget.h>
10 // -------------------------------------------------------------------------
11 void cpPluginsWidgets::SplineWidget::
16 // -------------------------------------------------------------------------
17 void cpPluginsWidgets::SplineWidget::
20 auto wdg = this->GetVTK< vtkSplineWidget >( );
24 wdg->GetInteractor( )->Render( );
29 // -------------------------------------------------------------------------
30 bool cpPluginsWidgets::SplineWidget::
33 auto wdg = this->GetVTK< const vtkSplineWidget >( );
36 vtkSplineWidget* w = const_cast< vtkSplineWidget* >( wdg );
37 return( w->GetEnabled( ) != 0 );
43 // -------------------------------------------------------------------------
44 cpPluginsWidgets::SplineWidget::
49 typedef cpPlugins::BaseObjects::DataObject _TData;
50 typedef cpPlugins::DataObjects::Mesh _TMesh;
52 this->_ConfigureInput< _TData >( "Input", false, false );
53 this->_ConfigureOutput< _TMesh >( "Output" );
54 this->m_Contour = vtkSmartPointer< vtkPolyData >::New( );
55 this->m_Contour->SetPoints( vtkSmartPointer< vtkPoints >::New( ) );
56 this->m_Contour->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) );
57 this->m_Contour->SetLines( vtkSmartPointer< vtkCellArray >::New( ) );
58 this->m_Contour->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) );
59 this->m_Contour->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) );
60 this->GetOutput( "Output" )->SetVTK( this->m_Contour );
63 // -------------------------------------------------------------------------
64 cpPluginsWidgets::SplineWidget::
69 // -------------------------------------------------------------------------
70 void cpPluginsWidgets::SplineWidget::
73 typedef cpExtensions::Visualization::WindowLevelImageActor _TActor;
75 auto image = this->GetInputData< vtkImageData >( "Input" );
77 this->_Error( "Invalid input image." );
78 if( this->m_Interactors.size( ) == 0 )
79 this->_Error( "Give at least one interactor." );
81 auto wdg = this->_CreateVTK< vtkSplineWidget >( );
82 if( this->m_Configured )
84 wdg->GetPolyData( this->m_Contour.GetPointer( ) );
88 auto iIt = this->m_Interactors.begin( );
89 vtkRenderWindowInteractor* iren = NULL;
90 vtkRenderer* ren = NULL;
91 _TActor* actor = NULL;
92 for( ; iIt != this->m_Interactors.end( ); ++iIt )
94 auto r = ( *iIt )->GetInteractorStyle( )->GetCurrentRenderer( );
97 auto props = r->GetViewProps( );
100 props->InitTraversal( );
101 while( vtkProp* prop = props->GetNextProp( ) )
103 auto a = dynamic_cast< _TActor* >( prop );
105 if( a->GetImage( ) == image )
120 if( actor == NULL || ren == NULL || iren == NULL )
121 this->_Error( "Invalid actor and/or renderer." );
123 // Widget configuration
124 wdg->SetCurrentRenderer( ren );
125 wdg->SetDefaultRenderer( ren );
126 wdg->SetInputData( image );
127 wdg->SetProp3D( actor );
128 wdg->SetInteractor( iren );
130 image->GetBounds( bnds );
132 bnds[ 0 ], bnds[ 1 ],
133 bnds[ 2 ], bnds[ 3 ],
136 wdg->ProjectToPlaneOn( );
137 wdg->SetProjectionNormalToZAxes( );
138 wdg->SetProjectionPosition(
140 actor->GetBounds( )[ 4 ] +
141 actor->GetBounds( )[ 5 ]
144 wdg->SetHandleSize( 0.005 );
145 wdg->SetNumberOfHandles( 3 );
146 this->m_Configured = true;