#include #include #include #include #include #include #include // ------------------------------------------------------------------------- cpPluginsWidgets::SplineWidget:: SplineWidget( ) : Superclass( ), m_Configured( false ) { typedef cpPlugins::BaseObjects::DataObject _TData; typedef cpPlugins::DataObjects::Mesh _TMesh; this->_ConfigureInput< _TData >( "Input", false, false ); this->_ConfigureOutput< _TMesh >( "Output" ); this->m_Contour = vtkSmartPointer< vtkPolyData >::New( ); this->m_Contour->SetPoints( vtkSmartPointer< vtkPoints >::New( ) ); this->m_Contour->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) ); this->m_Contour->SetLines( vtkSmartPointer< vtkCellArray >::New( ) ); this->m_Contour->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) ); this->m_Contour->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) ); this->GetOutput( "Output" )->SetVTK( this->m_Contour ); } // ------------------------------------------------------------------------- cpPluginsWidgets::SplineWidget:: ~SplineWidget( ) { } // ------------------------------------------------------------------------- void cpPluginsWidgets::SplineWidget:: _GenerateData( ) { typedef cpExtensions::Visualization::WindowLevelImageActor _TActor; auto image = this->GetInputData< vtkImageData >( "Input" ); if( image == NULL ) this->_Error( "Invalid input image." ); if( this->m_Interactors.size( ) == 0 ) this->_Error( "Give at least one interactor." ); auto wdg = this->_CreateVTK< vtkSplineWidget >( ); if( this->m_Configured ) { wdg->GetPolyData( this->m_Contour.GetPointer( ) ); wdg->Off( ); } else { auto iIt = this->m_Interactors.begin( ); vtkRenderWindowInteractor* iren = NULL; vtkRenderer* ren = NULL; _TActor* actor = NULL; for( ; iIt != this->m_Interactors.end( ); ++iIt ) { auto r = ( *iIt )->GetInteractorStyle( )->GetCurrentRenderer( ); if( r != NULL ) { auto props = r->GetViewProps( ); if( props != NULL ) { props->InitTraversal( ); while( vtkProp* prop = props->GetNextProp( ) ) { auto a = dynamic_cast< _TActor* >( prop ); if( a != NULL ) if( a->GetImage( ) == image ) { iren = *iIt; actor = a; ren = r; } // fi } // elihw } // fi } // fi } // rof if( actor == NULL || ren == NULL || iren == NULL ) this->_Error( "Invalid actor and/or renderer." ); // Widget configuration wdg->SetCurrentRenderer( ren ); wdg->SetDefaultRenderer( ren ); wdg->SetInputData( image ); wdg->SetProp3D( actor ); wdg->SetInteractor( iren ); double bnds[ 6 ]; image->GetBounds( bnds ); wdg->PlaceWidget( bnds[ 0 ], bnds[ 1 ], bnds[ 2 ], bnds[ 3 ], bnds[ 4 ], bnds[ 5 ] ); wdg->ProjectToPlaneOn( ); wdg->SetProjectionNormalToZAxes( ); wdg->SetProjectionPosition( ( actor->GetBounds( )[ 4 ] + actor->GetBounds( )[ 5 ] ) / double( 2 ) ); wdg->SetHandleSize( 0.005 ); wdg->SetNumberOfHandles( 3 ); wdg->On( ); this->m_Configured = true; } // fi } // eof - $RCSfile$