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