2 //----------------------------------------------------------------------------------------------------------------
3 // Class definition include
4 //----------------------------------------------------------------------------------------------------------------
5 #include "wxVtkBaseView_SceneManager.h"
6 #include "wxVtk2DBaseView.h"
8 //----------------------------------------------------------------------------------------------------------------
9 // Class implementation
10 //----------------------------------------------------------------------------------------------------------------
11 /** @file wxVtkBaseView_SceneManager.cxx */
14 //------------------------------------------------------------------------------------------------------------
16 //------------------------------------------------------------------------------------------------------------
17 #include "wxContour_ActionCommandsID.h"
19 //------------------------------------------------------------------------------------------------------------
20 // Generated events declaration and definition
21 //------------------------------------------------------------------------------------------------------------
23 DEFINE_EVENT_TYPE( wxEVT_START_CREATE_MULT_ROI )
24 DEFINE_EVENT_TYPE( wxEVT_STOP_CREATE_MULT_ROI )
25 DEFINE_EVENT_TYPE( wxEVT_START_CREATE_ROI )
26 DEFINE_EVENT_TYPE( wxEVT_STOP_CREATE_ROI )
27 DEFINE_EVENT_TYPE( wxEVT_DELETE_ROI )
28 DEFINE_EVENT_TYPE( wxEVT_SELECTED_MULT_ROI )
29 DEFINE_EVENT_TYPE( wxEVT_SELECTED_ROI )
30 DEFINE_EVENT_TYPE( wxEVT_UNSLECTED_ROI )
31 DEFINE_EVENT_TYPE( wxEVT_MANUAL_HIDED_ROI )
32 DEFINE_EVENT_TYPE( wxEVT_MANUAL_SHOWED_ROI )
33 DEFINE_EVENT_TYPE( wxEVT_EDITING_ROI )
34 DEFINE_EVENT_TYPE( wxEVT_MOVING_ROI )
35 DEFINE_EVENT_TYPE( wxEVT_MOVING_ROI_POINT )
36 DEFINE_EVENT_TYPE( wxEVT_SELECTED_ROI_POINT )
37 DEFINE_EVENT_TYPE( wxEVT_UNSELECTED_ROI_POINT )
38 DEFINE_EVENT_TYPE( wxEVT_CHANGED_DEEP )
41 wxVtkBaseView_SceneManager :: wxVtkBaseView_SceneManager( wxVtkBaseView * theWxBaseViewToManage, wxEvtHandler * theEventHandler, double * spc )
43 _widthOfContour = 1.0;
44 _lastInteraction = NULL;
45 _lastInteractionName = "";
46 _eventHandler = theEventHandler;
50 _contours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
51 _sceneContours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
52 _workingGroup = new std::map< std::string, ContourWrap_ViewControl * >();
54 _creatingMULT_ROI = false;
56 _toIncludeAtInteractionGroup = false;
59 _drawingSelectionROI = false;
62 _wxVtk_BaseView = theWxBaseViewToManage;
63 if( _wxVtk_BaseView!=NULL )
65 vtkInteractorStyleBaseView* theInteractorStyleBaseView = (vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView();
66 theInteractorStyleBaseView->AddInteractorStyleMaracas( this );
67 SetVtkInteractorStyleBaseView( theInteractorStyleBaseView );
69 configureSelectionROI( spc );
71 //------------------------------------------------------------------------------------------------------------
72 wxVtkBaseView_SceneManager :: ~wxVtkBaseView_SceneManager()
74 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
75 int size = _contours_ViewControl->size();
76 for ( int i = 0; i<size; iter++ )
78 _contours_ViewControl->erase( iter );
81 _contours_ViewControl->clear();
82 delete _contours_ViewControl;
83 _workingGroup->clear();
84 delete _lastInteraction;
86 //delete _contours_ViewControl;
89 //------------------------------------------------------------------------------------------------------------
90 // Methods for capturing events
91 //------------------------------------------------------------------------------------------------------------
94 //------------------------------------------------------------------------------------------------------------
95 // Methods for sending events
96 //------------------------------------------------------------------------------------------------------------
97 void wxVtkBaseView_SceneManager :: sendEnvent( WXTYPE theEventType, std::string text )
99 if ( _eventHandler != NULL )
101 wxCommandEvent cevent( theEventType );
102 cevent.SetString( wxString( text.c_str(), wxConvUTF8) );
103 _eventHandler->ProcessEvent( cevent );
108 //------------------------------------------------------------------------------------------------------------
109 // Attributes getters and setters
110 //------------------------------------------------------------------------------------------------------------
111 void wxVtkBaseView_SceneManager :: setWxEventHandler( wxEvtHandler * theEventHandler )
113 _eventHandler = theEventHandler;
115 //------------------------------------------------------------------------------------------------------------
116 void wxVtkBaseView_SceneManager :: setWxVtkViewBase( wxVtkBaseView * theBaseView )
118 _wxVtk_BaseView = theBaseView;
121 //------------------------------------------------------------------------------------------------------------
122 wxVtkBaseView * wxVtkBaseView_SceneManager :: getWxVtkViewBase()
124 return _wxVtk_BaseView;
126 //------------------------------------------------------------------------------------------------------------
127 void wxVtkBaseView_SceneManager :: configureViewControlTo( std::string theKeyName, manualBaseModel * manModelContour, double * spc,int typeContour)
129 //setControlActiveStateOfALL( false );
132 if( _lastInteraction!=NULL )
134 _lastInteraction->getControler()->SetEditable( false );
135 _lastInteraction->getViewer()->Refresh();
136 _lastInteraction->getControler()->SetActive( false );
137 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
141 manualContourBaseControler *manContourControl;
142 manualViewBaseContour *manViewerContour;
144 // Creating the view manualViewContour and the manualContourControler
145 // NOTE: The model is created in the KernelManagerContour class, factoryManualContourModel method
148 manContourControl = new manualContourControler();
149 manViewerContour = new manualViewContour();
154 manContourControl = new manualRoiControler();
155 manViewerContour = new manualViewRoi();
160 manContourControl = new manualCircleControler();
161 manViewerContour = new manualViewCircle();
166 manContourControl = new manualRoiControler();
167 manViewerContour = new manualViewBullEye();
172 manContourControl = new manualLineControler();
173 manViewerContour = new manualViewLine();
177 manContourControl = new manualContourControler();
178 manViewerContour = new manualViewPoints();
183 _lastInteraction = insertWrap( theKeyName, manContourControl, manViewerContour );
184 _lastInteractionName = theKeyName;
186 //Configuring the relations between the contour members representation
187 manViewerContour->SetModel( manModelContour );
188 manViewerContour->SetWxVtkBaseView( _wxVtk_BaseView );
189 manViewerContour->SetRange( 0.5 );
190 manViewerContour->SetZ( 1000 );
192 manViewerContour->SetSpacing(spc);
194 manViewerContour->SetColorNormalContour(0, 0, 1);
195 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
196 manViewerContour->SetColorSelectContour(1, 0.8, 0);
197 manViewerContour->SetWidthLine(_widthOfContour);
199 manContourControl->SetModelView( manModelContour , manViewerContour );
200 manContourControl->Configure();
201 int i,sizeLstPoints = manModelContour->GetSizeLstPoints();
202 for ( i=0; i<sizeLstPoints; i++ )
204 manViewerContour->AddPoint();
207 manContourControl->CreateNewManualContour();
208 manViewerContour->RefreshContour();
209 addToScene( theKeyName );
211 //------------------------------------------------------------------------------------------------------------
212 void wxVtkBaseView_SceneManager :: configureSelectionROI( double * spc )
214 _controlerSelectionROI = new manualRoiControler();
215 _viewerSelectionROI = new manualViewRoi();
216 _modelSelectionROI = new manualContourModel();
218 _viewerSelectionROI->SetModel( _modelSelectionROI );
219 _viewerSelectionROI->SetWxVtkBaseView( _wxVtk_BaseView );
220 _viewerSelectionROI->SetRange( 2 );
221 _viewerSelectionROI->SetZ( 1000 );
222 _viewerSelectionROI->SetColorNormalContour(0.6, 0.8, 0);
224 _viewerSelectionROI->SetSpacing( spc );
226 _controlerSelectionROI->SetModelView( _modelSelectionROI , _viewerSelectionROI );
227 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _controlerSelectionROI );
228 _controlerSelectionROI->SetActive(false);
231 //------------------------------------------------------------------------------------------------------------
232 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: insertWrap( std::string theKeyName, manualContourBaseControler * manContourControl, manualViewBaseContour * manViewerContour )
234 ContourWrap_ViewControl * newContourWrap = new ContourWrap_ViewControl(manContourControl, manViewerContour);
235 _contours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, newContourWrap ));
236 return newContourWrap;
238 //------------------------------------------------------------------------------------------------------------
239 void wxVtkBaseView_SceneManager :: desconfigureViewControlOf( std::string theKeyName )
243 //------------------------------------------------------------------------------------------------------------
244 void wxVtkBaseView_SceneManager :: removeWrap( std::string theKeyName )
246 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
247 iter = _contours_ViewControl->find( theKeyName );
248 _contours_ViewControl->erase( iter );
249 _lastInteraction=NULL;
250 _lastInteractionName = "";
251 _workingGroup->clear();
252 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
253 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
255 //------------------------------------------------------------------------------------------------------------
256 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName )
258 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
259 iter = _contours_ViewControl->find( theName );
261 //return iter->first;
263 //------------------------------------------------------------------------------------------------------------
264 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName, std::map<std::string, ContourWrap_ViewControl *> * theMap )
266 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
267 iter = theMap->find( theName );
270 //------------------------------------------------------------------------------------------------------------
271 manualContourBaseControler * wxVtkBaseView_SceneManager :: getControlerOf( std::string theName )
273 return getContourWrap_ViewControlOf ( theName )->getControler();
275 //------------------------------------------------------------------------------------------------------------
276 manualViewBaseContour * wxVtkBaseView_SceneManager :: getViewerOf( std::string theName )
278 return getContourWrap_ViewControlOf ( theName )->getViewer();
280 //------------------------------------------------------------------------------------------------------------
281 void wxVtkBaseView_SceneManager :: set_creatingMULT_ROI( bool condition )
283 _creatingMULT_ROI = condition;
285 //------------------------------------------------------------------------------------------------------------
286 void wxVtkBaseView_SceneManager :: set_editingROI( bool condition )
288 _editingROI = condition;
290 //------------------------------------------------------------------------------------------------------------
291 void wxVtkBaseView_SceneManager :: set_toIncludeAtInteractionGroup( bool condition )
293 _toIncludeAtInteractionGroup = condition;
295 //------------------------------------------------------------------------------------------------------------
296 void wxVtkBaseView_SceneManager :: set_waiting( bool condition )
298 _waiting = condition;
300 //------------------------------------------------------------------------------------------------------------
301 bool wxVtkBaseView_SceneManager :: get_creatingMULT_ROI( )
303 return _creatingMULT_ROI;
305 //------------------------------------------------------------------------------------------------------------
306 bool wxVtkBaseView_SceneManager :: get_editingROI( )
310 //------------------------------------------------------------------------------------------------------------
311 bool wxVtkBaseView_SceneManager :: get_toIncludeAtInteractionGroup( )
313 return _toIncludeAtInteractionGroup;
316 //------------------------------------------------------------------------------------------------------------
317 bool wxVtkBaseView_SceneManager :: get_waiting( )
322 //------------------------------------------------------------------------------------------------------------
323 bool wxVtkBaseView_SceneManager :: get_creatingROI()
327 //------------------------------------------------------------------------------------------------------------
328 void wxVtkBaseView_SceneManager :: set_creatingROI( bool condition )
330 _creatingROI = condition;
333 //------------------------------------------------------------------------------------------------------------
334 // Other functional methods
335 //------------------------------------------------------------------------------------------------------------
337 void wxVtkBaseView_SceneManager :: createCopyContourOf( std::string anExistingKName, std::string cloneName, manualBaseModel * manualModel, bool append )
341 setControlActiveStateOf( _workingGroup, false );
342 _workingGroup->clear();
344 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
347 iter = _contours_ViewControl->find( anExistingKName );
349 manualBaseModel *cModule = manualModel;
350 manualViewBaseContour *cViewer = iter->second->getViewer()->Clone();
351 manualContourBaseControler *cControl = iter->second->getControler()->Clone( );
353 cViewer->SetModel(cModule);
354 cControl->SetModelView( cModule , cViewer );
355 cControl->CreateNewManualContour();
356 cControl->SetActive( true );
357 cControl->SetEditable( false );
359 cViewer->RefreshContour();
361 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
362 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
364 _lastInteraction = insertWrap( cloneName, cControl, cViewer );
365 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( cloneName, _lastInteraction ));
366 addToScene( cloneName );
369 //------------------------------------------------------------------------------------------------------------
371 void wxVtkBaseView_SceneManager :: removeFromScene( ContourWrap_ViewControl * contourWRP, bool visualization, bool control )
373 if( contourWRP == _lastInteraction )
375 _lastInteraction = NULL;
376 _lastInteractionName = "";
380 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->RemoveInteractorStyleMaracas( contourWRP->getControler() );
382 contourWRP->getControler()->SetActive( control );
383 contourWRP->getControler()->SetEditable( false );
385 if ( !visualization && control )
387 contourWRP->getViewer()->RemoveControlPoints( );
388 contourWRP->getViewer()->RemoveTextActor( );
392 contourWRP->getViewer()->RemoveCompleteContourActor();
396 //------------------------------------------------------------------------------------------------------------
397 void wxVtkBaseView_SceneManager :: removeFromScene( std::string theKeyName, bool visualization , bool control )
400 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
401 iter = _sceneContours_ViewControl->find( theKeyName );
402 if (iter != _sceneContours_ViewControl->end())
404 ContourWrap_ViewControl * contourWRP = iter->second;
405 removeFromScene( contourWRP );
406 _sceneContours_ViewControl->erase(iter);
411 //------------------------------------------------------------------------------------------------------------
412 std::vector<std::string> wxVtkBaseView_SceneManager::GetlstContoursNameActualSlice()
414 std::vector<std::string> lstContoursNameActualSlice;
415 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
416 int i,size = _sceneContours_ViewControl->size();
417 for ( i = 0; i<size; i++ )
419 lstContoursNameActualSlice.push_back( iter->first );
422 return lstContoursNameActualSlice;
425 //------------------------------------------------------------------------------------------------------------
426 void wxVtkBaseView_SceneManager :: removeSceneContours( )
428 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
429 int size = _sceneContours_ViewControl->size();
430 for ( int i = 0; i<size; i++ )
432 removeFromScene( iter->second );
435 _sceneContours_ViewControl->clear();
438 //Removing the selection rectangle to avoid showing when it's innecesary
439 _controlerSelectionROI->SetActive( false );
440 _viewerSelectionROI->RemoveCompleteContourActor();
443 void wxVtkBaseView_SceneManager::removeAllOutlines()
445 manualViewBaseContour * cViewer;
446 manualContourBaseControler * cControler;
448 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
449 int i,size=_contours_ViewControl->size();
452 iter = _contours_ViewControl->begin();
453 cControler = iter->second->getControler();
454 cViewer = iter->second->getViewer();
455 removeWrap( iter->first );
463 //------------------------------------------------------------------------------------------------------------
464 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
468 removeSceneContours();
470 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
471 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
473 addToScene( theKeyName, contourWRP, true, visualization, control, ifActive, ifShowCtrlPoints);
476 //------------------------------------------------------------------------------------------------------------
477 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
481 removeSceneContours();
483 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
486 contourWRP->getViewer()->AddCompleteContourActor( ifShowCtrlPoints );
491 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( contourWRP->getControler() );
495 contourWRP->getControler()->SetActive( true );
496 contourWRP->getViewer()->RemoveTextActor();
500 //------------------------------------------------------------------------------------------------------------
501 void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
503 int i, size = theKeyNameVector.size();
504 for( i=0; i< size; i++ )
506 removeFromScene( theKeyNameVector[i], visualization, control );
510 //------------------------------------------------------------------------------------------------------------
511 void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
513 int i, size = theKeyNameVector.size();
514 for( i=0; i< size; i++ )
516 addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
520 //------------------------------------------------------------------------------------------------------------
521 void wxVtkBaseView_SceneManager :: setControlActiveStateOfALL( bool stateCondition )
523 setControlActiveStateOf( _contours_ViewControl, stateCondition );
526 //------------------------------------------------------------------------------------------------------------
527 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
529 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
530 setControlActiveStateOf( contourWRP, stateCondition );
533 //------------------------------------------------------------------------------------------------------------
534 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( ContourWrap_ViewControl * contourWRP, bool stateCondition )
536 contourWRP->getControler()->SetActive( stateCondition );
537 contourWRP->getControler()->SetEditable( false );
540 //------------------------------------------------------------------------------------------------------------
541 void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
543 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
544 // contourWRP->getViewer()->SetVisible( stateCondition );
545 if ( contourWRP!=NULL )
546 removeFromScene( contourWRP, false, stateCondition );
549 //------------------------------------------------------------------------------------------------------------
550 std::vector< std::string > wxVtkBaseView_SceneManager :: getSelectedObjects()
552 std::vector< std::string > selectedObjects;
553 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
554 int size = _workingGroup->size();
555 for ( int i = 0; i<size; i++ )
557 //EED??? manualViewBaseContour * viewer = iter->second->getViewer();
558 selectedObjects.push_back( iter->first);
562 return selectedObjects;
564 //------------------------------------------------------------------------------------------------------------
565 void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
567 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
568 //EED??? int size = _contours_ViewControl->size();
569 //EED??? bool selected;
570 /*for ( int i = 0; i<size; i++ )
573 manualViewBaseContour * viewer = iter->second->getViewer();
574 std::vector <std::string >::iterator iterIN;
576 for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
578 if( iter->first.compare( theExistingObjectsToSelect[i] ) )
580 viewer->SelectAllPoints( true );
581 viewer->SelectPosibleContour( true );
583 theExistingObjectsToSelect.erase( iterIN );
591 //------------------------------------------------------------------------------------------------------------
592 void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
594 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
595 int size = _contours_ViewControl->size();
596 for ( int i = 0; i<size; i++ )
598 manualViewBaseContour * viewer = iter->second->getViewer();
600 viewer->SetSelected( true );
601 /*viewer->SelectAllPoints( true );
602 viewer->SelectPosibleContour( true );*/
608 //------------------------------------------------------------------------------------------------------------
609 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
611 int i, size = theKeyNameVector.size();
612 for( i=0; i< size; i++ )
614 setControlActiveStateOf( theKeyNameVector[i], controlCondition );
618 //------------------------------------------------------------------------------------------------------------
619 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
621 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
622 int i, size = theMap->size();
623 for( i=0; i< size; i++ )
625 removeFromScene( iter->second, false, controlCondition );
630 //------------------------------------------------------------------------------------------------------------
632 //------------------------------------------------------------------------------------------------------------
634 //------------------------------------------------------------------------------------------------------------
635 // Creational and initialization methods
636 //------------------------------------------------------------------------------------------------------------
638 //------------------------------------------------------------------------------------------------------------
640 //------------------------------------------------------------------------------------------------------------
642 bool wxVtkBaseView_SceneManager :: isCtrlPressed()
646 bool wxVtkBaseView_SceneManager :: isShiftPressed()
650 char wxVtkBaseView_SceneManager :: getLastKeyCode()
654 bool wxVtkBaseView_SceneManager :: OnChar()
657 _ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
658 _shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
660 _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
662 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
663 _eventHandler->ProcessEvent( cevent );
666 /*if( _eventHandler!=NULL )
668 char * toolCommand = NULL;
670 if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
672 toolCommand = &(COPY_TOOL);
674 else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
676 toolCommand = &(PASTE_TOOL);
678 else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
680 toolCommand = &(DELETE_KEY);
682 else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
684 toolCommand = &(CREATE_CONTOUR_KEY);
686 else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
688 toolCommand = &(OPEN_TOOL);
690 else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
692 toolCommand = &(SAVE_KEY);
695 if ( toolCommand!=NULL )
697 currentkey = toolCommand;
698 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
699 cevent.SetClientData( (void *) toolCommand);
700 _eventHandler->ProcessEvent( cevent );
705 // long int endtime = clock();
709 //------------------------------------------------------------------------------------------------------------
711 bool wxVtkBaseView_SceneManager :: OnMouseMove()
714 bool condition = true;
716 wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
717 _wxVTKiren->GetEventPosition( X , Y );
719 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
720 //??? bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
722 if( _waiting && !ctrlKey )
724 sendEnvent( wxEVT_CHANGED_DEEP, "Update");
725 //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
728 if ( !_creatingROI && !_creatingMULT_ROI )
731 /*if( ctrlKey || shiftKey )
737 _toIncludeAtInteractionGroup = false;
740 bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
741 std::string preservingName = preserveState ? _lastInteractionName : "";
743 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
744 int i, size = _sceneContours_ViewControl->size();
745 bool foundOne = false;
747 manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
748 manualViewBaseContour * viewer = NULL;
751 bool singleMoving = true;
752 int selectionSize = _workingGroup->size();
753 if( selectionSize > 1 )
757 //EED??? bool ckecking = false;
758 for( i =0; i<size ; i++ )
760 control = iter->second->getControler();
761 viewer = iter->second->getViewer();
762 /*ckecking = */control->SetActive( true );
764 if (_lastInteraction != NULL)
766 singleMoving = !_lastInteraction->getViewer()->GetSelected();
771 size = selectionSize;
772 iter = _workingGroup->begin();
778 _toIncludeAtInteractionGroup = false;
781 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
784 _lastInteraction=NULL;
785 for( i =0; i<size ; i++ )
787 control = iter->second->getControler();
788 viewer = iter->second->getViewer();
789 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
790 control->SetActive( true );
792 foundOne = control->OnMouseMove();
793 foundOne &= viewer->GetPosibleSelected();
795 if ( !foundOne && singleMoving )
797 control->SetActive( false );
798 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
799 control->SetPosibleToMove( false );
803 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
805 _lastInteraction->getControler()->SetActive( true );
808 _lastInteraction = iter->second;
809 _lastInteractionName = iter->first;
811 viewer->UpdateColorActor();
812 control->SetPosibleToMove( true );
813 // viewer->AddCompleteContourActor();
828 //------------------------------------------------------------------------------------------------------------
829 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
834 //EED??? char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
835 bool condition = false;
836 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
837 //EED??? vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
838 //EED??? wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
839 //EED?? wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
840 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
842 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
843 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
844 _toIncludeAtInteractionGroup = false;
845 if ( ctrlKey || shftKey )
847 _toIncludeAtInteractionGroup = true;
851 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
853 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
855 _lastInteraction->getControler()->SetEditable( false );
856 _lastInteraction->getControler()->SetActive( false );
857 _lastInteraction->getControler()->SetPosibleToMove( false );
858 _lastInteraction->getViewer()->Refresh();
859 _lastInteraction=NULL;
866 if( !_toIncludeAtInteractionGroup )
868 _workingGroup->clear();
871 if( _lastInteraction!=NULL )
873 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
874 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
875 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
877 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
880 //setControlActiveStateOf( _contours_ViewControl, false );
881 sendEnvent( wxEVT_START_CREATE_ROI, "");
885 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
886 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
887 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
894 //------------------------------------------------------------------------------------------------------------
895 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
897 bool condition = false;
900 if( _drawingSelectionROI )
902 setSelection2DROIInternalOutlines();
906 //------------------------------------------------------------------------------------------------------------
907 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
909 bool condition = false;
914 //------------------------------------------------------------------------------------------------------------
915 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
917 bool condition = false;
922 //------------------------------------------------------------------------------------------------------------
923 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
925 bool condition = false;
926 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
927 //EED??? bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
934 //------------------------------------------------------------------------------------------------------------
935 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
937 bool condition = false;
939 //setControlActiveStateOfALL( false );//************************************************
940 if ( _creatingMULT_ROI )
942 //setControlActiveStateOfALL( false );
946 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
947 _creatingROI = false;
951 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
953 manualContourBaseControler * control = _lastInteraction->getControler();
954 //_lastInteraction->getControler()->SetPosibleToMove( false );
955 control->SetActive( false );
956 control->SetEditable( false );
957 control->SetPosibleToMove( false );
958 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
959 _lastInteraction->getViewer()->Refresh();
960 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
966 //------------------------------------------------------------------------------------------------------------
968 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
970 bool condition = false;
975 //------------------------------------------------------------------------------------------------------------
976 bool wxVtkBaseView_SceneManager :: OnRightDClick()
978 bool condition = false; condition = true;
979 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
980 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
981 //EED??? wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
985 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
986 set_creatingMULT_ROI( !_creatingMULT_ROI );
994 //------------------------------------------------------------------------------------------------------------
995 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
997 bool condition = false;
1002 //------------------------------------------------------------------------------------------------------------
1003 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
1005 bool condition = false;
1009 //------------------------------------------------------------------------------------------------------------
1011 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1013 _drawingSelectionROI = true;
1014 _workingGroup->clear();
1015 _controlerSelectionROI->CreateNewManualContour();
1016 if (_lastInteraction!=NULL)
1018 _lastInteraction->getControler()->SetEditable( false );
1019 _lastInteraction->getControler()->SetActive( false );
1020 _lastInteraction->getControler()->SetPosibleToMove( false );
1021 _lastInteraction->getViewer()->Refresh();
1023 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1024 int i, workSize = _workingGroup->size();
1025 for( i=0; i< workSize; i++ )
1027 manualContourBaseControler * control = iter->second->getControler();
1028 control->SetEditable( false );
1029 control->SetActive( false );
1030 control->SetPosibleToMove( false );
1031 iter->second->getViewer()->Refresh();
1035 _lastInteraction = NULL;
1036 _lastInteractionName = "";
1038 _viewerSelectionROI->AddCompleteContourActor( true );
1039 _controlerSelectionROI->SetActive( true );
1041 _viewerSelectionROI->RefreshContour();
1042 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1044 //------------------------------------------------------------------------------------------------------------
1045 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1047 _drawingSelectionROI = false;
1048 _workingGroup->clear();
1049 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1052 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1053 int i, size = _sceneContours_ViewControl->size();
1054 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1055 manualViewBaseContour * viewer;
1056 bool insideRoi = false;
1057 for ( i=0; i<size; i++ )
1059 viewer = iter->second->getViewer();
1060 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1061 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1064 viewer->SetSelected( true );
1065 viewer->UpdateColorActor();
1066 setControlActiveStateOf( iter->second, true );
1067 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1071 _viewerSelectionROI->RemoveCompleteContourActor( );
1072 _controlerSelectionROI->SetActive( false );
1074 //------------------------------------------------------------------------------------------------------------
1075 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1077 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1078 long int start = clock();
1080 double sg = (double)(start) / (double)CLK_TCK;
1082 double sg = (double)(start) / CLOCKS_PER_SEC;
1085 wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1086 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1087 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): %f\n \n",method.c_str(), tmpPx, tmpPy, sg);
1092 //------------------------------------------------------------------------------------------------------------
1093 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1095 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1096 manualViewBaseContour * cViewer;
1097 manualContourBaseControler * cControler;
1098 ContourWrap_ViewControl *conwraviwcont=iter->second;
1100 cViewer = conwraviwcont->getViewer();
1103 cControler = conwraviwcont->getControler();
1104 // cControler->Save(ff);
1106 // cModel = cControler->GetManualContourModel();
1107 // cModel->Save(ff);
1111 //------------------------------------------------------------------------------------------------------------
1112 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1114 std::vector<std::string> currentSelection = this->getSelectedObjects();
1115 if (currentSelection.size()>=1){
1117 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1118 manualBaseModel *cModel = cControler->GetManualContourModel();
1119 int i,size = cModel->GetNumberOfPointsSpline();
1121 for (i=0; i<size; i++)
1123 cModel->GetSpline_i_Point(i, &x, &y, &z);
1131 //------------------------------------------------------------------------------------------------------------
1132 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1134 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1135 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1138 //------------------------------------------------------------------------------------------------------------
1139 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1142 vtkImageData *imagedata = GetImageData();
1143 imagedata->GetExtent(ext);
1144 int sizeZ = ext[5]-ext[4]+1;
1152 //------------------------------------------------------------------------------------------------------------
1153 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1156 vtkImageData *imagedata = GetImageData();
1157 imagedata->GetExtent(ext);
1158 int sizeX = ext[1]-ext[0]+1;
1159 int sizeY = ext[3]-ext[2]+1;
1160 int sizeZ = GetImageDataSizeZ();
1161 int sizeXYZ = sizeX*sizeY*sizeZ;
1165 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1166 for (i=0;i<sizeXYZ;i++)
1168 if ( p[i]<range[0] ) range[0]=p[i];
1169 if ( p[i]>range[1] ) range[1]=p[i];
1173 //------------------------------------------------------------------------------------------------------------
1174 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1176 _widthOfContour = width;
1177 manualViewBaseContour *cViewer;
1178 ContourWrap_ViewControl *conwraviwcont;
1179 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
1181 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1183 conwraviwcont = iter->second;
1184 cViewer = conwraviwcont->getViewer();
1185 cViewer->SetWidthLine(_widthOfContour);
1189 bool wxVtkBaseView_SceneManager::isEditableCControler(std::string theKeyName){
1191 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1193 manualContourBaseControler* cControler = ccon->getControler();
1194 if(cControler != NULL && cControler->IsEditable() == false){
1201 void wxVtkBaseView_SceneManager::deleteCViewerCControler(std::string theKeyName){
1204 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1206 manualViewBaseContour * cViewer = ccon->getViewer();
1207 manualContourBaseControler * cControler = ccon->getControler();
1209 removeFromScene(theKeyName);
1210 removeWrap(theKeyName);