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