Exemple #1
1
void RPolyline::appendShape(const RShape& shape, bool prepend) {
//    const RDirected* directed = dynamic_cast<const RDirected*>(&shape);
//    if (directed==NULL) {
//        qWarning() << "RPolyline::appendShape: shape is not a line, arc or polyline: " << shape;
//        return;
//    }

    const RPolyline* pl = dynamic_cast<const RPolyline*>(&shape);
    if (pl!=NULL) {
        if (prepend) {
            for (int i=pl->countSegments()-1; i>=0; --i) {
                QSharedPointer<RShape> s = pl->getSegmentAt(i);
                if (s.isNull()) {
                    continue;
                }
                prependShape(*s);
            }
        }
        else {
            for (int i=0; i<pl->countSegments(); ++i) {
                QSharedPointer<RShape> s = pl->getSegmentAt(i);
                if (s.isNull()) {
                    continue;
                }
                appendShape(*s);
            }
        }
        return;
    }

    const RDirected* directed = NULL;
    double bulge = 0.0;

    const RLine* line = dynamic_cast<const RLine*>(&shape);
    if (line!=NULL) {
        directed = line;
    }
    else {
        const RArc* arc = dynamic_cast<const RArc*>(&shape);
        if (arc!=NULL) {
            bulge = arc->getBulge();
            directed = arc;
        }
    }

    if (directed==NULL) {
        qWarning() << "RPolyline::appendShape: shape is not a line, arc or polyline: " << shape;
        return;
    }

    RVector connectionPoint;
    RVector nextPoint;
    double gap;
    if (prepend) {
        connectionPoint = directed->getEndPoint();
        nextPoint = directed->getStartPoint();
        if (vertices.size()==0) {
            appendVertex(connectionPoint);
        }
        gap = vertices.first().getDistanceTo(connectionPoint);
    }
    else {
        connectionPoint = directed->getStartPoint();
        nextPoint = directed->getEndPoint();
        if (vertices.size()==0) {
            appendVertex(connectionPoint);
        }
        gap = vertices.last().getDistanceTo(connectionPoint);
    }

    if (!RMath::fuzzyCompare(gap, 0.0, 1.0e-4)) {
        qWarning() << "RPolyline::appendShape: arc or line not connected to polyline, gap: " << gap;
    }

    if (prepend) {
        prependVertex(nextPoint);
        setBulgeAt(0, bulge);
    }
    else {
        appendVertex(nextPoint);
        setBulgeAt(bulges.size()-2, bulge);
    }
}
Exemple #2
0
void RPolyline::appendShape(const RShape& shape) {
    const RDirected* directed = dynamic_cast<const RDirected*>(&shape);
    if (directed==NULL) {
        qWarning("RPolyline::appendShape: shape is not a line, arc or polyline");
        return;
    }

    const RPolyline* pl = dynamic_cast<const RPolyline*>(&shape);
    if (pl!=NULL) {
        for (int i=0; i<pl->countSegments(); ++i) {
            QSharedPointer<RShape> s = pl->getSegmentAt(i);
            if (s.isNull()) {
                continue;
            }
            appendShape(*s.data());
        }
    }

    double bulge = 0.0;
    const RArc* arc = dynamic_cast<const RArc*>(&shape);
    if (arc!=NULL) {
        bulge = arc->getBulge();
    }

    if (vertices.size()==0) {
        appendVertex(directed->getStartPoint());
    }

    appendVertex(directed->getEndPoint());
    setBulgeAt(bulges.size()-2, bulge);
}
Exemple #3
0
RSolidData::RSolidData(const RVector& p1, const RVector& p2, const RVector& p3) :
    RPolyline() {

    appendVertex(p1);
    appendVertex(p2);
    appendVertex(p3);
    setClosed(true);
}
Exemple #4
0
RSolidData::RSolidData(const RTriangle& triangle) :
    RPolyline() {

    appendVertex(triangle.corner[0]);
    appendVertex(triangle.corner[1]);
    appendVertex(triangle.corner[2]);
    setClosed(true);
}
Exemple #5
0
void QGLSection::appendSmooth(const QLogicalVertex &lv, int index)
{
    Q_ASSERT(lv.hasField(QGL::Position));
    Q_ASSERT(lv.hasField(QGL::Normal));

    int found_index = -1;
    QMap<int, int>::const_iterator it = d->index_map.constFind(index);
    if (it != d->index_map.constEnd())
        found_index = it.value();
    if (found_index == -1)
    {
        int newIndex = appendVertex(lv);
        d->index_map.insert(index, newIndex);
        appendIndex(newIndex);
        d->accumulateNormal(newIndex, lv.normal());
    }
    else
    {
        appendIndex(found_index);
        if (!d->normalAccumulated(found_index, lv.normal()))
        {
            normal(found_index) += lv.normal();
            d->accumulateNormal(found_index, lv.normal());
        }
    }
    d->finalized = false;
    m_displayList->setDirty(true);
}
Exemple #6
0
/**
 * Creates a polyline from segments (lines or arcs).
 */
RPolyline::RPolyline(const QList<QSharedPointer<RShape> >& segments) {
    QList<QSharedPointer<RShape> >::const_iterator it;
    for (it=segments.begin(); it!=segments.end(); ++it) {
        QSharedPointer<RDirected> directed = it->dynamicCast<RDirected>();

        if (!directed.isNull()) {
            if (vertices.size()==0) {
                appendVertex(directed->getStartPoint(), 0.0);
            }
            appendVertex(directed->getEndPoint(), 0.0);
        }

        QSharedPointer<RArc> arc = directed.dynamicCast<RArc>();
        if (!arc.isNull()) {
            if (bulges.size()>1) {
                bulges[bulges.size()-2] = arc->getBulge();
            }
        }
    }
}
Exemple #7
0
int QGLSection::appendOne(const QLogicalVertex &lv)
{
#ifndef QT_NO_DEBUG_STREAM
    if (count() && lv.fields() != fields())
    {
        qDebug() << "Warning: adding" << lv << "fields:" << lv.fields()
                << "fields do not match existing:" << fields()
                << "create new section first?";
    }
#endif
    int index = appendVertex(lv);
    d->mapVertex(lv.vertex(), index);
    appendIndex(index);
    return index;
}
Exemple #8
0
Vertex* Tree::appendText(Sit S, char *string, int len)
{
    Vertex *txt = NULL;
    if (!pendingTextNode)
    {
        // the initializing text does not matter
        txt = new(&getArena()) Text(*this, string, len);
	Processor *proc = S.getProcessor();
	if ( proc && proc->outputter() ) 
	  {
	    OutputDocument *doc=proc->outputter()->getDocumentForLevel(FALSE);
	    txt -> setOutputDocument(doc);
	  }

        appendVertex(S, txt);
        pendingTextNode = toText(txt);
    }
    pendingText.nadd(string,len);
    return txt;
}
Exemple #9
0
/*!
    \internal
    Append the logical vertex \a lv to this section.

    The vertex will be treated as flat colored, and thus no management
    of lighting normals is done.
*/
void QGLSection::appendFlat(const QLogicalVertex &lv)
{
    appendVertex(lv);
    d->finalized = false;
    m_displayList->setDirty(true);
}
sptr(Resource) DecoderOBJ::decode(const std::string &path)
{
    clear();

    TextFile objFile(path);

    std::string line;
    do
    {
        line = objFile.getLine();

        if (line == "END_OF_FILE")
            break;

        if (line.find("vt") != std::string::npos)
        { }

        if (line.find("vn") != std::string::npos)
            appendNormal(line);

        if (line.find("vp") != std::string::npos)
        { }

        if (line.at(0) == 'v')
            appendVertex(line);

        if (line.at(0) == 'f')
            appendFace(line);

        line.clear();

    } while (line.empty());

    if (faces.empty() || vertexList.empty())
    {
        syslog << "Unable to parse .obj file" << path << logwarn;
        return sptr(Resource)();
    }

    auto newMesh = std::make_shared<rend::Mesh>();

    triangulateModel();

    rend::VertexBuffer vb;
    vb.setType(rend::VertexBuffer::INDEXEDTRIANGLELIST);
    vb.appendVertices(vertexList, resultTrianglesIndices, !normalsList.empty());

    auto material = std::make_shared<rend::Material>();

    material->plainColor = rend::Color3(255, 255, 255);
    material->ambientColor = rend::Color3(255, 255, 255);
    material->diffuseColor = rend::Color3(255, 255, 255);

    material->shadeMode = rend::Material::SM_FLAT;
    material->sideType = rend::Material::ONE_SIDE;

    vb.setMaterial(material);

    newMesh->appendSubmesh(vb);

    auto newObject = std::make_shared<rend::SceneObject>(newMesh);

    std::tr2::sys::path p(path);
    newObject->setName(p.filename());

    syslog << "Decoded obj-model \"" << newObject->getName()
           << "\". Number of vertices:" << newMesh->numVertices()
           << ". Number of faces:" << faces.size() << logmess;

    return newObject;
}