]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualViewBaseContour.cpp
1e765740c51f3cc035f42b6b24d34d0fb312e66b
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualContour / manualViewBaseContour.cpp
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 #include "manualViewBaseContour.h"
27
28
29 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
32
33 manualViewBaseContour::manualViewBaseContour()
34 {
35         _show_text                      = true;
36         _textActor                      = NULL;
37         _manContModel           = NULL;
38         _wxvtkbaseview          = NULL;
39         _selected                       = false;
40         _posibleSelected        = false;
41         _viewControlPoints      = false;
42         _pts                            = NULL;
43         _pd                                     = NULL;
44         _contourVtkActor        = NULL;
45         _bboxMapper                     = NULL;
46         _range                          = 1;
47         _sizePointsContour      = 100;
48         _spc[0]                         = 1;
49         _spc[1]                         = 1;
50         _spc[2]                         = 1;
51
52         _coulorEdit_r           = 1;
53         _coulorEdit_g           = 1;
54         _coulorEdit_b           = 0;
55
56         _coulorNormal_r         = 1;
57         _coulorNormal_g         = 0;
58         _coulorNormal_b         = 1;
59
60         _coulorSelection_r      = 0;
61         _coulorSelection_g      = 1;
62         _coulorSelection_b      = 0;
63
64         _widthline                      = 1;
65
66 }
67 // ----------------------------------------------------------------------------
68 manualViewBaseContour::~manualViewBaseContour()
69 {
70         int i,size=_lstViewPoints.size();
71         for (i=0;i<size; i++){
72                 delete _lstViewPoints[i];
73         }
74         _lstViewPoints.clear();
75 }
76 // ----------------------------------------------------------------------------
77
78
79 int manualViewBaseContour::GetType() // virtual
80 {
81 // Information...
82 //int manualViewBaseContour::GetType()          0;
83 //int manualViewContour::GetType()                      1;
84 //int manualViewRoi::GetType()                          2;
85 //int manualViewCircle::GetType()                       3;
86 //int manualViewStar::GetType()                         4;
87 //int manualViewLine::GetType()                         6;
88 //int manualViewPoints::GetType()                       7;
89
90
91         return 0;
92 }
93 // ----------------------------------------------------------------------------
94
95 void manualViewBaseContour::Save(FILE *pFile)
96 {
97         fprintf(pFile,"TypeView %d\n", GetType() );
98 }
99
100 // ----------------------------------------------------------------------------
101 void manualViewBaseContour::Open(FILE *pFile)
102 {
103 }
104
105 // ----------------------------------------------------------------------------
106 void manualViewBaseContour :: AddCompleteContourActor(  bool ifControlPoints )
107 {
108         _viewControlPoints = ifControlPoints;
109          /*vtkRenderer * theRenderer = */  _wxvtkbaseview->GetRenderer();  // JPRx ??
110          //Adding the spline
111          AddSplineActor();
112          AddTextActor();
113
114          //Adding each control point
115          if( ifControlPoints )
116                 AddControlPoints();
117          RefreshContour();
118          Refresh();
119 }
120 // ---------------------------------------------------------------------------
121
122 void manualViewBaseContour :: RemoveCompleteContourActor()
123 {
124         /*vtkRenderer * theRenderer =*/  _wxvtkbaseview->GetRenderer(); // JPRx ??
125          //Removing the spline
126         RemoveSplineActor();
127         RemoveTextActor();
128
129         //Removing each point
130         RemoveControlPoints();
131         RefreshContour();
132         Refresh();
133 }
134 // ---------------------------------------------------------------------------
135 manualViewBaseContour *  manualViewBaseContour :: Clone( )//virtual
136 {
137         manualViewBaseContour * clone = new manualViewBaseContour();
138         CopyAttributesTo(clone);
139         return clone;
140
141 }
142
143 // ---------------------------------------------------------------------------
144
145 void manualViewBaseContour::CopyAttributesTo( manualViewBaseContour * cloneObject)
146 {
147         // Fathers object
148         //XXXX::CopyAttributesTo(cloneObject);
149
150         cloneObject-> SetWxVtkBaseView( this->_wxvtkbaseview );
151         cloneObject-> SetSelected( this->GetSelected() );
152         cloneObject-> SetPosibleSelected( this->GetPosibleSelected() );
153         cloneObject-> SetIfViewControlPoints( this->GetIfViewControlPoints() );
154         cloneObject-> SetRange( this->GetRange() );
155         cloneObject-> SetZ( this->GetZ() );
156         cloneObject-> SetSpacing( _spc );
157         cloneObject-> SetColorNormalContour( _coulorNormal_r, _coulorNormal_g, _coulorNormal_b );
158         cloneObject-> SetColorEditContour( _coulorEdit_r, _coulorEdit_g, _coulorEdit_b );
159         cloneObject-> SetColorSelectContour( _coulorSelection_r, _coulorSelection_g, _coulorSelection_b );
160
161         int i, size = _lstViewPoints.size();
162         for ( i=0; i<size; i++ )
163         {
164                 cloneObject->AddPoint(  );
165         }
166 }
167
168 // ----------------------------------------------------------------------------
169 void manualViewBaseContour :: AddSplineActor()
170 {
171         vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
172         if (_contourVtkActor!=NULL)
173                 theRenderer->AddActor( _contourVtkActor  );
174 }
175 // ----------------------------------------------------------------------------
176 void manualViewBaseContour :: RemoveSplineActor() // virtual
177 {
178         vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
179         if (_contourVtkActor!=NULL)
180                 theRenderer->RemoveActor( _contourVtkActor );
181 }
182 // ----------------------------------------------------------------------------
183 void manualViewBaseContour :: RemoveControlPoints()
184 {
185         if (_wxvtkbaseview!=NULL){
186                 vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
187                 int i,size=_lstViewPoints.size();
188                 for (i=0;i<size; i++)
189                 {
190                         vtkActor * pointActor = _lstViewPoints[i]->GetVtkActor();
191                         theRenderer->RemoveActor( pointActor );
192                 } // for
193         } // if
194         SetIfViewControlPoints( false );
195 }
196 // ----------------------------------------------------------------------------
197 void manualViewBaseContour::AddControlPoints()
198 {
199         vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
200         SetIfViewControlPoints( true );
201          if( _viewControlPoints )
202          {
203                 int i,size=_lstViewPoints.size();
204                 for (i=0;i<size; i++)
205                 {
206                         vtkActor * pointActor = _lstViewPoints[i]->GetVtkActor();
207                         theRenderer->AddActor( pointActor );
208                 }
209          }
210 }
211 // ----------------------------------------------------------------------------
212 void manualViewBaseContour::AddTextActor()
213 {
214         if(_show_text)
215         {
216                 _wxvtkbaseview->GetRenderer()->AddActor2D( _textActor );
217                 _wxvtkbaseview->GetRenderer()->AddActor2D( _textActor2 );
218         }
219 }
220 // ----------------------------------------------------------------------------
221 void manualViewBaseContour::RemoveTextActor()
222 {
223         if(_show_text)
224         {
225                 _wxvtkbaseview->GetRenderer()->RemoveActor2D( _textActor );
226                 _wxvtkbaseview->GetRenderer()->RemoveActor2D( _textActor2 );
227         }
228 }
229 // ----------------------------------------------------------------------------
230 void manualViewBaseContour::DeleteVtkObjects()
231 {
232         if ( _contourVtkActor   != NULL )       { _contourVtkActor  -> Delete(); }
233         if ( _bboxMapper                != NULL )       { _bboxMapper           -> Delete(); }
234         if ( _pts                               != NULL )       { _pts                          -> Delete(); }
235         if ( _pd                                != NULL )       { _pd                           -> Delete(); }
236         _contourVtkActor        = NULL;
237         _bboxMapper                     = NULL;
238         _pts                            = NULL;
239         _pd                                     = NULL;
240 }
241
242
243 // ----------------------------------------------------------------------------
244 void manualViewBaseContour::SetWidthLine(double width)
245 {
246         _widthline = width;
247         this->UpdateColorActor();
248
249         // for the control points
250         int id, size = _lstViewPoints.size();
251         for( id=0; id<size; id++)
252         {
253                 this->_lstViewPoints[id]->SetWidthLine(_widthline);
254         }
255
256 }
257
258 // ----------------------------------------------------------------------------
259 double manualViewBaseContour::GetWidthLine()
260 {
261         return _widthline;
262 }
263
264 // ----------------------------------------------------------------------------
265 void manualViewBaseContour::ConstructVTKObjects()
266 {
267
268
269 //JSTG 29-02-08 -----------------------------------------------
270         //int i , nps = _sizePointsContour;
271         int i;
272         int nps = _manContModel->GetNumberOfPointsSpline();
273 //-------------------------------------------------------------
274
275         DeleteVtkObjects();
276         _pts = vtkPoints::New();
277         _pts->SetNumberOfPoints(nps);
278         for (i=0 ; i<nps ; i++){
279                 _pts->SetPoint(i,       0       , 0     , 0 );
280         }
281         // This is for the boundaring inicialisation
282
283 //EED 29Mars2009        
284         //_pts->SetPoint(0,     0       , 0     , -1000 );
285         //_pts->SetPoint(1,     0       , 0     ,  1000 );
286         _pts->SetPoint(0,       -1000   , -1000 , -1000 );
287         _pts->SetPoint(1,       1000    , 1000  , 1000  );
288
289         vtkCellArray *lines = vtkCellArray::New();
290         lines->InsertNextCell( nps /* +1 */ );
291         for ( i=0 ; i<nps+1 ; i++ ){
292                 lines->InsertCellPoint(i % nps );
293         }
294         _pd = vtkPolyData::New();
295         _pd->SetPoints( _pts );
296         _pd->SetLines( lines );
297         lines->Delete();  //do not delete lines ??
298
299         _contourVtkActor        =       vtkActor::New();
300     _bboxMapper                 =       vtkPolyDataMapper::New();
301     _bboxMapper->ScalarVisibilityOff( );
302
303         _bboxMapper->SetInput(_pd);
304         _bboxMapper->ImmediateModeRenderingOn();
305         _contourVtkActor->SetMapper(_bboxMapper);
306         _contourVtkActor->GetProperty()->BackfaceCullingOff();
307
308         UpdateColorActor();
309
310         _pd->ComputeBounds();
311
312         InitTextActor();
313 }
314
315 // ----------------------------------------------------------------------------
316 void manualViewBaseContour::InitTextActor()
317 {
318         //      Text
319         _textActor = vtkTextActor::New();
320 //      _textActor->SetDisplayPosition(200, 200);
321         _textActor->SetInput("00");
322         // Set coordinates to match the old vtkScaledTextActor default value
323 //      _textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
324 //      _textActor->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
325         _textActor->GetPositionCoordinate()->SetCoordinateSystemToWorld ();
326 //      _textActor->GetPositionCoordinate()->SetValue( 0.8 , 0.8 );
327
328         vtkTextProperty *tprop = _textActor->GetTextProperty();
329         tprop->SetFontSize(14);
330         tprop->SetFontFamilyToArial();
331         tprop->SetColor(0, 0, 1);
332
333
334         //      Text 2
335         _textActor2 = vtkTextActor::New();
336 //      _textActor->SetDisplayPosition(200, 200);
337         _textActor2->SetInput("00");
338         // Set coordinates to match the old vtkScaledTextActor default value
339 //      _textActor2->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
340 //      _textActor2->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
341         _textActor2->GetPositionCoordinate()->SetCoordinateSystemToWorld ();
342 //      _textActor2->GetPositionCoordinate()->SetValue( 0.8 , 0.8 );
343
344         vtkTextProperty *tprop2 = _textActor2->GetTextProperty();
345         tprop2->SetFontSize(14);
346         tprop2->SetFontFamilyToArial();
347         tprop2->SetColor(0, 0, 1);
348
349 }
350
351 // ----------------------------------------------------------------------------
352 void manualViewBaseContour::CreateNewContour()
353 {
354         ConstructVTKObjects();
355         /*
356         _wxvtkbaseview->GetRenderer()->AddActor( _contourVtkActor );
357         _wxvtkbaseview->GetRenderer()->AddActor2D(_textActor);*/
358         AddCompleteContourActor();
359 }
360 // ----------------------------------------------------------------------------
361 void manualViewBaseContour::UpdateViewPoint(int id) // virtual
362 {
363         manualPoint             *mp             = _manContModel->GetManualPoint(id);
364
365 //EEDx6
366                         double XX=mp->GetX(),YY=mp->GetY(),ZZ=mp->GetZ();
367 //                      wxVtk2DBaseView *wxvtk2Dbasevie = (wxVtk2DBaseView*)this->GetWxVtkBaseView();
368 //                      wxvtk2Dbasevie->TransformCoordinate_spacing_ModelToView(XX,YY,ZZ);
369
370         _lstViewPoints[id]->SetPositionXY( XX , YY ,_range, ZZ );
371 }
372
373 // ----------------------------------------------------------------------------
374 void manualViewBaseContour::UpdateViewPoints()
375 {
376         int id, size = _lstViewPoints.size();
377         for( id=0; id<size; id++)
378         {
379                 UpdateViewPoint( id );
380         }
381 }
382
383 // ----------------------------------------------------------------------------
384 void manualViewBaseContour::AddPoint()
385 {
386         manualViewPoint *mvp    = new manualViewPoint( this->GetWxVtkBaseView() );
387         AddPoint( mvp );
388 }
389 // ----------------------------------------------------------------------------
390 void manualViewBaseContour::AddPoint( manualViewPoint * manualViewPoint )
391 {
392         _lstViewPoints.push_back( manualViewPoint );
393
394         // EED 3 oct 2006
395         manualViewPoint->SetSpacing(_spc);
396
397         vtkActor *actor = manualViewPoint->CreateVtkPointActor();
398         _wxvtkbaseview->GetRenderer()->AddActor( actor );       
399 }
400
401 // ----------------------------------------------------------------------------
402 void manualViewBaseContour::InsertPoint(int id)
403 {
404         manualViewPoint         *mvp    = new manualViewPoint( this->GetWxVtkBaseView() );
405
406 // EED 3 oct 2006
407         mvp->SetSpacing(_spc);
408
409         std::vector<manualViewPoint*>::iterator itNum = _lstViewPoints.begin() + id;
410         _lstViewPoints.insert(itNum,mvp);
411         _wxvtkbaseview->GetRenderer()->AddActor( mvp->CreateVtkPointActor() );
412 }
413 // ----------------------------------------------------------------------------
414 void manualViewBaseContour::DeleteContour()
415 {
416         RemoveCompleteContourActor();
417         /*if (_contourVtkActor!=NULL){
418                 _wxvtkbaseview->GetRenderer()->RemoveActor( _contourVtkActor );
419         }*/
420         DeleteVtkObjects();
421         int i,size=_lstViewPoints.size();
422         for (i=0;i<size;i++){
423                 manualViewBaseContour::DeletePoint(0);
424         }
425         Refresh();
426 }
427 // ----------------------------------------------------------------------------
428 void manualViewBaseContour::DeletePoint(int id) // virtual
429 {
430         int size=_lstViewPoints.size();
431         if ( (id>=0) && (id<size) ){
432                 manualViewPoint         *mvp    =_lstViewPoints[id];
433 //EED ups1
434 //              _handlePicker->DeletePickList(mvp->GetVtkActor());
435                 _wxvtkbaseview->GetRenderer()->RemoveActor( mvp->GetVtkActor() );
436                 std::vector<manualViewPoint*>::iterator itNum = _lstViewPoints.begin() + id;
437                 _lstViewPoints.erase(itNum);
438                 delete mvp;
439                 Refresh();
440         }
441 }
442 // ----------------------------------------------------------------------------
443 void manualViewBaseContour::DeletePoint(int x, int y, int z)
444 {
445         int id=GetIdPoint(x,y,z);
446         if (id!=-1){
447                 DeletePoint(id);
448         }
449 }
450 // ----------------------------------------------------------------------------
451 void manualViewBaseContour::SetSelected(bool selected)
452 {
453         _selected=selected;
454 }
455 // ----------------------------------------------------------------------------
456 void manualViewBaseContour::SetPosibleSelected(bool posibleSelected)
457 {
458         _posibleSelected=posibleSelected;
459 }
460 // ----------------------------------------------------------------------------
461 bool manualViewBaseContour::GetEditable()
462 {
463         return *_editable;
464 }
465 // ----------------------------------------------------------------------------
466 void manualViewBaseContour::SetEditable( bool * condition )
467 {
468         _editable = condition;
469 }
470 // ----------------------------------------------------------------------------
471 bool manualViewBaseContour::GetSelected()
472 {
473         return _selected;
474 }
475 // ----------------------------------------------------------------------------
476 bool manualViewBaseContour::GetPosibleSelected()
477 {
478         return _posibleSelected;
479 }
480 // ----------------------------------------------------------------------------
481 void manualViewBaseContour::DeleteSelectedPoints()
482 {
483         int i,size=_lstViewPoints.size();
484         for (i=size-1;i>=0;i--){
485                 if (_lstViewPoints[i]->GetSelected()==true){
486                         DeletePoint(i);
487                 }
488         }
489         Refresh();
490 }
491 // ----------------------------------------------------------------------------
492 void manualViewBaseContour::SelectPoint(int i, bool select)
493 {
494         _lstViewPoints[i]->SetSelected(select);
495 }
496 // ----------------------------------------------------------------------------
497 void manualViewBaseContour::SelectLstPoints()
498 {
499         // ToDo
500 }
501 // ----------------------------------------------------------------------------
502 void manualViewBaseContour::SelectAllPoints(bool select)
503 {
504         int i,size=_lstViewPoints.size();
505         for (i=0;i<size;i++){
506                 SelectPoint(i,select);
507         }
508 }
509 //-----------------------------------------------------------------------------
510 void manualViewBaseContour:: SetIfViewControlPoints(bool ifShow)
511 {
512         _viewControlPoints = ifShow;
513 }
514 // ----------------------------------------------------------------------------
515 bool manualViewBaseContour:: GetIfViewControlPoints()
516 {
517         return _viewControlPoints;
518 }
519
520 // ----------------------------------------------------------------------------
521 void manualViewBaseContour::SetPointPosibleSelected(int id,bool select)
522 {
523         _lstViewPoints[id]->SetPosibleSelected(select);
524 }
525 // ----------------------------------------------------------------------------
526 void manualViewBaseContour::SetPointSelected(int id,bool select)
527 {
528         _lstViewPoints[id]->SetSelected(select);
529 }
530 // ----------------------------------------------------------------------------
531 void manualViewBaseContour::SelectAllPossibleSelected(bool select)
532 {
533         int i,size=_lstViewPoints.size();
534         for (i=0;i<size;i++){
535                 SetPointPosibleSelected(i,select);
536         }
537 }
538 // ----------------------------------------------------------------------------
539 int manualViewBaseContour::SelectPosiblePoint(int x, int y, int z)  // virtual
540 {
541         SelectAllPossibleSelected(false);
542
543     int id = GetIdPoint(x,y,z);
544         if (id!=-1)
545         {
546                 SetPointPosibleSelected(id,true);
547         }
548         return id;
549 }
550 // ----------------------------------------------------------------------------
551 bool manualViewBaseContour::SelectPosibleContour(int x, int y, int z)
552 {
553         bool result=false;
554         SetPosibleSelected(result);
555     int id = GetIdPoint(x,y,z);
556         
557         if( !GetEditable() && !_selected && id!= -1)
558         {
559                 result=true;
560                 _posibleSelected=true;          
561         }
562         else
563         {
564                 if ( (GetEditable()==true) && (id==-1 ) && (this->_lstViewPoints.size()>=2) )
565                 {
566                         if (ifTouchContour(x,y,z)==true)
567                         {
568                                 result=true;
569                                 SetPosibleSelected(result);
570                         }
571                 }
572
573                 if (GetEditable()==false)
574                 {
575                         if (ifTouchContour(x,y,z)==true)
576                         {
577                                 result=true;
578                                 SetPosibleSelected(result);
579                         }
580                 }
581         }
582         return result;
583 }
584 // ----------------------------------------------------------------------------
585 bool manualViewBaseContour::ifTouchContour(int x,int y, int z) // virtual
586 {
587         return false;
588 }
589 // ----------------------------------------------------------------------------
590 void manualViewBaseContour::UnSelectPoint(int i){
591         _lstViewPoints[i]->SetSelected(false);
592         Refresh();
593 }
594 // ----------------------------------------------------------------------------
595 void manualViewBaseContour::UnSelectLstPoints(){
596         // ToDo
597 }
598 // ----------------------------------------------------------------------------
599 void manualViewBaseContour::UnSelectAllPoints(){
600         int i,size=_lstViewPoints.size();
601         for (i=0;i<size;i++){
602                 UnSelectPoint(i);
603         }
604         Refresh();
605 }
606 // ----------------------------------------------------------------------------
607 void manualViewBaseContour::SetModel(manualBaseModel *manContModel){
608         _manContModel=manContModel;
609 }
610 // ----------------------------------------------------------------------------
611 void manualViewBaseContour::SetWxVtkBaseView(wxVtkBaseView *wxvtkbaseview){
612         _wxvtkbaseview = wxvtkbaseview;
613 }
614 // ----------------------------------------------------------------------------
615 void manualViewBaseContour::RefreshContour()  // Virtual
616 {
617 }
618 // ----------------------------------------------------------------------------
619 double* manualViewBaseContour::GetVectorPointsXManualContour(){
620         double pp[3];
621         int i,size = _sizePointsContour;
622         double *vx = (double*)malloc(sizeof(double)*size);
623         for (i=0;i<size;i++){
624                 _pts->GetPoint(i,pp);
625                 vx[i]=pp[0];
626         }
627         return vx;
628 }
629 // ----------------------------------------------------------------------------
630 double* manualViewBaseContour::GetVectorPointsYManualContour()
631 {
632         double pp[3];
633         int i,size = _sizePointsContour;
634         double *vy = (double*)malloc(sizeof(double)*size);
635         for (i=0;i<size;i++){
636                 _pts->GetPoint(i,pp);
637                 vy[i]=pp[1];
638         }
639         return vy;
640 }
641 // ----------------------------------------------------------------------------
642 double* manualViewBaseContour::GetVectorPointsZManualContour()
643 {
644         double pp[3];
645         int i,size = _sizePointsContour;
646         double *vz = (double*)malloc(sizeof(double)*size);
647         for (i=0;i<size;i++){
648                 _pts->GetPoint(i,pp);
649                 vz[i]=pp[2];
650         }
651         return vz;
652 }
653 // ----------------------------------------------------------------------------
654 void manualViewBaseContour::Refresh() // virtual
655 {
656         if (_contourVtkActor!=NULL){
657                 RefreshContour();
658         }
659         int i,size=_lstViewPoints.size();
660         for (i=0;i<size;i++){
661                 UpdateViewPoint(i);
662                 _lstViewPoints[i]->UpdateColorActor();
663         }
664         UpdateColorActor();
665
666         if (_show_text==true)
667         {
668                 RefreshText();
669         }
670
671         vtkRenderWindowInteractor *vri = _wxvtkbaseview->GetWxVTKRenderWindowInteractor ();
672         if (vri==NULL)
673         {
674                 _wxvtkbaseview->GetRenWin()->Render();
675                 printf("EED %p How to optimize manualViewBaseContour::Refresh() \n",this);
676         }
677
678 }
679 // ----------------------------------------------------------------------------
680 void manualViewBaseContour::RefreshText()  // virtual
681 {
682         if( _textActor!=NULL)
683         {
684                 _textActor -> SetInput("00");
685                 _textActor2 -> SetInput("00");
686         }
687 }
688 // ----------------------------------------------------------------------------
689 void manualViewBaseContour::SetColorNormalContour(double r, double g, double b)
690 {
691         _coulorNormal_r = r;
692         _coulorNormal_g = g;
693         _coulorNormal_b = b;
694 }
695 // ----------------------------------------------------------------------------
696 void manualViewBaseContour::GetColorNormalContour(double &r, double &g, double &b)
697 {
698         r = _coulorNormal_r;
699         g = _coulorNormal_g;
700         b = _coulorNormal_b;
701 }
702 // ----------------------------------------------------------------------------
703 void manualViewBaseContour::SetColorEditContour(double r, double g, double b)
704 {
705         _coulorEdit_r = r;
706         _coulorEdit_g = g;
707         _coulorEdit_b = b;
708 }
709 // ----------------------------------------------------------------------------
710 void manualViewBaseContour::GetColorEditContour(double &r, double &g, double &b)
711 {
712         r = _coulorEdit_r;
713         g = _coulorEdit_g;
714         b = _coulorEdit_b;
715 }
716 // ----------------------------------------------------------------------------
717 void manualViewBaseContour::SetColorSelectContour(double r, double g, double b)
718 {
719         _coulorSelection_r = r;
720         _coulorSelection_g = g;
721         _coulorSelection_b = b;
722 }
723 // ----------------------------------------------------------------------------
724 void manualViewBaseContour::GetColorSelectContour(double &r, double &g, double &b)
725 {
726         r = _coulorSelection_r;
727         g = _coulorSelection_g;
728         b = _coulorSelection_b;
729 }
730 // ----------------------------------------------------------------------------
731 void manualViewBaseContour::UpdateColorActor()
732 {
733         if (_contourVtkActor!=NULL)
734         {
735                 _contourVtkActor->GetProperty()->SetLineWidth( _widthline );
736                 _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorNormal_r , _coulorNormal_g , _coulorNormal_b );
737                 if (_posibleSelected || (_posibleSelected && GetEditable() ) )
738                 {
739                         _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorEdit_r , _coulorEdit_g , _coulorEdit_b );
740                 }
741                 if( _selected )
742                 {
743                         _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorSelection_r , _coulorSelection_g , _coulorSelection_b );
744                 }
745         }
746 }
747 // ----------------------------------------------------------------------------
748 int     manualViewBaseContour::GetIdPoint(int x, int y, int z) // virtual
749 {
750         int ii = -1;
751         if (_manContModel!=NULL){
752                 double xx = x;
753                 double yy = y;
754                 double zz = z;
755                 TransfromCoordViewWorld(xx,yy,zz);
756                 ii=_manContModel->GetIdPoint(xx,yy,zz,_range,-1);
757         }
758         return ii;
759 }
760
761 // ----------------------------------------------------------------------------
762
763
764 int manualViewBaseContour::GetNumberOfPoints()
765 {
766         return _lstViewPoints.size();
767 }
768
769 // ----------------------------------------------------------------------------
770
771 //JSTG 25-02-08 ---------------------------------------------------------------
772 /*int manualViewBaseContour::GetNumberOfPointsSpline()
773 {
774         return _sizePointsContour;
775 }*/
776 //----------------------------------------------------------------------------
777
778 //JSTG 25-02-08 ---------------------------------------------------------------
779 /*void manualViewBaseContour::SetNumberOfPointsSpline(int size)
780 {
781         _sizePointsContour = size;
782 }*/
783 //----------------------------------------------------------------------------
784 // virtual
785 void manualViewBaseContour::TransfromCoordViewWorld(double &X, double &Y, double &Z, int type)  // Virtual
786 {
787         _wxvtkbaseview->TransFromCoordScreenToWorld(X, Y, Z,false, type);
788
789
790 //EED 27 sep 2007
791 //   //EEDx6
792 //      wxVtk2DBaseView *wxvtk2Dbaseview = (wxVtk2DBaseView*)_wxvtkbaseview;
793 //      wxvtk2Dbaseview->TransformCoordinate_spacing_ModelToView(X,Y,Z);
794
795 }
796 // ----------------------------------------------------------------------------
797 void manualViewBaseContour::SetRange(double range)
798 {
799         _range=range;
800 }
801 // ----------------------------------------------------------------------------
802 double  manualViewBaseContour::GetRange()
803 {
804         return _range;
805 }
806 // ----------------------------------------------------------------------------
807 void manualViewBaseContour::SetZ(int z)
808 {
809 //      _Z=z;
810 }
811 // ----------------------------------------------------------------------------
812 int     manualViewBaseContour::GetZ()
813 {
814 //      return _Z;
815         return 0;
816 }
817 // ----------------------------------------------------------------------------
818 void manualViewBaseContour::InitMove(int x, int y, int z) // virtual
819 {
820
821 }
822 // ----------------------------------------------------------------------------
823 void manualViewBaseContour::MoveContour(int x, int y, int z) // virtual
824 {
825 }
826 // ----------------------------------------------------------------------------
827 void manualViewBaseContour::MoveContour(int horizontalUnits, int verticalUnits )// virtual
828 {
829
830 }
831 // ----------------------------------------------------------------------------
832 void manualViewBaseContour::GetMinMax( double &minX,double &minY, double &minZ, double &maxX, double &maxY, double &maxZ )// virtual
833 {
834         double  pp[3];
835         manualPoint *mp;
836         int i;
837         int size=_manContModel->GetSizeLstPoints();
838         minX=99999;
839         minY=99999;
840         maxX=-99999;
841         maxY=-99999;
842         bool ifFindZ = minZ!=-1.0 && maxZ!=-1.0;
843         if ( ifFindZ )
844         {
845                 minZ=99999;
846                 maxZ=-99999;
847         }
848         for( i = 0; i < size; i++ )
849         {
850                 mp=_manContModel->GetManualPoint(i);
851                 pp[0]=mp->GetX();
852                 pp[1]=mp->GetY();
853                 if ( ifFindZ )
854                         pp[2]=mp->GetZ();
855
856                 // min X
857                 if (pp[0]<minX)
858                 {
859                         minX=pp[0];
860                 }
861                 //min Y
862                 if (pp[1]<minY)
863                 {
864                         minY=pp[1];
865                 }
866                 //max X
867                 if (pp[0]>maxX)
868                 {
869                         maxX=pp[0];
870                 }
871                 // max Y
872                 if (pp[1]>maxY)
873                 {
874                         maxY=pp[1];
875                 }
876                 if ( ifFindZ )
877                 {
878                         // min Z
879                         if (pp[2]<minZ)
880                         {
881                                 minZ=pp[2];
882                         }
883                         // max Z
884                         if (pp[2]>maxZ)
885                         {
886                                 maxZ=pp[2];
887                         }
888                 }
889         }
890         if ( size<1 )
891         {
892                 minX = 0;
893                 maxX = 0;
894
895                 minY = 0;
896                 maxY = 0;
897
898                 minZ = 0;
899                 maxZ = 0;
900         }
901 }
902 // ----------------------------------------------------------------------------
903 void manualViewBaseContour::ClearContour()
904 {
905         if (_contourVtkActor!=NULL){
906                 _wxvtkbaseview->GetRenderer()->RemoveActor( _contourVtkActor );
907         }
908         DeleteVtkObjects();
909         int i,size=_lstViewPoints.size();
910         for (i=0;i<size;i++){
911                 ClearPoint(0);
912         }
913         Refresh();
914 }
915 // ----------------------------------------------------------------------------
916 void manualViewBaseContour::ClearPoint(int id)
917 {
918         DeletePoint(id);
919 }
920 // ----------------------------------------------------------------------------
921 void manualViewBaseContour::SetVisible(bool ok)
922 {
923         double opacity;
924         if (ok==true)
925         {
926                 opacity=1;
927         } else {
928                 opacity=0.5;
929         }
930         vtkActor *actor;
931         int i,size=_lstViewPoints.size();
932         for (i=0;i<size;i++){
933                 actor = _lstViewPoints[i]->GetVtkActor();
934                 actor->GetProperty()->SetOpacity( opacity );
935         }
936         _contourVtkActor->GetProperty()->SetOpacity( opacity );
937         _textActor->GetProperty()->SetOpacity( opacity );
938         _textActor->SetInput("00");
939         _textActor2->GetProperty()->SetOpacity( opacity );
940         _textActor2->SetInput("00");
941
942 }
943 // ----------------------------------------------------------------------------
944 void manualViewBaseContour::SetShowText(bool ok)
945 {
946         _show_text = ok;
947         if (_show_text==false && _textActor!=NULL)
948         {
949                 _textActor->SetInput("00");
950                 _textActor2->SetInput("00");
951         }
952 }
953 // ----------------------------------------------------------------------------
954 wxVtkBaseView *manualViewBaseContour::GetWxVtkBaseView()
955 {
956         return this->_wxvtkbaseview;
957 }
958 // ----------------------------------------------------------------------------
959 void manualViewBaseContour::GetSpacing(double spc[3])
960 {
961         spc[0] = _spc[0];
962         spc[1] = _spc[1];
963         spc[2] = _spc[2];
964 }
965 // ----------------------------------------------------------------------------
966 void manualViewBaseContour::SetSpacing(double spc[3])
967 {
968         _spc[0] = spc[0];
969         _spc[1] = spc[1];
970         _spc[2] = spc[2];
971 }