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;
82 _showTextContour = true;
84 _wxVtk_BaseView = theWxBaseViewToManage;
85 if( _wxVtk_BaseView!=NULL )
87 vtkInteractorStyleBaseView* theInteractorStyleBaseView = (vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView();
88 theInteractorStyleBaseView->AddInteractorStyleMaracas( this );
89 SetVtkInteractorStyleBaseView( theInteractorStyleBaseView );
91 configureSelectionROI( spc );
92 configureTextNumberOfContour();
95 //------------------------------------------------------------------------------------------------------------
96 wxVtkBaseView_SceneManager :: ~wxVtkBaseView_SceneManager()
98 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
99 int size = _contours_ViewControl->size();
100 for ( int i = 0; i<size; iter++ )
102 _contours_ViewControl->erase( iter );
105 _contours_ViewControl->clear();
106 delete _contours_ViewControl;
107 _workingGroup->clear();
108 delete _lastInteraction;
109 delete _workingGroup;
110 //delete _contours_ViewControl;
113 //------------------------------------------------------------------------------------------------------------
114 // Methods for capturing events
115 //------------------------------------------------------------------------------------------------------------
118 //------------------------------------------------------------------------------------------------------------
119 // Methods for sending events
120 //------------------------------------------------------------------------------------------------------------
121 void wxVtkBaseView_SceneManager :: sendEnvent( WXTYPE theEventType, std::string text )
123 if ( _eventHandler != NULL )
125 wxCommandEvent cevent( theEventType );
126 cevent.SetString( wxString( text.c_str(), wxConvUTF8) );
127 _eventHandler->ProcessEvent( cevent );
131 //------------------------------------------------------------------------------------------------------------
132 // Attributes getters and setters
133 //------------------------------------------------------------------------------------------------------------
134 void wxVtkBaseView_SceneManager :: setWxEventHandler( wxEvtHandler * theEventHandler )
136 _eventHandler = theEventHandler;
139 //------------------------------------------------------------------------------------------------------------
140 void wxVtkBaseView_SceneManager :: setWxVtkViewBase( wxVtkBaseView * theBaseView )
142 _wxVtk_BaseView = theBaseView;
145 //------------------------------------------------------------------------------------------------------------
146 wxVtkBaseView * wxVtkBaseView_SceneManager :: getWxVtkViewBase()
148 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();
164 manualContourBaseControler *manContourControl;
165 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 void wxVtkBaseView_SceneManager::configureTextNumberOfContour()
266 vtkTextActor *textActor = vtkTextActor::New();
267 textActor->SetDisplayPosition(10, 85);
268 textActor->SetInput("contours:--");
269 // Set coordinates to match the old vtkScaledTextActor default value
270 textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
271 textActor->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
272 vtkTextProperty *tprop = textActor->GetTextProperty();
273 tprop->SetFontSize(14);
274 tprop->SetFontFamilyToArial();
275 tprop->SetColor(1, 1, 0);
276 _wxVtk_BaseView->GetRenderer()->AddActor2D(textActor);
277 _numberOfContoursTextActor=textActor;
280 //------------------------------------------------------------------------------------------------------------
281 void wxVtkBaseView_SceneManager::SetLabelNumberOfContours( std::string label )
283 _numberOfContoursTextActor->SetInput( label.c_str() );
286 //------------------------------------------------------------------------------------------------------------
287 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: insertWrap( std::string theKeyName, manualContourBaseControler * manContourControl, manualViewBaseContour * manViewerContour )
289 ContourWrap_ViewControl * newContourWrap = new ContourWrap_ViewControl(manContourControl, manViewerContour);
290 if(_contours_ViewControl == NULL)
292 _contours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
294 _contours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, newContourWrap ));
295 return newContourWrap;
298 //------------------------------------------------------------------------------------------------------------
299 void wxVtkBaseView_SceneManager :: desconfigureViewControlOf( std::string theKeyName )
303 //------------------------------------------------------------------------------------------------------------
304 void wxVtkBaseView_SceneManager :: removeWrap( std::string theKeyName )
306 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
307 iter = _contours_ViewControl->find( theKeyName );
308 _contours_ViewControl->erase( iter );
309 _lastInteraction=NULL;
310 _lastInteractionName = "";
311 _workingGroup->clear();
312 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
313 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
316 //------------------------------------------------------------------------------------------------------------
317 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName )
319 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
320 iter = _contours_ViewControl->find( theName );
322 //return iter->first;
325 //------------------------------------------------------------------------------------------------------------
326 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName, std::map<std::string, ContourWrap_ViewControl *> * theMap )
328 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
329 iter = theMap->find( theName );
333 //------------------------------------------------------------------------------------------------------------
334 manualContourBaseControler * wxVtkBaseView_SceneManager :: getControlerOf( std::string theName )
336 return getContourWrap_ViewControlOf ( theName )->getControler();
339 //------------------------------------------------------------------------------------------------------------
340 manualViewBaseContour * wxVtkBaseView_SceneManager :: getViewerOf( std::string theName )
342 return getContourWrap_ViewControlOf ( theName )->getViewer();
345 //------------------------------------------------------------------------------------------------------------
346 void wxVtkBaseView_SceneManager :: set_creatingMULT_ROI( bool condition )
348 _creatingMULT_ROI = condition;
351 //------------------------------------------------------------------------------------------------------------
352 void wxVtkBaseView_SceneManager :: set_editingROI( bool condition )
354 _editingROI = condition;
357 //------------------------------------------------------------------------------------------------------------
358 void wxVtkBaseView_SceneManager :: set_toIncludeAtInteractionGroup( bool condition )
360 _toIncludeAtInteractionGroup = condition;
363 //------------------------------------------------------------------------------------------------------------
364 void wxVtkBaseView_SceneManager :: set_waiting( bool condition )
366 _waiting = condition;
369 //------------------------------------------------------------------------------------------------------------
370 bool wxVtkBaseView_SceneManager :: get_creatingMULT_ROI( )
372 return _creatingMULT_ROI;
375 //------------------------------------------------------------------------------------------------------------
376 bool wxVtkBaseView_SceneManager :: get_editingROI( )
381 //------------------------------------------------------------------------------------------------------------
382 bool wxVtkBaseView_SceneManager :: get_toIncludeAtInteractionGroup( )
384 return _toIncludeAtInteractionGroup;
387 //------------------------------------------------------------------------------------------------------------
388 bool wxVtkBaseView_SceneManager :: get_waiting( )
393 //------------------------------------------------------------------------------------------------------------
394 bool wxVtkBaseView_SceneManager :: get_creatingROI()
398 //------------------------------------------------------------------------------------------------------------
399 void wxVtkBaseView_SceneManager :: set_creatingROI( bool condition )
401 _creatingROI = condition;
404 //------------------------------------------------------------------------------------------------------------
405 // Other functional methods
406 //------------------------------------------------------------------------------------------------------------
408 void wxVtkBaseView_SceneManager :: createCopyContourOf( std::string anExistingKName, std::string cloneName, manualBaseModel * manualModel, bool append )
412 setControlActiveStateOf( _workingGroup, false );
413 _workingGroup->clear();
415 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
418 iter = _contours_ViewControl->find( anExistingKName );
420 manualBaseModel *cModule = manualModel;
421 manualViewBaseContour *cViewer = iter->second->getViewer()->Clone();
422 manualContourBaseControler *cControl = iter->second->getControler()->Clone( );
424 cViewer->SetModel(cModule);
425 cControl->SetModelView( cModule , cViewer );
426 cControl->CreateNewManualContour();
427 cControl->SetActive( true );
428 cControl->SetEditable( false );
430 cViewer->RefreshContour();
432 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
433 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
435 _lastInteraction = insertWrap( cloneName, cControl, cViewer );
436 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( cloneName, _lastInteraction ));
437 addToScene( cloneName );
440 //------------------------------------------------------------------------------------------------------------
442 void wxVtkBaseView_SceneManager :: removeFromScene( ContourWrap_ViewControl * contourWRP, bool visualization, bool control )
444 if( contourWRP == _lastInteraction )
446 _lastInteraction = NULL;
447 _lastInteractionName = "";
451 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->RemoveInteractorStyleMaracas( contourWRP->getControler() );
453 contourWRP->getControler()->SetActive( control );
454 contourWRP->getControler()->SetEditable( false );
456 if ( !visualization && control )
458 contourWRP->getViewer()->RemoveControlPoints( );
459 contourWRP->getViewer()->RemoveTextActor( );
463 contourWRP->getViewer()->RemoveCompleteContourActor();
467 //------------------------------------------------------------------------------------------------------------
468 void wxVtkBaseView_SceneManager :: removeFromScene( std::string theKeyName, bool visualization , bool control )
471 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
472 iter = _sceneContours_ViewControl->find( theKeyName );
473 if (iter != _sceneContours_ViewControl->end())
475 ContourWrap_ViewControl * contourWRP = iter->second;
476 removeFromScene( contourWRP );
477 _sceneContours_ViewControl->erase(iter);
482 //------------------------------------------------------------------------------------------------------------
483 std::vector<std::string> wxVtkBaseView_SceneManager::GetlstContoursNameActualSlice()
485 std::vector<std::string> lstContoursNameActualSlice;
486 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
487 int i,size = _sceneContours_ViewControl->size();
488 for ( i = 0; i<size; i++ )
490 lstContoursNameActualSlice.push_back( iter->first );
493 return lstContoursNameActualSlice;
496 //------------------------------------------------------------------------------------------------------------
497 void wxVtkBaseView_SceneManager::removeSceneContours()
499 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
500 int size = _sceneContours_ViewControl->size();
501 for ( int i = 0; i<size; i++ )
503 removeFromScene( iter->second );
506 _sceneContours_ViewControl->clear();
507 //Removing the selection rectangle to avoid showing when it's innecesary
508 _controlerSelectionROI->SetActive( false );
509 _viewerSelectionROI->RemoveCompleteContourActor();
512 void wxVtkBaseView_SceneManager::removeAllOutlines()
514 manualViewBaseContour * cViewer;
515 manualContourBaseControler * cControler;
517 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
518 int i,size=_contours_ViewControl->size();
521 iter = _contours_ViewControl->begin();
522 cControler = iter->second->getControler();
523 cViewer = iter->second->getViewer();
524 removeWrap( iter->first );
532 //------------------------------------------------------------------------------------------------------------
533 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
537 removeSceneContours();
539 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
540 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
542 addToScene( theKeyName, contourWRP, true, visualization, control, ifActive, ifShowCtrlPoints);
545 //------------------------------------------------------------------------------------------------------------
546 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
550 removeSceneContours();
553 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
555 if ( visualization==true )
557 contourWRP->getViewer()->AddCompleteContourActor( ifShowCtrlPoints );
558 } // if visualization
562 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( contourWRP->getControler() );
567 contourWRP->getViewer()->SetColorNormalContour(1,0,0);
569 contourWRP->getViewer()->SetColorNormalContour(0,0,1);
574 contourWRP->getControler()->SetActive( true );
575 contourWRP->getViewer()->RemoveTextActor();
578 contourWRP->getViewer()->SetShowText(_showTextContour);
581 //------------------------------------------------------------------------------------------------------------
582 void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
584 int i, size = theKeyNameVector.size();
585 for( i=0; i< size; i++ )
587 removeFromScene( theKeyNameVector[i], visualization, control );
591 //------------------------------------------------------------------------------------------------------------
592 void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
594 int i, size = theKeyNameVector.size();
595 for( i=0; i< size; i++ )
597 addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
601 //------------------------------------------------------------------------------------------------------------
602 void wxVtkBaseView_SceneManager :: setControlActiveStateOfALL( bool stateCondition )
604 setControlActiveStateOf( _contours_ViewControl, stateCondition );
607 //------------------------------------------------------------------------------------------------------------
608 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
610 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
611 setControlActiveStateOf( contourWRP, stateCondition );
614 //------------------------------------------------------------------------------------------------------------
615 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( ContourWrap_ViewControl * contourWRP, bool stateCondition )
617 contourWRP->getControler()->SetActive( stateCondition );
618 contourWRP->getControler()->SetEditable( false );
621 //------------------------------------------------------------------------------------------------------------
622 void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
624 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
625 // contourWRP->getViewer()->SetVisible( stateCondition );
626 if ( contourWRP!=NULL )
627 removeFromScene( contourWRP, false, stateCondition );
630 //------------------------------------------------------------------------------------------------------------
631 std::vector< std::string > wxVtkBaseView_SceneManager :: getSelectedObjects()
633 std::vector< std::string > selectedObjects;
634 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
635 int size = _workingGroup->size();
636 for ( int i = 0; i<size; i++ )
638 //EED??? manualViewBaseContour * viewer = iter->second->getViewer();
639 selectedObjects.push_back( iter->first);
643 return selectedObjects;
645 //------------------------------------------------------------------------------------------------------------
646 void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
648 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
649 //EED??? int size = _contours_ViewControl->size();
650 //EED??? bool selected;
651 /*for ( int i = 0; i<size; i++ )
654 manualViewBaseContour * viewer = iter->second->getViewer();
655 std::vector <std::string >::iterator iterIN;
657 for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
659 if( iter->first.compare( theExistingObjectsToSelect[i] ) )
661 viewer->SelectAllPoints( true );
662 viewer->SelectPosibleContour( true );
664 theExistingObjectsToSelect.erase( iterIN );
672 //------------------------------------------------------------------------------------------------------------
673 void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
675 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
676 int size = _contours_ViewControl->size();
677 for ( int i = 0; i<size; i++ )
679 manualViewBaseContour * viewer = iter->second->getViewer();
681 viewer->SetSelected( true );
682 /*viewer->SelectAllPoints( true );
683 viewer->SelectPosibleContour( true );*/
689 //------------------------------------------------------------------------------------------------------------
690 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
692 int i, size = theKeyNameVector.size();
693 for( i=0; i< size; i++ )
695 setControlActiveStateOf( theKeyNameVector[i], controlCondition );
699 //------------------------------------------------------------------------------------------------------------
700 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
702 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
703 int i, size = theMap->size();
704 for( i=0; i< size; i++ )
706 removeFromScene( iter->second, false, controlCondition );
711 //------------------------------------------------------------------------------------------------------------
713 //------------------------------------------------------------------------------------------------------------
715 //------------------------------------------------------------------------------------------------------------
716 // Creational and initialization methods
717 //------------------------------------------------------------------------------------------------------------
719 //------------------------------------------------------------------------------------------------------------
721 //------------------------------------------------------------------------------------------------------------
723 bool wxVtkBaseView_SceneManager :: isCtrlPressed()
727 bool wxVtkBaseView_SceneManager :: isShiftPressed()
731 char wxVtkBaseView_SceneManager :: getLastKeyCode()
735 bool wxVtkBaseView_SceneManager :: OnChar()
738 _ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
739 _shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
741 _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
743 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
744 _eventHandler->ProcessEvent( cevent );
747 /*if( _eventHandler!=NULL )
749 char * toolCommand = NULL;
751 if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
753 toolCommand = &(COPY_TOOL);
755 else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
757 toolCommand = &(PASTE_TOOL);
759 else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
761 toolCommand = &(DELETE_KEY);
763 else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
765 toolCommand = &(CREATE_CONTOUR_KEY);
767 else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
769 toolCommand = &(OPEN_TOOL);
771 else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
773 toolCommand = &(SAVE_KEY);
776 if ( toolCommand!=NULL )
778 currentkey = toolCommand;
779 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
780 cevent.SetClientData( (void *) toolCommand);
781 _eventHandler->ProcessEvent( cevent );
786 // long int endtime = clock();
790 //------------------------------------------------------------------------------------------------------------
792 bool wxVtkBaseView_SceneManager :: OnMouseMove()
795 bool condition = true;
797 crea::wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
798 _wxVTKiren->GetEventPosition( X , Y );
800 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
801 //??? bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
803 if( _waiting && !ctrlKey )
805 sendEnvent( wxEVT_CHANGED_DEEP, "Update");
806 //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
809 if ( !_creatingROI && !_creatingMULT_ROI )
812 /*if( ctrlKey || shiftKey )
818 _toIncludeAtInteractionGroup = false;
821 bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
822 std::string preservingName = preserveState ? _lastInteractionName : "";
824 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
825 int i, size = _sceneContours_ViewControl->size();
826 bool foundOne = false;
828 manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
829 manualViewBaseContour * viewer = NULL;
832 bool singleMoving = true;
833 int selectionSize = _workingGroup->size();
834 if( selectionSize > 1 )
838 //EED??? bool ckecking = false;
839 for( i =0; i<size ; i++ )
841 control = iter->second->getControler();
842 viewer = iter->second->getViewer();
843 /*ckecking = */control->SetActive( true );
845 if (_lastInteraction != NULL)
847 singleMoving = !_lastInteraction->getViewer()->GetSelected();
852 size = selectionSize;
853 iter = _workingGroup->begin();
857 _toIncludeAtInteractionGroup = false;
860 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
863 _lastInteraction=NULL;
864 for( i =0; i<size ; i++ )
866 control = iter->second->getControler();
867 viewer = iter->second->getViewer();
868 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
869 control->SetActive( true );
871 foundOne = control->OnMouseMove();
872 foundOne &= viewer->GetPosibleSelected();
874 if ( !foundOne && singleMoving )
876 control->SetActive( false );
877 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
878 control->SetPosibleToMove( false );
882 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
884 _lastInteraction->getControler()->SetActive( true );
887 _lastInteraction = iter->second;
888 _lastInteractionName = iter->first;
890 viewer->UpdateColorActor();
891 control->SetPosibleToMove( true );
892 // viewer->AddCompleteContourActor();
907 //------------------------------------------------------------------------------------------------------------
908 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
913 //EED??? char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
914 bool condition = false;
915 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
916 //EED??? vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
917 //EED??? wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
918 //EED?? wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
919 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
921 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
922 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
923 _toIncludeAtInteractionGroup = false;
924 if ( ctrlKey || shftKey )
926 _toIncludeAtInteractionGroup = true;
930 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
932 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
934 _lastInteraction->getControler()->SetEditable( false );
935 _lastInteraction->getControler()->SetActive( false );
936 _lastInteraction->getControler()->SetPosibleToMove( false );
937 _lastInteraction->getViewer()->Refresh();
938 _lastInteraction=NULL;
945 if( !_toIncludeAtInteractionGroup )
947 _workingGroup->clear();
950 if( _lastInteraction!=NULL )
952 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
953 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
954 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
956 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
959 //setControlActiveStateOf( _contours_ViewControl, false );
960 sendEnvent( wxEVT_START_CREATE_ROI, "");
964 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
965 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
966 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
973 //------------------------------------------------------------------------------------------------------------
974 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
976 bool condition = false;
979 if( _drawingSelectionROI )
981 setSelection2DROIInternalOutlines();
985 //------------------------------------------------------------------------------------------------------------
986 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
988 bool condition = false;
993 //------------------------------------------------------------------------------------------------------------
994 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
996 bool condition = false;
1001 //------------------------------------------------------------------------------------------------------------
1002 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
1004 bool condition = false;
1005 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
1006 //EED??? bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
1013 //------------------------------------------------------------------------------------------------------------
1014 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
1016 bool condition = false;
1018 //setControlActiveStateOfALL( false );//************************************************
1019 if ( _creatingMULT_ROI )
1021 //setControlActiveStateOfALL( false );
1025 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
1026 _creatingROI = false;
1030 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
1032 manualContourBaseControler * control = _lastInteraction->getControler();
1033 //_lastInteraction->getControler()->SetPosibleToMove( false );
1034 control->SetActive( false );
1035 control->SetEditable( false );
1036 control->SetPosibleToMove( false );
1037 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
1038 _lastInteraction->getViewer()->Refresh();
1039 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1045 //------------------------------------------------------------------------------------------------------------
1047 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
1049 bool condition = false;
1054 //------------------------------------------------------------------------------------------------------------
1055 bool wxVtkBaseView_SceneManager :: OnRightDClick()
1057 bool condition = false; condition = true;
1058 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
1059 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
1060 //EED??? wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
1064 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
1065 set_creatingMULT_ROI( !_creatingMULT_ROI );
1073 //------------------------------------------------------------------------------------------------------------
1074 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
1076 bool condition = false;
1081 //------------------------------------------------------------------------------------------------------------
1082 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
1084 bool condition = false;
1088 //------------------------------------------------------------------------------------------------------------
1090 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1092 _drawingSelectionROI = true;
1093 _workingGroup->clear();
1094 _controlerSelectionROI->CreateNewManualContour();
1095 if (_lastInteraction!=NULL)
1097 _lastInteraction->getControler()->SetEditable( false );
1098 _lastInteraction->getControler()->SetActive( false );
1099 _lastInteraction->getControler()->SetPosibleToMove( false );
1100 _lastInteraction->getViewer()->Refresh();
1102 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1103 int i, workSize = _workingGroup->size();
1104 for( i=0; i< workSize; i++ )
1106 manualContourBaseControler * control = iter->second->getControler();
1107 control->SetEditable( false );
1108 control->SetActive( false );
1109 control->SetPosibleToMove( false );
1110 iter->second->getViewer()->Refresh();
1114 _lastInteraction = NULL;
1115 _lastInteractionName = "";
1117 _viewerSelectionROI->AddCompleteContourActor( true );
1118 _controlerSelectionROI->SetActive( true );
1120 _viewerSelectionROI->RefreshContour();
1121 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1123 //------------------------------------------------------------------------------------------------------------
1124 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1126 _drawingSelectionROI = false;
1127 _workingGroup->clear();
1128 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1131 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1132 int i, size = _sceneContours_ViewControl->size();
1133 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1134 manualViewBaseContour * viewer;
1135 bool insideRoi = false;
1136 for ( i=0; i<size; i++ )
1138 viewer = iter->second->getViewer();
1139 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1140 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1143 viewer->SetSelected( true );
1144 viewer->UpdateColorActor();
1145 setControlActiveStateOf( iter->second, true );
1146 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1150 _viewerSelectionROI->RemoveCompleteContourActor( );
1151 _controlerSelectionROI->SetActive( false );
1153 //------------------------------------------------------------------------------------------------------------
1154 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1156 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1157 long int start = clock();
1159 double sg = (double)(start) / (double)CLK_TCK;
1161 double sg = (double)(start) / CLOCKS_PER_SEC;
1164 crea::wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1165 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1166 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): %f\n \n",method.c_str(), tmpPx, tmpPy, sg);
1171 //------------------------------------------------------------------------------------------------------------
1172 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1174 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1175 manualViewBaseContour * cViewer;
1176 manualContourBaseControler * cControler;
1177 ContourWrap_ViewControl *conwraviwcont=iter->second;
1179 cViewer = conwraviwcont->getViewer();
1182 cControler = conwraviwcont->getControler();
1183 // cControler->Save(ff);
1185 // cModel = cControler->GetManualContourModel();
1186 // cModel->Save(ff);
1190 //------------------------------------------------------------------------------------------------------------
1191 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1193 std::vector<std::string> currentSelection = this->getSelectedObjects();
1194 if (currentSelection.size()>=1){
1196 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1197 manualBaseModel *cModel = cControler->GetManualContourModel();
1198 int i,size = cModel->GetNumberOfPointsSpline();
1200 for (i=0; i<size; i++)
1202 cModel->GetSpline_i_Point(i, &x, &y, &z);
1210 //------------------------------------------------------------------------------------------------------------
1211 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1213 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1214 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1217 //------------------------------------------------------------------------------------------------------------
1218 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1221 vtkImageData *imagedata = GetImageData();
1222 imagedata->GetExtent(ext);
1223 int sizeZ = ext[5]-ext[4]+1;
1231 //------------------------------------------------------------------------------------------------------------
1232 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1235 vtkImageData *imagedata = GetImageData();
1236 imagedata->GetExtent(ext);
1237 int sizeX = ext[1]-ext[0]+1;
1238 int sizeY = ext[3]-ext[2]+1;
1239 int sizeZ = GetImageDataSizeZ();
1240 int sizeXYZ = sizeX*sizeY*sizeZ;
1244 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1245 for (i=0;i<sizeXYZ;i++)
1247 if ( p[i]<range[0] ) range[0]=p[i];
1248 if ( p[i]>range[1] ) range[1]=p[i];
1252 //------------------------------------------------------------------------------------------------------------
1253 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1255 _widthOfContour = width;
1256 _widthOfControlPoint = _widthOfContour*_widthOfContour/2;
1257 manualViewBaseContour *cViewer;
1258 ContourWrap_ViewControl *conwraviwcont;
1259 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
1261 if (_contours_ViewControl!=NULL)
1263 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1265 conwraviwcont = iter->second;
1266 cViewer = conwraviwcont->getViewer();
1267 cViewer->SetShowText( false ); // EED 28Mars2011
1268 cViewer->SetWidthLine( _widthOfContour );
1269 cViewer->SetRange( _widthOfControlPoint );
1274 void wxVtkBaseView_SceneManager::SetShowTextContour(bool show)
1276 _showTextContour = show;
1279 bool wxVtkBaseView_SceneManager::isEditableCControler(std::string theKeyName){
1281 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1283 manualContourBaseControler* cControler = ccon->getControler();
1284 if(cControler != NULL && cControler->IsEditable() == false){
1291 void wxVtkBaseView_SceneManager::deleteCViewerCControler(std::string theKeyName){
1294 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1296 manualViewBaseContour * cViewer = ccon->getViewer();
1297 manualContourBaseControler * cControler = ccon->getControler();
1299 removeFromScene(theKeyName);
1300 removeWrap(theKeyName);