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