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