manualViewContour.cpp

Go to the documentation of this file.
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         // Call to Fathers object
00033         manualViewBaseContour::CopyAttributesTo(cloneObject);
00034 
00035         cloneObject->SetMesureScale(_mesureScale);
00036 }
00037 
00038 // ---------------------------------------------------------------------------
00039 
00040 int manualViewContour::GetType() // virtual
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() // virtual
00060 {
00061         int i,np,nps;
00062 
00063 //JSTG 25-02-08 --------------------
00064         //double t,delta, x,y,z;
00065         double x,y,z;
00066 //----------------------------------
00067 
00068         _manContModel->UpdateSpline();
00069     np  = GetNumberOfPoints( );
00070         //nps = GetNumberOfPointsSpline();
00071     nps = _manContModel->GetNumberOfPointsSpline();
00072         //delta=( double ) ( np  ) / ( double ) ( nps-1  );             //JSTG 25-02-08
00073 
00074 
00075         if ( _pts!=NULL )
00076         {
00077                 if (np>=2  )
00078                 {
00079                         for( i = 0; i < nps; i++ )
00080                         {
00081 //JSTG 25-02-08 ------------------------------------------------
00082                                 //t = delta * (double)i;
00083                                 //_manContModel->GetSplinePoint(t,x,y,z);
00084                                 _manContModel->GetSpline_i_Point(i,&x,&y,&z);
00085 //--------------------------------------------------------------
00086         // EED 27 sep 2006
00087         //                      _pts->SetPoint(i, x,y,z );
00088                                 _pts->SetPoint(i, x*_spc[0], y*_spc[1], z*_spc[2] );
00089 
00090                         }// for
00091                 }
00092                 else
00093                 {
00094                                 _pts->SetPoint(0, 0 , 0 , 0);
00095                                 _pts->SetPoint(1, 0 , 0 , 0);
00096                 } // if
00097         }
00098 }
00099 
00100 // ----------------------------------------------------------------------------
00101 void manualViewContour::RefreshText()  // virtual
00102 {
00103         if ((_textActor!=NULL) && ( _textActor->GetProperty()->GetOpacity()!=0 )){
00104                 int size = GetNumberOfPoints();
00105                 char text[50];
00106                 char resultText[50];
00107                 strcpy(resultText, " ");
00108 
00109 //CMRU 19-08-09 ----------------------------------
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 //CMRU 19-08-09 ----------------------------------
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 //CMRU 19-08-09 ----------------------------------
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                         //EED 27 sep 2006
00168                         px=px*_spc[0];
00169                         py=py*_spc[1];
00170 
00171                         _textActor->SetPosition(px+GetRange()+1,py);
00172                 }
00173 
00174         }
00175 }
00176 
00177 // ----------------------------------------------------------------------------
00178 bool manualViewContour::ifTouchContour(int x,int y,int z){
00179         bool result=false;
00180         double xx=x;
00181         double yy=y;
00182         double zz=z;
00183         double ppA[3];
00184         double ppB[3];
00185         double d1,d2,d3;
00186         TransfromCoordViewWorld(xx,yy,zz);
00187 
00188 //EED 27 sep 2006
00189         xx = xx * _spc[0];
00190         yy = yy * _spc[1];
00191         zz = zz * _spc[2];
00192 
00193     unsigned int i, nps,nps_t;
00194     nps   = _sizePointsContour;
00195         
00196         if (this->_manContModel->IfCloseContour()==true)
00197         {
00198                 nps_t = nps;
00199         } else {
00200                 nps_t = nps-1;
00201         }
00202 
00203         
00204         for( i = 0; i < nps_t; i++ ) 
00205         {
00206                 _pts->GetPoint(i%nps, ppA);
00207                 _pts->GetPoint((i+1)%nps, ppB);
00208                 d1= sqrt( (ppA[0]-xx)*(ppA[0]-xx) + (ppA[1]-yy)*(ppA[1]-yy) + (ppA[2]-zz)*(ppA[2]-zz));
00209                 d2= sqrt( (ppB[0]-xx)*(ppB[0]-xx) + (ppB[1]-yy)*(ppB[1]-yy) + (ppB[2]-zz)*(ppB[2]-zz));
00210                 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]));
00211 
00212 
00213                 if (  ((d1+d2)>=d3) &&  ((d1+d2)<=d3*1.3) ) 
00214                 {
00215                         result=true;
00216                         i=nps;
00217                 }
00218         }
00219         
00220         return result;
00221 }
00222 
00223 // ----------------------------------------------------------------------------
00224 void manualViewContour::DeletePoint(int id) // virtual
00225 {
00226         if (_lstViewPoints.size()>2)
00227         {
00228                 manualViewBaseContour::DeletePoint( id );
00229         }
00230 }
00231 // ----------------------------------------------------------------------------
00232 
00233 void manualViewContour::ClearPoint(int id)
00234 {
00235         manualViewBaseContour::DeletePoint( id );
00236 }
00237 
00238 //-------------------------------------------------------------------
00239 void manualViewContour::SetMesureScale(double mesureScale)
00240 {
00241         _mesureScale = mesureScale;
00242 }
00243 //-------------------------------------------------------------------
00244 void manualViewContour::InitMove(int x, int y, int z)
00245 {
00246         _initialConoturModel->DeleteAllPoints();
00247 
00248         manualPoint *mp = NULL;
00249         double XX=x;
00250         double YY=y;
00251         double ZZ=z;
00252         TransfromCoordViewWorld(XX,YY,ZZ);
00253 
00254         int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
00255         for ( i=0; i<manualPointsSZ; i++ )
00256         {
00257                 mp = _manContModel->GetManualPoint( i );
00258                 this->_initialConoturModel->AddPoint( mp->GetX() - XX, mp->GetY() - YY, mp->GetZ() );
00259         }
00260 }
00261 //-------------------------------------------------------------------
00262 void manualViewContour::MoveContour(int x, int y, int z)
00263 {
00264         manualPoint *mpOrigin = NULL;
00265         manualPoint *mpMoving = NULL;
00266         double XX=x;
00267         double YY=y;
00268         double ZZ=z;
00269 
00270         TransfromCoordViewWorld(XX,YY,ZZ);
00271 
00272         int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
00273         for ( i=0; i<manualPointsSZ; i++ )
00274         {
00275                 mpOrigin = _manContModel->GetManualPoint( i );
00276                 mpMoving = _initialConoturModel->GetManualPoint(i);
00277                 mpOrigin->SetPoint( mpMoving->GetX()+XX, mpMoving->GetY() + YY, mpMoving->GetZ() );
00278         }
00279         UpdateViewPoints();
00280 }
00281 void manualViewContour::MoveContour(int horizontalUnits, int verticalUnits )
00282 {
00283         manualPoint *mpOrigin = NULL;
00284 
00285         int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
00286         for ( i=0; i<manualPointsSZ; i++ )
00287         {
00288                 mpOrigin = _manContModel->GetManualPoint( i );
00289                 mpOrigin->SetPoint( mpOrigin->GetX()+horizontalUnits, mpOrigin->GetY()+verticalUnits, mpOrigin->GetZ() );
00290         }
00291         UpdateViewPoints();
00292 }

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1