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