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 );
253 //return iter->first;
255 //------------------------------------------------------------------------------------------------------------
256 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName, std::map<std::string, ContourWrap_ViewControl *> * theMap )
258 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
259 iter = theMap->find( theName );
262 //------------------------------------------------------------------------------------------------------------
263 manualContourBaseControler * wxVtkBaseView_SceneManager :: getControlerOf( std::string theName )
265 return getContourWrap_ViewControlOf ( theName )->getControler();
267 //------------------------------------------------------------------------------------------------------------
268 manualViewBaseContour * wxVtkBaseView_SceneManager :: getViewerOf( std::string theName )
270 return getContourWrap_ViewControlOf ( theName )->getViewer();
272 //------------------------------------------------------------------------------------------------------------
273 void wxVtkBaseView_SceneManager :: set_creatingMULT_ROI( bool condition )
275 _creatingMULT_ROI = condition;
277 //------------------------------------------------------------------------------------------------------------
278 void wxVtkBaseView_SceneManager :: set_editingROI( bool condition )
280 _editingROI = condition;
282 //------------------------------------------------------------------------------------------------------------
283 void wxVtkBaseView_SceneManager :: set_toIncludeAtInteractionGroup( bool condition )
285 _toIncludeAtInteractionGroup = condition;
287 //------------------------------------------------------------------------------------------------------------
288 void wxVtkBaseView_SceneManager :: set_waiting( bool condition )
290 _waiting = condition;
292 //------------------------------------------------------------------------------------------------------------
293 bool wxVtkBaseView_SceneManager :: get_creatingMULT_ROI( )
295 return _creatingMULT_ROI;
297 //------------------------------------------------------------------------------------------------------------
298 bool wxVtkBaseView_SceneManager :: get_editingROI( )
302 //------------------------------------------------------------------------------------------------------------
303 bool wxVtkBaseView_SceneManager :: get_toIncludeAtInteractionGroup( )
305 return _toIncludeAtInteractionGroup;
308 //------------------------------------------------------------------------------------------------------------
309 bool wxVtkBaseView_SceneManager :: get_waiting( )
314 //------------------------------------------------------------------------------------------------------------
315 bool wxVtkBaseView_SceneManager :: get_creatingROI()
319 //------------------------------------------------------------------------------------------------------------
320 void wxVtkBaseView_SceneManager :: set_creatingROI( bool condition )
322 _creatingROI = condition;
325 //------------------------------------------------------------------------------------------------------------
326 // Other functional methods
327 //------------------------------------------------------------------------------------------------------------
329 void wxVtkBaseView_SceneManager :: createCopyContourOf( std::string anExistingKName, std::string cloneName, manualContourModel * manualModel, bool append )
333 setControlActiveStateOf( _workingGroup, false );
334 _workingGroup->clear();
336 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
339 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
340 // fprintf(ff,"EED wxVtkBaseView_SceneManager::createCopyContourOf() \n" );
341 // int ii,size = _contours_ViewControl->size();
342 // iter = _contours_ViewControl->begin();
343 // for (ii=0;ii<size;ii++)
345 // fprintf(ff," %d %s\n ", ii ,iter->first.c_str() );
350 iter = _contours_ViewControl->find( anExistingKName );
352 manualContourModel *cModule = manualModel;
353 manualViewBaseContour *cViewer = iter->second->getViewer()->Clone();
354 manualContourBaseControler *cControl = iter->second->getControler()->Clone( );
356 cViewer->SetModel(cModule);
357 cControl->SetModelView( cModule , cViewer );
358 cControl->CreateNewManualContour();
359 cControl->SetActive( true );
360 cControl->SetEditable( false );
362 cViewer->RefreshContour();
364 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
365 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
367 _lastInteraction = insertWrap( cloneName, cControl, cViewer );
368 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( cloneName, _lastInteraction ));
369 addToScene( cloneName );
372 //------------------------------------------------------------------------------------------------------------
374 void wxVtkBaseView_SceneManager :: removeFromScene( ContourWrap_ViewControl * contourWRP, bool visualization, bool control )
376 if( contourWRP == _lastInteraction )
378 _lastInteraction = NULL;
379 _lastInteractionName = "";
383 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
384 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeFromScene \n" );
385 //fprintf(ff," %p \n", contourWRP->getControler() );
388 _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( contourWRP->getControler() );
390 contourWRP->getControler()->SetActive( control );
391 contourWRP->getControler()->SetEditable( false );
393 if ( !visualization && control )
395 contourWRP->getViewer()->RemoveControlPoints( );
396 contourWRP->getViewer()->RemoveTextActor( );
400 contourWRP->getViewer()->RemoveCompleteContourActor();
404 //------------------------------------------------------------------------------------------------------------
405 void wxVtkBaseView_SceneManager :: removeFromScene( std::string theKeyName, bool visualization , bool control )
408 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
409 iter = _sceneContours_ViewControl->find( theKeyName );
410 if (iter != _sceneContours_ViewControl->end()){
411 ContourWrap_ViewControl * contourWRP = iter->second;
412 removeFromScene( contourWRP );
414 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
415 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeFromScene Bbbbb \n" );
416 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
417 _sceneContours_ViewControl->erase(iter);
420 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
425 //------------------------------------------------------------------------------------------------------------
426 std::vector<std::string> wxVtkBaseView_SceneManager::GetlstContoursNameActualSlice()
428 std::vector<std::string> lstContoursNameActualSlice;
429 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
430 int i,size = _sceneContours_ViewControl->size();
431 for ( i = 0; i<size; i++ )
433 lstContoursNameActualSlice.push_back( iter->first );
436 return lstContoursNameActualSlice;
439 //------------------------------------------------------------------------------------------------------------
440 void wxVtkBaseView_SceneManager :: removeSceneContours( )
443 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
444 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeSceneContours \n" );
445 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
446 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
447 int size = _sceneContours_ViewControl->size();
448 for ( int i = 0; i<size; i++ )
450 removeFromScene( iter->second );
453 _sceneContours_ViewControl->clear();
456 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
459 //Removing the selection rectangle to avoid showing when it's innecesary
460 _controlerSelectionROI->SetActive( false );
461 _viewerSelectionROI->RemoveCompleteContourActor();
464 void wxVtkBaseView_SceneManager::removeAllOutlines()
466 manualViewBaseContour * cViewer;
467 manualContourBaseControler * cControler;
469 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
470 int i,size=_contours_ViewControl->size();
473 iter = _contours_ViewControl->begin();
474 cControler = iter->second->getControler();
475 cViewer = iter->second->getViewer();
476 removeWrap( iter->first );
484 //------------------------------------------------------------------------------------------------------------
485 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
489 removeSceneContours();
491 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
492 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
494 addToScene( theKeyName, contourWRP, true, visualization, control, ifActive, ifShowCtrlPoints);
497 //------------------------------------------------------------------------------------------------------------
498 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
502 removeSceneContours();
504 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
507 contourWRP->getViewer()->AddCompleteContourActor( ifShowCtrlPoints );
512 _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( contourWRP->getControler() );
516 contourWRP->getControler()->SetActive( true );
517 contourWRP->getViewer()->RemoveTextActor();
521 //------------------------------------------------------------------------------------------------------------
522 void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
524 int i, size = theKeyNameVector.size();
525 for( i=0; i< size; i++ )
527 removeFromScene( theKeyNameVector[i], visualization, control );
531 //------------------------------------------------------------------------------------------------------------
532 void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
534 int i, size = theKeyNameVector.size();
535 for( i=0; i< size; i++ )
537 addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
541 //------------------------------------------------------------------------------------------------------------
542 void wxVtkBaseView_SceneManager :: setControlActiveStateOfALL( bool stateCondition )
544 setControlActiveStateOf( _contours_ViewControl, stateCondition );
547 //------------------------------------------------------------------------------------------------------------
548 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
550 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
551 setControlActiveStateOf( contourWRP, stateCondition );
554 //------------------------------------------------------------------------------------------------------------
555 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( ContourWrap_ViewControl * contourWRP, bool stateCondition )
557 contourWRP->getControler()->SetActive( stateCondition );
558 contourWRP->getControler()->SetEditable( false );
561 //------------------------------------------------------------------------------------------------------------
562 void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
564 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
565 // contourWRP->getViewer()->SetVisible( stateCondition );
566 if ( contourWRP!=NULL )
567 removeFromScene( contourWRP, false, stateCondition );
570 //------------------------------------------------------------------------------------------------------------
571 std::vector< std::string > wxVtkBaseView_SceneManager :: getSelectedObjects()
573 std::vector< std::string > selectedObjects;
574 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
575 int size = _workingGroup->size();
576 for ( int i = 0; i<size; i++ )
578 manualViewBaseContour * viewer = iter->second->getViewer();
579 selectedObjects.push_back( iter->first);
583 return selectedObjects;
585 //------------------------------------------------------------------------------------------------------------
586 void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
588 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
589 int size = _contours_ViewControl->size();
591 /*for ( int i = 0; i<size; i++ )
594 manualViewBaseContour * viewer = iter->second->getViewer();
595 std::vector <std::string >::iterator iterIN;
597 for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
599 if( iter->first.compare( theExistingObjectsToSelect[i] ) )
601 viewer->SelectAllPoints( true );
602 viewer->SelectPosibleContour( true );
604 theExistingObjectsToSelect.erase( iterIN );
612 //------------------------------------------------------------------------------------------------------------
613 void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
615 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
616 int size = _contours_ViewControl->size();
617 for ( int i = 0; i<size; i++ )
619 manualViewBaseContour * viewer = iter->second->getViewer();
621 viewer->SetSelected( true );
622 /*viewer->SelectAllPoints( true );
623 viewer->SelectPosibleContour( true );*/
629 //------------------------------------------------------------------------------------------------------------
630 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
632 int i, size = theKeyNameVector.size();
633 for( i=0; i< size; i++ )
635 setControlActiveStateOf( theKeyNameVector[i], controlCondition );
639 //------------------------------------------------------------------------------------------------------------
640 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
642 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
643 int i, size = theMap->size();
644 for( i=0; i< size; i++ )
646 removeFromScene( iter->second, false, controlCondition );
651 //------------------------------------------------------------------------------------------------------------
653 //------------------------------------------------------------------------------------------------------------
655 //------------------------------------------------------------------------------------------------------------
656 // Creational and initialization methods
657 //------------------------------------------------------------------------------------------------------------
659 //------------------------------------------------------------------------------------------------------------
661 //------------------------------------------------------------------------------------------------------------
663 bool wxVtkBaseView_SceneManager :: OnChar()
666 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
667 bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
669 _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
672 if( _eventHandler!=NULL )
674 const char * toolCommand = NULL;
676 if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
678 toolCommand = &(wxContour_ActionCommandsID::COPY_TOOL);
680 else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
682 toolCommand = &(wxContour_ActionCommandsID::PASTE_TOOL);
684 else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
686 toolCommand = &(wxContour_ActionCommandsID::DELETE_KEY);
688 else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
690 toolCommand = &(wxContour_ActionCommandsID::CREATE_CONTOUR_KEY);
692 else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
694 toolCommand = &(wxContour_ActionCommandsID::OPEN_TOOL);
696 else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
698 toolCommand = &(wxContour_ActionCommandsID::SAVE_KEY);
701 if ( toolCommand!=NULL )
703 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
704 cevent.SetClientData( (void *) toolCommand);
705 _eventHandler->ProcessEvent( cevent );
710 // long int endtime = clock();
714 //------------------------------------------------------------------------------------------------------------
716 bool wxVtkBaseView_SceneManager :: OnMouseMove()
719 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
720 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnMouseMove() \n" );
723 bool condition = true;
725 wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
726 _wxVTKiren->GetEventPosition( X , Y );
728 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
729 bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
731 if( _waiting && !ctrlKey )
733 sendEnvent( wxEVT_CHANGED_DEEP, "Update");
734 //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
737 if ( !_creatingROI && !_creatingMULT_ROI )
740 /*if( ctrlKey || shiftKey )
746 _toIncludeAtInteractionGroup = false;
749 bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
750 std::string preservingName = preserveState ? _lastInteractionName : "";
752 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
753 int i, size = _sceneContours_ViewControl->size();
754 bool foundOne = false;
756 manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
757 manualViewBaseContour * viewer = NULL;
760 bool singleMoving = true;
761 int selectionSize = _workingGroup->size();
762 if( selectionSize > 1 )
766 bool ckecking = false;
767 for( i =0; i<size ; i++ )
769 control = iter->second->getControler();
770 viewer = iter->second->getViewer();
771 /*ckecking = */control->SetActive( true );
773 if (_lastInteraction != NULL)
775 singleMoving = !_lastInteraction->getViewer()->GetSelected();
780 size = selectionSize;
781 iter = _workingGroup->begin();
787 _toIncludeAtInteractionGroup = false;
790 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
793 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
794 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnMouseMove() 00222\n" );
796 _lastInteraction=NULL;
797 for( i =0; i<size ; i++ )
799 control = iter->second->getControler();
800 viewer = iter->second->getViewer();
801 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
802 control->SetActive( true );
804 foundOne = control->OnMouseMove();
805 foundOne &= viewer->GetPosibleSelected();
807 if ( !foundOne && singleMoving )
809 control->SetActive( false );
810 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
811 control->SetPosibleToMove( false );
815 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
817 _lastInteraction->getControler()->SetActive( true );
820 _lastInteraction = iter->second;
821 _lastInteractionName = iter->first;
823 viewer->UpdateColorActor();
824 control->SetPosibleToMove( true );
825 // viewer->AddCompleteContourActor();
840 //------------------------------------------------------------------------------------------------------------
841 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
845 ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
846 long int endtime = clock();
847 // double sg = (double)(endtime-startTimeAE) / (double)CLK_TCK;
848 fprintf(ff,"wxVtkBaseView_SceneManager :: OnLeftButtonDown() tLBDown = %i \n \n",endtime);
852 char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
853 bool condition = false;
854 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
855 vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
856 wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
857 wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
858 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
860 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
861 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
862 _toIncludeAtInteractionGroup = false;
863 if ( ctrlKey || shftKey )
865 _toIncludeAtInteractionGroup = true;
869 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
871 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
873 _lastInteraction->getControler()->SetEditable( false );
874 _lastInteraction->getControler()->SetActive( false );
875 _lastInteraction->getControler()->SetPosibleToMove( false );
876 _lastInteraction->getViewer()->Refresh();
877 _lastInteraction=NULL;
884 if( !_toIncludeAtInteractionGroup )
886 _workingGroup->clear();
889 if( _lastInteraction!=NULL )
891 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
892 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
893 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
895 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
898 //setControlActiveStateOf( _contours_ViewControl, false );
899 sendEnvent( wxEVT_START_CREATE_ROI, "");
903 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
904 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
905 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
912 //------------------------------------------------------------------------------------------------------------
913 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
915 bool condition = false;
918 if( _drawingSelectionROI )
920 setSelection2DROIInternalOutlines();
924 //------------------------------------------------------------------------------------------------------------
925 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
927 bool condition = false;
932 //------------------------------------------------------------------------------------------------------------
933 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
935 bool condition = false;
940 //------------------------------------------------------------------------------------------------------------
941 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
943 bool condition = false;
944 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
945 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
952 //------------------------------------------------------------------------------------------------------------
953 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
955 bool condition = false;
957 //setControlActiveStateOfALL( false );//************************************************
958 if ( _creatingMULT_ROI )
960 //setControlActiveStateOfALL( false );
964 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
965 _creatingROI = false;
969 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
971 manualContourBaseControler * control = _lastInteraction->getControler();
972 //_lastInteraction->getControler()->SetPosibleToMove( false );
973 control->SetActive( false );
974 control->SetEditable( false );
975 _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
976 _lastInteraction->getViewer()->Refresh();
977 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
983 //------------------------------------------------------------------------------------------------------------
985 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
987 bool condition = false;
992 //------------------------------------------------------------------------------------------------------------
993 bool wxVtkBaseView_SceneManager :: OnRightDClick()
995 bool condition = false; condition = true;
996 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
997 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
998 wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
1002 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
1003 set_creatingMULT_ROI( !_creatingMULT_ROI );
1011 //------------------------------------------------------------------------------------------------------------
1012 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
1014 bool condition = false;
1019 //------------------------------------------------------------------------------------------------------------
1020 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
1022 bool condition = false;
1026 //------------------------------------------------------------------------------------------------------------
1028 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1030 _drawingSelectionROI = true;
1031 _workingGroup->clear();
1032 _controlerSelectionROI->CreateNewManualContour();
1033 if (_lastInteraction!=NULL)
1035 _lastInteraction->getControler()->SetEditable( false );
1036 _lastInteraction->getControler()->SetActive( false );
1037 _lastInteraction->getControler()->SetPosibleToMove( false );
1038 _lastInteraction->getViewer()->Refresh();
1040 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1041 int i, workSize = _workingGroup->size();
1042 for( i=0; i< workSize; i++ )
1044 manualContourBaseControler * control = iter->second->getControler();
1045 control->SetEditable( false );
1046 control->SetActive( false );
1047 control->SetPosibleToMove( false );
1048 iter->second->getViewer()->Refresh();
1052 _lastInteraction = NULL;
1053 _lastInteractionName = "";
1055 _viewerSelectionROI->AddCompleteContourActor( true );
1056 _controlerSelectionROI->SetActive( true );
1058 _viewerSelectionROI->RefreshContour();
1059 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1061 //------------------------------------------------------------------------------------------------------------
1062 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1064 _drawingSelectionROI = false;
1065 _workingGroup->clear();
1066 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1069 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1070 int i, size = _sceneContours_ViewControl->size();
1071 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1072 manualViewBaseContour * viewer;
1073 bool insideRoi = false;
1074 for ( i=0; i<size; i++ )
1076 viewer = iter->second->getViewer();
1077 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1078 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1081 viewer->SetSelected( true );
1082 viewer->UpdateColorActor();
1083 setControlActiveStateOf( iter->second, true );
1084 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1088 _viewerSelectionROI->RemoveCompleteContourActor( );
1089 _controlerSelectionROI->SetActive( false );
1091 //------------------------------------------------------------------------------------------------------------
1092 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1094 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1095 long int start = clock();
1097 double sg = (double)(start) / (double)CLK_TCK;
1099 double sg = (double)(start) / CLOCKS_PER_SEC;
1102 wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1103 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1104 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): \n \n",method.c_str(), tmpPx, tmpPy, sg);
1109 //------------------------------------------------------------------------------------------------------------
1110 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1112 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1113 manualViewBaseContour * cViewer;
1114 manualContourBaseControler * cControler;
1115 ContourWrap_ViewControl *conwraviwcont=iter->second;
1117 cViewer = conwraviwcont->getViewer();
1120 cControler = conwraviwcont->getControler();
1121 // cControler->Save(ff);
1123 // cModel = cControler->GetManualContourModel();
1124 // cModel->Save(ff);
1128 //------------------------------------------------------------------------------------------------------------
1129 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1131 std::vector<std::string> currentSelection = this->getSelectedObjects();
1132 if (currentSelection.size()>=1){
1134 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1135 manualContourModel *cModel = cControler->GetManualContourModel();
1136 int i,size = cModel->GetNumberOfPointsSpline();
1138 for (i=0; i<size; i++)
1140 cModel->GetSpline_i_Point(i, &x, &y, &z);
1148 //------------------------------------------------------------------------------------------------------------
1149 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1151 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1152 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1155 //------------------------------------------------------------------------------------------------------------
1156 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1159 vtkImageData *imagedata = GetImageData();
1160 imagedata->GetExtent(ext);
1161 int sizeZ = ext[5]-ext[4]+1;
1169 //------------------------------------------------------------------------------------------------------------
1170 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1173 vtkImageData *imagedata = GetImageData();
1174 imagedata->GetExtent(ext);
1175 int sizeX = ext[1]-ext[0]+1;
1176 int sizeY = ext[3]-ext[2]+1;
1177 int sizeZ = GetImageDataSizeZ();
1178 int sizeXYZ = sizeX*sizeY*sizeZ;
1182 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1183 for (i=0;i<sizeXYZ;i++)
1185 if ( p[i]<range[0] ) range[0]=p[i];
1186 if ( p[i]>range[1] ) range[1]=p[i];
1190 //------------------------------------------------------------------------------------------------------------
1191 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1193 _widthOfContour = width;
1194 manualViewBaseContour *cViewer;
1195 ContourWrap_ViewControl *conwraviwcont;
1196 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;;
1198 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1200 conwraviwcont = iter->second;
1201 cViewer = conwraviwcont->getViewer();
1202 cViewer->SetWidthLine(_widthOfContour);
1206 bool wxVtkBaseView_SceneManager::isEditableCControler(std::string theKeyName){
1208 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1210 manualContourBaseControler* cControler = ccon->getControler();
1211 if(cControler != NULL && cControler->IsEditable() == false){
1218 void wxVtkBaseView_SceneManager::deleteCViewerCControler(std::string theKeyName){
1221 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1223 manualViewBaseContour * cViewer = ccon->getViewer();
1224 manualContourBaseControler * cControler = ccon->getControler();
1226 removeFromScene(theKeyName);
1227 removeWrap(theKeyName);