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 void manualViewContour::RefreshContour()
00060 {
00061 int i,np,nps;
00062
00063
00064
00065 double x,y,z;
00066
00067
00068 _manContModel->UpdateSpline();
00069 np = GetNumberOfPoints( );
00070
00071 nps = _manContModel->GetNumberOfPointsSpline();
00072
00073
00074
00075 if ( _pts!=NULL )
00076 {
00077 if (np>=2 )
00078 {
00079 for( i = 0; i < nps; i++ )
00080 {
00081
00082
00083
00084 _manContModel->GetSpline_i_Point(i,&x,&y,&z);
00085
00086
00087
00088 _pts->SetPoint(i, x*_spc[0], y*_spc[1], z*_spc[2] );
00089
00090 }
00091 }
00092 else
00093 {
00094 _pts->SetPoint(0, 0 , 0 , 0);
00095 _pts->SetPoint(1, 0 , 0 , 0);
00096 }
00097 }
00098 }
00099
00100
00101 void manualViewContour::RefreshText()
00102 {
00103 if ((_textActor!=NULL) && ( _textActor->GetProperty()->GetOpacity()!=0 )){
00104 int size = GetNumberOfPoints();
00105 char text[50];
00106 char resultText[50];
00107 strcpy(resultText, "000");
00108
00109
00110 std::string label;
00111 label = _manContModel->GetLabel();
00112
00113
00114 if (size==2)
00115 {
00116 strcpy(resultText,"L= ");
00117 gcvt ( _mesureScale * this->_manContModel->GetPathSize(), 5, text );
00118 strcat(resultText,text);
00119
00120
00121 strcat(resultText," ");
00122 strcat(resultText,label.c_str());
00123
00124 }
00125 if (size>2)
00126 {
00127 if (_manContModel->IfCloseContour()==true)
00128 {
00129 strcpy(resultText,"P= ");
00130 gcvt ( _mesureScale * this->_manContModel->GetPathSize(), 5, text );
00131 strcat(resultText,text);
00132 gcvt ( _mesureScale * _mesureScale * this->_manContModel->GetPathArea(), 5, text );
00133 strcat(resultText," A= ");
00134 strcat(resultText,text);
00135 strcat(resultText," ");
00136 } else {
00137 strcpy(resultText,"L= ");
00138 gcvt ( _mesureScale * this->_manContModel->GetPathSize(), 5, text );
00139 strcat(resultText,text);
00140 }
00141
00142 strcat(resultText,label.c_str());
00143
00144 }
00145
00146 _textActor->SetInput(resultText);
00147
00148 if (size>=1){
00149
00150 int i;
00151 for (i=0; i<size; i++)
00152 {
00153 if (_lstViewPoints[i]->GetPosibleSelected()==true)
00154 {
00155 _id_viewPoint_for_text = i;
00156 }
00157 }
00158
00159 if (_id_viewPoint_for_text>=size)
00160 {
00161 _id_viewPoint_for_text=0;
00162 }
00163
00164 double px = _manContModel->GetManualPoint(_id_viewPoint_for_text)->GetX();
00165 double py = _manContModel->GetManualPoint(_id_viewPoint_for_text)->GetY();
00166
00167
00168 px=px*_spc[0];
00169 py=py*_spc[1];
00170
00171 _textActor->SetPosition(px+GetRange()+1,py);
00172 }
00173 }
00174 }
00175
00176
00177 bool manualViewContour::ifTouchContour(int x,int y,int z){
00178 bool result=false;
00179 double xx=x;
00180 double yy=y;
00181 double zz=z;
00182 double ppA[3];
00183 double ppB[3];
00184 double d1,d2,d3;
00185 TransfromCoordViewWorld(xx,yy,zz);
00186
00187
00188 xx = xx * _spc[0];
00189 yy = yy * _spc[1];
00190 zz = zz * _spc[2];
00191
00192 unsigned int i, nps,nps_t;
00193 nps = _sizePointsContour;
00194
00195 if (this->_manContModel->IfCloseContour()==true)
00196 {
00197 nps_t = nps;
00198 } else {
00199 nps_t = nps-1;
00200 }
00201
00202 for( i = 0; i < nps_t; i++ )
00203 {
00204 _pts->GetPoint(i%nps, ppA);
00205 _pts->GetPoint((i+1)%nps, ppB);
00206 d1= sqrt( (ppA[0]-xx)*(ppA[0]-xx) + (ppA[1]-yy)*(ppA[1]-yy) + (ppA[2]-zz)*(ppA[2]-zz));
00207 d2= sqrt( (ppB[0]-xx)*(ppB[0]-xx) + (ppB[1]-yy)*(ppB[1]-yy) + (ppB[2]-zz)*(ppB[2]-zz));
00208 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]));
00209
00210
00211 if ( ((d1+d2)>=d3) && ((d1+d2)<=d3*1.3) )
00212 {
00213 result=true;
00214 i=nps;
00215 }
00216 }
00217 return result;
00218 }
00219
00220
00221 void manualViewContour::DeletePoint(int id)
00222 {
00223 if (_lstViewPoints.size()>2)
00224 {
00225 manualViewBaseContour::DeletePoint( id );
00226 }
00227 }
00228
00229
00230 void manualViewContour::ClearPoint(int id)
00231 {
00232 manualViewBaseContour::DeletePoint( id );
00233 }
00234
00235
00236 void manualViewContour::SetMesureScale(double mesureScale)
00237 {
00238 _mesureScale = mesureScale;
00239 }
00240
00241 void manualViewContour::InitMove(int x, int y, int z)
00242 {
00243 _initialConoturModel->DeleteAllPoints();
00244
00245 manualPoint *mp = NULL;
00246 double XX=x;
00247 double YY=y;
00248 double ZZ=z;
00249 TransfromCoordViewWorld(XX,YY,ZZ);
00250
00251 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
00252 for ( i=0; i<manualPointsSZ; i++ )
00253 {
00254 mp = _manContModel->GetManualPoint( i );
00255 this->_initialConoturModel->AddPoint( mp->GetX() - XX, mp->GetY() - YY, mp->GetZ() );
00256 }
00257 }
00258
00259 void manualViewContour::MoveContour(int x, int y, int z)
00260 {
00261 manualPoint *mpOrigin = NULL;
00262 manualPoint *mpMoving = NULL;
00263 double XX=x;
00264 double YY=y;
00265 double ZZ=z;
00266
00267 TransfromCoordViewWorld(XX,YY,ZZ);
00268
00269 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
00270 for ( i=0; i<manualPointsSZ; i++ )
00271 {
00272 mpOrigin = _manContModel->GetManualPoint( i );
00273 mpMoving = _initialConoturModel->GetManualPoint(i);
00274 mpOrigin->SetPoint( mpMoving->GetX()+XX, mpMoving->GetY() + YY, mpMoving->GetZ() );
00275 }
00276 UpdateViewPoints();
00277 }
00278 void manualViewContour::MoveContour(int horizontalUnits, int verticalUnits )
00279 {
00280 manualPoint *mpOrigin = NULL;
00281
00282 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
00283 for ( i=0; i<manualPointsSZ; i++ )
00284 {
00285 mpOrigin = _manContModel->GetManualPoint( i );
00286 mpOrigin->SetPoint( mpOrigin->GetX()+horizontalUnits, mpOrigin->GetY()+verticalUnits, mpOrigin->GetZ() );
00287 }
00288 UpdateViewPoints();
00289 }