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();
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( 0.5 );
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 _contours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, newContourWrap ));
245 return newContourWrap;
247 //------------------------------------------------------------------------------------------------------------
248 void wxVtkBaseView_SceneManager :: desconfigureViewControlOf( std::string theKeyName )
252 //------------------------------------------------------------------------------------------------------------
253 void wxVtkBaseView_SceneManager :: removeWrap( std::string theKeyName )
255 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
256 iter = _contours_ViewControl->find( theKeyName );
257 _contours_ViewControl->erase( iter );
258 _lastInteraction=NULL;
259 _lastInteractionName = "";
260 _workingGroup->clear();
261 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
262 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
264 //------------------------------------------------------------------------------------------------------------
265 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName )
267 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
268 iter = _contours_ViewControl->find( theName );
270 //return iter->first;
272 //------------------------------------------------------------------------------------------------------------
273 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName, std::map<std::string, ContourWrap_ViewControl *> * theMap )
275 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
276 iter = theMap->find( theName );
279 //------------------------------------------------------------------------------------------------------------
280 manualContourBaseControler * wxVtkBaseView_SceneManager :: getControlerOf( std::string theName )
282 return getContourWrap_ViewControlOf ( theName )->getControler();
284 //------------------------------------------------------------------------------------------------------------
285 manualViewBaseContour * wxVtkBaseView_SceneManager :: getViewerOf( std::string theName )
287 return getContourWrap_ViewControlOf ( theName )->getViewer();
289 //------------------------------------------------------------------------------------------------------------
290 void wxVtkBaseView_SceneManager :: set_creatingMULT_ROI( bool condition )
292 _creatingMULT_ROI = condition;
294 //------------------------------------------------------------------------------------------------------------
295 void wxVtkBaseView_SceneManager :: set_editingROI( bool condition )
297 _editingROI = condition;
299 //------------------------------------------------------------------------------------------------------------
300 void wxVtkBaseView_SceneManager :: set_toIncludeAtInteractionGroup( bool condition )
302 _toIncludeAtInteractionGroup = condition;
304 //------------------------------------------------------------------------------------------------------------
305 void wxVtkBaseView_SceneManager :: set_waiting( bool condition )
307 _waiting = condition;
309 //------------------------------------------------------------------------------------------------------------
310 bool wxVtkBaseView_SceneManager :: get_creatingMULT_ROI( )
312 return _creatingMULT_ROI;
314 //------------------------------------------------------------------------------------------------------------
315 bool wxVtkBaseView_SceneManager :: get_editingROI( )
319 //------------------------------------------------------------------------------------------------------------
320 bool wxVtkBaseView_SceneManager :: get_toIncludeAtInteractionGroup( )
322 return _toIncludeAtInteractionGroup;
325 //------------------------------------------------------------------------------------------------------------
326 bool wxVtkBaseView_SceneManager :: get_waiting( )
331 //------------------------------------------------------------------------------------------------------------
332 bool wxVtkBaseView_SceneManager :: get_creatingROI()
336 //------------------------------------------------------------------------------------------------------------
337 void wxVtkBaseView_SceneManager :: set_creatingROI( bool condition )
339 _creatingROI = condition;
342 //------------------------------------------------------------------------------------------------------------
343 // Other functional methods
344 //------------------------------------------------------------------------------------------------------------
346 void wxVtkBaseView_SceneManager :: createCopyContourOf( std::string anExistingKName, std::string cloneName, manualBaseModel * manualModel, bool append )
350 setControlActiveStateOf( _workingGroup, false );
351 _workingGroup->clear();
353 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
356 iter = _contours_ViewControl->find( anExistingKName );
358 manualBaseModel *cModule = manualModel;
359 manualViewBaseContour *cViewer = iter->second->getViewer()->Clone();
360 manualContourBaseControler *cControl = iter->second->getControler()->Clone( );
362 cViewer->SetModel(cModule);
363 cControl->SetModelView( cModule , cViewer );
364 cControl->CreateNewManualContour();
365 cControl->SetActive( true );
366 cControl->SetEditable( false );
368 cViewer->RefreshContour();
370 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
371 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
373 _lastInteraction = insertWrap( cloneName, cControl, cViewer );
374 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( cloneName, _lastInteraction ));
375 addToScene( cloneName );
378 //------------------------------------------------------------------------------------------------------------
380 void wxVtkBaseView_SceneManager :: removeFromScene( ContourWrap_ViewControl * contourWRP, bool visualization, bool control )
382 if( contourWRP == _lastInteraction )
384 _lastInteraction = NULL;
385 _lastInteractionName = "";
389 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->RemoveInteractorStyleMaracas( contourWRP->getControler() );
391 contourWRP->getControler()->SetActive( control );
392 contourWRP->getControler()->SetEditable( false );
394 if ( !visualization && control )
396 contourWRP->getViewer()->RemoveControlPoints( );
397 contourWRP->getViewer()->RemoveTextActor( );
401 contourWRP->getViewer()->RemoveCompleteContourActor();
405 //------------------------------------------------------------------------------------------------------------
406 void wxVtkBaseView_SceneManager :: removeFromScene( std::string theKeyName, bool visualization , bool control )
409 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
410 iter = _sceneContours_ViewControl->find( theKeyName );
411 if (iter != _sceneContours_ViewControl->end())
413 ContourWrap_ViewControl * contourWRP = iter->second;
414 removeFromScene( contourWRP );
415 _sceneContours_ViewControl->erase(iter);
420 //------------------------------------------------------------------------------------------------------------
421 std::vector<std::string> wxVtkBaseView_SceneManager::GetlstContoursNameActualSlice()
423 std::vector<std::string> lstContoursNameActualSlice;
424 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
425 int i,size = _sceneContours_ViewControl->size();
426 for ( i = 0; i<size; i++ )
428 lstContoursNameActualSlice.push_back( iter->first );
431 return lstContoursNameActualSlice;
434 //------------------------------------------------------------------------------------------------------------
435 void wxVtkBaseView_SceneManager :: removeSceneContours( )
437 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
438 int size = _sceneContours_ViewControl->size();
439 for ( int i = 0; i<size; i++ )
441 removeFromScene( iter->second );
444 _sceneContours_ViewControl->clear();
447 //Removing the selection rectangle to avoid showing when it's innecesary
448 _controlerSelectionROI->SetActive( false );
449 _viewerSelectionROI->RemoveCompleteContourActor();
452 void wxVtkBaseView_SceneManager::removeAllOutlines()
454 manualViewBaseContour * cViewer;
455 manualContourBaseControler * cControler;
457 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
458 int i,size=_contours_ViewControl->size();
461 iter = _contours_ViewControl->begin();
462 cControler = iter->second->getControler();
463 cViewer = iter->second->getViewer();
464 removeWrap( iter->first );
472 //------------------------------------------------------------------------------------------------------------
473 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
477 removeSceneContours();
479 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
480 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
482 addToScene( theKeyName, contourWRP, true, visualization, control, ifActive, ifShowCtrlPoints);
485 //------------------------------------------------------------------------------------------------------------
486 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
490 removeSceneContours();
492 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
495 contourWRP->getViewer()->AddCompleteContourActor( ifShowCtrlPoints );
500 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( contourWRP->getControler() );
504 contourWRP->getControler()->SetActive( true );
505 contourWRP->getViewer()->RemoveTextActor();
509 //------------------------------------------------------------------------------------------------------------
510 void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
512 int i, size = theKeyNameVector.size();
513 for( i=0; i< size; i++ )
515 removeFromScene( theKeyNameVector[i], visualization, control );
519 //------------------------------------------------------------------------------------------------------------
520 void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
522 int i, size = theKeyNameVector.size();
523 for( i=0; i< size; i++ )
525 addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
529 //------------------------------------------------------------------------------------------------------------
530 void wxVtkBaseView_SceneManager :: setControlActiveStateOfALL( bool stateCondition )
532 setControlActiveStateOf( _contours_ViewControl, stateCondition );
535 //------------------------------------------------------------------------------------------------------------
536 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
538 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
539 setControlActiveStateOf( contourWRP, stateCondition );
542 //------------------------------------------------------------------------------------------------------------
543 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( ContourWrap_ViewControl * contourWRP, bool stateCondition )
545 contourWRP->getControler()->SetActive( stateCondition );
546 contourWRP->getControler()->SetEditable( false );
549 //------------------------------------------------------------------------------------------------------------
550 void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
552 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
553 // contourWRP->getViewer()->SetVisible( stateCondition );
554 if ( contourWRP!=NULL )
555 removeFromScene( contourWRP, false, stateCondition );
558 //------------------------------------------------------------------------------------------------------------
559 std::vector< std::string > wxVtkBaseView_SceneManager :: getSelectedObjects()
561 std::vector< std::string > selectedObjects;
562 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
563 int size = _workingGroup->size();
564 for ( int i = 0; i<size; i++ )
566 //EED??? manualViewBaseContour * viewer = iter->second->getViewer();
567 selectedObjects.push_back( iter->first);
571 return selectedObjects;
573 //------------------------------------------------------------------------------------------------------------
574 void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
576 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
577 //EED??? int size = _contours_ViewControl->size();
578 //EED??? bool selected;
579 /*for ( int i = 0; i<size; i++ )
582 manualViewBaseContour * viewer = iter->second->getViewer();
583 std::vector <std::string >::iterator iterIN;
585 for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
587 if( iter->first.compare( theExistingObjectsToSelect[i] ) )
589 viewer->SelectAllPoints( true );
590 viewer->SelectPosibleContour( true );
592 theExistingObjectsToSelect.erase( iterIN );
600 //------------------------------------------------------------------------------------------------------------
601 void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
603 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
604 int size = _contours_ViewControl->size();
605 for ( int i = 0; i<size; i++ )
607 manualViewBaseContour * viewer = iter->second->getViewer();
609 viewer->SetSelected( true );
610 /*viewer->SelectAllPoints( true );
611 viewer->SelectPosibleContour( true );*/
617 //------------------------------------------------------------------------------------------------------------
618 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
620 int i, size = theKeyNameVector.size();
621 for( i=0; i< size; i++ )
623 setControlActiveStateOf( theKeyNameVector[i], controlCondition );
627 //------------------------------------------------------------------------------------------------------------
628 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
630 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
631 int i, size = theMap->size();
632 for( i=0; i< size; i++ )
634 removeFromScene( iter->second, false, controlCondition );
639 //------------------------------------------------------------------------------------------------------------
641 //------------------------------------------------------------------------------------------------------------
643 //------------------------------------------------------------------------------------------------------------
644 // Creational and initialization methods
645 //------------------------------------------------------------------------------------------------------------
647 //------------------------------------------------------------------------------------------------------------
649 //------------------------------------------------------------------------------------------------------------
651 bool wxVtkBaseView_SceneManager :: isCtrlPressed()
655 bool wxVtkBaseView_SceneManager :: isShiftPressed()
659 char wxVtkBaseView_SceneManager :: getLastKeyCode()
663 bool wxVtkBaseView_SceneManager :: OnChar()
666 _ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
667 _shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
669 _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
671 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
672 _eventHandler->ProcessEvent( cevent );
675 /*if( _eventHandler!=NULL )
677 char * toolCommand = NULL;
679 if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
681 toolCommand = &(COPY_TOOL);
683 else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
685 toolCommand = &(PASTE_TOOL);
687 else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
689 toolCommand = &(DELETE_KEY);
691 else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
693 toolCommand = &(CREATE_CONTOUR_KEY);
695 else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
697 toolCommand = &(OPEN_TOOL);
699 else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
701 toolCommand = &(SAVE_KEY);
704 if ( toolCommand!=NULL )
706 currentkey = toolCommand;
707 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
708 cevent.SetClientData( (void *) toolCommand);
709 _eventHandler->ProcessEvent( cevent );
714 // long int endtime = clock();
718 //------------------------------------------------------------------------------------------------------------
720 bool wxVtkBaseView_SceneManager :: OnMouseMove()
723 bool condition = true;
725 wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
726 _wxVTKiren->GetEventPosition( X , Y );
728 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
729 //??? bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
731 if( _waiting && !ctrlKey )
733 sendEnvent( wxEVT_CHANGED_DEEP, "Update");
734 //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
737 if ( !_creatingROI && !_creatingMULT_ROI )
740 /*if( ctrlKey || shiftKey )
746 _toIncludeAtInteractionGroup = false;
749 bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
750 std::string preservingName = preserveState ? _lastInteractionName : "";
752 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
753 int i, size = _sceneContours_ViewControl->size();
754 bool foundOne = false;
756 manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
757 manualViewBaseContour * viewer = NULL;
760 bool singleMoving = true;
761 int selectionSize = _workingGroup->size();
762 if( selectionSize > 1 )
766 //EED??? bool ckecking = false;
767 for( i =0; i<size ; i++ )
769 control = iter->second->getControler();
770 viewer = iter->second->getViewer();
771 /*ckecking = */control->SetActive( true );
773 if (_lastInteraction != NULL)
775 singleMoving = !_lastInteraction->getViewer()->GetSelected();
780 size = selectionSize;
781 iter = _workingGroup->begin();
787 _toIncludeAtInteractionGroup = false;
790 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
793 _lastInteraction=NULL;
794 for( i =0; i<size ; i++ )
796 control = iter->second->getControler();
797 viewer = iter->second->getViewer();
798 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
799 control->SetActive( true );
801 foundOne = control->OnMouseMove();
802 foundOne &= viewer->GetPosibleSelected();
804 if ( !foundOne && singleMoving )
806 control->SetActive( false );
807 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
808 control->SetPosibleToMove( false );
812 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
814 _lastInteraction->getControler()->SetActive( true );
817 _lastInteraction = iter->second;
818 _lastInteractionName = iter->first;
820 viewer->UpdateColorActor();
821 control->SetPosibleToMove( true );
822 // viewer->AddCompleteContourActor();
837 //------------------------------------------------------------------------------------------------------------
838 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
843 //EED??? char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
844 bool condition = false;
845 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
846 //EED??? vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
847 //EED??? wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
848 //EED?? wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
849 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
851 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
852 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
853 _toIncludeAtInteractionGroup = false;
854 if ( ctrlKey || shftKey )
856 _toIncludeAtInteractionGroup = true;
860 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
862 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
864 _lastInteraction->getControler()->SetEditable( false );
865 _lastInteraction->getControler()->SetActive( false );
866 _lastInteraction->getControler()->SetPosibleToMove( false );
867 _lastInteraction->getViewer()->Refresh();
868 _lastInteraction=NULL;
875 if( !_toIncludeAtInteractionGroup )
877 _workingGroup->clear();
880 if( _lastInteraction!=NULL )
882 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
883 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
884 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
886 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
889 //setControlActiveStateOf( _contours_ViewControl, false );
890 sendEnvent( wxEVT_START_CREATE_ROI, "");
894 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
895 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
896 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
903 //------------------------------------------------------------------------------------------------------------
904 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
906 bool condition = false;
909 if( _drawingSelectionROI )
911 setSelection2DROIInternalOutlines();
915 //------------------------------------------------------------------------------------------------------------
916 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
918 bool condition = false;
923 //------------------------------------------------------------------------------------------------------------
924 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
926 bool condition = false;
931 //------------------------------------------------------------------------------------------------------------
932 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
934 bool condition = false;
935 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
936 //EED??? bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
943 //------------------------------------------------------------------------------------------------------------
944 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
946 bool condition = false;
948 //setControlActiveStateOfALL( false );//************************************************
949 if ( _creatingMULT_ROI )
951 //setControlActiveStateOfALL( false );
955 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
956 _creatingROI = false;
960 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
962 manualContourBaseControler * control = _lastInteraction->getControler();
963 //_lastInteraction->getControler()->SetPosibleToMove( false );
964 control->SetActive( false );
965 control->SetEditable( false );
966 control->SetPosibleToMove( false );
967 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
968 _lastInteraction->getViewer()->Refresh();
969 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
975 //------------------------------------------------------------------------------------------------------------
977 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
979 bool condition = false;
984 //------------------------------------------------------------------------------------------------------------
985 bool wxVtkBaseView_SceneManager :: OnRightDClick()
987 bool condition = false; condition = true;
988 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
989 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
990 //EED??? wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
994 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
995 set_creatingMULT_ROI( !_creatingMULT_ROI );
1003 //------------------------------------------------------------------------------------------------------------
1004 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
1006 bool condition = false;
1011 //------------------------------------------------------------------------------------------------------------
1012 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
1014 bool condition = false;
1018 //------------------------------------------------------------------------------------------------------------
1020 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1022 _drawingSelectionROI = true;
1023 _workingGroup->clear();
1024 _controlerSelectionROI->CreateNewManualContour();
1025 if (_lastInteraction!=NULL)
1027 _lastInteraction->getControler()->SetEditable( false );
1028 _lastInteraction->getControler()->SetActive( false );
1029 _lastInteraction->getControler()->SetPosibleToMove( false );
1030 _lastInteraction->getViewer()->Refresh();
1032 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1033 int i, workSize = _workingGroup->size();
1034 for( i=0; i< workSize; i++ )
1036 manualContourBaseControler * control = iter->second->getControler();
1037 control->SetEditable( false );
1038 control->SetActive( false );
1039 control->SetPosibleToMove( false );
1040 iter->second->getViewer()->Refresh();
1044 _lastInteraction = NULL;
1045 _lastInteractionName = "";
1047 _viewerSelectionROI->AddCompleteContourActor( true );
1048 _controlerSelectionROI->SetActive( true );
1050 _viewerSelectionROI->RefreshContour();
1051 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1053 //------------------------------------------------------------------------------------------------------------
1054 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1056 _drawingSelectionROI = false;
1057 _workingGroup->clear();
1058 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1061 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1062 int i, size = _sceneContours_ViewControl->size();
1063 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1064 manualViewBaseContour * viewer;
1065 bool insideRoi = false;
1066 for ( i=0; i<size; i++ )
1068 viewer = iter->second->getViewer();
1069 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1070 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1073 viewer->SetSelected( true );
1074 viewer->UpdateColorActor();
1075 setControlActiveStateOf( iter->second, true );
1076 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1080 _viewerSelectionROI->RemoveCompleteContourActor( );
1081 _controlerSelectionROI->SetActive( false );
1083 //------------------------------------------------------------------------------------------------------------
1084 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1086 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1087 long int start = clock();
1089 double sg = (double)(start) / (double)CLK_TCK;
1091 double sg = (double)(start) / CLOCKS_PER_SEC;
1094 wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1095 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1096 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): %f\n \n",method.c_str(), tmpPx, tmpPy, sg);
1101 //------------------------------------------------------------------------------------------------------------
1102 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1104 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1105 manualViewBaseContour * cViewer;
1106 manualContourBaseControler * cControler;
1107 ContourWrap_ViewControl *conwraviwcont=iter->second;
1109 cViewer = conwraviwcont->getViewer();
1112 cControler = conwraviwcont->getControler();
1113 // cControler->Save(ff);
1115 // cModel = cControler->GetManualContourModel();
1116 // cModel->Save(ff);
1120 //------------------------------------------------------------------------------------------------------------
1121 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1123 std::vector<std::string> currentSelection = this->getSelectedObjects();
1124 if (currentSelection.size()>=1){
1126 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1127 manualBaseModel *cModel = cControler->GetManualContourModel();
1128 int i,size = cModel->GetNumberOfPointsSpline();
1130 for (i=0; i<size; i++)
1132 cModel->GetSpline_i_Point(i, &x, &y, &z);
1140 //------------------------------------------------------------------------------------------------------------
1141 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1143 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1144 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1147 //------------------------------------------------------------------------------------------------------------
1148 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1151 vtkImageData *imagedata = GetImageData();
1152 imagedata->GetExtent(ext);
1153 int sizeZ = ext[5]-ext[4]+1;
1161 //------------------------------------------------------------------------------------------------------------
1162 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1165 vtkImageData *imagedata = GetImageData();
1166 imagedata->GetExtent(ext);
1167 int sizeX = ext[1]-ext[0]+1;
1168 int sizeY = ext[3]-ext[2]+1;
1169 int sizeZ = GetImageDataSizeZ();
1170 int sizeXYZ = sizeX*sizeY*sizeZ;
1174 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1175 for (i=0;i<sizeXYZ;i++)
1177 if ( p[i]<range[0] ) range[0]=p[i];
1178 if ( p[i]>range[1] ) range[1]=p[i];
1182 //------------------------------------------------------------------------------------------------------------
1183 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1185 _widthOfContour = width;
1186 manualViewBaseContour *cViewer;
1187 ContourWrap_ViewControl *conwraviwcont;
1188 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
1190 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1192 conwraviwcont = iter->second;
1193 cViewer = conwraviwcont->getViewer();
1194 cViewer->SetWidthLine(_widthOfContour);
1198 bool wxVtkBaseView_SceneManager::isEditableCControler(std::string theKeyName){
1200 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1202 manualContourBaseControler* cControler = ccon->getControler();
1203 if(cControler != NULL && cControler->IsEditable() == false){
1210 void wxVtkBaseView_SceneManager::deleteCViewerCControler(std::string theKeyName){
1213 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1215 manualViewBaseContour * cViewer = ccon->getViewer();
1216 manualContourBaseControler * cControler = ccon->getControler();
1218 removeFromScene(theKeyName);
1219 removeWrap(theKeyName);