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