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, manualContourModel * 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
147 manContourControl = new manualContourControler();
148 manViewerContour = new manualViewContour();
149 manModelContour->SetCloseContour(false);
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();
178 _lastInteraction = insertWrap( theKeyName, manContourControl, manViewerContour );
179 _lastInteractionName = theKeyName;
181 //Configuring the relations between the contour members representation
182 manViewerContour->SetModel( manModelContour );
183 manViewerContour->SetWxVtkBaseView( _wxVtk_BaseView );
184 manViewerContour->SetRange( 0.5 );
185 manViewerContour->SetZ( 1000 );
187 manViewerContour->SetSpacing(spc);
189 manViewerContour->SetColorNormalContour(0, 0, 1);
190 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
191 manViewerContour->SetColorSelectContour(1, 0.8, 0);
192 manViewerContour->SetWidthLine(_widthOfContour);
194 manContourControl->SetModelView( manModelContour , manViewerContour );
195 manContourControl->Configure();
196 int i,sizeLstPoints = manModelContour->GetSizeLstPoints();
197 for ( i=0; i<sizeLstPoints; i++ )
199 manViewerContour->AddPoint();
202 manContourControl->CreateNewManualContour();
203 manViewerContour->RefreshContour();
204 addToScene( theKeyName );
206 //------------------------------------------------------------------------------------------------------------
207 void wxVtkBaseView_SceneManager :: configureSelectionROI( double * spc )
209 _controlerSelectionROI = new manualRoiControler();
210 _viewerSelectionROI = new manualViewRoi();
211 _modelSelectionROI = new manualContourModel();
213 _viewerSelectionROI->SetModel( _modelSelectionROI );
214 _viewerSelectionROI->SetWxVtkBaseView( _wxVtk_BaseView );
215 _viewerSelectionROI->SetRange( 2 );
216 _viewerSelectionROI->SetZ( 1000 );
217 _viewerSelectionROI->SetColorNormalContour(0.6, 0.8, 0);
219 _viewerSelectionROI->SetSpacing( spc );
221 _controlerSelectionROI->SetModelView( _modelSelectionROI , _viewerSelectionROI );
222 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _controlerSelectionROI );
223 _controlerSelectionROI->SetActive(false);
226 //------------------------------------------------------------------------------------------------------------
227 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: insertWrap( std::string theKeyName, manualContourBaseControler * manContourControl, manualViewBaseContour * manViewerContour )
229 ContourWrap_ViewControl * newContourWrap = new ContourWrap_ViewControl(manContourControl, manViewerContour);
230 _contours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, newContourWrap ));
231 return newContourWrap;
233 //------------------------------------------------------------------------------------------------------------
234 void wxVtkBaseView_SceneManager :: desconfigureViewControlOf( std::string theKeyName )
238 //------------------------------------------------------------------------------------------------------------
239 void wxVtkBaseView_SceneManager :: removeWrap( std::string theKeyName )
241 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
242 iter = _contours_ViewControl->find( theKeyName );
243 _contours_ViewControl->erase( iter );
244 _lastInteraction=NULL;
245 _lastInteractionName = "";
246 _workingGroup->clear();
247 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
248 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
250 //------------------------------------------------------------------------------------------------------------
251 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName )
253 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
254 iter = _contours_ViewControl->find( theName );
256 //return iter->first;
258 //------------------------------------------------------------------------------------------------------------
259 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName, std::map<std::string, ContourWrap_ViewControl *> * theMap )
261 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
262 iter = theMap->find( theName );
265 //------------------------------------------------------------------------------------------------------------
266 manualContourBaseControler * wxVtkBaseView_SceneManager :: getControlerOf( std::string theName )
268 return getContourWrap_ViewControlOf ( theName )->getControler();
270 //------------------------------------------------------------------------------------------------------------
271 manualViewBaseContour * wxVtkBaseView_SceneManager :: getViewerOf( std::string theName )
273 return getContourWrap_ViewControlOf ( theName )->getViewer();
275 //------------------------------------------------------------------------------------------------------------
276 void wxVtkBaseView_SceneManager :: set_creatingMULT_ROI( bool condition )
278 _creatingMULT_ROI = condition;
280 //------------------------------------------------------------------------------------------------------------
281 void wxVtkBaseView_SceneManager :: set_editingROI( bool condition )
283 _editingROI = condition;
285 //------------------------------------------------------------------------------------------------------------
286 void wxVtkBaseView_SceneManager :: set_toIncludeAtInteractionGroup( bool condition )
288 _toIncludeAtInteractionGroup = condition;
290 //------------------------------------------------------------------------------------------------------------
291 void wxVtkBaseView_SceneManager :: set_waiting( bool condition )
293 _waiting = condition;
295 //------------------------------------------------------------------------------------------------------------
296 bool wxVtkBaseView_SceneManager :: get_creatingMULT_ROI( )
298 return _creatingMULT_ROI;
300 //------------------------------------------------------------------------------------------------------------
301 bool wxVtkBaseView_SceneManager :: get_editingROI( )
305 //------------------------------------------------------------------------------------------------------------
306 bool wxVtkBaseView_SceneManager :: get_toIncludeAtInteractionGroup( )
308 return _toIncludeAtInteractionGroup;
311 //------------------------------------------------------------------------------------------------------------
312 bool wxVtkBaseView_SceneManager :: get_waiting( )
317 //------------------------------------------------------------------------------------------------------------
318 bool wxVtkBaseView_SceneManager :: get_creatingROI()
322 //------------------------------------------------------------------------------------------------------------
323 void wxVtkBaseView_SceneManager :: set_creatingROI( bool condition )
325 _creatingROI = condition;
328 //------------------------------------------------------------------------------------------------------------
329 // Other functional methods
330 //------------------------------------------------------------------------------------------------------------
332 void wxVtkBaseView_SceneManager :: createCopyContourOf( std::string anExistingKName, std::string cloneName, manualContourModel * manualModel, bool append )
336 setControlActiveStateOf( _workingGroup, false );
337 _workingGroup->clear();
339 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
342 iter = _contours_ViewControl->find( anExistingKName );
344 manualContourModel *cModule = manualModel;
345 manualViewBaseContour *cViewer = iter->second->getViewer()->Clone();
346 manualContourBaseControler *cControl = iter->second->getControler()->Clone( );
348 cViewer->SetModel(cModule);
349 cControl->SetModelView( cModule , cViewer );
350 cControl->CreateNewManualContour();
351 cControl->SetActive( true );
352 cControl->SetEditable( false );
354 cViewer->RefreshContour();
356 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
357 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
359 _lastInteraction = insertWrap( cloneName, cControl, cViewer );
360 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( cloneName, _lastInteraction ));
361 addToScene( cloneName );
364 //------------------------------------------------------------------------------------------------------------
366 void wxVtkBaseView_SceneManager :: removeFromScene( ContourWrap_ViewControl * contourWRP, bool visualization, bool control )
368 if( contourWRP == _lastInteraction )
370 _lastInteraction = NULL;
371 _lastInteractionName = "";
375 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->RemoveInteractorStyleMaracas( contourWRP->getControler() );
377 contourWRP->getControler()->SetActive( control );
378 contourWRP->getControler()->SetEditable( false );
380 if ( !visualization && control )
382 contourWRP->getViewer()->RemoveControlPoints( );
383 contourWRP->getViewer()->RemoveTextActor( );
387 contourWRP->getViewer()->RemoveCompleteContourActor();
391 //------------------------------------------------------------------------------------------------------------
392 void wxVtkBaseView_SceneManager :: removeFromScene( std::string theKeyName, bool visualization , bool control )
395 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
396 iter = _sceneContours_ViewControl->find( theKeyName );
397 if (iter != _sceneContours_ViewControl->end())
399 ContourWrap_ViewControl * contourWRP = iter->second;
400 removeFromScene( contourWRP );
401 _sceneContours_ViewControl->erase(iter);
406 //------------------------------------------------------------------------------------------------------------
407 std::vector<std::string> wxVtkBaseView_SceneManager::GetlstContoursNameActualSlice()
409 std::vector<std::string> lstContoursNameActualSlice;
410 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
411 int i,size = _sceneContours_ViewControl->size();
412 for ( i = 0; i<size; i++ )
414 lstContoursNameActualSlice.push_back( iter->first );
417 return lstContoursNameActualSlice;
420 //------------------------------------------------------------------------------------------------------------
421 void wxVtkBaseView_SceneManager :: removeSceneContours( )
423 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
424 int size = _sceneContours_ViewControl->size();
425 for ( int i = 0; i<size; i++ )
427 removeFromScene( iter->second );
430 _sceneContours_ViewControl->clear();
433 //Removing the selection rectangle to avoid showing when it's innecesary
434 _controlerSelectionROI->SetActive( false );
435 _viewerSelectionROI->RemoveCompleteContourActor();
438 void wxVtkBaseView_SceneManager::removeAllOutlines()
440 manualViewBaseContour * cViewer;
441 manualContourBaseControler * cControler;
443 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
444 int i,size=_contours_ViewControl->size();
447 iter = _contours_ViewControl->begin();
448 cControler = iter->second->getControler();
449 cViewer = iter->second->getViewer();
450 removeWrap( iter->first );
458 //------------------------------------------------------------------------------------------------------------
459 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
463 removeSceneContours();
465 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
466 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
468 addToScene( theKeyName, contourWRP, true, visualization, control, ifActive, ifShowCtrlPoints);
471 //------------------------------------------------------------------------------------------------------------
472 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
476 removeSceneContours();
478 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
481 contourWRP->getViewer()->AddCompleteContourActor( ifShowCtrlPoints );
486 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( contourWRP->getControler() );
490 contourWRP->getControler()->SetActive( true );
491 contourWRP->getViewer()->RemoveTextActor();
495 //------------------------------------------------------------------------------------------------------------
496 void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
498 int i, size = theKeyNameVector.size();
499 for( i=0; i< size; i++ )
501 removeFromScene( theKeyNameVector[i], visualization, control );
505 //------------------------------------------------------------------------------------------------------------
506 void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
508 int i, size = theKeyNameVector.size();
509 for( i=0; i< size; i++ )
511 addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
515 //------------------------------------------------------------------------------------------------------------
516 void wxVtkBaseView_SceneManager :: setControlActiveStateOfALL( bool stateCondition )
518 setControlActiveStateOf( _contours_ViewControl, stateCondition );
521 //------------------------------------------------------------------------------------------------------------
522 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
524 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
525 setControlActiveStateOf( contourWRP, stateCondition );
528 //------------------------------------------------------------------------------------------------------------
529 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( ContourWrap_ViewControl * contourWRP, bool stateCondition )
531 contourWRP->getControler()->SetActive( stateCondition );
532 contourWRP->getControler()->SetEditable( false );
535 //------------------------------------------------------------------------------------------------------------
536 void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
538 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
539 // contourWRP->getViewer()->SetVisible( stateCondition );
540 if ( contourWRP!=NULL )
541 removeFromScene( contourWRP, false, stateCondition );
544 //------------------------------------------------------------------------------------------------------------
545 std::vector< std::string > wxVtkBaseView_SceneManager :: getSelectedObjects()
547 std::vector< std::string > selectedObjects;
548 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
549 int size = _workingGroup->size();
550 for ( int i = 0; i<size; i++ )
552 //EED??? manualViewBaseContour * viewer = iter->second->getViewer();
553 selectedObjects.push_back( iter->first);
557 return selectedObjects;
559 //------------------------------------------------------------------------------------------------------------
560 void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
562 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
563 //EED??? int size = _contours_ViewControl->size();
564 //EED??? bool selected;
565 /*for ( int i = 0; i<size; i++ )
568 manualViewBaseContour * viewer = iter->second->getViewer();
569 std::vector <std::string >::iterator iterIN;
571 for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
573 if( iter->first.compare( theExistingObjectsToSelect[i] ) )
575 viewer->SelectAllPoints( true );
576 viewer->SelectPosibleContour( true );
578 theExistingObjectsToSelect.erase( iterIN );
586 //------------------------------------------------------------------------------------------------------------
587 void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
589 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
590 int size = _contours_ViewControl->size();
591 for ( int i = 0; i<size; i++ )
593 manualViewBaseContour * viewer = iter->second->getViewer();
595 viewer->SetSelected( true );
596 /*viewer->SelectAllPoints( true );
597 viewer->SelectPosibleContour( true );*/
603 //------------------------------------------------------------------------------------------------------------
604 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
606 int i, size = theKeyNameVector.size();
607 for( i=0; i< size; i++ )
609 setControlActiveStateOf( theKeyNameVector[i], controlCondition );
613 //------------------------------------------------------------------------------------------------------------
614 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
616 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
617 int i, size = theMap->size();
618 for( i=0; i< size; i++ )
620 removeFromScene( iter->second, false, controlCondition );
625 //------------------------------------------------------------------------------------------------------------
627 //------------------------------------------------------------------------------------------------------------
629 //------------------------------------------------------------------------------------------------------------
630 // Creational and initialization methods
631 //------------------------------------------------------------------------------------------------------------
633 //------------------------------------------------------------------------------------------------------------
635 //------------------------------------------------------------------------------------------------------------
637 bool wxVtkBaseView_SceneManager :: isCtrlPressed()
641 bool wxVtkBaseView_SceneManager :: isShiftPressed()
645 char wxVtkBaseView_SceneManager :: getLastKeyCode()
649 bool wxVtkBaseView_SceneManager :: OnChar()
652 _ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
653 _shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
655 _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
657 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
658 _eventHandler->ProcessEvent( cevent );
661 /*if( _eventHandler!=NULL )
663 char * toolCommand = NULL;
665 if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
667 toolCommand = &(COPY_TOOL);
669 else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
671 toolCommand = &(PASTE_TOOL);
673 else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
675 toolCommand = &(DELETE_KEY);
677 else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
679 toolCommand = &(CREATE_CONTOUR_KEY);
681 else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
683 toolCommand = &(OPEN_TOOL);
685 else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
687 toolCommand = &(SAVE_KEY);
690 if ( toolCommand!=NULL )
692 currentkey = toolCommand;
693 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
694 cevent.SetClientData( (void *) toolCommand);
695 _eventHandler->ProcessEvent( cevent );
700 // long int endtime = clock();
704 //------------------------------------------------------------------------------------------------------------
706 bool wxVtkBaseView_SceneManager :: OnMouseMove()
709 bool condition = true;
711 wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
712 _wxVTKiren->GetEventPosition( X , Y );
714 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
715 //??? bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
717 if( _waiting && !ctrlKey )
719 sendEnvent( wxEVT_CHANGED_DEEP, "Update");
720 //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
723 if ( !_creatingROI && !_creatingMULT_ROI )
726 /*if( ctrlKey || shiftKey )
732 _toIncludeAtInteractionGroup = false;
735 bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
736 std::string preservingName = preserveState ? _lastInteractionName : "";
738 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
739 int i, size = _sceneContours_ViewControl->size();
740 bool foundOne = false;
742 manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
743 manualViewBaseContour * viewer = NULL;
746 bool singleMoving = true;
747 int selectionSize = _workingGroup->size();
748 if( selectionSize > 1 )
752 //EED??? bool ckecking = false;
753 for( i =0; i<size ; i++ )
755 control = iter->second->getControler();
756 viewer = iter->second->getViewer();
757 /*ckecking = */control->SetActive( true );
759 if (_lastInteraction != NULL)
761 singleMoving = !_lastInteraction->getViewer()->GetSelected();
766 size = selectionSize;
767 iter = _workingGroup->begin();
773 _toIncludeAtInteractionGroup = false;
776 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
779 _lastInteraction=NULL;
780 for( i =0; i<size ; i++ )
782 control = iter->second->getControler();
783 viewer = iter->second->getViewer();
784 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
785 control->SetActive( true );
787 foundOne = control->OnMouseMove();
788 foundOne &= viewer->GetPosibleSelected();
790 if ( !foundOne && singleMoving )
792 control->SetActive( false );
793 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
794 control->SetPosibleToMove( false );
798 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
800 _lastInteraction->getControler()->SetActive( true );
803 _lastInteraction = iter->second;
804 _lastInteractionName = iter->first;
806 viewer->UpdateColorActor();
807 control->SetPosibleToMove( true );
808 // viewer->AddCompleteContourActor();
823 //------------------------------------------------------------------------------------------------------------
824 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
829 //EED??? char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
830 bool condition = false;
831 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
832 //EED??? vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
833 //EED??? wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
834 //EED?? wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
835 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
837 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
838 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
839 _toIncludeAtInteractionGroup = false;
840 if ( ctrlKey || shftKey )
842 _toIncludeAtInteractionGroup = true;
846 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
848 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
850 _lastInteraction->getControler()->SetEditable( false );
851 _lastInteraction->getControler()->SetActive( false );
852 _lastInteraction->getControler()->SetPosibleToMove( false );
853 _lastInteraction->getViewer()->Refresh();
854 _lastInteraction=NULL;
861 if( !_toIncludeAtInteractionGroup )
863 _workingGroup->clear();
866 if( _lastInteraction!=NULL )
868 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
869 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
870 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
872 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
875 //setControlActiveStateOf( _contours_ViewControl, false );
876 sendEnvent( wxEVT_START_CREATE_ROI, "");
880 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
881 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
882 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
889 //------------------------------------------------------------------------------------------------------------
890 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
892 bool condition = false;
895 if( _drawingSelectionROI )
897 setSelection2DROIInternalOutlines();
901 //------------------------------------------------------------------------------------------------------------
902 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
904 bool condition = false;
909 //------------------------------------------------------------------------------------------------------------
910 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
912 bool condition = false;
917 //------------------------------------------------------------------------------------------------------------
918 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
920 bool condition = false;
921 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
922 //EED??? bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
929 //------------------------------------------------------------------------------------------------------------
930 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
932 bool condition = false;
934 //setControlActiveStateOfALL( false );//************************************************
935 if ( _creatingMULT_ROI )
937 //setControlActiveStateOfALL( false );
941 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
942 _creatingROI = false;
946 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
948 manualContourBaseControler * control = _lastInteraction->getControler();
949 //_lastInteraction->getControler()->SetPosibleToMove( false );
950 control->SetActive( false );
951 control->SetEditable( false );
952 control->SetPosibleToMove( false );
953 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
954 _lastInteraction->getViewer()->Refresh();
955 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
961 //------------------------------------------------------------------------------------------------------------
963 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
965 bool condition = false;
970 //------------------------------------------------------------------------------------------------------------
971 bool wxVtkBaseView_SceneManager :: OnRightDClick()
973 bool condition = false; condition = true;
974 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
975 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
976 //EED??? wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
980 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
981 set_creatingMULT_ROI( !_creatingMULT_ROI );
989 //------------------------------------------------------------------------------------------------------------
990 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
992 bool condition = false;
997 //------------------------------------------------------------------------------------------------------------
998 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
1000 bool condition = false;
1004 //------------------------------------------------------------------------------------------------------------
1006 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1008 _drawingSelectionROI = true;
1009 _workingGroup->clear();
1010 _controlerSelectionROI->CreateNewManualContour();
1011 if (_lastInteraction!=NULL)
1013 _lastInteraction->getControler()->SetEditable( false );
1014 _lastInteraction->getControler()->SetActive( false );
1015 _lastInteraction->getControler()->SetPosibleToMove( false );
1016 _lastInteraction->getViewer()->Refresh();
1018 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1019 int i, workSize = _workingGroup->size();
1020 for( i=0; i< workSize; i++ )
1022 manualContourBaseControler * control = iter->second->getControler();
1023 control->SetEditable( false );
1024 control->SetActive( false );
1025 control->SetPosibleToMove( false );
1026 iter->second->getViewer()->Refresh();
1030 _lastInteraction = NULL;
1031 _lastInteractionName = "";
1033 _viewerSelectionROI->AddCompleteContourActor( true );
1034 _controlerSelectionROI->SetActive( true );
1036 _viewerSelectionROI->RefreshContour();
1037 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1039 //------------------------------------------------------------------------------------------------------------
1040 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1042 _drawingSelectionROI = false;
1043 _workingGroup->clear();
1044 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1047 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1048 int i, size = _sceneContours_ViewControl->size();
1049 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1050 manualViewBaseContour * viewer;
1051 bool insideRoi = false;
1052 for ( i=0; i<size; i++ )
1054 viewer = iter->second->getViewer();
1055 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1056 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1059 viewer->SetSelected( true );
1060 viewer->UpdateColorActor();
1061 setControlActiveStateOf( iter->second, true );
1062 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1066 _viewerSelectionROI->RemoveCompleteContourActor( );
1067 _controlerSelectionROI->SetActive( false );
1069 //------------------------------------------------------------------------------------------------------------
1070 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1072 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1073 long int start = clock();
1075 double sg = (double)(start) / (double)CLK_TCK;
1077 double sg = (double)(start) / CLOCKS_PER_SEC;
1080 wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1081 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1082 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): %f\n \n",method.c_str(), tmpPx, tmpPy, sg);
1087 //------------------------------------------------------------------------------------------------------------
1088 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1090 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1091 manualViewBaseContour * cViewer;
1092 manualContourBaseControler * cControler;
1093 ContourWrap_ViewControl *conwraviwcont=iter->second;
1095 cViewer = conwraviwcont->getViewer();
1098 cControler = conwraviwcont->getControler();
1099 // cControler->Save(ff);
1101 // cModel = cControler->GetManualContourModel();
1102 // cModel->Save(ff);
1106 //------------------------------------------------------------------------------------------------------------
1107 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1109 std::vector<std::string> currentSelection = this->getSelectedObjects();
1110 if (currentSelection.size()>=1){
1112 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1113 manualContourModel *cModel = cControler->GetManualContourModel();
1114 int i,size = cModel->GetNumberOfPointsSpline();
1116 for (i=0; i<size; i++)
1118 cModel->GetSpline_i_Point(i, &x, &y, &z);
1126 //------------------------------------------------------------------------------------------------------------
1127 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1129 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1130 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1133 //------------------------------------------------------------------------------------------------------------
1134 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1137 vtkImageData *imagedata = GetImageData();
1138 imagedata->GetExtent(ext);
1139 int sizeZ = ext[5]-ext[4]+1;
1147 //------------------------------------------------------------------------------------------------------------
1148 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1151 vtkImageData *imagedata = GetImageData();
1152 imagedata->GetExtent(ext);
1153 int sizeX = ext[1]-ext[0]+1;
1154 int sizeY = ext[3]-ext[2]+1;
1155 int sizeZ = GetImageDataSizeZ();
1156 int sizeXYZ = sizeX*sizeY*sizeZ;
1160 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1161 for (i=0;i<sizeXYZ;i++)
1163 if ( p[i]<range[0] ) range[0]=p[i];
1164 if ( p[i]>range[1] ) range[1]=p[i];
1168 //------------------------------------------------------------------------------------------------------------
1169 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1171 _widthOfContour = width;
1172 manualViewBaseContour *cViewer;
1173 ContourWrap_ViewControl *conwraviwcont;
1174 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;;
1176 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1178 conwraviwcont = iter->second;
1179 cViewer = conwraviwcont->getViewer();
1180 cViewer->SetWidthLine(_widthOfContour);
1184 bool wxVtkBaseView_SceneManager::isEditableCControler(std::string theKeyName){
1186 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1188 manualContourBaseControler* cControler = ccon->getControler();
1189 if(cControler != NULL && cControler->IsEditable() == false){
1196 void wxVtkBaseView_SceneManager::deleteCViewerCControler(std::string theKeyName){
1199 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1201 manualViewBaseContour * cViewer = ccon->getViewer();
1202 manualContourBaseControler * cControler = ccon->getControler();
1204 removeFromScene(theKeyName);
1205 removeWrap(theKeyName);