Commit 27df6733 authored by schultezub's avatar schultezub

* making OpenCL dependency in RandomWalksLib optional

* fixing some compiler warning in RandomWalksLib
* introducing ConfidenceMapGenerator processor

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@452 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent fdae080d
......@@ -43,6 +43,7 @@ namespace campvis {
, _camera("camera", "Camera")
, _usReader()
, _confidenceReader()
, _confidenceGenerator()
, _gvg()
, _lhh()
, _usFusion1(_effectiveRenderTargetSize)
......@@ -61,6 +62,7 @@ namespace campvis {
{
addProcessor(&_usReader);
addProcessor(&_confidenceReader);
addProcessor(&_confidenceGenerator);
addProcessor(&_gvg);
//addProcessor(&_lhh);
addProcessor(&_usBlurFilter);
......@@ -93,6 +95,7 @@ namespace campvis {
_usReader.p_url.setValue("D:\\Medical Data\\US Confidence Vis\\01\\BMode_01.mhd");
_usReader.p_targetImageID.setValue("us.image");
_usReader.p_targetImageID.connect(&_confidenceGenerator.p_sourceImageID);
_usReader.p_targetImageID.connect(&_usFusion1.p_usImageId);
_usReader.p_targetImageID.connect(&_usFusion2.p_usImageId);
_usReader.p_targetImageID.connect(&_usFusion3.p_usImageId);
......@@ -103,11 +106,13 @@ namespace campvis {
_usReader.p_targetImageID.connect(&_usDenoiseilter.p_sourceImageID);
_confidenceReader.p_url.setValue("D:\\Medical Data\\US Confidence Vis\\01\\Confidence_01.mhd");
_confidenceReader.p_targetImageID.setValue("confidence.image");
_confidenceReader.p_targetImageID.connect(&_usFusion1.p_confidenceImageID);
_confidenceReader.p_targetImageID.connect(&_usFusion2.p_confidenceImageID);
_confidenceReader.p_targetImageID.connect(&_usFusion3.p_confidenceImageID);
_confidenceReader.p_targetImageID.connect(&_usFusion4.p_confidenceImageID);
_confidenceReader.p_targetImageID.setValue("confidence.image.read");
_confidenceGenerator.p_targetImageID.setValue("confidence.image.generated");
_confidenceGenerator.p_targetImageID.connect(&_usFusion1.p_confidenceImageID);
_confidenceGenerator.p_targetImageID.connect(&_usFusion2.p_confidenceImageID);
_confidenceGenerator.p_targetImageID.connect(&_usFusion3.p_confidenceImageID);
_confidenceGenerator.p_targetImageID.connect(&_usFusion4.p_confidenceImageID);
_gvg.p_targetImageID.connect(&_lhh.p_gradientsId);
_gvg.p_targetImageID.connect(&_usFusion1.p_gradientImageID);
......
......@@ -44,6 +44,7 @@
#include "modules/vis/processors/eepgenerator.h"
#include "modules/vis/processors/simpleraycaster.h"
#include "modules/vis/processors/quadview.h"
#include "modules/randomwalk/processors/confidencemapgenerator.h"
namespace campvis {
class AdvancedUsVis : public VisualizationPipeline {
......@@ -82,6 +83,8 @@ namespace campvis {
MhdImageReader _usReader;
MhdImageReader _confidenceReader;
ConfidenceMapGenerator _confidenceGenerator;
GradientVolumeGenerator _gvg;
LHHistogram _lhh;
AdvancedUsFusion _usFusion1;
......
......@@ -5,49 +5,51 @@ PROJECT(RandomWalksLib)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0 FATAL_ERROR)
MESSAGE(STATUS " Configuring external RandomWalksLib Library")
#all headers
SET(headers ConfidenceMaps2D.h
# all RandomWalksLibHeaders except ViennaCL related stuff
SET(RandomWalksLibHeaders ConfidenceMaps2D.h
ConfidenceMaps2DFacade.h
RandomWalks2D.h
RandomWalks2DFacade.h
RandomWalks3D.h
RandomWalks3DFacade.h
RandomWalksCore.h
SparseSolverEigenBiCGSTAB.h
SparseSolverEigenCG.h
SparseSolverEigenCustom.h
SparseSolverEigenLLT.h
SparseSolverFactory.h
SparseSolverInterface.h
SparseSolverViennaCPU.h
SparseSolverViennaGPU.h)
SparseSolverInterface.h)
SET(sources ConfidenceMaps2D.cpp
SET(RandomWalksLibSources ConfidenceMaps2D.cpp
ConfidenceMaps2DFacade.cpp
RandomWalks2D.cpp
RandomWalks2DFacade.cpp
RandomWalks3D.cpp
RandomWalks3DFacade.cpp
RandomWalksCore.cpp
SparseSolverEigenBiCGSTAB.cpp
SparseSolverEigenCG.cpp
SparseSolverEigenCustom.cpp
SparseSolverEigenLLT.cpp
SparseSolverFactory.cpp
SparseSolverViennaCPU.cpp
SparseSolverViennaGPU.cpp)
SparseSolverFactory.cpp)
# Eigen headers are already in CAMPVis/ext
#include ViennaCl headers
INCLUDE_DIRECTORIES(${CampvisGlobalIncludeDirs})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES($ENV{NVSDKCOMPUTE_ROOT}/OpenCL/common/inc)
#path to OpenCl binaries
LINK_DIRECTORIES($ENV{CUDA_LIB_PATH})
# Make OpenCL dependency optional
IF(OPENCL_FOUND)
ADD_DEFINITIONS("-DRANDOMWALKSLIB_HAS_OPENCL")
LIST(APPEND RandomWalksLibExternalLibs ${OPENCL_LIBRARY})
LIST(APPEND RandomWalksLibHeaders SparseSolverViennaCPU.h SparseSolverViennaGPU.h)
LIST(APPEND RandomWalksLibSources SparseSolverViennaCPU.cpp SparseSolverViennaGPU.cpp)
ENDIF()
################################################################################
# define library target
################################################################################
ADD_LIBRARY(RandomWalksLib STATIC ${sources} ${headers})
# Eigen RandomWalksLibHeaders are already in CAMPVis/ext
INCLUDE_DIRECTORIES(${CampvisGlobalIncludeDirs})
#include ViennaCl RandomWalksLibHeaders
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
ADD_LIBRARY(RandomWalksLib STATIC ${RandomWalksLibSources} ${RandomWalksLibHeaders})
# We don't want this within CAMPVis...
#put debug target to x64/Debug and all other configurations to x64/Release
......@@ -56,4 +58,4 @@ ADD_LIBRARY(RandomWalksLib STATIC ${sources} ${headers})
# ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/x64/Debug
# ARCHIVE_OUTPUT_NAME RandomWalksLib
# ARCHIVE_OUTPUT_NAME_DEBUG RandomWalksLibd ) #debug build should end with a 'd'
TARGET_LINK_LIBRARIES(RandomWalksLib OpenCL)
TARGET_LINK_LIBRARIES(RandomWalksLib ${RandomWalksLibExternalLibs})
......@@ -26,7 +26,7 @@ void ConfidenceMaps2D::setMatrix2D(const std::vector<double> * matrix, int rows,
max_mat = (*matrix).front();
//Find min-max
for(int i=0; i<matrix->size();i++)
for(size_t i=0; i<matrix->size();i++)
{
double val = (*matrix)[i];
if( val< min_mat )
......@@ -43,7 +43,7 @@ void ConfidenceMaps2D::setMatrix2D(const std::vector<double> * matrix, int rows,
if(diff<epsilon_diff)
diff = epsilon_diff;
for(int i=0; i<matrix_ptr->size();i++)
for(size_t i=0; i<matrix_ptr->size();i++)
(*matrix_ptr)[i] = ((*matrix_ptr)[i] - min_mat) /diff;
}
......
......@@ -27,7 +27,7 @@ std::vector<double> SparseSolverEigenBiCGSTAB::solve_Ax_b( SparseMatrix<double>
xmat[uidx[i]] = val;
}
for (int i=0; i<seeds->size(); i++)
for (size_t i=0; i<seeds->size(); i++)
{
if((*labels)[i] == active_label)
xmat[(*seeds)[i]] = 1.0;
......
......@@ -26,7 +26,7 @@ std::vector<double> SparseSolverEigenCG::solve_Ax_b(SparseMatrix<double> A, Spar
xmat[uidx[i]] = val;
}
for (int i=0; i<seeds->size(); i++)
for (size_t i=0; i<seeds->size(); i++)
{
if((*labels)[i] == active_label)
xmat[(*seeds)[i]] = 1.0;
......
......@@ -19,7 +19,7 @@ std::vector<double> SparseSolverEigenCustom::solve_Ax_b(SparseMatrix<double> A,
xmat[uidx[it.index()]] = it.value();
}
for (int i=0; i<seeds->size(); i++)
for (size_t i=0; i<seeds->size(); i++)
{
if((*labels)[i] == active_label)
xmat[(*seeds)[i]] = 1.0;
......
......@@ -34,7 +34,7 @@ std::vector<double> SparseSolverEigenLLT::solve_Ax_b(SparseMatrix<double> A, Spa
xmat[uidx[i]] = val;
}
for (int i=0; i<seeds->size(); i++)
for (size_t i=0; i<seeds->size(); i++)
{
if((*labels)[i] == active_label)
xmat[(*seeds)[i]] = 1.0;
......
......@@ -3,8 +3,11 @@
#include "SparseSolverEigenCG.h"
#include "SparseSolverEigenBiCGSTAB.h"
#include "SparseSolverEigenCustom.h"
#ifdef RANDOMWALKSLIB_HAS_OPENCL
#include "SparseSolverViennaCPU.h"
#include "SparseSolverViennaGPU.h"
#endif
#include <iostream>
......@@ -32,6 +35,7 @@ SparseSolverInterface * SparseSolverFactory::createSolver(std::string type, int
SparseSolverInterface * solver = new SparseSolverEigenCustom(iterations,tolerance);
return solver;
}
#ifdef RANDOMWALKSLIB_HAS_OPENCL
else if(type.compare("Vienna-CG-CPU")==0)
{
SparseSolverInterface * solver = new SparseSolverViennaCPU(iterations,tolerance);
......@@ -42,6 +46,7 @@ SparseSolverInterface * SparseSolverFactory::createSolver(std::string type, int
SparseSolverInterface * solver = new SparseSolverViennaGPU(iterations,tolerance);
return solver;
}
#endif
else
{
return new SparseSolverEigenLLT();
......
......@@ -27,7 +27,7 @@ std::vector<double> SparseSolverViennaCPU::solve_Ax_b(SparseMatrix<double> A, Sp
xmat[uidx[i]] = x_dense(i);
}
for (int i=0; i<seeds->size(); i++)
for (size_t i=0; i<seeds->size(); i++)
{
if((*labels)[i] == active_label)
xmat[(*seeds)[i]] = 1.0;
......
......@@ -38,7 +38,7 @@ std::vector<double> SparseSolverViennaGPU::solve_Ax_b(SparseMatrix<double> A, Sp
xmat[uidx[i]] = x_dense(i);
}
for (int i=0; i<seeds->size(); i++)
for (size_t i=0; i<seeds->size(); i++)
{
if((*labels)[i] == active_label)
xmat[(*seeds)[i]] = 1.0;
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, 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".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// 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 HOLDER 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 "confidencemapgenerator.h"
#include "tgt/logmanager.h"
#include "core/datastructures/imagedata.h"
#include "core/datastructures/genericimagerepresentationlocal.h"
#include "modules/randomwalk/ext/RandomWalksLib/ConfidenceMaps2DFacade.h"
#include <vector>
namespace campvis {
static const GenericOption<std::string> filterModes[2] = {
GenericOption<std::string>("median", "Median"),
GenericOption<std::string>("gauss", "Gauss"),
};
const std::string ConfidenceMapGenerator::loggerCat_ = "CAMPVis.modules.classification.ConfidenceMapGenerator";
ConfidenceMapGenerator::ConfidenceMapGenerator()
: AbstractProcessor()
, p_sourceImageID("InputImage", "Input Image ID", "image", DataNameProperty::READ)
, p_targetImageID("OutputConfidenceMap", "Output Confidence Map Image ID", "confidencemap", DataNameProperty::WRITE)
, p_alpha("Alpha", "Alpha Parameter", 2.f, .1f, 10.f)
, p_beta("Beta", "Beta Parameter", 100.f, 1.f, 1000.f)
, p_gamma("Gamma", "Gamma Parameter", .06f, .01f, 1.f)
, p_normalizeValues("NormalizeValues", "Noramlize Values", false)
, p_solver("FilterMode", "Filter Mode", filterModes, 2)
{
addProperty(&p_sourceImageID);
addProperty(&p_targetImageID);
addProperty(&p_alpha);
addProperty(&p_beta);
addProperty(&p_gamma);
addProperty(&p_normalizeValues);
addProperty(&p_solver);
}
ConfidenceMapGenerator::~ConfidenceMapGenerator() {
}
void ConfidenceMapGenerator::process(DataContainer& data) {
ImageRepresentationLocal::ScopedRepresentation input(data, p_sourceImageID.getValue());
if (input != 0 && input->getDimensionality() >= 2 && input->getParent()->getNumChannels() == 1) {
const tgt::svec3& imageSize = input->getSize();
size_t numElements = input->getNumElements();
size_t numElementsPerSlice = tgt::hmul(imageSize.xy());
ConfidenceMaps2DFacade cmGenerator;
std::vector<double> inputValues;
inputValues.resize(numElementsPerSlice);
float* outputValues = new float[numElements];
// Get each slice through the confidence map generator
size_t offset = 0;
for (size_t slice = 0; slice < imageSize.z; ++slice) {
// Since the confidence map generator expects a vector of double, we need to copy the image data...
for (size_t i = 0; i < numElementsPerSlice; ++i) {
inputValues[i] = static_cast<double>(input->getElementNormalized(i + offset, 0));
}
// compute confidence map
cmGenerator.setImage(inputValues, imageSize.x, imageSize.y, p_alpha.getValue(), p_normalizeValues.getValue());
std::vector<double> tmp = cmGenerator.computeMap(p_beta.getValue(), p_gamma.getValue());
// copy back
for (size_t i = 0; i < numElementsPerSlice; ++i) {
outputValues[i + offset] = static_cast<float>(tmp[i]);
}
offset += numElementsPerSlice;
}
ImageData* output = new ImageData(input->getDimensionality(), input->getSize(), 1);
GenericImageRepresentationLocal<float, 1>* confidenceMap = GenericImageRepresentationLocal<float, 1>::create(output, outputValues);
data.addData(p_targetImageID.getValue(), output);
p_targetImageID.issueWrite();
}
else {
LDEBUG("No suitable input image found.");
}
_invalidationLevel.setValid();
}
}
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, 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".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// 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 HOLDER 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.
//
// ================================================================================================
#ifndef CONFIDENCEMAPGENERATOR_H__
#define CONFIDENCEMAPGENERATOR_H__
#include "core/pipeline/abstractprocessor.h"
#include "core/properties/datanameproperty.h"
#include "core/properties/numericproperty.h"
#include "core/properties/optionproperty.h"
namespace campvis {
/**
* Creates Confidence Maps for Ultrasound Images.
*/
class ConfidenceMapGenerator : public AbstractProcessor {
public:
/**
* Constructs a new ConfidenceMapGenerator Processor
**/
ConfidenceMapGenerator();
/**
* Destructor
**/
virtual ~ConfidenceMapGenerator();
/// \see AbstractProcessor::getName()
virtual const std::string getName() const { return "ConfidenceMapGenerator"; };
/// \see AbstractProcessor::getDescription()
virtual const std::string getDescription() const { return "Creates Confidence Maps for Ultrasound Images."; };
virtual void process(DataContainer& data);
DataNameProperty p_sourceImageID; ///< ID for input image
DataNameProperty p_targetImageID; ///< ID for output confidence map image
FloatProperty p_alpha; ///< Alpha Parameter
FloatProperty p_beta; ///< Beta Parameter
FloatProperty p_gamma; ///< Gamma Parameter
BoolProperty p_normalizeValues; ///< Flag whether to normalize the values before computation
GenericOptionProperty<std::string> p_solver; ///< Solver to use
protected:
static const std::string loggerCat_;
};
}
#endif // CONFIDENCEMAPGENERATOR_H__
# CMake file for Randomwalk module
# build RadomWalksLib library
ADD_SUBDIRECTORY(modules/randomwalk/ext/RandomWalksLib)
\ No newline at end of file
ADD_SUBDIRECTORY(modules/randomwalk/ext/RandomWalksLib)
SET(ThisModExternalLibs "RandomWalksLib")
#add additional processors:
# Source files:
FILE(GLOB ThisModSources RELATIVE ${ModulesDir}
modules/randomwalk/processors/*.cpp
)
# Header files
FILE(GLOB ThisModHeaders RELATIVE ${ModulesDir}
modules/randomwalk/processors/*.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