2.12.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
Browse files

* 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() ...@@ -28,8 +28,8 @@ ENDIF()
# #
# Further Build Configurations # Further Build Configurations
# #
include(cmake/commonconf.cmake) include(cmake/commonconf.cmake)
include(cmake/parseModulesDir.cmake)
MESSAGE(STATUS "--------------------------------------------------------------------------------") MESSAGE(STATUS "--------------------------------------------------------------------------------")
......
IF(NOT CommonconfProcessed) IF(NOT CommonconfProcessed)
SET(CampvisHome ${CMAKE_CURRENT_SOURCE_DIR}) SET(CampvisHome ${CMAKE_CURRENT_SOURCE_DIR})
SET(CampvisBinaryDir ${CMAKE_BINARY_DIR})
MESSAGE(STATUS "TUMVis Source Directory: ${CampvisHome}") MESSAGE(STATUS "TUMVis Source Directory: ${CampvisHome}")
MESSAGE(STATUS "TUMVis Binary Directory: ${CMAKE_BINARY_DIR}") MESSAGE(STATUS "TUMVis Binary Directory: ${CampvisBinaryDir}")
# include macros # include macros
INCLUDE(${CampvisHome}/cmake/macros.cmake) INCLUDE(${CampvisHome}/cmake/macros.cmake)
...@@ -200,69 +201,5 @@ ELSE(OPENCL_FOUND) ...@@ -200,69 +201,5 @@ ELSE(OPENCL_FOUND)
MESSAGE(STATUS "* Did NOT find OpenCL!") MESSAGE(STATUS "* Did NOT find OpenCL!")
ENDIF(OPENCL_FOUND) 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) SET(CommonconfProcessed TRUE)
ENDIF(NOT CommonconfProcessed) 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) ...@@ -18,12 +18,12 @@ FILE(GLOB KISSCL_SOURCES *.cpp)
# define library target # define library target
################################################################################ ################################################################################
ADD_LIBRARY(kisscl ${KISSCL_SOURCES} ${KISSCL_HEADERS}) ADD_LIBRARY(kisscl ${KISSCL_SOURCES} ${KISSCL_HEADERS})
ADD_DEFINITIONS(${CampvisGlobalDefinitions} ${CAMPVIS_MODULE_DEFINITIONS}) ADD_DEFINITIONS(${CampvisGlobalDefinitions})
IF(CAMPVIS_SHARED_LIBS AND MSVC) IF(CAMPVIS_SHARED_LIBS AND MSVC)
ADD_DEFINITIONS("-DKISSCL_BUILD_DLL") ADD_DEFINITIONS("-DKISSCL_BUILD_DLL")
ENDIF() ENDIF()
INCLUDE_DIRECTORIES(${CampvisGlobalIncludeDirs} ${CAMPVIS_MODULE_INCLUDE_DIRECTORIES}) INCLUDE_DIRECTORIES(${CampvisGlobalIncludeDirs})
TARGET_LINK_LIBRARIES(kisscl ${CAMPVIS_EXTERNAL_LIBRARIES}) TARGET_LINK_LIBRARIES(kisscl ${CampvisGlobalExternalLibs})
################################################################################ ################################################################################
# deployment # deployment
......
...@@ -11,7 +11,7 @@ IF(ITK_FOUND) ...@@ -11,7 +11,7 @@ IF(ITK_FOUND)
#SET(ThisModIncludeDirs ${ITK_INCLUDE_DIRS}) #SET(ThisModIncludeDirs ${ITK_INCLUDE_DIRS})
#SET(ThisModExternalLibs ${ITK_LIBRARIES}) #SET(ThisModExternalLibs ${ITK_LIBRARIES})
MESSAGE(STATUS "** Found ITK library") MESSAGE(STATUS " Found ITK library")
ELSE(ITK_FOUND) ELSE(ITK_FOUND)
MESSAGE(FATAL_ERROR "Could not locate ITK.") MESSAGE(FATAL_ERROR "Could not locate ITK.")
ENDIF(ITK_FOUND) 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*rows);
}
// Lower row seeds
for(int i=0;i<cols;i++)
{
seeds.push_back((i*rows)+(rows-1));
}
// UpperLabels
for(int i=0;i<cols;i++)
{
labels.push_back(0);
}
// Lover labels
for(int i=0;i<cols;i++)
{
labels.push_back(1);
}
maps2D->setLabeling(&seeds,&labels,0,2);
}
void ConfidenceMaps2DFacade::setSolver(std::string solver, int iterations, double tolerance)
{
maps2D->setSolver(solver,iterations,tolerance);
}
\ 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_FACADE_H__
#define CONFIDENCE_MAPS_2D_FACADE_H__
#include <vector>
/** \brief Facade for computing 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)
*
* Use the facade to automatically generate the boundary conditions for the confidence estimation problem.
*/
class ConfidenceMaps2D;
class ConfidenceMaps2DFacade
{
public:
ConfidenceMaps2DFacade();
virtual ~ConfidenceMaps2DFacade();
/// Compute map for image
std::vector<double> computeMap(double beta = 100, double gamma = 0.06);
/// Set external image 2D as vector with column-major ordering
void setImage(std::vector<double> &image, int rows, int cols, double alpha=2.0, bool normalizeValues=false );
/// Set desired solver (default Eigen LLT)
void setSolver(std::string solver, int iterations = 2000, double tolerance = 1.0e-7);
private:
ConfidenceMaps2D * maps2D; ///< Implementation of confidence estimation
std::vector<int> seeds; ///< Seeds/boundary conditions
std::vector<int> labels; ///< Labels for seeds
};
#endif
\ No newline at end of file
MOZILLA PUBLIC LICENSE
VERSION 2.0
1. DEFINITIONS
1.1. “Contributor”
means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software.
1.2. “Contributor Version”
means the combination of the Contributions of others (if any) used by a Contributor and that particular Contributor’s Contribution.
1.3. “Contribution”
means Covered Software of a particular Contributor.
1.4. “Covered Software”
means Source Code Form to which the initial Contributor has attached the notice in Exhibit A, the Executable Form of such Source Code Form, and Modifications of such Source Code Form, in each case including portions thereof.
1.5. “Incompatible With Secondary Licenses”
means
a. that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or
b. that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License.
1.6. “Executable Form”