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