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