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;
148 //------------------------------------------------------------------------------------------------------------
149 void wxVtkBaseView_SceneManager :: configureViewControlTo( std::string theKeyName, manualBaseModel * manModelContour, double * spc,int typeContour)
151 //setControlActiveStateOfALL( false );
154 if( _lastInteraction!=NULL )
156 _lastInteraction->getControler()->SetEditable( false );
157 _lastInteraction->getViewer()->Refresh();
158 _lastInteraction->getControler()->SetActive( false );
159 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
163 manualContourBaseControler *manContourControl;
164 manualViewBaseContour *manViewerContour;
166 // Creating the view manualViewContour and the manualContourControler
167 // NOTE: The model is created in the KernelManagerContour class, factoryManualContourModel method
170 manContourControl = new manualContourControler();
171 manViewerContour = new manualViewContour();
176 manContourControl = new manualRoiControler();
177 manViewerContour = new manualViewRoi();
182 manContourControl = new manualCircleControler();
183 manViewerContour = new manualViewCircle();
188 manContourControl = new manualRoiControler();
189 manViewerContour = new manualViewBullEye();
194 manContourControl = new manualLineControler();
195 manViewerContour = new manualViewLine();
201 manContourControl = new manualContourControler();
202 manViewerContour = new manualViewPoints();
208 manContourControl = new manualContourControler();
209 manViewerContour = new manualViewContour();
214 _lastInteraction = insertWrap( theKeyName, manContourControl, manViewerContour );
215 _lastInteractionName = theKeyName;
217 //Configuring the relations between the contour members representation
218 manViewerContour->SetModel( manModelContour );
219 manViewerContour->SetWxVtkBaseView( _wxVtk_BaseView );
220 manViewerContour->SetRange( _widthOfControlPoint );
221 manViewerContour->SetZ( -900 );
223 manViewerContour->SetSpacing(spc);
225 manViewerContour->SetColorNormalContour(0, 0, 1);
226 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
227 manViewerContour->SetColorSelectContour(1, 0.8, 0);
228 manViewerContour->SetWidthLine(_widthOfContour);
230 manContourControl->SetModelView( manModelContour , manViewerContour );
231 manContourControl->Configure();
232 int i,sizeLstPoints = manModelContour->GetSizeLstPoints();
233 for ( i=0; i<sizeLstPoints; i++ )
235 manViewerContour->AddPoint();
238 manContourControl->CreateNewManualContour();
239 manViewerContour->RefreshContour();
240 addToScene( theKeyName );
242 //------------------------------------------------------------------------------------------------------------
243 void wxVtkBaseView_SceneManager :: configureSelectionROI( double * spc )
245 _controlerSelectionROI = new manualRoiControler();
246 _viewerSelectionROI = new manualViewRoi();
247 _modelSelectionROI = new manualContourModel();
249 _viewerSelectionROI->SetModel( _modelSelectionROI );
250 _viewerSelectionROI->SetWxVtkBaseView( _wxVtk_BaseView );
251 _viewerSelectionROI->SetRange( 2 );
252 _viewerSelectionROI->SetZ( -900 );
253 _viewerSelectionROI->SetColorNormalContour(0.6, 0.8, 0);
255 _viewerSelectionROI->SetSpacing( spc );
257 _controlerSelectionROI->SetModelView( _modelSelectionROI , _viewerSelectionROI );
258 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _controlerSelectionROI );
259 _controlerSelectionROI->SetActive(false);
262 //------------------------------------------------------------------------------------------------------------
263 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: insertWrap( std::string theKeyName, manualContourBaseControler * manContourControl, manualViewBaseContour * manViewerContour )
265 ContourWrap_ViewControl * newContourWrap = new ContourWrap_ViewControl(manContourControl, manViewerContour);
266 if(_contours_ViewControl == NULL)
268 _contours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
270 _contours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, newContourWrap ));
271 return newContourWrap;
273 //------------------------------------------------------------------------------------------------------------
274 void wxVtkBaseView_SceneManager :: desconfigureViewControlOf( std::string theKeyName )
278 //------------------------------------------------------------------------------------------------------------
279 void wxVtkBaseView_SceneManager :: removeWrap( std::string theKeyName )
281 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
282 iter = _contours_ViewControl->find( theKeyName );
283 _contours_ViewControl->erase( iter );
284 _lastInteraction=NULL;
285 _lastInteractionName = "";
286 _workingGroup->clear();
287 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
288 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;
298 //------------------------------------------------------------------------------------------------------------
299 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName, std::map<std::string, ContourWrap_ViewControl *> * theMap )
301 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
302 iter = theMap->find( theName );
305 //------------------------------------------------------------------------------------------------------------
306 manualContourBaseControler * wxVtkBaseView_SceneManager :: getControlerOf( std::string theName )
308 return getContourWrap_ViewControlOf ( theName )->getControler();
310 //------------------------------------------------------------------------------------------------------------
311 manualViewBaseContour * wxVtkBaseView_SceneManager :: getViewerOf( std::string theName )
313 return getContourWrap_ViewControlOf ( theName )->getViewer();
315 //------------------------------------------------------------------------------------------------------------
316 void wxVtkBaseView_SceneManager :: set_creatingMULT_ROI( bool condition )
318 _creatingMULT_ROI = condition;
320 //------------------------------------------------------------------------------------------------------------
321 void wxVtkBaseView_SceneManager :: set_editingROI( bool condition )
323 _editingROI = condition;
325 //------------------------------------------------------------------------------------------------------------
326 void wxVtkBaseView_SceneManager :: set_toIncludeAtInteractionGroup( bool condition )
328 _toIncludeAtInteractionGroup = condition;
330 //------------------------------------------------------------------------------------------------------------
331 void wxVtkBaseView_SceneManager :: set_waiting( bool condition )
333 _waiting = condition;
335 //------------------------------------------------------------------------------------------------------------
336 bool wxVtkBaseView_SceneManager :: get_creatingMULT_ROI( )
338 return _creatingMULT_ROI;
340 //------------------------------------------------------------------------------------------------------------
341 bool wxVtkBaseView_SceneManager :: get_editingROI( )
345 //------------------------------------------------------------------------------------------------------------
346 bool wxVtkBaseView_SceneManager :: get_toIncludeAtInteractionGroup( )
348 return _toIncludeAtInteractionGroup;
351 //------------------------------------------------------------------------------------------------------------
352 bool wxVtkBaseView_SceneManager :: get_waiting( )
357 //------------------------------------------------------------------------------------------------------------
358 bool wxVtkBaseView_SceneManager :: get_creatingROI()
362 //------------------------------------------------------------------------------------------------------------
363 void wxVtkBaseView_SceneManager :: set_creatingROI( bool condition )
365 _creatingROI = condition;
368 //------------------------------------------------------------------------------------------------------------
369 // Other functional methods
370 //------------------------------------------------------------------------------------------------------------
372 void wxVtkBaseView_SceneManager :: createCopyContourOf( std::string anExistingKName, std::string cloneName, manualBaseModel * manualModel, bool append )
376 setControlActiveStateOf( _workingGroup, false );
377 _workingGroup->clear();
379 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
382 iter = _contours_ViewControl->find( anExistingKName );
384 manualBaseModel *cModule = manualModel;
385 manualViewBaseContour *cViewer = iter->second->getViewer()->Clone();
386 manualContourBaseControler *cControl = iter->second->getControler()->Clone( );
388 cViewer->SetModel(cModule);
389 cControl->SetModelView( cModule , cViewer );
390 cControl->CreateNewManualContour();
391 cControl->SetActive( true );
392 cControl->SetEditable( false );
394 cViewer->RefreshContour();
396 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
397 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
399 _lastInteraction = insertWrap( cloneName, cControl, cViewer );
400 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( cloneName, _lastInteraction ));
401 addToScene( cloneName );
404 //------------------------------------------------------------------------------------------------------------
406 void wxVtkBaseView_SceneManager :: removeFromScene( ContourWrap_ViewControl * contourWRP, bool visualization, bool control )
408 if( contourWRP == _lastInteraction )
410 _lastInteraction = NULL;
411 _lastInteractionName = "";
415 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->RemoveInteractorStyleMaracas( contourWRP->getControler() );
417 contourWRP->getControler()->SetActive( control );
418 contourWRP->getControler()->SetEditable( false );
420 if ( !visualization && control )
422 contourWRP->getViewer()->RemoveControlPoints( );
423 contourWRP->getViewer()->RemoveTextActor( );
427 contourWRP->getViewer()->RemoveCompleteContourActor();
431 //------------------------------------------------------------------------------------------------------------
432 void wxVtkBaseView_SceneManager :: removeFromScene( std::string theKeyName, bool visualization , bool control )
435 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
436 iter = _sceneContours_ViewControl->find( theKeyName );
437 if (iter != _sceneContours_ViewControl->end())
439 ContourWrap_ViewControl * contourWRP = iter->second;
440 removeFromScene( contourWRP );
441 _sceneContours_ViewControl->erase(iter);
446 //------------------------------------------------------------------------------------------------------------
447 std::vector<std::string> wxVtkBaseView_SceneManager::GetlstContoursNameActualSlice()
449 std::vector<std::string> lstContoursNameActualSlice;
450 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
451 int i,size = _sceneContours_ViewControl->size();
452 for ( i = 0; i<size; i++ )
454 lstContoursNameActualSlice.push_back( iter->first );
457 return lstContoursNameActualSlice;
460 //------------------------------------------------------------------------------------------------------------
461 void wxVtkBaseView_SceneManager::removeSceneContours()
463 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
464 int size = _sceneContours_ViewControl->size();
465 for ( int i = 0; i<size; i++ )
467 removeFromScene( iter->second );
470 _sceneContours_ViewControl->clear();
471 //Removing the selection rectangle to avoid showing when it's innecesary
472 _controlerSelectionROI->SetActive( false );
473 _viewerSelectionROI->RemoveCompleteContourActor();
476 void wxVtkBaseView_SceneManager::removeAllOutlines()
478 manualViewBaseContour * cViewer;
479 manualContourBaseControler * cControler;
481 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
482 int i,size=_contours_ViewControl->size();
485 iter = _contours_ViewControl->begin();
486 cControler = iter->second->getControler();
487 cViewer = iter->second->getViewer();
488 removeWrap( iter->first );
496 //------------------------------------------------------------------------------------------------------------
497 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
501 removeSceneContours();
503 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
504 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
506 addToScene( theKeyName, contourWRP, true, visualization, control, ifActive, ifShowCtrlPoints);
509 //------------------------------------------------------------------------------------------------------------
510 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
514 removeSceneContours();
516 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
519 contourWRP->getViewer()->AddCompleteContourActor( ifShowCtrlPoints );
524 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( contourWRP->getControler() );
528 contourWRP->getControler()->SetActive( true );
529 contourWRP->getViewer()->RemoveTextActor();
533 //------------------------------------------------------------------------------------------------------------
534 void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
536 int i, size = theKeyNameVector.size();
537 for( i=0; i< size; i++ )
539 removeFromScene( theKeyNameVector[i], visualization, control );
543 //------------------------------------------------------------------------------------------------------------
544 void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
546 int i, size = theKeyNameVector.size();
547 for( i=0; i< size; i++ )
549 addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
553 //------------------------------------------------------------------------------------------------------------
554 void wxVtkBaseView_SceneManager :: setControlActiveStateOfALL( bool stateCondition )
556 setControlActiveStateOf( _contours_ViewControl, stateCondition );
559 //------------------------------------------------------------------------------------------------------------
560 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
562 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
563 setControlActiveStateOf( contourWRP, stateCondition );
566 //------------------------------------------------------------------------------------------------------------
567 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( ContourWrap_ViewControl * contourWRP, bool stateCondition )
569 contourWRP->getControler()->SetActive( stateCondition );
570 contourWRP->getControler()->SetEditable( false );
573 //------------------------------------------------------------------------------------------------------------
574 void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
576 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
577 // contourWRP->getViewer()->SetVisible( stateCondition );
578 if ( contourWRP!=NULL )
579 removeFromScene( contourWRP, false, stateCondition );
582 //------------------------------------------------------------------------------------------------------------
583 std::vector< std::string > wxVtkBaseView_SceneManager :: getSelectedObjects()
585 std::vector< std::string > selectedObjects;
586 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
587 int size = _workingGroup->size();
588 for ( int i = 0; i<size; i++ )
590 //EED??? manualViewBaseContour * viewer = iter->second->getViewer();
591 selectedObjects.push_back( iter->first);
595 return selectedObjects;
597 //------------------------------------------------------------------------------------------------------------
598 void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
600 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
601 //EED??? int size = _contours_ViewControl->size();
602 //EED??? bool selected;
603 /*for ( int i = 0; i<size; i++ )
606 manualViewBaseContour * viewer = iter->second->getViewer();
607 std::vector <std::string >::iterator iterIN;
609 for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
611 if( iter->first.compare( theExistingObjectsToSelect[i] ) )
613 viewer->SelectAllPoints( true );
614 viewer->SelectPosibleContour( true );
616 theExistingObjectsToSelect.erase( iterIN );
624 //------------------------------------------------------------------------------------------------------------
625 void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
627 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
628 int size = _contours_ViewControl->size();
629 for ( int i = 0; i<size; i++ )
631 manualViewBaseContour * viewer = iter->second->getViewer();
633 viewer->SetSelected( true );
634 /*viewer->SelectAllPoints( true );
635 viewer->SelectPosibleContour( true );*/
641 //------------------------------------------------------------------------------------------------------------
642 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
644 int i, size = theKeyNameVector.size();
645 for( i=0; i< size; i++ )
647 setControlActiveStateOf( theKeyNameVector[i], controlCondition );
651 //------------------------------------------------------------------------------------------------------------
652 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
654 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
655 int i, size = theMap->size();
656 for( i=0; i< size; i++ )
658 removeFromScene( iter->second, false, controlCondition );
663 //------------------------------------------------------------------------------------------------------------
665 //------------------------------------------------------------------------------------------------------------
667 //------------------------------------------------------------------------------------------------------------
668 // Creational and initialization methods
669 //------------------------------------------------------------------------------------------------------------
671 //------------------------------------------------------------------------------------------------------------
673 //------------------------------------------------------------------------------------------------------------
675 bool wxVtkBaseView_SceneManager :: isCtrlPressed()
679 bool wxVtkBaseView_SceneManager :: isShiftPressed()
683 char wxVtkBaseView_SceneManager :: getLastKeyCode()
687 bool wxVtkBaseView_SceneManager :: OnChar()
690 _ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
691 _shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
693 _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
695 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
696 _eventHandler->ProcessEvent( cevent );
699 /*if( _eventHandler!=NULL )
701 char * toolCommand = NULL;
703 if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
705 toolCommand = &(COPY_TOOL);
707 else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
709 toolCommand = &(PASTE_TOOL);
711 else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
713 toolCommand = &(DELETE_KEY);
715 else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
717 toolCommand = &(CREATE_CONTOUR_KEY);
719 else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
721 toolCommand = &(OPEN_TOOL);
723 else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
725 toolCommand = &(SAVE_KEY);
728 if ( toolCommand!=NULL )
730 currentkey = toolCommand;
731 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
732 cevent.SetClientData( (void *) toolCommand);
733 _eventHandler->ProcessEvent( cevent );
738 // long int endtime = clock();
742 //------------------------------------------------------------------------------------------------------------
744 bool wxVtkBaseView_SceneManager :: OnMouseMove()
747 bool condition = true;
749 crea::wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
750 _wxVTKiren->GetEventPosition( X , Y );
752 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
753 //??? bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
755 if( _waiting && !ctrlKey )
757 sendEnvent( wxEVT_CHANGED_DEEP, "Update");
758 //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
761 if ( !_creatingROI && !_creatingMULT_ROI )
764 /*if( ctrlKey || shiftKey )
770 _toIncludeAtInteractionGroup = false;
773 bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
774 std::string preservingName = preserveState ? _lastInteractionName : "";
776 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
777 int i, size = _sceneContours_ViewControl->size();
778 bool foundOne = false;
780 manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
781 manualViewBaseContour * viewer = NULL;
784 bool singleMoving = true;
785 int selectionSize = _workingGroup->size();
786 if( selectionSize > 1 )
790 //EED??? bool ckecking = false;
791 for( i =0; i<size ; i++ )
793 control = iter->second->getControler();
794 viewer = iter->second->getViewer();
795 /*ckecking = */control->SetActive( true );
797 if (_lastInteraction != NULL)
799 singleMoving = !_lastInteraction->getViewer()->GetSelected();
804 size = selectionSize;
805 iter = _workingGroup->begin();
809 _toIncludeAtInteractionGroup = false;
812 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
815 _lastInteraction=NULL;
816 for( i =0; i<size ; i++ )
818 control = iter->second->getControler();
819 viewer = iter->second->getViewer();
820 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
821 control->SetActive( true );
823 foundOne = control->OnMouseMove();
824 foundOne &= viewer->GetPosibleSelected();
826 if ( !foundOne && singleMoving )
828 control->SetActive( false );
829 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
830 control->SetPosibleToMove( false );
834 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
836 _lastInteraction->getControler()->SetActive( true );
839 _lastInteraction = iter->second;
840 _lastInteractionName = iter->first;
842 viewer->UpdateColorActor();
843 control->SetPosibleToMove( true );
844 // viewer->AddCompleteContourActor();
859 //------------------------------------------------------------------------------------------------------------
860 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
865 //EED??? char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
866 bool condition = false;
867 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
868 //EED??? vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
869 //EED??? wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
870 //EED?? wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
871 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
873 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
874 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
875 _toIncludeAtInteractionGroup = false;
876 if ( ctrlKey || shftKey )
878 _toIncludeAtInteractionGroup = true;
882 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
884 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
886 _lastInteraction->getControler()->SetEditable( false );
887 _lastInteraction->getControler()->SetActive( false );
888 _lastInteraction->getControler()->SetPosibleToMove( false );
889 _lastInteraction->getViewer()->Refresh();
890 _lastInteraction=NULL;
897 if( !_toIncludeAtInteractionGroup )
899 _workingGroup->clear();
902 if( _lastInteraction!=NULL )
904 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
905 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
906 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
908 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
911 //setControlActiveStateOf( _contours_ViewControl, false );
912 sendEnvent( wxEVT_START_CREATE_ROI, "");
916 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
917 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
918 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
925 //------------------------------------------------------------------------------------------------------------
926 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
928 bool condition = false;
931 if( _drawingSelectionROI )
933 setSelection2DROIInternalOutlines();
937 //------------------------------------------------------------------------------------------------------------
938 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
940 bool condition = false;
945 //------------------------------------------------------------------------------------------------------------
946 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
948 bool condition = false;
953 //------------------------------------------------------------------------------------------------------------
954 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
956 bool condition = false;
957 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
958 //EED??? bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
965 //------------------------------------------------------------------------------------------------------------
966 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
968 bool condition = false;
970 //setControlActiveStateOfALL( false );//************************************************
971 if ( _creatingMULT_ROI )
973 //setControlActiveStateOfALL( false );
977 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
978 _creatingROI = false;
982 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
984 manualContourBaseControler * control = _lastInteraction->getControler();
985 //_lastInteraction->getControler()->SetPosibleToMove( false );
986 control->SetActive( false );
987 control->SetEditable( false );
988 control->SetPosibleToMove( false );
989 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
990 _lastInteraction->getViewer()->Refresh();
991 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
997 //------------------------------------------------------------------------------------------------------------
999 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
1001 bool condition = false;
1006 //------------------------------------------------------------------------------------------------------------
1007 bool wxVtkBaseView_SceneManager :: OnRightDClick()
1009 bool condition = false; condition = true;
1010 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
1011 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
1012 //EED??? wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
1016 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
1017 set_creatingMULT_ROI( !_creatingMULT_ROI );
1025 //------------------------------------------------------------------------------------------------------------
1026 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
1028 bool condition = false;
1033 //------------------------------------------------------------------------------------------------------------
1034 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
1036 bool condition = false;
1040 //------------------------------------------------------------------------------------------------------------
1042 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1044 _drawingSelectionROI = true;
1045 _workingGroup->clear();
1046 _controlerSelectionROI->CreateNewManualContour();
1047 if (_lastInteraction!=NULL)
1049 _lastInteraction->getControler()->SetEditable( false );
1050 _lastInteraction->getControler()->SetActive( false );
1051 _lastInteraction->getControler()->SetPosibleToMove( false );
1052 _lastInteraction->getViewer()->Refresh();
1054 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1055 int i, workSize = _workingGroup->size();
1056 for( i=0; i< workSize; i++ )
1058 manualContourBaseControler * control = iter->second->getControler();
1059 control->SetEditable( false );
1060 control->SetActive( false );
1061 control->SetPosibleToMove( false );
1062 iter->second->getViewer()->Refresh();
1066 _lastInteraction = NULL;
1067 _lastInteractionName = "";
1069 _viewerSelectionROI->AddCompleteContourActor( true );
1070 _controlerSelectionROI->SetActive( true );
1072 _viewerSelectionROI->RefreshContour();
1073 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1075 //------------------------------------------------------------------------------------------------------------
1076 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1078 _drawingSelectionROI = false;
1079 _workingGroup->clear();
1080 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1083 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1084 int i, size = _sceneContours_ViewControl->size();
1085 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1086 manualViewBaseContour * viewer;
1087 bool insideRoi = false;
1088 for ( i=0; i<size; i++ )
1090 viewer = iter->second->getViewer();
1091 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1092 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1095 viewer->SetSelected( true );
1096 viewer->UpdateColorActor();
1097 setControlActiveStateOf( iter->second, true );
1098 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1102 _viewerSelectionROI->RemoveCompleteContourActor( );
1103 _controlerSelectionROI->SetActive( false );
1105 //------------------------------------------------------------------------------------------------------------
1106 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1108 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1109 long int start = clock();
1111 double sg = (double)(start) / (double)CLK_TCK;
1113 double sg = (double)(start) / CLOCKS_PER_SEC;
1116 crea::wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1117 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1118 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): %f\n \n",method.c_str(), tmpPx, tmpPy, sg);
1123 //------------------------------------------------------------------------------------------------------------
1124 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1126 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1127 manualViewBaseContour * cViewer;
1128 manualContourBaseControler * cControler;
1129 ContourWrap_ViewControl *conwraviwcont=iter->second;
1131 cViewer = conwraviwcont->getViewer();
1134 cControler = conwraviwcont->getControler();
1135 // cControler->Save(ff);
1137 // cModel = cControler->GetManualContourModel();
1138 // cModel->Save(ff);
1142 //------------------------------------------------------------------------------------------------------------
1143 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1145 std::vector<std::string> currentSelection = this->getSelectedObjects();
1146 if (currentSelection.size()>=1){
1148 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1149 manualBaseModel *cModel = cControler->GetManualContourModel();
1150 int i,size = cModel->GetNumberOfPointsSpline();
1152 for (i=0; i<size; i++)
1154 cModel->GetSpline_i_Point(i, &x, &y, &z);
1162 //------------------------------------------------------------------------------------------------------------
1163 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1165 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1166 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1169 //------------------------------------------------------------------------------------------------------------
1170 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1173 vtkImageData *imagedata = GetImageData();
1174 imagedata->GetExtent(ext);
1175 int sizeZ = ext[5]-ext[4]+1;
1183 //------------------------------------------------------------------------------------------------------------
1184 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1187 vtkImageData *imagedata = GetImageData();
1188 imagedata->GetExtent(ext);
1189 int sizeX = ext[1]-ext[0]+1;
1190 int sizeY = ext[3]-ext[2]+1;
1191 int sizeZ = GetImageDataSizeZ();
1192 int sizeXYZ = sizeX*sizeY*sizeZ;
1196 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1197 for (i=0;i<sizeXYZ;i++)
1199 if ( p[i]<range[0] ) range[0]=p[i];
1200 if ( p[i]>range[1] ) range[1]=p[i];
1204 //------------------------------------------------------------------------------------------------------------
1205 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1207 _widthOfContour = width;
1208 _widthOfControlPoint = _widthOfContour*_widthOfContour/2;
1209 manualViewBaseContour *cViewer;
1210 ContourWrap_ViewControl *conwraviwcont;
1211 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
1213 if (_contours_ViewControl!=NULL)
1215 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1217 conwraviwcont = iter->second;
1218 cViewer = conwraviwcont->getViewer();
1219 cViewer->SetShowText( false ); // EED 28Mars2011
1220 cViewer->SetWidthLine( _widthOfContour );
1221 cViewer->SetRange( _widthOfControlPoint );
1226 bool wxVtkBaseView_SceneManager::isEditableCControler(std::string theKeyName){
1228 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1230 manualContourBaseControler* cControler = ccon->getControler();
1231 if(cControler != NULL && cControler->IsEditable() == false){
1238 void wxVtkBaseView_SceneManager::deleteCViewerCControler(std::string theKeyName){
1241 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1243 manualViewBaseContour * cViewer = ccon->getViewer();
1244 manualContourBaseControler * cControler = ccon->getControler();
1246 removeFromScene(theKeyName);
1247 removeWrap(theKeyName);