1 #include "manualViewContour.h"
3 // ----------------------------------------------------------------------------
4 // ----------------------------------------------------------------------------
5 // ----------------------------------------------------------------------------
7 manualViewContour::manualViewContour()
9 _id_viewPoint_for_text = 0;
11 _initialConoturModel = new manualContourModel();
19 // ----------------------------------------------------------------------------
20 manualViewContour::~manualViewContour()
22 delete _initialConoturModel;
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
27 manualViewContour * manualViewContour :: Clone()
29 manualViewContour * clone = new manualViewContour();
30 CopyAttributesTo(clone);
34 // ---------------------------------------------------------------------------
36 void manualViewContour::CopyAttributesTo( manualViewContour * cloneObject)
38 // Call to Fathers object
39 manualViewBaseContour::CopyAttributesTo(cloneObject);
41 cloneObject->SetMesureScale(_mesureScale);
44 // ---------------------------------------------------------------------------
46 int manualViewContour::GetType() // virtual
51 // ----------------------------------------------------------------------------
53 void manualViewContour::Save(FILE *pFile)
55 manualViewBaseContour::Save(pFile);
58 // ----------------------------------------------------------------------------
60 void manualViewContour::Open(FILE *pFile)
64 // ----------------------------------------------------------------------------
65 void manualViewContour::RefreshContour() // virtual
69 //JSTG 25-02-08 --------------------
70 //double t,delta, x,y,z;
73 //----------------------------------
75 _manContModel->UpdateSpline();
76 np = GetNumberOfPoints( );
77 //nps = GetNumberOfPointsSpline();
78 nps = _manContModel->GetNumberOfPointsSpline();
79 //delta=( double ) ( np ) / ( double ) ( nps-1 ); //JSTG 25-02-08
92 for( i = 0; i < nps; i++ )
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 //--------------------------------------------------------------
100 // _pts->SetPoint(i, x,y,z );
104 _pts->SetPoint(i,xx,yy,zz );
108 if (xx < _minX) { _minX = xx; }
109 if (yy < _minY) { _minY = yy; }
110 if (xx > _maxX) { _maxX = xx; }
111 if (yy > _maxY) { _maxY = yy; }
117 _pts->SetPoint(0, 0 , 0 , 0);
118 _pts->SetPoint(1, 0 , 0 , 0);
123 // ----------------------------------------------------------------------------
124 void manualViewContour::RefreshText() // virtual
126 if ((_textActor!=NULL) && ( _textActor->GetProperty()->GetOpacity()!=0 )){
127 int size = GetNumberOfPoints();
130 strcpy(resultText, "000");
132 //CMRU 19-08-09 ----------------------------------
134 label = _manContModel->GetLabel();
135 // ------------------------------------
139 strcpy(resultText,"L= ");
140 gcvt ( _mesureScale * this->_manContModel->GetPathSize(), 5, text );
141 strcat(resultText,text);
143 //CMRU 19-08-09 ----------------------------------
144 strcat(resultText," ");
145 strcat(resultText,label.c_str());
146 //------------------------------------------------
150 if (_manContModel->IfCloseContour()==true)
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," ");
160 strcpy(resultText,"L= ");
161 gcvt ( _mesureScale * this->_manContModel->GetPathSize(), 5, text );
162 strcat(resultText,text);
164 //CMRU 19-08-09 ----------------------------------
165 strcat(resultText,label.c_str());
166 //------------------------------------------------
169 _textActor->SetInput(resultText);
174 for (i=0; i<size; i++)
176 if (_lstViewPoints[i]->GetPosibleSelected()==true)
178 _id_viewPoint_for_text = i;
182 if (_id_viewPoint_for_text>=size)
184 _id_viewPoint_for_text=0;
187 double px = _manContModel->GetManualPoint(_id_viewPoint_for_text)->GetX();
188 double py = _manContModel->GetManualPoint(_id_viewPoint_for_text)->GetY();
194 _textActor->SetPosition(px+GetRange()+1,py);
199 // ----------------------------------------------------------------------------
200 bool manualViewContour::ifTouchContour(int x,int y,int z)
209 TransfromCoordViewWorld(xx,yy,zz);
216 if ( (xx>=_minX) && (yy>=_minY) && (xx<=_maxX) && (yy<=_maxY)) { // inside the boundaring box
218 unsigned int i, nps,nps_t;
219 nps = _sizePointsContour;
221 if (this->_manContModel->IfCloseContour()==true)
228 printf("EED manualViewContour::ifTouchContour \n");
230 for( i = 0; i < nps_t; 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]));
239 if ( ((d1+d2)>=d3) && ((d1+d2)<=d3*1.3) )
249 // ----------------------------------------------------------------------------
250 void manualViewContour::DeletePoint(int id) // virtual
252 if (_lstViewPoints.size()>2)
254 manualViewBaseContour::DeletePoint( id );
257 // ----------------------------------------------------------------------------
259 void manualViewContour::ClearPoint(int id)
261 manualViewBaseContour::DeletePoint( id );
264 //-------------------------------------------------------------------
265 void manualViewContour::SetMesureScale(double mesureScale)
267 _mesureScale = mesureScale;
269 //-------------------------------------------------------------------
270 void manualViewContour::InitMove(int x, int y, int z)
272 _initialConoturModel->DeleteAllPoints();
274 manualPoint *mp = NULL;
278 TransfromCoordViewWorld(XX,YY,ZZ);
280 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
281 for ( i=0; i<manualPointsSZ; i++ )
283 mp = _manContModel->GetManualPoint( i );
284 this->_initialConoturModel->AddPoint( mp->GetX() - XX, mp->GetY() - YY, mp->GetZ() );
287 //-------------------------------------------------------------------
288 void manualViewContour::MoveContour(int x, int y, int z)
290 manualPoint *mpOrigin = NULL;
291 manualPoint *mpMoving = NULL;
296 TransfromCoordViewWorld(XX,YY,ZZ);
298 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
299 for ( i=0; i<manualPointsSZ; i++ )
301 mpOrigin = _manContModel->GetManualPoint( i );
302 mpMoving = _initialConoturModel->GetManualPoint(i);
303 mpOrigin->SetPoint( mpMoving->GetX()+XX, mpMoving->GetY() + YY, mpMoving->GetZ() );
307 void manualViewContour::MoveContour(int horizontalUnits, int verticalUnits )
309 manualPoint *mpOrigin = NULL;
311 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
312 for ( i=0; i<manualPointsSZ; i++ )
314 mpOrigin = _manContModel->GetManualPoint( i );
315 mpOrigin->SetPoint( mpOrigin->GetX()+horizontalUnits, mpOrigin->GetY()+verticalUnits, mpOrigin->GetZ() );