00001 #include "manualViewContour.h"
00002
00003
00004
00005
00006
00007 manualViewContour::manualViewContour()
00008 {
00009 _id_viewPoint_for_text = 0;
00010 _mesureScale = 1;
00011 _initialConoturModel = new manualContourModel();
00012 }
00013
00014 manualViewContour::~manualViewContour()
00015 {
00016 delete _initialConoturModel;
00017 }
00018
00019
00020
00021 manualViewContour * manualViewContour :: Clone()
00022 {
00023 manualViewContour * clone = new manualViewContour();
00024 CopyAttributesTo(clone);
00025 return clone;
00026 }
00027
00028
00029
00030 void manualViewContour::CopyAttributesTo( manualViewContour * cloneObject)
00031 {
00032
00033 manualViewBaseContour::CopyAttributesTo(cloneObject);
00034
00035 cloneObject->SetMesureScale(_mesureScale);
00036 }
00037
00038
00039
00040 int manualViewContour::GetType()
00041 {
00042 return 1;
00043 }
00044
00045
00046
00047 void manualViewContour::Save(FILE *pFile)
00048 {
00049 manualViewBaseContour::Save(pFile);
00050 }
00051
00052
00053
00054 void manualViewContour::Open(FILE *pFile)
00055 {
00056 }
00057
00058
00059
00060
00061 void manualViewContour::RefreshContour()
00062 {
00063
00064 int i,np,nps;
00065
00066
00067
00068 double x,y,z;
00069
00070
00071 _manContModel->UpdateSpline();
00072 np = GetNumberOfPoints( );
00073
00074 nps = _manContModel->GetNumberOfPointsSpline();
00075
00076
00077
00078 if ( _pts!=NULL )
00079 {
00080 if (np>=2 )
00081 {
00082 for( i = 0; i < nps; i++ )
00083 {
00084
00085
00086
00087 _manContModel->GetSpline_i_Point(i,&x,&y,&z);
00088
00089
00090
00091 _pts->SetPoint(i , x*_spc[0] , y*_spc[1] , z*_spc[2] );
00092
00093
00094 }
00095 }
00096 else
00097 {
00098 _pts->SetPoint(0, 0 , 0 , 0);
00099 _pts->SetPoint(1, 0 , 0 , 0);
00100 }
00101 }
00102 }
00103
00104
00105 void manualViewContour::RefreshText()
00106 {
00107 if ((_textActor!=NULL) && ( _textActor->GetProperty()->GetOpacity()!=0 )){
00108 int size = GetNumberOfPoints();
00109 char text[50];
00110 char resultText[50];
00111 strcpy(resultText," ");
00112 if (size==2)
00113 {
00114 strcpy(resultText,"L= ");
00115 gcvt ( _mesureScale * this->_manContModel->GetPathSize() , 5, text );
00116 strcat(resultText,text);
00117 }
00118 if (size>2)
00119 {
00120 if (_manContModel->IfCloseContour()==true)
00121 {
00122 strcpy(resultText,"P= ");
00123 gcvt ( _mesureScale * this->_manContModel->GetPathSize() , 5, text );
00124 strcat(resultText,text);
00125 gcvt ( _mesureScale * _mesureScale * this->_manContModel->GetPathArea() , 5, text );
00126 strcat(resultText," A= ");
00127 strcat(resultText,text);
00128 } else {
00129 strcpy(resultText,"L= ");
00130 gcvt ( _mesureScale * this->_manContModel->GetPathSize() , 5, text );
00131 strcat(resultText,text);
00132 }
00133 }
00134
00135 _textActor->SetInput(resultText);
00136
00137 if (size>=1){
00138
00139 int i;
00140 for (i=0; i<size; i++)
00141 {
00142 if (_lstViewPoints[i]->GetPosibleSelected()==true)
00143 {
00144 _id_viewPoint_for_text = i;
00145 }
00146 }
00147
00148 int id = _id_viewPoint_for_text;
00149 double px = _manContModel->GetManualPoint(id)->GetX();
00150 double py = _manContModel->GetManualPoint(id)->GetY();
00151
00152
00153 px=px*_spc[0];
00154 py=py*_spc[1];
00155
00156 _textActor->SetPosition(px+GetRange()+1,py);
00157 }
00158
00159 }
00160 }
00161
00162
00163 bool manualViewContour::ifTouchContour(int x,int y,int z){
00164 bool result=false;
00165 double xx=x;
00166 double yy=y;
00167 double zz=z;
00168 double ppA[3];
00169 double ppB[3];
00170 double d1,d2,d3;
00171 TransfromCoordViewWorld(xx,yy,zz);
00172
00173
00174 xx = xx * _spc[0];
00175 yy = yy * _spc[1];
00176 zz = zz * _spc[2];
00177
00178 unsigned int i, nps,nps_t;
00179 nps = _sizePointsContour;
00180
00181 if (this->_manContModel->IfCloseContour()==true)
00182 {
00183 nps_t = nps;
00184 } else {
00185 nps_t = nps-1;
00186 }
00187
00188
00189 for( i = 0; i < nps_t; i++ )
00190 {
00191 _pts->GetPoint(i%nps, ppA);
00192 _pts->GetPoint((i+1)%nps, ppB);
00193 d1= sqrt( (ppA[0]-xx)*(ppA[0]-xx) + (ppA[1]-yy)*(ppA[1]-yy) + (ppA[2]-zz)*(ppA[2]-zz));
00194 d2= sqrt( (ppB[0]-xx)*(ppB[0]-xx) + (ppB[1]-yy)*(ppB[1]-yy) + (ppB[2]-zz)*(ppB[2]-zz));
00195 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]));
00196
00197
00198 if ( ((d1+d2)>=d3) && ((d1+d2)<=d3*1.3) )
00199 {
00200 result=true;
00201 i=nps;
00202 }
00203 }
00204
00205 return result;
00206 }
00207
00208
00209 void manualViewContour::DeletePoint(int id)
00210 {
00211 if (_lstViewPoints.size()>2)
00212 {
00213 manualViewBaseContour::DeletePoint( id );
00214 }
00215 }
00216
00217
00218 void manualViewContour::ClearPoint(int id)
00219 {
00220 manualViewBaseContour::DeletePoint( id );
00221 }
00222
00223
00224 void manualViewContour::SetMesureScale(double mesureScale)
00225 {
00226 _mesureScale = mesureScale;
00227 }
00228
00229 void manualViewContour::InitMove(int x, int y, int z)
00230 {
00231 _initialConoturModel->DeleteAllPoints();
00232
00233 manualPoint *mp = NULL;
00234 double XX=x;
00235 double YY=y;
00236 double ZZ=z;
00237 TransfromCoordViewWorld(XX,YY,ZZ);
00238
00239 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
00240 for ( i=0; i<manualPointsSZ; i++ )
00241 {
00242 mp = _manContModel->GetManualPoint( i );
00243 this->_initialConoturModel->AddPoint( mp->GetX() - XX, mp->GetY() - YY, mp->GetZ() );
00244 }
00245 }
00246
00247 void manualViewContour::MoveContour(int x, int y, int z)
00248 {
00249 manualPoint *mpOrigin = NULL;
00250 manualPoint *mpMoving = NULL;
00251 double XX=x;
00252 double YY=y;
00253 double ZZ=z;
00254
00255 TransfromCoordViewWorld(XX,YY,ZZ);
00256
00257 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
00258 for ( i=0; i<manualPointsSZ; i++ )
00259 {
00260 mpOrigin = _manContModel->GetManualPoint( i );
00261 mpMoving = _initialConoturModel->GetManualPoint(i);
00262 mpOrigin->SetPoint( mpMoving->GetX()+XX, mpMoving->GetY() + YY, mpMoving->GetZ() );
00263 }
00264 UpdateViewPoints();
00265 }
00266 void manualViewContour::MoveContour(int horizontalUnits, int verticalUnits )
00267 {
00268 manualPoint *mpOrigin = NULL;
00269
00270 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
00271 for ( i=0; i<manualPointsSZ; i++ )
00272 {
00273 mpOrigin = _manContModel->GetManualPoint( i );
00274 mpOrigin->SetPoint( mpOrigin->GetX()+horizontalUnits, mpOrigin->GetY()+verticalUnits, mpOrigin->GetZ() );
00275 }
00276 UpdateViewPoints();
00277 }