]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualViewContour.cpp
8cc853cb0b28244b5806e3ce307a42528d60d980
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualContour / manualViewContour.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 "manualViewContour.h"
27
28 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
31
32 manualViewContour::manualViewContour()
33 {
34         _id_viewPoint_for_text  = 0;
35         _mesureScale                    = 1;
36         _initialConoturModel    = new manualContourModel();
37         
38         _minX                                   = 99999;
39         _minY                                   = 99999;
40         _maxX                                   = -99999;
41         _maxY                                   = -99999;
42         
43 }
44 // ----------------------------------------------------------------------------
45 manualViewContour::~manualViewContour()
46 {
47         delete _initialConoturModel;
48 }
49 // ----------------------------------------------------------------------------
50
51 // ----------------------------------------------------------------------------
52 manualViewContour * manualViewContour :: Clone()
53 {
54         manualViewContour * clone = new manualViewContour();
55         CopyAttributesTo(clone);
56         return clone;
57 }
58
59 // ---------------------------------------------------------------------------
60
61 void manualViewContour::CopyAttributesTo( manualViewContour * cloneObject)
62 {
63         // Call to Fathers object
64         manualViewBaseContour::CopyAttributesTo(cloneObject);
65
66         cloneObject->SetMesureScale(_mesureScale);
67 }
68
69 // ---------------------------------------------------------------------------
70
71 int manualViewContour::GetType() // virtual
72 {
73         return 1;
74 }
75
76 // ----------------------------------------------------------------------------
77
78 void manualViewContour::Save(FILE *pFile)
79 {
80         manualViewBaseContour::Save(pFile);
81 }
82
83 // ----------------------------------------------------------------------------
84
85 void manualViewContour::Open(FILE *pFile)
86 {
87 }
88
89 // ----------------------------------------------------------------------------
90 void manualViewContour::RefreshContour() // virtual
91 {
92         int i,np,nps;
93
94 //JSTG 25-02-08 --------------------
95         //double t,delta, x,y,z;
96         double x,y,z;
97         double xx,yy,zz;
98 //----------------------------------
99
100         _manContModel->UpdateSpline();
101     np  = GetNumberOfPoints( );
102         //nps = GetNumberOfPointsSpline();
103     nps = _manContModel->GetNumberOfPointsSpline();
104         //delta=( double ) ( np  ) / ( double ) ( nps-1  );             //JSTG 25-02-08
105
106         //EED 27 Juin 2012
107     //Boundaring box    
108         _minX=99999;
109         _minY=99999;
110         _maxX=-99999;
111         _maxY=-99999;
112         
113         if ( _pts!=NULL )
114         {
115                 if (np>=2  )
116                 {
117                         for( i = 0; i < nps; i++ )
118                         {
119 //JSTG 25-02-08 ------------------------------------------------
120                                 //t = delta * (double)i;
121                                 //_manContModel->GetSplinePoint(t,x,y,z);
122                                 _manContModel->GetSpline_i_Point(i,&x,&y,&z);
123 //--------------------------------------------------------------
124         // EED 27 sep 2006
125         //                      _pts->SetPoint(i, x,y,z );
126                                 xx=x*_spc[0];
127                                 yy=y*_spc[1];
128                                 zz=z*_spc[2];
129                                 _pts->SetPoint(i,xx,yy,zz );
130
131                 //EED 27 Juin 2012
132                                 //Boundaring box
133                                 if (xx < _minX) { _minX = xx; }
134                                 if (yy < _minY) { _minY = yy; }
135                                 if (xx > _maxX) { _maxX = xx; }
136                                 if (yy > _maxY) { _maxY = yy; }
137                                 
138                         }// for
139                 }
140                 else
141                 {
142                                 _pts->SetPoint(0, 0 , 0 , 0);
143                                 _pts->SetPoint(1, 0 , 0 , 0);
144                 } // if
145         }
146 }
147
148 // ----------------------------------------------------------------------------
149 void manualViewContour::RefreshText()  // virtual
150 {
151         if ((_textActor!=NULL) && ( _textActor->GetProperty()->GetOpacity()!=0 )){
152                 int size = GetNumberOfPoints();
153                 char text[50];
154                 char resultText[50];
155                 strcpy(resultText, "000");
156
157 //CMRU 19-08-09 ----------------------------------
158                 std::string label;
159                 label = _manContModel->GetLabel();
160 // ------------------------------------
161
162                 if (size==2)
163                 {
164                         strcpy(resultText,"L= ");
165                         gcvt ( _mesureScale * this->_manContModel->GetPathSize(), 5, text );
166                         strcat(resultText,text);
167
168 //CMRU 19-08-09 ----------------------------------
169                         strcat(resultText," ");
170                         strcat(resultText,label.c_str());
171 //------------------------------------------------
172                 }
173                 if (size>2)
174                 {
175                         if (_manContModel->IfCloseContour()==true)
176                         {
177                                 strcpy(resultText,"P= ");
178                                 gcvt ( _mesureScale * this->_manContModel->GetPathSize(), 5, text );
179                                 strcat(resultText,text);
180                                 gcvt ( _mesureScale * _mesureScale * this->_manContModel->GetPathArea(), 5, text );
181                                 strcat(resultText,"   A= ");
182                                 strcat(resultText,text);
183                                 strcat(resultText," ");
184                         } else {
185                                 strcpy(resultText,"L= ");
186                                 gcvt (  _mesureScale * this->_manContModel->GetPathSize(), 5, text );
187                                 strcat(resultText,text);
188                         }
189 //CMRU 19-08-09 ----------------------------------
190                         strcat(resultText,label.c_str());
191 //------------------------------------------------
192                 }
193
194                 _textActor->SetInput(resultText);
195                 
196                 if (size>=1){
197
198                         int i;
199                         for (i=0; i<size; i++)
200                         {
201                                 if (_lstViewPoints[i]->GetPosibleSelected()==true)
202                                 {
203                                         _id_viewPoint_for_text = i;
204                                 }
205                         }
206
207                         if (_id_viewPoint_for_text>=size) 
208                         {
209                                 _id_viewPoint_for_text=0;
210                         }
211                         
212                         double px = _manContModel->GetManualPoint(_id_viewPoint_for_text)->GetX();
213                         double py = _manContModel->GetManualPoint(_id_viewPoint_for_text)->GetY();
214
215                         //EED 27 sep 2006
216                         px=px*_spc[0];
217                         py=py*_spc[1];
218
219                         _textActor->SetPosition(px+GetRange()+1,py);
220                 }
221         }
222 }
223
224 // ----------------------------------------------------------------------------
225 bool manualViewContour::ifTouchContour(int x,int y,int z)
226 {
227         bool result=false;
228         double xx=x;
229         double yy=y;
230         double zz=z;
231         double ppA[3];
232         double ppB[3];
233         double d1,d2,d3;
234         TransfromCoordViewWorld(xx,yy,zz);
235
236 //EED 27 sep 2006
237         xx = xx * _spc[0];
238         yy = yy * _spc[1];
239         zz = zz * _spc[2];
240
241         if ( (xx>=_minX) &&  (yy>=_minY) && (xx<=_maxX) && (yy<=_maxY)) {  // inside the boundaring box
242         
243                 unsigned int i, nps,nps_t;
244                 nps       = _sizePointsContour;
245         
246                 if (this->_manContModel->IfCloseContour()==true)
247                 {
248                         nps_t = nps;
249                 } else {
250                 nps_t = nps-1;
251                 } // if close
252
253 printf("EED  Warning manualViewContour::ifTouchContour \n");
254
255                 for( i = 0; i < nps_t; i++ ) 
256                 {
257                         _pts->GetPoint(i%nps, ppA);
258                         _pts->GetPoint((i+1)%nps, ppB);
259                         d1 = sqrt( (ppA[0]-xx)*(ppA[0]-xx) + (ppA[1]-yy)*(ppA[1]-yy) + (ppA[2]-zz)*(ppA[2]-zz));
260                         d2 = sqrt( (ppB[0]-xx)*(ppB[0]-xx) + (ppB[1]-yy)*(ppB[1]-yy) + (ppB[2]-zz)*(ppB[2]-zz));
261                         d3 = sqrt( (ppB[0]-ppA[0])*(ppB[0]-ppA[0]) + (ppB[1]-ppA[1])*(ppB[1]-ppA[1]) + (ppB[2]-ppA[2])*(ppB[2]-ppA[2]));
262
263                         if (  ((d1+d2)>=d3) &&  ((d1+d2)<=d3*1.3) ) 
264                         {
265                                 result=true;
266                                 i=nps;
267                         } // if
268                 } // for i
269         } // if min max
270         return result;
271 }
272
273 // ----------------------------------------------------------------------------
274 void manualViewContour::DeletePoint(int id) // virtual
275 {
276         if (_lstViewPoints.size()>2)
277         {
278                 manualViewBaseContour::DeletePoint( id );
279         }
280 }
281 // ----------------------------------------------------------------------------
282
283 void manualViewContour::ClearPoint(int id)
284 {
285         manualViewBaseContour::DeletePoint( id );
286 }
287
288 //-------------------------------------------------------------------
289 void manualViewContour::SetMesureScale(double mesureScale)
290 {
291         _mesureScale = mesureScale;
292 }
293 //-------------------------------------------------------------------
294 void manualViewContour::InitMove(int x, int y, int z)
295 {
296         _initialConoturModel->DeleteAllPoints();
297
298         manualPoint *mp = NULL;
299         double XX=x;
300         double YY=y;
301         double ZZ=z;
302         TransfromCoordViewWorld(XX,YY,ZZ);
303
304         int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
305         for ( i=0; i<manualPointsSZ; i++ )
306         {
307                 mp = _manContModel->GetManualPoint( i );
308                 this->_initialConoturModel->AddPoint( mp->GetX() - XX, mp->GetY() - YY, mp->GetZ() );
309         }
310 }
311 //-------------------------------------------------------------------
312 void manualViewContour::MoveContour(int x, int y, int z)
313 {
314         manualPoint *mpOrigin = NULL;
315         manualPoint *mpMoving = NULL;
316         double XX=x;
317         double YY=y;
318         double ZZ=z;
319
320         TransfromCoordViewWorld(XX,YY,ZZ);
321
322         int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
323         for ( i=0; i<manualPointsSZ; i++ )
324         {
325                 mpOrigin = _manContModel->GetManualPoint( i );
326                 mpMoving = _initialConoturModel->GetManualPoint(i);
327                 mpOrigin->SetPoint( mpMoving->GetX()+XX, mpMoving->GetY() + YY, mpMoving->GetZ() );
328         }
329         UpdateViewPoints();
330 }
331 void manualViewContour::MoveContour(int horizontalUnits, int verticalUnits )
332 {
333         manualPoint *mpOrigin = NULL;
334
335         int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
336         for ( i=0; i<manualPointsSZ; i++ )
337         {
338                 mpOrigin = _manContModel->GetManualPoint( i );
339                 mpOrigin->SetPoint( mpOrigin->GetX()+horizontalUnits, mpOrigin->GetY()+verticalUnits, mpOrigin->GetZ() );
340         }
341         UpdateViewPoints();
342 }