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 )
69 _lastInteraction = NULL;
70 _lastInteractionName = "";
71 _eventHandler = theEventHandler;
75 _contours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
76 _sceneContours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
77 _workingGroup = new std::map< std::string, ContourWrap_ViewControl * >();
79 _creatingMULT_ROI = false;
81 _toIncludeAtInteractionGroup = false;
84 _drawingSelectionROI = false;
87 _wxVtk_BaseView = theWxBaseViewToManage;
88 if( _wxVtk_BaseView!=NULL )
90 vtkInteractorStyleBaseView* theInteractorStyleBaseView = (vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView();
91 theInteractorStyleBaseView->AddInteractorStyleMaracas( this );
92 SetVtkInteractorStyleBaseView( theInteractorStyleBaseView );
94 configureSelectionROI( spc );
96 //------------------------------------------------------------------------------------------------------------
97 wxVtkBaseView_SceneManager :: ~wxVtkBaseView_SceneManager()
99 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
100 int size = _contours_ViewControl->size();
101 for ( int i = 0; i<size; iter++ )
103 _contours_ViewControl->erase( iter );
106 _contours_ViewControl->clear();
107 delete _contours_ViewControl;
108 _workingGroup->clear();
109 delete _lastInteraction;
110 delete _workingGroup;
111 //delete _contours_ViewControl;
114 //------------------------------------------------------------------------------------------------------------
115 // Methods for capturing events
116 //------------------------------------------------------------------------------------------------------------
119 //------------------------------------------------------------------------------------------------------------
120 // Methods for sending events
121 //------------------------------------------------------------------------------------------------------------
122 void wxVtkBaseView_SceneManager :: sendEnvent( WXTYPE theEventType, std::string text )
124 if ( _eventHandler != NULL )
126 wxCommandEvent cevent( theEventType );
127 cevent.SetString( wxString( text.c_str(), wxConvUTF8) );
128 _eventHandler->ProcessEvent( cevent );
133 //------------------------------------------------------------------------------------------------------------
134 // Attributes getters and setters
135 //------------------------------------------------------------------------------------------------------------
136 void wxVtkBaseView_SceneManager :: setWxEventHandler( wxEvtHandler * theEventHandler )
138 _eventHandler = theEventHandler;
140 //------------------------------------------------------------------------------------------------------------
141 void wxVtkBaseView_SceneManager :: setWxVtkViewBase( wxVtkBaseView * theBaseView )
143 _wxVtk_BaseView = theBaseView;
146 //------------------------------------------------------------------------------------------------------------
147 wxVtkBaseView * wxVtkBaseView_SceneManager :: getWxVtkViewBase()
149 return _wxVtk_BaseView;
151 //------------------------------------------------------------------------------------------------------------
152 void wxVtkBaseView_SceneManager :: configureViewControlTo( std::string theKeyName, manualBaseModel * manModelContour, double * spc,int typeContour)
154 //setControlActiveStateOfALL( false );
157 if( _lastInteraction!=NULL )
159 _lastInteraction->getControler()->SetEditable( false );
160 _lastInteraction->getViewer()->Refresh();
161 _lastInteraction->getControler()->SetActive( false );
162 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
166 manualContourBaseControler *manContourControl;
167 manualViewBaseContour *manViewerContour;
169 // Creating the view manualViewContour and the manualContourControler
170 // NOTE: The model is created in the KernelManagerContour class, factoryManualContourModel method
173 manContourControl = new manualContourControler();
174 manViewerContour = new manualViewContour();
179 manContourControl = new manualRoiControler();
180 manViewerContour = new manualViewRoi();
185 manContourControl = new manualCircleControler();
186 manViewerContour = new manualViewCircle();
191 manContourControl = new manualRoiControler();
192 manViewerContour = new manualViewBullEye();
197 manContourControl = new manualLineControler();
198 manViewerContour = new manualViewLine();
204 manContourControl = new manualContourControler();
205 manViewerContour = new manualViewPoints();
211 manContourControl = new manualContourControler();
212 manViewerContour = new manualViewContour();
217 _lastInteraction = insertWrap( theKeyName, manContourControl, manViewerContour );
218 _lastInteractionName = theKeyName;
220 //Configuring the relations between the contour members representation
221 manViewerContour->SetModel( manModelContour );
222 manViewerContour->SetWxVtkBaseView( _wxVtk_BaseView );
223 manViewerContour->SetRange( _widthOfControlPoint );
224 manViewerContour->SetZ( -900 );
226 manViewerContour->SetSpacing(spc);
228 manViewerContour->SetColorNormalContour(0, 0, 1);
229 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
230 manViewerContour->SetColorSelectContour(1, 0.8, 0);
231 manViewerContour->SetWidthLine(_widthOfContour);
233 manContourControl->SetModelView( manModelContour , manViewerContour );
234 manContourControl->Configure();
235 int i,sizeLstPoints = manModelContour->GetSizeLstPoints();
236 for ( i=0; i<sizeLstPoints; i++ )
238 manViewerContour->AddPoint();
241 manContourControl->CreateNewManualContour();
242 manViewerContour->RefreshContour();
243 addToScene( theKeyName );
245 //------------------------------------------------------------------------------------------------------------
246 void wxVtkBaseView_SceneManager :: configureSelectionROI( double * spc )
248 _controlerSelectionROI = new manualRoiControler();
249 _viewerSelectionROI = new manualViewRoi();
250 _modelSelectionROI = new manualContourModel();
252 _viewerSelectionROI->SetModel( _modelSelectionROI );
253 _viewerSelectionROI->SetWxVtkBaseView( _wxVtk_BaseView );
254 _viewerSelectionROI->SetRange( 2 );
255 _viewerSelectionROI->SetZ( -900 );
256 _viewerSelectionROI->SetColorNormalContour(0.6, 0.8, 0);
258 _viewerSelectionROI->SetSpacing( spc );
260 _controlerSelectionROI->SetModelView( _modelSelectionROI , _viewerSelectionROI );
261 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _controlerSelectionROI );
262 _controlerSelectionROI->SetActive(false);
265 //------------------------------------------------------------------------------------------------------------
266 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: insertWrap( std::string theKeyName, manualContourBaseControler * manContourControl, manualViewBaseContour * manViewerContour )
268 ContourWrap_ViewControl * newContourWrap = new ContourWrap_ViewControl(manContourControl, manViewerContour);
269 if(_contours_ViewControl == NULL)
271 _contours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
273 _contours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, newContourWrap ));
274 return newContourWrap;
276 //------------------------------------------------------------------------------------------------------------
277 void wxVtkBaseView_SceneManager :: desconfigureViewControlOf( std::string theKeyName )
281 //------------------------------------------------------------------------------------------------------------
282 void wxVtkBaseView_SceneManager :: removeWrap( std::string theKeyName )
284 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
285 iter = _contours_ViewControl->find( theKeyName );
286 _contours_ViewControl->erase( iter );
287 _lastInteraction=NULL;
288 _lastInteractionName = "";
289 _workingGroup->clear();
290 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
291 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
293 //------------------------------------------------------------------------------------------------------------
294 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName )
296 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
297 iter = _contours_ViewControl->find( theName );
299 //return iter->first;
301 //------------------------------------------------------------------------------------------------------------
302 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName, std::map<std::string, ContourWrap_ViewControl *> * theMap )
304 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
305 iter = theMap->find( theName );
308 //------------------------------------------------------------------------------------------------------------
309 manualContourBaseControler * wxVtkBaseView_SceneManager :: getControlerOf( std::string theName )
311 return getContourWrap_ViewControlOf ( theName )->getControler();
313 //------------------------------------------------------------------------------------------------------------
314 manualViewBaseContour * wxVtkBaseView_SceneManager :: getViewerOf( std::string theName )
316 return getContourWrap_ViewControlOf ( theName )->getViewer();
318 //------------------------------------------------------------------------------------------------------------
319 void wxVtkBaseView_SceneManager :: set_creatingMULT_ROI( bool condition )
321 _creatingMULT_ROI = condition;
323 //------------------------------------------------------------------------------------------------------------
324 void wxVtkBaseView_SceneManager :: set_editingROI( bool condition )
326 _editingROI = condition;
328 //------------------------------------------------------------------------------------------------------------
329 void wxVtkBaseView_SceneManager :: set_toIncludeAtInteractionGroup( bool condition )
331 _toIncludeAtInteractionGroup = condition;
333 //------------------------------------------------------------------------------------------------------------
334 void wxVtkBaseView_SceneManager :: set_waiting( bool condition )
336 _waiting = condition;
338 //------------------------------------------------------------------------------------------------------------
339 bool wxVtkBaseView_SceneManager :: get_creatingMULT_ROI( )
341 return _creatingMULT_ROI;
343 //------------------------------------------------------------------------------------------------------------
344 bool wxVtkBaseView_SceneManager :: get_editingROI( )
348 //------------------------------------------------------------------------------------------------------------
349 bool wxVtkBaseView_SceneManager :: get_toIncludeAtInteractionGroup( )
351 return _toIncludeAtInteractionGroup;
354 //------------------------------------------------------------------------------------------------------------
355 bool wxVtkBaseView_SceneManager :: get_waiting( )
360 //------------------------------------------------------------------------------------------------------------
361 bool wxVtkBaseView_SceneManager :: get_creatingROI()
365 //------------------------------------------------------------------------------------------------------------
366 void wxVtkBaseView_SceneManager :: set_creatingROI( bool condition )
368 _creatingROI = condition;
371 //------------------------------------------------------------------------------------------------------------
372 // Other functional methods
373 //------------------------------------------------------------------------------------------------------------
375 void wxVtkBaseView_SceneManager :: createCopyContourOf( std::string anExistingKName, std::string cloneName, manualBaseModel * manualModel, bool append )
379 setControlActiveStateOf( _workingGroup, false );
380 _workingGroup->clear();
382 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
385 iter = _contours_ViewControl->find( anExistingKName );
387 manualBaseModel *cModule = manualModel;
388 manualViewBaseContour *cViewer = iter->second->getViewer()->Clone();
389 manualContourBaseControler *cControl = iter->second->getControler()->Clone( );
391 cViewer->SetModel(cModule);
392 cControl->SetModelView( cModule , cViewer );
393 cControl->CreateNewManualContour();
394 cControl->SetActive( true );
395 cControl->SetEditable( false );
397 cViewer->RefreshContour();
399 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
400 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
402 _lastInteraction = insertWrap( cloneName, cControl, cViewer );
403 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( cloneName, _lastInteraction ));
404 addToScene( cloneName );
407 //------------------------------------------------------------------------------------------------------------
409 void wxVtkBaseView_SceneManager :: removeFromScene( ContourWrap_ViewControl * contourWRP, bool visualization, bool control )
411 if( contourWRP == _lastInteraction )
413 _lastInteraction = NULL;
414 _lastInteractionName = "";
418 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->RemoveInteractorStyleMaracas( contourWRP->getControler() );
420 contourWRP->getControler()->SetActive( control );
421 contourWRP->getControler()->SetEditable( false );
423 if ( !visualization && control )
425 contourWRP->getViewer()->RemoveControlPoints( );
426 contourWRP->getViewer()->RemoveTextActor( );
430 contourWRP->getViewer()->RemoveCompleteContourActor();
434 //------------------------------------------------------------------------------------------------------------
435 void wxVtkBaseView_SceneManager :: removeFromScene( std::string theKeyName, bool visualization , bool control )
438 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
439 iter = _sceneContours_ViewControl->find( theKeyName );
440 if (iter != _sceneContours_ViewControl->end())
442 ContourWrap_ViewControl * contourWRP = iter->second;
443 removeFromScene( contourWRP );
444 _sceneContours_ViewControl->erase(iter);
449 //------------------------------------------------------------------------------------------------------------
450 std::vector<std::string> wxVtkBaseView_SceneManager::GetlstContoursNameActualSlice()
452 std::vector<std::string> lstContoursNameActualSlice;
453 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
454 int i,size = _sceneContours_ViewControl->size();
455 for ( i = 0; i<size; i++ )
457 lstContoursNameActualSlice.push_back( iter->first );
460 return lstContoursNameActualSlice;
463 //------------------------------------------------------------------------------------------------------------
464 void wxVtkBaseView_SceneManager :: removeSceneContours( )
466 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
467 int size = _sceneContours_ViewControl->size();
468 for ( int i = 0; i<size; i++ )
470 removeFromScene( iter->second );
473 _sceneContours_ViewControl->clear();
476 //Removing the selection rectangle to avoid showing when it's innecesary
477 _controlerSelectionROI->SetActive( false );
478 _viewerSelectionROI->RemoveCompleteContourActor();
481 void wxVtkBaseView_SceneManager::removeAllOutlines()
483 manualViewBaseContour * cViewer;
484 manualContourBaseControler * cControler;
486 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
487 int i,size=_contours_ViewControl->size();
490 iter = _contours_ViewControl->begin();
491 cControler = iter->second->getControler();
492 cViewer = iter->second->getViewer();
493 removeWrap( iter->first );
501 //------------------------------------------------------------------------------------------------------------
502 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
506 removeSceneContours();
508 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
509 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
511 addToScene( theKeyName, contourWRP, true, visualization, control, ifActive, ifShowCtrlPoints);
514 //------------------------------------------------------------------------------------------------------------
515 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
519 removeSceneContours();
521 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
524 contourWRP->getViewer()->AddCompleteContourActor( ifShowCtrlPoints );
529 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( contourWRP->getControler() );
533 contourWRP->getControler()->SetActive( true );
534 contourWRP->getViewer()->RemoveTextActor();
538 //------------------------------------------------------------------------------------------------------------
539 void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
541 int i, size = theKeyNameVector.size();
542 for( i=0; i< size; i++ )
544 removeFromScene( theKeyNameVector[i], visualization, control );
548 //------------------------------------------------------------------------------------------------------------
549 void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
551 int i, size = theKeyNameVector.size();
552 for( i=0; i< size; i++ )
554 addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
558 //------------------------------------------------------------------------------------------------------------
559 void wxVtkBaseView_SceneManager :: setControlActiveStateOfALL( bool stateCondition )
561 setControlActiveStateOf( _contours_ViewControl, stateCondition );
564 //------------------------------------------------------------------------------------------------------------
565 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
567 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
568 setControlActiveStateOf( contourWRP, stateCondition );
571 //------------------------------------------------------------------------------------------------------------
572 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( ContourWrap_ViewControl * contourWRP, bool stateCondition )
574 contourWRP->getControler()->SetActive( stateCondition );
575 contourWRP->getControler()->SetEditable( false );
578 //------------------------------------------------------------------------------------------------------------
579 void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
581 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
582 // contourWRP->getViewer()->SetVisible( stateCondition );
583 if ( contourWRP!=NULL )
584 removeFromScene( contourWRP, false, stateCondition );
587 //------------------------------------------------------------------------------------------------------------
588 std::vector< std::string > wxVtkBaseView_SceneManager :: getSelectedObjects()
590 std::vector< std::string > selectedObjects;
591 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
592 int size = _workingGroup->size();
593 for ( int i = 0; i<size; i++ )
595 //EED??? manualViewBaseContour * viewer = iter->second->getViewer();
596 selectedObjects.push_back( iter->first);
600 return selectedObjects;
602 //------------------------------------------------------------------------------------------------------------
603 void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
605 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
606 //EED??? int size = _contours_ViewControl->size();
607 //EED??? bool selected;
608 /*for ( int i = 0; i<size; i++ )
611 manualViewBaseContour * viewer = iter->second->getViewer();
612 std::vector <std::string >::iterator iterIN;
614 for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
616 if( iter->first.compare( theExistingObjectsToSelect[i] ) )
618 viewer->SelectAllPoints( true );
619 viewer->SelectPosibleContour( true );
621 theExistingObjectsToSelect.erase( iterIN );
629 //------------------------------------------------------------------------------------------------------------
630 void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
632 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
633 int size = _contours_ViewControl->size();
634 for ( int i = 0; i<size; i++ )
636 manualViewBaseContour * viewer = iter->second->getViewer();
638 viewer->SetSelected( true );
639 /*viewer->SelectAllPoints( true );
640 viewer->SelectPosibleContour( true );*/
646 //------------------------------------------------------------------------------------------------------------
647 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
649 int i, size = theKeyNameVector.size();
650 for( i=0; i< size; i++ )
652 setControlActiveStateOf( theKeyNameVector[i], controlCondition );
656 //------------------------------------------------------------------------------------------------------------
657 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
659 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
660 int i, size = theMap->size();
661 for( i=0; i< size; i++ )
663 removeFromScene( iter->second, false, controlCondition );
668 //------------------------------------------------------------------------------------------------------------
670 //------------------------------------------------------------------------------------------------------------
672 //------------------------------------------------------------------------------------------------------------
673 // Creational and initialization methods
674 //------------------------------------------------------------------------------------------------------------
676 //------------------------------------------------------------------------------------------------------------
678 //------------------------------------------------------------------------------------------------------------
680 bool wxVtkBaseView_SceneManager :: isCtrlPressed()
684 bool wxVtkBaseView_SceneManager :: isShiftPressed()
688 char wxVtkBaseView_SceneManager :: getLastKeyCode()
692 bool wxVtkBaseView_SceneManager :: OnChar()
695 _ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
696 _shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
698 _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
700 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
701 _eventHandler->ProcessEvent( cevent );
704 /*if( _eventHandler!=NULL )
706 char * toolCommand = NULL;
708 if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
710 toolCommand = &(COPY_TOOL);
712 else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
714 toolCommand = &(PASTE_TOOL);
716 else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
718 toolCommand = &(DELETE_KEY);
720 else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
722 toolCommand = &(CREATE_CONTOUR_KEY);
724 else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
726 toolCommand = &(OPEN_TOOL);
728 else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
730 toolCommand = &(SAVE_KEY);
733 if ( toolCommand!=NULL )
735 currentkey = toolCommand;
736 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
737 cevent.SetClientData( (void *) toolCommand);
738 _eventHandler->ProcessEvent( cevent );
743 // long int endtime = clock();
747 //------------------------------------------------------------------------------------------------------------
749 bool wxVtkBaseView_SceneManager :: OnMouseMove()
752 bool condition = true;
754 crea::wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
755 _wxVTKiren->GetEventPosition( X , Y );
757 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
758 //??? bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
760 if( _waiting && !ctrlKey )
762 sendEnvent( wxEVT_CHANGED_DEEP, "Update");
763 //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
766 if ( !_creatingROI && !_creatingMULT_ROI )
769 /*if( ctrlKey || shiftKey )
775 _toIncludeAtInteractionGroup = false;
778 bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
779 std::string preservingName = preserveState ? _lastInteractionName : "";
781 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
782 int i, size = _sceneContours_ViewControl->size();
783 bool foundOne = false;
785 manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
786 manualViewBaseContour * viewer = NULL;
789 bool singleMoving = true;
790 int selectionSize = _workingGroup->size();
791 if( selectionSize > 1 )
795 //EED??? bool ckecking = false;
796 for( i =0; i<size ; i++ )
798 control = iter->second->getControler();
799 viewer = iter->second->getViewer();
800 /*ckecking = */control->SetActive( true );
802 if (_lastInteraction != NULL)
804 singleMoving = !_lastInteraction->getViewer()->GetSelected();
809 size = selectionSize;
810 iter = _workingGroup->begin();
814 _toIncludeAtInteractionGroup = false;
817 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
820 _lastInteraction=NULL;
821 for( i =0; i<size ; i++ )
823 control = iter->second->getControler();
824 viewer = iter->second->getViewer();
825 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
826 control->SetActive( true );
828 foundOne = control->OnMouseMove();
829 foundOne &= viewer->GetPosibleSelected();
831 if ( !foundOne && singleMoving )
833 control->SetActive( false );
834 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
835 control->SetPosibleToMove( false );
839 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
841 _lastInteraction->getControler()->SetActive( true );
844 _lastInteraction = iter->second;
845 _lastInteractionName = iter->first;
847 viewer->UpdateColorActor();
848 control->SetPosibleToMove( true );
849 // viewer->AddCompleteContourActor();
864 //------------------------------------------------------------------------------------------------------------
865 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
870 //EED??? char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
871 bool condition = false;
872 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
873 //EED??? vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
874 //EED??? wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
875 //EED?? wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
876 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
878 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
879 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
880 _toIncludeAtInteractionGroup = false;
881 if ( ctrlKey || shftKey )
883 _toIncludeAtInteractionGroup = true;
887 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
889 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
891 _lastInteraction->getControler()->SetEditable( false );
892 _lastInteraction->getControler()->SetActive( false );
893 _lastInteraction->getControler()->SetPosibleToMove( false );
894 _lastInteraction->getViewer()->Refresh();
895 _lastInteraction=NULL;
902 if( !_toIncludeAtInteractionGroup )
904 _workingGroup->clear();
907 if( _lastInteraction!=NULL )
909 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
910 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
911 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
913 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
916 //setControlActiveStateOf( _contours_ViewControl, false );
917 sendEnvent( wxEVT_START_CREATE_ROI, "");
921 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
922 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
923 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
930 //------------------------------------------------------------------------------------------------------------
931 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
933 bool condition = false;
936 if( _drawingSelectionROI )
938 setSelection2DROIInternalOutlines();
942 //------------------------------------------------------------------------------------------------------------
943 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
945 bool condition = false;
950 //------------------------------------------------------------------------------------------------------------
951 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
953 bool condition = false;
958 //------------------------------------------------------------------------------------------------------------
959 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
961 bool condition = false;
962 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
963 //EED??? bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
970 //------------------------------------------------------------------------------------------------------------
971 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
973 bool condition = false;
975 //setControlActiveStateOfALL( false );//************************************************
976 if ( _creatingMULT_ROI )
978 //setControlActiveStateOfALL( false );
982 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
983 _creatingROI = false;
987 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
989 manualContourBaseControler * control = _lastInteraction->getControler();
990 //_lastInteraction->getControler()->SetPosibleToMove( false );
991 control->SetActive( false );
992 control->SetEditable( false );
993 control->SetPosibleToMove( false );
994 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
995 _lastInteraction->getViewer()->Refresh();
996 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1002 //------------------------------------------------------------------------------------------------------------
1004 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
1006 bool condition = false;
1011 //------------------------------------------------------------------------------------------------------------
1012 bool wxVtkBaseView_SceneManager :: OnRightDClick()
1014 bool condition = false; condition = true;
1015 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
1016 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
1017 //EED??? wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
1021 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
1022 set_creatingMULT_ROI( !_creatingMULT_ROI );
1030 //------------------------------------------------------------------------------------------------------------
1031 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
1033 bool condition = false;
1038 //------------------------------------------------------------------------------------------------------------
1039 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
1041 bool condition = false;
1045 //------------------------------------------------------------------------------------------------------------
1047 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1049 _drawingSelectionROI = true;
1050 _workingGroup->clear();
1051 _controlerSelectionROI->CreateNewManualContour();
1052 if (_lastInteraction!=NULL)
1054 _lastInteraction->getControler()->SetEditable( false );
1055 _lastInteraction->getControler()->SetActive( false );
1056 _lastInteraction->getControler()->SetPosibleToMove( false );
1057 _lastInteraction->getViewer()->Refresh();
1059 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1060 int i, workSize = _workingGroup->size();
1061 for( i=0; i< workSize; i++ )
1063 manualContourBaseControler * control = iter->second->getControler();
1064 control->SetEditable( false );
1065 control->SetActive( false );
1066 control->SetPosibleToMove( false );
1067 iter->second->getViewer()->Refresh();
1071 _lastInteraction = NULL;
1072 _lastInteractionName = "";
1074 _viewerSelectionROI->AddCompleteContourActor( true );
1075 _controlerSelectionROI->SetActive( true );
1077 _viewerSelectionROI->RefreshContour();
1078 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1080 //------------------------------------------------------------------------------------------------------------
1081 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1083 _drawingSelectionROI = false;
1084 _workingGroup->clear();
1085 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1088 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1089 int i, size = _sceneContours_ViewControl->size();
1090 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1091 manualViewBaseContour * viewer;
1092 bool insideRoi = false;
1093 for ( i=0; i<size; i++ )
1095 viewer = iter->second->getViewer();
1096 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1097 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1100 viewer->SetSelected( true );
1101 viewer->UpdateColorActor();
1102 setControlActiveStateOf( iter->second, true );
1103 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1107 _viewerSelectionROI->RemoveCompleteContourActor( );
1108 _controlerSelectionROI->SetActive( false );
1110 //------------------------------------------------------------------------------------------------------------
1111 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1113 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1114 long int start = clock();
1116 double sg = (double)(start) / (double)CLK_TCK;
1118 double sg = (double)(start) / CLOCKS_PER_SEC;
1121 crea::wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1122 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1123 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): %f\n \n",method.c_str(), tmpPx, tmpPy, sg);
1128 //------------------------------------------------------------------------------------------------------------
1129 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1131 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1132 manualViewBaseContour * cViewer;
1133 manualContourBaseControler * cControler;
1134 ContourWrap_ViewControl *conwraviwcont=iter->second;
1136 cViewer = conwraviwcont->getViewer();
1139 cControler = conwraviwcont->getControler();
1140 // cControler->Save(ff);
1142 // cModel = cControler->GetManualContourModel();
1143 // cModel->Save(ff);
1147 //------------------------------------------------------------------------------------------------------------
1148 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1150 std::vector<std::string> currentSelection = this->getSelectedObjects();
1151 if (currentSelection.size()>=1){
1153 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1154 manualBaseModel *cModel = cControler->GetManualContourModel();
1155 int i,size = cModel->GetNumberOfPointsSpline();
1157 for (i=0; i<size; i++)
1159 cModel->GetSpline_i_Point(i, &x, &y, &z);
1167 //------------------------------------------------------------------------------------------------------------
1168 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1170 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1171 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1174 //------------------------------------------------------------------------------------------------------------
1175 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1178 vtkImageData *imagedata = GetImageData();
1179 imagedata->GetExtent(ext);
1180 int sizeZ = ext[5]-ext[4]+1;
1188 //------------------------------------------------------------------------------------------------------------
1189 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1192 vtkImageData *imagedata = GetImageData();
1193 imagedata->GetExtent(ext);
1194 int sizeX = ext[1]-ext[0]+1;
1195 int sizeY = ext[3]-ext[2]+1;
1196 int sizeZ = GetImageDataSizeZ();
1197 int sizeXYZ = sizeX*sizeY*sizeZ;
1201 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1202 for (i=0;i<sizeXYZ;i++)
1204 if ( p[i]<range[0] ) range[0]=p[i];
1205 if ( p[i]>range[1] ) range[1]=p[i];
1209 //------------------------------------------------------------------------------------------------------------
1210 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1212 _widthOfContour = width;
1213 _widthOfControlPoint = _widthOfContour*_widthOfContour/2;
1214 manualViewBaseContour *cViewer;
1215 ContourWrap_ViewControl *conwraviwcont;
1216 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
1218 if (_contours_ViewControl!=NULL)
1220 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1222 conwraviwcont = iter->second;
1223 cViewer = conwraviwcont->getViewer();
1224 cViewer->SetShowText( false ); // EED 28Mars2011
1225 cViewer->SetWidthLine( _widthOfContour );
1226 cViewer->SetRange( _widthOfControlPoint );
1231 bool wxVtkBaseView_SceneManager::isEditableCControler(std::string theKeyName){
1233 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1235 manualContourBaseControler* cControler = ccon->getControler();
1236 if(cControler != NULL && cControler->IsEditable() == false){
1243 void wxVtkBaseView_SceneManager::deleteCViewerCControler(std::string theKeyName){
1246 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1248 manualViewBaseContour * cViewer = ccon->getViewer();
1249 manualContourBaseControler * cControler = ccon->getControler();
1251 removeFromScene(theKeyName);
1252 removeWrap(theKeyName);