void setUniform(tgt::Shader* shader, const std::string& volumeUniform, const std::string& structUniform, const VolumeBase* vh, const tgt::TextureUnit* texUnit, const tgt::Camera* camera, const tgt::vec4& lightPosition) { if(texUnit) shader->setUniform(volumeUniform, texUnit->getUnitNumber()); // volume size, i.e. dimensions of the proxy geometry in world coordinates shader->setUniform(structUniform + ".datasetDimensions_", tgt::vec3(vh->getDimensions())); shader->setUniform(structUniform + ".datasetDimensionsRCP_", vec3(1.f) / tgt::vec3(vh->getDimensions())); // volume spacing, i.e. voxel size shader->setUniform(structUniform + ".datasetSpacing_", vh->getSpacing()); shader->setUniform(structUniform + ".datasetSpacingRCP_", vec3(1.f) / vh->getSpacing()); // volume's size in its physical coordinates shader->setUniform(structUniform + ".volumeCubeSize_", vh->getCubeSize()); shader->setUniform(structUniform + ".volumeCubeSizeRCP_", vec3(1.f) / vh->getCubeSize()); shader->setUniform(structUniform + ".volumeOffset_", vh->getOffset()); shader->setUniform(structUniform + ".numChannels_", static_cast<GLint>(vh->getNumChannels())); // volume's transformation matrix shader->setUniform(structUniform + ".physicalToWorldMatrix_", vh->getPhysicalToWorldMatrix()); tgt::mat4 invTm = vh->getWorldToPhysicalMatrix(); shader->setUniform(structUniform + ".worldToPhysicalMatrix_", invTm); shader->setUniform(structUniform + ".worldToTextureMatrix_", vh->getWorldToTextureMatrix()); shader->setUniform(structUniform + ".textureToWorldMatrix_", vh->getTextureToWorldMatrix()); // camera position in volume object coords if (camera) shader->setUniform(structUniform + ".cameraPositionPhysical_", invTm*camera->getPosition()); // light position in volume object coords shader->setUniform(structUniform + ".lightPositionPhysical_", (invTm*lightPosition).xyz()); LGL_ERROR; // bit depth of the volume shader->setUniform(structUniform + ".bitDepth_", (GLint)(vh->getBytesPerVoxel() * 8)); // construct shader real-world mapping by combining volume rwm and pixel transfer mapping RealWorldMapping rwm = vh->getRealWorldMapping(); RealWorldMapping transferMapping; if (vh->getRepresentation<VolumeGL>()) transferMapping = vh->getRepresentation<VolumeGL>()->getPixelTransferMapping(); else LWARNINGC("voreen.glsl", "setUniform(): no VolumeGL"); RealWorldMapping shaderMapping = RealWorldMapping::combine(transferMapping.getInverseMapping(), rwm); shader->setUniform(structUniform + ".rwmScale_", shaderMapping.getScale()); shader->setUniform(structUniform + ".rwmOffset_", shaderMapping.getOffset()); }
void setUniform(tgt::Shader* shader, const std::string& imageUniform, const std::string& structUniform, const Slice* sl, const tgt::TextureUnit* texUnit) { bool ignoreErr = shader->getIgnoreUniformLocationError(); shader->setIgnoreUniformLocationError(true); if(texUnit) shader->setUniform(imageUniform, texUnit->getUnitNumber()); // volume size, i.e. dimensions of the proxy geometry in world coordinates shader->setUniform(structUniform + ".datasetDimensions_", tgt::vec3(sl->getTexture()->getDimensions())); shader->setUniform(structUniform + ".datasetDimensionsRCP_", vec3(1.f) / tgt::vec3(sl->getTexture()->getDimensions())); // volume spacing, i.e. voxel size //shader->setUniform(structUniform + ".datasetSpacing_", sl->getSpacing()); //shader->setUniform(structUniform + ".datasetSpacingRCP_", vec3(1.f) / sl->getSpacing()); shader->setUniform(structUniform + ".numChannels_", static_cast<GLint>(sl->getTexture()->getNumChannels())); //shader->setUniform(structUniform + ".numChannels_", static_cast<GLint>(1)); // volume's transformation matrix //shader->setUniform(structUniform + ".physicalToWorldMatrix_", sl->getPhysicalToWorldMatrix()); //tgt::mat4 invTm = sl->getWorldToPhysicalMatrix(); //shader->setUniform(structUniform + ".worldToPhysicalMatrix_", invTm); shader->setUniform(structUniform + ".worldToTextureMatrix_", sl->getWorldToTextureMatrix()); shader->setUniform(structUniform + ".textureToWorldMatrix_", sl->getTextureToWorldMatrix()); LGL_ERROR; // construct shader real-world mapping by combining volume rwm and pixel transfer mapping RealWorldMapping rwm = sl->getRealWorldMapping(); //RealWorldMapping transferMapping; //if (sl->getRepresentation<VolumeGL>()) //transferMapping = sl->getRepresentation<VolumeGL>()->getPixelTransferMapping(); //else //LWARNINGC("voreen.glsl", "setUniform(): no VolumeGL"); //RealWorldMapping shaderMapping = RealWorldMapping::combine(transferMapping.getInverseMapping(), rwm); RealWorldMapping shaderMapping = rwm; shader->setUniform(structUniform + ".rwmScale_", shaderMapping.getScale()); shader->setUniform(structUniform + ".rwmOffset_", shaderMapping.getOffset()); shader->setIgnoreUniformLocationError(ignoreErr); }
void TransFunc1DKeysEditor::volumeChanged() { if (volume_ /*&& volume_->hasRepresentation<VolumeRAM>()*/) { updateDataBounds(); /*if(unit == "") dataLabel_->setText("Data Bounds"); else dataLabel_->setText(QString("Data Bounds [") + QString::fromStdString(unit) + "]");*/ RealWorldMapping rwm = volume_->getRealWorldMapping(); if(property_->getAlwaysFitToDomain() || (((rwm.getOffset() != 0.0f) || (rwm.getScale() != 1.0f) || (rwm.getUnit() != "")) && *transferFuncIntensity_ == TransFunc1DKeys())) { fitDomainToData(); } // propagate new volume to transfuncMappingCanvas transCanvas_->volumeChanged(volume_); } else { transCanvas_->volumeChanged(0); } checkDomainVersusData(); }