]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualViewBaseContour.cpp
#3470 merge vtk8itk5wx3-mingw64
[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      = 500;
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         _bboxMapper->ImmediateModeRenderingOn();
318 #else
319         _bboxMapper->SetInputData(_pd);
320 #endif
321
322
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         {
654                 _pts->GetPoint(i,pp);
655                 vx[i]=pp[0];
656         } // for i
657         return vx;
658 }
659 // ----------------------------------------------------------------------------
660 double* manualViewBaseContour::GetVectorPointsYManualContour()
661 {
662         double pp[3];
663         int i,size = _sizePointsContour;
664         double *vy = (double*)malloc(sizeof(double)*size);
665         for (i=0;i<size;i++)
666         {
667                 _pts->GetPoint(i,pp);
668                 vy[i]=pp[1];
669         } // for i
670         return vy;
671 }
672 // ----------------------------------------------------------------------------
673 double* manualViewBaseContour::GetVectorPointsZManualContour()
674 {
675         double pp[3];
676         int i,size = _sizePointsContour;
677         double *vz = (double*)malloc(sizeof(double)*size);
678         for (i=0;i<size;i++)
679         {
680                 _pts->GetPoint(i,pp);
681                 vz[i]=pp[2];
682         } // for i
683         return vz;
684 }
685 // ----------------------------------------------------------------------------
686 void manualViewBaseContour::Refresh() // virtual
687 {
688         if (_contourVtkActor!=NULL)
689         {
690                 RefreshContour();
691         }
692         int i,size=_lstViewPoints.size();
693         for (i=0;i<size;i++)
694         {
695                 UpdateViewPoint(i);
696                 _lstViewPoints[i]->UpdateColorActor();
697         } // for i
698         UpdateColorActor();
699
700         if (_show_text==true)
701         {
702                 RefreshText();
703         }
704
705         vtkRenderWindowInteractor *vri = _wxvtkbaseview->GetWxVTKRenderWindowInteractor ();
706         if (vri==NULL)
707         {
708                 _wxvtkbaseview->GetRenWin()->Render();
709                 printf("EED %p How to optimize manualViewBaseContour::Refresh() \n",this);
710         }
711
712 }
713 // ----------------------------------------------------------------------------
714 void manualViewBaseContour::RefreshText()  // virtual
715 {
716         if( _textActor!=NULL)
717         {
718                 _textActor -> SetInput("00");
719                 _textActor2 -> SetInput("00");
720         }
721 }
722 // ----------------------------------------------------------------------------
723 void manualViewBaseContour::SetColorNormalContour(double r, double g, double b)
724 {
725         _coulorNormal_r = r;
726         _coulorNormal_g = g;
727         _coulorNormal_b = b;
728 }
729 // ----------------------------------------------------------------------------
730 void manualViewBaseContour::GetColorNormalContour(double &r, double &g, double &b)
731 {
732         r = _coulorNormal_r;
733         g = _coulorNormal_g;
734         b = _coulorNormal_b;
735 }
736 // ----------------------------------------------------------------------------
737 void manualViewBaseContour::SetColorEditContour(double r, double g, double b)
738 {
739         _coulorEdit_r = r;
740         _coulorEdit_g = g;
741         _coulorEdit_b = b;
742 }
743 // ----------------------------------------------------------------------------
744 void manualViewBaseContour::GetColorEditContour(double &r, double &g, double &b)
745 {
746         r = _coulorEdit_r;
747         g = _coulorEdit_g;
748         b = _coulorEdit_b;
749 }
750 // ----------------------------------------------------------------------------
751 void manualViewBaseContour::SetColorSelectContour(double r, double g, double b)
752 {
753         _coulorSelection_r = r;
754         _coulorSelection_g = g;
755         _coulorSelection_b = b;
756 }
757 // ----------------------------------------------------------------------------
758 void manualViewBaseContour::GetColorSelectContour(double &r, double &g, double &b)
759 {
760         r = _coulorSelection_r;
761         g = _coulorSelection_g;
762         b = _coulorSelection_b;
763 }
764 // ----------------------------------------------------------------------------
765 void manualViewBaseContour::UpdateColorActor()
766 {
767         if (_contourVtkActor!=NULL)
768         {
769                 _contourVtkActor->GetProperty()->SetLineWidth( _widthline );
770                 _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorNormal_r , _coulorNormal_g , _coulorNormal_b );
771                 if (_posibleSelected || (_posibleSelected && GetEditable() ) )
772                 {
773                         _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorEdit_r , _coulorEdit_g , _coulorEdit_b );
774                 }
775                 if( _selected )
776                 {
777                         _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorSelection_r , _coulorSelection_g , _coulorSelection_b );
778                 }
779         }
780 }
781 // ----------------------------------------------------------------------------
782 int     manualViewBaseContour::GetIdPoint(int x, int y, int z) // virtual
783 {
784         int ii = -1;
785         if (_manContModel!=NULL){
786                 double xx = x;
787                 double yy = y;
788                 double zz = z;
789                 TransfromCoordViewWorld(xx,yy,zz);
790                 ii=_manContModel->GetIdPoint(xx,yy,zz,_range,-1);
791         }
792         return ii;
793 }
794
795 // ----------------------------------------------------------------------------
796
797
798 int manualViewBaseContour::GetNumberOfPoints()
799 {
800         return _lstViewPoints.size();
801 }
802
803 // ----------------------------------------------------------------------------
804
805 //JSTG 25-02-08 ---------------------------------------------------------------
806 /*int manualViewBaseContour::GetNumberOfPointsSpline()
807 {
808         return _sizePointsContour;
809 }*/
810 //----------------------------------------------------------------------------
811
812 //JSTG 25-02-08 ---------------------------------------------------------------
813 /*void manualViewBaseContour::SetNumberOfPointsSpline(int size)
814 {
815         _sizePointsContour = size;
816 }*/
817 //----------------------------------------------------------------------------
818 // virtual
819 void manualViewBaseContour::TransfromCoordViewWorld(double &X, double &Y, double &Z, int type)  // Virtual
820 {
821         _wxvtkbaseview->TransFromCoordScreenToWorld(X, Y, Z,false, type);
822
823
824 //EED 27 sep 2007
825 //   //EEDx6
826 //      wxVtk2DBaseView *wxvtk2Dbaseview = (wxVtk2DBaseView*)_wxvtkbaseview;
827 //      wxvtk2Dbaseview->TransformCoordinate_spacing_ModelToView(X,Y,Z);
828
829 }
830 // ----------------------------------------------------------------------------
831 void manualViewBaseContour::SetRange(double range)
832 {
833         _range=range;
834 }
835 // ----------------------------------------------------------------------------
836 double  manualViewBaseContour::GetRange()
837 {
838         return _range;
839 }
840 // ----------------------------------------------------------------------------
841 void manualViewBaseContour::SetZ(int z)
842 {
843 //      _Z=z;
844 }
845 // ----------------------------------------------------------------------------
846 int     manualViewBaseContour::GetZ()
847 {
848 //      return _Z;
849         return 0;
850 }
851 // ----------------------------------------------------------------------------
852 void manualViewBaseContour::InitMove(int x, int y, int z) // virtual
853 {
854
855 }
856 // ----------------------------------------------------------------------------
857 void manualViewBaseContour::MoveContour(int x, int y, int z) // virtual
858 {
859 }
860 // ----------------------------------------------------------------------------
861 void manualViewBaseContour::MoveContour(int horizontalUnits, int verticalUnits )// virtual
862 {
863
864 }
865 // ----------------------------------------------------------------------------
866 void manualViewBaseContour::GetMinMax( double &minX,double &minY, double &minZ, double &maxX, double &maxY, double &maxZ )// virtual
867 {
868         double  pp[3];
869         manualPoint *mp;
870         int i;
871         int size=_manContModel->GetSizeLstPoints();
872         minX=99999;
873         minY=99999;
874         maxX=-99999;
875         maxY=-99999;
876         bool ifFindZ = minZ!=-1.0 && maxZ!=-1.0;
877         if ( ifFindZ )
878         {
879                 minZ=99999;
880                 maxZ=-99999;
881         }
882         for( i = 0; i < size; i++ )
883         {
884                 mp=_manContModel->GetManualPoint(i);
885                 pp[0]=mp->GetX();
886                 pp[1]=mp->GetY();
887                 if ( ifFindZ )
888                         pp[2]=mp->GetZ();
889
890                 // min X
891                 if (pp[0]<minX)
892                 {
893                         minX=pp[0];
894                 }
895                 //min Y
896                 if (pp[1]<minY)
897                 {
898                         minY=pp[1];
899                 }
900                 //max X
901                 if (pp[0]>maxX)
902                 {
903                         maxX=pp[0];
904                 }
905                 // max Y
906                 if (pp[1]>maxY)
907                 {
908                         maxY=pp[1];
909                 }
910                 if ( ifFindZ )
911                 {
912                         // min Z
913                         if (pp[2]<minZ)
914                         {
915                                 minZ=pp[2];
916                         }
917                         // max Z
918                         if (pp[2]>maxZ)
919                         {
920                                 maxZ=pp[2];
921                         }
922                 }
923         }
924         if ( size<1 )
925         {
926                 minX = 0;
927                 maxX = 0;
928
929                 minY = 0;
930                 maxY = 0;
931
932                 minZ = 0;
933                 maxZ = 0;
934         }
935 }
936 // ----------------------------------------------------------------------------
937 void manualViewBaseContour::ClearContour()
938 {
939         if (_contourVtkActor!=NULL){
940                 _wxvtkbaseview->GetRenderer()->RemoveActor( _contourVtkActor );
941         }
942         DeleteVtkObjects();
943         int i,size=_lstViewPoints.size();
944         for (i=0;i<size;i++){
945                 ClearPoint(0);
946         }
947         Refresh();
948 }
949 // ----------------------------------------------------------------------------
950 void manualViewBaseContour::ClearPoint(int id)
951 {
952         DeletePoint(id);
953 }
954 // ----------------------------------------------------------------------------
955 void manualViewBaseContour::SetVisible(bool ok)
956 {
957         double opacity;
958         if (ok==true)
959         {
960                 opacity=1;
961         } else {
962                 opacity=0.5;
963         }
964         vtkActor *actor;
965         int i,size=_lstViewPoints.size();
966         for (i=0;i<size;i++){
967                 actor = _lstViewPoints[i]->GetVtkActor();
968                 actor->GetProperty()->SetOpacity( opacity );
969         }
970         _contourVtkActor->GetProperty()->SetOpacity( opacity );
971         _textActor->GetProperty()->SetOpacity( opacity );
972         _textActor->SetInput("00");
973         _textActor2->GetProperty()->SetOpacity( opacity );
974         _textActor2->SetInput("00");
975
976 }
977 // ----------------------------------------------------------------------------
978 void manualViewBaseContour::SetShowText(bool ok)
979 {
980         _show_text = ok;
981         if (_show_text==false && _textActor!=NULL)
982         {
983                 _textActor->SetInput("");
984                 _textActor2->SetInput("");
985         }
986 }
987 // ----------------------------------------------------------------------------
988 wxVtkBaseView *manualViewBaseContour::GetWxVtkBaseView()
989 {
990         return this->_wxvtkbaseview;
991 }
992 // ----------------------------------------------------------------------------
993 void manualViewBaseContour::GetSpacing(double spc[3])
994 {
995         spc[0] = _spc[0];
996         spc[1] = _spc[1];
997         spc[2] = _spc[2];
998 }
999 // ----------------------------------------------------------------------------
1000 void manualViewBaseContour::SetSpacing(double spc[3])
1001 {
1002         _spc[0] = spc[0];
1003         _spc[1] = spc[1];
1004         _spc[2] = spc[2];
1005 }