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