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 )
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();
179 manContourControl = new manualContourControler();
180 manViewerContour = new manualViewPoints();
186 manContourControl = new manualContourControler();
187 manViewerContour = new manualViewContour();
192 _lastInteraction = insertWrap( theKeyName, manContourControl, manViewerContour );
193 _lastInteractionName = theKeyName;
195 //Configuring the relations between the contour members representation
196 manViewerContour->SetModel( manModelContour );
197 manViewerContour->SetWxVtkBaseView( _wxVtk_BaseView );
198 manViewerContour->SetRange( _widthOfControlPoint );
199 manViewerContour->SetZ( 1000 );
201 manViewerContour->SetSpacing(spc);
203 manViewerContour->SetColorNormalContour(0, 0, 1);
204 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
205 manViewerContour->SetColorSelectContour(1, 0.8, 0);
206 manViewerContour->SetWidthLine(_widthOfContour);
208 manContourControl->SetModelView( manModelContour , manViewerContour );
209 manContourControl->Configure();
210 int i,sizeLstPoints = manModelContour->GetSizeLstPoints();
211 for ( i=0; i<sizeLstPoints; i++ )
213 manViewerContour->AddPoint();
216 manContourControl->CreateNewManualContour();
217 manViewerContour->RefreshContour();
218 addToScene( theKeyName );
220 //------------------------------------------------------------------------------------------------------------
221 void wxVtkBaseView_SceneManager :: configureSelectionROI( double * spc )
223 _controlerSelectionROI = new manualRoiControler();
224 _viewerSelectionROI = new manualViewRoi();
225 _modelSelectionROI = new manualContourModel();
227 _viewerSelectionROI->SetModel( _modelSelectionROI );
228 _viewerSelectionROI->SetWxVtkBaseView( _wxVtk_BaseView );
229 _viewerSelectionROI->SetRange( 2 );
230 _viewerSelectionROI->SetZ( 1000 );
231 _viewerSelectionROI->SetColorNormalContour(0.6, 0.8, 0);
233 _viewerSelectionROI->SetSpacing( spc );
235 _controlerSelectionROI->SetModelView( _modelSelectionROI , _viewerSelectionROI );
236 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _controlerSelectionROI );
237 _controlerSelectionROI->SetActive(false);
240 //------------------------------------------------------------------------------------------------------------
241 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: insertWrap( std::string theKeyName, manualContourBaseControler * manContourControl, manualViewBaseContour * manViewerContour )
243 ContourWrap_ViewControl * newContourWrap = new ContourWrap_ViewControl(manContourControl, manViewerContour);
244 if(_contours_ViewControl == NULL)
246 _contours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
248 _contours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, newContourWrap ));
249 return newContourWrap;
251 //------------------------------------------------------------------------------------------------------------
252 void wxVtkBaseView_SceneManager :: desconfigureViewControlOf( std::string theKeyName )
256 //------------------------------------------------------------------------------------------------------------
257 void wxVtkBaseView_SceneManager :: removeWrap( std::string theKeyName )
259 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
260 iter = _contours_ViewControl->find( theKeyName );
261 _contours_ViewControl->erase( iter );
262 _lastInteraction=NULL;
263 _lastInteractionName = "";
264 _workingGroup->clear();
265 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
266 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
268 //------------------------------------------------------------------------------------------------------------
269 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName )
271 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
272 iter = _contours_ViewControl->find( theName );
274 //return iter->first;
276 //------------------------------------------------------------------------------------------------------------
277 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName, std::map<std::string, ContourWrap_ViewControl *> * theMap )
279 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
280 iter = theMap->find( theName );
283 //------------------------------------------------------------------------------------------------------------
284 manualContourBaseControler * wxVtkBaseView_SceneManager :: getControlerOf( std::string theName )
286 return getContourWrap_ViewControlOf ( theName )->getControler();
288 //------------------------------------------------------------------------------------------------------------
289 manualViewBaseContour * wxVtkBaseView_SceneManager :: getViewerOf( std::string theName )
291 return getContourWrap_ViewControlOf ( theName )->getViewer();
293 //------------------------------------------------------------------------------------------------------------
294 void wxVtkBaseView_SceneManager :: set_creatingMULT_ROI( bool condition )
296 _creatingMULT_ROI = condition;
298 //------------------------------------------------------------------------------------------------------------
299 void wxVtkBaseView_SceneManager :: set_editingROI( bool condition )
301 _editingROI = condition;
303 //------------------------------------------------------------------------------------------------------------
304 void wxVtkBaseView_SceneManager :: set_toIncludeAtInteractionGroup( bool condition )
306 _toIncludeAtInteractionGroup = condition;
308 //------------------------------------------------------------------------------------------------------------
309 void wxVtkBaseView_SceneManager :: set_waiting( bool condition )
311 _waiting = condition;
313 //------------------------------------------------------------------------------------------------------------
314 bool wxVtkBaseView_SceneManager :: get_creatingMULT_ROI( )
316 return _creatingMULT_ROI;
318 //------------------------------------------------------------------------------------------------------------
319 bool wxVtkBaseView_SceneManager :: get_editingROI( )
323 //------------------------------------------------------------------------------------------------------------
324 bool wxVtkBaseView_SceneManager :: get_toIncludeAtInteractionGroup( )
326 return _toIncludeAtInteractionGroup;
329 //------------------------------------------------------------------------------------------------------------
330 bool wxVtkBaseView_SceneManager :: get_waiting( )
335 //------------------------------------------------------------------------------------------------------------
336 bool wxVtkBaseView_SceneManager :: get_creatingROI()
340 //------------------------------------------------------------------------------------------------------------
341 void wxVtkBaseView_SceneManager :: set_creatingROI( bool condition )
343 _creatingROI = condition;
346 //------------------------------------------------------------------------------------------------------------
347 // Other functional methods
348 //------------------------------------------------------------------------------------------------------------
350 void wxVtkBaseView_SceneManager :: createCopyContourOf( std::string anExistingKName, std::string cloneName, manualBaseModel * manualModel, bool append )
354 setControlActiveStateOf( _workingGroup, false );
355 _workingGroup->clear();
357 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
360 iter = _contours_ViewControl->find( anExistingKName );
362 manualBaseModel *cModule = manualModel;
363 manualViewBaseContour *cViewer = iter->second->getViewer()->Clone();
364 manualContourBaseControler *cControl = iter->second->getControler()->Clone( );
366 cViewer->SetModel(cModule);
367 cControl->SetModelView( cModule , cViewer );
368 cControl->CreateNewManualContour();
369 cControl->SetActive( true );
370 cControl->SetEditable( false );
372 cViewer->RefreshContour();
374 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
375 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
377 _lastInteraction = insertWrap( cloneName, cControl, cViewer );
378 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( cloneName, _lastInteraction ));
379 addToScene( cloneName );
382 //------------------------------------------------------------------------------------------------------------
384 void wxVtkBaseView_SceneManager :: removeFromScene( ContourWrap_ViewControl * contourWRP, bool visualization, bool control )
386 if( contourWRP == _lastInteraction )
388 _lastInteraction = NULL;
389 _lastInteractionName = "";
393 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->RemoveInteractorStyleMaracas( contourWRP->getControler() );
395 contourWRP->getControler()->SetActive( control );
396 contourWRP->getControler()->SetEditable( false );
398 if ( !visualization && control )
400 contourWRP->getViewer()->RemoveControlPoints( );
401 contourWRP->getViewer()->RemoveTextActor( );
405 contourWRP->getViewer()->RemoveCompleteContourActor();
409 //------------------------------------------------------------------------------------------------------------
410 void wxVtkBaseView_SceneManager :: removeFromScene( std::string theKeyName, bool visualization , bool control )
413 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
414 iter = _sceneContours_ViewControl->find( theKeyName );
415 if (iter != _sceneContours_ViewControl->end())
417 ContourWrap_ViewControl * contourWRP = iter->second;
418 removeFromScene( contourWRP );
419 _sceneContours_ViewControl->erase(iter);
424 //------------------------------------------------------------------------------------------------------------
425 std::vector<std::string> wxVtkBaseView_SceneManager::GetlstContoursNameActualSlice()
427 std::vector<std::string> lstContoursNameActualSlice;
428 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
429 int i,size = _sceneContours_ViewControl->size();
430 for ( i = 0; i<size; i++ )
432 lstContoursNameActualSlice.push_back( iter->first );
435 return lstContoursNameActualSlice;
438 //------------------------------------------------------------------------------------------------------------
439 void wxVtkBaseView_SceneManager :: removeSceneContours( )
441 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
442 int size = _sceneContours_ViewControl->size();
443 for ( int i = 0; i<size; i++ )
445 removeFromScene( iter->second );
448 _sceneContours_ViewControl->clear();
451 //Removing the selection rectangle to avoid showing when it's innecesary
452 _controlerSelectionROI->SetActive( false );
453 _viewerSelectionROI->RemoveCompleteContourActor();
456 void wxVtkBaseView_SceneManager::removeAllOutlines()
458 manualViewBaseContour * cViewer;
459 manualContourBaseControler * cControler;
461 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
462 int i,size=_contours_ViewControl->size();
465 iter = _contours_ViewControl->begin();
466 cControler = iter->second->getControler();
467 cViewer = iter->second->getViewer();
468 removeWrap( iter->first );
476 //------------------------------------------------------------------------------------------------------------
477 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
481 removeSceneContours();
483 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
484 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
486 addToScene( theKeyName, contourWRP, true, visualization, control, ifActive, ifShowCtrlPoints);
489 //------------------------------------------------------------------------------------------------------------
490 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
494 removeSceneContours();
496 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
499 contourWRP->getViewer()->AddCompleteContourActor( ifShowCtrlPoints );
504 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( contourWRP->getControler() );
508 contourWRP->getControler()->SetActive( true );
509 contourWRP->getViewer()->RemoveTextActor();
513 //------------------------------------------------------------------------------------------------------------
514 void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
516 int i, size = theKeyNameVector.size();
517 for( i=0; i< size; i++ )
519 removeFromScene( theKeyNameVector[i], visualization, control );
523 //------------------------------------------------------------------------------------------------------------
524 void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
526 int i, size = theKeyNameVector.size();
527 for( i=0; i< size; i++ )
529 addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
533 //------------------------------------------------------------------------------------------------------------
534 void wxVtkBaseView_SceneManager :: setControlActiveStateOfALL( bool stateCondition )
536 setControlActiveStateOf( _contours_ViewControl, stateCondition );
539 //------------------------------------------------------------------------------------------------------------
540 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
542 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
543 setControlActiveStateOf( contourWRP, stateCondition );
546 //------------------------------------------------------------------------------------------------------------
547 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( ContourWrap_ViewControl * contourWRP, bool stateCondition )
549 contourWRP->getControler()->SetActive( stateCondition );
550 contourWRP->getControler()->SetEditable( false );
553 //------------------------------------------------------------------------------------------------------------
554 void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
556 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
557 // contourWRP->getViewer()->SetVisible( stateCondition );
558 if ( contourWRP!=NULL )
559 removeFromScene( contourWRP, false, stateCondition );
562 //------------------------------------------------------------------------------------------------------------
563 std::vector< std::string > wxVtkBaseView_SceneManager :: getSelectedObjects()
565 std::vector< std::string > selectedObjects;
566 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
567 int size = _workingGroup->size();
568 for ( int i = 0; i<size; i++ )
570 //EED??? manualViewBaseContour * viewer = iter->second->getViewer();
571 selectedObjects.push_back( iter->first);
575 return selectedObjects;
577 //------------------------------------------------------------------------------------------------------------
578 void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
580 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
581 //EED??? int size = _contours_ViewControl->size();
582 //EED??? bool selected;
583 /*for ( int i = 0; i<size; i++ )
586 manualViewBaseContour * viewer = iter->second->getViewer();
587 std::vector <std::string >::iterator iterIN;
589 for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
591 if( iter->first.compare( theExistingObjectsToSelect[i] ) )
593 viewer->SelectAllPoints( true );
594 viewer->SelectPosibleContour( true );
596 theExistingObjectsToSelect.erase( iterIN );
604 //------------------------------------------------------------------------------------------------------------
605 void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
607 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
608 int size = _contours_ViewControl->size();
609 for ( int i = 0; i<size; i++ )
611 manualViewBaseContour * viewer = iter->second->getViewer();
613 viewer->SetSelected( true );
614 /*viewer->SelectAllPoints( true );
615 viewer->SelectPosibleContour( true );*/
621 //------------------------------------------------------------------------------------------------------------
622 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
624 int i, size = theKeyNameVector.size();
625 for( i=0; i< size; i++ )
627 setControlActiveStateOf( theKeyNameVector[i], controlCondition );
631 //------------------------------------------------------------------------------------------------------------
632 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
634 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
635 int i, size = theMap->size();
636 for( i=0; i< size; i++ )
638 removeFromScene( iter->second, false, controlCondition );
643 //------------------------------------------------------------------------------------------------------------
645 //------------------------------------------------------------------------------------------------------------
647 //------------------------------------------------------------------------------------------------------------
648 // Creational and initialization methods
649 //------------------------------------------------------------------------------------------------------------
651 //------------------------------------------------------------------------------------------------------------
653 //------------------------------------------------------------------------------------------------------------
655 bool wxVtkBaseView_SceneManager :: isCtrlPressed()
659 bool wxVtkBaseView_SceneManager :: isShiftPressed()
663 char wxVtkBaseView_SceneManager :: getLastKeyCode()
667 bool wxVtkBaseView_SceneManager :: OnChar()
670 _ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
671 _shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
673 _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
675 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
676 _eventHandler->ProcessEvent( cevent );
679 /*if( _eventHandler!=NULL )
681 char * toolCommand = NULL;
683 if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
685 toolCommand = &(COPY_TOOL);
687 else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
689 toolCommand = &(PASTE_TOOL);
691 else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
693 toolCommand = &(DELETE_KEY);
695 else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
697 toolCommand = &(CREATE_CONTOUR_KEY);
699 else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
701 toolCommand = &(OPEN_TOOL);
703 else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
705 toolCommand = &(SAVE_KEY);
708 if ( toolCommand!=NULL )
710 currentkey = toolCommand;
711 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
712 cevent.SetClientData( (void *) toolCommand);
713 _eventHandler->ProcessEvent( cevent );
718 // long int endtime = clock();
722 //------------------------------------------------------------------------------------------------------------
724 bool wxVtkBaseView_SceneManager :: OnMouseMove()
727 bool condition = true;
729 wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
730 _wxVTKiren->GetEventPosition( X , Y );
732 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
733 //??? bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
735 if( _waiting && !ctrlKey )
737 sendEnvent( wxEVT_CHANGED_DEEP, "Update");
738 //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
741 if ( !_creatingROI && !_creatingMULT_ROI )
744 /*if( ctrlKey || shiftKey )
750 _toIncludeAtInteractionGroup = false;
753 bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
754 std::string preservingName = preserveState ? _lastInteractionName : "";
756 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
757 int i, size = _sceneContours_ViewControl->size();
758 bool foundOne = false;
760 manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
761 manualViewBaseContour * viewer = NULL;
764 bool singleMoving = true;
765 int selectionSize = _workingGroup->size();
766 if( selectionSize > 1 )
770 //EED??? bool ckecking = false;
771 for( i =0; i<size ; i++ )
773 control = iter->second->getControler();
774 viewer = iter->second->getViewer();
775 /*ckecking = */control->SetActive( true );
777 if (_lastInteraction != NULL)
779 singleMoving = !_lastInteraction->getViewer()->GetSelected();
784 size = selectionSize;
785 iter = _workingGroup->begin();
791 _toIncludeAtInteractionGroup = false;
794 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
797 _lastInteraction=NULL;
798 for( i =0; i<size ; i++ )
800 control = iter->second->getControler();
801 viewer = iter->second->getViewer();
802 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
803 control->SetActive( true );
805 foundOne = control->OnMouseMove();
806 foundOne &= viewer->GetPosibleSelected();
808 if ( !foundOne && singleMoving )
810 control->SetActive( false );
811 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
812 control->SetPosibleToMove( false );
816 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
818 _lastInteraction->getControler()->SetActive( true );
821 _lastInteraction = iter->second;
822 _lastInteractionName = iter->first;
824 viewer->UpdateColorActor();
825 control->SetPosibleToMove( true );
826 // viewer->AddCompleteContourActor();
841 //------------------------------------------------------------------------------------------------------------
842 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
847 //EED??? char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
848 bool condition = false;
849 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
850 //EED??? vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
851 //EED??? wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
852 //EED?? wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
853 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
855 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
856 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
857 _toIncludeAtInteractionGroup = false;
858 if ( ctrlKey || shftKey )
860 _toIncludeAtInteractionGroup = true;
864 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
866 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
868 _lastInteraction->getControler()->SetEditable( false );
869 _lastInteraction->getControler()->SetActive( false );
870 _lastInteraction->getControler()->SetPosibleToMove( false );
871 _lastInteraction->getViewer()->Refresh();
872 _lastInteraction=NULL;
879 if( !_toIncludeAtInteractionGroup )
881 _workingGroup->clear();
884 if( _lastInteraction!=NULL )
886 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
887 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
888 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
890 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
893 //setControlActiveStateOf( _contours_ViewControl, false );
894 sendEnvent( wxEVT_START_CREATE_ROI, "");
898 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
899 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
900 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
907 //------------------------------------------------------------------------------------------------------------
908 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
910 bool condition = false;
913 if( _drawingSelectionROI )
915 setSelection2DROIInternalOutlines();
919 //------------------------------------------------------------------------------------------------------------
920 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
922 bool condition = false;
927 //------------------------------------------------------------------------------------------------------------
928 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
930 bool condition = false;
935 //------------------------------------------------------------------------------------------------------------
936 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
938 bool condition = false;
939 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
940 //EED??? bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
947 //------------------------------------------------------------------------------------------------------------
948 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
950 bool condition = false;
952 //setControlActiveStateOfALL( false );//************************************************
953 if ( _creatingMULT_ROI )
955 //setControlActiveStateOfALL( false );
959 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
960 _creatingROI = false;
964 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
966 manualContourBaseControler * control = _lastInteraction->getControler();
967 //_lastInteraction->getControler()->SetPosibleToMove( false );
968 control->SetActive( false );
969 control->SetEditable( false );
970 control->SetPosibleToMove( false );
971 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
972 _lastInteraction->getViewer()->Refresh();
973 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
979 //------------------------------------------------------------------------------------------------------------
981 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
983 bool condition = false;
988 //------------------------------------------------------------------------------------------------------------
989 bool wxVtkBaseView_SceneManager :: OnRightDClick()
991 bool condition = false; condition = true;
992 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
993 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
994 //EED??? wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
998 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
999 set_creatingMULT_ROI( !_creatingMULT_ROI );
1007 //------------------------------------------------------------------------------------------------------------
1008 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
1010 bool condition = false;
1015 //------------------------------------------------------------------------------------------------------------
1016 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
1018 bool condition = false;
1022 //------------------------------------------------------------------------------------------------------------
1024 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1026 _drawingSelectionROI = true;
1027 _workingGroup->clear();
1028 _controlerSelectionROI->CreateNewManualContour();
1029 if (_lastInteraction!=NULL)
1031 _lastInteraction->getControler()->SetEditable( false );
1032 _lastInteraction->getControler()->SetActive( false );
1033 _lastInteraction->getControler()->SetPosibleToMove( false );
1034 _lastInteraction->getViewer()->Refresh();
1036 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1037 int i, workSize = _workingGroup->size();
1038 for( i=0; i< workSize; i++ )
1040 manualContourBaseControler * control = iter->second->getControler();
1041 control->SetEditable( false );
1042 control->SetActive( false );
1043 control->SetPosibleToMove( false );
1044 iter->second->getViewer()->Refresh();
1048 _lastInteraction = NULL;
1049 _lastInteractionName = "";
1051 _viewerSelectionROI->AddCompleteContourActor( true );
1052 _controlerSelectionROI->SetActive( true );
1054 _viewerSelectionROI->RefreshContour();
1055 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1057 //------------------------------------------------------------------------------------------------------------
1058 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1060 _drawingSelectionROI = false;
1061 _workingGroup->clear();
1062 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1065 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1066 int i, size = _sceneContours_ViewControl->size();
1067 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1068 manualViewBaseContour * viewer;
1069 bool insideRoi = false;
1070 for ( i=0; i<size; i++ )
1072 viewer = iter->second->getViewer();
1073 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1074 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1077 viewer->SetSelected( true );
1078 viewer->UpdateColorActor();
1079 setControlActiveStateOf( iter->second, true );
1080 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1084 _viewerSelectionROI->RemoveCompleteContourActor( );
1085 _controlerSelectionROI->SetActive( false );
1087 //------------------------------------------------------------------------------------------------------------
1088 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1090 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1091 long int start = clock();
1093 double sg = (double)(start) / (double)CLK_TCK;
1095 double sg = (double)(start) / CLOCKS_PER_SEC;
1098 wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1099 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1100 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): %f\n \n",method.c_str(), tmpPx, tmpPy, sg);
1105 //------------------------------------------------------------------------------------------------------------
1106 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1108 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1109 manualViewBaseContour * cViewer;
1110 manualContourBaseControler * cControler;
1111 ContourWrap_ViewControl *conwraviwcont=iter->second;
1113 cViewer = conwraviwcont->getViewer();
1116 cControler = conwraviwcont->getControler();
1117 // cControler->Save(ff);
1119 // cModel = cControler->GetManualContourModel();
1120 // cModel->Save(ff);
1124 //------------------------------------------------------------------------------------------------------------
1125 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1127 std::vector<std::string> currentSelection = this->getSelectedObjects();
1128 if (currentSelection.size()>=1){
1130 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1131 manualBaseModel *cModel = cControler->GetManualContourModel();
1132 int i,size = cModel->GetNumberOfPointsSpline();
1134 for (i=0; i<size; i++)
1136 cModel->GetSpline_i_Point(i, &x, &y, &z);
1144 //------------------------------------------------------------------------------------------------------------
1145 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1147 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1148 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1151 //------------------------------------------------------------------------------------------------------------
1152 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1155 vtkImageData *imagedata = GetImageData();
1156 imagedata->GetExtent(ext);
1157 int sizeZ = ext[5]-ext[4]+1;
1165 //------------------------------------------------------------------------------------------------------------
1166 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1169 vtkImageData *imagedata = GetImageData();
1170 imagedata->GetExtent(ext);
1171 int sizeX = ext[1]-ext[0]+1;
1172 int sizeY = ext[3]-ext[2]+1;
1173 int sizeZ = GetImageDataSizeZ();
1174 int sizeXYZ = sizeX*sizeY*sizeZ;
1178 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1179 for (i=0;i<sizeXYZ;i++)
1181 if ( p[i]<range[0] ) range[0]=p[i];
1182 if ( p[i]>range[1] ) range[1]=p[i];
1186 //------------------------------------------------------------------------------------------------------------
1187 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1189 _widthOfContour = width;
1190 _widthOfControlPoint = _widthOfContour*_widthOfContour/2;
1191 manualViewBaseContour *cViewer;
1192 ContourWrap_ViewControl *conwraviwcont;
1193 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
1195 if (_contours_ViewControl!=NULL)
1197 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1199 conwraviwcont = iter->second;
1200 cViewer = conwraviwcont->getViewer();
1201 cViewer->SetWidthLine( _widthOfContour );
1202 cViewer->SetRange( _widthOfControlPoint );
1207 bool wxVtkBaseView_SceneManager::isEditableCControler(std::string theKeyName){
1209 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1211 manualContourBaseControler* cControler = ccon->getControler();
1212 if(cControler != NULL && cControler->IsEditable() == false){
1219 void wxVtkBaseView_SceneManager::deleteCViewerCControler(std::string theKeyName){
1222 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1224 manualViewBaseContour * cViewer = ccon->getViewer();
1225 manualContourBaseControler * cControler = ccon->getControler();
1227 removeFromScene(theKeyName);
1228 removeWrap(theKeyName);