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