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 8 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
2 changes: 2 additions & 0 deletions .github/presets/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"IVW_MODULE_NANOVGUTILS": { "type": "BOOL", "value": "ON"},
"IVW_MODULE_TENSORVISBASE": { "type": "BOOL", "value": "ON"},
"IVW_MODULE_INTEGRALLINEFILTERING": { "type": "BOOL", "value": "ON"},
"IVW_MODULE_FEATURELEVELSETSGL": { "type": "BOOL", "value": "ON"},
"IVW_MODULE_COMPUTEUTILS": { "type": "BOOL", "value": "ON"},
"IVW_MODULE_MOLVISBASE": { "type": "BOOL", "value": "ON"},
"IVW_MODULE_MOLVISGL": { "type": "BOOL", "value": "ON"},
"IVW_MODULE_MOLVISPYTHON": { "type": "BOOL", "value": "ON"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,12 @@

namespace inviwo {

/** \docpage{org.inviwo.ComputeShaderBufferExample, Compute Shader Buffer Example}
* ![](org.inviwo.ComputeShaderBufferExample.png?classIdentifier=org.inviwo.ComputeShaderBufferExample)
*
* An processor to show how compute shaders can be utilized to create vertex buffers. Uses shader
* spiral.comp to create a simple spiral.
*
*
* ### Outports
* * __mesh__ Mesh containing the created vertex buffers.
*
* ### Properties
* * __Number of points__ Number of points used to represent the spiral.
* * __Radius__ The radius of the spiral.
* * __Rotations__ How many rotations the spiral will have.
* * __Height__ Hight difference between start and end point of the spiral.
* * __Color Mapping__ Used to colorize the spiral.
*
*/

class IVW_MODULE_COMPUTESHADEREXAMPLES_API ComputeShaderBufferExample : public Processor {
public:
ComputeShaderBufferExample();
virtual ~ComputeShaderBufferExample() = default;

virtual void initializeResources() override;
virtual void process() override;

virtual const ProcessorInfo& getProcessorInfo() const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,12 @@

namespace inviwo {

/** \docpage{org.inviwo.ComputeShaderImageExample, Compute Shader Image Example}
* ![](org.inviwo.ComputeShaderImageExample.png?classIdentifier=org.inviwo.ComputeShaderImageExample)
*
* An processor to show how compute shaders can be utilized to create images. Uses shader
* roll.comp to create a simple procedural image.
* C++ and glsl source code is havily inspired by http://wili.cc/blog/opengl-cs.html
*
*
* ### Outports
* * __outport__ The produced image.
*
* ### Properties
* * __Roll__ Used as offset in to the sin function in the shader to create an rolling effect.
*
*/

class IVW_MODULE_COMPUTESHADEREXAMPLES_API ComputeShaderImageExample : public Processor {
public:
ComputeShaderImageExample();
virtual ~ComputeShaderImageExample() = default;

virtual void initializeResources() override;
virtual void process() override;

virtual const ProcessorInfo& getProcessorInfo() const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,37 @@ const ProcessorInfo ComputeShaderBufferExample::processorInfo_{
"Example", // Category
CodeState::Experimental, // Code state
Tags::GL, // Tags
R"(An processor to show how compute shaders can be utilized to create vertex buffers.
Uses shader `spiral.comp` to create a simple spiral.)"_unindentHelp,
};
const ProcessorInfo& ComputeShaderBufferExample::getProcessorInfo() const { return processorInfo_; }

ComputeShaderBufferExample::ComputeShaderBufferExample()
: Processor()
, mesh_("mesh")
, shader_({{ShaderType::Compute, "spiral.comp"}})
, numPoints_("numPoints", "Number of points", 1024, 1, 10000)
, radius_("radius", "Radius", 1, 0, 10)
, rotations_("rotations", "Rotations", 1, 0, 10)
, height_("height", "Height", 1, 0, 10)
, tf_("tf", "Color Mapping") {
addPort(mesh_);
: Processor{}
, mesh_{"mesh", "Mesh containing the created vertex buffers"_help}
, shader_{{{ShaderType::Compute, "spiral.comp"}}, Shader::Build::No}
, numPoints_{"numPoints", "Number of points",
util::ordinalCount(1024, 10000)
.setMin(1)
.set("Number of points used to represent the spiral"_help)}
, radius_{"radius", "Radius",
util::ordinalScale(1.0f, 10.0f).set("The radius of the spiral"_help)}
, rotations_{"rotations", "Rotations",
util::ordinalScale(1.0f, 10.0f)
.set("Number of rotations the spiral will have"_help)}
, height_{"height", "Height",
util::ordinalScale(1.0f, 10.0f)
.set("Height difference between start and end point of the spiral"_help)}
, tf_{"tf", "Color Mapping", "Used to colorize the spiral"_help} {

addPort(mesh_);
addProperties(numPoints_, radius_, rotations_, height_, tf_);

shader_.onReload([this]() { invalidate(InvalidationLevel::InvalidOutput); });
shader_.onReload([this]() { invalidate(InvalidationLevel::InvalidResources); });
}

void ComputeShaderBufferExample::initializeResources() { shader_.build(); }

void ComputeShaderBufferExample::process() {
shader_.activate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,32 @@ const ProcessorInfo ComputeShaderImageExample::processorInfo_{
"Example", // Category
CodeState::Experimental, // Code state
Tags::GL, // Tags
R"(A processor to show how compute shaders can be utilized to create images.
Uses shader `roll.comp` to create a simple procedural image.

C++ and GSLS source code is heavily inspired by http://wili.cc/blog/opengl-cs.html)"_help,
};
const ProcessorInfo& ComputeShaderImageExample::getProcessorInfo() const { return processorInfo_; }

ComputeShaderImageExample::ComputeShaderImageExample()
: Processor()
, outport_("outport")
, shader_({{ShaderType::Compute, "roll.comp"}})
, roll_{"roll", "Roll", 0, 0, 10} {
: Processor{}
, outport_{"outport", "Generated output image"_help}
, shader_{{{ShaderType::Compute, "roll.comp"}}, Shader::Build::No}
, roll_{"roll", "Roll",
util::ordinalLength(0.0f, 10.0f)
.set("Used as offset in the sin function used in the shader to "
"create a rolling effect"_help)} {

addPort(outport_);

addProperty(roll_);

shader_.onReload([this]() { invalidate(InvalidationLevel::InvalidOutput); });
shader_.onReload([this]() { invalidate(InvalidationLevel::InvalidResources); });
}

void ComputeShaderImageExample::initializeResources() { shader_.build(); }

void ComputeShaderImageExample::process() {
// http://wili.cc/blog/opengl-cs.html
// inspired by http://wili.cc/blog/opengl-cs.html

glActiveTexture(GL_TEXTURE0);

Expand Down
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-2025 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));
}
Loading
Loading