creaContours_lib
wxVtkBaseView_SceneManager.cxx
Go to the documentation of this file.
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 # pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
15 #
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
20 # liability.
21 #
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25 
26 
27 //----------------------------------------------------------------------------------------------------------------
28 // Class definition include
29 //----------------------------------------------------------------------------------------------------------------
31 #include "wxVtk2DBaseView.h"
32 
33 //----------------------------------------------------------------------------------------------------------------
34 // Class implementation
35 //----------------------------------------------------------------------------------------------------------------
39 //------------------------------------------------------------------------------------------------------------
40 // Includes
41 //------------------------------------------------------------------------------------------------------------
43 
44 //------------------------------------------------------------------------------------------------------------
45 // Generated events declaration and definition
46 //------------------------------------------------------------------------------------------------------------
47 
48 DEFINE_EVENT_TYPE( wxEVT_START_CREATE_MULT_ROI )
49 DEFINE_EVENT_TYPE( wxEVT_STOP_CREATE_MULT_ROI )
50 DEFINE_EVENT_TYPE( wxEVT_START_CREATE_ROI )
51 DEFINE_EVENT_TYPE( wxEVT_STOP_CREATE_ROI )
52 DEFINE_EVENT_TYPE( wxEVT_DELETE_ROI )
53 DEFINE_EVENT_TYPE( wxEVT_SELECTED_MULT_ROI )
54 DEFINE_EVENT_TYPE( wxEVT_SELECTED_ROI )
55 DEFINE_EVENT_TYPE( wxEVT_UNSLECTED_ROI )
56 DEFINE_EVENT_TYPE( wxEVT_MANUAL_HIDED_ROI )
57 DEFINE_EVENT_TYPE( wxEVT_MANUAL_SHOWED_ROI )
58 DEFINE_EVENT_TYPE( wxEVT_EDITING_ROI )
59 DEFINE_EVENT_TYPE( wxEVT_MOVING_ROI )
60 DEFINE_EVENT_TYPE( wxEVT_MOVING_ROI_POINT )
61 DEFINE_EVENT_TYPE( wxEVT_SELECTED_ROI_POINT )
62 DEFINE_EVENT_TYPE( wxEVT_UNSELECTED_ROI_POINT )
63 DEFINE_EVENT_TYPE( wxEVT_CHANGED_DEEP )
64 
65 
66  wxVtkBaseView_SceneManager :: wxVtkBaseView_SceneManager( wxVtkBaseView * theWxBaseViewToManage, wxEvtHandler * theEventHandler, double * spc )
67  {
68 
69  _lastInteraction = NULL;
70  _lastInteractionName = "";
71  _eventHandler = theEventHandler;
72  _leftClickCount = 0;
73  _rigthClickCount = 0;
74 
75  _contours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
76  _sceneContours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
77  _workingGroup = new std::map< std::string, ContourWrap_ViewControl * >();
78 
79  _creatingMULT_ROI = false;
80  _editingROI = false;
81  _toIncludeAtInteractionGroup = false;
82  _waiting = false;
83  _creatingROI = false;
84  _drawingSelectionROI = false;
85  SetWidthContour(1.0);
86 
87  _wxVtk_BaseView = theWxBaseViewToManage;
88  if( _wxVtk_BaseView!=NULL )
89  {
90  vtkInteractorStyleBaseView* theInteractorStyleBaseView = (vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView();
91  theInteractorStyleBaseView->AddInteractorStyleMaracas( this );
92  SetVtkInteractorStyleBaseView( theInteractorStyleBaseView );
93  }
94  configureSelectionROI( spc );
95  }
96  //------------------------------------------------------------------------------------------------------------
98  {
99  std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
100  int size = _contours_ViewControl->size();
101  for ( int i = 0; i<size; iter++ )
102  {
103  _contours_ViewControl->erase( iter );
104  i++;
105  }
106  _contours_ViewControl->clear();
107  delete _contours_ViewControl;
108  _workingGroup->clear();
109  delete _lastInteraction;
110  delete _workingGroup;
111  //delete _contours_ViewControl;
112  }
113 
114  //------------------------------------------------------------------------------------------------------------
115  // Methods for capturing events
116  //------------------------------------------------------------------------------------------------------------
117 
118 
119  //------------------------------------------------------------------------------------------------------------
120  // Methods for sending events
121  //------------------------------------------------------------------------------------------------------------
122  void wxVtkBaseView_SceneManager :: sendEnvent( WXTYPE theEventType, std::string text )
123  {
124  if ( _eventHandler != NULL )
125  {
126  wxCommandEvent cevent( theEventType );
127  cevent.SetString( wxString( text.c_str(), wxConvUTF8) );
128  _eventHandler->ProcessEvent( cevent );
129  }
130  }
131 
132 
133  //------------------------------------------------------------------------------------------------------------
134  // Attributes getters and setters
135  //------------------------------------------------------------------------------------------------------------
136  void wxVtkBaseView_SceneManager :: setWxEventHandler( wxEvtHandler * theEventHandler )
137  {
138  _eventHandler = theEventHandler;
139  }
140  //------------------------------------------------------------------------------------------------------------
141  void wxVtkBaseView_SceneManager :: setWxVtkViewBase( wxVtkBaseView * theBaseView )
142  {
143  _wxVtk_BaseView = theBaseView;
144  }
145 
146  //------------------------------------------------------------------------------------------------------------
148  {
149  return _wxVtk_BaseView;
150  }
151  //------------------------------------------------------------------------------------------------------------
152  void wxVtkBaseView_SceneManager :: configureViewControlTo( std::string theKeyName, manualBaseModel * manModelContour, double * spc,int typeContour)
153  {
154  //setControlActiveStateOfALL( false );
155  _creatingROI = true;
156  _waiting = false;
157  if( _lastInteraction!=NULL )
158  {
159  _lastInteraction->getControler()->SetEditable( false );
160  _lastInteraction->getViewer()->Refresh();
161  _lastInteraction->getControler()->SetActive( false );
162  this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
163  }
164 
165 
166  manualContourBaseControler *manContourControl;
167  manualViewBaseContour *manViewerContour;
168 
169  // Creating the view manualViewContour and the manualContourControler
170  // NOTE: The model is created in the KernelManagerContour class, factoryManualContourModel method
171  if (typeContour==1)
172  {
173  manContourControl = new manualContourControler();
174  manViewerContour = new manualViewContour();
175  }
176 
177  if (typeContour==2)
178  {
179  manContourControl = new manualRoiControler();
180  manViewerContour = new manualViewRoi();
181  }
182 
183  if (typeContour==3)
184  {
185  manContourControl = new manualCircleControler();
186  manViewerContour = new manualViewCircle();
187  }
188 
189  if (typeContour==4)
190  {
191  manContourControl = new manualRoiControler();
192  manViewerContour = new manualViewBullEye();
193  }
194 
195  if (typeContour==6)
196  {
197  manContourControl = new manualLineControler();
198  manViewerContour = new manualViewLine();
199  }
200 
201  //Points
202  if (typeContour==7)
203  {
204  manContourControl = new manualContourControler();
205  manViewerContour = new manualViewPoints();
206  }
207 
208  //Polygon
209  if (typeContour==10)
210  {
211  manContourControl = new manualContourControler();
212  manViewerContour = new manualViewContour();
213  }
214 
215 
216 
217  _lastInteraction = insertWrap( theKeyName, manContourControl, manViewerContour );
218  _lastInteractionName = theKeyName;
219 
220  //Configuring the relations between the contour members representation
221  manViewerContour->SetModel( manModelContour );
222  manViewerContour->SetWxVtkBaseView( _wxVtk_BaseView );
223  manViewerContour->SetRange( _widthOfControlPoint );
224  manViewerContour->SetZ( -900 );
225 
226  manViewerContour->SetSpacing(spc);
227 
228  manViewerContour->SetColorNormalContour(0, 0, 1);
229  manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
230  manViewerContour->SetColorSelectContour(1, 0.8, 0);
231  manViewerContour->SetWidthLine(_widthOfContour);
232 
233  manContourControl->SetModelView( manModelContour , manViewerContour );
234  manContourControl->Configure();
235  int i,sizeLstPoints = manModelContour->GetSizeLstPoints();
236  for ( i=0; i<sizeLstPoints; i++ )
237  {
238  manViewerContour->AddPoint();
239  }
240 
241  manContourControl->CreateNewManualContour();
242  manViewerContour->RefreshContour();
243  addToScene( theKeyName );
244  }
245  //------------------------------------------------------------------------------------------------------------
247  {
248  _controlerSelectionROI = new manualRoiControler();
249  _viewerSelectionROI = new manualViewRoi();
250  _modelSelectionROI = new manualContourModel();
251 
253  _viewerSelectionROI->SetWxVtkBaseView( _wxVtk_BaseView );
254  _viewerSelectionROI->SetRange( 2 );
255  _viewerSelectionROI->SetZ( -900 );
256  _viewerSelectionROI->SetColorNormalContour(0.6, 0.8, 0);
257 
258  _viewerSelectionROI->SetSpacing( spc );
259 
261  ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _controlerSelectionROI );
262  _controlerSelectionROI->SetActive(false);
263  }
264 
265  //------------------------------------------------------------------------------------------------------------
266  ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: insertWrap( std::string theKeyName, manualContourBaseControler * manContourControl, manualViewBaseContour * manViewerContour )
267  {
268  ContourWrap_ViewControl * newContourWrap = new ContourWrap_ViewControl(manContourControl, manViewerContour);
269  if(_contours_ViewControl == NULL)
270  {
271  _contours_ViewControl = new std::map< std::string, ContourWrap_ViewControl * >();
272  }
273  _contours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, newContourWrap ));
274  return newContourWrap;
275  }
276  //------------------------------------------------------------------------------------------------------------
278  {
279 
280  }
281  //------------------------------------------------------------------------------------------------------------
282  void wxVtkBaseView_SceneManager :: removeWrap( std::string theKeyName )
283  {
284  std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
285  iter = _contours_ViewControl->find( theKeyName );
286  _contours_ViewControl->erase( iter );
287  _lastInteraction=NULL;
289  _workingGroup->clear();
290  this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
291  this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
292  }
293  //------------------------------------------------------------------------------------------------------------
295  {
296  std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
297  iter = _contours_ViewControl->find( theName );
298  return iter->second;
299  //return iter->first;
300  }
301  //------------------------------------------------------------------------------------------------------------
302  ContourWrap_ViewControl * wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf ( std::string theName, std::map<std::string, ContourWrap_ViewControl *> * theMap )
303  {
304  std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
305  iter = theMap->find( theName );
306  return iter->second;
307  }
308  //------------------------------------------------------------------------------------------------------------
309  manualContourBaseControler * wxVtkBaseView_SceneManager :: getControlerOf( std::string theName )
310  {
311  return getContourWrap_ViewControlOf ( theName )->getControler();
312  }
313  //------------------------------------------------------------------------------------------------------------
314  manualViewBaseContour * wxVtkBaseView_SceneManager :: getViewerOf( std::string theName )
315  {
316  return getContourWrap_ViewControlOf ( theName )->getViewer();
317  }
318  //------------------------------------------------------------------------------------------------------------
320  {
321  _creatingMULT_ROI = condition;
322  }
323  //------------------------------------------------------------------------------------------------------------
325  {
326  _editingROI = condition;
327  }
328  //------------------------------------------------------------------------------------------------------------
330  {
331  _toIncludeAtInteractionGroup = condition;
332  }
333  //------------------------------------------------------------------------------------------------------------
335  {
336  _waiting = condition;
337  }
338  //------------------------------------------------------------------------------------------------------------
340  {
341  return _creatingMULT_ROI;
342  }
343  //------------------------------------------------------------------------------------------------------------
345  {
346  return _editingROI;
347  }
348  //------------------------------------------------------------------------------------------------------------
350  {
352  }
353 
354  //------------------------------------------------------------------------------------------------------------
356  {
357  return _waiting;
358  }
359 
360  //------------------------------------------------------------------------------------------------------------
362  {
363  return _creatingROI;
364  }
365  //------------------------------------------------------------------------------------------------------------
367  {
368  _creatingROI = condition;
369  }
370 
371  //------------------------------------------------------------------------------------------------------------
372  // Other functional methods
373  //------------------------------------------------------------------------------------------------------------
374 
375  void wxVtkBaseView_SceneManager :: createCopyContourOf( std::string anExistingKName, std::string cloneName, manualBaseModel * manualModel, bool append )
376  {
377  if ( !append )
378  {
380  _workingGroup->clear();
381  }
382  std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
383 
384 
385  iter = _contours_ViewControl->find( anExistingKName );
386 
387  manualBaseModel *cModule = manualModel;
388  manualViewBaseContour *cViewer = iter->second->getViewer()->Clone();
389  manualContourBaseControler *cControl = iter->second->getControler()->Clone( );
390 
391  cViewer->SetModel(cModule);
392  cControl->SetModelView( cModule , cViewer );
393  cControl->CreateNewManualContour();
394  cControl->SetActive( true );
395  cControl->SetEditable( false );
396 
397  cViewer->RefreshContour();
398  cViewer->Refresh();
399  this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
400  this->_vtkInteractorStyleBaseView->EvaluateToRefresh();
401 
402  _lastInteraction = insertWrap( cloneName, cControl, cViewer );
403  _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( cloneName, _lastInteraction ));
404  addToScene( cloneName );
405  }
406 
407  //------------------------------------------------------------------------------------------------------------
408 
409  void wxVtkBaseView_SceneManager :: removeFromScene( ContourWrap_ViewControl * contourWRP, bool visualization, bool control )
410  {
411  if( contourWRP == _lastInteraction )
412  {
413  _lastInteraction = NULL;
415  }
416 
417 
418  ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->RemoveInteractorStyleMaracas( contourWRP->getControler() );
419 
420  contourWRP->getControler()->SetActive( control );
421  contourWRP->getControler()->SetEditable( false );
422 
423  if ( !visualization && control )
424  {
425  contourWRP->getViewer()->RemoveControlPoints( );
426  contourWRP->getViewer()->RemoveTextActor( );
427  }
428  if ( visualization )
429  {
430  contourWRP->getViewer()->RemoveCompleteContourActor();
431  }
432 
433  }
434  //------------------------------------------------------------------------------------------------------------
435  void wxVtkBaseView_SceneManager :: removeFromScene( std::string theKeyName, bool visualization , bool control )
436  {
437 
438  std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
439  iter = _sceneContours_ViewControl->find( theKeyName );
440  if (iter != _sceneContours_ViewControl->end())
441  {
442  ContourWrap_ViewControl * contourWRP = iter->second;
443  removeFromScene( contourWRP );
444  _sceneContours_ViewControl->erase(iter);
445  }
446  }
447 
448 
449  //------------------------------------------------------------------------------------------------------------
451  {
452  std::vector<std::string> lstContoursNameActualSlice;
453  std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
454  int i,size = _sceneContours_ViewControl->size();
455  for ( i = 0; i<size; i++ )
456  {
457  lstContoursNameActualSlice.push_back( iter->first );
458  iter++;
459  }
460  return lstContoursNameActualSlice;
461  }
462 
463  //------------------------------------------------------------------------------------------------------------
465  {
466  std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
467  int size = _sceneContours_ViewControl->size();
468  for ( int i = 0; i<size; i++ )
469  {
470  removeFromScene( iter->second );
471  iter++;
472  }
474 
475 
476  //Removing the selection rectangle to avoid showing when it's innecesary
477  _controlerSelectionROI->SetActive( false );
478  _viewerSelectionROI->RemoveCompleteContourActor();
479  }
480 
482  {
483  manualViewBaseContour * cViewer;
484  manualContourBaseControler * cControler;
485 
486  std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
487  int i,size=_contours_ViewControl->size();
488  for (i=0;i<size;i++)
489  {
490  iter = _contours_ViewControl->begin();
491  cControler = iter->second->getControler();
492  cViewer = iter->second->getViewer();
493  removeWrap( iter->first );
494  delete cViewer;
495  delete cControler;
496  }// for
497 
498  }
499 
500 
501  //------------------------------------------------------------------------------------------------------------
502  void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
503  {
504  if( !append )
505  {
507  }
508  ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
509  _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
510 
511  addToScene( theKeyName, contourWRP, true, visualization, control, ifActive, ifShowCtrlPoints);
512  }
513 
514  //------------------------------------------------------------------------------------------------------------
515  void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
516  {
517  if( !append )
518  {
520  }
521  _sceneContours_ViewControl->insert(std::pair <std::string, ContourWrap_ViewControl *> ( theKeyName, contourWRP ) );
522  if ( visualization )
523  {
524  contourWRP->getViewer()->AddCompleteContourActor( ifShowCtrlPoints );
525  }
526 
527  if( control )
528  {
529  ((vtkInteractorStyleBaseView*)_wxVtk_BaseView->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( contourWRP->getControler() );
530  }
531  if( ifActive )
532  {
533  contourWRP->getControler()->SetActive( true );
534  contourWRP->getViewer()->RemoveTextActor();
535  }
536  }
537 
538  //------------------------------------------------------------------------------------------------------------
539  void wxVtkBaseView_SceneManager :: removeFromScene( std::vector< std::string> theKeyNameVector, bool visualization, bool control )
540  {
541  int i, size = theKeyNameVector.size();
542  for( i=0; i< size; i++ )
543  {
544  removeFromScene( theKeyNameVector[i], visualization, control );
545  }
546  }
547 
548  //------------------------------------------------------------------------------------------------------------
549  void wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
550  {
551  int i, size = theKeyNameVector.size();
552  for( i=0; i< size; i++ )
553  {
554  addToScene( theKeyNameVector[i], append, visualization, control, ifActive, ifShowCtrlPoints );
555  }
556  }
557 
558  //------------------------------------------------------------------------------------------------------------
560  {
562  }
563 
564  //------------------------------------------------------------------------------------------------------------
565  void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::string theKeyName, bool stateCondition )
566  {
567  ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
568  setControlActiveStateOf( contourWRP, stateCondition );
569  }
570 
571  //------------------------------------------------------------------------------------------------------------
573  {
574  contourWRP->getControler()->SetActive( stateCondition );
575  contourWRP->getControler()->SetEditable( false );
576  }
577 
578  //------------------------------------------------------------------------------------------------------------
579  void wxVtkBaseView_SceneManager :: setVisibleStateOf( std::string theKeyName, bool stateCondition )
580  {
581  ContourWrap_ViewControl * contourWRP = getContourWrap_ViewControlOf( theKeyName );
582 // contourWRP->getViewer()->SetVisible( stateCondition );
583  if ( contourWRP!=NULL )
584  removeFromScene( contourWRP, false, stateCondition );
585  }
586 
587  //------------------------------------------------------------------------------------------------------------
589  {
590  std::vector< std::string > selectedObjects;
591  std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
592  int size = _workingGroup->size();
593  for ( int i = 0; i<size; i++ )
594  {
595 //EED??? manualViewBaseContour * viewer = iter->second->getViewer();
596  selectedObjects.push_back( iter->first);
597 
598  iter++;
599  }
600  return selectedObjects;
601  }
602  //------------------------------------------------------------------------------------------------------------
603  void wxVtkBaseView_SceneManager :: selectObjects( std::vector< std::string > theExistingObjectsToSelect )
604  {
605  std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->begin();
606 //EED??? int size = _contours_ViewControl->size();
607 //EED??? bool selected;
608  /*for ( int i = 0; i<size; i++ )
609  {
610  selected = false;
611  manualViewBaseContour * viewer = iter->second->getViewer();
612  std::vector <std::string >::iterator iterIN;
613  int a = 0;
614  for( a = 0, iterIN = theExistingObjectsToSelect.begin() ; !selected && a < theExistingObjectsToSelect.size() ; a++ )
615  {
616  if( iter->first.compare( theExistingObjectsToSelect[i] ) )
617  {
618  viewer->SelectAllPoints( true );
619  viewer->SelectPosibleContour( true );
620  selected = true;
621  theExistingObjectsToSelect.erase( iterIN );
622  }
623  if( !selected )
624  iterIN++;
625  }
626  } */
627  }
628 
629  //------------------------------------------------------------------------------------------------------------
630  void wxVtkBaseView_SceneManager :: selectObjects( std::map<std::string, ContourWrap_ViewControl *> * theMap )
631  {
632  std::map <std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
633  int size = _contours_ViewControl->size();
634  for ( int i = 0; i<size; i++ )
635  {
636  manualViewBaseContour * viewer = iter->second->getViewer();
637 
638  viewer->SetSelected( true );
639  /*viewer->SelectAllPoints( true );
640  viewer->SelectPosibleContour( true );*/
641 
642  iter++;
643  }
644  }
645 
646  //------------------------------------------------------------------------------------------------------------
647  void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::vector< std::string> &theKeyNameVector, bool controlCondition )
648  {
649  int i, size = theKeyNameVector.size();
650  for( i=0; i< size; i++ )
651  {
652  setControlActiveStateOf( theKeyNameVector[i], controlCondition );
653  }
654  }
655 
656  //------------------------------------------------------------------------------------------------------------
657  void wxVtkBaseView_SceneManager :: setControlActiveStateOf( std::map<std::string, ContourWrap_ViewControl *> * theMap, bool controlCondition )
658  {
659  std::map<std::string, ContourWrap_ViewControl *>::iterator iter = theMap->begin();
660  int i, size = theMap->size();
661  for( i=0; i< size; i++ )
662  {
663  removeFromScene( iter->second, false, controlCondition );
664  iter++;
665  }
666  }
667 
668  //------------------------------------------------------------------------------------------------------------
669  // Private methods
670  //------------------------------------------------------------------------------------------------------------
671 
672  //------------------------------------------------------------------------------------------------------------
673  // Creational and initialization methods
674  //------------------------------------------------------------------------------------------------------------
675 
676  //------------------------------------------------------------------------------------------------------------
677  // Inherited Methods
678  //------------------------------------------------------------------------------------------------------------
679 
681  {
682  return _ctrlKey;
683  }
685  {
686  return _shiftKey;
687  }
689  {
690  return _lastKeyCode;
691  }
693  {
694 
695  _ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
696  _shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
697 
698  _lastKeyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
699 
700  wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
701  _eventHandler->ProcessEvent( cevent );
702 
703 
704  /*if( _eventHandler!=NULL )
705  {
706  char * toolCommand = NULL;
707 
708  if ( _lastKeyCode == 3 && ctrlKey ) //'C' || 'c'
709  {
710  toolCommand = &(COPY_TOOL);
711  }
712  else if( _lastKeyCode == 22 && ctrlKey ) //'V' || 'v'
713  {
714  toolCommand = &(PASTE_TOOL);
715  }
716  else if( _lastKeyCode == 8 || (_lastKeyCode==127) ) // Delete
717  {
718  toolCommand = &(DELETE_KEY);
719  }
720  else if( _lastKeyCode == 14 && ctrlKey ) //'N' || 'n'
721  {
722  toolCommand = &(CREATE_CONTOUR_KEY);
723  }
724  else if( _lastKeyCode == 15 && ctrlKey ) //'O' || 'o'
725  {
726  toolCommand = &(OPEN_TOOL);
727  }
728  else if( _lastKeyCode == 19 && ctrlKey ) //'S' || 's'
729  {
730  toolCommand = &(SAVE_KEY);
731  }
732 
733  if ( toolCommand!=NULL )
734  {
735  currentkey = toolCommand;
736  wxCommandEvent cevent( wxEVT_COMMAND_BUTTON_CLICKED );
737  cevent.SetClientData( (void *) toolCommand);
738  _eventHandler->ProcessEvent( cevent );
739  }
740  }*/
741 
742 
743  // long int endtime = clock();
744 
745  return true;
746  }
747  //------------------------------------------------------------------------------------------------------------
748 
750  {
751 
752  bool condition = true;
753  int X,Y;
754  wxVTKRenderWindowInteractor *_wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
755  _wxVTKiren->GetEventPosition( X , Y );
756 
757  bool ctrlKey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey() == 1;
758 //??? bool shiftKey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey() == 1;
759 
760  if( _waiting && !ctrlKey )
761  {
762  sendEnvent( wxEVT_CHANGED_DEEP, "Update");
763  //toca ver como decirle al viewer que no se mueva mientras no se este esperando que se pueda mover
764  }
765 
766  if ( !_creatingROI && !_creatingMULT_ROI )
767  {
768 
769  /*if( ctrlKey || shiftKey )
770  {
771 
772  }
773  else
774  {
775  _toIncludeAtInteractionGroup = false;
776  }*/
777 
778  bool preserveState = _lastInteraction!=NULL? _lastInteraction->getViewer()->GetSelected() : false;
779  std::string preservingName = preserveState ? _lastInteractionName : "";
780 
781  std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
782  int i, size = _sceneContours_ViewControl->size();
783  bool foundOne = false;
784 
785  manualContourBaseControler * control = _lastInteraction != NULL ? _lastInteraction->getControler() : NULL;
786  manualViewBaseContour * viewer = NULL;
787 
788 
789  bool singleMoving = true;
790  int selectionSize = _workingGroup->size();
791  if( selectionSize > 1 )
792  {
793  //Multiple moving
794 
795 //EED??? bool ckecking = false;
796  for( i =0; i<size ; i++ )
797  {
798  control = iter->second->getControler();
799  viewer = iter->second->getViewer();
800  /*ckecking = */control->SetActive( true );
801  }
802  if (_lastInteraction != NULL)
803  {
804  singleMoving = !_lastInteraction->getViewer()->GetSelected();
805 
806  }
807  if( !singleMoving )
808  {
809  size = selectionSize;
810  iter = _workingGroup->begin();
811  }
812  }
813  else
814  {
815 
817  }
818 
819  if( ((_lastInteraction != NULL && !control->IsEditable() && !control->IsMoving() ) || _lastInteraction==NULL ))
820  {
821 
822  _lastInteraction=NULL;
823  for( i =0; i<size ; i++ )
824  {
825  control = iter->second->getControler();
826  viewer = iter->second->getViewer();
827 // _wxVtk_BaseView->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( control );
828  control->SetActive( true );
829 
830  foundOne = control->OnMouseMove();
831  foundOne &= viewer->GetPosibleSelected();
832 
833  if ( !foundOne && singleMoving )
834  {
835  control->SetActive( false );
836 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
837  control->SetPosibleToMove( false );
838  }
839  else
840  {
841  if( _toIncludeAtInteractionGroup && preserveState && _lastInteractionName.compare( preservingName)==0 )
842  {
843  _lastInteraction->getControler()->SetActive( true );
844  }
845 
846  _lastInteraction = iter->second;
847  _lastInteractionName = iter->first;
848 
849  viewer->UpdateColorActor();
850  control->SetPosibleToMove( true );
851  // viewer->AddCompleteContourActor();
852  }
853  iter++;
854  }
855  control = NULL;
856  viewer = NULL;
857  }
858  }
859  return condition;
860  }
861 
862 
863 
864 
865 
866  //------------------------------------------------------------------------------------------------------------
868  {
869 
870 
871 
872 //EED??? char aa = _vtkInteractorStyleBaseView->GetInteractor()->GetKeyCode();
873  bool condition = false;
874  //vtkCommand * theComand = _wxVtk_BaseView ->GetInteractorStyleBaseView()->GetCommand(
875 //EED??? vtkRenderWindowInteractor * vtkRWInteractor1 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
876 //EED??? wxVTKRenderWindowInteractor * vtkRWInteractor2 = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
877 //EED?? wxVTKRenderWindowInteractorPlus * vtkRWInteractor3 = (wxVTKRenderWindowInteractorPlus*)_wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();//GetInteractorStyleBaseView()->GetInteractor();
878  vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
879 
880  bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
881  bool shftKey = vtkRWInteractor->GetShiftKey() == 1;
883  if ( ctrlKey || shftKey )
884  {
886  }
887  else
888  {
890  {
891  if( _lastInteraction->getControler()->GetIfCompleteCreation() && !_lastInteraction->getControler()->IsEditable()&& !_lastInteraction->getViewer()->GetPosibleSelected() )
892  {
893  _lastInteraction->getControler()->SetEditable( false );
894  _lastInteraction->getControler()->SetActive( false );
895  _lastInteraction->getControler()->SetPosibleToMove( false );
896  _lastInteraction->getViewer()->Refresh();
897  _lastInteraction=NULL;
898  }
899  }
900  }
901 
902 
903 
905  {
906  _workingGroup->clear();
907  }
908 
909  if( _lastInteraction!=NULL )
910  {
913  _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( _lastInteractionName, _lastInteraction ));
914  }
915  if( _creatingMULT_ROI && !_creatingROI && !ctrlKey && !shftKey )
916  {
917  _creatingROI = true;
918  //setControlActiveStateOf( _contours_ViewControl, false );
919  sendEnvent( wxEVT_START_CREATE_ROI, "");
920  }
921  condition = true;
922 
923 // FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
924 // fprintf(ff,"EED wxVtkBaseView_SceneManager::OnLeftButtonDown() contours=%d sceneContour=%d workingContours=%d\n",
925 // _contours_ViewControl->size(), _sceneContours_ViewControl->size(), _workingGroup->size() );
926 // fclose(ff);
927 
928 
929  return condition;
930  }
931 
932  //------------------------------------------------------------------------------------------------------------
934  {
935  bool condition = false;
936  condition = true;
937 
939  {
941  }
942  return condition;
943  }
944  //------------------------------------------------------------------------------------------------------------
946  {
947  bool condition = false;
948  condition = true;
949 
950  return condition;
951  }
952  //------------------------------------------------------------------------------------------------------------
954  {
955  bool condition = false;
956  condition = true;
957 
958  return condition;
959  }
960  //------------------------------------------------------------------------------------------------------------
962  {
963  bool condition = false;
964 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
965 //EED??? bool ctrlKey = vtkRWInteractor->GetControlKey() == 1;
966  _waiting = true;
967 
968  condition = true;
969 
970  return condition;
971  }
972  //------------------------------------------------------------------------------------------------------------
974  {
975  bool condition = false;
976  condition = true;
977  //setControlActiveStateOfALL( false );//************************************************
978  if ( _creatingMULT_ROI )
979  {
980  //setControlActiveStateOfALL( false );
981  }
982  if( _creatingROI )
983  {
984  sendEnvent( wxEVT_STOP_CREATE_ROI, "Activate");
985  _creatingROI = false;
986  }
987  else
988  {
990  {
991  manualContourBaseControler * control = _lastInteraction->getControler();
992  //_lastInteraction->getControler()->SetPosibleToMove( false );
993  control->SetActive( false );
994  control->SetEditable( false );
995  control->SetPosibleToMove( false );
996 // _wxVtk_BaseView->GetInteractorStyleBaseView()->RemoveInteractorStyleMaracas( control );
997  _lastInteraction->getViewer()->Refresh();
998  this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
999  }
1000  }
1001  _waiting = false;
1002  return condition;
1003  }
1004  //------------------------------------------------------------------------------------------------------------
1005 
1007  {
1008  bool condition = false;
1009  condition = true;
1010 
1011  return condition;
1012  }
1013  //------------------------------------------------------------------------------------------------------------
1015  {
1016  bool condition = false; condition = true;
1017 //EED??? vtkRenderWindowInteractor * vtkRWInteractor = _vtkInteractorStyleBaseView->GetInteractor();
1018  /*vtkRenderWindowInteractor * vtkRWInteractor1 =*/ _vtkInteractorStyleBaseView->OnChar();
1019 //EED??? wxVTKRenderWindowInteractor * wxVtkRWInterator = _wxVtk_BaseView ->GetWxVTKRenderWindowInteractor();
1020 
1021  /*if( _waiting )
1022  {
1023  sendEnvent( wxEVT_START_CREATE_MULT_ROI, "Multiple");
1024  set_creatingMULT_ROI( !_creatingMULT_ROI );
1025  _waiting = false;
1026  }
1027  else
1028  _waiting = true;*/
1029 
1030  return condition;
1031  }
1032  //------------------------------------------------------------------------------------------------------------
1034  {
1035  bool condition = false;
1036  condition = true;
1037 
1038  return condition;
1039  }
1040  //------------------------------------------------------------------------------------------------------------
1042  {
1043  bool condition = false;
1044  condition = true;
1045  return condition;
1046  }
1047  //------------------------------------------------------------------------------------------------------------
1048 
1050  {
1051  _drawingSelectionROI = true;
1052  _workingGroup->clear();
1053  _controlerSelectionROI->CreateNewManualContour();
1054  if (_lastInteraction!=NULL)
1055  {
1056  _lastInteraction->getControler()->SetEditable( false );
1057  _lastInteraction->getControler()->SetActive( false );
1058  _lastInteraction->getControler()->SetPosibleToMove( false );
1059  _lastInteraction->getViewer()->Refresh();
1060  }
1061  std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _workingGroup->begin();
1062  int i, workSize = _workingGroup->size();
1063  for( i=0; i< workSize; i++ )
1064  {
1065  manualContourBaseControler * control = iter->second->getControler();
1066  control->SetEditable( false );
1067  control->SetActive( false );
1068  control->SetPosibleToMove( false );
1069  iter->second->getViewer()->Refresh();
1070 
1071  iter++;
1072  }
1073  _lastInteraction = NULL;
1074  _lastInteractionName = "";
1075 
1076  _viewerSelectionROI->AddCompleteContourActor( true );
1077  _controlerSelectionROI->SetActive( true );
1078 
1079  _viewerSelectionROI->RefreshContour();
1080  this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1081  }
1082  //------------------------------------------------------------------------------------------------------------
1084  {
1085  _drawingSelectionROI = false;
1086  _workingGroup->clear();
1087  double minX,minY,maxX,maxY, minX_ROI,minY_ROI,maxX_ROI,maxY_ROI;
1088  double minZ = -1.0;
1089  double maxZ = -1.0;
1090  std::map<std::string, ContourWrap_ViewControl *>::iterator iter = _sceneContours_ViewControl->begin();
1091  int i, size = _sceneContours_ViewControl->size();
1092  _viewerSelectionROI->GetMinMax( minX_ROI, minY_ROI, maxX_ROI, maxY_ROI );
1093  manualViewBaseContour * viewer;
1094  bool insideRoi = false;
1095  for ( i=0; i<size; i++ )
1096  {
1097  viewer = iter->second->getViewer();
1098  viewer->GetMinMax( minX, minY, minZ, maxX, maxY, maxZ );
1099  insideRoi = minX >= minX_ROI && maxX <= maxX_ROI && minY_ROI && maxY <= maxY_ROI;
1100  if ( insideRoi )
1101  {
1102  viewer->SetSelected( true );
1103  viewer->UpdateColorActor();
1104  setControlActiveStateOf( iter->second, true );
1105  _workingGroup->insert(std::pair <std::string, ContourWrap_ViewControl *> ( iter->first, iter->second ));
1106  }
1107  iter++;
1108  }
1109  _viewerSelectionROI->RemoveCompleteContourActor( );
1110  _controlerSelectionROI->SetActive( false );
1111  }
1112  //------------------------------------------------------------------------------------------------------------
1114  {
1115  FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1116  long int start = clock();
1117 #if(WIN32)
1118  double sg = (double)(start) / (double)CLK_TCK;
1119 #else
1120  double sg = (double)(start) / CLOCKS_PER_SEC;
1121 #endif
1122  int tmpPx,tmpPy;
1123  wxVTKRenderWindowInteractor *wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1124  wxVTKiren->GetEventPosition( tmpPx , tmpPy );
1125  fprintf(ff,"::%s (x,y) = (%i, %i) t(sg): %f\n \n",method.c_str(), tmpPx, tmpPy, sg);
1126  fclose(ff);
1127  }
1128 
1129 
1130  //------------------------------------------------------------------------------------------------------------
1131  void wxVtkBaseView_SceneManager::SaveThingName(FILE *ff, std::string nameThing)
1132  {
1133  std::map <std::string, ContourWrap_ViewControl *>::iterator iter = _contours_ViewControl->find(nameThing);
1134  manualViewBaseContour * cViewer;
1135  manualContourBaseControler * cControler;
1136  ContourWrap_ViewControl *conwraviwcont=iter->second;
1137 
1138  cViewer = conwraviwcont->getViewer();
1139  cViewer->Save(ff);
1140 
1141  cControler = conwraviwcont->getControler();
1142 // cControler->Save(ff);
1143 
1144 // cModel = cControler->GetManualContourModel();
1145 // cModel->Save(ff);
1146  }
1147 
1148 
1149  //------------------------------------------------------------------------------------------------------------
1150  void wxVtkBaseView_SceneManager::GetPointsOfActualContour( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ )
1151  {
1152  std::vector<std::string> currentSelection = this->getSelectedObjects();
1153  if (currentSelection.size()>=1){
1154 
1155  manualContourBaseControler *cControler = this->getControlerOf( currentSelection[0] );
1156  manualBaseModel *cModel = cControler->GetManualContourModel();
1157  int i,size = cModel->GetNumberOfPointsSpline();
1158  double x,y,z;
1159  for (i=0; i<size; i++)
1160  {
1161  cModel->GetSpline_i_Point(i, &x, &y, &z);
1162  vecX->push_back(x);
1163  vecY->push_back(y);
1164  vecZ->push_back(z);
1165  }
1166  }
1167  }
1168 
1169  //------------------------------------------------------------------------------------------------------------
1171  {
1172  wxVtk2DBaseView *wxvtk2dbaseview =(wxVtk2DBaseView*)_wxVtk_BaseView;
1173  return wxvtk2dbaseview->GetVtkBaseData()->GetImageData();
1174  }
1175 
1176  //------------------------------------------------------------------------------------------------------------
1178  {
1179  int ext[6];
1180  vtkImageData *imagedata = GetImageData();
1181  imagedata->GetExtent(ext);
1182  int sizeZ = ext[5]-ext[4]+1;
1183 
1184 //EED OJO Machete
1185 // sizeZ = sizeZ-1;
1186 
1187  return sizeZ;
1188  }
1189 
1190  //------------------------------------------------------------------------------------------------------------
1192  {
1193  int ext[6];
1194  vtkImageData *imagedata = GetImageData();
1195  imagedata->GetExtent(ext);
1196  int sizeX = ext[1]-ext[0]+1;
1197  int sizeY = ext[3]-ext[2]+1;
1198  int sizeZ = GetImageDataSizeZ();
1199  int sizeXYZ = sizeX*sizeY*sizeZ;
1200  long int i;
1201  range[0]=9999999;
1202  range[1]=-9999999;
1203  unsigned short *p = (unsigned short *)imagedata->GetScalarPointer(0,0,0);
1204  for (i=0;i<sizeXYZ;i++)
1205  {
1206  if ( p[i]<range[0] ) range[0]=p[i];
1207  if ( p[i]>range[1] ) range[1]=p[i];
1208  }
1209  }
1210 
1211  //------------------------------------------------------------------------------------------------------------
1213  {
1214  _widthOfContour = width;
1216  manualViewBaseContour *cViewer;
1217  ContourWrap_ViewControl *conwraviwcont;
1218  std::map <std::string, ContourWrap_ViewControl *>::iterator iter;
1219 
1220  if (_contours_ViewControl!=NULL)
1221  {
1222  for (iter=_contours_ViewControl->begin(); iter!=_contours_ViewControl->end(); iter++ )
1223  {
1224  conwraviwcont = iter->second;
1225  cViewer = conwraviwcont->getViewer();
1226  cViewer->SetShowText( false ); // EED 28Mars2011
1227  cViewer->SetWidthLine( _widthOfContour );
1228  cViewer->SetRange( _widthOfControlPoint );
1229  } // for
1230  } // if
1231  }
1232 
1234 
1236  if(ccon != NULL ){
1237  manualContourBaseControler* cControler = ccon->getControler();
1238  if(cControler != NULL && cControler->IsEditable() == false){
1239  return true;
1240  }
1241  }
1242  return false;
1243  }
1244 
1246 
1247 
1249 
1250  manualViewBaseContour * cViewer = ccon->getViewer();
1251  manualContourBaseControler * cControler = ccon->getControler();
1252 
1253  removeFromScene(theKeyName);
1254  removeWrap(theKeyName);
1255 
1256  delete cViewer;
1257  delete cControler;
1258  }
1259 
1260 
1261