コード例 #1
0
ファイル: Path.cpp プロジェクト: EgoIncarnate/vpaint
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);
        }
    }
}
コード例 #2
0
ファイル: Path.cpp プロジェクト: EgoIncarnate/vpaint
KeyVertex * Path::startVertex() const
{
    assert(isValid());

    if(type() == SingleVertex)
    {
        return singleVertex();
    }
    else
    {
        return halfedges_.first().startVertex();
    }
}
コード例 #3
0
ファイル: Path.cpp プロジェクト: EgoIncarnate/vpaint
KeyVertex * Path::endVertex() const
{
    assert(isValid());

    if(type() == SingleVertex)
    {
        return singleVertex();
    }
    else
    {
        return halfedges_.last().endVertex();
    }
}
コード例 #4
0
ファイル: Cycle.cpp プロジェクト: gitter-badger/vpaint
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];
    }

}