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