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