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 cpPluginsWidgets::SplineWidget::
35 typedef cpPlugins::BaseObjects::DataObject _TData;
36 typedef cpPlugins::DataObjects::Mesh _TMesh;
38 this->_ConfigureInput< _TData >( "Input", false, false );
39 this->_ConfigureOutput< _TMesh >( "Output" );
40 this->m_Contour = vtkSmartPointer< vtkPolyData >::New( );
41 this->m_Contour->SetPoints( vtkSmartPointer< vtkPoints >::New( ) );
42 this->m_Contour->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) );
43 this->m_Contour->SetLines( vtkSmartPointer< vtkCellArray >::New( ) );
44 this->m_Contour->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) );
45 this->m_Contour->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) );
46 this->GetOutput( "Output" )->SetVTK( this->m_Contour );
49 // -------------------------------------------------------------------------
50 cpPluginsWidgets::SplineWidget::
55 // -------------------------------------------------------------------------
56 void cpPluginsWidgets::SplineWidget::
59 typedef cpExtensions::Visualization::WindowLevelImageActor _TActor;
61 auto image = this->GetInputData< vtkImageData >( "Input" );
63 this->_Error( "Invalid input image." );
64 if( this->m_Interactors.size( ) == 0 )
65 this->_Error( "Give at least one interactor." );
67 auto wdg = this->_CreateVTK< vtkSplineWidget >( );
68 if( this->m_Configured )
70 wdg->GetPolyData( this->m_Contour.GetPointer( ) );
74 auto iIt = this->m_Interactors.begin( );
75 vtkRenderWindowInteractor* iren = NULL;
76 vtkRenderer* ren = NULL;
77 _TActor* actor = NULL;
78 for( ; iIt != this->m_Interactors.end( ); ++iIt )
80 auto r = ( *iIt )->GetInteractorStyle( )->GetCurrentRenderer( );
83 auto props = r->GetViewProps( );
86 props->InitTraversal( );
87 while( vtkProp* prop = props->GetNextProp( ) )
89 auto a = dynamic_cast< _TActor* >( prop );
91 if( a->GetImage( ) == image )
106 if( actor == NULL || ren == NULL || iren == NULL )
107 this->_Error( "Invalid actor and/or renderer." );
109 // Widget configuration
110 wdg->SetCurrentRenderer( ren );
111 wdg->SetDefaultRenderer( ren );
112 wdg->SetInputData( image );
113 wdg->SetProp3D( actor );
114 wdg->SetInteractor( iren );
116 image->GetBounds( bnds );
118 bnds[ 0 ], bnds[ 1 ],
119 bnds[ 2 ], bnds[ 3 ],
122 wdg->ProjectToPlaneOn( );
123 wdg->SetProjectionNormalToZAxes( );
124 wdg->SetProjectionPosition(
126 actor->GetBounds( )[ 4 ] +
127 actor->GetBounds( )[ 5 ]
130 wdg->SetHandleSize( 0.005 );
131 wdg->SetNumberOfHandles( 3 );
132 this->m_Configured = true;