]> Creatis software - cpPlugins.git/blob - plugins/cpPluginsWidgets/SeedWidget.cxx
64069e4ce4602c971cde376a7600b3a23b5c411f
[cpPlugins.git] / plugins / cpPluginsWidgets / SeedWidget.cxx
1 #include "SeedWidget.h"
2
3 #include <vtkProperty.h>
4 #include <vtkRenderWindowInteractor.h>
5 #include <cpExtensions/QT/SimpleMPRWidget.h>
6
7 // -------------------------------------------------------------------------
8 void cpPluginsWidgets::SeedWidget::WidgetData::
9 Configure( vtkRenderWindowInteractor* interactor, vtkImageActor* actor )
10 {
11   this->Placer = vtkSmartPointer< vtkImageActorPointPlacer >::New( );
12   this->Handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( );
13   this->Seed = vtkSmartPointer< vtkSeedRepresentation >::New( );
14   this->Widget =
15     vtkSmartPointer< cpExtensions::Interaction::SeedWidget >::New( );
16
17   this->Placer->SetImageActor( actor );
18   this->Handle->GetProperty( )->SetColor( 1, 0, 0 );
19   this->Handle->SetPointPlacer( this->Placer );
20   this->Seed->SetHandleRepresentation( this->Handle );
21   this->Widget->SetRepresentation( this->Seed );
22   this->Widget->SetInteractor( interactor );
23 }
24
25 // -------------------------------------------------------------------------
26 void cpPluginsWidgets::SeedWidget::WidgetData::
27 On( )
28 {
29   this->Widget->On( );
30 }
31
32 // -------------------------------------------------------------------------
33 void cpPluginsWidgets::SeedWidget::WidgetData::
34 Off( )
35 {
36   this->Widget->Off( );
37 }
38
39 // -------------------------------------------------------------------------
40 itk::ModifiedTimeType cpPluginsWidgets::SeedWidget::
41 GetMTime( ) const
42 {
43   this->Modified( );
44   return( this->Superclass::GetMTime( ) );
45 }
46
47 // -------------------------------------------------------------------------
48 cpPluginsWidgets::SeedWidget::
49 SeedWidget( )
50   : Superclass( ),
51     m_Configured( false )
52 {
53   this->_AddOutput< cpPlugins::DataObject >( "Output" );
54 }
55
56 // -------------------------------------------------------------------------
57 cpPluginsWidgets::SeedWidget::
58 ~SeedWidget( )
59 {
60 }
61
62 // -------------------------------------------------------------------------
63 void cpPluginsWidgets::SeedWidget::
64 _GenerateData( )
65 {
66   if( this->m_Configured )
67   {
68     auto points = this->_CreateVTK< vtkPoints >( );
69     for(
70       auto wIt = this->m_Widgets.begin( );
71       wIt != this->m_Widgets.end( );
72       ++wIt
73       )
74     {
75       double pos[ 3 ];
76       for( unsigned int i = 0; i < wIt->Seed->GetNumberOfSeeds( ); ++i )
77       {
78         wIt->Seed->GetSeedWorldPosition( i, pos );
79         points->InsertNextPoint( pos );
80
81       } // rof
82
83     } // rof
84     this->GetOutput( "Output" )->SetVTK( points );
85   }
86   else
87   {
88     std::vector< vtkRenderWindowInteractor* > ints;
89     if( this->m_MPRViewer != NULL )
90     {
91       ints.push_back( this->m_MPRViewer->GetInteractor( 0 ) );
92       ints.push_back( this->m_MPRViewer->GetInteractor( 1 ) );
93       ints.push_back( this->m_MPRViewer->GetInteractor( 2 ) );
94
95     } // fi
96     if( this->m_SingleInteractor != NULL )
97       ints.push_back( this->m_SingleInteractor );
98
99     for( auto iIt = ints.begin( ); iIt !=  ints.end( ); ++iIt )
100     {
101       auto ren = ( *iIt )->GetInteractorStyle( )->GetCurrentRenderer( );
102       if( ren != NULL )
103       {
104         auto props = ren->GetViewProps( );
105         if( props != NULL )
106         {
107           props->InitTraversal( );
108           vtkProp* prop;
109           while( ( prop = props->GetNextProp( ) ) != NULL )
110           {
111             auto actor = dynamic_cast< vtkImageActor* >( prop );
112             if( actor != NULL )
113             {
114               WidgetData d;
115               d.Configure( *iIt, actor );
116               d.On( );
117               this->m_Widgets.push_back( d );
118               this->m_Configured = true;
119
120             } // fi
121
122           } // elihw
123
124         } // fi
125
126       } // fi
127
128     } // rof
129
130   } // fi
131   if( !( this->m_Configured ) )
132     this->_Error(
133       "Could not create valid widget: are there any valid actors?"
134       );
135 }
136
137 // eof - $RCSfile$