Пример #1
0
MeshListGeometry* ROICube::generateNormalizedMesh(tgt::plane pl) const {
    FaceGeometry planeFace = createQuad(pl, getColor());

    vec4 xm(-1.0f, 0.0f, 0.0f, 1.0f);
    vec4 xp(1.0f, 0.0f, 0.0f, 1.0f);
    vec4 ym(0.0f, -1.0f, 0.0f, 1.0f);
    vec4 yp(0.0f, 1.0f, 0.0f, 1.0f);
    vec4 zm(0.0f, 0.0f, -1.0f, 1.0f);
    vec4 zp(0.0f, 0.0f, 1.0f, 1.0f);

    planeFace.clip(xm);
    planeFace.clip(xp);
    planeFace.clip(ym);
    planeFace.clip(yp);
    planeFace.clip(zm);
    planeFace.clip(zp);

    MeshGeometry mg;

    if(planeFace.getVertexCount() > 2)
        mg.addFace(planeFace);

    MeshListGeometry* mlg = new MeshListGeometry();
    mlg->addMesh(mg);
    return mlg;
}
void MultiVolumeProxyGeometry::process() {
    tgtAssert(inport_.getData()->getRepresentation<VolumeRAM>(), "no volume");

    MeshListGeometry* geometry = new MeshListGeometry();

    std::vector<const VolumeBase*> data = inport_.getAllData();
    for(size_t d=0; d<data.size(); ++d) {
        if(!data[d])
            continue;

        const VolumeBase* volume = data[d];

        tgt::vec3 coordLlf = volume->getLLF();
        tgt::vec3 coordUrb = volume->getURB();


        MeshGeometry mesh = MeshGeometry::createCube(coordLlf, coordUrb, coordLlf, coordUrb);
        //apply dataset transformation matrix:
        mesh.transform(volume->getPhysicalToWorldMatrix());

        //reset tex coords to coords after transformation:
        for(size_t j=0; j<mesh.getFaceCount(); ++j) {
            FaceGeometry& fg = mesh.getFace(j);
            for(size_t k=0; k<fg.getVertexCount(); ++k) {
                VertexGeometry& vg = fg.getVertex(k);
                vg.setTexCoords(vg.getCoords());
            }
        }
        geometry->addMesh(mesh);
    }

    outport_.setData(geometry);
}
Пример #3
0
void HypercubeBuilder::rebuildProjections() {
    MeshListGeometry* geom = new MeshListGeometry();

    // Для каждой проекции:
    //for (size_t i = 0; i < numProjections; i++) {
        const MatrixXd points = projection->getPointsMatrix();
        const VectorXd distances = projection->getDistanceVector();
        size_t numPoints = projection->getNumPoints();
        size_t numEdges = projection->getNumEdges();
        size_t numFaces = projection->getNumFaces();
        double maxD = distance_.get();
        // 1) Строим проекции вершин. Отображаем их кубами
        for (size_t j = 0; j < numPoints; j++) {
            double d = distances(j);
            if (d > maxD) continue;
            double a = vertexSize_.get() * 1 / (1 + d) / 10;
            tgt::vec3 cubeSize(a,a,a);
            tgt::vec3 point = pointToVec3(points, j);
            geom->addMesh(MeshGeometry::createCube(point-cubeSize, point+cubeSize));
        }
        
        // 2) Строим проекции ребер. Отображаем их цилиндрами
        if (drawEdges_.get() == true)
        for (size_t j = 0; j < numEdges; j++) {
            Edge e = projection->getEdge(j);
            size_t i1 = e.getV1();
            size_t i2 = e.getV2();
            if (distances(i1) > maxD || distances(i2) > maxD) continue;
            tgt::vec3 v1 = pointToVec3(points, i1);
            tgt::vec3 v2 = pointToVec3(points, i2);
            geom->addMesh(PrimitiveGeometryBuilder::createCylinder(v1, v2, edgeSize_.get() / 10, 4, tgt::vec3(1.,1.,0)));
        }
        
        // 3) Строим проекции граней
        if (drawFaces_.get() == true) {
            MeshGeometry mesh;
            for (size_t j = 0; j < numFaces; j++) {
                Face f = projection->getFace(j);
                
                std::vector<size_t> fv = f.getVertices();
                std::vector<tgt::vec3> projections;
                for (size_t k = 0; k < fv.size(); k++) {
                    projections.push_back(pointToVec3(points, fv[k]));
                }
                
                bool br = false;
                for (size_t k = 0; k < fv.size(); k++) {
                    if (distances(fv[k]) > maxD) br = true;
                }
                if (br == true) continue;
                
                mesh.addFace(PrimitiveGeometryBuilder::createFace(projections, tgt::vec4(1,1,0,0.7)));
            }
            geom->addMesh(mesh);
        }
    //}
    // Delete old geometry and set new
    outport_.setData(geom);
}
Пример #4
0
void CubeMeshProxyGeometry::process() {
    tgtAssert(inport_.getData(), "no input volume");

    // adapt clipping plane properties on volume change
    if (inport_.hasChanged()) {
        adjustClipPropertiesRanges();
    }

    const VolumeHandleBase* inputVolume = inport_.getData();
    tgt::vec3 volumeSize = inputVolume->getCubeSize();

     // vertex and tex coords of bounding box without clipping
    tgt::vec3 coordLlf = inputVolume->getLLF();
    tgt::vec3 coordUrb = inputVolume->getURB();
    const tgt::vec3 noClippingTexLlf(0, 0, 0);
    const tgt::vec3 noClippingTexUrb(1, 1, 1);

    tgt::vec3 texLlf;
    tgt::vec3 texUrb;
    if (enableClipping_.get()) {
        tgt::ivec3 orgDims = inputVolume->getOriginalDimensions();
        // adjust vertex and tex coords to clipping
        texLlf = tgt::vec3(
            clipRight_.get()  / static_cast<float>(orgDims.x),
            clipFront_.get()  / static_cast<float>(orgDims.y),
            clipBottom_.get() / static_cast<float>(orgDims.z));
        texUrb = tgt::vec3(
            (clipLeft_.get()+1.0f) / static_cast<float>(orgDims.x),
            (clipBack_.get()+1.0f) / static_cast<float>(orgDims.y),
            (clipTop_.get()+1.0f)  / static_cast<float>(orgDims.z));

        // calculate original offset and clip volume
        tgt::vec3 orgDimSpac = static_cast<tgt::vec3>(orgDims)*inputVolume->getSpacing();
        tgt::vec3 orgOffset = orgDimSpac / tgt::max(orgDimSpac); 
        tgt::vec3 coordLlfOrg = (texLlf*(2.f*orgOffset))-orgOffset;
        tgt::vec3 coordUrbOrg = (texUrb*(2.f*orgOffset))-orgOffset;
        tgt::vec3 coordSize = coordUrb-coordLlf;

        // calculate correct volume coordinates [-1, 1]
        coordLlf = tgt::min(tgt::max(coordLlfOrg, coordLlf), coordUrb);
        coordUrb = tgt::max(tgt::min(coordUrbOrg, coordUrb), coordLlf);

        // calculate correct texture coordinates [0, 1]
        texLlf = (coordLlf-inputVolume->getLLF())/(coordSize);
        texUrb = tgt::vec3(1.f)-(inputVolume->getURB()-coordUrb)/(coordSize);
    }
    else {
        texLlf = noClippingTexLlf;
        texUrb = noClippingTexUrb;
    }

    // create output mesh
    MeshListGeometry* geometry = new MeshListGeometry();
    geometry->addMesh(MeshGeometry::createCube(coordLlf, coordUrb, texLlf, texUrb, texLlf, texUrb));
    geometry->transform(inputVolume->getPhysicalToWorldMatrix());

    outport_.setData(geometry);
}
Пример #5
0
MeshListGeometry MeshListGeometry::clip(const tgt::vec4& clipplane, double epsilon) {
    MeshListGeometry closingFaces;
    for (iterator it = begin(); it != end(); ++it) {
        MeshGeometry closingFace = it->clip(clipplane, epsilon);
        if (!closingFace.empty())
            closingFaces.addMesh(closingFace);
    }
    return closingFaces;
}
Пример #6
0
void CubeProxyGeometry::process() {
    tgtAssert(inport_.getData(), "no input volume");

    // adapt clipping plane properties on volume change
    if (inport_.hasChanged()) {
        adjustClipPropertiesRanges();
    }

    const VolumeBase* inputVolume = inport_.getData();
    tgt::vec3 volumeSize = inputVolume->getCubeSize();
    tgt::ivec3 numSlices = inputVolume->getDimensions();

    // vertex and tex coords of bounding box without clipping
    tgt::vec3 coordLlf = inputVolume->getLLF();
    tgt::vec3 coordUrb = inputVolume->getURB();
    const tgt::vec3 noClippingTexLlf(0, 0, 0);
    const tgt::vec3 noClippingTexUrb(1, 1, 1);

    tgt::vec3 texLlf;
    tgt::vec3 texUrb;
    if (enableClipping_.get()) {
        // adjust vertex and tex coords to clipping
        texLlf = tgt::vec3(
            clipRight_.get()  / static_cast<float>(numSlices.x),
            clipFront_.get()  / static_cast<float>(numSlices.y),
            clipBottom_.get() / static_cast<float>(numSlices.z));
        texUrb = tgt::vec3(
            (clipLeft_.get()+1.0f) / static_cast<float>(numSlices.x),
            (clipBack_.get()+1.0f) / static_cast<float>(numSlices.y),
            (clipTop_.get()+1.0f)  / static_cast<float>(numSlices.z));

        coordLlf -= volumeSize * (noClippingTexLlf - texLlf);
        coordUrb -= volumeSize * (noClippingTexUrb - texUrb);
    }
    else {
        texLlf = noClippingTexLlf;
        texUrb = noClippingTexUrb;
    }

    // create output mesh
    MeshListGeometry* geometry = new MeshListGeometry();
    geometry->addMesh(MeshGeometry::createCube(coordLlf, coordUrb, texLlf, texUrb, texLlf, texUrb));
    geometry->transform(inputVolume->getPhysicalToWorldMatrix());

    outport_.setData(geometry);
}
Пример #7
0
bool MeshListGeometry::equals(const MeshListGeometry& meshList, double epsilon /*= 1e-6*/) const {
    if (getMeshCount() != meshList.getMeshCount())
        return false;
    for (size_t i=0; i<getMeshCount(); i++) {
        if (!meshes_[i].equals(meshList.meshes_[i], epsilon))
            return false;
    }
    return true;
}
Пример #8
0
void MeshListGeometry::clip(const tgt::vec4& clipPlane, MeshListGeometry& closingFaces, double epsilon) {
    tgtAssert(epsilon >= 0.0, "negative epsilon");
    for (iterator it = begin(); it != end(); ++it) {
        MeshGeometry closingFace;
        it->clip(clipPlane, closingFace, epsilon);
        if (!closingFace.empty())
            closingFaces.addMesh(closingFace);
    }
}
Пример #9
0
void HypercubeBuilder::rebuildProjections() {
    MeshListGeometry* geom = new MeshListGeometry();

        const MatrixXd points = projection->getPointsMatrix();
        const VectorXd distances = projection->getDistanceVector();
        size_t numPoints = projection->getNumPoints();
        size_t numEdges = projection->getNumEdges();
        // 1) Строим проекции вершин. Отображаем их кубами
        for (size_t j = 0; j < numPoints; j++) {
            double d = distances(j);
            if (d > distance_.get()) continue;
            double a = vertexSize_.get() * 1 / (1 + d) / 10;
            tgt::vec3 cubeSize(a,a,a);
            tgt::vec3 point = pointToVec3(points, j);
            geom->addMesh(MeshGeometry::createCube(point-cubeSize, point+cubeSize));
        }
        
        // 2) Строим проекции ребер. Отображаем их цилиндрами
        if (drawEdges_.get() == true)
        for (size_t j = 0; j < numEdges; j++) {
            Edge e = projection->getEdge(j);
            tgt::vec3 v1 = pointToVec3(points, e.getV1());
            tgt::vec3 v2 = pointToVec3(points, e.getV2());
            geom->addMesh(PrimitiveGeometryBuilder::createCylinder(v1, v2, edgeSize_.get() / 10, 4, tgt::vec3(1.,1.,0)));
        }
        
        // 3) Строим проекции квази-ребер (например, мозаики Пенроуза)
        if (drawQuasiEdges_.get() == true) {
        double t = 0.01;
        double d = quasiEdgeDistance_.get();
        projection->buildQuasiEdgesByDistance(d-t, d+t, distance_.get(), 0);
        for (size_t i = 0; i < projection->getNumQuasiEdgeClasses(); i++)
        for (size_t j = 0; j < projection->getNumQuasiEdges(i); j++) {
            Edge e = projection->getQuasiEdge(i, j);
            tgt::vec3 v1 = pointToVec3(points, e.getV1());
            tgt::vec3 v2 = pointToVec3(points, e.getV2());
            geom->addMesh(PrimitiveGeometryBuilder::createCylinder(v1, v2, edgeSize_.get() / 10, 4, tgt::vec3(1.,1.,0)));
        }
        }

    outport_.setData(geom);
}
Пример #10
0
MeshListGeometry* ROICube::generateNormalizedMesh() const {
    MeshListGeometry* geometry = new MeshListGeometry();
    geometry->addMesh(MeshGeometry::createCube(vec3(-1.0f), vec3(1.0f), vec3(0.0f), vec3(1.0f), getColor().xyz(), getColor().xyz()));
    return geometry;
}
Пример #11
0
void StereoMeshEntryExitPoints::process() {
    // retrieve input geometry
    const MeshListGeometry* meshListGeometry = dynamic_cast<const MeshListGeometry*>(inport_.getData());
    const MeshGeometry* meshGeometry = dynamic_cast<const MeshGeometry*>(inport_.getData());
    if (meshListGeometry) {
        geometry_ = *meshListGeometry;
    }
    else if (meshGeometry) {
        geometry_.clear();
        geometry_.addMesh(*meshGeometry);
    }
    else {
        LERROR("Geometry of type MeshListGeometry/MeshGeometry expected.");
        return;
    }

    // A new volume was loaded
    if(inport_.hasChanged())
        cameraHandler_->adaptInteractionToScene(geometry_);

    // set modelview and projection matrices
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    tgt::loadMatrix(camera_.get().getProjectionMatrix(entryPort_.isReady() ? entryPort_.getSize() : exitPort_.getSize()));

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    tgt::loadMatrix(camera_.get().getViewMatrix());

    // enable culling
    if(useCulling_.get())
        glEnable(GL_CULL_FACE);

    // activate shader program
    shaderProgram_->activate();
    tgt::Camera cam = camera_.get();
    setGlobalShaderParameters(shaderProgram_, &cam);
    LGL_ERROR;

    //
    // render back texture
    //
    if (exitPort_.isReady()) {
        exitPort_.activateTarget();
        glClearDepth(0.0f);
        glDepthFunc(GL_GREATER);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glCullFace(GL_FRONT);

        geometry_.render();
        LGL_ERROR;
        exitPort_.deactivateTarget();
        glDepthFunc(GL_LESS);
        glClearDepth(1.0f);
        LGL_ERROR;
    }

    //
    // render front texture
    //
    // use temporary target if necessary
    if (entryPort_.isReady()) {
        if (!jitterEntryPoints_.get())
            entryPort_.activateTarget();
        else
            tmpPort_.activateTarget();
        LGL_ERROR;

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glCullFace(GL_BACK);

        geometry_.render();
        LGL_ERROR;

        if (supportCameraInsideVolume_.get()) {
            // clip proxy geometry against near-plane
            float nearPlaneDistToOrigin = tgt::dot(camera_.get().getPosition(), -camera_.get().getLook()) - camera_.get().getNearDist() - 0.0001f;
            MeshListGeometry closingFaces;
            double epsilon = static_cast<double>(tgt::length(geometry_.getBoundingBox().diagonal())) * 1e-6;
            geometry_.clip(tgt::vec4(-camera_.get().getLook(), nearPlaneDistToOrigin), closingFaces, epsilon);

            // render closing face separately, if not empty
            if (!closingFaces.empty()) {
                // project closing faces onto near-plane
                tgt::mat4 trafoMatrix = camera_.get().getProjectionMatrix(entryPort_.getSize()) * camera_.get().getViewMatrix();
                closingFaces.transform(trafoMatrix);
                // set z-coord of closing face vertices to 0.0 in order to avoid near-plane clipping
                tgt::mat4 zTrafo = tgt::mat4::createIdentity();
                zTrafo[2][2] = 0.f;
                closingFaces.transform(zTrafo);

                //render closing faces with identity transformations
                glMatrixMode(GL_PROJECTION);
                glLoadIdentity();
                glMatrixMode(GL_MODELVIEW);
                glLoadIdentity();
                closingFaces.render();
                LGL_ERROR;
            }
        }

        if (!jitterEntryPoints_.get())
            entryPort_.deactivateTarget();
        else
            tmpPort_.deactivateTarget();
    }

    // deactivate shader program
    shaderProgram_->deactivate();

    // restore OpenGL state
    glCullFace(GL_BACK);
    glDisable(GL_CULL_FACE);
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    LGL_ERROR;

    if (entryPort_.isReady()) {
        // jittering of entry points
        if (jitterEntryPoints_.get())
            jitterEntryPoints();

        entryPort_.deactivateTarget();
    }

    TextureUnit::setZeroUnit();
    LGL_ERROR;
}