#include #include "ModelShowNPoints.h" //---------------------------------------------------------------------- ModelShowNPoints::ModelShowNPoints() { firsttime=true; } //---------------------------------------------------------------------- ModelShowNPoints::~ModelShowNPoints() { } //------------------------------------------------------------------------ void ModelShowNPoints::SetRadio(double radio) { mradio = radio; } //------------------------------------------------------------------------ double ModelShowNPoints::GetRadio() { return mradio; } //------------------------------------------------------------------------ std::vector ModelShowNPoints::GetLstPointsX() { return lstPointsX; } //------------------------------------------------------------------------ std::vector ModelShowNPoints::GetLstPointsY() { return lstPointsY; } //------------------------------------------------------------------------ std::vector ModelShowNPoints::GetLstPointsZ() { return lstPointsZ; } //------------------------------------------------------------------------ std::vector ModelShowNPoints::GetLstLabels() { return lstLabels; } //------------------------------------------------------------------------ void ModelShowNPoints::SetReferencePoint(std::vector ppoint) { mReferencePoint = ppoint; } //------------------------------------------------------------------------ std::vector ModelShowNPoints::GetReferencePoint() { return mReferencePoint; } //------------------------------------------------------------------------ void ModelShowNPoints::SetImage(vtkImageData *image) { this->mimage=image; } //------------------------------------------------------------------------ std::string ModelShowNPoints::CleanSpaces(std::string ss) { int i; while( (i=ss.find(32))>=0 ) { ss.replace(i,1,"_"); } return ss; } //------------------------------------------------------------------------ void ModelShowNPoints::GetIdPoint(int id, int *x, int *y, int *z) { *x=lstPointsX[id]; *y=lstPointsY[id]; *z=lstPointsZ[id]; } //------------------------------------------------------------------------ std::string ModelShowNPoints::GetIdLabel(int id) { return lstLabels[id]; } //------------------------------------------------------------------------ vtkImageData *ModelShowNPoints::GetImage() { return mimage; } //------------------------------------------------------------------------ void ModelShowNPoints::AddPoint(int x, int y, int z, std::string label) { lstPointsX.push_back( x ); lstPointsY.push_back( y ); lstPointsZ.push_back( z ); std::string strLabel = CleanSpaces( label ); lstLabels.push_back( strLabel ); } //------------------------------------------------------------------------ double ModelShowNPoints::Distance(double dX0, double dY0, double dZ0, double dX1, double dY1, double dZ1)//CFT { return sqrt((dX1 - dX0)*(dX1 - dX0) + (dY1 - dY0)*(dY1 - dY0) + (dZ1 - dZ0)*(dZ1 - dZ0)); } //------------------------------------------------------------------------ int ModelShowNPoints::InsertPoint(int x, int y, int z, std::string label) { if(lstPointsX.size()>1) { std::vector dTotal; int pos = 1; int a,b,res; //Calcule distance for each pair of points for(int i = 0; i<(int)lstPointsX.size()-1 ; i++) { a = Distance(x, y, z, lstPointsX[i], lstPointsY[i], lstPointsZ[i]); b = Distance(x, y, z, lstPointsX[i+1], lstPointsY[i+1], lstPointsZ[i+1]); res = a + b; dTotal.push_back (res); } //Gets the smallest distance int smallTMP = dTotal[0]; for (int j = 0; j < (int) dTotal.size(); j++) { if(dTotal[j]::iterator it; //Insert the point in the list of points it = lstPointsX.begin(); lstPointsX.insert( it+pos, x ); it = lstPointsY.begin(); lstPointsY.insert( it+pos, y ); it = lstPointsZ.begin(); lstPointsZ.insert( it+pos, z ); std::string strLabel = CleanSpaces( label ); std::vector::iterator itS; itS = lstLabels.begin(); //Insert Label in list of labels lstLabels.insert( itS+pos, strLabel ); return pos; } else { return -1; }// if size lst X } //------------------------------------------------------------------------ void ModelShowNPoints::SavePoints(std::string filename) { std::string tmpLabel; FILE *ff; ff = fopen( filename.c_str() , "w+" ); if (ff!=NULL) { int i , size = (int) (lstPointsX.size()); fprintf(ff,"NumberOfPoints %d \n",size); fprintf(ff," X\tY\tZ\tvalue\tLabel\n"); int x, y, z; double value; for (i=0; iGetScalarComponentAsDouble(x,y,z,0); if (lstLabels[i]!="") { tmpLabel=lstLabels[i]; } else{ tmpLabel="<_VOID_>"; } fprintf(ff,"%d\t%d\t%d\t%f\t%s\n", x , y , z , value , tmpLabel.c_str()); } // for fclose(ff); } else { // else ff printf("ModelShowNPoints::SavePoints ...Error... creating file"); } //ff } //------------------------------------------------------------------------ int ModelShowNPoints::ReadPoints(std::string filename) { int i,size; char chartmp[256]; FILE *ff; ff = fopen( filename.c_str() , "r+" ); if (ff!=NULL) { fscanf(ff," %s %d",chartmp,&size); fscanf(ff," %s %s %s %s %s",chartmp, chartmp,chartmp,chartmp,chartmp ); float value; int x,y,z; for (i=0; i")==0) { strcpy(chartmp,""); } AddPoint(x,y,z, chartmp ); } fclose(ff); } else { // else ff printf("ModelShowNPoints::LoadPoints ...Error... reading file"); } //ff return size; } //------------------------------------------------------------------------ int ModelShowNPoints::GetNearestPoint() { int id=-1; int i, size=(int)(lstPointsX.size()); double radioMin=10000000; for ( i=0 ; iGetSpacing(spc); for ( i=0 ; i=0) { std::string strLabel = CleanSpaces( label ); lstLabels[id] = strLabel; } return id; } //---------------------------------------------------------------------- void ModelShowNPoints::ErasePoint(int id) { lstPointsX.erase( lstPointsX.begin()+id ); lstPointsY.erase( lstPointsY.begin()+id ); lstPointsZ.erase( lstPointsZ.begin()+id ); lstLabels.erase( lstLabels.begin()+id ); } //---------------------------------------------------------------------- void ModelShowNPoints::SetFirstTime(bool value) { firsttime=value; } //---------------------------------------------------------------------- bool ModelShowNPoints::GetFirstTime() { return firsttime; }