1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
27 //----------------------------------------------------------------------------------------------------------------
28 // Class definition include
29 //----------------------------------------------------------------------------------------------------------------
30 #include "wxVtkBaseView_SceneManager.h"
31 #include "wxVtk2DBaseView.h"
33 //----------------------------------------------------------------------------------------------------------------
34 // Class implementation
35 //----------------------------------------------------------------------------------------------------------------
36 /** @file wxVtkBaseView_SceneManager.cxx */
39 //------------------------------------------------------------------------------------------------------------
41 //------------------------------------------------------------------------------------------------------------
42 #include "wxContour_ActionCommandsID.h"
44 //------------------------------------------------------------------------------------------------------------
45 // Generated events declaration and definition
46 //------------------------------------------------------------------------------------------------------------
49 DEFINE_EVENT_TYPE( wxEVT_START_CREATE_MULT_ROI )
50 DEFINE_EVENT_TYPE( wxEVT_STOP_CREATE_MULT_ROI )
51 DEFINE_EVENT_TYPE( wxEVT_START_CREATE_ROI )
52 DEFINE_EVENT_TYPE( wxEVT_STOP_CREATE_ROI )
53 DEFINE_EVENT_TYPE( wxEVT_DELETE_ROI )
54 DEFINE_EVENT_TYPE( wxEVT_SELECTED_MULT_ROI )
55 DEFINE_EVENT_TYPE( wxEVT_SELECTED_ROI )
56 DEFINE_EVENT_TYPE( wxEVT_UNSLECTED_ROI )
57 DEFINE_EVENT_TYPE( wxEVT_MANUAL_HIDED_ROI )
58 DEFINE_EVENT_TYPE( wxEVT_MANUAL_SHOWED_ROI )
59 DEFINE_EVENT_TYPE( wxEVT_EDITING_ROI )
60 DEFINE_EVENT_TYPE( wxEVT_MOVING_ROI )
61 DEFINE_EVENT_TYPE( wxEVT_MOVING_ROI_POINT )
62 DEFINE_EVENT_TYPE( wxEVT_SELECTED_ROI_POINT )
63 DEFINE_EVENT_TYPE( wxEVT_UNSELECTED_ROI_POINT )
64 DEFINE_EVENT_TYPE( wxEVT_CHANGED_DEEP )
66 wxDEFINE_EVENT(wxEVT_START_CREATE_MULT_ROI, wxCommandEvent);
67 wxDEFINE_EVENT(wxEVT_STOP_CREATE_MULT_ROI, wxCommandEvent);
68 wxDEFINE_EVENT(wxEVT_START_CREATE_ROI, wxCommandEvent);
69 wxDEFINE_EVENT(wxEVT_STOP_CREATE_ROI, wxCommandEvent);
70 wxDEFINE_EVENT(wxEVT_DELETE_ROI, wxCommandEvent);
71 wxDEFINE_EVENT(wxEVT_SELECTED_MULT_ROI, wxCommandEvent);
72 wxDEFINE_EVENT(wxEVT_SELECTED_ROI, wxCommandEvent);
73 wxDEFINE_EVENT(wxEVT_UNSLECTED_ROI, wxCommandEvent);
74 wxDEFINE_EVENT(wxEVT_MANUAL_HIDED_ROI, wxCommandEvent);
75 wxDEFINE_EVENT(wxEVT_MANUAL_SHOWED_ROI, wxCommandEvent);
76 wxDEFINE_EVENT(wxEVT_EDITING_ROI, wxCommandEvent);
77 wxDEFINE_EVENT(wxEVT_MOVING_ROI, wxCommandEvent);
78 wxDEFINE_EVENT(wxEVT_MOVING_ROI_POINT, wxCommandEvent);
79 wxDEFINE_EVENT(wxEVT_SELECTED_ROI_POINT, wxCommandEvent);
80 wxDEFINE_EVENT(wxEVT_UNSELECTED_ROI_POINT, wxCommandEvent);
81 wxDEFINE_EVENT(wxEVT_CHANGED_DEEP, wxCommandEvent);
84 wxVtkBaseView_SceneManager :: wxVtkBaseView_SceneManager( wxVtkBaseView * theWxBaseViewToManage, wxEvtHandler * theEventHandler, double * spc )
86 _lastInteraction = NULL;
87 _lastInteractionName = "";
88 _eventHandler = theEventHandler;
91 _contours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
92 _sceneContours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
93 _workingGroup = new std::map< std::string, ContourWrap_ViewControl * >();
94 _creatingMULT_ROI = false;
96 _toIncludeAtInteractionGroup = false;
99 _drawingSelectionROI = false;
100 _showTextContour = false;
101 SetWidthContour( 3.0/2 );
102 _wxVtk_BaseView = theWxBaseViewToManage;
103 if( _wxVtk_BaseView!=NULL )
105 vtkInteractorStyleBaseView* theInteractorStyleBaseView = (vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView();
106 theInteractorStyleBaseView->AddInteractorStyleMaracas( this );
107 SetVtkInteractorStyleBaseView( theInteractorStyleBaseView );
109 configureSelectionROI( spc );
110 configureTextNumberOfContour();
113 //------------------------------------------------------------------------------------------------------------
114 wxVtkBaseView_SceneManager :: ~wxVtkBaseView_SceneManager()
116 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
117 int size = _contours_ViewControl->size();
118 for ( int i = 0; i<size; iter++ )
120 _contours_ViewControl->erase( iter );
123 _contours_ViewControl->clear();
124 delete _contours_ViewControl;
125 _workingGroup->clear();
126 delete _lastInteraction;
127 delete _workingGroup;
128 //delete _contours_ViewControl;
131 //------------------------------------------------------------------------------------------------------------
132 // Methods for capturing events
133 //------------------------------------------------------------------------------------------------------------
136 //------------------------------------------------------------------------------------------------------------
137 // Methods for sending events
138 //------------------------------------------------------------------------------------------------------------
139 void wxVtkBaseView_SceneManager :: sendEnvent( WXTYPE theEventType, std::string text )
141 if ( _eventHandler != NULL )
143 wxCommandEvent cevent( theEventType );
144 cevent.SetString( wxString( text.c_str(), wxConvUTF8) );
145 _eventHandler->ProcessEvent( cevent );
149 //------------------------------------------------------------------------------------------------------------
150 // Attributes getters and setters
151 //------------------------------------------------------------------------------------------------------------
152 void wxVtkBaseView_SceneManager :: setWxEventHandler( wxEvtHandler * theEventHandler )
154 _eventHandler = theEventHandler;
157 //------------------------------------------------------------------------------------------------------------
158 void wxVtkBaseView_SceneManager :: setWxVtkViewBase( wxVtkBaseView * theBaseView )
160 _wxVtk_BaseView = theBaseView;
163 //------------------------------------------------------------------------------------------------------------
164 wxVtkBaseView * wxVtkBaseView_SceneManager :: getWxVtkViewBase()
166 return _wxVtk_BaseView;
169 //------------------------------------------------------------------------------------------------------------
170 void wxVtkBaseView_SceneManager::configureViewControlTo( std::string theKeyName, manualBaseModel * manModelContour, double * spc,int typeContour)
172 //setControlActiveStateOfALL( false );
175 if( _lastInteraction!=NULL )
177 _lastInteraction->getControler()->SetEditable( false );
178 _lastInteraction->getViewer()->Refresh();
179 _lastInteraction->getControler()->SetActive( false );
180 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
182 manualContourBaseControler *manContourControl;
183 manualViewBaseContour *manViewerContour;
184 // Creating the view manualViewContour and the manualContourControler
185 // NOTE: The model is created in the KernelManagerContour class, factoryManualContourModel method
188 manContourControl = new manualContourControler();
189 manViewerContour = new manualViewContour();
194 manContourControl = new manualRoiControler();
195 manViewerContour = new manualViewRoi();
200 manContourControl = new manualCircleControler();
201 manViewerContour = new manualViewCircle();
206 manContourControl = new manualRoiControler();
207 manViewerContour = new manualViewBullEye();
212 manContourControl = new manualLineControler();
213 manViewerContour = new manualViewLine();
219 manContourControl = new manualContourControler();
220 manViewerContour = new manualViewPoints();
226 manContourControl = new manualContourControler();
227 manViewerContour = new manualViewContour();
232 _lastInteraction = insertWrap( theKeyName, manContourControl, manViewerContour );
233 _lastInteractionName = theKeyName;
235 //Configuring the relations between the contour members representation
236 manViewerContour->SetModel( manModelContour );
237 manViewerContour->SetWxVtkBaseView( _wxVtk_BaseView );
238 manViewerContour->SetRange( _widthOfControlPoint );
239 manViewerContour->SetZ( -900 );
241 manViewerContour->SetSpacing(spc);
243 manViewerContour->SetColorNormalContour(0, 0, 1);
244 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
245 manViewerContour->SetColorSelectContour(1, 0.8, 0);
246 manViewerContour->SetWidthLine(_widthOfContour);
248 manContourControl->SetModelView( manModelContour , manViewerContour );
249 manContourControl->Configure();
250 int i,sizeLstPoints = manModelContour->GetSizeLstPoints();
251 for ( i=0; i<sizeLstPoints; i++ )
253 manViewerContour->AddPoint();
256 manContourControl->CreateNewManualContour();
257 manViewerContour->RefreshContour();
258 addToScene( theKeyName );
260 //------------------------------------------------------------------------------------------------------------
261 void wxVtkBaseView_SceneManager :: configureSelectionROI( double * spc )
263 _controlerSelectionROI = new manualRoiControler();
264 _viewerSelectionROI = new manualViewRoi();
265 _modelSelectionROI = new manualContourModel();
267 _viewerSelectionROI->SetModel( _modelSelectionROI );
268 _viewerSelectionROI->SetWxVtkBaseView( _wxVtk_BaseView );
269 _viewerSelectionROI->SetRange( 2 );
270 _viewerSelectionROI->SetZ( -900 );
271 _viewerSelectionROI->SetColorNormalContour(0.6, 0.8, 0);
273 _viewerSelectionROI->SetSpacing( spc );
275 _controlerSelectionROI->SetModelView( _modelSelectionROI , _viewerSelectionROI );
276 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _controlerSelectionROI );
277 _controlerSelectionROI->SetActive(false);
280 //------------------------------------------------------------------------------------------------------------
281 void wxVtkBaseView_SceneManager::configureTextNumberOfContour()
284 vtkTextActor *textActor = vtkTextActor::New();
285 textActor->SetDisplayPosition(10, 85);
286 textActor->SetInput("contours:--");
287 // Set coordinates to match the old vtkScaledTextActor default value
288 textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
289 textActor->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
290 vtkTextProperty *tprop = textActor->GetTextProperty();
291 tprop->SetFontSize(14);
292 tprop->SetFontFamilyToArial();
293 tprop->SetColor(1, 1, 0);
294 _wxVtk_BaseView->GetRenderer()->AddActor2D(textActor);
295 _numberOfContoursTextActor=textActor;
298 //------------------------------------------------------------------------------------------------------------
299 void wxVtkBaseView_SceneManager::SetLabelNumberOfContours( std::string label )
301 _numberOfContoursTextActor->SetInput( label.c_str() );
304 //------------------------------------------------------------------------------------------------------------
305 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: insertWrap( std::string theKeyName, manualContourBaseControler * manContourControl, manualViewBaseContour * manViewerContour )
307 ContourWrap_ViewControl * newContourWrap = new ContourWrap_ViewControl(manContourControl, manViewerContour);
308 if(_contours_ViewControl == NULL)
310 _contours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
312 _contours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, newContourWrap ));
313 return newContourWrap;
316 //------------------------------------------------------------------------------------------------------------
317 void wxVtkBaseView_SceneManager :: desconfigureViewControlOf( std::string theKeyName )
321 //------------------------------------------------------------------------------------------------------------
322 void wxVtkBaseView_SceneManager :: removeWrap( std::string theKeyName )
324 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
325 iter = _contours_ViewControl->find( theKeyName );
326 _contours_ViewControl->erase( iter );
327 _lastInteraction=NULL;
328 _lastInteractionName = "";
329 _workingGroup->clear();
330 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
331 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
334 //------------------------------------------------------------------------------------------------------------
335 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName )
337 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
338 iter = _contours_ViewControl->find( theName );
340 //return iter->first;
343 //------------------------------------------------------------------------------------------------------------
344 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName, std::map<std::string, ContourWrap_ViewControl *> * theMap )
346 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
347 iter = theMap->find( theName );
351 //------------------------------------------------------------------------------------------------------------
352 manualContourBaseControler * wxVtkBaseView_SceneManager :: getControlerOf( std::string theName )
354 return getContourWrap_ViewControlOf ( theName )->getControler();
357 //------------------------------------------------------------------------------------------------------------
358 manualViewBaseContour * wxVtkBaseView_SceneManager :: getViewerOf( std::string theName )
360 return getContourWrap_ViewControlOf ( theName )->getViewer();
363 //------------------------------------------------------------------------------------------------------------
364 void wxVtkBaseView_SceneManager :: set_creatingMULT_ROI( bool condition )
366 _creatingMULT_ROI = condition;
369 //------------------------------------------------------------------------------------------------------------
370 void wxVtkBaseView_SceneManager :: set_editingROI( bool condition )
372 _editingROI = condition;
375 //------------------------------------------------------------------------------------------------------------
376 void wxVtkBaseView_SceneManager :: set_toIncludeAtInteractionGroup( bool condition )
378 _toIncludeAtInteractionGroup = condition;
381 //------------------------------------------------------------------------------------------------------------
382 void wxVtkBaseView_SceneManager :: set_waiting( bool condition )
384 _waiting = condition;
387 //------------------------------------------------------------------------------------------------------------
388 bool wxVtkBaseView_SceneManager :: get_creatingMULT_ROI( )
390 return _creatingMULT_ROI;
393 //------------------------------------------------------------------------------------------------------------
394 bool wxVtkBaseView_SceneManager :: get_editingROI( )
399 //------------------------------------------------------------------------------------------------------------
400 bool wxVtkBaseView_SceneManager :: get_toIncludeAtInteractionGroup( )
402 return _toIncludeAtInteractionGroup;
405 //------------------------------------------------------------------------------------------------------------
406 bool wxVtkBaseView_SceneManager :: get_waiting( )
411 //------------------------------------------------------------------------------------------------------------
412 bool wxVtkBaseView_SceneManager :: get_creatingROI()
416 //------------------------------------------------------------------------------------------------------------
417 void wxVtkBaseView_SceneManager :: set_creatingROI( bool condition )
419 _creatingROI = condition;
422 //------------------------------------------------------------------------------------------------------------
423 // Other functional methods
424 //------------------------------------------------------------------------------------------------------------
426 void wxVtkBaseView_SceneManager :: createCopyContourOf( std::string anExistingKName, std::string cloneName, manualBaseModel * manualModel, bool append )
430 setControlActiveStateOf( _workingGroup, false );
431 _workingGroup->clear();
433 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
436 iter = _contours_ViewControl->find( anExistingKName );
438 manualBaseModel *cModule = manualModel;
439 manualViewBaseContour *cViewer = iter->second->getViewer()->Clone();
440 manualContourBaseControler *cControl = iter->second->getControler()->Clone( );
442 cViewer->SetModel(cModule);
443 cControl->SetModelView( cModule , cViewer );
444 cControl->CreateNewManualContour();
445 cControl->SetActive( true );
446 cControl->SetEditable( false );
448 cViewer->RefreshContour();
450 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
451 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
453 _lastInteraction = insertWrap( cloneName, cControl, cViewer );
454 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( cloneName, _lastInteraction ));
455 addToScene( cloneName );
458 //------------------------------------------------------------------------------------------------------------
460 void wxVtkBaseView_SceneManager :: removeFromScene( ContourWrap_ViewControl * contourWRP, bool visualization, bool control )
462 if( contourWRP == _lastInteraction )
464 _lastInteraction = NULL;
465 _lastInteractionName = "";
469 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->RemoveInteractorStyleMaracas( contourWRP->getControler() );
471 contourWRP->getControler()->SetActive( control );
472 contourWRP->getControler()->SetEditable( false );
474 if ( !visualization && control )
476 contourWRP->getViewer()->RemoveControlPoints( );
477 contourWRP->getViewer()->RemoveTextActor( );
481 contourWRP->getViewer()->RemoveCompleteContourActor();
485 //------------------------------------------------------------------------------------------------------------
486 void wxVtkBaseView_SceneManager :: removeFromScene( std::string theKeyName, bool visualization , bool control )
489 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
490 iter = _sceneContours_ViewControl->find( theKeyName );
491 if (iter != _sceneContours_ViewControl->end())
493 ContourWrap_ViewControl * contourWRP = iter->second;
494 removeFromScene( contourWRP );
495 _sceneContours_ViewControl->erase(iter);
500 //------------------------------------------------------------------------------------------------------------
501 std::vector<std::string> wxVtkBaseView_SceneManager::GetlstContoursNameActualSlice()
503 std::vector<std::string> lstContoursNameActualSlice;
504 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
505 int i,size = _sceneContours_ViewControl->size();
506 for ( i = 0; i<size; i++ )
508 lstContoursNameActualSlice.push_back( iter->first );
511 return lstContoursNameActualSlice;
514 //------------------------------------------------------------------------------------------------------------
515 void wxVtkBaseView_SceneManager::removeSceneContours()
517 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
518 int size = _sceneContours_ViewControl->size();
519 for ( int i = 0; i<size; i++ )
521 removeFromScene( iter->second );
524 _sceneContours_ViewControl->clear();
525 //Removing the selection rectangle to avoid showing when it's innecesary
526 _controlerSelectionROI->SetActive( false );
527 _viewerSelectionROI->RemoveCompleteContourActor();
530 void wxVtkBaseView_SceneManager::removeAllOutlines()
532 manualViewBaseContour * cViewer;
533 manualContourBaseControler * cControler;
535 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
536 int i,size=_contours_ViewControl->size();
539 iter = _contours_ViewControl->begin();
540 cControler = iter->second->getControler();
541 cViewer = iter->second->getViewer();
542 removeWrap( iter->first );
550 //------------------------------------------------------------------------------------------------------------
551 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
555 removeSceneContours();
557 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
558 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
560 addToScene( theKeyName, contourWRP, true, visualization, control, ifActive, ifShowCtrlPoints);
563 //------------------------------------------------------------------------------------------------------------
564 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
568 removeSceneContours();
571 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
573 if ( visualization==true )
575 contourWRP->getViewer()->AddCompleteContourActor( ifShowCtrlPoints );
576 } // if visualization
580 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( contourWRP->getControler() );
585 contourWRP->getViewer()->SetColorNormalContour(1,0,0);
587 contourWRP->getViewer()->SetColorNormalContour(0,0,1);
592 contourWRP->getControler()->SetActive( true );
593 contourWRP->getViewer()->RemoveTextActor();
596 contourWRP->getViewer()->SetShowText(_showTextContour);
599 //------------------------------------------------------------------------------------------------------------
600 void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
602 int i, size = theKeyNameVector.size();
603 for( i=0; i< size; i++ )
605 removeFromScene( theKeyNameVector[i], visualization, control );
609 //------------------------------------------------------------------------------------------------------------
610 void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
612 int i, size = theKeyNameVector.size();
613 for( i=0; i< size; i++ )
615 addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
619 //------------------------------------------------------------------------------------------------------------
620 void wxVtkBaseView_SceneManager :: setControlActiveStateOfALL( bool stateCondition )
622 setControlActiveStateOf( _contours_ViewControl, stateCondition );
625 //------------------------------------------------------------------------------------------------------------
626 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
628 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
629 setControlActiveStateOf( contourWRP, stateCondition );
632 //------------------------------------------------------------------------------------------------------------
633 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( ContourWrap_ViewControl * contourWRP, bool stateCondition )
635 contourWRP->getControler()->SetActive( stateCondition );
636 contourWRP->getControler()->SetEditable( false );
639 //------------------------------------------------------------------------------------------------------------
640 void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
642 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
643 // contourWRP->getViewer()->SetVisible( stateCondition );
644 if ( contourWRP!=NULL )
645 removeFromScene( contourWRP, false, stateCondition );
648 //------------------------------------------------------------------------------------------------------------
649 std::vector< std::string > wxVtkBaseView_SceneManager :: getSelectedObjects()
651 std::vector< std::string > selectedObjects;
652 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
653 int size = _workingGroup->size();
654 for ( int i = 0; i<size; i++ )
656 //EED??? manualViewBaseContour * viewer = iter->second->getViewer();
657 selectedObjects.push_back( iter->first);
661 return selectedObjects;
663 //------------------------------------------------------------------------------------------------------------
664 void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
666 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
667 //EED??? int size = _contours_ViewControl->size();
668 //EED??? bool selected;
669 /*for ( int i = 0; i<size; i++ )
672 manualViewBaseContour * viewer = iter->second->getViewer();
673 std::vector <std::string >::iterator iterIN;
675 for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
677 if( iter->first.compare( theExistingObjectsToSelect[i] ) )
679 viewer->SelectAllPoints( true );
680 viewer->SelectPosibleContour( true );
682 theExistingObjectsToSelect.erase( iterIN );
690 //------------------------------------------------------------------------------------------------------------
691 void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
693 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
694 int size = _contours_ViewControl->size();
695 for ( int i = 0; i<size; i++ )
697 manualViewBaseContour * viewer = iter->second->getViewer();
699 viewer->SetSelected( true );
700 /*viewer->SelectAllPoints( true );
701 viewer->SelectPosibleContour( true );*/
707 //------------------------------------------------------------------------------------------------------------
708 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
710 int i, size = theKeyNameVector.size();
711 for( i=0; i< size; i++ )
713 setControlActiveStateOf( theKeyNameVector[i], controlCondition );
717 //------------------------------------------------------------------------------------------------------------
718 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
720 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
721 int i, size = theMap->size();
722 for( i=0; i< size; i++ )
724 removeFromScene( iter->second, false, controlCondition );
729 //------------------------------------------------------------------------------------------------------------
731 //------------------------------------------------------------------------------------------------------------
733 //------------------------------------------------------------------------------------------------------------
734 // Creational and initialization methods
735 //------------------------------------------------------------------------------------------------------------
737 //------------------------------------------------------------------------------------------------------------
739 //------------------------------------------------------------------------------------------------------------
741 bool wxVtkBaseView_SceneManager :: isCtrlPressed()
745 bool wxVtkBaseView_SceneManager :: isShiftPressed()
749 char wxVtkBaseView_SceneManager :: getLastKeyCode()
753 bool wxVtkBaseView_SceneManager :: OnChar()
756 _ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
757 _shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
759 _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
761 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
762 _eventHandler->ProcessEvent( cevent );
765 /*if( _eventHandler!=NULL )
767 char * toolCommand = NULL;
769 if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
771 toolCommand = &(COPY_TOOL);
773 else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
775 toolCommand = &(PASTE_TOOL);
777 else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
779 toolCommand = &(DELETE_KEY);
781 else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
783 toolCommand = &(CREATE_CONTOUR_KEY);
785 else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
787 toolCommand = &(OPEN_TOOL);
789 else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
791 toolCommand = &(SAVE_KEY);
794 if ( toolCommand!=NULL )
796 currentkey = toolCommand;
797 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
798 cevent.SetClientData( (void *) toolCommand);
799 _eventHandler->ProcessEvent( cevent );
804 // long int endtime = clock();
808 //------------------------------------------------------------------------------------------------------------
810 bool wxVtkBaseView_SceneManager :: OnMouseMove()
813 bool condition = true;
815 crea::wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
816 _wxVTKiren->GetEventPosition( X , Y );
818 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
819 //??? bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
821 if( _waiting && !ctrlKey )
823 sendEnvent( wxEVT_CHANGED_DEEP, "Update");
824 //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
827 if ( !_creatingROI && !_creatingMULT_ROI )
830 /*if( ctrlKey || shiftKey )
836 _toIncludeAtInteractionGroup = false;
839 bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
840 std::string preservingName = preserveState ? _lastInteractionName : "";
842 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
843 int i, size = _sceneContours_ViewControl->size();
844 bool foundOne = false;
846 manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
847 manualViewBaseContour * viewer = NULL;
850 bool singleMoving = true;
851 int selectionSize = _workingGroup->size();
852 if( selectionSize > 1 )
856 //EED??? bool ckecking = false;
857 for( i =0; i<size ; i++ )
859 control = iter->second->getControler();
860 viewer = iter->second->getViewer();
861 /*ckecking = */control->SetActive( true );
863 if (_lastInteraction != NULL)
865 singleMoving = !_lastInteraction->getViewer()->GetSelected();
870 size = selectionSize;
871 iter = _workingGroup->begin();
875 _toIncludeAtInteractionGroup = false;
878 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
881 _lastInteraction=NULL;
882 for( i =0; i<size ; i++ )
884 control = iter->second->getControler();
885 viewer = iter->second->getViewer();
886 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
887 control->SetActive( true );
889 foundOne = control->OnMouseMove();
890 foundOne &= viewer->GetPosibleSelected();
892 if ( !foundOne && singleMoving )
894 control->SetActive( false );
895 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
896 control->SetPosibleToMove( false );
900 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
902 _lastInteraction->getControler()->SetActive( true );
905 _lastInteraction = iter->second;
906 _lastInteractionName = iter->first;
908 viewer->UpdateColorActor();
909 control->SetPosibleToMove( true );
910 // viewer->AddCompleteContourActor();
925 //------------------------------------------------------------------------------------------------------------
926 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
931 //EED??? char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
932 bool condition = false;
933 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
934 //EED??? vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
935 //EED??? wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
936 //EED?? wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
937 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
939 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
940 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
941 _toIncludeAtInteractionGroup = false;
942 if ( ctrlKey || shftKey )
944 _toIncludeAtInteractionGroup = true;
948 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
950 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
952 _lastInteraction->getControler()->SetEditable( false );
953 _lastInteraction->getControler()->SetActive( false );
954 _lastInteraction->getControler()->SetPosibleToMove( false );
955 _lastInteraction->getViewer()->Refresh();
956 _lastInteraction=NULL;
963 if( !_toIncludeAtInteractionGroup )
965 _workingGroup->clear();
968 if( _lastInteraction!=NULL )
970 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
971 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
972 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
974 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
977 //setControlActiveStateOf( _contours_ViewControl, false );
978 sendEnvent( wxEVT_START_CREATE_ROI, "");
982 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
983 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
984 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
991 //------------------------------------------------------------------------------------------------------------
992 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
994 bool condition = false;
997 if( _drawingSelectionROI )
999 setSelection2DROIInternalOutlines();
1003 //------------------------------------------------------------------------------------------------------------
1004 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
1006 bool condition = false;
1011 //------------------------------------------------------------------------------------------------------------
1012 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
1014 bool condition = false;
1019 //------------------------------------------------------------------------------------------------------------
1020 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
1022 bool condition = false;
1023 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
1024 //EED??? bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
1031 //------------------------------------------------------------------------------------------------------------
1032 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
1034 bool condition = false;
1036 //setControlActiveStateOfALL( false );//************************************************
1037 if ( _creatingMULT_ROI )
1039 //setControlActiveStateOfALL( false );
1043 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
1044 _creatingROI = false;
1048 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
1050 manualContourBaseControler * control = _lastInteraction->getControler();
1051 //_lastInteraction->getControler()->SetPosibleToMove( false );
1052 control->SetActive( false );
1053 control->SetEditable( false );
1054 control->SetPosibleToMove( false );
1055 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
1056 _lastInteraction->getViewer()->Refresh();
1057 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1063 //------------------------------------------------------------------------------------------------------------
1065 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
1067 bool condition = false;
1072 //------------------------------------------------------------------------------------------------------------
1073 bool wxVtkBaseView_SceneManager :: OnRightDClick()
1075 bool condition = false; condition = true;
1076 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
1077 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
1078 //EED??? wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
1082 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
1083 set_creatingMULT_ROI( !_creatingMULT_ROI );
1091 //------------------------------------------------------------------------------------------------------------
1092 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
1094 bool condition = false;
1099 //------------------------------------------------------------------------------------------------------------
1100 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
1102 bool condition = false;
1106 //------------------------------------------------------------------------------------------------------------
1108 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1110 _drawingSelectionROI = true;
1111 _workingGroup->clear();
1112 _controlerSelectionROI->CreateNewManualContour();
1113 if (_lastInteraction!=NULL)
1115 _lastInteraction->getControler()->SetEditable( false );
1116 _lastInteraction->getControler()->SetActive( false );
1117 _lastInteraction->getControler()->SetPosibleToMove( false );
1118 _lastInteraction->getViewer()->Refresh();
1120 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1121 int i, workSize = _workingGroup->size();
1122 for( i=0; i< workSize; i++ )
1124 manualContourBaseControler * control = iter->second->getControler();
1125 control->SetEditable( false );
1126 control->SetActive( false );
1127 control->SetPosibleToMove( false );
1128 iter->second->getViewer()->Refresh();
1132 _lastInteraction = NULL;
1133 _lastInteractionName = "";
1135 _viewerSelectionROI->AddCompleteContourActor( true );
1136 _controlerSelectionROI->SetActive( true );
1138 _viewerSelectionROI->RefreshContour();
1139 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1141 //------------------------------------------------------------------------------------------------------------
1142 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1144 _drawingSelectionROI = false;
1145 _workingGroup->clear();
1146 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1149 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1150 int i, size = _sceneContours_ViewControl->size();
1151 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1152 manualViewBaseContour * viewer;
1153 bool insideRoi = false;
1154 for ( i=0; i<size; i++ )
1156 viewer = iter->second->getViewer();
1157 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1158 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1161 viewer->SetSelected( true );
1162 viewer->UpdateColorActor();
1163 setControlActiveStateOf( iter->second, true );
1164 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1168 _viewerSelectionROI->RemoveCompleteContourActor( );
1169 _controlerSelectionROI->SetActive( false );
1171 //------------------------------------------------------------------------------------------------------------
1172 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1174 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1175 long int start = clock();
1177 double sg = (double)(start) / (double)CLK_TCK;
1179 double sg = (double)(start) / CLOCKS_PER_SEC;
1182 crea::wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1183 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1184 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): %f\n \n",method.c_str(), tmpPx, tmpPy, sg);
1189 //------------------------------------------------------------------------------------------------------------
1190 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1192 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1193 manualViewBaseContour * cViewer;
1194 manualContourBaseControler * cControler;
1195 ContourWrap_ViewControl *conwraviwcont=iter->second;
1197 cViewer = conwraviwcont->getViewer();
1200 cControler = conwraviwcont->getControler();
1201 // cControler->Save(ff);
1203 // cModel = cControler->GetManualContourModel();
1204 // cModel->Save(ff);
1208 //------------------------------------------------------------------------------------------------------------
1209 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1211 std::vector<std::string> currentSelection = this->getSelectedObjects();
1212 if (currentSelection.size()>=1){
1214 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1215 manualBaseModel *cModel = cControler->GetManualContourModel();
1216 int i,size = cModel->GetNumberOfPointsSpline();
1218 for (i=0; i<size; i++)
1220 cModel->GetSpline_i_Point(i, &x, &y, &z);
1228 //------------------------------------------------------------------------------------------------------------
1229 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1231 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1232 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1235 //------------------------------------------------------------------------------------------------------------
1236 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1239 vtkImageData *imagedata = GetImageData();
1240 imagedata->GetExtent(ext);
1241 int sizeZ = ext[5]-ext[4]+1;
1249 //------------------------------------------------------------------------------------------------------------
1250 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1253 vtkImageData *imagedata = GetImageData();
1254 imagedata->GetExtent(ext);
1255 int sizeX = ext[1]-ext[0]+1;
1256 int sizeY = ext[3]-ext[2]+1;
1257 int sizeZ = GetImageDataSizeZ();
1258 int sizeXYZ = sizeX*sizeY*sizeZ;
1262 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1263 for (i=0;i<sizeXYZ;i++)
1265 if ( p[i]<range[0] ) range[0]=p[i];
1266 if ( p[i]>range[1] ) range[1]=p[i];
1270 //------------------------------------------------------------------------------------------------------------
1271 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1273 _widthOfContour = width;
1274 _widthOfControlPoint = _widthOfContour*_widthOfContour/2;
1275 manualViewBaseContour *cViewer;
1276 ContourWrap_ViewControl *conwraviwcont;
1277 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
1279 if (_contours_ViewControl!=NULL)
1281 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1283 conwraviwcont = iter->second;
1284 cViewer = conwraviwcont->getViewer();
1285 cViewer->SetShowText( false ); // EED 28Mars2011
1286 cViewer->SetWidthLine( _widthOfContour );
1287 cViewer->SetRange( _widthOfControlPoint );
1292 void wxVtkBaseView_SceneManager::SetShowTextContour(bool show)
1294 _showTextContour = show;
1297 bool wxVtkBaseView_SceneManager::isEditableCControler(std::string theKeyName){
1299 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1301 manualContourBaseControler* cControler = ccon->getControler();
1302 if(cControler != NULL && cControler->IsEditable() == false){
1309 void wxVtkBaseView_SceneManager::deleteCViewerCControler(std::string theKeyName){
1312 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1314 manualViewBaseContour * cViewer = ccon->getViewer();
1315 manualContourBaseControler * cControler = ccon->getControler();
1317 removeFromScene(theKeyName);
1318 removeWrap(theKeyName);