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); }
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); }
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); }
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; }
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); } }
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); }
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); }
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; }