コード例 #1
0
void FloorScene::loadFloorPlan() {
    this->clear();

    FloorVertex* floorplan = mesh->getFloorPlan();
    unsigned int floorPlanSize = mesh->getFloorPlanSize();
    float x(0.0f);
    float y(0.0f);
    Vertex* currentVertex = floorplan;

    // go through the vertices of the floor plan, create and draw their ellipse
    for (unsigned int i(0); i < floorPlanSize; ++i) {
        x = currentVertex->getX();
        y = currentVertex->getY();

        QRectF thisSize = this->sceneRect();
        Utils::adjustCoordinates3DToScene(x, y, thisSize.width(), thisSize.height());
        if(currentVertex->getEllipse() == 0){
            currentVertex->setEllipse(new QGraphicsEllipseItem(x - vertexRadius, y - vertexRadius, vertexRadius * 2.0f, vertexRadius * 2.0f));
            this->addItem(currentVertex->getEllipse());
        } else {
            std::cerr << "something strange happen, try to reload an already loaded floorplan maybe is ok and i shouldn't do anything";
        }

        currentVertex = currentVertex->getNeighbor2();
    }

    // go through the vertices of the floor plan, create and draw their edges
    currentVertex = floorplan;
    for (unsigned int i(0); i < floorPlanSize; ++i) {
        if(currentVertex->addEdge1()){
            this->addItem(currentVertex->getEdge1());
        }
        if(currentVertex->addEdge2()){
           this->addItem(currentVertex->getEdge2());
        }
        currentVertex = currentVertex->getNeighbor2();
    }

    // tell the mesh to generate new point/triangle
    mesh->setUpdateOnMesh();
}