Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelluethi committed Dec 14, 2017
2 parents fc49565 + d54a2c9 commit 97bdfe0
Show file tree
Hide file tree
Showing 70 changed files with 1,094 additions and 687 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -6,10 +6,10 @@ compiler:
before_install:
- sudo add-apt-repository ppa:zarquon42/precise-backports -y
- sudo apt-get update -qq
- sudo apt-get install -y cmake libboost1.55-dev libboost1.55 libeigen3-dev libhdf5-serial-dev libvtk6-dev libinsighttoolkit4-dev
- sudo apt-get install -y cmake libboost1.55-dev libboost1.55 libeigen3-dev libvtk6-dev libinsighttoolkit4-dev

script:
- mkdir -p build
- cd build
- cmake -DCMAKE_BUILD_TYPE:STRING=Release ../
- cmake -DCMAKE_BUILD_TYPE:STRING=Release -DON_TRAVIS=True ../
- make -j2
32 changes: 22 additions & 10 deletions CMakeLists.txt
Expand Up @@ -57,7 +57,7 @@ set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
set(INSTALL_INCLUDE_DIR include CACHE PATH
"Installation directory for header files")
set(INSTALL_DOC_DIR share/doc/statismo CACHE PATH
set(INSTALL_DOC_DIR share/doc/statismo CACHE PATH
"Installation directory for documentation")

if(WIN32 AND NOT CYGWIN)
Expand Down Expand Up @@ -116,8 +116,6 @@ include_directories( ${Boost_INCLUDE_DIRS} )
link_directories( ${Boost_LIBRARY_DIRS} )
add_definitions( -DBOOST_THREAD_VERSION=3 -DBOOST_FILESYSTEM_VERSION=3 )

find_package( HDF5 COMPONENTS C CXX)
include_directories( ${HDF5_INCLUDE_DIRS} )

if(WIN32)
# On Windows, we can only build static libraries, as the dynamic libraries would be
Expand All @@ -127,22 +125,29 @@ if(WIN32)
set(statismo_LIB_TYPE STATIC)
endif()

foreach( _library ${HDF5_LIBRARIES} )
get_filename_component( _tempDir${_library} ${_library} PATH )
list( APPEND HDF5_LIBRARY_DIR ${_tempDir${_library}} )
endforeach()

option( ITK_SUPPORT "Build ITK Support" ON )

if( ${ITK_SUPPORT} MATCHES "ON" )
find_package( ITK REQUIRED )
find_package( ITK REQUIRED PATHS ${INSTALL_DEPENDENCIES_DIR})
include( ${ITK_USE_FILE} )
endif()

# We rely on the hdf5 libraries that are shipped with ITK, as this will reduce version conflicts.
set(ITK_VERSION ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR})
find_path(ITK_INCLUDE_WITH_HDF5 NAMES itkhdf5/hdf5.h PATHS ${ITK_INCLUDE_DIRS} )
set(ITK_HDF5_DIR ${ITK_INCLUDE_WITH_HDF5}/itkhdf5)
set(HDF5_INCLUDE_DIRS ${ITK_HDF5_DIR} ${ITK_HDF5_DIR}/cpp)
set(HDF5_LIBRARIES ${ITKHDF5_LIBRARIES})


set(HDF5_LIBRARY_DIR ${INSTALL_DEPENDENCIES_DIR}/lib)
include_directories( ${HDF5_INCLUDE_DIRS} )


option( VTK_SUPPORT "Build VTK Support" ON )

if( ${VTK_SUPPORT} MATCHES "ON" )
find_package( VTK REQUIRED )
find_package( VTK REQUIRED PATHS ${INSTALL_DEPENDENCIES_DIR})
include( ${VTK_USE_FILE} )
endif()

Expand All @@ -152,6 +157,13 @@ option( BUILD_EXAMPLES "Build examples" ON )
option( BUILD_WRAPPING "Build Python Wrappers (experimental)" OFF )
mark_as_advanced(BUILD_WRAPPING)

#make sure the executables have access to the dll's created by the superbuild on windows to make them runnable even without installing & adding the isntall path to the cmd PATH
if( NOT INSTALL_DEPENDENCIES_DIR )
set( TESTS_WORKING_DIR "." CACHE INTERNAL "")
else()
set( TEST_WORKING_DIR "${INSTALL_DEPENDENCIES_DIR}/bin" CACHE INTERNAL "")
endif()

add_subdirectory( modules )
add_subdirectory( doc )
# -------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions doc/IJ/pictures/class_diagram.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 4 additions & 6 deletions doc/IJ/statismo_ij.tex
Expand Up @@ -411,10 +411,8 @@ \subsection{Representers} \label{sec:representers}
form. The discretization and normalization step are specific to the
type of object that are modeled. A \code{Representer} class in
\Statismo needs to provide the methods
\code{Representer::DatasetToSample},
\code{Representer::SampleToSampleVector} and
\code{Representer::SampleVectorToSample}. The first method takes care
of the discretization and normalization, the second method is used to
\code{Representer::SampleVectorToSample}. The first method is used to
convert a dataset to its vectorial representation. The last method is
used to convert the vectorial representation back to an object of the
modeled type. Figure~\ref{fig:statismo-flow} illustrates this concept.
Expand Down Expand Up @@ -594,13 +592,13 @@ \subsection{Using statistical models as a prior}
\code{DrawSample} method:
\begin{verbatim}
vtkPolyData* dataset = someAlgorithm();
VectorType coeffs = model->ComputeCoefficientsForDataset(dataset);
VectorType coeffs = model->ComputeCoefficients(dataset);
vtkPolyData* projection = model->DrawSample(coeffs);
\end{verbatim}
Often, an algorithm is regularized by penalizing unlikely solutions. For this purpose, \Statismo
provides a method to compute a (log) probability of a given dataset.
\begin{verbatim}
float logProbability = model->ComputeLogProbabilityForDataset(aDataset);
float logProbability = model->ComputeLogProbability(aDataset);
\end{verbatim}

\subsection{Cross validation}
Expand Down Expand Up @@ -635,7 +633,7 @@ \subsection{Cross validation}
{
vtkPolyData* testSample = (*it)->GetAsNewSample();
vtkPolyData* projection = model->DrawSample(
model->ComputeCoefficientsForDataset(dataset));
model->ComputeCoefficients(dataset));
/// here we could for example compute the approximation error between the
/// projection and the test sample - omitted
Expand Down
1 change: 1 addition & 0 deletions modules/ITK/CMakeLists.txt
Expand Up @@ -6,6 +6,7 @@ if(MSVC11) #i.e. Visual Studio 2012
add_definitions( -D BOOST_NO_0X_HDR_INITIALIZER_LIST )
endif()

include( ${ITK_USE_FILE} )

include_directories( BEFORE
${CMAKE_CURRENT_SOURCE_DIR}/include
Expand Down
35 changes: 17 additions & 18 deletions modules/ITK/cli/statismo-build-deformation-model.cxx
Expand Up @@ -38,6 +38,7 @@
#include <itkImageFileReader.h>
#include <itkPCAModelBuilder.h>
#include <itkStandardImageRepresenter.h>
#include <itkStatismoIO.h>
#include <itkStatisticalModel.h>

#include "utils/statismo-build-models-utils.h"
Expand All @@ -47,6 +48,7 @@ using namespace std;

struct programOptions {
bool bDisplayHelp;
bool bComputeScores;
string strDataListFile;
string strOutputFileName;
float fNoiseVariance;
Expand Down Expand Up @@ -143,26 +145,22 @@ void buildAndSaveDeformationModel(programOptions opt) {

typedef itk::ImageFileReader<ImageType> ImageReaderType;
typedef vector<typename ImageReaderType::Pointer> ImageReaderList;
ImageReaderList images;
images.reserve(fileNames.size());

if (fileNames.size() == 0) {
itkGenericExceptionMacro( << "No Data was loaded and thus the model can't be built.");
}
bool firstPass = true;
for (StringList::const_iterator it = fileNames.begin(); it != fileNames.end(); ++it) {

typename ImageReaderType::Pointer reader = ImageReaderType::New();

reader->SetFileName(it->c_str());
reader->Update();
//itk::PCAModelBuilder is not a Filter in the ITK world, so the pipeline would not get executed if its main method is called. So the pipeline before calling itk::PCAModelBuilder must be executed by the means of calls to Update() (at least for last elements needed by itk::PCAModelBuilder).
images.push_back(reader);
}

if (images.size() == 0) {
itkGenericExceptionMacro( << "No Data was loaded and thus the model can't be built.");
}
typename ImageReaderType::Pointer referenceReader = *images.begin();
representer->SetReference(referenceReader->GetOutput());
dataManager->SetRepresenter(representer);

for (typename ImageReaderList::const_iterator it = images.begin(); it != images.end(); ++it) {
typename ImageReaderType::Pointer reader = *it;
if ( firstPass ) {
representer->SetReference(reader->GetOutput());
dataManager->SetRepresenter(representer);
firstPass = false;
}
dataManager->AddDataset(reader->GetOutput(), reader->GetFileName().c_str());
}

Expand All @@ -171,8 +169,8 @@ void buildAndSaveDeformationModel(programOptions opt) {

typedef itk::PCAModelBuilder<ImageType> ModelBuilderType;
typename ModelBuilderType::Pointer pcaModelBuilder = ModelBuilderType::New();
model = pcaModelBuilder->BuildNewModel(dataManager->GetData(), opt.fNoiseVariance);
model->Save(opt.strOutputFileName.c_str());
model = pcaModelBuilder->BuildNewModel(dataManager->GetData(), opt.fNoiseVariance, opt.bComputeScores);
itk::StatismoIO<ImageType>::SaveStatisticalModel(model, opt.strOutputFileName.c_str());
}

po::options_description initializeProgramOptions(programOptions& poParameters) {
Expand All @@ -185,10 +183,11 @@ po::options_description initializeProgramOptions(programOptions& poParameters) {
po::options_description optAdditional("Optional options");
optAdditional.add_options()
("noise,n", po::value<float>(&poParameters.fNoiseVariance)->default_value(0), "Noise variance of the PPCA model")
("scores,s", po::value<bool>(&poParameters.bComputeScores)->default_value(true), "Compute scores (default true)")
("help,h", po::bool_switch(&poParameters.bDisplayHelp), "Display this help message")
;

po::options_description optAllOptions;
optAllOptions.add(optMandatory).add(optAdditional);
return optAllOptions;
}
}
13 changes: 5 additions & 8 deletions modules/ITK/cli/statismo-build-gp-model.cxx
Expand Up @@ -42,6 +42,7 @@
#include <itkMeshFileReader.h>
#include <itkStandardImageRepresenter.h>
#include <itkStandardMeshRepresenter.h>
#include <itkStatismoIO.h>
#include <itkStatisticalModel.h>

//Add new kernels in this file (and document their usage in the statismo-build-gp-model.md file)
Expand Down Expand Up @@ -204,7 +205,8 @@ void buildAndSaveModel(programOptions opt) {

if(opt.strOptionalModelPath != "") {
try {
pRawStatisticalModel.reset(RawModelType::Load(pRepresenter.GetPointer(), opt.strOptionalModelPath.c_str()));
pRawStatisticalModel.reset(statismo::IO<DataType>::LoadStatisticalModel(pRepresenter.GetPointer(),
opt.strOptionalModelPath.c_str()));
pStatModelKernel.reset(new statismo::StatisticalModelKernel<DataType>(pRawStatisticalModel.get()));
pModelBuildingKernel.reset(new statismo::SumKernel<PointType>(pStatModelKernel.get(), pScaledKernel.get()));
} catch (statismo::StatisticalModelException& s) {
Expand All @@ -218,22 +220,17 @@ void buildAndSaveModel(programOptions opt) {
pReferenceReader->Update();
pRepresenter->SetReference(pReferenceReader->GetOutput());
pMean = pRepresenter->IdentitySample();

}




typedef itk::LowRankGPModelBuilder<DataType> ModelBuilderType;
typename ModelBuilderType::Pointer gpModelBuilder = ModelBuilderType::New();
gpModelBuilder->SetRepresenter(pRepresenter);


typedef itk::StatisticalModel<DataType> StatisticalModelType;
typename StatisticalModelType::Pointer pModel;
pModel = gpModelBuilder->BuildNewModel(pMean, *pModelBuildingKernel.get(), opt.iNrOfBasisFunctions);

pModel->Save(opt.strOutputFileName.c_str());
itk::StatismoIO<DataType>::SaveStatisticalModel(pModel, opt.strOutputFileName.c_str());
}

string getAvailableKernelsStr() {
Expand Down Expand Up @@ -276,4 +273,4 @@ po::options_description initializeProgramOptions(programOptions& poParameters) {
po::options_description optAllOptions;
optAllOptions.add(optMandatory).add(optAdditional);
return optAllOptions;
}
}
5 changes: 3 additions & 2 deletions modules/ITK/cli/statismo-build-shape-model.cxx
Expand Up @@ -44,6 +44,7 @@
#include <itkPCAModelBuilder.h>
#include <itkRigid3DTransform.h>
#include <itkStandardMeshRepresenter.h>
#include <itkStatismoIO.h>
#include <itkStatisticalModel.h>
#include <itkTransformMeshFilter.h>

Expand Down Expand Up @@ -212,7 +213,7 @@ void buildAndSaveShapeModel(programOptions opt) {
typedef itk::PCAModelBuilder<MeshType> PCAModelBuilder;
PCAModelBuilder::Pointer pcaModelBuilder = PCAModelBuilder::New();
model = pcaModelBuilder->BuildNewModel(dataManager->GetData(), opt.fNoiseVariance);
model->Save(opt.strOutputFileName.c_str());
itk::StatismoIO<MeshType>::SaveStatisticalModel(model, opt.strOutputFileName.c_str());
}

po::options_description initializeProgramOptions(programOptions& poParameters) {
Expand All @@ -232,4 +233,4 @@ po::options_description initializeProgramOptions(programOptions& poParameters) {
po::options_description optAllOptions;
optAllOptions.add(optMandatory).add(optAdditional);
return optAllOptions;
}
}
3 changes: 2 additions & 1 deletion modules/ITK/cli/statismo-fit-image.cxx
Expand Up @@ -43,6 +43,7 @@
#include <itkNormalizedCorrelationImageToImageMetric.h>
#include <itkRigid2DTransform.h>
#include <itkStandardImageRepresenter.h>
#include <itkStatismoIO.h>
#include <itkStatisticalModel.h>
#if (ITK_VERSION_MAJOR >= 4 && ITK_VERSION_MINOR >= 6)
#include <itkTransformToDisplacementFieldFilter.h>
Expand Down Expand Up @@ -223,7 +224,7 @@ void fitImage(programOptions opt, ConsoleOutputSilencer* pCOSilencer) {

typedef itk::StatisticalModel<VectorImageType> StatisticalModelType;
typename StatisticalModelType::Pointer pModel = StatisticalModelType::New();
pModel->Load(pRepresenter, opt.strInputModelFileName.c_str());
pModel = itk::StatismoIO<VectorImageType>::LoadStatisticalModel(pRepresenter, opt.strInputModelFileName.c_str());

typedef itk::Transform<double, Dimensions, Dimensions> TransformType;
typename TransformType::Pointer pTransform;
Expand Down
4 changes: 3 additions & 1 deletion modules/ITK/cli/statismo-fit-surface.cxx
Expand Up @@ -44,6 +44,7 @@
#include <itkPointsLocator.h>
#include <itkReducedVarianceModelBuilder.h>
#include <itkStandardMeshRepresenter.h>
#include <itkStatismoIO.h>
#include <itkStatisticalModel.h>
#include <itkStatisticalShapeModelTransform.h>
#include <itkVersorRigid3DTransform.h>
Expand Down Expand Up @@ -224,7 +225,8 @@ void fitMesh(programOptions opt, ConsoleOutputSilencer* pCOSilencer) {
typedef itk::StandardMeshRepresenter<float, Dimensions> RepresenterType;
RepresenterType::Pointer pRepresenter = RepresenterType::New();
StatisticalModelType::Pointer pModel = StatisticalModelType::New();
pModel->Load(pRepresenter.GetPointer(), opt.strInputModelFileName.c_str());
pModel = itk::StatismoIO<DataType>::LoadStatisticalModel(pRepresenter.GetPointer(),
opt.strInputModelFileName.c_str());

StatisticalModelType::Pointer pConstrainedModel;
typedef itk::StatisticalShapeModelTransform<DataType, double, Dimensions> StatisticalModelTransformType;
Expand Down
13 changes: 8 additions & 5 deletions modules/ITK/cli/statismo-posterior.cxx
Expand Up @@ -40,6 +40,7 @@
#include <itkPointsLocator.h>
#include <itkStandardImageRepresenter.h>
#include <itkStandardMeshRepresenter.h>
#include <itkStatismoIO.h>
#include <itkStatisticalModel.h>
#include <itkVersorRigid3DTransform.h>

Expand Down Expand Up @@ -172,7 +173,8 @@ void buildPosteriorShapeModel(programOptions& opt) {
typedef itk::StandardMeshRepresenter<float, Dimensionality3D> RepresenterType;
RepresenterType::Pointer pRepresenter = RepresenterType::New();
StatisticalModelType::Pointer pModel = StatisticalModelType::New();
pModel->Load(pRepresenter.GetPointer(), opt.strInputModelFileName.c_str());
pModel = itk::StatismoIO<DataType>::LoadStatisticalModel(pRepresenter.GetPointer(),
opt.strInputModelFileName.c_str());

StatisticalModelType::Pointer pConstrainedModel;
if (opt.strInputMeshFileName == "") {
Expand All @@ -187,7 +189,7 @@ void buildPosteriorShapeModel(programOptions& opt) {
pConstrainedModel = buildPosteriorShapeModel<DataType, StatisticalModelType>(pModel, pMeshInCorrespondence, opt.dVariance);
}

pConstrainedModel->Save(opt.strOutputModelFileName.c_str());
itk::StatismoIO<DataType>::SaveStatisticalModel(pConstrainedModel, opt.strOutputModelFileName.c_str());
}

template<unsigned Dimensionality>
Expand All @@ -198,12 +200,13 @@ void buildPosteriorDeformationModel(programOptions& opt) {
typedef itk::StandardImageRepresenter<VectorPixelType, Dimensionality> RepresenterType;
typename RepresenterType::Pointer pRepresenter = RepresenterType::New();
typename StatisticalModelType::Pointer pModel = StatisticalModelType::New();
pModel->Load(pRepresenter.GetPointer(), opt.strInputModelFileName.c_str());
pModel = itk::StatismoIO<DataType>::LoadStatisticalModel(pRepresenter.GetPointer(),
opt.strInputModelFileName.c_str());

typename StatisticalModelType::Pointer pConstrainedModel;
pConstrainedModel = buildPosteriorDeformationModel<DataType, StatisticalModelType>(pModel, opt.strInputFixedLandmarksFileName, opt.strInputMovingLandmarksFileName, opt.dVariance);

pConstrainedModel->Save(opt.strOutputModelFileName.c_str());
itk::StatismoIO<DataType>::SaveStatisticalModel(pConstrainedModel, opt.strOutputModelFileName.c_str());
}


Expand Down Expand Up @@ -237,4 +240,4 @@ po::options_description initializeProgramOptions(programOptions& poParameters) {
po::options_description optAllOptions;
optAllOptions.add(optMandatory).add(optMesh).add(optLandmarks).add(optAdditional);
return optAllOptions;
}
}

0 comments on commit 97bdfe0

Please sign in to comment.