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() );
538 contourWRP->getControler()->SetActive( true );
539 contourWRP->getViewer()->RemoveTextActor();
543 //------------------------------------------------------------------------------------------------------------
544 void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
546 int i, size = theKeyNameVector.size();
547 for( i=0; i< size; i++ )
549 removeFromScene( theKeyNameVector[i], visualization, control );
553 //------------------------------------------------------------------------------------------------------------
554 void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
556 int i, size = theKeyNameVector.size();
557 for( i=0; i< size; i++ )
559 addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
563 //------------------------------------------------------------------------------------------------------------
564 void wxVtkBaseView_SceneManager :: setControlActiveStateOfALL( bool stateCondition )
566 setControlActiveStateOf( _contours_ViewControl, stateCondition );
569 //------------------------------------------------------------------------------------------------------------
570 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
572 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
573 setControlActiveStateOf( contourWRP, stateCondition );
576 //------------------------------------------------------------------------------------------------------------
577 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( ContourWrap_ViewControl * contourWRP, bool stateCondition )
579 contourWRP->getControler()->SetActive( stateCondition );
580 contourWRP->getControler()->SetEditable( false );
583 //------------------------------------------------------------------------------------------------------------
584 void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
586 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
587 // contourWRP->getViewer()->SetVisible( stateCondition );
588 if ( contourWRP!=NULL )
589 removeFromScene( contourWRP, false, stateCondition );
592 //------------------------------------------------------------------------------------------------------------
593 std::vector< std::string > wxVtkBaseView_SceneManager :: getSelectedObjects()
595 std::vector< std::string > selectedObjects;
596 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
597 int size = _workingGroup->size();
598 for ( int i = 0; i<size; i++ )
600 //EED??? manualViewBaseContour * viewer = iter->second->getViewer();
601 selectedObjects.push_back( iter->first);
605 return selectedObjects;
607 //------------------------------------------------------------------------------------------------------------
608 void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
610 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
611 //EED??? int size = _contours_ViewControl->size();
612 //EED??? bool selected;
613 /*for ( int i = 0; i<size; i++ )
616 manualViewBaseContour * viewer = iter->second->getViewer();
617 std::vector <std::string >::iterator iterIN;
619 for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
621 if( iter->first.compare( theExistingObjectsToSelect[i] ) )
623 viewer->SelectAllPoints( true );
624 viewer->SelectPosibleContour( true );
626 theExistingObjectsToSelect.erase( iterIN );
634 //------------------------------------------------------------------------------------------------------------
635 void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
637 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
638 int size = _contours_ViewControl->size();
639 for ( int i = 0; i<size; i++ )
641 manualViewBaseContour * viewer = iter->second->getViewer();
643 viewer->SetSelected( true );
644 /*viewer->SelectAllPoints( true );
645 viewer->SelectPosibleContour( true );*/
651 //------------------------------------------------------------------------------------------------------------
652 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
654 int i, size = theKeyNameVector.size();
655 for( i=0; i< size; i++ )
657 setControlActiveStateOf( theKeyNameVector[i], controlCondition );
661 //------------------------------------------------------------------------------------------------------------
662 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
664 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
665 int i, size = theMap->size();
666 for( i=0; i< size; i++ )
668 removeFromScene( iter->second, false, controlCondition );
673 //------------------------------------------------------------------------------------------------------------
675 //------------------------------------------------------------------------------------------------------------
677 //------------------------------------------------------------------------------------------------------------
678 // Creational and initialization methods
679 //------------------------------------------------------------------------------------------------------------
681 //------------------------------------------------------------------------------------------------------------
683 //------------------------------------------------------------------------------------------------------------
685 bool wxVtkBaseView_SceneManager :: isCtrlPressed()
689 bool wxVtkBaseView_SceneManager :: isShiftPressed()
693 char wxVtkBaseView_SceneManager :: getLastKeyCode()
697 bool wxVtkBaseView_SceneManager :: OnChar()
700 _ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
701 _shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
703 _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
705 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
706 _eventHandler->ProcessEvent( cevent );
709 /*if( _eventHandler!=NULL )
711 char * toolCommand = NULL;
713 if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
715 toolCommand = &(COPY_TOOL);
717 else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
719 toolCommand = &(PASTE_TOOL);
721 else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
723 toolCommand = &(DELETE_KEY);
725 else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
727 toolCommand = &(CREATE_CONTOUR_KEY);
729 else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
731 toolCommand = &(OPEN_TOOL);
733 else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
735 toolCommand = &(SAVE_KEY);
738 if ( toolCommand!=NULL )
740 currentkey = toolCommand;
741 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
742 cevent.SetClientData( (void *) toolCommand);
743 _eventHandler->ProcessEvent( cevent );
748 // long int endtime = clock();
752 //------------------------------------------------------------------------------------------------------------
754 bool wxVtkBaseView_SceneManager :: OnMouseMove()
757 bool condition = true;
759 crea::wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
760 _wxVTKiren->GetEventPosition( X , Y );
762 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
763 //??? bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
765 if( _waiting && !ctrlKey )
767 sendEnvent( wxEVT_CHANGED_DEEP, "Update");
768 //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
771 if ( !_creatingROI && !_creatingMULT_ROI )
774 /*if( ctrlKey || shiftKey )
780 _toIncludeAtInteractionGroup = false;
783 bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
784 std::string preservingName = preserveState ? _lastInteractionName : "";
786 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
787 int i, size = _sceneContours_ViewControl->size();
788 bool foundOne = false;
790 manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
791 manualViewBaseContour * viewer = NULL;
794 bool singleMoving = true;
795 int selectionSize = _workingGroup->size();
796 if( selectionSize > 1 )
800 //EED??? bool ckecking = false;
801 for( i =0; i<size ; i++ )
803 control = iter->second->getControler();
804 viewer = iter->second->getViewer();
805 /*ckecking = */control->SetActive( true );
807 if (_lastInteraction != NULL)
809 singleMoving = !_lastInteraction->getViewer()->GetSelected();
814 size = selectionSize;
815 iter = _workingGroup->begin();
819 _toIncludeAtInteractionGroup = false;
822 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
825 _lastInteraction=NULL;
826 for( i =0; i<size ; i++ )
828 control = iter->second->getControler();
829 viewer = iter->second->getViewer();
830 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
831 control->SetActive( true );
833 foundOne = control->OnMouseMove();
834 foundOne &= viewer->GetPosibleSelected();
836 if ( !foundOne && singleMoving )
838 control->SetActive( false );
839 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
840 control->SetPosibleToMove( false );
844 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
846 _lastInteraction->getControler()->SetActive( true );
849 _lastInteraction = iter->second;
850 _lastInteractionName = iter->first;
852 viewer->UpdateColorActor();
853 control->SetPosibleToMove( true );
854 // viewer->AddCompleteContourActor();
869 //------------------------------------------------------------------------------------------------------------
870 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
875 //EED??? char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
876 bool condition = false;
877 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
878 //EED??? vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
879 //EED??? wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
880 //EED?? wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
881 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
883 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
884 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
885 _toIncludeAtInteractionGroup = false;
886 if ( ctrlKey || shftKey )
888 _toIncludeAtInteractionGroup = true;
892 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
894 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
896 _lastInteraction->getControler()->SetEditable( false );
897 _lastInteraction->getControler()->SetActive( false );
898 _lastInteraction->getControler()->SetPosibleToMove( false );
899 _lastInteraction->getViewer()->Refresh();
900 _lastInteraction=NULL;
907 if( !_toIncludeAtInteractionGroup )
909 _workingGroup->clear();
912 if( _lastInteraction!=NULL )
914 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
915 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
916 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
918 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
921 //setControlActiveStateOf( _contours_ViewControl, false );
922 sendEnvent( wxEVT_START_CREATE_ROI, "");
926 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
927 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
928 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
935 //------------------------------------------------------------------------------------------------------------
936 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
938 bool condition = false;
941 if( _drawingSelectionROI )
943 setSelection2DROIInternalOutlines();
947 //------------------------------------------------------------------------------------------------------------
948 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
950 bool condition = false;
955 //------------------------------------------------------------------------------------------------------------
956 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
958 bool condition = false;
963 //------------------------------------------------------------------------------------------------------------
964 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
966 bool condition = false;
967 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
968 //EED??? bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
975 //------------------------------------------------------------------------------------------------------------
976 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
978 bool condition = false;
980 //setControlActiveStateOfALL( false );//************************************************
981 if ( _creatingMULT_ROI )
983 //setControlActiveStateOfALL( false );
987 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
988 _creatingROI = false;
992 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
994 manualContourBaseControler * control = _lastInteraction->getControler();
995 //_lastInteraction->getControler()->SetPosibleToMove( false );
996 control->SetActive( false );
997 control->SetEditable( false );
998 control->SetPosibleToMove( false );
999 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
1000 _lastInteraction->getViewer()->Refresh();
1001 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1007 //------------------------------------------------------------------------------------------------------------
1009 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
1011 bool condition = false;
1016 //------------------------------------------------------------------------------------------------------------
1017 bool wxVtkBaseView_SceneManager :: OnRightDClick()
1019 bool condition = false; condition = true;
1020 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
1021 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
1022 //EED??? wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
1026 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
1027 set_creatingMULT_ROI( !_creatingMULT_ROI );
1035 //------------------------------------------------------------------------------------------------------------
1036 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
1038 bool condition = false;
1043 //------------------------------------------------------------------------------------------------------------
1044 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
1046 bool condition = false;
1050 //------------------------------------------------------------------------------------------------------------
1052 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1054 _drawingSelectionROI = true;
1055 _workingGroup->clear();
1056 _controlerSelectionROI->CreateNewManualContour();
1057 if (_lastInteraction!=NULL)
1059 _lastInteraction->getControler()->SetEditable( false );
1060 _lastInteraction->getControler()->SetActive( false );
1061 _lastInteraction->getControler()->SetPosibleToMove( false );
1062 _lastInteraction->getViewer()->Refresh();
1064 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1065 int i, workSize = _workingGroup->size();
1066 for( i=0; i< workSize; i++ )
1068 manualContourBaseControler * control = iter->second->getControler();
1069 control->SetEditable( false );
1070 control->SetActive( false );
1071 control->SetPosibleToMove( false );
1072 iter->second->getViewer()->Refresh();
1076 _lastInteraction = NULL;
1077 _lastInteractionName = "";
1079 _viewerSelectionROI->AddCompleteContourActor( true );
1080 _controlerSelectionROI->SetActive( true );
1082 _viewerSelectionROI->RefreshContour();
1083 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1085 //------------------------------------------------------------------------------------------------------------
1086 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1088 _drawingSelectionROI = false;
1089 _workingGroup->clear();
1090 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1093 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1094 int i, size = _sceneContours_ViewControl->size();
1095 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1096 manualViewBaseContour * viewer;
1097 bool insideRoi = false;
1098 for ( i=0; i<size; i++ )
1100 viewer = iter->second->getViewer();
1101 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1102 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1105 viewer->SetSelected( true );
1106 viewer->UpdateColorActor();
1107 setControlActiveStateOf( iter->second, true );
1108 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1112 _viewerSelectionROI->RemoveCompleteContourActor( );
1113 _controlerSelectionROI->SetActive( false );
1115 //------------------------------------------------------------------------------------------------------------
1116 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1118 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1119 long int start = clock();
1121 double sg = (double)(start) / (double)CLK_TCK;
1123 double sg = (double)(start) / CLOCKS_PER_SEC;
1126 crea::wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1127 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1128 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): %f\n \n",method.c_str(), tmpPx, tmpPy, sg);
1133 //------------------------------------------------------------------------------------------------------------
1134 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1136 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1137 manualViewBaseContour * cViewer;
1138 manualContourBaseControler * cControler;
1139 ContourWrap_ViewControl *conwraviwcont=iter->second;
1141 cViewer = conwraviwcont->getViewer();
1144 cControler = conwraviwcont->getControler();
1145 // cControler->Save(ff);
1147 // cModel = cControler->GetManualContourModel();
1148 // cModel->Save(ff);
1152 //------------------------------------------------------------------------------------------------------------
1153 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1155 std::vector<std::string> currentSelection = this->getSelectedObjects();
1156 if (currentSelection.size()>=1){
1158 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1159 manualBaseModel *cModel = cControler->GetManualContourModel();
1160 int i,size = cModel->GetNumberOfPointsSpline();
1162 for (i=0; i<size; i++)
1164 cModel->GetSpline_i_Point(i, &x, &y, &z);
1172 //------------------------------------------------------------------------------------------------------------
1173 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1175 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1176 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1179 //------------------------------------------------------------------------------------------------------------
1180 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1183 vtkImageData *imagedata = GetImageData();
1184 imagedata->GetExtent(ext);
1185 int sizeZ = ext[5]-ext[4]+1;
1193 //------------------------------------------------------------------------------------------------------------
1194 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1197 vtkImageData *imagedata = GetImageData();
1198 imagedata->GetExtent(ext);
1199 int sizeX = ext[1]-ext[0]+1;
1200 int sizeY = ext[3]-ext[2]+1;
1201 int sizeZ = GetImageDataSizeZ();
1202 int sizeXYZ = sizeX*sizeY*sizeZ;
1206 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1207 for (i=0;i<sizeXYZ;i++)
1209 if ( p[i]<range[0] ) range[0]=p[i];
1210 if ( p[i]>range[1] ) range[1]=p[i];
1214 //------------------------------------------------------------------------------------------------------------
1215 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1217 _widthOfContour = width;
1218 _widthOfControlPoint = _widthOfContour*_widthOfContour/2;
1219 manualViewBaseContour *cViewer;
1220 ContourWrap_ViewControl *conwraviwcont;
1221 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
1223 if (_contours_ViewControl!=NULL)
1225 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1227 conwraviwcont = iter->second;
1228 cViewer = conwraviwcont->getViewer();
1229 cViewer->SetShowText( false ); // EED 28Mars2011
1230 cViewer->SetWidthLine( _widthOfContour );
1231 cViewer->SetRange( _widthOfControlPoint );
1236 bool wxVtkBaseView_SceneManager::isEditableCControler(std::string theKeyName){
1238 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1240 manualContourBaseControler* cControler = ccon->getControler();
1241 if(cControler != NULL && cControler->IsEditable() == false){
1248 void wxVtkBaseView_SceneManager::deleteCViewerCControler(std::string theKeyName){
1251 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1253 manualViewBaseContour * cViewer = ccon->getViewer();
1254 manualContourBaseControler * cControler = ccon->getControler();
1256 removeFromScene(theKeyName);
1257 removeWrap(theKeyName);