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