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();
153 manContourControl = new manualRoiControler();
154 manViewerContour = new manualViewRoi();
159 manContourControl = new manualCircleControler();
160 manViewerContour = new manualViewCircle();
165 manContourControl = new manualRoiControler();
166 manViewerContour = new manualViewBullEye();
171 manContourControl = new manualLineControler();
172 manViewerContour = new manualViewLine();
177 _lastInteraction = insertWrap( theKeyName, manContourControl, manViewerContour );
178 _lastInteractionName = theKeyName;
180 //Configuring the relations between the contour members representation
181 manViewerContour->SetModel( manModelContour );
182 manViewerContour->SetWxVtkBaseView( _wxVtk_BaseView );
183 manViewerContour->SetRange( 0.5 );
184 manViewerContour->SetZ( 1000 );
186 manViewerContour->SetSpacing(spc);
188 manViewerContour->SetColorNormalContour(0, 0, 1);
189 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
190 manViewerContour->SetColorSelectContour(1, 0.8, 0);
191 manViewerContour->SetWidthLine(_widthOfContour);
193 manContourControl->SetModelView( manModelContour , manViewerContour );
194 manContourControl->Configure();
195 int i,sizeLstPoints = manModelContour->GetSizeLstPoints();
196 for ( i=0; i<sizeLstPoints; i++ )
198 manViewerContour->AddPoint();
201 manContourControl->CreateNewManualContour();
202 manViewerContour->RefreshContour();
203 addToScene( theKeyName );
205 //------------------------------------------------------------------------------------------------------------
206 void wxVtkBaseView_SceneManager :: configureSelectionROI( double * spc )
208 _controlerSelectionROI = new manualRoiControler();
209 _viewerSelectionROI = new manualViewRoi();
210 _modelSelectionROI = new manualContourModel();
212 _viewerSelectionROI->SetModel( _modelSelectionROI );
213 _viewerSelectionROI->SetWxVtkBaseView( _wxVtk_BaseView );
214 _viewerSelectionROI->SetRange( 2 );
215 _viewerSelectionROI->SetZ( 1000 );
216 _viewerSelectionROI->SetColorNormalContour(0.6, 0.8, 0);
218 _viewerSelectionROI->SetSpacing( spc );
220 _controlerSelectionROI->SetModelView( _modelSelectionROI , _viewerSelectionROI );
221 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _controlerSelectionROI );
222 _controlerSelectionROI->SetActive(false);
225 //------------------------------------------------------------------------------------------------------------
226 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: insertWrap( std::string theKeyName, manualContourBaseControler * manContourControl, manualViewBaseContour * manViewerContour )
228 ContourWrap_ViewControl * newContourWrap = new ContourWrap_ViewControl(manContourControl, manViewerContour);
229 _contours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, newContourWrap ));
230 return newContourWrap;
232 //------------------------------------------------------------------------------------------------------------
233 void wxVtkBaseView_SceneManager :: desconfigureViewControlOf( std::string theKeyName )
237 //------------------------------------------------------------------------------------------------------------
238 void wxVtkBaseView_SceneManager :: removeWrap( std::string theKeyName )
240 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
241 iter = _contours_ViewControl->find( theKeyName );
242 _contours_ViewControl->erase( iter );
243 _lastInteraction=NULL;
244 _lastInteractionName = "";
245 _workingGroup->clear();
246 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
247 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
249 //------------------------------------------------------------------------------------------------------------
250 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName )
252 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
253 iter = _contours_ViewControl->find( theName );
255 //return iter->first;
257 //------------------------------------------------------------------------------------------------------------
258 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName, std::map<std::string, ContourWrap_ViewControl *> * theMap )
260 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
261 iter = theMap->find( theName );
264 //------------------------------------------------------------------------------------------------------------
265 manualContourBaseControler * wxVtkBaseView_SceneManager :: getControlerOf( std::string theName )
267 return getContourWrap_ViewControlOf ( theName )->getControler();
269 //------------------------------------------------------------------------------------------------------------
270 manualViewBaseContour * wxVtkBaseView_SceneManager :: getViewerOf( std::string theName )
272 return getContourWrap_ViewControlOf ( theName )->getViewer();
274 //------------------------------------------------------------------------------------------------------------
275 void wxVtkBaseView_SceneManager :: set_creatingMULT_ROI( bool condition )
277 _creatingMULT_ROI = condition;
279 //------------------------------------------------------------------------------------------------------------
280 void wxVtkBaseView_SceneManager :: set_editingROI( bool condition )
282 _editingROI = condition;
284 //------------------------------------------------------------------------------------------------------------
285 void wxVtkBaseView_SceneManager :: set_toIncludeAtInteractionGroup( bool condition )
287 _toIncludeAtInteractionGroup = condition;
289 //------------------------------------------------------------------------------------------------------------
290 void wxVtkBaseView_SceneManager :: set_waiting( bool condition )
292 _waiting = condition;
294 //------------------------------------------------------------------------------------------------------------
295 bool wxVtkBaseView_SceneManager :: get_creatingMULT_ROI( )
297 return _creatingMULT_ROI;
299 //------------------------------------------------------------------------------------------------------------
300 bool wxVtkBaseView_SceneManager :: get_editingROI( )
304 //------------------------------------------------------------------------------------------------------------
305 bool wxVtkBaseView_SceneManager :: get_toIncludeAtInteractionGroup( )
307 return _toIncludeAtInteractionGroup;
310 //------------------------------------------------------------------------------------------------------------
311 bool wxVtkBaseView_SceneManager :: get_waiting( )
316 //------------------------------------------------------------------------------------------------------------
317 bool wxVtkBaseView_SceneManager :: get_creatingROI()
321 //------------------------------------------------------------------------------------------------------------
322 void wxVtkBaseView_SceneManager :: set_creatingROI( bool condition )
324 _creatingROI = condition;
327 //------------------------------------------------------------------------------------------------------------
328 // Other functional methods
329 //------------------------------------------------------------------------------------------------------------
331 void wxVtkBaseView_SceneManager :: createCopyContourOf( std::string anExistingKName, std::string cloneName, manualContourModel * manualModel, bool append )
335 setControlActiveStateOf( _workingGroup, false );
336 _workingGroup->clear();
338 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
341 iter = _contours_ViewControl->find( anExistingKName );
343 manualContourModel *cModule = manualModel;
344 manualViewBaseContour *cViewer = iter->second->getViewer()->Clone();
345 manualContourBaseControler *cControl = iter->second->getControler()->Clone( );
347 cViewer->SetModel(cModule);
348 cControl->SetModelView( cModule , cViewer );
349 cControl->CreateNewManualContour();
350 cControl->SetActive( true );
351 cControl->SetEditable( false );
353 cViewer->RefreshContour();
355 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
356 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
358 _lastInteraction = insertWrap( cloneName, cControl, cViewer );
359 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( cloneName, _lastInteraction ));
360 addToScene( cloneName );
363 //------------------------------------------------------------------------------------------------------------
365 void wxVtkBaseView_SceneManager :: removeFromScene( ContourWrap_ViewControl * contourWRP, bool visualization, bool control )
367 if( contourWRP == _lastInteraction )
369 _lastInteraction = NULL;
370 _lastInteractionName = "";
374 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->RemoveInteractorStyleMaracas( contourWRP->getControler() );
376 contourWRP->getControler()->SetActive( control );
377 contourWRP->getControler()->SetEditable( false );
379 if ( !visualization && control )
381 contourWRP->getViewer()->RemoveControlPoints( );
382 contourWRP->getViewer()->RemoveTextActor( );
386 contourWRP->getViewer()->RemoveCompleteContourActor();
390 //------------------------------------------------------------------------------------------------------------
391 void wxVtkBaseView_SceneManager :: removeFromScene( std::string theKeyName, bool visualization , bool control )
394 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
395 iter = _sceneContours_ViewControl->find( theKeyName );
396 if (iter != _sceneContours_ViewControl->end())
398 ContourWrap_ViewControl * contourWRP = iter->second;
399 removeFromScene( contourWRP );
400 _sceneContours_ViewControl->erase(iter);
405 //------------------------------------------------------------------------------------------------------------
406 std::vector<std::string> wxVtkBaseView_SceneManager::GetlstContoursNameActualSlice()
408 std::vector<std::string> lstContoursNameActualSlice;
409 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
410 int i,size = _sceneContours_ViewControl->size();
411 for ( i = 0; i<size; i++ )
413 lstContoursNameActualSlice.push_back( iter->first );
416 return lstContoursNameActualSlice;
419 //------------------------------------------------------------------------------------------------------------
420 void wxVtkBaseView_SceneManager :: removeSceneContours( )
422 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
423 int size = _sceneContours_ViewControl->size();
424 for ( int i = 0; i<size; i++ )
426 removeFromScene( iter->second );
429 _sceneContours_ViewControl->clear();
432 //Removing the selection rectangle to avoid showing when it's innecesary
433 _controlerSelectionROI->SetActive( false );
434 _viewerSelectionROI->RemoveCompleteContourActor();
437 void wxVtkBaseView_SceneManager::removeAllOutlines()
439 manualViewBaseContour * cViewer;
440 manualContourBaseControler * cControler;
442 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
443 int i,size=_contours_ViewControl->size();
446 iter = _contours_ViewControl->begin();
447 cControler = iter->second->getControler();
448 cViewer = iter->second->getViewer();
449 removeWrap( iter->first );
457 //------------------------------------------------------------------------------------------------------------
458 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
462 removeSceneContours();
464 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
465 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
467 addToScene( theKeyName, contourWRP, true, visualization, control, ifActive, ifShowCtrlPoints);
470 //------------------------------------------------------------------------------------------------------------
471 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
475 removeSceneContours();
477 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
480 contourWRP->getViewer()->AddCompleteContourActor( ifShowCtrlPoints );
485 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( contourWRP->getControler() );
489 contourWRP->getControler()->SetActive( true );
490 contourWRP->getViewer()->RemoveTextActor();
494 //------------------------------------------------------------------------------------------------------------
495 void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
497 int i, size = theKeyNameVector.size();
498 for( i=0; i< size; i++ )
500 removeFromScene( theKeyNameVector[i], visualization, control );
504 //------------------------------------------------------------------------------------------------------------
505 void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
507 int i, size = theKeyNameVector.size();
508 for( i=0; i< size; i++ )
510 addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
514 //------------------------------------------------------------------------------------------------------------
515 void wxVtkBaseView_SceneManager :: setControlActiveStateOfALL( bool stateCondition )
517 setControlActiveStateOf( _contours_ViewControl, stateCondition );
520 //------------------------------------------------------------------------------------------------------------
521 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
523 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
524 setControlActiveStateOf( contourWRP, stateCondition );
527 //------------------------------------------------------------------------------------------------------------
528 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( ContourWrap_ViewControl * contourWRP, bool stateCondition )
530 contourWRP->getControler()->SetActive( stateCondition );
531 contourWRP->getControler()->SetEditable( false );
534 //------------------------------------------------------------------------------------------------------------
535 void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
537 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
538 // contourWRP->getViewer()->SetVisible( stateCondition );
539 if ( contourWRP!=NULL )
540 removeFromScene( contourWRP, false, stateCondition );
543 //------------------------------------------------------------------------------------------------------------
544 std::vector< std::string > wxVtkBaseView_SceneManager :: getSelectedObjects()
546 std::vector< std::string > selectedObjects;
547 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
548 int size = _workingGroup->size();
549 for ( int i = 0; i<size; i++ )
551 //EED??? manualViewBaseContour * viewer = iter->second->getViewer();
552 selectedObjects.push_back( iter->first);
556 return selectedObjects;
558 //------------------------------------------------------------------------------------------------------------
559 void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
561 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
562 //EED??? int size = _contours_ViewControl->size();
563 //EED??? bool selected;
564 /*for ( int i = 0; i<size; i++ )
567 manualViewBaseContour * viewer = iter->second->getViewer();
568 std::vector <std::string >::iterator iterIN;
570 for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
572 if( iter->first.compare( theExistingObjectsToSelect[i] ) )
574 viewer->SelectAllPoints( true );
575 viewer->SelectPosibleContour( true );
577 theExistingObjectsToSelect.erase( iterIN );
585 //------------------------------------------------------------------------------------------------------------
586 void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
588 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
589 int size = _contours_ViewControl->size();
590 for ( int i = 0; i<size; i++ )
592 manualViewBaseContour * viewer = iter->second->getViewer();
594 viewer->SetSelected( true );
595 /*viewer->SelectAllPoints( true );
596 viewer->SelectPosibleContour( true );*/
602 //------------------------------------------------------------------------------------------------------------
603 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
605 int i, size = theKeyNameVector.size();
606 for( i=0; i< size; i++ )
608 setControlActiveStateOf( theKeyNameVector[i], controlCondition );
612 //------------------------------------------------------------------------------------------------------------
613 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
615 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
616 int i, size = theMap->size();
617 for( i=0; i< size; i++ )
619 removeFromScene( iter->second, false, controlCondition );
624 //------------------------------------------------------------------------------------------------------------
626 //------------------------------------------------------------------------------------------------------------
628 //------------------------------------------------------------------------------------------------------------
629 // Creational and initialization methods
630 //------------------------------------------------------------------------------------------------------------
632 //------------------------------------------------------------------------------------------------------------
634 //------------------------------------------------------------------------------------------------------------
636 bool wxVtkBaseView_SceneManager :: isCtrlPressed()
640 bool wxVtkBaseView_SceneManager :: isShiftPressed()
644 char wxVtkBaseView_SceneManager :: getLastKeyCode()
648 bool wxVtkBaseView_SceneManager :: OnChar()
651 _ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
652 _shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
654 _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
656 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
657 _eventHandler->ProcessEvent( cevent );
660 /*if( _eventHandler!=NULL )
662 char * toolCommand = NULL;
664 if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
666 toolCommand = &(COPY_TOOL);
668 else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
670 toolCommand = &(PASTE_TOOL);
672 else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
674 toolCommand = &(DELETE_KEY);
676 else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
678 toolCommand = &(CREATE_CONTOUR_KEY);
680 else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
682 toolCommand = &(OPEN_TOOL);
684 else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
686 toolCommand = &(SAVE_KEY);
689 if ( toolCommand!=NULL )
691 currentkey = toolCommand;
692 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
693 cevent.SetClientData( (void *) toolCommand);
694 _eventHandler->ProcessEvent( cevent );
699 // long int endtime = clock();
703 //------------------------------------------------------------------------------------------------------------
705 bool wxVtkBaseView_SceneManager :: OnMouseMove()
708 bool condition = true;
710 wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
711 _wxVTKiren->GetEventPosition( X , Y );
713 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
714 //??? bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
716 if( _waiting && !ctrlKey )
718 sendEnvent( wxEVT_CHANGED_DEEP, "Update");
719 //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
722 if ( !_creatingROI && !_creatingMULT_ROI )
725 /*if( ctrlKey || shiftKey )
731 _toIncludeAtInteractionGroup = false;
734 bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
735 std::string preservingName = preserveState ? _lastInteractionName : "";
737 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
738 int i, size = _sceneContours_ViewControl->size();
739 bool foundOne = false;
741 manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
742 manualViewBaseContour * viewer = NULL;
745 bool singleMoving = true;
746 int selectionSize = _workingGroup->size();
747 if( selectionSize > 1 )
751 //EED??? bool ckecking = false;
752 for( i =0; i<size ; i++ )
754 control = iter->second->getControler();
755 viewer = iter->second->getViewer();
756 /*ckecking = */control->SetActive( true );
758 if (_lastInteraction != NULL)
760 singleMoving = !_lastInteraction->getViewer()->GetSelected();
765 size = selectionSize;
766 iter = _workingGroup->begin();
772 _toIncludeAtInteractionGroup = false;
775 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
778 _lastInteraction=NULL;
779 for( i =0; i<size ; i++ )
781 control = iter->second->getControler();
782 viewer = iter->second->getViewer();
783 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
784 control->SetActive( true );
786 foundOne = control->OnMouseMove();
787 foundOne &= viewer->GetPosibleSelected();
789 if ( !foundOne && singleMoving )
791 control->SetActive( false );
792 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
793 control->SetPosibleToMove( false );
797 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
799 _lastInteraction->getControler()->SetActive( true );
802 _lastInteraction = iter->second;
803 _lastInteractionName = iter->first;
805 viewer->UpdateColorActor();
806 control->SetPosibleToMove( true );
807 // viewer->AddCompleteContourActor();
822 //------------------------------------------------------------------------------------------------------------
823 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
828 //EED??? char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
829 bool condition = false;
830 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
831 //EED??? vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
832 //EED??? wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
833 //EED?? wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
834 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
836 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
837 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
838 _toIncludeAtInteractionGroup = false;
839 if ( ctrlKey || shftKey )
841 _toIncludeAtInteractionGroup = true;
845 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
847 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
849 _lastInteraction->getControler()->SetEditable( false );
850 _lastInteraction->getControler()->SetActive( false );
851 _lastInteraction->getControler()->SetPosibleToMove( false );
852 _lastInteraction->getViewer()->Refresh();
853 _lastInteraction=NULL;
860 if( !_toIncludeAtInteractionGroup )
862 _workingGroup->clear();
865 if( _lastInteraction!=NULL )
867 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
868 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
869 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
871 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
874 //setControlActiveStateOf( _contours_ViewControl, false );
875 sendEnvent( wxEVT_START_CREATE_ROI, "");
879 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
880 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
881 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
888 //------------------------------------------------------------------------------------------------------------
889 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
891 bool condition = false;
894 if( _drawingSelectionROI )
896 setSelection2DROIInternalOutlines();
900 //------------------------------------------------------------------------------------------------------------
901 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
903 bool condition = false;
908 //------------------------------------------------------------------------------------------------------------
909 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
911 bool condition = false;
916 //------------------------------------------------------------------------------------------------------------
917 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
919 bool condition = false;
920 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
921 //EED??? bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
928 //------------------------------------------------------------------------------------------------------------
929 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
931 bool condition = false;
933 //setControlActiveStateOfALL( false );//************************************************
934 if ( _creatingMULT_ROI )
936 //setControlActiveStateOfALL( false );
940 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
941 _creatingROI = false;
945 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
947 manualContourBaseControler * control = _lastInteraction->getControler();
948 //_lastInteraction->getControler()->SetPosibleToMove( false );
949 control->SetActive( false );
950 control->SetEditable( false );
951 control->SetPosibleToMove( false );
952 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
953 _lastInteraction->getViewer()->Refresh();
954 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
960 //------------------------------------------------------------------------------------------------------------
962 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
964 bool condition = false;
969 //------------------------------------------------------------------------------------------------------------
970 bool wxVtkBaseView_SceneManager :: OnRightDClick()
972 bool condition = false; condition = true;
973 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
974 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
975 //EED??? wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
979 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
980 set_creatingMULT_ROI( !_creatingMULT_ROI );
988 //------------------------------------------------------------------------------------------------------------
989 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
991 bool condition = false;
996 //------------------------------------------------------------------------------------------------------------
997 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
999 bool condition = false;
1003 //------------------------------------------------------------------------------------------------------------
1005 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1007 _drawingSelectionROI = true;
1008 _workingGroup->clear();
1009 _controlerSelectionROI->CreateNewManualContour();
1010 if (_lastInteraction!=NULL)
1012 _lastInteraction->getControler()->SetEditable( false );
1013 _lastInteraction->getControler()->SetActive( false );
1014 _lastInteraction->getControler()->SetPosibleToMove( false );
1015 _lastInteraction->getViewer()->Refresh();
1017 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1018 int i, workSize = _workingGroup->size();
1019 for( i=0; i< workSize; i++ )
1021 manualContourBaseControler * control = iter->second->getControler();
1022 control->SetEditable( false );
1023 control->SetActive( false );
1024 control->SetPosibleToMove( false );
1025 iter->second->getViewer()->Refresh();
1029 _lastInteraction = NULL;
1030 _lastInteractionName = "";
1032 _viewerSelectionROI->AddCompleteContourActor( true );
1033 _controlerSelectionROI->SetActive( true );
1035 _viewerSelectionROI->RefreshContour();
1036 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1038 //------------------------------------------------------------------------------------------------------------
1039 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1041 _drawingSelectionROI = false;
1042 _workingGroup->clear();
1043 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1046 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1047 int i, size = _sceneContours_ViewControl->size();
1048 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1049 manualViewBaseContour * viewer;
1050 bool insideRoi = false;
1051 for ( i=0; i<size; i++ )
1053 viewer = iter->second->getViewer();
1054 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1055 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1058 viewer->SetSelected( true );
1059 viewer->UpdateColorActor();
1060 setControlActiveStateOf( iter->second, true );
1061 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1065 _viewerSelectionROI->RemoveCompleteContourActor( );
1066 _controlerSelectionROI->SetActive( false );
1068 //------------------------------------------------------------------------------------------------------------
1069 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1071 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1072 long int start = clock();
1074 double sg = (double)(start) / (double)CLK_TCK;
1076 double sg = (double)(start) / CLOCKS_PER_SEC;
1079 wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1080 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1081 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): %f\n \n",method.c_str(), tmpPx, tmpPy, sg);
1086 //------------------------------------------------------------------------------------------------------------
1087 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1089 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1090 manualViewBaseContour * cViewer;
1091 manualContourBaseControler * cControler;
1092 ContourWrap_ViewControl *conwraviwcont=iter->second;
1094 cViewer = conwraviwcont->getViewer();
1097 cControler = conwraviwcont->getControler();
1098 // cControler->Save(ff);
1100 // cModel = cControler->GetManualContourModel();
1101 // cModel->Save(ff);
1105 //------------------------------------------------------------------------------------------------------------
1106 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1108 std::vector<std::string> currentSelection = this->getSelectedObjects();
1109 if (currentSelection.size()>=1){
1111 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1112 manualContourModel *cModel = cControler->GetManualContourModel();
1113 int i,size = cModel->GetNumberOfPointsSpline();
1115 for (i=0; i<size; i++)
1117 cModel->GetSpline_i_Point(i, &x, &y, &z);
1125 //------------------------------------------------------------------------------------------------------------
1126 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1128 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1129 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1132 //------------------------------------------------------------------------------------------------------------
1133 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1136 vtkImageData *imagedata = GetImageData();
1137 imagedata->GetExtent(ext);
1138 int sizeZ = ext[5]-ext[4]+1;
1146 //------------------------------------------------------------------------------------------------------------
1147 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1150 vtkImageData *imagedata = GetImageData();
1151 imagedata->GetExtent(ext);
1152 int sizeX = ext[1]-ext[0]+1;
1153 int sizeY = ext[3]-ext[2]+1;
1154 int sizeZ = GetImageDataSizeZ();
1155 int sizeXYZ = sizeX*sizeY*sizeZ;
1159 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1160 for (i=0;i<sizeXYZ;i++)
1162 if ( p[i]<range[0] ) range[0]=p[i];
1163 if ( p[i]>range[1] ) range[1]=p[i];
1167 //------------------------------------------------------------------------------------------------------------
1168 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1170 _widthOfContour = width;
1171 manualViewBaseContour *cViewer;
1172 ContourWrap_ViewControl *conwraviwcont;
1173 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;;
1175 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1177 conwraviwcont = iter->second;
1178 cViewer = conwraviwcont->getViewer();
1179 cViewer->SetWidthLine(_widthOfContour);
1183 bool wxVtkBaseView_SceneManager::isEditableCControler(std::string theKeyName){
1185 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1187 manualContourBaseControler* cControler = ccon->getControler();
1188 if(cControler != NULL && cControler->IsEditable() == false){
1195 void wxVtkBaseView_SceneManager::deleteCViewerCControler(std::string theKeyName){
1198 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1200 manualViewBaseContour * cViewer = ccon->getViewer();
1201 manualContourBaseControler * cControler = ccon->getControler();
1203 removeFromScene(theKeyName);
1204 removeWrap(theKeyName);