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 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
178 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: configureViewControlTo \n" );
179 //fprintf(ff," %s %p \n",theKeyName.c_str() , manContourControl );
183 _lastInteraction = insertWrap( theKeyName, manContourControl, manViewerContour );
184 _lastInteractionName = theKeyName;
186 //Configuring the relations between the contour members representation
187 manViewerContour->SetModel( manModelContour );
188 manViewerContour->SetWxVtkBaseView( _wxVtk_BaseView );
189 manViewerContour->SetRange( 2 );
190 manViewerContour->SetZ( 1000 );
192 manViewerContour->SetSpacing(spc);
194 manViewerContour->SetColorNormalContour(0, 0, 1);
195 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
196 manViewerContour->SetColorSelectContour(1, 0.8, 0);
197 manViewerContour->SetWidthLine(_widthOfContour);
199 manContourControl->SetModelView( manModelContour , manViewerContour );
200 manContourControl->Configure();
201 int i,sizeLstPoints = manModelContour->GetSizeLstPoints();
202 for ( i=0; i<sizeLstPoints; i++ )
204 manViewerContour->AddPoint();
207 manContourControl->CreateNewManualContour();
208 manViewerContour->RefreshContour();
209 addToScene( theKeyName );
211 //------------------------------------------------------------------------------------------------------------
212 void wxVtkBaseView_SceneManager :: configureSelectionROI( double * spc )
214 _controlerSelectionROI = new manualRoiControler();
215 _viewerSelectionROI = new manualViewRoi();
216 _modelSelectionROI = new manualContourModel();
218 _viewerSelectionROI->SetModel( _modelSelectionROI );
219 _viewerSelectionROI->SetWxVtkBaseView( _wxVtk_BaseView );
220 _viewerSelectionROI->SetRange( 2 );
221 _viewerSelectionROI->SetZ( 1000 );
222 _viewerSelectionROI->SetColorNormalContour(0.6, 0.8, 0);
224 _viewerSelectionROI->SetSpacing( spc );
226 _controlerSelectionROI->SetModelView( _modelSelectionROI , _viewerSelectionROI );
227 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _controlerSelectionROI );
228 _controlerSelectionROI->SetActive(false);
231 //------------------------------------------------------------------------------------------------------------
232 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: insertWrap( std::string theKeyName, manualContourBaseControler * manContourControl, manualViewBaseContour * manViewerContour )
234 ContourWrap_ViewControl * newContourWrap = new ContourWrap_ViewControl(manContourControl, manViewerContour);
235 _contours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, newContourWrap ));
236 return newContourWrap;
238 //------------------------------------------------------------------------------------------------------------
239 void wxVtkBaseView_SceneManager :: desconfigureViewControlOf( std::string theKeyName )
243 //------------------------------------------------------------------------------------------------------------
244 void wxVtkBaseView_SceneManager :: removeWrap( std::string theKeyName )
246 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
247 iter = _contours_ViewControl->find( theKeyName );
248 _contours_ViewControl->erase( iter );
249 _lastInteraction=NULL;
250 _lastInteractionName = "";
251 _workingGroup->clear();
252 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
253 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
255 //------------------------------------------------------------------------------------------------------------
256 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName )
258 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
259 iter = _contours_ViewControl->find( theName );
261 //return iter->first;
263 //------------------------------------------------------------------------------------------------------------
264 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName, std::map<std::string, ContourWrap_ViewControl *> * theMap )
266 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
267 iter = theMap->find( theName );
270 //------------------------------------------------------------------------------------------------------------
271 manualContourBaseControler * wxVtkBaseView_SceneManager :: getControlerOf( std::string theName )
273 return getContourWrap_ViewControlOf ( theName )->getControler();
275 //------------------------------------------------------------------------------------------------------------
276 manualViewBaseContour * wxVtkBaseView_SceneManager :: getViewerOf( std::string theName )
278 return getContourWrap_ViewControlOf ( theName )->getViewer();
280 //------------------------------------------------------------------------------------------------------------
281 void wxVtkBaseView_SceneManager :: set_creatingMULT_ROI( bool condition )
283 _creatingMULT_ROI = condition;
285 //------------------------------------------------------------------------------------------------------------
286 void wxVtkBaseView_SceneManager :: set_editingROI( bool condition )
288 _editingROI = condition;
290 //------------------------------------------------------------------------------------------------------------
291 void wxVtkBaseView_SceneManager :: set_toIncludeAtInteractionGroup( bool condition )
293 _toIncludeAtInteractionGroup = condition;
295 //------------------------------------------------------------------------------------------------------------
296 void wxVtkBaseView_SceneManager :: set_waiting( bool condition )
298 _waiting = condition;
300 //------------------------------------------------------------------------------------------------------------
301 bool wxVtkBaseView_SceneManager :: get_creatingMULT_ROI( )
303 return _creatingMULT_ROI;
305 //------------------------------------------------------------------------------------------------------------
306 bool wxVtkBaseView_SceneManager :: get_editingROI( )
310 //------------------------------------------------------------------------------------------------------------
311 bool wxVtkBaseView_SceneManager :: get_toIncludeAtInteractionGroup( )
313 return _toIncludeAtInteractionGroup;
316 //------------------------------------------------------------------------------------------------------------
317 bool wxVtkBaseView_SceneManager :: get_waiting( )
322 //------------------------------------------------------------------------------------------------------------
323 bool wxVtkBaseView_SceneManager :: get_creatingROI()
327 //------------------------------------------------------------------------------------------------------------
328 void wxVtkBaseView_SceneManager :: set_creatingROI( bool condition )
330 _creatingROI = condition;
333 //------------------------------------------------------------------------------------------------------------
334 // Other functional methods
335 //------------------------------------------------------------------------------------------------------------
337 void wxVtkBaseView_SceneManager :: createCopyContourOf( std::string anExistingKName, std::string cloneName, manualContourModel * manualModel, bool append )
341 setControlActiveStateOf( _workingGroup, false );
342 _workingGroup->clear();
344 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
347 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
348 // fprintf(ff,"EED wxVtkBaseView_SceneManager::createCopyContourOf() \n" );
349 // int ii,size = _contours_ViewControl->size();
350 // iter = _contours_ViewControl->begin();
351 // for (ii=0;ii<size;ii++)
353 // fprintf(ff," %d %s\n ", ii ,iter->first.c_str() );
358 iter = _contours_ViewControl->find( anExistingKName );
360 manualContourModel *cModule = manualModel;
361 manualViewBaseContour *cViewer = iter->second->getViewer()->Clone();
362 manualContourBaseControler *cControl = iter->second->getControler()->Clone( );
364 cViewer->SetModel(cModule);
365 cControl->SetModelView( cModule , cViewer );
366 cControl->CreateNewManualContour();
367 cControl->SetActive( true );
368 cControl->SetEditable( false );
370 cViewer->RefreshContour();
372 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
373 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
375 _lastInteraction = insertWrap( cloneName, cControl, cViewer );
376 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( cloneName, _lastInteraction ));
377 addToScene( cloneName );
380 //------------------------------------------------------------------------------------------------------------
382 void wxVtkBaseView_SceneManager :: removeFromScene( ContourWrap_ViewControl * contourWRP, bool visualization, bool control )
384 if( contourWRP == _lastInteraction )
386 _lastInteraction = NULL;
387 _lastInteractionName = "";
391 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
392 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeFromScene \n" );
393 //fprintf(ff," %p \n", contourWRP->getControler() );
396 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->RemoveInteractorStyleMaracas( contourWRP->getControler() );
398 contourWRP->getControler()->SetActive( control );
399 contourWRP->getControler()->SetEditable( false );
401 if ( !visualization && control )
403 contourWRP->getViewer()->RemoveControlPoints( );
404 contourWRP->getViewer()->RemoveTextActor( );
408 contourWRP->getViewer()->RemoveCompleteContourActor();
412 //------------------------------------------------------------------------------------------------------------
413 void wxVtkBaseView_SceneManager :: removeFromScene( std::string theKeyName, bool visualization , bool control )
416 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
417 iter = _sceneContours_ViewControl->find( theKeyName );
418 if (iter != _sceneContours_ViewControl->end())
420 ContourWrap_ViewControl * contourWRP = iter->second;
421 removeFromScene( contourWRP );
423 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
424 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeFromScene Bbbbb \n" );
425 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
426 _sceneContours_ViewControl->erase(iter);
429 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
434 //------------------------------------------------------------------------------------------------------------
435 std::vector<std::string> wxVtkBaseView_SceneManager::GetlstContoursNameActualSlice()
437 std::vector<std::string> lstContoursNameActualSlice;
438 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
439 int i,size = _sceneContours_ViewControl->size();
440 for ( i = 0; i<size; i++ )
442 lstContoursNameActualSlice.push_back( iter->first );
445 return lstContoursNameActualSlice;
448 //------------------------------------------------------------------------------------------------------------
449 void wxVtkBaseView_SceneManager :: removeSceneContours( )
452 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
453 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeSceneContours \n" );
454 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
455 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
456 int size = _sceneContours_ViewControl->size();
457 for ( int i = 0; i<size; i++ )
459 removeFromScene( iter->second );
462 _sceneContours_ViewControl->clear();
465 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
468 //Removing the selection rectangle to avoid showing when it's innecesary
469 _controlerSelectionROI->SetActive( false );
470 _viewerSelectionROI->RemoveCompleteContourActor();
473 void wxVtkBaseView_SceneManager::removeAllOutlines()
475 manualViewBaseContour * cViewer;
476 manualContourBaseControler * cControler;
478 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
479 int i,size=_contours_ViewControl->size();
482 iter = _contours_ViewControl->begin();
483 cControler = iter->second->getControler();
484 cViewer = iter->second->getViewer();
485 removeWrap( iter->first );
493 //------------------------------------------------------------------------------------------------------------
494 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
498 removeSceneContours();
500 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
501 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
503 addToScene( theKeyName, contourWRP, true, visualization, control, ifActive, ifShowCtrlPoints);
506 //------------------------------------------------------------------------------------------------------------
507 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
511 removeSceneContours();
513 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
516 contourWRP->getViewer()->AddCompleteContourActor( ifShowCtrlPoints );
521 ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( contourWRP->getControler() );
525 contourWRP->getControler()->SetActive( true );
526 contourWRP->getViewer()->RemoveTextActor();
530 //------------------------------------------------------------------------------------------------------------
531 void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
533 int i, size = theKeyNameVector.size();
534 for( i=0; i< size; i++ )
536 removeFromScene( theKeyNameVector[i], visualization, control );
540 //------------------------------------------------------------------------------------------------------------
541 void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
543 int i, size = theKeyNameVector.size();
544 for( i=0; i< size; i++ )
546 addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
550 //------------------------------------------------------------------------------------------------------------
551 void wxVtkBaseView_SceneManager :: setControlActiveStateOfALL( bool stateCondition )
553 setControlActiveStateOf( _contours_ViewControl, stateCondition );
556 //------------------------------------------------------------------------------------------------------------
557 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
559 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
560 setControlActiveStateOf( contourWRP, stateCondition );
563 //------------------------------------------------------------------------------------------------------------
564 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( ContourWrap_ViewControl * contourWRP, bool stateCondition )
566 contourWRP->getControler()->SetActive( stateCondition );
567 contourWRP->getControler()->SetEditable( false );
570 //------------------------------------------------------------------------------------------------------------
571 void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
573 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
574 // contourWRP->getViewer()->SetVisible( stateCondition );
575 if ( contourWRP!=NULL )
576 removeFromScene( contourWRP, false, stateCondition );
579 //------------------------------------------------------------------------------------------------------------
580 std::vector< std::string > wxVtkBaseView_SceneManager :: getSelectedObjects()
582 std::vector< std::string > selectedObjects;
583 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
584 int size = _workingGroup->size();
585 for ( int i = 0; i<size; i++ )
587 //EED??? manualViewBaseContour * viewer = iter->second->getViewer();
588 selectedObjects.push_back( iter->first);
592 return selectedObjects;
594 //------------------------------------------------------------------------------------------------------------
595 void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
597 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
598 //EED??? int size = _contours_ViewControl->size();
599 //EED??? bool selected;
600 /*for ( int i = 0; i<size; i++ )
603 manualViewBaseContour * viewer = iter->second->getViewer();
604 std::vector <std::string >::iterator iterIN;
606 for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
608 if( iter->first.compare( theExistingObjectsToSelect[i] ) )
610 viewer->SelectAllPoints( true );
611 viewer->SelectPosibleContour( true );
613 theExistingObjectsToSelect.erase( iterIN );
621 //------------------------------------------------------------------------------------------------------------
622 void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
624 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
625 int size = _contours_ViewControl->size();
626 for ( int i = 0; i<size; i++ )
628 manualViewBaseContour * viewer = iter->second->getViewer();
630 viewer->SetSelected( true );
631 /*viewer->SelectAllPoints( true );
632 viewer->SelectPosibleContour( true );*/
638 //------------------------------------------------------------------------------------------------------------
639 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
641 int i, size = theKeyNameVector.size();
642 for( i=0; i< size; i++ )
644 setControlActiveStateOf( theKeyNameVector[i], controlCondition );
648 //------------------------------------------------------------------------------------------------------------
649 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
651 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
652 int i, size = theMap->size();
653 for( i=0; i< size; i++ )
655 removeFromScene( iter->second, false, controlCondition );
660 //------------------------------------------------------------------------------------------------------------
662 //------------------------------------------------------------------------------------------------------------
664 //------------------------------------------------------------------------------------------------------------
665 // Creational and initialization methods
666 //------------------------------------------------------------------------------------------------------------
668 //------------------------------------------------------------------------------------------------------------
670 //------------------------------------------------------------------------------------------------------------
672 bool wxVtkBaseView_SceneManager :: isCtrlPressed()
676 bool wxVtkBaseView_SceneManager :: isShiftPressed()
680 char wxVtkBaseView_SceneManager :: getLastKeyCode()
684 bool wxVtkBaseView_SceneManager :: OnChar()
687 _ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
688 _shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
690 _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
692 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
693 _eventHandler->ProcessEvent( cevent );
696 /*if( _eventHandler!=NULL )
698 char * toolCommand = NULL;
700 if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
702 toolCommand = &(COPY_TOOL);
704 else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
706 toolCommand = &(PASTE_TOOL);
708 else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
710 toolCommand = &(DELETE_KEY);
712 else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
714 toolCommand = &(CREATE_CONTOUR_KEY);
716 else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
718 toolCommand = &(OPEN_TOOL);
720 else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
722 toolCommand = &(SAVE_KEY);
725 if ( toolCommand!=NULL )
727 currentkey = toolCommand;
728 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
729 cevent.SetClientData( (void *) toolCommand);
730 _eventHandler->ProcessEvent( cevent );
735 // long int endtime = clock();
739 //------------------------------------------------------------------------------------------------------------
741 bool wxVtkBaseView_SceneManager :: OnMouseMove()
744 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
745 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnMouseMove() \n" );
748 bool condition = true;
750 wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
751 _wxVTKiren->GetEventPosition( X , Y );
753 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
754 //??? bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
756 if( _waiting && !ctrlKey )
758 sendEnvent( wxEVT_CHANGED_DEEP, "Update");
759 //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
762 if ( !_creatingROI && !_creatingMULT_ROI )
765 /*if( ctrlKey || shiftKey )
771 _toIncludeAtInteractionGroup = false;
774 bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
775 std::string preservingName = preserveState ? _lastInteractionName : "";
777 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
778 int i, size = _sceneContours_ViewControl->size();
779 bool foundOne = false;
781 manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
782 manualViewBaseContour * viewer = NULL;
785 bool singleMoving = true;
786 int selectionSize = _workingGroup->size();
787 if( selectionSize > 1 )
791 //EED??? bool ckecking = false;
792 for( i =0; i<size ; i++ )
794 control = iter->second->getControler();
795 viewer = iter->second->getViewer();
796 /*ckecking = */control->SetActive( true );
798 if (_lastInteraction != NULL)
800 singleMoving = !_lastInteraction->getViewer()->GetSelected();
805 size = selectionSize;
806 iter = _workingGroup->begin();
812 _toIncludeAtInteractionGroup = false;
815 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
818 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
819 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnMouseMove() 00222\n" );
821 _lastInteraction=NULL;
822 for( i =0; i<size ; i++ )
824 control = iter->second->getControler();
825 viewer = iter->second->getViewer();
826 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
827 control->SetActive( true );
829 foundOne = control->OnMouseMove();
830 foundOne &= viewer->GetPosibleSelected();
832 if ( !foundOne && singleMoving )
834 control->SetActive( false );
835 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
836 control->SetPosibleToMove( false );
840 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
842 _lastInteraction->getControler()->SetActive( true );
845 _lastInteraction = iter->second;
846 _lastInteractionName = iter->first;
848 viewer->UpdateColorActor();
849 control->SetPosibleToMove( true );
850 // viewer->AddCompleteContourActor();
865 //------------------------------------------------------------------------------------------------------------
866 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
870 ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
871 long int endtime = clock();
872 // double sg = (double)(endtime-startTimeAE) / (double)CLK_TCK;
873 fprintf(ff,"wxVtkBaseView_SceneManager :: OnLeftButtonDown() tLBDown = %i \n \n",endtime);
877 //EED??? char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
878 bool condition = false;
879 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
880 //EED??? vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
881 //EED??? wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
882 //EED?? wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
883 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
885 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
886 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
887 _toIncludeAtInteractionGroup = false;
888 if ( ctrlKey || shftKey )
890 _toIncludeAtInteractionGroup = true;
894 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
896 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
898 _lastInteraction->getControler()->SetEditable( false );
899 _lastInteraction->getControler()->SetActive( false );
900 _lastInteraction->getControler()->SetPosibleToMove( false );
901 _lastInteraction->getViewer()->Refresh();
902 _lastInteraction=NULL;
909 if( !_toIncludeAtInteractionGroup )
911 _workingGroup->clear();
914 if( _lastInteraction!=NULL )
916 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
917 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
918 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
920 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
923 //setControlActiveStateOf( _contours_ViewControl, false );
924 sendEnvent( wxEVT_START_CREATE_ROI, "");
928 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
929 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
930 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
937 //------------------------------------------------------------------------------------------------------------
938 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
940 bool condition = false;
943 if( _drawingSelectionROI )
945 setSelection2DROIInternalOutlines();
949 //------------------------------------------------------------------------------------------------------------
950 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
952 bool condition = false;
957 //------------------------------------------------------------------------------------------------------------
958 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
960 bool condition = false;
965 //------------------------------------------------------------------------------------------------------------
966 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
968 bool condition = false;
969 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
970 //EED??? bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
977 //------------------------------------------------------------------------------------------------------------
978 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
980 bool condition = false;
982 //setControlActiveStateOfALL( false );//************************************************
983 if ( _creatingMULT_ROI )
985 //setControlActiveStateOfALL( false );
989 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
990 _creatingROI = false;
994 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
996 manualContourBaseControler * control = _lastInteraction->getControler();
997 //_lastInteraction->getControler()->SetPosibleToMove( false );
998 control->SetActive( false );
999 control->SetEditable( false );
1000 control->SetPosibleToMove( false );
1001 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
1002 _lastInteraction->getViewer()->Refresh();
1003 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1009 //------------------------------------------------------------------------------------------------------------
1011 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
1013 bool condition = false;
1018 //------------------------------------------------------------------------------------------------------------
1019 bool wxVtkBaseView_SceneManager :: OnRightDClick()
1021 bool condition = false; condition = true;
1022 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
1023 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
1024 //EED??? wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
1028 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
1029 set_creatingMULT_ROI( !_creatingMULT_ROI );
1037 //------------------------------------------------------------------------------------------------------------
1038 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
1040 bool condition = false;
1045 //------------------------------------------------------------------------------------------------------------
1046 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
1048 bool condition = false;
1052 //------------------------------------------------------------------------------------------------------------
1054 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1056 _drawingSelectionROI = true;
1057 _workingGroup->clear();
1058 _controlerSelectionROI->CreateNewManualContour();
1059 if (_lastInteraction!=NULL)
1061 _lastInteraction->getControler()->SetEditable( false );
1062 _lastInteraction->getControler()->SetActive( false );
1063 _lastInteraction->getControler()->SetPosibleToMove( false );
1064 _lastInteraction->getViewer()->Refresh();
1066 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1067 int i, workSize = _workingGroup->size();
1068 for( i=0; i< workSize; i++ )
1070 manualContourBaseControler * control = iter->second->getControler();
1071 control->SetEditable( false );
1072 control->SetActive( false );
1073 control->SetPosibleToMove( false );
1074 iter->second->getViewer()->Refresh();
1078 _lastInteraction = NULL;
1079 _lastInteractionName = "";
1081 _viewerSelectionROI->AddCompleteContourActor( true );
1082 _controlerSelectionROI->SetActive( true );
1084 _viewerSelectionROI->RefreshContour();
1085 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1087 //------------------------------------------------------------------------------------------------------------
1088 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1090 _drawingSelectionROI = false;
1091 _workingGroup->clear();
1092 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1095 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1096 int i, size = _sceneContours_ViewControl->size();
1097 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1098 manualViewBaseContour * viewer;
1099 bool insideRoi = false;
1100 for ( i=0; i<size; i++ )
1102 viewer = iter->second->getViewer();
1103 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1104 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1107 viewer->SetSelected( true );
1108 viewer->UpdateColorActor();
1109 setControlActiveStateOf( iter->second, true );
1110 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1114 _viewerSelectionROI->RemoveCompleteContourActor( );
1115 _controlerSelectionROI->SetActive( false );
1117 //------------------------------------------------------------------------------------------------------------
1118 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1120 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1121 long int start = clock();
1123 double sg = (double)(start) / (double)CLK_TCK;
1125 double sg = (double)(start) / CLOCKS_PER_SEC;
1128 wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1129 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1130 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): %f\n \n",method.c_str(), tmpPx, tmpPy, sg);
1135 //------------------------------------------------------------------------------------------------------------
1136 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1138 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1139 manualViewBaseContour * cViewer;
1140 manualContourBaseControler * cControler;
1141 ContourWrap_ViewControl *conwraviwcont=iter->second;
1143 cViewer = conwraviwcont->getViewer();
1146 cControler = conwraviwcont->getControler();
1147 // cControler->Save(ff);
1149 // cModel = cControler->GetManualContourModel();
1150 // cModel->Save(ff);
1154 //------------------------------------------------------------------------------------------------------------
1155 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1157 std::vector<std::string> currentSelection = this->getSelectedObjects();
1158 if (currentSelection.size()>=1){
1160 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1161 manualContourModel *cModel = cControler->GetManualContourModel();
1162 int i,size = cModel->GetNumberOfPointsSpline();
1164 for (i=0; i<size; i++)
1166 cModel->GetSpline_i_Point(i, &x, &y, &z);
1174 //------------------------------------------------------------------------------------------------------------
1175 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1177 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1178 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1181 //------------------------------------------------------------------------------------------------------------
1182 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1185 vtkImageData *imagedata = GetImageData();
1186 imagedata->GetExtent(ext);
1187 int sizeZ = ext[5]-ext[4]+1;
1195 //------------------------------------------------------------------------------------------------------------
1196 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1199 vtkImageData *imagedata = GetImageData();
1200 imagedata->GetExtent(ext);
1201 int sizeX = ext[1]-ext[0]+1;
1202 int sizeY = ext[3]-ext[2]+1;
1203 int sizeZ = GetImageDataSizeZ();
1204 int sizeXYZ = sizeX*sizeY*sizeZ;
1208 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1209 for (i=0;i<sizeXYZ;i++)
1211 if ( p[i]<range[0] ) range[0]=p[i];
1212 if ( p[i]>range[1] ) range[1]=p[i];
1216 //------------------------------------------------------------------------------------------------------------
1217 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1219 _widthOfContour = width;
1220 manualViewBaseContour *cViewer;
1221 ContourWrap_ViewControl *conwraviwcont;
1222 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;;
1224 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1226 conwraviwcont = iter->second;
1227 cViewer = conwraviwcont->getViewer();
1228 cViewer->SetWidthLine(_widthOfContour);
1232 bool wxVtkBaseView_SceneManager::isEditableCControler(std::string theKeyName){
1234 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1236 manualContourBaseControler* cControler = ccon->getControler();
1237 if(cControler != NULL && cControler->IsEditable() == false){
1244 void wxVtkBaseView_SceneManager::deleteCViewerCControler(std::string theKeyName){
1247 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1249 manualViewBaseContour * cViewer = ccon->getViewer();
1250 manualContourBaseControler * cControler = ccon->getControler();
1252 removeFromScene(theKeyName);
1253 removeWrap(theKeyName);