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