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;
61 _wxVtk_BaseView = theWxBaseViewToManage;
62 if( _wxVtk_BaseView!=NULL )
64 vtkInteractorStyleBaseView* theInteractorStyleBaseView = _wxVtk_BaseView->GetInteractorStyleBaseView();
65 theInteractorStyleBaseView->AddInteractorStyleMaracas( this );
66 SetVtkInteractorStyleBaseView( theInteractorStyleBaseView );
68 configureSelectionROI( spc );
70 //------------------------------------------------------------------------------------------------------------
71 wxVtkBaseView_SceneManager :: ~wxVtkBaseView_SceneManager()
73 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
74 int size = _contours_ViewControl->size();
75 for ( int i = 0; i<size; iter++ )
77 _contours_ViewControl->erase( iter );
80 delete _contours_ViewControl;
81 _contours_ViewControl->clear();
82 _workingGroup->clear();
83 delete _lastInteraction;
85 delete _contours_ViewControl;
88 //------------------------------------------------------------------------------------------------------------
89 // Methods for capturing events
90 //------------------------------------------------------------------------------------------------------------
93 //------------------------------------------------------------------------------------------------------------
94 // Methods for sending events
95 //------------------------------------------------------------------------------------------------------------
96 void wxVtkBaseView_SceneManager :: sendEnvent( WXTYPE theEventType, std::string text )
98 if ( _eventHandler != NULL )
100 wxCommandEvent cevent( theEventType );
101 cevent.SetString( wxString( text.c_str(), wxConvUTF8) );
102 _eventHandler->ProcessEvent( cevent );
107 //------------------------------------------------------------------------------------------------------------
108 // Attributes getters and setters
109 //------------------------------------------------------------------------------------------------------------
110 void wxVtkBaseView_SceneManager :: setWxEventHandler( wxEvtHandler * theEventHandler )
112 _eventHandler = theEventHandler;
114 //------------------------------------------------------------------------------------------------------------
115 void wxVtkBaseView_SceneManager :: setWxVtkViewBase( wxVtkBaseView * theBaseView )
117 _wxVtk_BaseView = theBaseView;
120 //------------------------------------------------------------------------------------------------------------
121 wxVtkBaseView * wxVtkBaseView_SceneManager :: getWxVtkViewBase()
123 return _wxVtk_BaseView;
125 //------------------------------------------------------------------------------------------------------------
126 void wxVtkBaseView_SceneManager :: configureViewControlTo( std::string theKeyName, manualContourModel * manModelContour, double * spc,int typeContour)
128 //setControlActiveStateOfALL( false );
131 if( _lastInteraction!=NULL )
133 _lastInteraction->getControler()->SetEditable( false );
134 _lastInteraction->getViewer()->Refresh();
135 _lastInteraction->getControler()->SetActive( false );
136 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
140 manualContourBaseControler *manContourControl;
141 manualViewBaseContour *manViewerContour;
143 // Creating the view manualViewContour and the manualContourControler
146 manContourControl = new manualContourControler();
147 manViewerContour = new manualViewContour();
152 manContourControl = new manualRoiControler();
153 manViewerContour = new manualViewRoi();
158 manContourControl = new manualCircleControler();
159 manViewerContour = new manualViewCircle();
164 manContourControl = new manualRoiControler();
165 manViewerContour = new manualViewBullEye();
170 manContourControl = new manualLineControler();
171 manViewerContour = new manualViewLine();
176 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
177 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: configureViewControlTo \n" );
178 //fprintf(ff," %s %p \n",theKeyName.c_str() , manContourControl );
182 _lastInteraction = insertWrap( theKeyName, manContourControl, manViewerContour );
183 _lastInteractionName = theKeyName;
185 //Configuring the relations between the contour members representation
186 manViewerContour->SetModel( manModelContour );
187 manViewerContour->SetWxVtkBaseView( _wxVtk_BaseView );
188 manViewerContour->SetRange( 2 );
189 manViewerContour->SetZ( 1000 );
191 manViewerContour->SetSpacing(spc);
193 manViewerContour->SetColorNormalContour(0, 0, 1);
194 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
195 manViewerContour->SetColorSelectContour(1, 0.8, 0);
196 manViewerContour->SetWidthLine(_widthOfContour);
198 manContourControl->SetModelView( manModelContour , manViewerContour );
199 manContourControl->Configure();
200 int i,sizeLstPoints = manModelContour->GetSizeLstPoints();
201 for ( i=0; i<sizeLstPoints; i++ )
203 manViewerContour->AddPoint();
206 manContourControl->CreateNewManualContour();
207 manViewerContour->RefreshContour();
208 addToScene( theKeyName );
210 //------------------------------------------------------------------------------------------------------------
211 void wxVtkBaseView_SceneManager :: configureSelectionROI( double * spc )
213 _controlerSelectionROI = new manualRoiControler();
214 _viewerSelectionROI = new manualViewRoi();
215 _modelSelectionROI = new manualContourModel();
217 _viewerSelectionROI->SetModel( _modelSelectionROI );
218 _viewerSelectionROI->SetWxVtkBaseView( _wxVtk_BaseView );
219 _viewerSelectionROI->SetRange( 2 );
220 _viewerSelectionROI->SetZ( 1000 );
221 _viewerSelectionROI->SetColorNormalContour(0.6, 0.8, 0);
223 _viewerSelectionROI->SetSpacing( spc );
225 _controlerSelectionROI->SetModelView( _modelSelectionROI , _viewerSelectionROI );
226 _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _controlerSelectionROI );
227 _controlerSelectionROI->SetActive(false);
230 //------------------------------------------------------------------------------------------------------------
231 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: insertWrap( std::string theKeyName, manualContourBaseControler * manContourControl, manualViewBaseContour * manViewerContour )
233 ContourWrap_ViewControl * newContourWrap = new ContourWrap_ViewControl(manContourControl, manViewerContour);
234 _contours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, newContourWrap ));
235 return newContourWrap;
237 //------------------------------------------------------------------------------------------------------------
238 void wxVtkBaseView_SceneManager :: desconfigureViewControlOf( std::string theKeyName )
242 //------------------------------------------------------------------------------------------------------------
243 void wxVtkBaseView_SceneManager :: removeWrap( std::string theKeyName )
245 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
246 iter = _contours_ViewControl->find( theKeyName );
247 _contours_ViewControl->erase( iter );
248 _lastInteraction=NULL;
249 _lastInteractionName = "";
250 _workingGroup->clear();
251 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
252 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
254 //------------------------------------------------------------------------------------------------------------
255 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName )
257 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
258 iter = _contours_ViewControl->find( theName );
260 //return iter->first;
262 //------------------------------------------------------------------------------------------------------------
263 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName, std::map<std::string, ContourWrap_ViewControl *> * theMap )
265 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
266 iter = theMap->find( theName );
269 //------------------------------------------------------------------------------------------------------------
270 manualContourBaseControler * wxVtkBaseView_SceneManager :: getControlerOf( std::string theName )
272 return getContourWrap_ViewControlOf ( theName )->getControler();
274 //------------------------------------------------------------------------------------------------------------
275 manualViewBaseContour * wxVtkBaseView_SceneManager :: getViewerOf( std::string theName )
277 return getContourWrap_ViewControlOf ( theName )->getViewer();
279 //------------------------------------------------------------------------------------------------------------
280 void wxVtkBaseView_SceneManager :: set_creatingMULT_ROI( bool condition )
282 _creatingMULT_ROI = condition;
284 //------------------------------------------------------------------------------------------------------------
285 void wxVtkBaseView_SceneManager :: set_editingROI( bool condition )
287 _editingROI = condition;
289 //------------------------------------------------------------------------------------------------------------
290 void wxVtkBaseView_SceneManager :: set_toIncludeAtInteractionGroup( bool condition )
292 _toIncludeAtInteractionGroup = condition;
294 //------------------------------------------------------------------------------------------------------------
295 void wxVtkBaseView_SceneManager :: set_waiting( bool condition )
297 _waiting = condition;
299 //------------------------------------------------------------------------------------------------------------
300 bool wxVtkBaseView_SceneManager :: get_creatingMULT_ROI( )
302 return _creatingMULT_ROI;
304 //------------------------------------------------------------------------------------------------------------
305 bool wxVtkBaseView_SceneManager :: get_editingROI( )
309 //------------------------------------------------------------------------------------------------------------
310 bool wxVtkBaseView_SceneManager :: get_toIncludeAtInteractionGroup( )
312 return _toIncludeAtInteractionGroup;
315 //------------------------------------------------------------------------------------------------------------
316 bool wxVtkBaseView_SceneManager :: get_waiting( )
321 //------------------------------------------------------------------------------------------------------------
322 bool wxVtkBaseView_SceneManager :: get_creatingROI()
326 //------------------------------------------------------------------------------------------------------------
327 void wxVtkBaseView_SceneManager :: set_creatingROI( bool condition )
329 _creatingROI = condition;
332 //------------------------------------------------------------------------------------------------------------
333 // Other functional methods
334 //------------------------------------------------------------------------------------------------------------
336 void wxVtkBaseView_SceneManager :: createCopyContourOf( std::string anExistingKName, std::string cloneName, manualContourModel * manualModel, bool append )
340 setControlActiveStateOf( _workingGroup, false );
341 _workingGroup->clear();
343 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
346 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
347 // fprintf(ff,"EED wxVtkBaseView_SceneManager::createCopyContourOf() \n" );
348 // int ii,size = _contours_ViewControl->size();
349 // iter = _contours_ViewControl->begin();
350 // for (ii=0;ii<size;ii++)
352 // fprintf(ff," %d %s\n ", ii ,iter->first.c_str() );
357 iter = _contours_ViewControl->find( anExistingKName );
359 manualContourModel *cModule = manualModel;
360 manualViewBaseContour *cViewer = iter->second->getViewer()->Clone();
361 manualContourBaseControler *cControl = iter->second->getControler()->Clone( );
363 cViewer->SetModel(cModule);
364 cControl->SetModelView( cModule , cViewer );
365 cControl->CreateNewManualContour();
366 cControl->SetActive( true );
367 cControl->SetEditable( false );
369 cViewer->RefreshContour();
371 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
372 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
374 _lastInteraction = insertWrap( cloneName, cControl, cViewer );
375 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( cloneName, _lastInteraction ));
376 addToScene( cloneName );
379 //------------------------------------------------------------------------------------------------------------
381 void wxVtkBaseView_SceneManager :: removeFromScene( ContourWrap_ViewControl * contourWRP, bool visualization, bool control )
383 if( contourWRP == _lastInteraction )
385 _lastInteraction = NULL;
386 _lastInteractionName = "";
390 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
391 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeFromScene \n" );
392 //fprintf(ff," %p \n", contourWRP->getControler() );
395 _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( contourWRP->getControler() );
397 contourWRP->getControler()->SetActive( control );
398 contourWRP->getControler()->SetEditable( false );
400 if ( !visualization && control )
402 contourWRP->getViewer()->RemoveControlPoints( );
403 contourWRP->getViewer()->RemoveTextActor( );
407 contourWRP->getViewer()->RemoveCompleteContourActor();
411 //------------------------------------------------------------------------------------------------------------
412 void wxVtkBaseView_SceneManager :: removeFromScene( std::string theKeyName, bool visualization , bool control )
415 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
416 iter = _sceneContours_ViewControl->find( theKeyName );
417 if (iter != _sceneContours_ViewControl->end())
419 ContourWrap_ViewControl * contourWRP = iter->second;
420 removeFromScene( contourWRP );
422 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
423 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeFromScene Bbbbb \n" );
424 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
425 _sceneContours_ViewControl->erase(iter);
428 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
433 //------------------------------------------------------------------------------------------------------------
434 std::vector<std::string> wxVtkBaseView_SceneManager::GetlstContoursNameActualSlice()
436 std::vector<std::string> lstContoursNameActualSlice;
437 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
438 int i,size = _sceneContours_ViewControl->size();
439 for ( i = 0; i<size; i++ )
441 lstContoursNameActualSlice.push_back( iter->first );
444 return lstContoursNameActualSlice;
447 //------------------------------------------------------------------------------------------------------------
448 void wxVtkBaseView_SceneManager :: removeSceneContours( )
451 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
452 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeSceneContours \n" );
453 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
454 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
455 int size = _sceneContours_ViewControl->size();
456 for ( int i = 0; i<size; i++ )
458 removeFromScene( iter->second );
461 _sceneContours_ViewControl->clear();
464 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
467 //Removing the selection rectangle to avoid showing when it's innecesary
468 _controlerSelectionROI->SetActive( false );
469 _viewerSelectionROI->RemoveCompleteContourActor();
472 void wxVtkBaseView_SceneManager::removeAllOutlines()
474 manualViewBaseContour * cViewer;
475 manualContourBaseControler * cControler;
477 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
478 int i,size=_contours_ViewControl->size();
481 iter = _contours_ViewControl->begin();
482 cControler = iter->second->getControler();
483 cViewer = iter->second->getViewer();
484 removeWrap( iter->first );
492 //------------------------------------------------------------------------------------------------------------
493 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
497 removeSceneContours();
499 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
500 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
502 addToScene( theKeyName, contourWRP, true, visualization, control, ifActive, ifShowCtrlPoints);
505 //------------------------------------------------------------------------------------------------------------
506 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
510 removeSceneContours();
512 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
515 contourWRP->getViewer()->AddCompleteContourActor( ifShowCtrlPoints );
520 _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( contourWRP->getControler() );
524 contourWRP->getControler()->SetActive( true );
525 contourWRP->getViewer()->RemoveTextActor();
529 //------------------------------------------------------------------------------------------------------------
530 void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
532 int i, size = theKeyNameVector.size();
533 for( i=0; i< size; i++ )
535 removeFromScene( theKeyNameVector[i], visualization, control );
539 //------------------------------------------------------------------------------------------------------------
540 void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
542 int i, size = theKeyNameVector.size();
543 for( i=0; i< size; i++ )
545 addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
549 //------------------------------------------------------------------------------------------------------------
550 void wxVtkBaseView_SceneManager :: setControlActiveStateOfALL( bool stateCondition )
552 setControlActiveStateOf( _contours_ViewControl, stateCondition );
555 //------------------------------------------------------------------------------------------------------------
556 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
558 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
559 setControlActiveStateOf( contourWRP, stateCondition );
562 //------------------------------------------------------------------------------------------------------------
563 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( ContourWrap_ViewControl * contourWRP, bool stateCondition )
565 contourWRP->getControler()->SetActive( stateCondition );
566 contourWRP->getControler()->SetEditable( false );
569 //------------------------------------------------------------------------------------------------------------
570 void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
572 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
573 // contourWRP->getViewer()->SetVisible( stateCondition );
574 if ( contourWRP!=NULL )
575 removeFromScene( contourWRP, false, stateCondition );
578 //------------------------------------------------------------------------------------------------------------
579 std::vector< std::string > wxVtkBaseView_SceneManager :: getSelectedObjects()
581 std::vector< std::string > selectedObjects;
582 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
583 int size = _workingGroup->size();
584 for ( int i = 0; i<size; i++ )
586 manualViewBaseContour * viewer = iter->second->getViewer();
587 selectedObjects.push_back( iter->first);
591 return selectedObjects;
593 //------------------------------------------------------------------------------------------------------------
594 void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
596 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
597 int size = _contours_ViewControl->size();
599 /*for ( int i = 0; i<size; i++ )
602 manualViewBaseContour * viewer = iter->second->getViewer();
603 std::vector <std::string >::iterator iterIN;
605 for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
607 if( iter->first.compare( theExistingObjectsToSelect[i] ) )
609 viewer->SelectAllPoints( true );
610 viewer->SelectPosibleContour( true );
612 theExistingObjectsToSelect.erase( iterIN );
620 //------------------------------------------------------------------------------------------------------------
621 void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
623 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
624 int size = _contours_ViewControl->size();
625 for ( int i = 0; i<size; i++ )
627 manualViewBaseContour * viewer = iter->second->getViewer();
629 viewer->SetSelected( true );
630 /*viewer->SelectAllPoints( true );
631 viewer->SelectPosibleContour( true );*/
637 //------------------------------------------------------------------------------------------------------------
638 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
640 int i, size = theKeyNameVector.size();
641 for( i=0; i< size; i++ )
643 setControlActiveStateOf( theKeyNameVector[i], controlCondition );
647 //------------------------------------------------------------------------------------------------------------
648 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
650 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
651 int i, size = theMap->size();
652 for( i=0; i< size; i++ )
654 removeFromScene( iter->second, false, controlCondition );
659 //------------------------------------------------------------------------------------------------------------
661 //------------------------------------------------------------------------------------------------------------
663 //------------------------------------------------------------------------------------------------------------
664 // Creational and initialization methods
665 //------------------------------------------------------------------------------------------------------------
667 //------------------------------------------------------------------------------------------------------------
669 //------------------------------------------------------------------------------------------------------------
671 bool wxVtkBaseView_SceneManager :: isCtrlPressed()
675 bool wxVtkBaseView_SceneManager :: isShiftPressed()
679 char wxVtkBaseView_SceneManager :: getLastKeyCode()
683 bool wxVtkBaseView_SceneManager :: OnChar()
686 _ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
687 _shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
689 _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
691 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
692 _eventHandler->ProcessEvent( cevent );
695 /*if( _eventHandler!=NULL )
697 char * toolCommand = NULL;
699 if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
701 toolCommand = &(COPY_TOOL);
703 else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
705 toolCommand = &(PASTE_TOOL);
707 else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
709 toolCommand = &(DELETE_KEY);
711 else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
713 toolCommand = &(CREATE_CONTOUR_KEY);
715 else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
717 toolCommand = &(OPEN_TOOL);
719 else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
721 toolCommand = &(SAVE_KEY);
724 if ( toolCommand!=NULL )
726 currentkey = toolCommand;
727 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
728 cevent.SetClientData( (void *) toolCommand);
729 _eventHandler->ProcessEvent( cevent );
734 // long int endtime = clock();
738 //------------------------------------------------------------------------------------------------------------
740 bool wxVtkBaseView_SceneManager :: OnMouseMove()
743 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
744 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnMouseMove() \n" );
747 bool condition = true;
749 wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
750 _wxVTKiren->GetEventPosition( X , Y );
752 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
753 bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
755 if( _waiting && !ctrlKey )
757 sendEnvent( wxEVT_CHANGED_DEEP, "Update");
758 //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
761 if ( !_creatingROI && !_creatingMULT_ROI )
764 /*if( ctrlKey || shiftKey )
770 _toIncludeAtInteractionGroup = false;
773 bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
774 std::string preservingName = preserveState ? _lastInteractionName : "";
776 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
777 int i, size = _sceneContours_ViewControl->size();
778 bool foundOne = false;
780 manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
781 manualViewBaseContour * viewer = NULL;
784 bool singleMoving = true;
785 int selectionSize = _workingGroup->size();
786 if( selectionSize > 1 )
790 bool ckecking = false;
791 for( i =0; i<size ; i++ )
793 control = iter->second->getControler();
794 viewer = iter->second->getViewer();
795 /*ckecking = */control->SetActive( true );
797 if (_lastInteraction != NULL)
799 singleMoving = !_lastInteraction->getViewer()->GetSelected();
804 size = selectionSize;
805 iter = _workingGroup->begin();
811 _toIncludeAtInteractionGroup = false;
814 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
817 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
818 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnMouseMove() 00222\n" );
820 _lastInteraction=NULL;
821 for( i =0; i<size ; i++ )
823 control = iter->second->getControler();
824 viewer = iter->second->getViewer();
825 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
826 control->SetActive( true );
828 foundOne = control->OnMouseMove();
829 foundOne &= viewer->GetPosibleSelected();
831 if ( !foundOne && singleMoving )
833 control->SetActive( false );
834 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
835 control->SetPosibleToMove( false );
839 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
841 _lastInteraction->getControler()->SetActive( true );
844 _lastInteraction = iter->second;
845 _lastInteractionName = iter->first;
847 viewer->UpdateColorActor();
848 control->SetPosibleToMove( true );
849 // viewer->AddCompleteContourActor();
864 //------------------------------------------------------------------------------------------------------------
865 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
869 ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
870 long int endtime = clock();
871 // double sg = (double)(endtime-startTimeAE) / (double)CLK_TCK;
872 fprintf(ff,"wxVtkBaseView_SceneManager :: OnLeftButtonDown() tLBDown = %i \n \n",endtime);
876 char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
877 bool condition = false;
878 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
879 vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
880 wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
881 wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
882 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
884 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
885 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
886 _toIncludeAtInteractionGroup = false;
887 if ( ctrlKey || shftKey )
889 _toIncludeAtInteractionGroup = true;
893 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
895 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
897 _lastInteraction->getControler()->SetEditable( false );
898 _lastInteraction->getControler()->SetActive( false );
899 _lastInteraction->getControler()->SetPosibleToMove( false );
900 _lastInteraction->getViewer()->Refresh();
901 _lastInteraction=NULL;
908 if( !_toIncludeAtInteractionGroup )
910 _workingGroup->clear();
913 if( _lastInteraction!=NULL )
915 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
916 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
917 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
919 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
922 //setControlActiveStateOf( _contours_ViewControl, false );
923 sendEnvent( wxEVT_START_CREATE_ROI, "");
927 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
928 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
929 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
936 //------------------------------------------------------------------------------------------------------------
937 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
939 bool condition = false;
942 if( _drawingSelectionROI )
944 setSelection2DROIInternalOutlines();
948 //------------------------------------------------------------------------------------------------------------
949 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
951 bool condition = false;
956 //------------------------------------------------------------------------------------------------------------
957 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
959 bool condition = false;
964 //------------------------------------------------------------------------------------------------------------
965 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
967 bool condition = false;
968 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
969 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
976 //------------------------------------------------------------------------------------------------------------
977 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
979 bool condition = false;
981 //setControlActiveStateOfALL( false );//************************************************
982 if ( _creatingMULT_ROI )
984 //setControlActiveStateOfALL( false );
988 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
989 _creatingROI = false;
993 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
995 manualContourBaseControler * control = _lastInteraction->getControler();
996 //_lastInteraction->getControler()->SetPosibleToMove( false );
997 control->SetActive( false );
998 control->SetEditable( false );
999 _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
1000 _lastInteraction->getViewer()->Refresh();
1001 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1007 //------------------------------------------------------------------------------------------------------------
1009 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
1011 bool condition = false;
1016 //------------------------------------------------------------------------------------------------------------
1017 bool wxVtkBaseView_SceneManager :: OnRightDClick()
1019 bool condition = false; condition = true;
1020 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
1021 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
1022 wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
1026 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
1027 set_creatingMULT_ROI( !_creatingMULT_ROI );
1035 //------------------------------------------------------------------------------------------------------------
1036 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
1038 bool condition = false;
1043 //------------------------------------------------------------------------------------------------------------
1044 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
1046 bool condition = false;
1050 //------------------------------------------------------------------------------------------------------------
1052 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1054 _drawingSelectionROI = true;
1055 _workingGroup->clear();
1056 _controlerSelectionROI->CreateNewManualContour();
1057 if (_lastInteraction!=NULL)
1059 _lastInteraction->getControler()->SetEditable( false );
1060 _lastInteraction->getControler()->SetActive( false );
1061 _lastInteraction->getControler()->SetPosibleToMove( false );
1062 _lastInteraction->getViewer()->Refresh();
1064 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1065 int i, workSize = _workingGroup->size();
1066 for( i=0; i< workSize; i++ )
1068 manualContourBaseControler * control = iter->second->getControler();
1069 control->SetEditable( false );
1070 control->SetActive( false );
1071 control->SetPosibleToMove( false );
1072 iter->second->getViewer()->Refresh();
1076 _lastInteraction = NULL;
1077 _lastInteractionName = "";
1079 _viewerSelectionROI->AddCompleteContourActor( true );
1080 _controlerSelectionROI->SetActive( true );
1082 _viewerSelectionROI->RefreshContour();
1083 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1085 //------------------------------------------------------------------------------------------------------------
1086 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1088 _drawingSelectionROI = false;
1089 _workingGroup->clear();
1090 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1093 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1094 int i, size = _sceneContours_ViewControl->size();
1095 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1096 manualViewBaseContour * viewer;
1097 bool insideRoi = false;
1098 for ( i=0; i<size; i++ )
1100 viewer = iter->second->getViewer();
1101 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1102 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1105 viewer->SetSelected( true );
1106 viewer->UpdateColorActor();
1107 setControlActiveStateOf( iter->second, true );
1108 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1112 _viewerSelectionROI->RemoveCompleteContourActor( );
1113 _controlerSelectionROI->SetActive( false );
1115 //------------------------------------------------------------------------------------------------------------
1116 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1118 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1119 long int start = clock();
1121 double sg = (double)(start) / (double)CLK_TCK;
1123 double sg = (double)(start) / CLOCKS_PER_SEC;
1126 wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1127 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1128 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): \n \n",method.c_str(), tmpPx, tmpPy, sg);
1133 //------------------------------------------------------------------------------------------------------------
1134 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1136 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1137 manualViewBaseContour * cViewer;
1138 manualContourBaseControler * cControler;
1139 ContourWrap_ViewControl *conwraviwcont=iter->second;
1141 cViewer = conwraviwcont->getViewer();
1144 cControler = conwraviwcont->getControler();
1145 // cControler->Save(ff);
1147 // cModel = cControler->GetManualContourModel();
1148 // cModel->Save(ff);
1152 //------------------------------------------------------------------------------------------------------------
1153 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1155 std::vector<std::string> currentSelection = this->getSelectedObjects();
1156 if (currentSelection.size()>=1){
1158 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1159 manualContourModel *cModel = cControler->GetManualContourModel();
1160 int i,size = cModel->GetNumberOfPointsSpline();
1162 for (i=0; i<size; i++)
1164 cModel->GetSpline_i_Point(i, &x, &y, &z);
1172 //------------------------------------------------------------------------------------------------------------
1173 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1175 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1176 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1179 //------------------------------------------------------------------------------------------------------------
1180 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1183 vtkImageData *imagedata = GetImageData();
1184 imagedata->GetExtent(ext);
1185 int sizeZ = ext[5]-ext[4]+1;
1193 //------------------------------------------------------------------------------------------------------------
1194 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1197 vtkImageData *imagedata = GetImageData();
1198 imagedata->GetExtent(ext);
1199 int sizeX = ext[1]-ext[0]+1;
1200 int sizeY = ext[3]-ext[2]+1;
1201 int sizeZ = GetImageDataSizeZ();
1202 int sizeXYZ = sizeX*sizeY*sizeZ;
1206 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1207 for (i=0;i<sizeXYZ;i++)
1209 if ( p[i]<range[0] ) range[0]=p[i];
1210 if ( p[i]>range[1] ) range[1]=p[i];
1214 //------------------------------------------------------------------------------------------------------------
1215 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1217 _widthOfContour = width;
1218 manualViewBaseContour *cViewer;
1219 ContourWrap_ViewControl *conwraviwcont;
1220 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;;
1222 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1224 conwraviwcont = iter->second;
1225 cViewer = conwraviwcont->getViewer();
1226 cViewer->SetWidthLine(_widthOfContour);
1230 bool wxVtkBaseView_SceneManager::isEditableCControler(std::string theKeyName){
1232 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1234 manualContourBaseControler* cControler = ccon->getControler();
1235 if(cControler != NULL && cControler->IsEditable() == false){
1242 void wxVtkBaseView_SceneManager::deleteCViewerCControler(std::string theKeyName){
1245 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1247 manualViewBaseContour * cViewer = ccon->getViewer();
1248 manualContourBaseControler * cControler = ccon->getControler();
1250 removeFromScene(theKeyName);
1251 removeWrap(theKeyName);