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 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();
816 _toIncludeAtInteractionGroup = false;
819 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
822 _lastInteraction=NULL;
823 for( i =0; i<size ; i++ )
825 control = iter->second->getControler();
826 viewer = iter->second->getViewer();
827 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
828 control->SetActive( true );
830 foundOne = control->OnMouseMove();
831 foundOne &= viewer->GetPosibleSelected();
833 if ( !foundOne && singleMoving )
835 control->SetActive( false );
836 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
837 control->SetPosibleToMove( false );
841 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
843 _lastInteraction->getControler()->SetActive( true );
846 _lastInteraction = iter->second;
847 _lastInteractionName = iter->first;
849 viewer->UpdateColorActor();
850 control->SetPosibleToMove( true );
851 // viewer->AddCompleteContourActor();
866 //------------------------------------------------------------------------------------------------------------
867 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
872 //EED??? char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
873 bool condition = false;
874 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
875 //EED??? vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
876 //EED??? wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
877 //EED?? wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
878 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
880 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
881 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
882 _toIncludeAtInteractionGroup = false;
883 if ( ctrlKey || shftKey )
885 _toIncludeAtInteractionGroup = true;
889 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
891 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
893 _lastInteraction->getControler()->SetEditable( false );
894 _lastInteraction->getControler()->SetActive( false );
895 _lastInteraction->getControler()->SetPosibleToMove( false );
896 _lastInteraction->getViewer()->Refresh();
897 _lastInteraction=NULL;
904 if( !_toIncludeAtInteractionGroup )
906 _workingGroup->clear();
909 if( _lastInteraction!=NULL )
911 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
912 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
913 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
915 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
918 //setControlActiveStateOf( _contours_ViewControl, false );
919 sendEnvent( wxEVT_START_CREATE_ROI, "");
923 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
924 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
925 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
932 //------------------------------------------------------------------------------------------------------------
933 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
935 bool condition = false;
938 if( _drawingSelectionROI )
940 setSelection2DROIInternalOutlines();
944 //------------------------------------------------------------------------------------------------------------
945 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
947 bool condition = false;
952 //------------------------------------------------------------------------------------------------------------
953 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
955 bool condition = false;
960 //------------------------------------------------------------------------------------------------------------
961 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
963 bool condition = false;
964 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
965 //EED??? bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
972 //------------------------------------------------------------------------------------------------------------
973 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
975 bool condition = false;
977 //setControlActiveStateOfALL( false );//************************************************
978 if ( _creatingMULT_ROI )
980 //setControlActiveStateOfALL( false );
984 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
985 _creatingROI = false;
989 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
991 manualContourBaseControler * control = _lastInteraction->getControler();
992 //_lastInteraction->getControler()->SetPosibleToMove( false );
993 control->SetActive( false );
994 control->SetEditable( false );
995 control->SetPosibleToMove( false );
996 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
997 _lastInteraction->getViewer()->Refresh();
998 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1004 //------------------------------------------------------------------------------------------------------------
1006 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
1008 bool condition = false;
1013 //------------------------------------------------------------------------------------------------------------
1014 bool wxVtkBaseView_SceneManager :: OnRightDClick()
1016 bool condition = false; condition = true;
1017 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
1018 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
1019 //EED??? wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
1023 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
1024 set_creatingMULT_ROI( !_creatingMULT_ROI );
1032 //------------------------------------------------------------------------------------------------------------
1033 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
1035 bool condition = false;
1040 //------------------------------------------------------------------------------------------------------------
1041 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
1043 bool condition = false;
1047 //------------------------------------------------------------------------------------------------------------
1049 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1051 _drawingSelectionROI = true;
1052 _workingGroup->clear();
1053 _controlerSelectionROI->CreateNewManualContour();
1054 if (_lastInteraction!=NULL)
1056 _lastInteraction->getControler()->SetEditable( false );
1057 _lastInteraction->getControler()->SetActive( false );
1058 _lastInteraction->getControler()->SetPosibleToMove( false );
1059 _lastInteraction->getViewer()->Refresh();
1061 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1062 int i, workSize = _workingGroup->size();
1063 for( i=0; i< workSize; i++ )
1065 manualContourBaseControler * control = iter->second->getControler();
1066 control->SetEditable( false );
1067 control->SetActive( false );
1068 control->SetPosibleToMove( false );
1069 iter->second->getViewer()->Refresh();
1073 _lastInteraction = NULL;
1074 _lastInteractionName = "";
1076 _viewerSelectionROI->AddCompleteContourActor( true );
1077 _controlerSelectionROI->SetActive( true );
1079 _viewerSelectionROI->RefreshContour();
1080 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1082 //------------------------------------------------------------------------------------------------------------
1083 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1085 _drawingSelectionROI = false;
1086 _workingGroup->clear();
1087 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1090 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1091 int i, size = _sceneContours_ViewControl->size();
1092 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1093 manualViewBaseContour * viewer;
1094 bool insideRoi = false;
1095 for ( i=0; i<size; i++ )
1097 viewer = iter->second->getViewer();
1098 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1099 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1102 viewer->SetSelected( true );
1103 viewer->UpdateColorActor();
1104 setControlActiveStateOf( iter->second, true );
1105 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1109 _viewerSelectionROI->RemoveCompleteContourActor( );
1110 _controlerSelectionROI->SetActive( false );
1112 //------------------------------------------------------------------------------------------------------------
1113 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1115 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1116 long int start = clock();
1118 double sg = (double)(start) / (double)CLK_TCK;
1120 double sg = (double)(start) / CLOCKS_PER_SEC;
1123 wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1124 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1125 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): %f\n \n",method.c_str(), tmpPx, tmpPy, sg);
1130 //------------------------------------------------------------------------------------------------------------
1131 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1133 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1134 manualViewBaseContour * cViewer;
1135 manualContourBaseControler * cControler;
1136 ContourWrap_ViewControl *conwraviwcont=iter->second;
1138 cViewer = conwraviwcont->getViewer();
1141 cControler = conwraviwcont->getControler();
1142 // cControler->Save(ff);
1144 // cModel = cControler->GetManualContourModel();
1145 // cModel->Save(ff);
1149 //------------------------------------------------------------------------------------------------------------
1150 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1152 std::vector<std::string> currentSelection = this->getSelectedObjects();
1153 if (currentSelection.size()>=1){
1155 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1156 manualBaseModel *cModel = cControler->GetManualContourModel();
1157 int i,size = cModel->GetNumberOfPointsSpline();
1159 for (i=0; i<size; i++)
1161 cModel->GetSpline_i_Point(i, &x, &y, &z);
1169 //------------------------------------------------------------------------------------------------------------
1170 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1172 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1173 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1176 //------------------------------------------------------------------------------------------------------------
1177 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1180 vtkImageData *imagedata = GetImageData();
1181 imagedata->GetExtent(ext);
1182 int sizeZ = ext[5]-ext[4]+1;
1190 //------------------------------------------------------------------------------------------------------------
1191 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1194 vtkImageData *imagedata = GetImageData();
1195 imagedata->GetExtent(ext);
1196 int sizeX = ext[1]-ext[0]+1;
1197 int sizeY = ext[3]-ext[2]+1;
1198 int sizeZ = GetImageDataSizeZ();
1199 int sizeXYZ = sizeX*sizeY*sizeZ;
1203 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1204 for (i=0;i<sizeXYZ;i++)
1206 if ( p[i]<range[0] ) range[0]=p[i];
1207 if ( p[i]>range[1] ) range[1]=p[i];
1211 //------------------------------------------------------------------------------------------------------------
1212 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1214 _widthOfContour = width;
1215 _widthOfControlPoint = _widthOfContour*_widthOfContour/2;
1216 manualViewBaseContour *cViewer;
1217 ContourWrap_ViewControl *conwraviwcont;
1218 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
1220 if (_contours_ViewControl!=NULL)
1222 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1224 conwraviwcont = iter->second;
1225 cViewer = conwraviwcont->getViewer();
1226 cViewer->SetShowText( false ); // EED 28Mars2011
1227 cViewer->SetWidthLine( _widthOfContour );
1228 cViewer->SetRange( _widthOfControlPoint );
1233 bool wxVtkBaseView_SceneManager::isEditableCControler(std::string theKeyName){
1235 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1237 manualContourBaseControler* cControler = ccon->getControler();
1238 if(cControler != NULL && cControler->IsEditable() == false){
1245 void wxVtkBaseView_SceneManager::deleteCViewerCControler(std::string theKeyName){
1248 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1250 manualViewBaseContour * cViewer = ccon->getViewer();
1251 manualContourBaseControler * cControler = ccon->getControler();
1253 removeFromScene(theKeyName);
1254 removeWrap(theKeyName);