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