void Path::sample(int numSamples, QList<Eigen::Vector2d> & out) const { assert(isValid()); out.clear(); if(type() == SingleVertex) { Eigen::Vector2d pos = singleVertex()->pos(); for(int i=0; i<numSamples; ++i) out << pos; } else { assert(numSamples >= 2); double ds = length()/(numSamples-1); double cumulativeLength = 0; int indexHe = 0; KeyHalfedge he = halfedges_[indexHe]; for(int i=0; i<numSamples; ++i) { double s = i*ds; while ( (s > cumulativeLength + he.length()) && (indexHe+1 < halfedges_.size()) ) { cumulativeLength += he.length(); he = halfedges_[++indexHe]; } out << he.pos(s-cumulativeLength); } } }
KeyVertex * Path::startVertex() const { assert(isValid()); if(type() == SingleVertex) { return singleVertex(); } else { return halfedges_.first().startVertex(); } }
KeyVertex * Path::endVertex() const { assert(isValid()); if(type() == SingleVertex) { return singleVertex(); } else { return halfedges_.last().endVertex(); } }
void Cycle::sample(int numSamples, QList<EdgeSample> & out) const { assert(isValid()); out.clear(); if(type() == SingleVertex) { Eigen::Vector2d pos = singleVertex()->pos(); EdgeSample posSample(pos[0],pos[1],0); for(int i=0; i<numSamples; ++i) out << posSample; } else { QList<EdgeSample> outAux; assert(numSamples >= 2); double l = length(); double ds = l/(numSamples-1); // Computing unoffset cycle double cumulativeLength = 0; int indexHe = 0; KeyHalfedge he = halfedges_[indexHe]; for(int i=0; i<numSamples; ++i) { double s = i*ds; while ( (s > cumulativeLength + he.length()) && (indexHe+1 < halfedges_.size()) ) { cumulativeLength += he.length(); he = halfedges_[++indexHe]; } outAux << he.sample(s-cumulativeLength); } // Apply offset int i0 = std::floor( numSamples * s0_ + 0.5); if(i0 < 0) i0 = 0; if(i0 > numSamples - 1) i0 = numSamples - 1; for(int i=i0; i<numSamples; ++i) out << outAux[i]; for(int i=0; i<i0; ++i) out << outAux[i]; } }