Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature level-sets and dependencies #177

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions misc/computeutils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
ivw_module(ComputeUtils)

set(HEADER_FILES
include/inviwo/computeutils/algorithm/volumechannelsplitgl.h
include/inviwo/computeutils/algorithm/volumeminmaxgl.h
include/inviwo/computeutils/algorithm/volumenormalizationgl.h
include/inviwo/computeutils/algorithm/volumereductiongl.h
include/inviwo/computeutils/algorithm/volumeshrinktonormalrangegl.h
include/inviwo/computeutils/computeutilsmodule.h
include/inviwo/computeutils/computeutilsmoduledefine.h
include/inviwo/computeutils/processors/volumechannelsplitglprocessor.h
include/inviwo/computeutils/processors/volumeminmaxglprocessor.h
include/inviwo/computeutils/processors/volumenormalizationglprocessor.h
include/inviwo/computeutils/processors/volumereductionglprocessor.h
include/inviwo/computeutils/processors/volumeshrinktonormalrangeglprocessor.h
)
ivw_group("Header Files" ${HEADER_FILES})

set(SOURCE_FILES
src/algorithm/volumechannelsplitgl.cpp
src/algorithm/volumeminmaxgl.cpp
src/algorithm/volumenormalizationgl.cpp
src/algorithm/volumereductiongl.cpp
src/algorithm/volumeshrinktonormalrangegl.cpp
src/computeutilsmodule.cpp
src/processors/volumechannelsplitglprocessor.cpp
src/processors/volumeminmaxglprocessor.cpp
src/processors/volumenormalizationglprocessor.cpp
src/processors/volumereductionglprocessor.cpp
src/processors/volumeshrinktonormalrangeglprocessor.cpp
)
ivw_group("Source Files" ${SOURCE_FILES})

set(SHADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/glsl/volumesplit.comp
${CMAKE_CURRENT_SOURCE_DIR}/glsl/volumereduction.comp
${CMAKE_CURRENT_SOURCE_DIR}/glsl/volumenormalization.comp
${CMAKE_CURRENT_SOURCE_DIR}/glsl/volumeshrinktonormalrange.comp
)
ivw_group("Shader Files" ${SHADER_FILES})

set(TEST_FILES
tests/unittests/computeutils-unittest-main.cpp
)
ivw_add_unittest(${TEST_FILES})

ivw_create_module(${SOURCE_FILES} ${HEADER_FILES} ${SHADER_FILES})

# Add shader directory to install package
#ivw_add_to_module_pack(${CMAKE_CURRENT_SOURCE_DIR}/glsl)
3 changes: 3 additions & 0 deletions misc/computeutils/depends.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(dependencies
InviwoOpenGLModule
)
80 changes: 80 additions & 0 deletions misc/computeutils/glsl/volumenormalization.comp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*********************************************************************************
*
* Inviwo - Interactive Visualization Workshop
*
* Copyright (c) 2014-2021 Inviwo Foundation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*********************************************************************************/

#include "utils/structs.glsl"

uniform sampler3D inputTexture;
uniform VolumeParameters inputTextureParameters;
writeonly uniform image3D outputTexture;

layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

vec4 getNormalizedVoxel(sampler3D volume, VolumeParameters volumeParams, ivec3 samplePos) {
return (texelFetch(volume, samplePos, 0) + volumeParams.formatOffset)
* (1.0 - volumeParams.formatScaling);
}

float getNormalizedVoxelChannel(sampler3D volume, VolumeParameters volumeParams, ivec3 samplePos, int channel) {
vec4 v = getNormalizedVoxel(volume, volumeParams, samplePos);
return v[channel];
}

void main() {
ivec3 samplePos = ivec3(gl_GlobalInvocationID);

vec4 original = texelFetch(inputTexture, samplePos, 0);

float l, m, n, o;

#ifdef NORMALIZE_CHANNEL_0
l = getNormalizedVoxelChannel(inputTexture, inputTextureParameters, samplePos, 0);
#else
l = original[0];
#endif

#ifdef NORMALIZE_CHANNEL_1
m = getNormalizedVoxelChannel(inputTexture, inputTextureParameters, samplePos, 1);
#else
m = original[1];
#endif

#ifdef NORMALIZE_CHANNEL_2
n = getNormalizedVoxelChannel(inputTexture, inputTextureParameters, samplePos, 2);
#else
n = original[2];
#endif

#ifdef NORMALIZE_CHANNEL_3
o = getNormalizedVoxelChannel(inputTexture, inputTextureParameters, samplePos, 3);
#else
o = original[3];
#endif

imageStore(outputTexture, samplePos, vec4(l, m, n, o));
}
218 changes: 218 additions & 0 deletions misc/computeutils/glsl/volumereduction.comp
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
/*********************************************************************************
*
* Inviwo - Interactive Visualization Workshop
*
* Copyright (c) 2021 Inviwo Foundation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*********************************************************************************/

uniform
#if defined REDUCTION_SAMPLER_TYPE_FLOAT
sampler3D
#elif defined REDUCTION_SAMPLER_TYPE_INTEGER
isampler3D
#elif defined REDUCTION_SAMPLER_TYPE_UNSIGNED
usampler3D
#endif
inputTexture;

uniform vec2 disregardingRange;

writeonly uniform image3D outputTexture;

layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

void main() {
ivec3 outputPosition = ivec3(gl_GlobalInvocationID);
ivec3 samplePosition000 = outputPosition * ivec3(2, 2, 2);
ivec3 samplePosition001 = samplePosition000 + ivec3(0, 0, 1);
ivec3 samplePosition010 = samplePosition000 + ivec3(0, 1, 0);
ivec3 samplePosition011 = samplePosition000 + ivec3(0, 1, 1);
ivec3 samplePosition100 = samplePosition000 + ivec3(1, 0, 0);
ivec3 samplePosition101 = samplePosition000 + ivec3(1, 0, 1);
ivec3 samplePosition110 = samplePosition000 + ivec3(1, 1, 0);
ivec3 samplePosition111 = samplePosition000 + ivec3(1, 1, 1);

vec4 val = vec4(0);
vec4 sampledVal = vec4(0);
bool less = false;
bool greater = false;
vec4 disregardingRangeMin = vec4(disregardingRange.x);
vec4 disregardingRangeMax = vec4(disregardingRange.y);

// Min operator
#if OPERATOR == 0
// Init with infinity
val = vec4(1.0 / 0.0);


sampledVal = texelFetch(inputTexture, samplePosition000, 0);
#if DISREGARD == 1
less = any(lessThan(sampledVal, disregardingRangeMin));
val = less ? val : min(val, sampledVal);
#else
val = min(val, sampledVal);
#endif

sampledVal = texelFetch(inputTexture, samplePosition001, 0);
#if DISREGARD == 1
less = any(lessThan(sampledVal, disregardingRangeMin));
val = less ? val : min(val, sampledVal);
#else
val = min(val, sampledVal);
#endif

sampledVal = texelFetch(inputTexture, samplePosition010, 0);
#if DISREGARD == 1
less = any(lessThan(sampledVal, disregardingRangeMin));
val = less ? val : min(val, sampledVal);
#else
val = min(val, sampledVal);
#endif

sampledVal = texelFetch(inputTexture, samplePosition011, 0);
#if DISREGARD == 1
less = any(lessThan(sampledVal, disregardingRangeMin));
val = less ? val : min(val, sampledVal);
#else
val = min(val, sampledVal);
#endif

sampledVal = texelFetch(inputTexture, samplePosition100, 0);
#if DISREGARD == 1
less = any(lessThan(sampledVal, disregardingRangeMin));
val = less ? val : min(val, sampledVal);
#else
val = min(val, sampledVal);
#endif

sampledVal = texelFetch(inputTexture, samplePosition101, 0);
#if DISREGARD == 1
less = any(lessThan(sampledVal, disregardingRangeMin));
val = less ? val : min(val, sampledVal);
#else
val = min(val, sampledVal);
#endif

sampledVal = texelFetch(inputTexture, samplePosition110, 0);
#if DISREGARD == 1
less = any(lessThan(sampledVal, disregardingRangeMin));
val = less ? val : min(val, sampledVal);
#else
val = min(val, sampledVal);
#endif

sampledVal = texelFetch(inputTexture, samplePosition111, 0);
#if DISREGARD == 1
less = any(lessThan(sampledVal, disregardingRangeMin));
val = less ? val : min(val, sampledVal);
#else
val = min(val, sampledVal);
#endif
#endif

// Max operator
#if OPERATOR == 1
// Init with -infinity
val = vec4(-1.0 / 0.0);

sampledVal = texelFetch(inputTexture, samplePosition000, 0);
#if DISREGARD == 1
greater = any(greaterThan(sampledVal, disregardingRangeMax));
val = greater ? val : max(val, sampledVal);
#else
val = max(val, sampledVal);
#endif

sampledVal = texelFetch(inputTexture, samplePosition001, 0);
#if DISREGARD == 1
greater = any(greaterThan(sampledVal, disregardingRangeMax));
val = greater ? val : max(val, sampledVal);
#else
val = max(val, sampledVal);
#endif

sampledVal = texelFetch(inputTexture, samplePosition010, 0);
#if DISREGARD == 1
greater = any(greaterThan(sampledVal, disregardingRangeMax));
val = greater ? val : max(val, sampledVal);
#else
val = max(val, sampledVal);
#endif

sampledVal = texelFetch(inputTexture, samplePosition011, 0);
#if DISREGARD == 1
greater = any(greaterThan(sampledVal, disregardingRangeMax));
val = greater ? val : max(val, sampledVal);
#else
val = max(val, sampledVal);
#endif

sampledVal = texelFetch(inputTexture, samplePosition100, 0);
#if DISREGARD == 1
greater = any(greaterThan(sampledVal, disregardingRangeMax));
val = greater ? val : max(val, sampledVal);
#else
val = max(val, sampledVal);
#endif

sampledVal = texelFetch(inputTexture, samplePosition101, 0);
#if DISREGARD == 1
greater = any(greaterThan(sampledVal, disregardingRangeMax));
val = greater ? val : max(val, sampledVal);
#else
val = max(val, sampledVal);
#endif

sampledVal = texelFetch(inputTexture, samplePosition110, 0);
#if DISREGARD == 1
greater = any(greaterThan(sampledVal, disregardingRangeMax));
val = greater ? val : max(val, sampledVal);
#else
val = max(val, sampledVal);
#endif

sampledVal = texelFetch(inputTexture, samplePosition111, 0);
#if DISREGARD == 1
greater = any(greaterThan(sampledVal, disregardingRangeMax));
val = greater ? val : max(val, sampledVal);
#else
val = max(val, sampledVal);
#endif
#endif

// Sum operator
#if OPERATOR == 2
val = texelFetch(inputTexture, samplePosition000, 0);
val = val + texelFetch(inputTexture, samplePosition001, 0);
val = val + texelFetch(inputTexture, samplePosition010, 0);
val = val + texelFetch(inputTexture, samplePosition011, 0);
val = val + texelFetch(inputTexture, samplePosition100, 0);
val = val + texelFetch(inputTexture, samplePosition101, 0);
val = val + texelFetch(inputTexture, samplePosition110, 0);
val = val + texelFetch(inputTexture, samplePosition111, 0);
#endif

imageStore (outputTexture, outputPosition, val);
}
Loading