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
90 for( i = 0; i < nps; i++ )
92 //JSTG 25-02-08 ------------------------------------------------
93 //t = delta * (double)i;
94 //_manContModel->GetSplinePoint(t,x,y,z);
95 _manContModel->GetSpline_i_Point(i,&x,&y,&z);
96 //--------------------------------------------------------------
98 // _pts->SetPoint(i, x,y,z );
102 _pts->SetPoint(i,xx,yy,zz );
105 if (xx < _minX) { _minX = xx; }
106 if (yy < _minY) { _minY = yy; }
107 if (xx > _maxX) { _maxX = xx; }
108 if (yy > _maxY) { _maxY = yy; }
114 _pts->SetPoint(0, 0 , 0 , 0);
115 _pts->SetPoint(1, 0 , 0 , 0);
120 // ----------------------------------------------------------------------------
121 void manualViewContour::RefreshText() // virtual
123 if ((_textActor!=NULL) && ( _textActor->GetProperty()->GetOpacity()!=0 )){
124 int size = GetNumberOfPoints();
127 strcpy(resultText, "000");
129 //CMRU 19-08-09 ----------------------------------
131 label = _manContModel->GetLabel();
132 // ------------------------------------
136 strcpy(resultText,"L= ");
137 gcvt ( _mesureScale * this->_manContModel->GetPathSize(), 5, text );
138 strcat(resultText,text);
140 //CMRU 19-08-09 ----------------------------------
141 strcat(resultText," ");
142 strcat(resultText,label.c_str());
143 //------------------------------------------------
147 if (_manContModel->IfCloseContour()==true)
149 strcpy(resultText,"P= ");
150 gcvt ( _mesureScale * this->_manContModel->GetPathSize(), 5, text );
151 strcat(resultText,text);
152 gcvt ( _mesureScale * _mesureScale * this->_manContModel->GetPathArea(), 5, text );
153 strcat(resultText," A= ");
154 strcat(resultText,text);
155 strcat(resultText," ");
157 strcpy(resultText,"L= ");
158 gcvt ( _mesureScale * this->_manContModel->GetPathSize(), 5, text );
159 strcat(resultText,text);
161 //CMRU 19-08-09 ----------------------------------
162 strcat(resultText,label.c_str());
163 //------------------------------------------------
166 _textActor->SetInput(resultText);
171 for (i=0; i<size; i++)
173 if (_lstViewPoints[i]->GetPosibleSelected()==true)
175 _id_viewPoint_for_text = i;
179 if (_id_viewPoint_for_text>=size)
181 _id_viewPoint_for_text=0;
184 double px = _manContModel->GetManualPoint(_id_viewPoint_for_text)->GetX();
185 double py = _manContModel->GetManualPoint(_id_viewPoint_for_text)->GetY();
191 _textActor->SetPosition(px+GetRange()+1,py);
196 // ----------------------------------------------------------------------------
197 bool manualViewContour::ifTouchContour(int x,int y,int z)
206 TransfromCoordViewWorld(xx,yy,zz);
213 if ( (xx>=_minX) && (yy>=_minY) && (xx<=_maxX) && (yy<=_maxY)) {
215 unsigned int i, nps,nps_t;
216 nps = _sizePointsContour;
218 if (this->_manContModel->IfCloseContour()==true)
225 printf("EED manualViewContour::ifTouchContour \n");
227 for( i = 0; i < nps_t; i++ )
230 _pts->GetPoint(i%nps, ppA);
231 _pts->GetPoint((i+1)%nps, ppB);
232 d1 = sqrt( (ppA[0]-xx)*(ppA[0]-xx) + (ppA[1]-yy)*(ppA[1]-yy) + (ppA[2]-zz)*(ppA[2]-zz));
233 d2 = sqrt( (ppB[0]-xx)*(ppB[0]-xx) + (ppB[1]-yy)*(ppB[1]-yy) + (ppB[2]-zz)*(ppB[2]-zz));
234 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]));
236 if ( ((d1+d2)>=d3) && ((d1+d2)<=d3*1.3) )
246 // ----------------------------------------------------------------------------
247 void manualViewContour::DeletePoint(int id) // virtual
249 if (_lstViewPoints.size()>2)
251 manualViewBaseContour::DeletePoint( id );
254 // ----------------------------------------------------------------------------
256 void manualViewContour::ClearPoint(int id)
258 manualViewBaseContour::DeletePoint( id );
261 //-------------------------------------------------------------------
262 void manualViewContour::SetMesureScale(double mesureScale)
264 _mesureScale = mesureScale;
266 //-------------------------------------------------------------------
267 void manualViewContour::InitMove(int x, int y, int z)
269 _initialConoturModel->DeleteAllPoints();
271 manualPoint *mp = NULL;
275 TransfromCoordViewWorld(XX,YY,ZZ);
277 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
278 for ( i=0; i<manualPointsSZ; i++ )
280 mp = _manContModel->GetManualPoint( i );
281 this->_initialConoturModel->AddPoint( mp->GetX() - XX, mp->GetY() - YY, mp->GetZ() );
284 //-------------------------------------------------------------------
285 void manualViewContour::MoveContour(int x, int y, int z)
287 manualPoint *mpOrigin = NULL;
288 manualPoint *mpMoving = NULL;
293 TransfromCoordViewWorld(XX,YY,ZZ);
295 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
296 for ( i=0; i<manualPointsSZ; i++ )
298 mpOrigin = _manContModel->GetManualPoint( i );
299 mpMoving = _initialConoturModel->GetManualPoint(i);
300 mpOrigin->SetPoint( mpMoving->GetX()+XX, mpMoving->GetY() + YY, mpMoving->GetZ() );
304 void manualViewContour::MoveContour(int horizontalUnits, int verticalUnits )
306 manualPoint *mpOrigin = NULL;
308 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
309 for ( i=0; i<manualPointsSZ; i++ )
311 mpOrigin = _manContModel->GetManualPoint( i );
312 mpOrigin->SetPoint( mpOrigin->GetX()+horizontalUnits, mpOrigin->GetY()+verticalUnits, mpOrigin->GetZ() );