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