Added missing files, fixed redundant p_targetImageId field in AdvOptimizedRaycaster.

parent 3572dba4
......@@ -39,7 +39,6 @@ namespace campvis {
AdvOptimizedRaycaster::AdvOptimizedRaycaster(IVec2Property* viewportSizeProp)
: RaycastingProcessor(viewportSizeProp, "modules/vis/advraycaster/glsl/AdvOptimizedRaycaster.frag", true, "400")
, p_targetImageID("targetImageID", "Output Image", "", DataNameProperty::WRITE)
, p_enableShadowing("EnableShadowing", "Enable Hard Shadows (Expensive!)", false, AbstractProcessor::INVALID_RESULT | AbstractProcessor::INVALID_SHADER | AbstractProcessor::INVALID_PROPERTIES)
, p_shadowIntensity("ShadowIntensity", "Shadow Intensity", .5f, .0f, 1.f)
, p_enableIntersectionRefinement("EnableIntersectionRefinement", "Enable Intersection Refinement", false, AbstractProcessor::INVALID_RESULT | AbstractProcessor::INVALID_SHADER)
......@@ -52,7 +51,6 @@ namespace campvis {
{
addDecorator(new ProcessorDecoratorShading());
addProperty(&p_targetImageID);
addProperty(&p_enableIntersectionRefinement);
addProperty(&p_useEmptySpaceSkipping);
......
......@@ -75,7 +75,6 @@ namespace campvis {
/// \see AbstractProcessor::deinit
virtual void deinit();
DataNameProperty p_targetImageID; ///< image ID for output image
BoolProperty p_enableShadowing;
FloatProperty p_shadowIntensity;
BoolProperty p_enableIntersectionRefinement;
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
in vec3 ex_TexCoord; ///< incoming texture coordinate
in vec4 ex_Position; ///< incoming texture coordinate
out uint result;
#include "tools/texture2d.frag"
#include "tools/texture3d.frag"
#include "tools/transferfunction.frag"
// DRR volume
uniform sampler3D _volume;
uniform TextureParameters3D _volumeTextureParams;
// Transfer function
uniform sampler1D _transferFunction;
uniform TFParameters1D _transferFunctionParams;
uniform float _inverseTexSizeX; // 1.0 / mipmapLevelResolution
uniform float _inverseTexSizeY; // 1.0 / mipmapLevelResolution
uniform uint _voxelSize;
uniform uint _voxelDepth;
void main() {
result = uint(0);
vec3 startIdx = vec3(0, 0, 0);
vec3 endIdx = _volumeTextureParams._size - vec3(1, 1, 1);
// For each bit of the int value, the area is checked to find voxels or not. If some voxels were found, the bit is set or cleared.
for(int d = 0; d < 32; d++){
vec3 samplePosition = vec3((gl_FragCoord.x - 0.5) * _voxelSize, (gl_FragCoord.y - 0.5) * _voxelSize, d * _voxelDepth);
bool hasData = false;
float intensity;
vec4 color;
/** For each bit _voxelSize number of voxels in x and y direction and _voxelDepth number of voxel in z-direction should be considered.
* Also, to make sure that all voxels are considered, one offset voxel is considered in x, y, and z boundary from each side so that
* each side will consider 2 more voxels.
*/
for(int i = 0; i < (_voxelSize + 2) * (_voxelSize + 2) * (_voxelDepth + 2); i++){
// the offset value calculates which voxel should be checked.
ivec3 offset = ivec3(i % (_voxelSize + 2) - 1, (i / (_voxelSize + 2)) % (_voxelSize + 2) - 1, i / ((_voxelSize + 2) * (_voxelSize + 2)) - 1);
vec3 s = clamp(samplePosition + vec3(0.5, 0.5, 0.5) + offset, startIdx, endIdx);
intensity = texture(_volume, s * _volumeTextureParams._sizeRCP).r;
color = lookupTF(_transferFunction, _transferFunctionParams, intensity);
// if there was any data in the volume data in that voxel, set the bit.
if(color.a > 0){
hasData = true;
break;
}
}
if(hasData){
result |= (1 << d);
}
}
}
\ No newline at end of file
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#include "rendervolumevoxelizing.h"
#include "tgt/assert.h"
#include "tgt/glmath.h"
#include "tgt/texture.h"
#include "tgt/textureunit.h"
#include "tgt/tgt_gl.h"
#include "core/datastructures/genericimagerepresentationlocal.h"
#define DIV_CEIL(x,y) ((x) > 0) ? (1 + ((x) - 1)/(y)) : ((x) / (y))
namespace campvis {
VoxelizedRenderVolume::VoxelizedRenderVolume(const ImageData* referenceImage, size_t brickSize)
: _referenceImage(referenceImage)
, _brickSize(brickSize)
, _bricks(0)
{
tgtAssert(_referenceImage != 0, "Reference Image must not be 0!");
// perform ceiling integer division:
// z is not considered.
_dimBricks = referenceImage->getSize();
for (int i = 0; i < 2; ++i)
_dimBricks.elem[i] = DIV_CEIL(_dimBricks.elem[i], _brickSize);
// set the depth of the bricks
_brickDepth = _dimBricks.z / VOXEL_DEPTH;
// since the texture is a 2D texture and the elements store the depth will pack VOXEL_DEPTH number of values along the z axis into one block, the _dimBricks.z is
_dimBricks.z = VOXEL_DEPTH;
_numBrickIndices = tgt::hmul(_dimBricks);
_dimPackedBricks = _dimBricks;
_dimPackedBricks.z = _dimPackedBricks.z / VOXEL_DEPTH;
_numElementsInBricksArray = tgt::hmul(_dimPackedBricks);
#if (VOXEL_DEPTH == 8)
_bricks = new uint8_t[_numElementsInBricksArray];
memset(_bricks, 0, _numElementsInBricksArray);
#else if(VOXEL_DEPTH == 32)
_bricks = new uint32_t[_numElementsInBricksArray];
memset(_bricks, 0, 4 * _numElementsInBricksArray);
#endif
}
VoxelizedRenderVolume::~VoxelizedRenderVolume() {
delete _bricks;
}
std::vector<tgt::svec3> VoxelizedRenderVolume::getAllVoxelsForBrick(size_t brickIndex) const {
tgt::ivec3 refImageSize = _referenceImage->getSize();
std::vector<tgt::svec3> toReturn;
toReturn.reserve((_brickSize+2) * (_brickSize+2) * (_brickDepth+2));
// traverse each dimension, check that voxel is within reference image size
tgt::ivec3 startVoxel = indexToBrick(brickIndex);
startVoxel.x *= _brickSize;
startVoxel.y *= _brickSize;
startVoxel.z *= _brickDepth;
for (int x = -1; x < static_cast<int>(_brickSize + 1); ++x) {
int xx = startVoxel.x + x;
if (xx < 0)
continue;
else if (xx >= refImageSize.x)
break;
for (int y = -1; y < static_cast<int>(_brickSize + 1); ++y) {
int yy = startVoxel.y + y;
if (yy < 0)
continue;
else if (yy >= refImageSize.y)
break;
for (int z = -1; z < static_cast<int>(_brickDepth + 1); ++z) {
int zz = startVoxel.z + z;
if (zz < 0)
continue;
else if (zz >= refImageSize.z)
break;
toReturn.push_back(tgt::svec3(xx, yy, zz));
}
}
}
return toReturn;
}
tgt::svec3 VoxelizedRenderVolume::indexToBrick(size_t brickIndex) const {
size_t z = brickIndex / (_dimBricks.x * _dimBricks.y);
size_t y = (brickIndex % (_dimBricks.x * _dimBricks.y)) / _dimBricks.x;
size_t x = (brickIndex % (_dimBricks.x * _dimBricks.y)) % _dimBricks.x;
return tgt::svec3(x, y, z);
}
size_t VoxelizedRenderVolume::brickToIndex(const tgt::svec3& brick) const {
return brick.x + (_dimBricks.x * brick.y) + (_dimBricks.x * _dimBricks.y * brick.z);
}
bool VoxelizedRenderVolume::getValueForIndex(size_t brickIndex) const {
size_t byte = brickIndex % (_dimBricks.x * _dimBricks.y);
size_t bit = brickIndex / (_dimBricks.x * _dimBricks.y);
tgtAssert(byte < _numElementsInBricksArray, "Brick brickIndex out of bounds!");
return (_bricks[byte] & (1 << bit)) != 0;
}
void VoxelizedRenderVolume::setValueForIndex(size_t brickIndex, bool value) {
size_t byte = brickIndex % (_dimBricks.x * _dimBricks.y);
size_t bit = brickIndex / (_dimBricks.x * _dimBricks.y);
tgtAssert(byte < _numElementsInBricksArray, "Brick brickIndex out of bounds!");
#if (VOXEL_DEPTH == 8)
if (value)
_bricks[byte] |= static_cast<uint8_t>(1 << bit);
else
_bricks[byte] &= static_cast<uint8_t>(~(1 << bit));
#else if(VOXEL_DEPTH == 32)
if (value)
_bricks[byte] |= static_cast<uint32_t>(1 << bit);
else
_bricks[byte] &= static_cast<uint32_t>(~(1 << bit));
#endif
}
tgt::Texture* VoxelizedRenderVolume::createEmptyImageData() const {
#if(VOXEL_DEPTH == 8)
tgt::Texture* toReturn = new tgt::Texture(0, _dimPackedBricks, GL_RED_INTEGER, GL_R32UI, GL_UNSIGNED_BYTE, tgt::Texture::NEAREST);
#else if(VOXEL_DEPTH == 32)
tgt::Texture* toReturn = new tgt::Texture(0, _dimPackedBricks, GL_RED_INTEGER, GL_R32UI, GL_UNSIGNED_INT, tgt::Texture::NEAREST);
#endif
LGL_ERROR;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
tgt::TextureUnit tempUnit;
tempUnit.activate();
toReturn->bind();
toReturn->uploadTexture();
LGL_ERROR;
toReturn->setWrapping(tgt::Texture::CLAMP);
toReturn->setPixelData(0);
LGL_ERROR;
return toReturn;
}
tgt::Texture* VoxelizedRenderVolume::exportToImageData() const {
#if(VOXEL_DEPTH == 8)
tgt::Texture* toReturn = new tgt::Texture(_bricks, _dimPackedBricks, GL_RED_INTEGER, GL_R32UI, GL_UNSIGNED_BYTE, tgt::Texture::NEAREST);
#else if(VOXEL_DEPTH == 32)
tgt::Texture* toReturn = new tgt::Texture((GLubyte*)_bricks, _dimPackedBricks, GL_RED_INTEGER, GL_R32UI, GL_UNSIGNED_INT, tgt::Texture::NEAREST);
#endif
LGL_ERROR;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
tgt::TextureUnit tempUnit;
tempUnit.activate();
toReturn->bind();
toReturn->uploadTexture();
LGL_ERROR;
toReturn->setWrapping(tgt::Texture::CLAMP);
LGL_ERROR;
return toReturn;
}
const tgt::svec3& VoxelizedRenderVolume::getNumBricks() const {
return _dimBricks;
}
size_t VoxelizedRenderVolume::getNumBrickIndices() const {
return _numBrickIndices;
}
size_t VoxelizedRenderVolume::getBrickSize() const {
return _brickSize;
}
size_t VoxelizedRenderVolume::getBrickDepth() const {
return _brickDepth;
}
int VoxelizedRenderVolume::getMaxDim() const {
return std::max(_dimPackedBricks.x, _dimPackedBricks.y);
}
int VoxelizedRenderVolume::getWidth() {
return _dimPackedBricks.x;
}
int VoxelizedRenderVolume::getHeight() {
return _dimPackedBricks.y;
}
}
\ No newline at end of file
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#ifndef VOLUMEVOXELIZING_H__
#define VOLUMEVOXELIZING_H__
#include "tgt/vector.h"
#include "core/datastructures/imagedata.h"
#include <vector>
#define VOXEL_DEPTH 32
namespace tgt {
class Texture;
}
namespace campvis {
class VoxelizedRenderVolume {
public:
VoxelizedRenderVolume(const ImageData* referenceImage, size_t brickSize);
~VoxelizedRenderVolume();
/**
* Gets the number of bricks in each dimension.
* \return _dimBricks
*/
const tgt::svec3& getNumBricks() const;
/**
* Gets the number of brick indices (= hmul(_dimBricks)).
* \return _numBrickIndices
*/
size_t getNumBrickIndices() const;
/**
* Gets the number of voxels a brick is covering in its width and height.
* \return _brickSize
*/
size_t getBrickSize() const;
/**
* Gets the number of voxels a brick is covering in its depth.
* \return _brickDepth
*/
size_t getBrickDepth() const;
/**
* Gets the maximum value in the dimensions of the voxelized volume.
* \return maximum between the
*/
int getMaxDim() const;
int getWidth();
int getHeight();
/**
* Returns the boolean value for the brick with index \a brickIndex.
* \param brickIndex Lookup brick index
* \return The boolean value for the brick with index \a brickIndex.
*/
bool getValueForIndex(size_t brickIndex) const;
/**
* Sets the boolean value for the brick with index \a brickIndex to \a value.
* \param brickIndex Lookup brick index
* \param value The new boolean value for this brick.
*/
void setValueForIndex(size_t brickIndex, bool value);
/**
* Return a vector of all voxels positions in the reference image that are in the brick with the index \a brickIndex.
* \param brickIndex Lookup brick index.
* \return A vector of all voxels positions in the reference image that are in the brick with the index \a brickIndex.
*/
std::vector<tgt::svec3> getAllVoxelsForBrick(size_t brickIndex) const;
/**
* Create an empty texture and return it.
* \return the created empty image.
*/
tgt::Texture* createEmptyImageData() const;
/**
* Create a texture and fill it with data in _bricks array and returns it.
* \return the texture filled with _bricks data.
*/
tgt::Texture* exportToImageData() const;
private:
/**
* Returns the brick coordinates for the brick with index \a brickIndex.
* \param brickIndex The Brick index to look up
* \return The corresponding 3D brick coordinates.
*/
tgt::svec3 indexToBrick(size_t brickIndex) const;
/**
* Transforms brick coordinates to the corresponding index.
* \param brick Brick coordinates.
* \return The corresponding index in if all bricks are in contiguous storage.
*/
size_t brickToIndex(const tgt::svec3& brick) const;
const ImageData* _referenceImage; ///< the reference image
size_t _brickSize; ///< number of voxels a brick is covering in x, y dimension
size_t _brickDepth; ///< number of voxel a brick is covering in its depth dimension
tgt::svec3 _dimBricks; ///< number of bricks in each dimension
size_t _numBrickIndices; ///< number of brick indices (= hmul(_dimPackedBricks))
#if(VOXEL_DEPTH == 8)
uint8_t* _bricks; ///< the densly packed bricks
#else if(VOXEL_DEPTH == 32)
uint32_t* _bricks; ///< the densly packed bricks
#endif
float* _maxVals; ///< Array of maximum values in a brick
float* _minVals; ///< Array of minimum values in a brick
tgt::svec3 _dimPackedBricks; ///< number of elements when bricks are tightly packed
size_t _numElementsInBricksArray; ///< number of elements in _bricks
};
}
#endif // VOLUMEVOXELIZING_H__
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment