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 cpPluginsWidgets::SplineWidget::
16 typedef cpPlugins::BaseObjects::DataObject _TData;
17 typedef cpPlugins::DataObjects::Mesh _TMesh;
19 this->_ConfigureInput< _TData >( "Input", false, false );
20 this->_ConfigureOutput< _TMesh >( "Output" );
21 this->m_Contour = vtkSmartPointer< vtkPolyData >::New( );
22 this->m_Contour->SetPoints( vtkSmartPointer< vtkPoints >::New( ) );
23 this->m_Contour->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) );
24 this->m_Contour->SetLines( vtkSmartPointer< vtkCellArray >::New( ) );
25 this->m_Contour->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) );
26 this->m_Contour->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) );
27 this->GetOutput( "Output" )->SetVTK( this->m_Contour );
30 // -------------------------------------------------------------------------
31 cpPluginsWidgets::SplineWidget::
36 // -------------------------------------------------------------------------
37 void cpPluginsWidgets::SplineWidget::
40 typedef cpExtensions::Visualization::WindowLevelImageActor _TActor;
42 auto image = this->GetInputData< vtkImageData >( "Input" );
44 this->_Error( "Invalid input image." );
45 if( this->m_Interactors.size( ) == 0 )
46 this->_Error( "Give at least one interactor." );
48 auto wdg = this->_CreateVTK< vtkSplineWidget >( );
49 if( this->m_Configured )
51 wdg->GetPolyData( this->m_Contour.GetPointer( ) );
56 auto iIt = this->m_Interactors.begin( );
57 vtkRenderWindowInteractor* iren = NULL;
58 vtkRenderer* ren = NULL;
59 _TActor* actor = NULL;
60 for( ; iIt != this->m_Interactors.end( ); ++iIt )
62 auto r = ( *iIt )->GetInteractorStyle( )->GetCurrentRenderer( );
65 auto props = r->GetViewProps( );
68 props->InitTraversal( );
69 while( vtkProp* prop = props->GetNextProp( ) )
71 auto a = dynamic_cast< _TActor* >( prop );
73 if( a->GetImage( ) == image )
88 if( actor == NULL || ren == NULL || iren == NULL )
89 this->_Error( "Invalid actor and/or renderer." );
91 // Widget configuration
92 wdg->SetCurrentRenderer( ren );
93 wdg->SetDefaultRenderer( ren );
94 wdg->SetInputData( image );
95 wdg->SetProp3D( actor );
96 wdg->SetInteractor( iren );
98 image->GetBounds( bnds );
100 bnds[ 0 ], bnds[ 1 ],
101 bnds[ 2 ], bnds[ 3 ],
104 wdg->ProjectToPlaneOn( );
105 wdg->SetProjectionNormalToZAxes( );
106 wdg->SetProjectionPosition(
108 actor->GetBounds( )[ 4 ] +
109 actor->GetBounds( )[ 5 ]
112 wdg->SetHandleSize( 0.005 );
113 wdg->SetNumberOfHandles( 3 );
115 this->m_Configured = true;