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