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