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 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
179 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: configureViewControlTo \n" );
180 //fprintf(ff," %s %p \n",theKeyName.c_str() , manContourControl );
184 _lastInteraction = insertWrap( theKeyName, manContourControl, manViewerContour );
185 _lastInteractionName = theKeyName;
187 //Configuring the relations between the contour members representation
188 manViewerContour->SetModel( manModelContour );
189 manViewerContour->SetWxVtkBaseView( _wxVtk_BaseView );
190 manViewerContour->SetRange( 0.5 );
191 manViewerContour->SetZ( 1000 );
193 manViewerContour->SetSpacing(spc);
195 manViewerContour->SetColorNormalContour(0, 0, 1);
196 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
197 manViewerContour->SetColorSelectContour(1, 0.8, 0);
198 manViewerContour->SetWidthLine(_widthOfContour);
200 manContourControl->SetModelView( manModelContour , manViewerContour );
201 manContourControl->Configure();
202 int i,sizeLstPoints = manModelContour->GetSizeLstPoints();
203 for ( i=0; i<sizeLstPoints; i++ )
205 manViewerContour->AddPoint();
208 manContourControl->CreateNewManualContour();
209 manViewerContour->RefreshContour();
210 addToScene( theKeyName );
212 //------------------------------------------------------------------------------------------------------------
213 void wxVtkBaseView_SceneManager :: configureSelectionROI( double * spc )
215 _controlerSelectionROI = new manualRoiControler();
216 _viewerSelectionROI = new manualViewRoi();
217 _modelSelectionROI = new manualContourModel();
219 _viewerSelectionROI->SetModel( _modelSelectionROI );
220 _viewerSelectionROI->SetWxVtkBaseView( _wxVtk_BaseView );
221 _viewerSelectionROI->SetRange( 2 );
222 _viewerSelectionROI->SetZ( 1000 );
223 _viewerSelectionROI->SetColorNormalContour(0.6, 0.8, 0);
225 _viewerSelectionROI->SetSpacing( spc );
227 _controlerSelectionROI->SetModelView( _modelSelectionROI , _viewerSelectionROI );
228 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _controlerSelectionROI );
229 _controlerSelectionROI->SetActive(false);
232 //------------------------------------------------------------------------------------------------------------
233 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: insertWrap( std::string theKeyName, manualContourBaseControler * manContourControl, manualViewBaseContour * manViewerContour )
235 ContourWrap_ViewControl * newContourWrap = new ContourWrap_ViewControl(manContourControl, manViewerContour);
236 _contours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, newContourWrap ));
237 return newContourWrap;
239 //------------------------------------------------------------------------------------------------------------
240 void wxVtkBaseView_SceneManager :: desconfigureViewControlOf( std::string theKeyName )
244 //------------------------------------------------------------------------------------------------------------
245 void wxVtkBaseView_SceneManager :: removeWrap( std::string theKeyName )
247 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
248 iter = _contours_ViewControl->find( theKeyName );
249 _contours_ViewControl->erase( iter );
250 _lastInteraction=NULL;
251 _lastInteractionName = "";
252 _workingGroup->clear();
253 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
254 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
256 //------------------------------------------------------------------------------------------------------------
257 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName )
259 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
260 iter = _contours_ViewControl->find( theName );
262 //return iter->first;
264 //------------------------------------------------------------------------------------------------------------
265 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName, std::map<std::string, ContourWrap_ViewControl *> * theMap )
267 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
268 iter = theMap->find( theName );
271 //------------------------------------------------------------------------------------------------------------
272 manualContourBaseControler * wxVtkBaseView_SceneManager :: getControlerOf( std::string theName )
274 return getContourWrap_ViewControlOf ( theName )->getControler();
276 //------------------------------------------------------------------------------------------------------------
277 manualViewBaseContour * wxVtkBaseView_SceneManager :: getViewerOf( std::string theName )
279 return getContourWrap_ViewControlOf ( theName )->getViewer();
281 //------------------------------------------------------------------------------------------------------------
282 void wxVtkBaseView_SceneManager :: set_creatingMULT_ROI( bool condition )
284 _creatingMULT_ROI = condition;
286 //------------------------------------------------------------------------------------------------------------
287 void wxVtkBaseView_SceneManager :: set_editingROI( bool condition )
289 _editingROI = condition;
291 //------------------------------------------------------------------------------------------------------------
292 void wxVtkBaseView_SceneManager :: set_toIncludeAtInteractionGroup( bool condition )
294 _toIncludeAtInteractionGroup = condition;
296 //------------------------------------------------------------------------------------------------------------
297 void wxVtkBaseView_SceneManager :: set_waiting( bool condition )
299 _waiting = condition;
301 //------------------------------------------------------------------------------------------------------------
302 bool wxVtkBaseView_SceneManager :: get_creatingMULT_ROI( )
304 return _creatingMULT_ROI;
306 //------------------------------------------------------------------------------------------------------------
307 bool wxVtkBaseView_SceneManager :: get_editingROI( )
311 //------------------------------------------------------------------------------------------------------------
312 bool wxVtkBaseView_SceneManager :: get_toIncludeAtInteractionGroup( )
314 return _toIncludeAtInteractionGroup;
317 //------------------------------------------------------------------------------------------------------------
318 bool wxVtkBaseView_SceneManager :: get_waiting( )
323 //------------------------------------------------------------------------------------------------------------
324 bool wxVtkBaseView_SceneManager :: get_creatingROI()
328 //------------------------------------------------------------------------------------------------------------
329 void wxVtkBaseView_SceneManager :: set_creatingROI( bool condition )
331 _creatingROI = condition;
334 //------------------------------------------------------------------------------------------------------------
335 // Other functional methods
336 //------------------------------------------------------------------------------------------------------------
338 void wxVtkBaseView_SceneManager :: createCopyContourOf( std::string anExistingKName, std::string cloneName, manualContourModel * manualModel, bool append )
342 setControlActiveStateOf( _workingGroup, false );
343 _workingGroup->clear();
345 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
348 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
349 // fprintf(ff,"EED wxVtkBaseView_SceneManager::createCopyContourOf() \n" );
350 // int ii,size = _contours_ViewControl->size();
351 // iter = _contours_ViewControl->begin();
352 // for (ii=0;ii<size;ii++)
354 // fprintf(ff," %d %s\n ", ii ,iter->first.c_str() );
359 iter = _contours_ViewControl->find( anExistingKName );
361 manualContourModel *cModule = manualModel;
362 manualViewBaseContour *cViewer = iter->second->getViewer()->Clone();
363 manualContourBaseControler *cControl = iter->second->getControler()->Clone( );
365 cViewer->SetModel(cModule);
366 cControl->SetModelView( cModule , cViewer );
367 cControl->CreateNewManualContour();
368 cControl->SetActive( true );
369 cControl->SetEditable( false );
371 cViewer->RefreshContour();
373 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
374 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
376 _lastInteraction = insertWrap( cloneName, cControl, cViewer );
377 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( cloneName, _lastInteraction ));
378 addToScene( cloneName );
381 //------------------------------------------------------------------------------------------------------------
383 void wxVtkBaseView_SceneManager :: removeFromScene( ContourWrap_ViewControl * contourWRP, bool visualization, bool control )
385 if( contourWRP == _lastInteraction )
387 _lastInteraction = NULL;
388 _lastInteractionName = "";
392 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
393 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeFromScene \n" );
394 //fprintf(ff," %p \n", contourWRP->getControler() );
397 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->RemoveInteractorStyleMaracas( contourWRP->getControler() );
399 contourWRP->getControler()->SetActive( control );
400 contourWRP->getControler()->SetEditable( false );
402 if ( !visualization && control )
404 contourWRP->getViewer()->RemoveControlPoints( );
405 contourWRP->getViewer()->RemoveTextActor( );
409 contourWRP->getViewer()->RemoveCompleteContourActor();
413 //------------------------------------------------------------------------------------------------------------
414 void wxVtkBaseView_SceneManager :: removeFromScene( std::string theKeyName, bool visualization , bool control )
417 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
418 iter = _sceneContours_ViewControl->find( theKeyName );
419 if (iter != _sceneContours_ViewControl->end())
421 ContourWrap_ViewControl * contourWRP = iter->second;
422 removeFromScene( contourWRP );
424 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
425 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeFromScene Bbbbb \n" );
426 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
427 _sceneContours_ViewControl->erase(iter);
430 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
435 //------------------------------------------------------------------------------------------------------------
436 std::vector<std::string> wxVtkBaseView_SceneManager::GetlstContoursNameActualSlice()
438 std::vector<std::string> lstContoursNameActualSlice;
439 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
440 int i,size = _sceneContours_ViewControl->size();
441 for ( i = 0; i<size; i++ )
443 lstContoursNameActualSlice.push_back( iter->first );
446 return lstContoursNameActualSlice;
449 //------------------------------------------------------------------------------------------------------------
450 void wxVtkBaseView_SceneManager :: removeSceneContours( )
453 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
454 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeSceneContours \n" );
455 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
456 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
457 int size = _sceneContours_ViewControl->size();
458 for ( int i = 0; i<size; i++ )
460 removeFromScene( iter->second );
463 _sceneContours_ViewControl->clear();
466 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
469 //Removing the selection rectangle to avoid showing when it's innecesary
470 _controlerSelectionROI->SetActive( false );
471 _viewerSelectionROI->RemoveCompleteContourActor();
474 void wxVtkBaseView_SceneManager::removeAllOutlines()
476 manualViewBaseContour * cViewer;
477 manualContourBaseControler * cControler;
479 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
480 int i,size=_contours_ViewControl->size();
483 iter = _contours_ViewControl->begin();
484 cControler = iter->second->getControler();
485 cViewer = iter->second->getViewer();
486 removeWrap( iter->first );
494 //------------------------------------------------------------------------------------------------------------
495 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
499 removeSceneContours();
501 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
502 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
504 addToScene( theKeyName, contourWRP, true, visualization, control, ifActive, ifShowCtrlPoints);
507 //------------------------------------------------------------------------------------------------------------
508 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
512 removeSceneContours();
514 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
517 contourWRP->getViewer()->AddCompleteContourActor( ifShowCtrlPoints );
522 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( contourWRP->getControler() );
526 contourWRP->getControler()->SetActive( true );
527 contourWRP->getViewer()->RemoveTextActor();
531 //------------------------------------------------------------------------------------------------------------
532 void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
534 int i, size = theKeyNameVector.size();
535 for( i=0; i< size; i++ )
537 removeFromScene( theKeyNameVector[i], visualization, control );
541 //------------------------------------------------------------------------------------------------------------
542 void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
544 int i, size = theKeyNameVector.size();
545 for( i=0; i< size; i++ )
547 addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
551 //------------------------------------------------------------------------------------------------------------
552 void wxVtkBaseView_SceneManager :: setControlActiveStateOfALL( bool stateCondition )
554 setControlActiveStateOf( _contours_ViewControl, stateCondition );
557 //------------------------------------------------------------------------------------------------------------
558 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
560 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
561 setControlActiveStateOf( contourWRP, stateCondition );
564 //------------------------------------------------------------------------------------------------------------
565 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( ContourWrap_ViewControl * contourWRP, bool stateCondition )
567 contourWRP->getControler()->SetActive( stateCondition );
568 contourWRP->getControler()->SetEditable( false );
571 //------------------------------------------------------------------------------------------------------------
572 void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
574 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
575 // contourWRP->getViewer()->SetVisible( stateCondition );
576 if ( contourWRP!=NULL )
577 removeFromScene( contourWRP, false, stateCondition );
580 //------------------------------------------------------------------------------------------------------------
581 std::vector< std::string > wxVtkBaseView_SceneManager :: getSelectedObjects()
583 std::vector< std::string > selectedObjects;
584 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
585 int size = _workingGroup->size();
586 for ( int i = 0; i<size; i++ )
588 //EED??? manualViewBaseContour * viewer = iter->second->getViewer();
589 selectedObjects.push_back( iter->first);
593 return selectedObjects;
595 //------------------------------------------------------------------------------------------------------------
596 void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
598 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
599 //EED??? int size = _contours_ViewControl->size();
600 //EED??? bool selected;
601 /*for ( int i = 0; i<size; i++ )
604 manualViewBaseContour * viewer = iter->second->getViewer();
605 std::vector <std::string >::iterator iterIN;
607 for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
609 if( iter->first.compare( theExistingObjectsToSelect[i] ) )
611 viewer->SelectAllPoints( true );
612 viewer->SelectPosibleContour( true );
614 theExistingObjectsToSelect.erase( iterIN );
622 //------------------------------------------------------------------------------------------------------------
623 void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
625 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
626 int size = _contours_ViewControl->size();
627 for ( int i = 0; i<size; i++ )
629 manualViewBaseContour * viewer = iter->second->getViewer();
631 viewer->SetSelected( true );
632 /*viewer->SelectAllPoints( true );
633 viewer->SelectPosibleContour( true );*/
639 //------------------------------------------------------------------------------------------------------------
640 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
642 int i, size = theKeyNameVector.size();
643 for( i=0; i< size; i++ )
645 setControlActiveStateOf( theKeyNameVector[i], controlCondition );
649 //------------------------------------------------------------------------------------------------------------
650 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
652 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
653 int i, size = theMap->size();
654 for( i=0; i< size; i++ )
656 removeFromScene( iter->second, false, controlCondition );
661 //------------------------------------------------------------------------------------------------------------
663 //------------------------------------------------------------------------------------------------------------
665 //------------------------------------------------------------------------------------------------------------
666 // Creational and initialization methods
667 //------------------------------------------------------------------------------------------------------------
669 //------------------------------------------------------------------------------------------------------------
671 //------------------------------------------------------------------------------------------------------------
673 bool wxVtkBaseView_SceneManager :: isCtrlPressed()
677 bool wxVtkBaseView_SceneManager :: isShiftPressed()
681 char wxVtkBaseView_SceneManager :: getLastKeyCode()
685 bool wxVtkBaseView_SceneManager :: OnChar()
688 _ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
689 _shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
691 _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
693 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
694 _eventHandler->ProcessEvent( cevent );
697 /*if( _eventHandler!=NULL )
699 char * toolCommand = NULL;
701 if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
703 toolCommand = &(COPY_TOOL);
705 else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
707 toolCommand = &(PASTE_TOOL);
709 else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
711 toolCommand = &(DELETE_KEY);
713 else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
715 toolCommand = &(CREATE_CONTOUR_KEY);
717 else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
719 toolCommand = &(OPEN_TOOL);
721 else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
723 toolCommand = &(SAVE_KEY);
726 if ( toolCommand!=NULL )
728 currentkey = toolCommand;
729 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
730 cevent.SetClientData( (void *) toolCommand);
731 _eventHandler->ProcessEvent( cevent );
736 // long int endtime = clock();
740 //------------------------------------------------------------------------------------------------------------
742 bool wxVtkBaseView_SceneManager :: OnMouseMove()
745 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
746 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnMouseMove() \n" );
749 bool condition = true;
751 wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
752 _wxVTKiren->GetEventPosition( X , Y );
754 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
755 //??? bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
757 if( _waiting && !ctrlKey )
759 sendEnvent( wxEVT_CHANGED_DEEP, "Update");
760 //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
763 if ( !_creatingROI && !_creatingMULT_ROI )
766 /*if( ctrlKey || shiftKey )
772 _toIncludeAtInteractionGroup = false;
775 bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
776 std::string preservingName = preserveState ? _lastInteractionName : "";
778 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
779 int i, size = _sceneContours_ViewControl->size();
780 bool foundOne = false;
782 manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
783 manualViewBaseContour * viewer = NULL;
786 bool singleMoving = true;
787 int selectionSize = _workingGroup->size();
788 if( selectionSize > 1 )
792 //EED??? bool ckecking = false;
793 for( i =0; i<size ; i++ )
795 control = iter->second->getControler();
796 viewer = iter->second->getViewer();
797 /*ckecking = */control->SetActive( true );
799 if (_lastInteraction != NULL)
801 singleMoving = !_lastInteraction->getViewer()->GetSelected();
806 size = selectionSize;
807 iter = _workingGroup->begin();
813 _toIncludeAtInteractionGroup = false;
816 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
819 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
820 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnMouseMove() 00222\n" );
822 _lastInteraction=NULL;
823 for( i =0; i<size ; i++ )
825 control = iter->second->getControler();
826 viewer = iter->second->getViewer();
827 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
828 control->SetActive( true );
830 foundOne = control->OnMouseMove();
831 foundOne &= viewer->GetPosibleSelected();
833 if ( !foundOne && singleMoving )
835 control->SetActive( false );
836 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
837 control->SetPosibleToMove( false );
841 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
843 _lastInteraction->getControler()->SetActive( true );
846 _lastInteraction = iter->second;
847 _lastInteractionName = iter->first;
849 viewer->UpdateColorActor();
850 control->SetPosibleToMove( true );
851 // viewer->AddCompleteContourActor();
866 //------------------------------------------------------------------------------------------------------------
867 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
871 ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
872 long int endtime = clock();
873 // double sg = (double)(endtime-startTimeAE) / (double)CLK_TCK;
874 fprintf(ff,"wxVtkBaseView_SceneManager :: OnLeftButtonDown() tLBDown = %i \n \n",endtime);
878 //EED??? char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
879 bool condition = false;
880 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
881 //EED??? vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
882 //EED??? wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
883 //EED?? wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
884 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
886 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
887 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
888 _toIncludeAtInteractionGroup = false;
889 if ( ctrlKey || shftKey )
891 _toIncludeAtInteractionGroup = true;
895 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
897 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
899 _lastInteraction->getControler()->SetEditable( false );
900 _lastInteraction->getControler()->SetActive( false );
901 _lastInteraction->getControler()->SetPosibleToMove( false );
902 _lastInteraction->getViewer()->Refresh();
903 _lastInteraction=NULL;
910 if( !_toIncludeAtInteractionGroup )
912 _workingGroup->clear();
915 if( _lastInteraction!=NULL )
917 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
918 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
919 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
921 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
924 //setControlActiveStateOf( _contours_ViewControl, false );
925 sendEnvent( wxEVT_START_CREATE_ROI, "");
929 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
930 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
931 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
938 //------------------------------------------------------------------------------------------------------------
939 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
941 bool condition = false;
944 if( _drawingSelectionROI )
946 setSelection2DROIInternalOutlines();
950 //------------------------------------------------------------------------------------------------------------
951 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
953 bool condition = false;
958 //------------------------------------------------------------------------------------------------------------
959 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
961 bool condition = false;
966 //------------------------------------------------------------------------------------------------------------
967 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
969 bool condition = false;
970 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
971 //EED??? bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
978 //------------------------------------------------------------------------------------------------------------
979 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
981 bool condition = false;
983 //setControlActiveStateOfALL( false );//************************************************
984 if ( _creatingMULT_ROI )
986 //setControlActiveStateOfALL( false );
990 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
991 _creatingROI = false;
995 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
997 manualContourBaseControler * control = _lastInteraction->getControler();
998 //_lastInteraction->getControler()->SetPosibleToMove( false );
999 control->SetActive( false );
1000 control->SetEditable( false );
1001 control->SetPosibleToMove( false );
1002 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
1003 _lastInteraction->getViewer()->Refresh();
1004 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1010 //------------------------------------------------------------------------------------------------------------
1012 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
1014 bool condition = false;
1019 //------------------------------------------------------------------------------------------------------------
1020 bool wxVtkBaseView_SceneManager :: OnRightDClick()
1022 bool condition = false; condition = true;
1023 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
1024 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
1025 //EED??? wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
1029 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
1030 set_creatingMULT_ROI( !_creatingMULT_ROI );
1038 //------------------------------------------------------------------------------------------------------------
1039 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
1041 bool condition = false;
1046 //------------------------------------------------------------------------------------------------------------
1047 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
1049 bool condition = false;
1053 //------------------------------------------------------------------------------------------------------------
1055 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1057 _drawingSelectionROI = true;
1058 _workingGroup->clear();
1059 _controlerSelectionROI->CreateNewManualContour();
1060 if (_lastInteraction!=NULL)
1062 _lastInteraction->getControler()->SetEditable( false );
1063 _lastInteraction->getControler()->SetActive( false );
1064 _lastInteraction->getControler()->SetPosibleToMove( false );
1065 _lastInteraction->getViewer()->Refresh();
1067 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1068 int i, workSize = _workingGroup->size();
1069 for( i=0; i< workSize; i++ )
1071 manualContourBaseControler * control = iter->second->getControler();
1072 control->SetEditable( false );
1073 control->SetActive( false );
1074 control->SetPosibleToMove( false );
1075 iter->second->getViewer()->Refresh();
1079 _lastInteraction = NULL;
1080 _lastInteractionName = "";
1082 _viewerSelectionROI->AddCompleteContourActor( true );
1083 _controlerSelectionROI->SetActive( true );
1085 _viewerSelectionROI->RefreshContour();
1086 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1088 //------------------------------------------------------------------------------------------------------------
1089 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1091 _drawingSelectionROI = false;
1092 _workingGroup->clear();
1093 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1096 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1097 int i, size = _sceneContours_ViewControl->size();
1098 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1099 manualViewBaseContour * viewer;
1100 bool insideRoi = false;
1101 for ( i=0; i<size; i++ )
1103 viewer = iter->second->getViewer();
1104 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1105 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1108 viewer->SetSelected( true );
1109 viewer->UpdateColorActor();
1110 setControlActiveStateOf( iter->second, true );
1111 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1115 _viewerSelectionROI->RemoveCompleteContourActor( );
1116 _controlerSelectionROI->SetActive( false );
1118 //------------------------------------------------------------------------------------------------------------
1119 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1121 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1122 long int start = clock();
1124 double sg = (double)(start) / (double)CLK_TCK;
1126 double sg = (double)(start) / CLOCKS_PER_SEC;
1129 wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1130 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1131 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): %f\n \n",method.c_str(), tmpPx, tmpPy, sg);
1136 //------------------------------------------------------------------------------------------------------------
1137 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1139 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1140 manualViewBaseContour * cViewer;
1141 manualContourBaseControler * cControler;
1142 ContourWrap_ViewControl *conwraviwcont=iter->second;
1144 cViewer = conwraviwcont->getViewer();
1147 cControler = conwraviwcont->getControler();
1148 // cControler->Save(ff);
1150 // cModel = cControler->GetManualContourModel();
1151 // cModel->Save(ff);
1155 //------------------------------------------------------------------------------------------------------------
1156 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1158 std::vector<std::string> currentSelection = this->getSelectedObjects();
1159 if (currentSelection.size()>=1){
1161 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1162 manualContourModel *cModel = cControler->GetManualContourModel();
1163 int i,size = cModel->GetNumberOfPointsSpline();
1165 for (i=0; i<size; i++)
1167 cModel->GetSpline_i_Point(i, &x, &y, &z);
1175 //------------------------------------------------------------------------------------------------------------
1176 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1178 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1179 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1182 //------------------------------------------------------------------------------------------------------------
1183 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1186 vtkImageData *imagedata = GetImageData();
1187 imagedata->GetExtent(ext);
1188 int sizeZ = ext[5]-ext[4]+1;
1196 //------------------------------------------------------------------------------------------------------------
1197 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1200 vtkImageData *imagedata = GetImageData();
1201 imagedata->GetExtent(ext);
1202 int sizeX = ext[1]-ext[0]+1;
1203 int sizeY = ext[3]-ext[2]+1;
1204 int sizeZ = GetImageDataSizeZ();
1205 int sizeXYZ = sizeX*sizeY*sizeZ;
1209 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1210 for (i=0;i<sizeXYZ;i++)
1212 if ( p[i]<range[0] ) range[0]=p[i];
1213 if ( p[i]>range[1] ) range[1]=p[i];
1217 //------------------------------------------------------------------------------------------------------------
1218 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1220 _widthOfContour = width;
1221 manualViewBaseContour *cViewer;
1222 ContourWrap_ViewControl *conwraviwcont;
1223 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;;
1225 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1227 conwraviwcont = iter->second;
1228 cViewer = conwraviwcont->getViewer();
1229 cViewer->SetWidthLine(_widthOfContour);
1233 bool wxVtkBaseView_SceneManager::isEditableCControler(std::string theKeyName){
1235 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1237 manualContourBaseControler* cControler = ccon->getControler();
1238 if(cControler != NULL && cControler->IsEditable() == false){
1245 void wxVtkBaseView_SceneManager::deleteCViewerCControler(std::string theKeyName){
1248 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1250 manualViewBaseContour * cViewer = ccon->getViewer();
1251 manualContourBaseControler * cControler = ccon->getControler();
1253 removeFromScene(theKeyName);
1254 removeWrap(theKeyName);