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 //------------------------------------------------------------------------------------------------------------
48 DEFINE_EVENT_TYPE( wxEVT_START_CREATE_MULT_ROI )
49 DEFINE_EVENT_TYPE( wxEVT_STOP_CREATE_MULT_ROI )
50 DEFINE_EVENT_TYPE( wxEVT_START_CREATE_ROI )
51 DEFINE_EVENT_TYPE( wxEVT_STOP_CREATE_ROI )
52 DEFINE_EVENT_TYPE( wxEVT_DELETE_ROI )
53 DEFINE_EVENT_TYPE( wxEVT_SELECTED_MULT_ROI )
54 DEFINE_EVENT_TYPE( wxEVT_SELECTED_ROI )
55 DEFINE_EVENT_TYPE( wxEVT_UNSLECTED_ROI )
56 DEFINE_EVENT_TYPE( wxEVT_MANUAL_HIDED_ROI )
57 DEFINE_EVENT_TYPE( wxEVT_MANUAL_SHOWED_ROI )
58 DEFINE_EVENT_TYPE( wxEVT_EDITING_ROI )
59 DEFINE_EVENT_TYPE( wxEVT_MOVING_ROI )
60 DEFINE_EVENT_TYPE( wxEVT_MOVING_ROI_POINT )
61 DEFINE_EVENT_TYPE( wxEVT_SELECTED_ROI_POINT )
62 DEFINE_EVENT_TYPE( wxEVT_UNSELECTED_ROI_POINT )
63 DEFINE_EVENT_TYPE( wxEVT_CHANGED_DEEP )
66 wxVtkBaseView_SceneManager :: wxVtkBaseView_SceneManager( wxVtkBaseView * theWxBaseViewToManage, wxEvtHandler * theEventHandler, double * spc )
68 _lastInteraction = NULL;
69 _lastInteractionName = "";
70 _eventHandler = theEventHandler;
73 _contours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
74 _sceneContours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
75 _workingGroup = new std::map< std::string, ContourWrap_ViewControl * >();
76 _creatingMULT_ROI = false;
78 _toIncludeAtInteractionGroup = false;
81 _drawingSelectionROI = false;
83 _wxVtk_BaseView = theWxBaseViewToManage;
84 if( _wxVtk_BaseView!=NULL )
86 vtkInteractorStyleBaseView* theInteractorStyleBaseView = (vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView();
87 theInteractorStyleBaseView->AddInteractorStyleMaracas( this );
88 SetVtkInteractorStyleBaseView( theInteractorStyleBaseView );
90 configureSelectionROI( spc );
93 //------------------------------------------------------------------------------------------------------------
94 wxVtkBaseView_SceneManager :: ~wxVtkBaseView_SceneManager()
96 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
97 int size = _contours_ViewControl->size();
98 for ( int i = 0; i<size; iter++ )
100 _contours_ViewControl->erase( iter );
103 _contours_ViewControl->clear();
104 delete _contours_ViewControl;
105 _workingGroup->clear();
106 delete _lastInteraction;
107 delete _workingGroup;
108 //delete _contours_ViewControl;
111 //------------------------------------------------------------------------------------------------------------
112 // Methods for capturing events
113 //------------------------------------------------------------------------------------------------------------
116 //------------------------------------------------------------------------------------------------------------
117 // Methods for sending events
118 //------------------------------------------------------------------------------------------------------------
119 void wxVtkBaseView_SceneManager :: sendEnvent( WXTYPE theEventType, std::string text )
121 if ( _eventHandler != NULL )
123 wxCommandEvent cevent( theEventType );
124 cevent.SetString( wxString( text.c_str(), wxConvUTF8) );
125 _eventHandler->ProcessEvent( cevent );
129 //------------------------------------------------------------------------------------------------------------
130 // Attributes getters and setters
131 //------------------------------------------------------------------------------------------------------------
132 void wxVtkBaseView_SceneManager :: setWxEventHandler( wxEvtHandler * theEventHandler )
134 _eventHandler = theEventHandler;
137 //------------------------------------------------------------------------------------------------------------
138 void wxVtkBaseView_SceneManager :: setWxVtkViewBase( wxVtkBaseView * theBaseView )
140 _wxVtk_BaseView = theBaseView;
143 //------------------------------------------------------------------------------------------------------------
144 wxVtkBaseView * wxVtkBaseView_SceneManager :: getWxVtkViewBase()
146 return _wxVtk_BaseView;
149 //------------------------------------------------------------------------------------------------------------
150 void wxVtkBaseView_SceneManager::configureViewControlTo( std::string theKeyName, manualBaseModel * manModelContour, double * spc,int typeContour)
152 //setControlActiveStateOfALL( false );
155 if( _lastInteraction!=NULL )
157 _lastInteraction->getControler()->SetEditable( false );
158 _lastInteraction->getViewer()->Refresh();
159 _lastInteraction->getControler()->SetActive( false );
160 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
162 manualContourBaseControler *manContourControl;
163 manualViewBaseContour *manViewerContour;
164 // Creating the view manualViewContour and the manualContourControler
165 // NOTE: The model is created in the KernelManagerContour class, factoryManualContourModel method
168 manContourControl = new manualContourControler();
169 manViewerContour = new manualViewContour();
174 manContourControl = new manualRoiControler();
175 manViewerContour = new manualViewRoi();
180 manContourControl = new manualCircleControler();
181 manViewerContour = new manualViewCircle();
186 manContourControl = new manualRoiControler();
187 manViewerContour = new manualViewBullEye();
192 manContourControl = new manualLineControler();
193 manViewerContour = new manualViewLine();
199 manContourControl = new manualContourControler();
200 manViewerContour = new manualViewPoints();
206 manContourControl = new manualContourControler();
207 manViewerContour = new manualViewContour();
212 _lastInteraction = insertWrap( theKeyName, manContourControl, manViewerContour );
213 _lastInteractionName = theKeyName;
215 //Configuring the relations between the contour members representation
216 manViewerContour->SetModel( manModelContour );
217 manViewerContour->SetWxVtkBaseView( _wxVtk_BaseView );
218 manViewerContour->SetRange( _widthOfControlPoint );
219 manViewerContour->SetZ( -900 );
221 manViewerContour->SetSpacing(spc);
223 manViewerContour->SetColorNormalContour(0, 0, 1);
224 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
225 manViewerContour->SetColorSelectContour(1, 0.8, 0);
226 manViewerContour->SetWidthLine(_widthOfContour);
228 manContourControl->SetModelView( manModelContour , manViewerContour );
229 manContourControl->Configure();
230 int i,sizeLstPoints = manModelContour->GetSizeLstPoints();
231 for ( i=0; i<sizeLstPoints; i++ )
233 manViewerContour->AddPoint();
236 manContourControl->CreateNewManualContour();
237 manViewerContour->RefreshContour();
238 addToScene( theKeyName );
240 //------------------------------------------------------------------------------------------------------------
241 void wxVtkBaseView_SceneManager :: configureSelectionROI( double * spc )
243 _controlerSelectionROI = new manualRoiControler();
244 _viewerSelectionROI = new manualViewRoi();
245 _modelSelectionROI = new manualContourModel();
247 _viewerSelectionROI->SetModel( _modelSelectionROI );
248 _viewerSelectionROI->SetWxVtkBaseView( _wxVtk_BaseView );
249 _viewerSelectionROI->SetRange( 2 );
250 _viewerSelectionROI->SetZ( -900 );
251 _viewerSelectionROI->SetColorNormalContour(0.6, 0.8, 0);
253 _viewerSelectionROI->SetSpacing( spc );
255 _controlerSelectionROI->SetModelView( _modelSelectionROI , _viewerSelectionROI );
256 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _controlerSelectionROI );
257 _controlerSelectionROI->SetActive(false);
260 //------------------------------------------------------------------------------------------------------------
261 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: insertWrap( std::string theKeyName, manualContourBaseControler * manContourControl, manualViewBaseContour * manViewerContour )
263 ContourWrap_ViewControl * newContourWrap = new ContourWrap_ViewControl(manContourControl, manViewerContour);
264 if(_contours_ViewControl == NULL)
266 _contours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
268 _contours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, newContourWrap ));
269 return newContourWrap;
272 //------------------------------------------------------------------------------------------------------------
273 void wxVtkBaseView_SceneManager :: desconfigureViewControlOf( std::string theKeyName )
277 //------------------------------------------------------------------------------------------------------------
278 void wxVtkBaseView_SceneManager :: removeWrap( std::string theKeyName )
280 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
281 iter = _contours_ViewControl->find( theKeyName );
282 _contours_ViewControl->erase( iter );
283 _lastInteraction=NULL;
284 _lastInteractionName = "";
285 _workingGroup->clear();
286 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
287 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
290 //------------------------------------------------------------------------------------------------------------
291 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName )
293 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
294 iter = _contours_ViewControl->find( theName );
296 //return iter->first;
299 //------------------------------------------------------------------------------------------------------------
300 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName, std::map<std::string, ContourWrap_ViewControl *> * theMap )
302 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
303 iter = theMap->find( theName );
307 //------------------------------------------------------------------------------------------------------------
308 manualContourBaseControler * wxVtkBaseView_SceneManager :: getControlerOf( std::string theName )
310 return getContourWrap_ViewControlOf ( theName )->getControler();
313 //------------------------------------------------------------------------------------------------------------
314 manualViewBaseContour * wxVtkBaseView_SceneManager :: getViewerOf( std::string theName )
316 return getContourWrap_ViewControlOf ( theName )->getViewer();
319 //------------------------------------------------------------------------------------------------------------
320 void wxVtkBaseView_SceneManager :: set_creatingMULT_ROI( bool condition )
322 _creatingMULT_ROI = condition;
325 //------------------------------------------------------------------------------------------------------------
326 void wxVtkBaseView_SceneManager :: set_editingROI( bool condition )
328 _editingROI = condition;
331 //------------------------------------------------------------------------------------------------------------
332 void wxVtkBaseView_SceneManager :: set_toIncludeAtInteractionGroup( bool condition )
334 _toIncludeAtInteractionGroup = condition;
337 //------------------------------------------------------------------------------------------------------------
338 void wxVtkBaseView_SceneManager :: set_waiting( bool condition )
340 _waiting = condition;
343 //------------------------------------------------------------------------------------------------------------
344 bool wxVtkBaseView_SceneManager :: get_creatingMULT_ROI( )
346 return _creatingMULT_ROI;
349 //------------------------------------------------------------------------------------------------------------
350 bool wxVtkBaseView_SceneManager :: get_editingROI( )
355 //------------------------------------------------------------------------------------------------------------
356 bool wxVtkBaseView_SceneManager :: get_toIncludeAtInteractionGroup( )
358 return _toIncludeAtInteractionGroup;
361 //------------------------------------------------------------------------------------------------------------
362 bool wxVtkBaseView_SceneManager :: get_waiting( )
367 //------------------------------------------------------------------------------------------------------------
368 bool wxVtkBaseView_SceneManager :: get_creatingROI()
372 //------------------------------------------------------------------------------------------------------------
373 void wxVtkBaseView_SceneManager :: set_creatingROI( bool condition )
375 _creatingROI = condition;
378 //------------------------------------------------------------------------------------------------------------
379 // Other functional methods
380 //------------------------------------------------------------------------------------------------------------
382 void wxVtkBaseView_SceneManager :: createCopyContourOf( std::string anExistingKName, std::string cloneName, manualBaseModel * manualModel, bool append )
386 setControlActiveStateOf( _workingGroup, false );
387 _workingGroup->clear();
389 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
392 iter = _contours_ViewControl->find( anExistingKName );
394 manualBaseModel *cModule = manualModel;
395 manualViewBaseContour *cViewer = iter->second->getViewer()->Clone();
396 manualContourBaseControler *cControl = iter->second->getControler()->Clone( );
398 cViewer->SetModel(cModule);
399 cControl->SetModelView( cModule , cViewer );
400 cControl->CreateNewManualContour();
401 cControl->SetActive( true );
402 cControl->SetEditable( false );
404 cViewer->RefreshContour();
406 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
407 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
409 _lastInteraction = insertWrap( cloneName, cControl, cViewer );
410 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( cloneName, _lastInteraction ));
411 addToScene( cloneName );
414 //------------------------------------------------------------------------------------------------------------
416 void wxVtkBaseView_SceneManager :: removeFromScene( ContourWrap_ViewControl * contourWRP, bool visualization, bool control )
418 if( contourWRP == _lastInteraction )
420 _lastInteraction = NULL;
421 _lastInteractionName = "";
425 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->RemoveInteractorStyleMaracas( contourWRP->getControler() );
427 contourWRP->getControler()->SetActive( control );
428 contourWRP->getControler()->SetEditable( false );
430 if ( !visualization && control )
432 contourWRP->getViewer()->RemoveControlPoints( );
433 contourWRP->getViewer()->RemoveTextActor( );
437 contourWRP->getViewer()->RemoveCompleteContourActor();
441 //------------------------------------------------------------------------------------------------------------
442 void wxVtkBaseView_SceneManager :: removeFromScene( std::string theKeyName, bool visualization , bool control )
445 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
446 iter = _sceneContours_ViewControl->find( theKeyName );
447 if (iter != _sceneContours_ViewControl->end())
449 ContourWrap_ViewControl * contourWRP = iter->second;
450 removeFromScene( contourWRP );
451 _sceneContours_ViewControl->erase(iter);
456 //------------------------------------------------------------------------------------------------------------
457 std::vector<std::string> wxVtkBaseView_SceneManager::GetlstContoursNameActualSlice()
459 std::vector<std::string> lstContoursNameActualSlice;
460 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
461 int i,size = _sceneContours_ViewControl->size();
462 for ( i = 0; i<size; i++ )
464 lstContoursNameActualSlice.push_back( iter->first );
467 return lstContoursNameActualSlice;
470 //------------------------------------------------------------------------------------------------------------
471 void wxVtkBaseView_SceneManager::removeSceneContours()
473 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
474 int size = _sceneContours_ViewControl->size();
475 for ( int i = 0; i<size; i++ )
477 removeFromScene( iter->second );
480 _sceneContours_ViewControl->clear();
481 //Removing the selection rectangle to avoid showing when it's innecesary
482 _controlerSelectionROI->SetActive( false );
483 _viewerSelectionROI->RemoveCompleteContourActor();
486 void wxVtkBaseView_SceneManager::removeAllOutlines()
488 manualViewBaseContour * cViewer;
489 manualContourBaseControler * cControler;
491 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
492 int i,size=_contours_ViewControl->size();
495 iter = _contours_ViewControl->begin();
496 cControler = iter->second->getControler();
497 cViewer = iter->second->getViewer();
498 removeWrap( iter->first );
506 //------------------------------------------------------------------------------------------------------------
507 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
511 removeSceneContours();
513 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
514 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
516 addToScene( theKeyName, contourWRP, true, visualization, control, ifActive, ifShowCtrlPoints);
519 //------------------------------------------------------------------------------------------------------------
520 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
524 removeSceneContours();
526 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
529 contourWRP->getViewer()->AddCompleteContourActor( ifShowCtrlPoints );
534 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( contourWRP->getControler() );
539 contourWRP->getViewer()->SetColorNormalContour(1,0,0);
541 contourWRP->getViewer()->SetColorNormalContour(0,0,1);
546 contourWRP->getControler()->SetActive( true );
547 contourWRP->getViewer()->RemoveTextActor();
551 //------------------------------------------------------------------------------------------------------------
552 void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
554 int i, size = theKeyNameVector.size();
555 for( i=0; i< size; i++ )
557 removeFromScene( theKeyNameVector[i], visualization, control );
561 //------------------------------------------------------------------------------------------------------------
562 void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
564 int i, size = theKeyNameVector.size();
565 for( i=0; i< size; i++ )
567 addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
571 //------------------------------------------------------------------------------------------------------------
572 void wxVtkBaseView_SceneManager :: setControlActiveStateOfALL( bool stateCondition )
574 setControlActiveStateOf( _contours_ViewControl, stateCondition );
577 //------------------------------------------------------------------------------------------------------------
578 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
580 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
581 setControlActiveStateOf( contourWRP, stateCondition );
584 //------------------------------------------------------------------------------------------------------------
585 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( ContourWrap_ViewControl * contourWRP, bool stateCondition )
587 contourWRP->getControler()->SetActive( stateCondition );
588 contourWRP->getControler()->SetEditable( false );
591 //------------------------------------------------------------------------------------------------------------
592 void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
594 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
595 // contourWRP->getViewer()->SetVisible( stateCondition );
596 if ( contourWRP!=NULL )
597 removeFromScene( contourWRP, false, stateCondition );
600 //------------------------------------------------------------------------------------------------------------
601 std::vector< std::string > wxVtkBaseView_SceneManager :: getSelectedObjects()
603 std::vector< std::string > selectedObjects;
604 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
605 int size = _workingGroup->size();
606 for ( int i = 0; i<size; i++ )
608 //EED??? manualViewBaseContour * viewer = iter->second->getViewer();
609 selectedObjects.push_back( iter->first);
613 return selectedObjects;
615 //------------------------------------------------------------------------------------------------------------
616 void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
618 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
619 //EED??? int size = _contours_ViewControl->size();
620 //EED??? bool selected;
621 /*for ( int i = 0; i<size; i++ )
624 manualViewBaseContour * viewer = iter->second->getViewer();
625 std::vector <std::string >::iterator iterIN;
627 for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
629 if( iter->first.compare( theExistingObjectsToSelect[i] ) )
631 viewer->SelectAllPoints( true );
632 viewer->SelectPosibleContour( true );
634 theExistingObjectsToSelect.erase( iterIN );
642 //------------------------------------------------------------------------------------------------------------
643 void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
645 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
646 int size = _contours_ViewControl->size();
647 for ( int i = 0; i<size; i++ )
649 manualViewBaseContour * viewer = iter->second->getViewer();
651 viewer->SetSelected( true );
652 /*viewer->SelectAllPoints( true );
653 viewer->SelectPosibleContour( true );*/
659 //------------------------------------------------------------------------------------------------------------
660 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
662 int i, size = theKeyNameVector.size();
663 for( i=0; i< size; i++ )
665 setControlActiveStateOf( theKeyNameVector[i], controlCondition );
669 //------------------------------------------------------------------------------------------------------------
670 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
672 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
673 int i, size = theMap->size();
674 for( i=0; i< size; i++ )
676 removeFromScene( iter->second, false, controlCondition );
681 //------------------------------------------------------------------------------------------------------------
683 //------------------------------------------------------------------------------------------------------------
685 //------------------------------------------------------------------------------------------------------------
686 // Creational and initialization methods
687 //------------------------------------------------------------------------------------------------------------
689 //------------------------------------------------------------------------------------------------------------
691 //------------------------------------------------------------------------------------------------------------
693 bool wxVtkBaseView_SceneManager :: isCtrlPressed()
697 bool wxVtkBaseView_SceneManager :: isShiftPressed()
701 char wxVtkBaseView_SceneManager :: getLastKeyCode()
705 bool wxVtkBaseView_SceneManager :: OnChar()
708 _ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
709 _shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
711 _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
713 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
714 _eventHandler->ProcessEvent( cevent );
717 /*if( _eventHandler!=NULL )
719 char * toolCommand = NULL;
721 if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
723 toolCommand = &(COPY_TOOL);
725 else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
727 toolCommand = &(PASTE_TOOL);
729 else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
731 toolCommand = &(DELETE_KEY);
733 else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
735 toolCommand = &(CREATE_CONTOUR_KEY);
737 else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
739 toolCommand = &(OPEN_TOOL);
741 else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
743 toolCommand = &(SAVE_KEY);
746 if ( toolCommand!=NULL )
748 currentkey = toolCommand;
749 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
750 cevent.SetClientData( (void *) toolCommand);
751 _eventHandler->ProcessEvent( cevent );
756 // long int endtime = clock();
760 //------------------------------------------------------------------------------------------------------------
762 bool wxVtkBaseView_SceneManager :: OnMouseMove()
765 bool condition = true;
767 crea::wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
768 _wxVTKiren->GetEventPosition( X , Y );
770 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
771 //??? bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
773 if( _waiting && !ctrlKey )
775 sendEnvent( wxEVT_CHANGED_DEEP, "Update");
776 //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
779 if ( !_creatingROI && !_creatingMULT_ROI )
782 /*if( ctrlKey || shiftKey )
788 _toIncludeAtInteractionGroup = false;
791 bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
792 std::string preservingName = preserveState ? _lastInteractionName : "";
794 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
795 int i, size = _sceneContours_ViewControl->size();
796 bool foundOne = false;
798 manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
799 manualViewBaseContour * viewer = NULL;
802 bool singleMoving = true;
803 int selectionSize = _workingGroup->size();
804 if( selectionSize > 1 )
808 //EED??? bool ckecking = false;
809 for( i =0; i<size ; i++ )
811 control = iter->second->getControler();
812 viewer = iter->second->getViewer();
813 /*ckecking = */control->SetActive( true );
815 if (_lastInteraction != NULL)
817 singleMoving = !_lastInteraction->getViewer()->GetSelected();
822 size = selectionSize;
823 iter = _workingGroup->begin();
827 _toIncludeAtInteractionGroup = false;
830 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
833 _lastInteraction=NULL;
834 for( i =0; i<size ; i++ )
836 control = iter->second->getControler();
837 viewer = iter->second->getViewer();
838 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
839 control->SetActive( true );
841 foundOne = control->OnMouseMove();
842 foundOne &= viewer->GetPosibleSelected();
844 if ( !foundOne && singleMoving )
846 control->SetActive( false );
847 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
848 control->SetPosibleToMove( false );
852 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
854 _lastInteraction->getControler()->SetActive( true );
857 _lastInteraction = iter->second;
858 _lastInteractionName = iter->first;
860 viewer->UpdateColorActor();
861 control->SetPosibleToMove( true );
862 // viewer->AddCompleteContourActor();
877 //------------------------------------------------------------------------------------------------------------
878 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
883 //EED??? char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
884 bool condition = false;
885 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
886 //EED??? vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
887 //EED??? wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
888 //EED?? wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
889 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
891 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
892 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
893 _toIncludeAtInteractionGroup = false;
894 if ( ctrlKey || shftKey )
896 _toIncludeAtInteractionGroup = true;
900 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
902 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
904 _lastInteraction->getControler()->SetEditable( false );
905 _lastInteraction->getControler()->SetActive( false );
906 _lastInteraction->getControler()->SetPosibleToMove( false );
907 _lastInteraction->getViewer()->Refresh();
908 _lastInteraction=NULL;
915 if( !_toIncludeAtInteractionGroup )
917 _workingGroup->clear();
920 if( _lastInteraction!=NULL )
922 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
923 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
924 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
926 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
929 //setControlActiveStateOf( _contours_ViewControl, false );
930 sendEnvent( wxEVT_START_CREATE_ROI, "");
934 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
935 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
936 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
943 //------------------------------------------------------------------------------------------------------------
944 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
946 bool condition = false;
949 if( _drawingSelectionROI )
951 setSelection2DROIInternalOutlines();
955 //------------------------------------------------------------------------------------------------------------
956 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
958 bool condition = false;
963 //------------------------------------------------------------------------------------------------------------
964 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
966 bool condition = false;
971 //------------------------------------------------------------------------------------------------------------
972 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
974 bool condition = false;
975 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
976 //EED??? bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
983 //------------------------------------------------------------------------------------------------------------
984 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
986 bool condition = false;
988 //setControlActiveStateOfALL( false );//************************************************
989 if ( _creatingMULT_ROI )
991 //setControlActiveStateOfALL( false );
995 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
996 _creatingROI = false;
1000 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
1002 manualContourBaseControler * control = _lastInteraction->getControler();
1003 //_lastInteraction->getControler()->SetPosibleToMove( false );
1004 control->SetActive( false );
1005 control->SetEditable( false );
1006 control->SetPosibleToMove( false );
1007 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
1008 _lastInteraction->getViewer()->Refresh();
1009 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1015 //------------------------------------------------------------------------------------------------------------
1017 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
1019 bool condition = false;
1024 //------------------------------------------------------------------------------------------------------------
1025 bool wxVtkBaseView_SceneManager :: OnRightDClick()
1027 bool condition = false; condition = true;
1028 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
1029 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
1030 //EED??? wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
1034 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
1035 set_creatingMULT_ROI( !_creatingMULT_ROI );
1043 //------------------------------------------------------------------------------------------------------------
1044 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
1046 bool condition = false;
1051 //------------------------------------------------------------------------------------------------------------
1052 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
1054 bool condition = false;
1058 //------------------------------------------------------------------------------------------------------------
1060 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1062 _drawingSelectionROI = true;
1063 _workingGroup->clear();
1064 _controlerSelectionROI->CreateNewManualContour();
1065 if (_lastInteraction!=NULL)
1067 _lastInteraction->getControler()->SetEditable( false );
1068 _lastInteraction->getControler()->SetActive( false );
1069 _lastInteraction->getControler()->SetPosibleToMove( false );
1070 _lastInteraction->getViewer()->Refresh();
1072 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1073 int i, workSize = _workingGroup->size();
1074 for( i=0; i< workSize; i++ )
1076 manualContourBaseControler * control = iter->second->getControler();
1077 control->SetEditable( false );
1078 control->SetActive( false );
1079 control->SetPosibleToMove( false );
1080 iter->second->getViewer()->Refresh();
1084 _lastInteraction = NULL;
1085 _lastInteractionName = "";
1087 _viewerSelectionROI->AddCompleteContourActor( true );
1088 _controlerSelectionROI->SetActive( true );
1090 _viewerSelectionROI->RefreshContour();
1091 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1093 //------------------------------------------------------------------------------------------------------------
1094 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1096 _drawingSelectionROI = false;
1097 _workingGroup->clear();
1098 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1101 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1102 int i, size = _sceneContours_ViewControl->size();
1103 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1104 manualViewBaseContour * viewer;
1105 bool insideRoi = false;
1106 for ( i=0; i<size; i++ )
1108 viewer = iter->second->getViewer();
1109 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1110 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1113 viewer->SetSelected( true );
1114 viewer->UpdateColorActor();
1115 setControlActiveStateOf( iter->second, true );
1116 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1120 _viewerSelectionROI->RemoveCompleteContourActor( );
1121 _controlerSelectionROI->SetActive( false );
1123 //------------------------------------------------------------------------------------------------------------
1124 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1126 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1127 long int start = clock();
1129 double sg = (double)(start) / (double)CLK_TCK;
1131 double sg = (double)(start) / CLOCKS_PER_SEC;
1134 crea::wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1135 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1136 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): %f\n \n",method.c_str(), tmpPx, tmpPy, sg);
1141 //------------------------------------------------------------------------------------------------------------
1142 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1144 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1145 manualViewBaseContour * cViewer;
1146 manualContourBaseControler * cControler;
1147 ContourWrap_ViewControl *conwraviwcont=iter->second;
1149 cViewer = conwraviwcont->getViewer();
1152 cControler = conwraviwcont->getControler();
1153 // cControler->Save(ff);
1155 // cModel = cControler->GetManualContourModel();
1156 // cModel->Save(ff);
1160 //------------------------------------------------------------------------------------------------------------
1161 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1163 std::vector<std::string> currentSelection = this->getSelectedObjects();
1164 if (currentSelection.size()>=1){
1166 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1167 manualBaseModel *cModel = cControler->GetManualContourModel();
1168 int i,size = cModel->GetNumberOfPointsSpline();
1170 for (i=0; i<size; i++)
1172 cModel->GetSpline_i_Point(i, &x, &y, &z);
1180 //------------------------------------------------------------------------------------------------------------
1181 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1183 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1184 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1187 //------------------------------------------------------------------------------------------------------------
1188 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1191 vtkImageData *imagedata = GetImageData();
1192 imagedata->GetExtent(ext);
1193 int sizeZ = ext[5]-ext[4]+1;
1201 //------------------------------------------------------------------------------------------------------------
1202 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1205 vtkImageData *imagedata = GetImageData();
1206 imagedata->GetExtent(ext);
1207 int sizeX = ext[1]-ext[0]+1;
1208 int sizeY = ext[3]-ext[2]+1;
1209 int sizeZ = GetImageDataSizeZ();
1210 int sizeXYZ = sizeX*sizeY*sizeZ;
1214 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1215 for (i=0;i<sizeXYZ;i++)
1217 if ( p[i]<range[0] ) range[0]=p[i];
1218 if ( p[i]>range[1] ) range[1]=p[i];
1222 //------------------------------------------------------------------------------------------------------------
1223 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1225 _widthOfContour = width;
1226 _widthOfControlPoint = _widthOfContour*_widthOfContour/2;
1227 manualViewBaseContour *cViewer;
1228 ContourWrap_ViewControl *conwraviwcont;
1229 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
1231 if (_contours_ViewControl!=NULL)
1233 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1235 conwraviwcont = iter->second;
1236 cViewer = conwraviwcont->getViewer();
1237 cViewer->SetShowText( false ); // EED 28Mars2011
1238 cViewer->SetWidthLine( _widthOfContour );
1239 cViewer->SetRange( _widthOfControlPoint );
1244 bool wxVtkBaseView_SceneManager::isEditableCControler(std::string theKeyName){
1246 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1248 manualContourBaseControler* cControler = ccon->getControler();
1249 if(cControler != NULL && cControler->IsEditable() == false){
1256 void wxVtkBaseView_SceneManager::deleteCViewerCControler(std::string theKeyName){
1259 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1261 manualViewBaseContour * cViewer = ccon->getViewer();
1262 manualContourBaseControler * cControler = ccon->getControler();
1264 removeFromScene(theKeyName);
1265 removeWrap(theKeyName);