2 //----------------------------------------------------------------------------------------------------------------
3 // Class definition include
4 //----------------------------------------------------------------------------------------------------------------
5 #include "wxVtkBaseView_SceneManager.h"
7 //----------------------------------------------------------------------------------------------------------------
8 // Class implementation
9 //----------------------------------------------------------------------------------------------------------------
10 /** @file wxVtkBaseView_SceneManager.cxx */
13 //------------------------------------------------------------------------------------------------------------
15 //------------------------------------------------------------------------------------------------------------
16 #include "wxContour_ActionCommandsID.h"
18 //------------------------------------------------------------------------------------------------------------
19 // Generated events declaration and definition
20 //------------------------------------------------------------------------------------------------------------
22 DEFINE_EVENT_TYPE( wxEVT_START_CREATE_MULT_ROI )
23 DEFINE_EVENT_TYPE( wxEVT_STOP_CREATE_MULT_ROI )
24 DEFINE_EVENT_TYPE( wxEVT_START_CREATE_ROI )
25 DEFINE_EVENT_TYPE( wxEVT_STOP_CREATE_ROI )
26 DEFINE_EVENT_TYPE( wxEVT_DELETE_ROI )
27 DEFINE_EVENT_TYPE( wxEVT_SELECTED_MULT_ROI )
28 DEFINE_EVENT_TYPE( wxEVT_SELECTED_ROI )
29 DEFINE_EVENT_TYPE( wxEVT_UNSLECTED_ROI )
30 DEFINE_EVENT_TYPE( wxEVT_MANUAL_HIDED_ROI )
31 DEFINE_EVENT_TYPE( wxEVT_MANUAL_SHOWED_ROI )
32 DEFINE_EVENT_TYPE( wxEVT_EDITING_ROI )
33 DEFINE_EVENT_TYPE( wxEVT_MOVING_ROI )
34 DEFINE_EVENT_TYPE( wxEVT_MOVING_ROI_POINT )
35 DEFINE_EVENT_TYPE( wxEVT_SELECTED_ROI_POINT )
36 DEFINE_EVENT_TYPE( wxEVT_UNSELECTED_ROI_POINT )
37 DEFINE_EVENT_TYPE( wxEVT_CHANGED_DEEP )
40 wxVtkBaseView_SceneManager :: wxVtkBaseView_SceneManager( wxVtkBaseView * theWxBaseViewToManage, wxEvtHandler * theEventHandler, double * spc )
42 _widthOfContour = 1.0;
43 _lastInteraction = NULL;
44 _lastInteractionName = "";
45 _eventHandler = theEventHandler;
49 _contours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
50 _sceneContours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
51 _workingGroup = new std::map< std::string, ContourWrap_ViewControl * >();
53 _creatingMULT_ROI = false;
55 _toIncludeAtInteractionGroup = false;
58 _drawingSelectionROI = false;
60 _wxVtk_BaseView = theWxBaseViewToManage;
61 if( _wxVtk_BaseView!=NULL )
63 vtkInteractorStyleBaseView* theInteractorStyleBaseView = _wxVtk_BaseView->GetInteractorStyleBaseView();
64 theInteractorStyleBaseView->AddInteractorStyleMaracas( this );
65 SetVtkInteractorStyleBaseView( theInteractorStyleBaseView );
67 configureSelectionROI( spc );
69 //------------------------------------------------------------------------------------------------------------
70 wxVtkBaseView_SceneManager :: ~wxVtkBaseView_SceneManager()
72 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
73 int size = _contours_ViewControl->size();
74 for ( int i = 0; i<size; iter++ )
76 _contours_ViewControl->erase( iter );
79 delete _contours_ViewControl;
80 _contours_ViewControl->clear();
81 _workingGroup->clear();
82 delete _lastInteraction;
84 delete _contours_ViewControl;
87 //------------------------------------------------------------------------------------------------------------
88 // Methods for capturing events
89 //------------------------------------------------------------------------------------------------------------
92 //------------------------------------------------------------------------------------------------------------
93 // Methods for sending events
94 //------------------------------------------------------------------------------------------------------------
95 void wxVtkBaseView_SceneManager :: sendEnvent( WXTYPE theEventType, std::string text )
97 if ( _eventHandler != NULL )
99 wxCommandEvent cevent( theEventType );
100 cevent.SetString( wxString( text.c_str(), wxConvUTF8) );
101 _eventHandler->ProcessEvent( cevent );
106 //------------------------------------------------------------------------------------------------------------
107 // Attributes getters and setters
108 //------------------------------------------------------------------------------------------------------------
109 void wxVtkBaseView_SceneManager :: setWxEventHandler( wxEvtHandler * theEventHandler )
111 _eventHandler = theEventHandler;
113 //------------------------------------------------------------------------------------------------------------
114 void wxVtkBaseView_SceneManager :: setWxVtkViewBase( wxVtkBaseView * theBaseView )
116 _wxVtk_BaseView = theBaseView;
119 //------------------------------------------------------------------------------------------------------------
120 wxVtkBaseView * wxVtkBaseView_SceneManager :: getWxVtkViewBase()
122 return _wxVtk_BaseView;
124 //------------------------------------------------------------------------------------------------------------
125 void wxVtkBaseView_SceneManager :: configureViewControlTo( std::string theKeyName, manualContourModel * manModelContour, double * spc,int typeContour)
127 //setControlActiveStateOfALL( false );
130 if( _lastInteraction!=NULL )
132 _lastInteraction->getControler()->SetEditable( false );
133 _lastInteraction->getViewer()->Refresh();
134 _lastInteraction->getControler()->SetActive( false );
135 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
139 manualContourBaseControler *manContourControl;
140 manualViewBaseContour *manViewerContour;
142 // Creating the view manualViewContour and the manualContourControler
145 manContourControl = new manualContourControler();
146 manViewerContour = new manualViewContour();
151 manContourControl = new manualRoiControler();
152 manViewerContour = new manualViewRoi();
157 manContourControl = new manualCircleControler();
158 manViewerContour = new manualViewCircle();
163 manContourControl = new manualRoiControler();
164 manViewerContour = new manualViewBullEye();
169 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
170 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: configureViewControlTo \n" );
171 //fprintf(ff," %s %p \n",theKeyName.c_str() , manContourControl );
175 _lastInteraction = insertWrap( theKeyName, manContourControl, manViewerContour );
176 _lastInteractionName = theKeyName;
178 //Configuring the relations between the contour members representation
179 manViewerContour->SetModel( manModelContour );
180 manViewerContour->SetWxVtkBaseView( _wxVtk_BaseView );
181 manViewerContour->SetRange( 2 );
182 manViewerContour->SetZ( 1000 );
184 manViewerContour->SetSpacing(spc);
186 manViewerContour->SetColorNormalContour(0, 0, 1);
187 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
188 manViewerContour->SetColorSelectContour(1, 0.8, 0);
189 manViewerContour->SetWidthLine(_widthOfContour);
191 manContourControl->SetModelView( manModelContour , manViewerContour );
192 manContourControl->Configure();
193 int i,sizeLstPoints = manModelContour->GetSizeLstPoints();
194 for ( i=0; i<sizeLstPoints; i++ )
196 manViewerContour->AddPoint();
199 manContourControl->CreateNewManualContour();
200 manViewerContour->RefreshContour();
201 addToScene( theKeyName );
203 //------------------------------------------------------------------------------------------------------------
204 void wxVtkBaseView_SceneManager :: configureSelectionROI( double * spc )
206 _controlerSelectionROI = new manualRoiControler();
207 _viewerSelectionROI = new manualViewRoi();
208 _modelSelectionROI = new manualContourModel();
210 _viewerSelectionROI->SetModel( _modelSelectionROI );
211 _viewerSelectionROI->SetWxVtkBaseView( _wxVtk_BaseView );
212 _viewerSelectionROI->SetRange( 2 );
213 _viewerSelectionROI->SetZ( 1000 );
214 _viewerSelectionROI->SetColorNormalContour(0.6, 0.8, 0);
216 _viewerSelectionROI->SetSpacing( spc );
218 _controlerSelectionROI->SetModelView( _modelSelectionROI , _viewerSelectionROI );
219 _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _controlerSelectionROI );
220 _controlerSelectionROI->SetActive(false);
223 //------------------------------------------------------------------------------------------------------------
224 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: insertWrap( std::string theKeyName, manualContourBaseControler * manContourControl, manualViewBaseContour * manViewerContour )
226 ContourWrap_ViewControl * newContourWrap = new ContourWrap_ViewControl(manContourControl, manViewerContour);
227 _contours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, newContourWrap ));
228 return newContourWrap;
230 //------------------------------------------------------------------------------------------------------------
231 void wxVtkBaseView_SceneManager :: desconfigureViewControlOf( std::string theKeyName )
235 //------------------------------------------------------------------------------------------------------------
236 void wxVtkBaseView_SceneManager :: removeWrap( std::string theKeyName )
238 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
239 iter = _contours_ViewControl->find( theKeyName );
240 _contours_ViewControl->erase( iter );
241 _lastInteraction=NULL;
242 _lastInteractionName = "";
243 _workingGroup->clear();
244 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
245 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
247 //------------------------------------------------------------------------------------------------------------
248 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName )
250 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
251 iter = _contours_ViewControl->find( theName );
254 //------------------------------------------------------------------------------------------------------------
255 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName, std::map<std::string, ContourWrap_ViewControl *> * theMap )
257 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
258 iter = theMap->find( theName );
261 //------------------------------------------------------------------------------------------------------------
262 manualContourBaseControler * wxVtkBaseView_SceneManager :: getControlerOf( std::string theName )
264 return getContourWrap_ViewControlOf ( theName )->getControler();
266 //------------------------------------------------------------------------------------------------------------
267 manualViewBaseContour * wxVtkBaseView_SceneManager :: getViewerOf( std::string theName )
269 return getContourWrap_ViewControlOf ( theName )->getViewer();
271 //------------------------------------------------------------------------------------------------------------
272 void wxVtkBaseView_SceneManager :: set_creatingMULT_ROI( bool condition )
274 _creatingMULT_ROI = condition;
276 //------------------------------------------------------------------------------------------------------------
277 void wxVtkBaseView_SceneManager :: set_editingROI( bool condition )
279 _editingROI = condition;
281 //------------------------------------------------------------------------------------------------------------
282 void wxVtkBaseView_SceneManager :: set_toIncludeAtInteractionGroup( bool condition )
284 _toIncludeAtInteractionGroup = condition;
286 //------------------------------------------------------------------------------------------------------------
287 void wxVtkBaseView_SceneManager :: set_waiting( bool condition )
289 _waiting = condition;
291 //------------------------------------------------------------------------------------------------------------
292 bool wxVtkBaseView_SceneManager :: get_creatingMULT_ROI( )
294 return _creatingMULT_ROI;
296 //------------------------------------------------------------------------------------------------------------
297 bool wxVtkBaseView_SceneManager :: get_editingROI( )
301 //------------------------------------------------------------------------------------------------------------
302 bool wxVtkBaseView_SceneManager :: get_toIncludeAtInteractionGroup( )
304 return _toIncludeAtInteractionGroup;
307 //------------------------------------------------------------------------------------------------------------
308 bool wxVtkBaseView_SceneManager :: get_waiting( )
313 //------------------------------------------------------------------------------------------------------------
314 bool wxVtkBaseView_SceneManager :: get_creatingROI()
318 //------------------------------------------------------------------------------------------------------------
319 void wxVtkBaseView_SceneManager :: set_creatingROI( bool condition )
321 _creatingROI = condition;
324 //------------------------------------------------------------------------------------------------------------
325 // Other functional methods
326 //------------------------------------------------------------------------------------------------------------
328 void wxVtkBaseView_SceneManager :: createCopyContourOf( std::string anExistingKName, std::string cloneName, manualContourModel * manualModel, bool append )
332 setControlActiveStateOf( _workingGroup, false );
333 _workingGroup->clear();
335 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = NULL;
338 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
339 // fprintf(ff,"EED wxVtkBaseView_SceneManager::createCopyContourOf() \n" );
340 // int ii,size = _contours_ViewControl->size();
341 // iter = _contours_ViewControl->begin();
342 // for (ii=0;ii<size;ii++)
344 // fprintf(ff," %d %s\n ", ii ,iter->first.c_str() );
349 iter = _contours_ViewControl->find( anExistingKName );
351 manualContourModel *cModule = manualModel;
352 manualViewBaseContour *cViewer = iter->second->getViewer()->Clone();
353 manualContourBaseControler *cControl = iter->second->getControler()->Clone( );
355 cViewer->SetModel(cModule);
356 cControl->SetModelView( cModule , cViewer );
357 cControl->CreateNewManualContour();
358 cControl->SetActive( true );
359 cControl->SetEditable( false );
361 cViewer->RefreshContour();
363 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
364 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
366 _lastInteraction = insertWrap( cloneName, cControl, cViewer );
367 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( cloneName, _lastInteraction ));
368 addToScene( cloneName );
371 //------------------------------------------------------------------------------------------------------------
373 void wxVtkBaseView_SceneManager :: removeFromScene( ContourWrap_ViewControl * contourWRP, bool visualization, bool control )
375 if( contourWRP == _lastInteraction )
377 _lastInteraction = NULL;
378 _lastInteractionName = "";
382 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
383 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeFromScene \n" );
384 //fprintf(ff," %p \n", contourWRP->getControler() );
387 _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( contourWRP->getControler() );
389 contourWRP->getControler()->SetActive( control );
390 contourWRP->getControler()->SetEditable( false );
392 if ( !visualization && control )
394 contourWRP->getViewer()->RemoveControlPoints( );
395 contourWRP->getViewer()->RemoveTextActor( );
399 contourWRP->getViewer()->RemoveCompleteContourActor();
403 //------------------------------------------------------------------------------------------------------------
404 void wxVtkBaseView_SceneManager :: removeFromScene( std::string theKeyName, bool visualization , bool control )
407 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
408 iter = _sceneContours_ViewControl->find( theKeyName );
409 if (iter != _sceneContours_ViewControl->end()){
410 ContourWrap_ViewControl * contourWRP = iter->second;
411 removeFromScene( contourWRP );
413 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
414 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeFromScene Bbbbb \n" );
415 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
416 _sceneContours_ViewControl->erase(iter);
419 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
424 //------------------------------------------------------------------------------------------------------------
425 std::vector<std::string> wxVtkBaseView_SceneManager::GetlstContoursNameActualSlice()
427 std::vector<std::string> lstContoursNameActualSlice;
428 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
429 int i,size = _sceneContours_ViewControl->size();
430 for ( i = 0; i<size; i++ )
432 lstContoursNameActualSlice.push_back( iter->first );
435 return lstContoursNameActualSlice;
438 //------------------------------------------------------------------------------------------------------------
439 void wxVtkBaseView_SceneManager :: removeSceneContours( )
442 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
443 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeSceneContours \n" );
444 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
445 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
446 int size = _sceneContours_ViewControl->size();
447 for ( int i = 0; i<size; i++ )
449 removeFromScene( iter->second );
452 _sceneContours_ViewControl->clear();
455 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
458 //Removing the selection rectangle to avoid showing when it's innecesary
459 _controlerSelectionROI->SetActive( false );
460 _viewerSelectionROI->RemoveCompleteContourActor();
463 void wxVtkBaseView_SceneManager::removeAllOutlines()
465 manualViewBaseContour * cViewer;
466 manualContourBaseControler * cControler;
468 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
469 int i,size=_contours_ViewControl->size();
472 iter = _contours_ViewControl->begin();
473 cControler = iter->second->getControler();
474 cViewer = iter->second->getViewer();
475 removeWrap( iter->first );
483 //------------------------------------------------------------------------------------------------------------
484 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
488 removeSceneContours();
490 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
491 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
493 addToScene( theKeyName, contourWRP, true, visualization, control, ifActive, ifShowCtrlPoints);
496 //------------------------------------------------------------------------------------------------------------
497 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
501 removeSceneContours();
503 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
506 contourWRP->getViewer()->AddCompleteContourActor( ifShowCtrlPoints );
511 _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( contourWRP->getControler() );
515 contourWRP->getControler()->SetActive( true );
516 contourWRP->getViewer()->RemoveTextActor();
520 //------------------------------------------------------------------------------------------------------------
521 void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
523 int i, size = theKeyNameVector.size();
524 for( i=0; i< size; i++ )
526 removeFromScene( theKeyNameVector[i], visualization, control );
530 //------------------------------------------------------------------------------------------------------------
531 void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
533 int i, size = theKeyNameVector.size();
534 for( i=0; i< size; i++ )
536 addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
540 //------------------------------------------------------------------------------------------------------------
541 void wxVtkBaseView_SceneManager :: setControlActiveStateOfALL( bool stateCondition )
543 setControlActiveStateOf( _contours_ViewControl, stateCondition );
546 //------------------------------------------------------------------------------------------------------------
547 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
549 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
550 setControlActiveStateOf( contourWRP, stateCondition );
553 //------------------------------------------------------------------------------------------------------------
554 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( ContourWrap_ViewControl * contourWRP, bool stateCondition )
556 contourWRP->getControler()->SetActive( stateCondition );
557 contourWRP->getControler()->SetEditable( false );
560 //------------------------------------------------------------------------------------------------------------
561 void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
563 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
564 // contourWRP->getViewer()->SetVisible( stateCondition );
565 if ( contourWRP!=NULL )
566 removeFromScene( contourWRP, false, stateCondition );
569 //------------------------------------------------------------------------------------------------------------
570 std::vector< std::string > wxVtkBaseView_SceneManager :: getSelectedObjects()
572 std::vector< std::string > selectedObjects;
573 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
574 int size = _workingGroup->size();
575 for ( int i = 0; i<size; i++ )
577 manualViewBaseContour * viewer = iter->second->getViewer();
578 selectedObjects.push_back( iter->first);
582 return selectedObjects;
584 //------------------------------------------------------------------------------------------------------------
585 void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
587 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
588 int size = _contours_ViewControl->size();
590 /*for ( int i = 0; i<size; i++ )
593 manualViewBaseContour * viewer = iter->second->getViewer();
594 std::vector <std::string >::iterator iterIN;
596 for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
598 if( iter->first.compare( theExistingObjectsToSelect[i] ) )
600 viewer->SelectAllPoints( true );
601 viewer->SelectPosibleContour( true );
603 theExistingObjectsToSelect.erase( iterIN );
611 //------------------------------------------------------------------------------------------------------------
612 void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
614 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
615 int size = _contours_ViewControl->size();
616 for ( int i = 0; i<size; i++ )
618 manualViewBaseContour * viewer = iter->second->getViewer();
620 viewer->SetSelected( true );
621 /*viewer->SelectAllPoints( true );
622 viewer->SelectPosibleContour( true );*/
628 //------------------------------------------------------------------------------------------------------------
629 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
631 int i, size = theKeyNameVector.size();
632 for( i=0; i< size; i++ )
634 setControlActiveStateOf( theKeyNameVector[i], controlCondition );
638 //------------------------------------------------------------------------------------------------------------
639 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
641 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
642 int i, size = theMap->size();
643 for( i=0; i< size; i++ )
645 removeFromScene( iter->second, false, controlCondition );
650 //------------------------------------------------------------------------------------------------------------
652 //------------------------------------------------------------------------------------------------------------
654 //------------------------------------------------------------------------------------------------------------
655 // Creational and initialization methods
656 //------------------------------------------------------------------------------------------------------------
658 //------------------------------------------------------------------------------------------------------------
660 //------------------------------------------------------------------------------------------------------------
662 bool wxVtkBaseView_SceneManager :: OnChar()
665 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
666 bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
668 _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
671 if( _eventHandler!=NULL )
673 const char * toolCommand = NULL;
675 if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
677 toolCommand = &(wxContour_ActionCommandsID::COPY_TOOL);
679 else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
681 toolCommand = &(wxContour_ActionCommandsID::PASTE_TOOL);
683 else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
685 toolCommand = &(wxContour_ActionCommandsID::DELETE_KEY);
687 else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
689 toolCommand = &(wxContour_ActionCommandsID::CREATE_CONTOUR_KEY);
691 else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
693 toolCommand = &(wxContour_ActionCommandsID::OPEN_TOOL);
695 else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
697 toolCommand = &(wxContour_ActionCommandsID::SAVE_KEY);
700 if ( toolCommand!=NULL )
702 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
703 cevent.SetClientData( (void *) toolCommand);
704 _eventHandler->ProcessEvent( cevent );
709 // long int endtime = clock();
713 //------------------------------------------------------------------------------------------------------------
715 bool wxVtkBaseView_SceneManager :: OnMouseMove()
718 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
719 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnMouseMove() \n" );
722 bool condition = true;
724 wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
725 _wxVTKiren->GetEventPosition( X , Y );
727 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
728 bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
730 if( _waiting && !ctrlKey )
732 sendEnvent( wxEVT_CHANGED_DEEP, "Update");
733 //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
736 if ( !_creatingROI && !_creatingMULT_ROI )
739 /*if( ctrlKey || shiftKey )
745 _toIncludeAtInteractionGroup = false;
748 bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
749 std::string preservingName = preserveState ? _lastInteractionName : "";
751 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
752 int i, size = _sceneContours_ViewControl->size();
753 bool foundOne = false;
755 manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
756 manualViewBaseContour * viewer = NULL;
759 bool singleMoving = true;
760 int selectionSize = _workingGroup->size();
761 if( selectionSize > 1 )
765 bool ckecking = false;
766 for( i =0; i<size ; i++ )
768 control = iter->second->getControler();
769 viewer = iter->second->getViewer();
770 /*ckecking = */control->SetActive( true );
772 if (_lastInteraction != NULL)
774 singleMoving = !_lastInteraction->getViewer()->GetSelected();
779 size = selectionSize;
780 iter = _workingGroup->begin();
786 _toIncludeAtInteractionGroup = false;
789 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
792 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
793 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnMouseMove() 00222\n" );
795 _lastInteraction=NULL;
796 for( i =0; i<size ; i++ )
798 control = iter->second->getControler();
799 viewer = iter->second->getViewer();
800 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
801 control->SetActive( true );
803 foundOne = control->OnMouseMove();
804 foundOne &= viewer->GetPosibleSelected();
806 if ( !foundOne && singleMoving )
808 control->SetActive( false );
809 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
810 control->SetPosibleToMove( false );
814 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
816 _lastInteraction->getControler()->SetActive( true );
819 _lastInteraction = iter->second;
820 _lastInteractionName = iter->first;
822 viewer->UpdateColorActor();
823 control->SetPosibleToMove( true );
824 // viewer->AddCompleteContourActor();
839 //------------------------------------------------------------------------------------------------------------
840 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
844 ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
845 long int endtime = clock();
846 // double sg = (double)(endtime-startTimeAE) / (double)CLK_TCK;
847 fprintf(ff,"wxVtkBaseView_SceneManager :: OnLeftButtonDown() tLBDown = %i \n \n",endtime);
851 char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
852 bool condition = false;
853 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
854 vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
855 wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
856 wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
857 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
859 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
860 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
861 _toIncludeAtInteractionGroup = false;
862 if ( ctrlKey || shftKey )
864 _toIncludeAtInteractionGroup = true;
868 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
870 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
872 _lastInteraction->getControler()->SetEditable( false );
873 _lastInteraction->getControler()->SetActive( false );
874 _lastInteraction->getControler()->SetPosibleToMove( false );
875 _lastInteraction->getViewer()->Refresh();
876 _lastInteraction=NULL;
883 if( !_toIncludeAtInteractionGroup )
885 _workingGroup->clear();
888 if( _lastInteraction!=NULL )
890 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
891 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
892 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
894 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
897 //setControlActiveStateOf( _contours_ViewControl, false );
898 sendEnvent( wxEVT_START_CREATE_ROI, "");
902 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
903 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
904 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
911 //------------------------------------------------------------------------------------------------------------
912 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
914 bool condition = false;
917 if( _drawingSelectionROI )
919 setSelection2DROIInternalOutlines();
923 //------------------------------------------------------------------------------------------------------------
924 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
926 bool condition = false;
931 //------------------------------------------------------------------------------------------------------------
932 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
934 bool condition = false;
939 //------------------------------------------------------------------------------------------------------------
940 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
942 bool condition = false;
943 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
944 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
951 //------------------------------------------------------------------------------------------------------------
952 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
954 bool condition = false;
956 //setControlActiveStateOfALL( false );//************************************************
957 if ( _creatingMULT_ROI )
959 //setControlActiveStateOfALL( false );
963 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
964 _creatingROI = false;
968 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
970 manualContourBaseControler * control = _lastInteraction->getControler();
971 //_lastInteraction->getControler()->SetPosibleToMove( false );
972 control->SetActive( false );
973 control->SetEditable( false );
974 _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
975 _lastInteraction->getViewer()->Refresh();
976 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
982 //------------------------------------------------------------------------------------------------------------
984 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
986 bool condition = false;
991 //------------------------------------------------------------------------------------------------------------
992 bool wxVtkBaseView_SceneManager :: OnRightDClick()
994 bool condition = false; condition = true;
995 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
996 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
997 wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
1001 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
1002 set_creatingMULT_ROI( !_creatingMULT_ROI );
1010 //------------------------------------------------------------------------------------------------------------
1011 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
1013 bool condition = false;
1018 //------------------------------------------------------------------------------------------------------------
1019 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
1021 bool condition = false;
1025 //------------------------------------------------------------------------------------------------------------
1027 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1029 _drawingSelectionROI = true;
1030 _workingGroup->clear();
1031 _controlerSelectionROI->CreateNewManualContour();
1032 if (_lastInteraction!=NULL)
1034 _lastInteraction->getControler()->SetEditable( false );
1035 _lastInteraction->getControler()->SetActive( false );
1036 _lastInteraction->getControler()->SetPosibleToMove( false );
1037 _lastInteraction->getViewer()->Refresh();
1039 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1040 int i, workSize = _workingGroup->size();
1041 for( i=0; i< workSize; i++ )
1043 manualContourBaseControler * control = iter->second->getControler();
1044 control->SetEditable( false );
1045 control->SetActive( false );
1046 control->SetPosibleToMove( false );
1047 iter->second->getViewer()->Refresh();
1051 _lastInteraction = NULL;
1052 _lastInteractionName = "";
1054 _viewerSelectionROI->AddCompleteContourActor( true );
1055 _controlerSelectionROI->SetActive( true );
1057 _viewerSelectionROI->RefreshContour();
1058 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1060 //------------------------------------------------------------------------------------------------------------
1061 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1063 _drawingSelectionROI = false;
1064 _workingGroup->clear();
1065 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1068 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1069 int i, size = _sceneContours_ViewControl->size();
1070 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1071 manualViewBaseContour * viewer;
1072 bool insideRoi = false;
1073 for ( i=0; i<size; i++ )
1075 viewer = iter->second->getViewer();
1076 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1077 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1080 viewer->SetSelected( true );
1081 viewer->UpdateColorActor();
1082 setControlActiveStateOf( iter->second, true );
1083 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1087 _viewerSelectionROI->RemoveCompleteContourActor( );
1088 _controlerSelectionROI->SetActive( false );
1090 //------------------------------------------------------------------------------------------------------------
1091 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1093 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1094 long int start = clock();
1095 double sg = (double)(start) / (double)CLK_TCK;
1097 wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1098 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1099 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): \n \n",method, tmpPx, tmpPy, sg);
1104 //------------------------------------------------------------------------------------------------------------
1105 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1107 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1108 manualViewBaseContour * cViewer;
1109 manualContourBaseControler * cControler;
1110 ContourWrap_ViewControl *conwraviwcont=iter->second;
1112 cViewer = conwraviwcont->getViewer();
1115 cControler = conwraviwcont->getControler();
1116 // cControler->Save(ff);
1118 // cModel = cControler->GetManualContourModel();
1119 // cModel->Save(ff);
1123 //------------------------------------------------------------------------------------------------------------
1124 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1126 std::vector<std::string> currentSelection = this->getSelectedObjects();
1127 if (currentSelection.size()>=1){
1129 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1130 manualContourModel *cModel = cControler->GetManualContourModel();
1131 int i,size = cModel->GetNumberOfPointsSpline();
1133 for (i=0; i<size; i++)
1135 cModel->GetSpline_i_Point(i, &x, &y, &z);
1143 //------------------------------------------------------------------------------------------------------------
1144 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1146 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1147 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1150 //------------------------------------------------------------------------------------------------------------
1151 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1154 vtkImageData *imagedata = GetImageData();
1155 imagedata->GetExtent(ext);
1156 int sizeZ = ext[5]-ext[4]+1;
1164 //------------------------------------------------------------------------------------------------------------
1165 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1168 vtkImageData *imagedata = GetImageData();
1169 imagedata->GetExtent(ext);
1170 int sizeX = ext[1]-ext[0]+1;
1171 int sizeY = ext[3]-ext[2]+1;
1172 int sizeZ = GetImageDataSizeZ();
1173 int sizeXYZ = sizeX*sizeY*sizeZ;
1177 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1178 for (i=0;i<sizeXYZ;i++)
1180 if ( p[i]<range[0] ) range[0]=p[i];
1181 if ( p[i]>range[1] ) range[1]=p[i];
1185 //------------------------------------------------------------------------------------------------------------
1186 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1188 _widthOfContour = width;
1189 manualViewBaseContour *cViewer;
1190 ContourWrap_ViewControl *conwraviwcont;
1191 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;;
1193 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1195 conwraviwcont = iter->second;
1196 cViewer = conwraviwcont->getViewer();
1197 cViewer->SetWidthLine(_widthOfContour);