11.3.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit fdae080d authored by schultezub's avatar schultezub

* refactored modules/ directory parsing out of commonconf.conf into separate CMake file

* introducing randomwalk module providing Athanasios' RandomWalksLib

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@450 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent cfff4e09
......@@ -28,8 +28,8 @@ ENDIF()
#
# Further Build Configurations
#
include(cmake/commonconf.cmake)
include(cmake/parseModulesDir.cmake)
MESSAGE(STATUS "--------------------------------------------------------------------------------")
......
IF(NOT CommonconfProcessed)
SET(CampvisHome ${CMAKE_CURRENT_SOURCE_DIR})
SET(CampvisBinaryDir ${CMAKE_BINARY_DIR})
MESSAGE(STATUS "TUMVis Source Directory: ${CampvisHome}")
MESSAGE(STATUS "TUMVis Binary Directory: ${CMAKE_BINARY_DIR}")
MESSAGE(STATUS "TUMVis Binary Directory: ${CampvisBinaryDir}")
# include macros
INCLUDE(${CampvisHome}/cmake/macros.cmake)
......@@ -200,69 +201,5 @@ ELSE(OPENCL_FOUND)
MESSAGE(STATUS "* Did NOT find OpenCL!")
ENDIF(OPENCL_FOUND)
# detect modules
MESSAGE(STATUS "--------------------------------------------------------------------------------")
MESSAGE(STATUS "Detecting installed modules:")
# collect list of directories in modules directories
SET(ModulesDir ${CampvisHome}/modules)
LIST_SUBDIRECTORIES(ModDirs ${ModulesDir} false)
# remove CMake and SVN realated directories from list
LIST(REMOVE_ITEM ModDirs CMakeFiles campvis-modules.dir .svn)
# go through each subdirectory
FOREACH(ModDir ${ModDirs})
# check whether module.cmake file exists
SET(ModFile ${ModulesDir}/${ModDir}/${ModDir}.cmake)
IF(EXISTS ${ModFile})
STRING(TOLOWER ${ModDir} ModDirLower)
STRING(TOUPPER ${ModDir} ModDirUpper)
# check whether the option to build this very module exists and is checked
IF(CAMPVIS_BUILD_MODULE_${ModDirUpper})
SET(ThisModDir ${ModulesDir}/${ModDir})
# load .cmake file
INCLUDE(${ModFile})
# merge module settings into global settings
LIST(APPEND CampvisModulesDefinitions ${ThisModDefinitions})
LIST(APPEND CampvisModulesIncludeDirs ${ThisModIncludeDirs})
LIST(APPEND CampvisModulesExternalLibs ${ThisModExternalLibs})
LIST(APPEND CampvisModulesSources ${ThisModSources})
LIST(APPEND CampvisModulesHeaders ${ThisModHeaders})
LIST(APPEND CampvisModulesCoreSources ${ThisModCoreSources})
LIST(APPEND CampvisModulesCoreHeaders ${ThisModCoreHeaders})
# add definition that this module is activated
LIST(APPEND CampvisGlobalDefinitions -DCAMPVIS_HAS_MODULE_${ModDirUpper})
# unset module settings to avoid duplicates if module cmake file misses sth.
UNSET(ThisModDefinitions)
UNSET(ThisModIncludeDirs)
UNSET(ThisModExternalLibs)
UNSET(ThisModSources)
UNSET(ThisModHeaders)
UNSET(ThisModCoreSources)
UNSET(ThisModCoreHeaders)
MESSAGE(STATUS "* Found Module '${ModDir}' . ENABLED")
ELSE()
MESSAGE(STATUS "* Found Module '${ModDir}'")
ENDIF(CAMPVIS_BUILD_MODULE_${ModDirUpper})
IF(NOT DEFINED CAMPVIS_BUILD_MODULE_${ModDirUpper})
# add a CMake option for building this module
OPTION(CAMPVIS_BUILD_MODULE_${ModDirUpper} "Build Module ${ModDir}" OFF)
ENDIF(NOT DEFINED CAMPVIS_BUILD_MODULE_${ModDirUpper})
ELSE(EXISTS ${ModFile})
MESSAGE(STATUS "* WARNING: Found Directory ${ModDir} Without CMake file - ignored")
ENDIF(EXISTS ${ModFile})
ENDFOREACH(ModDir ${ModDirs})
SET(CommonconfProcessed TRUE)
ENDIF(NOT CommonconfProcessed)
IF(NOT ModulesDirsParsed)
# detect modules
MESSAGE(STATUS "--------------------------------------------------------------------------------")
MESSAGE(STATUS "Detecting installed modules:")
# collect list of directories in modules directories
SET(ModulesDir ${CampvisHome}/modules)
LIST_SUBDIRECTORIES(ModDirs ${ModulesDir} false)
# remove CMake and SVN realated directories from list
LIST(REMOVE_ITEM ModDirs CMakeFiles campvis-modules.dir .svn)
# go through each subdirectory
FOREACH(ModDir ${ModDirs})
# check whether module.cmake file exists
SET(ModFile ${ModulesDir}/${ModDir}/${ModDir}.cmake)
IF(EXISTS ${ModFile})
STRING(TOLOWER ${ModDir} ModDirLower)
STRING(TOUPPER ${ModDir} ModDirUpper)
# check whether the option to build this very module exists and is checked
IF(CAMPVIS_BUILD_MODULE_${ModDirUpper})
MESSAGE(STATUS "* Found Module '${ModDir}' : ENABLED")
SET(ThisModDir ${ModulesDir}/${ModDir})
# load .cmake file
INCLUDE(${ModFile})
# merge module settings into global settings
LIST(APPEND CampvisModulesDefinitions ${ThisModDefinitions})
LIST(APPEND CampvisModulesIncludeDirs ${ThisModIncludeDirs})
LIST(APPEND CampvisModulesExternalLibs ${ThisModExternalLibs})
LIST(APPEND CampvisModulesSources ${ThisModSources})
LIST(APPEND CampvisModulesHeaders ${ThisModHeaders})
LIST(APPEND CampvisModulesCoreSources ${ThisModCoreSources})
LIST(APPEND CampvisModulesCoreHeaders ${ThisModCoreHeaders})
# add definition that this module is activated
LIST(APPEND CampvisGlobalDefinitions -DCAMPVIS_HAS_MODULE_${ModDirUpper})
# unset module settings to avoid duplicates if module cmake file misses sth.
UNSET(ThisModDefinitions)
UNSET(ThisModIncludeDirs)
UNSET(ThisModExternalLibs)
UNSET(ThisModSources)
UNSET(ThisModHeaders)
UNSET(ThisModCoreSources)
UNSET(ThisModCoreHeaders)
ELSE()
MESSAGE(STATUS "* Found Module '${ModDir}'")
ENDIF(CAMPVIS_BUILD_MODULE_${ModDirUpper})
IF(NOT DEFINED CAMPVIS_BUILD_MODULE_${ModDirUpper})
# add a CMake option for building this module
OPTION(CAMPVIS_BUILD_MODULE_${ModDirUpper} "Build Module ${ModDir}" OFF)
ENDIF(NOT DEFINED CAMPVIS_BUILD_MODULE_${ModDirUpper})
ELSE(EXISTS ${ModFile})
MESSAGE(STATUS "* WARNING: Found Directory ${ModDir} Without CMake file - ignored")
ENDIF(EXISTS ${ModFile})
ENDFOREACH(ModDir ${ModDirs})
SET(ModulesDirsParsed TRUE)
ENDIF(NOT ModulesDirsParsed)
......@@ -18,12 +18,12 @@ FILE(GLOB KISSCL_SOURCES *.cpp)
# define library target
################################################################################
ADD_LIBRARY(kisscl ${KISSCL_SOURCES} ${KISSCL_HEADERS})
ADD_DEFINITIONS(${CampvisGlobalDefinitions} ${CAMPVIS_MODULE_DEFINITIONS})
ADD_DEFINITIONS(${CampvisGlobalDefinitions})
IF(CAMPVIS_SHARED_LIBS AND MSVC)
ADD_DEFINITIONS("-DKISSCL_BUILD_DLL")
ENDIF()
INCLUDE_DIRECTORIES(${CampvisGlobalIncludeDirs} ${CAMPVIS_MODULE_INCLUDE_DIRECTORIES})
TARGET_LINK_LIBRARIES(kisscl ${CAMPVIS_EXTERNAL_LIBRARIES})
INCLUDE_DIRECTORIES(${CampvisGlobalIncludeDirs})
TARGET_LINK_LIBRARIES(kisscl ${CampvisGlobalExternalLibs})
################################################################################
# deployment
......
......@@ -11,7 +11,7 @@ IF(ITK_FOUND)
#SET(ThisModIncludeDirs ${ITK_INCLUDE_DIRS})
#SET(ThisModExternalLibs ${ITK_LIBRARIES})
MESSAGE(STATUS "** Found ITK library")
MESSAGE(STATUS " Found ITK library")
ELSE(ITK_FOUND)
MESSAGE(FATAL_ERROR "Could not locate ITK.")
ENDIF(ITK_FOUND)
......
################################################################################
# Project file for the RandomWalksLib library
################################################################################
PROJECT(RandomWalksLib)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0 FATAL_ERROR)
MESSAGE(STATUS " Configuring external RandomWalksLib Library")
#all headers
SET(headers ConfidenceMaps2D.h
ConfidenceMaps2DFacade.h
RandomWalks2D.h
RandomWalks2DFacade.h
RandomWalks3D.h
RandomWalks3DFacade.h
RandomWalksCore.h
SparseSolverEigenCG.h
SparseSolverEigenCustom.h
SparseSolverEigenLLT.h
SparseSolverFactory.h
SparseSolverInterface.h
SparseSolverViennaCPU.h
SparseSolverViennaGPU.h)
SET(sources ConfidenceMaps2D.cpp
ConfidenceMaps2DFacade.cpp
RandomWalks2D.cpp
RandomWalks2DFacade.cpp
RandomWalks3D.cpp
RandomWalks3DFacade.cpp
RandomWalksCore.cpp
SparseSolverEigenCG.cpp
SparseSolverEigenCustom.cpp
SparseSolverEigenLLT.cpp
SparseSolverFactory.cpp
SparseSolverViennaCPU.cpp
SparseSolverViennaGPU.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})
################################################################################
# define library target
################################################################################
ADD_LIBRARY(RandomWalksLib STATIC ${sources} ${headers})
# We don't want this within CAMPVis...
#put debug target to x64/Debug and all other configurations to x64/Release
#SET_TARGET_PROPERTIES( RandomWalksLib PROPERTIES
# ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/x64/Release #static libs are archives
# 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)
#include "ConfidenceMaps2D.h"
ConfidenceMaps2D::ConfidenceMaps2D()
{
}
ConfidenceMaps2D::~ConfidenceMaps2D()
{
}
void ConfidenceMaps2D::setMatrix2D(const std::vector<double> * matrix, int rows, int cols, bool normalizeValues)
{
this->matrix = matrix;
this->rows = rows;
this->cols = cols;
this->numel = rows*cols;
std::vector<double> * matrix_ptr = const_cast<std::vector<double>* >(matrix);
if(normalizeValues)
{
double min_mat;
double max_mat;
min_mat = (*matrix).front();
max_mat = (*matrix).front();
//Find min-max
for(int i=0; i<matrix->size();i++)
{
double val = (*matrix)[i];
if( val< min_mat )
min_mat = val;
if(val > max_mat)
max_mat = val;
}
// Normalization values
double diff = (max_mat - min_mat);
// Prevent division by zero
const double epsilon_diff = 1.0e-17;
if(diff<epsilon_diff)
diff = epsilon_diff;
for(int i=0; i<matrix_ptr->size();i++)
(*matrix_ptr)[i] = ((*matrix_ptr)[i] - min_mat) /diff;
}
std::vector<double> dist_penalty;
dist_penalty.reserve(rows);
for(int i=0; i<rows; i++)
{
double val = 1.0- (exp(- alpha * (double(i)/double(rows))));
dist_penalty.push_back(val);
}
// Apply distance weighting to image
for(int j=0;j<cols;j++){
for(int i=1; i<rows; i++){
(*matrix_ptr)[i+j*rows] = (*matrix_ptr)[i+j*rows]*dist_penalty[i];
}
}
}
void ConfidenceMaps2D::assembleLaplacianEdges()
{
//const T epsilon = std::numeric_limits<T>::epsilon(); // Numerical limit to avoid division by zero and add to the weights to avoid zero weights in Laplacian
// Numerical limit to avoid division by zero and add to the weights to avoid zero weights in Laplacian
const double epsilon = 1.0e-5;
this->L.resize(numel,numel);
// Find min and max weights
double min_weight;
double max_weight;
min_weight = (*matrix).front();
max_weight = (*matrix).front();
// Horizontal edges
for(int i=0; i<= numel-rows-1; i++)
{
double weight = abs((*matrix)[i] - (*matrix)[i+rows]);
weight += gamma;
if(weight < min_weight )
min_weight = weight;
if(weight > max_weight)
max_weight = weight;
}
// Vertical edges
for(int i=0; i<= numel-rows; i+=rows)
{
for(int j=0; j<=rows-2; j++)
{
double weight = abs((*matrix)[i+j] - (*matrix)[i+j+1]) ;
if(weight < min_weight )
min_weight = weight;
if(weight > max_weight)
max_weight = weight;
}
}
// ---Find min and max weights
// Normalization values
double diff = (max_weight - min_weight);
// Prevent division by zero
const double epsilon_diff = 1.0e-17;
if(diff<epsilon_diff)
diff = epsilon_diff;
// Reserve 5 non-zero entries for each column.
// This is the case for the 4-connected lattice.
// Always reserve more than less entries (this is very crucial for performance)
L.reserve(VectorXi::Constant(numel,5));
// Horizontal edges
for(int i=0; i<= numel-rows-1; i++)
{
// .coeffRef save
// .insert assumes entry is zero, faster but if entry non-zero crash
// Alternative but a lot slower L.coeffRef(i,i+rows) = 1.0; L.coeffRef(i+rows,i) = 1.0;
// Weighted by matrix
double weight = abs((*matrix)[i] - (*matrix)[i+rows]);
weight += gamma;
weight = (weight - min_weight) / diff;
weight = exp(-beta*weight) + epsilon; // Compute Gaussian weighting
L.insert(i,i+rows) = -weight;
L.insert(i+rows,i) = -weight;
}
// Vertical edges
for(int i=0; i<= numel-rows; i+=rows)
{
for(int j=0; j<=rows-2; j++)
{
double weight = abs((*matrix)[i+j] - (*matrix)[i+j+1]) ;
weight = (weight - min_weight) / diff;
weight = exp(-beta*weight) + epsilon; // Compute Gaussian weighting
L.insert(i+j,i+j+1) = -weight;
L.insert(i+j+1,i+j) = -weight;
}
}
}
\ No newline at end of file
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef CONFIDENCE_MAPS_2D_H__
#define CONFIDENCE_MAPS_2D_H__
#include "RandomWalksCore.h"
/** \brief Confidence Map for 2D image
* \author Athanasios Karamalis
* \date 11.06.2012
*
* Implementing ultrasound confidence estimation algorithm as described in
* A. Karamalis, W. Wein, T. Klein, N. Navab
* Ultrasound Confidence Maps using Random Walks
* Medical Image Analysis, 16, 6, 1101 - 1112, 2012, DOI: http://dx.doi.org/10.1016/j.media.2012.07.005 (bib)
*/
class ConfidenceMaps2D : public RandomWalksCore
{
public:
ConfidenceMaps2D();
virtual ~ConfidenceMaps2D();
/// Set data matrix. We assume normalized values. If this is not the case use the flag in the function call.
void setMatrix2D(const std::vector<double> * matrix, int rows, int cols, bool normalizeValues=false);
/// Implement the random walks 2D edge assembly (L is then finalized in RandomWalksCore)
virtual void assembleLaplacianEdges();
/// Set the alpha parameter - penalizing vertical walks with distance
void setAlpha(double alpha){this->alpha = alpha;};
/// Set the beta parameter (default random walks)
void setBeta(double beta){this->beta = beta;};
/// Set the gamma parameter - penalizing horizontal walks
void setGamma(double gamma){this->gamma = gamma;};
private:
double alpha; ///< Vertical walks penalty
double beta; ///< Default walks parameter
double gamma; ///< Horizontal walks penalty
};
#endif
\ No newline at end of file
#include "ConfidenceMaps2DFacade.h"
#include "ConfidenceMaps2D.h"
ConfidenceMaps2DFacade::ConfidenceMaps2DFacade()
{
maps2D = new ConfidenceMaps2D();
}
ConfidenceMaps2DFacade::~ConfidenceMaps2DFacade()
{
if(maps2D!=0)
delete maps2D;
maps2D = 0;
}
std::vector<double> ConfidenceMaps2DFacade::computeMap(double beta, double gamma)
{
maps2D->setBeta(beta);
maps2D->setGamma(gamma);
std::vector<double> map;
map = maps2D->solve();
return map;
}
void ConfidenceMaps2DFacade::setImage(std::vector<double> &image, int rows, int cols, double alpha, bool normalizeValues)
{
maps2D->setAlpha(alpha);
maps2D->setMatrix2D(&image,rows,cols,normalizeValues);
this->seeds.clear();
this->labels.clear();
// Automatic seed generation for confidence maps
seeds.reserve(cols*2);
labels.reserve(cols*2);
// Upper row seeds
for(int i=0;i<cols;i++)
{
seeds.push_back(i