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 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
171 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: configureViewControlTo \n" );
172 //fprintf(ff," %s %p \n",theKeyName.c_str() , manContourControl );
176 _lastInteraction = insertWrap( theKeyName, manContourControl, manViewerContour );
177 _lastInteractionName = theKeyName;
179 //Configuring the relations between the contour members representation
180 manViewerContour->SetModel( manModelContour );
181 manViewerContour->SetWxVtkBaseView( _wxVtk_BaseView );
182 manViewerContour->SetRange( 2 );
183 manViewerContour->SetZ( 1000 );
185 manViewerContour->SetSpacing(spc);
187 manViewerContour->SetColorNormalContour(0, 0, 1);
188 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
189 manViewerContour->SetColorSelectContour(1, 0.8, 0);
190 manViewerContour->SetWidthLine(_widthOfContour);
192 manContourControl->SetModelView( manModelContour , manViewerContour );
193 manContourControl->Configure();
194 int i,sizeLstPoints = manModelContour->GetSizeLstPoints();
195 for ( i=0; i<sizeLstPoints; i++ )
197 manViewerContour->AddPoint();
200 manContourControl->CreateNewManualContour();
201 manViewerContour->RefreshContour();
202 addToScene( theKeyName );
204 //------------------------------------------------------------------------------------------------------------
205 void wxVtkBaseView_SceneManager :: configureSelectionROI( double * spc )
207 _controlerSelectionROI = new manualRoiControler();
208 _viewerSelectionROI = new manualViewRoi();
209 _modelSelectionROI = new manualContourModel();
211 _viewerSelectionROI->SetModel( _modelSelectionROI );
212 _viewerSelectionROI->SetWxVtkBaseView( _wxVtk_BaseView );
213 _viewerSelectionROI->SetRange( 2 );
214 _viewerSelectionROI->SetZ( 1000 );
215 _viewerSelectionROI->SetColorNormalContour(0.6, 0.8, 0);
217 _viewerSelectionROI->SetSpacing( spc );
219 _controlerSelectionROI->SetModelView( _modelSelectionROI , _viewerSelectionROI );
220 _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _controlerSelectionROI );
221 _controlerSelectionROI->SetActive(false);
224 //------------------------------------------------------------------------------------------------------------
225 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: insertWrap( std::string theKeyName, manualContourBaseControler * manContourControl, manualViewBaseContour * manViewerContour )
227 ContourWrap_ViewControl * newContourWrap = new ContourWrap_ViewControl(manContourControl, manViewerContour);
228 _contours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, newContourWrap ));
229 return newContourWrap;
231 //------------------------------------------------------------------------------------------------------------
232 void wxVtkBaseView_SceneManager :: desconfigureViewControlOf( std::string theKeyName )
236 //------------------------------------------------------------------------------------------------------------
237 void wxVtkBaseView_SceneManager :: removeWrap( std::string theKeyName )
239 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
240 iter = _contours_ViewControl->find( theKeyName );
241 _contours_ViewControl->erase( iter );
242 _lastInteraction=NULL;
243 _lastInteractionName = "";
244 _workingGroup->clear();
245 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
246 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
248 //------------------------------------------------------------------------------------------------------------
249 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName )
251 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
252 iter = _contours_ViewControl->find( theName );
254 //return iter->first;
256 //------------------------------------------------------------------------------------------------------------
257 ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName, std::map<std::string, ContourWrap_ViewControl *> * theMap )
259 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
260 iter = theMap->find( theName );
263 //------------------------------------------------------------------------------------------------------------
264 manualContourBaseControler * wxVtkBaseView_SceneManager :: getControlerOf( std::string theName )
266 return getContourWrap_ViewControlOf ( theName )->getControler();
268 //------------------------------------------------------------------------------------------------------------
269 manualViewBaseContour * wxVtkBaseView_SceneManager :: getViewerOf( std::string theName )
271 return getContourWrap_ViewControlOf ( theName )->getViewer();
273 //------------------------------------------------------------------------------------------------------------
274 void wxVtkBaseView_SceneManager :: set_creatingMULT_ROI( bool condition )
276 _creatingMULT_ROI = condition;
278 //------------------------------------------------------------------------------------------------------------
279 void wxVtkBaseView_SceneManager :: set_editingROI( bool condition )
281 _editingROI = condition;
283 //------------------------------------------------------------------------------------------------------------
284 void wxVtkBaseView_SceneManager :: set_toIncludeAtInteractionGroup( bool condition )
286 _toIncludeAtInteractionGroup = condition;
288 //------------------------------------------------------------------------------------------------------------
289 void wxVtkBaseView_SceneManager :: set_waiting( bool condition )
291 _waiting = condition;
293 //------------------------------------------------------------------------------------------------------------
294 bool wxVtkBaseView_SceneManager :: get_creatingMULT_ROI( )
296 return _creatingMULT_ROI;
298 //------------------------------------------------------------------------------------------------------------
299 bool wxVtkBaseView_SceneManager :: get_editingROI( )
303 //------------------------------------------------------------------------------------------------------------
304 bool wxVtkBaseView_SceneManager :: get_toIncludeAtInteractionGroup( )
306 return _toIncludeAtInteractionGroup;
309 //------------------------------------------------------------------------------------------------------------
310 bool wxVtkBaseView_SceneManager :: get_waiting( )
315 //------------------------------------------------------------------------------------------------------------
316 bool wxVtkBaseView_SceneManager :: get_creatingROI()
320 //------------------------------------------------------------------------------------------------------------
321 void wxVtkBaseView_SceneManager :: set_creatingROI( bool condition )
323 _creatingROI = condition;
326 //------------------------------------------------------------------------------------------------------------
327 // Other functional methods
328 //------------------------------------------------------------------------------------------------------------
330 void wxVtkBaseView_SceneManager :: createCopyContourOf( std::string anExistingKName, std::string cloneName, manualContourModel * manualModel, bool append )
334 setControlActiveStateOf( _workingGroup, false );
335 _workingGroup->clear();
337 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
340 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
341 // fprintf(ff,"EED wxVtkBaseView_SceneManager::createCopyContourOf() \n" );
342 // int ii,size = _contours_ViewControl->size();
343 // iter = _contours_ViewControl->begin();
344 // for (ii=0;ii<size;ii++)
346 // fprintf(ff," %d %s\n ", ii ,iter->first.c_str() );
351 iter = _contours_ViewControl->find( anExistingKName );
353 manualContourModel *cModule = manualModel;
354 manualViewBaseContour *cViewer = iter->second->getViewer()->Clone();
355 manualContourBaseControler *cControl = iter->second->getControler()->Clone( );
357 cViewer->SetModel(cModule);
358 cControl->SetModelView( cModule , cViewer );
359 cControl->CreateNewManualContour();
360 cControl->SetActive( true );
361 cControl->SetEditable( false );
363 cViewer->RefreshContour();
365 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
366 this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
368 _lastInteraction = insertWrap( cloneName, cControl, cViewer );
369 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( cloneName, _lastInteraction ));
370 addToScene( cloneName );
373 //------------------------------------------------------------------------------------------------------------
375 void wxVtkBaseView_SceneManager :: removeFromScene( ContourWrap_ViewControl * contourWRP, bool visualization, bool control )
377 if( contourWRP == _lastInteraction )
379 _lastInteraction = NULL;
380 _lastInteractionName = "";
384 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
385 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeFromScene \n" );
386 //fprintf(ff," %p \n", contourWRP->getControler() );
389 _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( contourWRP->getControler() );
391 contourWRP->getControler()->SetActive( control );
392 contourWRP->getControler()->SetEditable( false );
394 if ( !visualization && control )
396 contourWRP->getViewer()->RemoveControlPoints( );
397 contourWRP->getViewer()->RemoveTextActor( );
401 contourWRP->getViewer()->RemoveCompleteContourActor();
405 //------------------------------------------------------------------------------------------------------------
406 void wxVtkBaseView_SceneManager :: removeFromScene( std::string theKeyName, bool visualization , bool control )
409 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
410 iter = _sceneContours_ViewControl->find( theKeyName );
411 if (iter != _sceneContours_ViewControl->end()){
412 ContourWrap_ViewControl * contourWRP = iter->second;
413 removeFromScene( contourWRP );
415 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
416 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeFromScene Bbbbb \n" );
417 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
418 _sceneContours_ViewControl->erase(iter);
421 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
426 //------------------------------------------------------------------------------------------------------------
427 std::vector<std::string> wxVtkBaseView_SceneManager::GetlstContoursNameActualSlice()
429 std::vector<std::string> lstContoursNameActualSlice;
430 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
431 int i,size = _sceneContours_ViewControl->size();
432 for ( i = 0; i<size; i++ )
434 lstContoursNameActualSlice.push_back( iter->first );
437 return lstContoursNameActualSlice;
440 //------------------------------------------------------------------------------------------------------------
441 void wxVtkBaseView_SceneManager :: removeSceneContours( )
444 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
445 //fprintf(ff,"EED wxVtkBaseView_SceneManager :: removeSceneContours \n" );
446 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
447 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
448 int size = _sceneContours_ViewControl->size();
449 for ( int i = 0; i<size; i++ )
451 removeFromScene( iter->second );
454 _sceneContours_ViewControl->clear();
457 //fprintf(ff," %d \n", _sceneContours_ViewControl->size() );
460 //Removing the selection rectangle to avoid showing when it's innecesary
461 _controlerSelectionROI->SetActive( false );
462 _viewerSelectionROI->RemoveCompleteContourActor();
465 void wxVtkBaseView_SceneManager::removeAllOutlines()
467 manualViewBaseContour * cViewer;
468 manualContourBaseControler * cControler;
470 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
471 int i,size=_contours_ViewControl->size();
474 iter = _contours_ViewControl->begin();
475 cControler = iter->second->getControler();
476 cViewer = iter->second->getViewer();
477 removeWrap( iter->first );
485 //------------------------------------------------------------------------------------------------------------
486 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
490 removeSceneContours();
492 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
493 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
495 addToScene( theKeyName, contourWRP, true, visualization, control, ifActive, ifShowCtrlPoints);
498 //------------------------------------------------------------------------------------------------------------
499 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
503 removeSceneContours();
505 _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
508 contourWRP->getViewer()->AddCompleteContourActor( ifShowCtrlPoints );
513 _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( contourWRP->getControler() );
517 contourWRP->getControler()->SetActive( true );
518 contourWRP->getViewer()->RemoveTextActor();
522 //------------------------------------------------------------------------------------------------------------
523 void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
525 int i, size = theKeyNameVector.size();
526 for( i=0; i< size; i++ )
528 removeFromScene( theKeyNameVector[i], visualization, control );
532 //------------------------------------------------------------------------------------------------------------
533 void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
535 int i, size = theKeyNameVector.size();
536 for( i=0; i< size; i++ )
538 addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
542 //------------------------------------------------------------------------------------------------------------
543 void wxVtkBaseView_SceneManager :: setControlActiveStateOfALL( bool stateCondition )
545 setControlActiveStateOf( _contours_ViewControl, stateCondition );
548 //------------------------------------------------------------------------------------------------------------
549 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
551 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
552 setControlActiveStateOf( contourWRP, stateCondition );
555 //------------------------------------------------------------------------------------------------------------
556 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( ContourWrap_ViewControl * contourWRP, bool stateCondition )
558 contourWRP->getControler()->SetActive( stateCondition );
559 contourWRP->getControler()->SetEditable( false );
562 //------------------------------------------------------------------------------------------------------------
563 void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
565 ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
566 // contourWRP->getViewer()->SetVisible( stateCondition );
567 if ( contourWRP!=NULL )
568 removeFromScene( contourWRP, false, stateCondition );
571 //------------------------------------------------------------------------------------------------------------
572 std::vector< std::string > wxVtkBaseView_SceneManager :: getSelectedObjects()
574 std::vector< std::string > selectedObjects;
575 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
576 int size = _workingGroup->size();
577 for ( int i = 0; i<size; i++ )
579 manualViewBaseContour * viewer = iter->second->getViewer();
580 selectedObjects.push_back( iter->first);
584 return selectedObjects;
586 //------------------------------------------------------------------------------------------------------------
587 void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
589 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
590 int size = _contours_ViewControl->size();
592 /*for ( int i = 0; i<size; i++ )
595 manualViewBaseContour * viewer = iter->second->getViewer();
596 std::vector <std::string >::iterator iterIN;
598 for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
600 if( iter->first.compare( theExistingObjectsToSelect[i] ) )
602 viewer->SelectAllPoints( true );
603 viewer->SelectPosibleContour( true );
605 theExistingObjectsToSelect.erase( iterIN );
613 //------------------------------------------------------------------------------------------------------------
614 void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
616 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
617 int size = _contours_ViewControl->size();
618 for ( int i = 0; i<size; i++ )
620 manualViewBaseContour * viewer = iter->second->getViewer();
622 viewer->SetSelected( true );
623 /*viewer->SelectAllPoints( true );
624 viewer->SelectPosibleContour( true );*/
630 //------------------------------------------------------------------------------------------------------------
631 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
633 int i, size = theKeyNameVector.size();
634 for( i=0; i< size; i++ )
636 setControlActiveStateOf( theKeyNameVector[i], controlCondition );
640 //------------------------------------------------------------------------------------------------------------
641 void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
643 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
644 int i, size = theMap->size();
645 for( i=0; i< size; i++ )
647 removeFromScene( iter->second, false, controlCondition );
652 //------------------------------------------------------------------------------------------------------------
654 //------------------------------------------------------------------------------------------------------------
656 //------------------------------------------------------------------------------------------------------------
657 // Creational and initialization methods
658 //------------------------------------------------------------------------------------------------------------
660 //------------------------------------------------------------------------------------------------------------
662 //------------------------------------------------------------------------------------------------------------
664 bool wxVtkBaseView_SceneManager :: isCtrlPressed()
668 bool wxVtkBaseView_SceneManager :: isShiftPressed()
672 char wxVtkBaseView_SceneManager :: getLastKeyCode()
676 bool wxVtkBaseView_SceneManager :: OnChar()
679 _ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
680 _shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
682 _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
684 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
685 _eventHandler->ProcessEvent( cevent );
688 /*if( _eventHandler!=NULL )
690 char * toolCommand = NULL;
692 if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
694 toolCommand = &(COPY_TOOL);
696 else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
698 toolCommand = &(PASTE_TOOL);
700 else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
702 toolCommand = &(DELETE_KEY);
704 else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
706 toolCommand = &(CREATE_CONTOUR_KEY);
708 else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
710 toolCommand = &(OPEN_TOOL);
712 else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
714 toolCommand = &(SAVE_KEY);
717 if ( toolCommand!=NULL )
719 currentkey = toolCommand;
720 wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
721 cevent.SetClientData( (void *) toolCommand);
722 _eventHandler->ProcessEvent( cevent );
727 // long int endtime = clock();
731 //------------------------------------------------------------------------------------------------------------
733 bool wxVtkBaseView_SceneManager :: OnMouseMove()
736 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
737 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnMouseMove() \n" );
740 bool condition = true;
742 wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
743 _wxVTKiren->GetEventPosition( X , Y );
745 bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
746 bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
748 if( _waiting && !ctrlKey )
750 sendEnvent( wxEVT_CHANGED_DEEP, "Update");
751 //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
754 if ( !_creatingROI && !_creatingMULT_ROI )
757 /*if( ctrlKey || shiftKey )
763 _toIncludeAtInteractionGroup = false;
766 bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
767 std::string preservingName = preserveState ? _lastInteractionName : "";
769 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
770 int i, size = _sceneContours_ViewControl->size();
771 bool foundOne = false;
773 manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
774 manualViewBaseContour * viewer = NULL;
777 bool singleMoving = true;
778 int selectionSize = _workingGroup->size();
779 if( selectionSize > 1 )
783 bool ckecking = false;
784 for( i =0; i<size ; i++ )
786 control = iter->second->getControler();
787 viewer = iter->second->getViewer();
788 /*ckecking = */control->SetActive( true );
790 if (_lastInteraction != NULL)
792 singleMoving = !_lastInteraction->getViewer()->GetSelected();
797 size = selectionSize;
798 iter = _workingGroup->begin();
804 _toIncludeAtInteractionGroup = false;
807 if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
810 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
811 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnMouseMove() 00222\n" );
813 _lastInteraction=NULL;
814 for( i =0; i<size ; i++ )
816 control = iter->second->getControler();
817 viewer = iter->second->getViewer();
818 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
819 control->SetActive( true );
821 foundOne = control->OnMouseMove();
822 foundOne &= viewer->GetPosibleSelected();
824 if ( !foundOne && singleMoving )
826 control->SetActive( false );
827 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
828 control->SetPosibleToMove( false );
832 if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
834 _lastInteraction->getControler()->SetActive( true );
837 _lastInteraction = iter->second;
838 _lastInteractionName = iter->first;
840 viewer->UpdateColorActor();
841 control->SetPosibleToMove( true );
842 // viewer->AddCompleteContourActor();
857 //------------------------------------------------------------------------------------------------------------
858 bool wxVtkBaseView_SceneManager :: OnLeftButtonDown()
862 ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
863 long int endtime = clock();
864 // double sg = (double)(endtime-startTimeAE) / (double)CLK_TCK;
865 fprintf(ff,"wxVtkBaseView_SceneManager :: OnLeftButtonDown() tLBDown = %i \n \n",endtime);
869 char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
870 bool condition = false;
871 //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
872 vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
873 wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
874 wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
875 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
877 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
878 bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
879 _toIncludeAtInteractionGroup = false;
880 if ( ctrlKey || shftKey )
882 _toIncludeAtInteractionGroup = true;
886 if( _lastInteraction!=NULL && !_toIncludeAtInteractionGroup )
888 if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
890 _lastInteraction->getControler()->SetEditable( false );
891 _lastInteraction->getControler()->SetActive( false );
892 _lastInteraction->getControler()->SetPosibleToMove( false );
893 _lastInteraction->getViewer()->Refresh();
894 _lastInteraction=NULL;
901 if( !_toIncludeAtInteractionGroup )
903 _workingGroup->clear();
906 if( _lastInteraction!=NULL )
908 _toIncludeAtInteractionGroup = !_lastInteraction->getControler()->IsEditable();
909 _toIncludeAtInteractionGroup &= _lastInteraction->getViewer()->GetSelected();
910 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
912 if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
915 //setControlActiveStateOf( _contours_ViewControl, false );
916 sendEnvent( wxEVT_START_CREATE_ROI, "");
920 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
921 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
922 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
929 //------------------------------------------------------------------------------------------------------------
930 bool wxVtkBaseView_SceneManager :: OnLeftButtonUp()
932 bool condition = false;
935 if( _drawingSelectionROI )
937 setSelection2DROIInternalOutlines();
941 //------------------------------------------------------------------------------------------------------------
942 bool wxVtkBaseView_SceneManager :: OnMiddleButtonDown()
944 bool condition = false;
949 //------------------------------------------------------------------------------------------------------------
950 bool wxVtkBaseView_SceneManager :: OnMiddleButtonUp()
952 bool condition = false;
957 //------------------------------------------------------------------------------------------------------------
958 bool wxVtkBaseView_SceneManager :: OnRightButtonDown()
960 bool condition = false;
961 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
962 bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
969 //------------------------------------------------------------------------------------------------------------
970 bool wxVtkBaseView_SceneManager :: OnRightButtonUp()
972 bool condition = false;
974 //setControlActiveStateOfALL( false );//************************************************
975 if ( _creatingMULT_ROI )
977 //setControlActiveStateOfALL( false );
981 sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
982 _creatingROI = false;
986 if(_lastInteraction!=NULL && !_toIncludeAtInteractionGroup)
988 manualContourBaseControler * control = _lastInteraction->getControler();
989 //_lastInteraction->getControler()->SetPosibleToMove( false );
990 control->SetActive( false );
991 control->SetEditable( false );
992 _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
993 _lastInteraction->getViewer()->Refresh();
994 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1000 //------------------------------------------------------------------------------------------------------------
1002 bool wxVtkBaseView_SceneManager :: OnLeftDClick()
1004 bool condition = false;
1009 //------------------------------------------------------------------------------------------------------------
1010 bool wxVtkBaseView_SceneManager :: OnRightDClick()
1012 bool condition = false; condition = true;
1013 vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
1014 /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
1015 wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
1019 sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
1020 set_creatingMULT_ROI( !_creatingMULT_ROI );
1028 //------------------------------------------------------------------------------------------------------------
1029 bool wxVtkBaseView_SceneManager :: OnMiddleDClick()
1031 bool condition = false;
1036 //------------------------------------------------------------------------------------------------------------
1037 bool wxVtkBaseView_SceneManager :: OnMouseWheel()
1039 bool condition = false;
1043 //------------------------------------------------------------------------------------------------------------
1045 void wxVtkBaseView_SceneManager :: drawSelectionROI()
1047 _drawingSelectionROI = true;
1048 _workingGroup->clear();
1049 _controlerSelectionROI->CreateNewManualContour();
1050 if (_lastInteraction!=NULL)
1052 _lastInteraction->getControler()->SetEditable( false );
1053 _lastInteraction->getControler()->SetActive( false );
1054 _lastInteraction->getControler()->SetPosibleToMove( false );
1055 _lastInteraction->getViewer()->Refresh();
1057 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1058 int i, workSize = _workingGroup->size();
1059 for( i=0; i< workSize; i++ )
1061 manualContourBaseControler * control = iter->second->getControler();
1062 control->SetEditable( false );
1063 control->SetActive( false );
1064 control->SetPosibleToMove( false );
1065 iter->second->getViewer()->Refresh();
1069 _lastInteraction = NULL;
1070 _lastInteractionName = "";
1072 _viewerSelectionROI->AddCompleteContourActor( true );
1073 _controlerSelectionROI->SetActive( true );
1075 _viewerSelectionROI->RefreshContour();
1076 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1078 //------------------------------------------------------------------------------------------------------------
1079 void wxVtkBaseView_SceneManager :: setSelection2DROIInternalOutlines( )
1081 _drawingSelectionROI = false;
1082 _workingGroup->clear();
1083 double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1086 std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1087 int i, size = _sceneContours_ViewControl->size();
1088 _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1089 manualViewBaseContour * viewer;
1090 bool insideRoi = false;
1091 for ( i=0; i<size; i++ )
1093 viewer = iter->second->getViewer();
1094 viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1095 insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1098 viewer->SetSelected( true );
1099 viewer->UpdateColorActor();
1100 setControlActiveStateOf( iter->second, true );
1101 _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1105 _viewerSelectionROI->RemoveCompleteContourActor( );
1106 _controlerSelectionROI->SetActive( false );
1108 //------------------------------------------------------------------------------------------------------------
1109 void wxVtkBaseView_SceneManager :: writeCoords( std::string method )
1111 FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1112 long int start = clock();
1114 double sg = (double)(start) / (double)CLK_TCK;
1116 double sg = (double)(start) / CLOCKS_PER_SEC;
1119 wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1120 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1121 fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): \n \n",method.c_str(), tmpPx, tmpPy, sg);
1126 //------------------------------------------------------------------------------------------------------------
1127 void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1129 std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1130 manualViewBaseContour * cViewer;
1131 manualContourBaseControler * cControler;
1132 ContourWrap_ViewControl *conwraviwcont=iter->second;
1134 cViewer = conwraviwcont->getViewer();
1137 cControler = conwraviwcont->getControler();
1138 // cControler->Save(ff);
1140 // cModel = cControler->GetManualContourModel();
1141 // cModel->Save(ff);
1145 //------------------------------------------------------------------------------------------------------------
1146 void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1148 std::vector<std::string> currentSelection = this->getSelectedObjects();
1149 if (currentSelection.size()>=1){
1151 manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1152 manualContourModel *cModel = cControler->GetManualContourModel();
1153 int i,size = cModel->GetNumberOfPointsSpline();
1155 for (i=0; i<size; i++)
1157 cModel->GetSpline_i_Point(i, &x, &y, &z);
1165 //------------------------------------------------------------------------------------------------------------
1166 vtkImageData *wxVtkBaseView_SceneManager::GetImageData()
1168 wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1169 return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1172 //------------------------------------------------------------------------------------------------------------
1173 int wxVtkBaseView_SceneManager::GetImageDataSizeZ()
1176 vtkImageData *imagedata = GetImageData();
1177 imagedata->GetExtent(ext);
1178 int sizeZ = ext[5]-ext[4]+1;
1186 //------------------------------------------------------------------------------------------------------------
1187 void wxVtkBaseView_SceneManager::GetImageDataRange( double *range )
1190 vtkImageData *imagedata = GetImageData();
1191 imagedata->GetExtent(ext);
1192 int sizeX = ext[1]-ext[0]+1;
1193 int sizeY = ext[3]-ext[2]+1;
1194 int sizeZ = GetImageDataSizeZ();
1195 int sizeXYZ = sizeX*sizeY*sizeZ;
1199 unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1200 for (i=0;i<sizeXYZ;i++)
1202 if ( p[i]<range[0] ) range[0]=p[i];
1203 if ( p[i]>range[1] ) range[1]=p[i];
1207 //------------------------------------------------------------------------------------------------------------
1208 void wxVtkBaseView_SceneManager::SetWidthContour(double width)
1210 _widthOfContour = width;
1211 manualViewBaseContour *cViewer;
1212 ContourWrap_ViewControl *conwraviwcont;
1213 std::map <std::string, ContourWrap_ViewControl *>::iterator iter;;
1215 for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1217 conwraviwcont = iter->second;
1218 cViewer = conwraviwcont->getViewer();
1219 cViewer->SetWidthLine(_widthOfContour);
1223 bool wxVtkBaseView_SceneManager::isEditableCControler(std::string theKeyName){
1225 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1227 manualContourBaseControler* cControler = ccon->getControler();
1228 if(cControler != NULL && cControler->IsEditable() == false){
1235 void wxVtkBaseView_SceneManager::deleteCViewerCControler(std::string theKeyName){
1238 ContourWrap_ViewControl* ccon = getContourWrap_ViewControlOf(theKeyName);
1240 manualViewBaseContour * cViewer = ccon->getViewer();
1241 manualContourBaseControler * cControler = ccon->getControler();
1243 removeFromScene(theKeyName);
1244 removeWrap(theKeyName);