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