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