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