1 #include "manualViewContour.h"
3 // ----------------------------------------------------------------------------
4 // ----------------------------------------------------------------------------
5 // ----------------------------------------------------------------------------
7 manualViewContour::manualViewContour()
9 _id_viewPoint_for_text = 0;
11 _initialConoturModel = new manualContourModel();
13 // ----------------------------------------------------------------------------
14 manualViewContour::~manualViewContour()
16 delete _initialConoturModel;
18 // ----------------------------------------------------------------------------
20 // ----------------------------------------------------------------------------
21 manualViewContour * manualViewContour :: Clone()
23 manualViewContour * clone = new manualViewContour();
24 CopyAttributesTo(clone);
28 // ---------------------------------------------------------------------------
30 void manualViewContour::CopyAttributesTo( manualViewContour * cloneObject)
32 // Call to Fathers object
33 manualViewBaseContour::CopyAttributesTo(cloneObject);
35 cloneObject->SetMesureScale(_mesureScale);
38 // ---------------------------------------------------------------------------
40 int manualViewContour::GetType() // virtual
45 // ----------------------------------------------------------------------------
47 void manualViewContour::Save(FILE *pFile)
49 manualViewBaseContour::Save(pFile);
52 // ----------------------------------------------------------------------------
54 void manualViewContour::Open(FILE *pFile)
60 // ----------------------------------------------------------------------------
61 void manualViewContour::RefreshContour() // virtual
66 //JSTG 25-02-08 --------------------
67 //double t,delta, x,y,z;
69 //----------------------------------
71 _manContModel->UpdateSpline();
72 np = GetNumberOfPoints( );
73 //nps = GetNumberOfPointsSpline();
74 nps = _manContModel->GetNumberOfPointsSpline();
75 //delta=( double ) ( np ) / ( double ) ( nps-1 ); //JSTG 25-02-08
82 for( i = 0; i < nps; i++ )
84 //JSTG 25-02-08 ------------------------------------------------
85 //t = delta * (double)i;
86 //_manContModel->GetSplinePoint(t,x,y,z);
87 _manContModel->GetSpline_i_Point(i,&x,&y,&z);
88 //--------------------------------------------------------------
90 // _pts->SetPoint(i, x,y,z );
91 _pts->SetPoint(i , x*_spc[0] , y*_spc[1] , z*_spc[2] );
98 _pts->SetPoint(0, 0 , 0 , 0);
99 _pts->SetPoint(1, 0 , 0 , 0);
104 // ----------------------------------------------------------------------------
105 void manualViewContour::RefreshText() // virtual
107 if ((_textActor!=NULL) && ( _textActor->GetProperty()->GetOpacity()!=0 )){
108 int size = GetNumberOfPoints();
111 strcpy(resultText," ");
114 strcpy(resultText,"L= ");
115 gcvt ( _mesureScale * this->_manContModel->GetPathSize() , 5, text );
116 strcat(resultText,text);
120 if (_manContModel->IfCloseContour()==true)
122 strcpy(resultText,"P= ");
123 gcvt ( _mesureScale * this->_manContModel->GetPathSize() , 5, text );
124 strcat(resultText,text);
125 gcvt ( _mesureScale * _mesureScale * this->_manContModel->GetPathArea() , 5, text );
126 strcat(resultText," A= ");
127 strcat(resultText,text);
129 strcpy(resultText,"L= ");
130 gcvt ( _mesureScale * this->_manContModel->GetPathSize() , 5, text );
131 strcat(resultText,text);
135 _textActor->SetInput(resultText);
140 for (i=0; i<size; i++)
142 if (_lstViewPoints[i]->GetPosibleSelected()==true)
144 _id_viewPoint_for_text = i;
148 int id = _id_viewPoint_for_text;
149 double px = _manContModel->GetManualPoint(id)->GetX();
150 double py = _manContModel->GetManualPoint(id)->GetY();
156 _textActor->SetPosition(px+GetRange()+1,py);
162 // ----------------------------------------------------------------------------
163 bool manualViewContour::ifTouchContour(int x,int y,int z){
171 TransfromeCoordViewWorld(xx,yy,zz);
178 unsigned int i, nps,nps_t;
179 nps = _sizePointsContour;
181 if (this->_manContModel->IfCloseContour()==true)
189 for( i = 0; i < nps_t; i++ )
191 _pts->GetPoint(i%nps, ppA);
192 _pts->GetPoint((i+1)%nps, ppB);
193 d1= sqrt( (ppA[0]-xx)*(ppA[0]-xx) + (ppA[1]-yy)*(ppA[1]-yy) + (ppA[2]-zz)*(ppA[2]-zz));
194 d2= sqrt( (ppB[0]-xx)*(ppB[0]-xx) + (ppB[1]-yy)*(ppB[1]-yy) + (ppB[2]-zz)*(ppB[2]-zz));
195 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]));
198 if ( ((d1+d2)>=d3) && ((d1+d2)<=d3*1.3) )
208 // ----------------------------------------------------------------------------
209 void manualViewContour::DeletePoint(int id) // virtual
211 if (_lstViewPoints.size()>2)
213 manualViewBaseContour::DeletePoint( id );
216 // ----------------------------------------------------------------------------
218 void manualViewContour::ClearPoint(int id)
220 manualViewBaseContour::DeletePoint( id );
223 //-------------------------------------------------------------------
224 void manualViewContour::SetMesureScale(double mesureScale)
226 _mesureScale = mesureScale;
228 //-------------------------------------------------------------------
229 void manualViewContour::InitMove(int x, int y, int z)
231 _initialConoturModel->DeleteAllPoints();
233 manualPoint *mp = NULL;
237 TransfromeCoordViewWorld(XX,YY,ZZ);
239 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
240 for ( i=0; i<manualPointsSZ; i++ )
242 mp = _manContModel->GetManualPoint( i );
243 this->_initialConoturModel->AddPoint( mp->GetX() - XX, mp->GetY() - YY, mp->GetZ() );
246 //-------------------------------------------------------------------
247 void manualViewContour::MoveContour(int x, int y, int z)
249 manualPoint *mpOrigin = NULL;
250 manualPoint *mpMoving = NULL;
255 TransfromeCoordViewWorld(XX,YY,ZZ);
257 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
258 for ( i=0; i<manualPointsSZ; i++ )
260 mpOrigin = _manContModel->GetManualPoint( i );
261 mpMoving = _initialConoturModel->GetManualPoint(i);
262 mpOrigin->SetPoint( mpMoving->GetX()+XX, mpMoving->GetY() + YY, mpMoving->GetZ() );
266 void manualViewContour::MoveContour(int horizontalUnits, int verticalUnits )
268 manualPoint *mpOrigin = NULL;
270 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
271 for ( i=0; i<manualPointsSZ; i++ )
273 mpOrigin = _manContModel->GetManualPoint( i );
274 mpOrigin->SetPoint( mpOrigin->GetX()+horizontalUnits, mpOrigin->GetY()+verticalUnits, mpOrigin->GetZ() );