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

ENH: Add Active Registration Model metrics #450

Open
wants to merge 2 commits into
base: main
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
29 changes: 29 additions & 0 deletions Components/Metrics/ActiveRegistrationModel/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ADD_ELXCOMPONENT(ActiveRegistrationModelShapeMetric OFF
elxActiveRegistrationModelShapeMetric.cxx
elxActiveRegistrationModelShapeMetric.h
elxActiveRegistrationModelShapeMetric.hxx
itkActiveRegistrationModelShapeMetric.h
itkActiveRegistrationModelShapeMetric.hxx
)

ADD_ELXCOMPONENT(ActiveRegistrationModelIntensityMetric OFF
elxActiveRegistrationModelIntensityMetric.h
elxActiveRegistrationModelIntensityMetric.hxx
elxActiveRegistrationModelIntensityMetric.cxx
itkActiveRegistrationModelIntensityMetric.h
itkActiveRegistrationModelIntensityMetric.hxx
)

# Eigen3, statismo and hdf5 include directories and Eigen3 and hdf5 libraries are transitively included via
# the statismo_core target
if(${USE_ActiveRegistrationModelShapeMetric} OR ${USE_ActiveRegistrationModelIntensityMetric})
add_subdirectory(Statismo)
endif()

if(${USE_ActiveRegistrationModelShapeMetric})
target_link_libraries(ActiveRegistrationModelShapeMetric statismo_core ${Boost_LIBRARIES} ITKInternalEigen3::Eigen)
endif()

if(${USE_ActiveRegistrationModelIntensityMetric})
target_link_libraries(ActiveRegistrationModelIntensityMetric statismo_core ${Boost_LIBRARIES} ITKInternalEigen3::Eigen)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(core)
add_subdirectory(ITK)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if(MSVC11) #i.e. Visual Studio 2012
# Fix for VS2012 that has _VARIADIC_MAX set to 5. Don't set too high because it increases compiler memory usage / compile-time.
add_definitions(-D_VARIADIC_MAX=10 )
# Fix for another VS2012 problem: not all TR1 options are automatically detected, therefore we force them here.
add_definitions(-D BOOST_HAS_TR1)
add_definitions(-D BOOST_NO_0X_HDR_INITIALIZER_LIST)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* This file is part of the statismo library.
*
* Author: Marcel Luethi ([email protected])
*
* Copyright (c) 2011 University of Basel
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 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.
*
* Neither the name of the project's author nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* 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 ITKMODELBUILDER_H_
#define ITKMODELBUILDER_H_

#include <itkObject.h>
#include <itkObjectFactory.h>

#include "itkDataManager.h"
#include "itkStatisticalModel.h"
#include "ConditionalModelBuilder.h"
#include "statismoITKConfig.h"

namespace itk {

/**
* \brief ITK Wrapper for the statismo::PCAModelBuilder class.
* \see statismo::PCAModelBuilder for detailed documentation.
*/
template <class Representer>
class ConditionalModelBuilder : public Object {
public:

typedef ConditionalModelBuilder Self;
typedef Object Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;

itkNewMacro( Self );
itkTypeMacro( ConditionalModelBuilder, Object );


typedef statismo::ConditionalModelBuilder<Representer> ImplType;
typedef statismo::DataManager<Representer> DataManagerType;
typedef typename DataManagerType::SampleDataStructureListType SampleDataStructureListType;

ConditionalModelBuilder() : m_impl(ImplType::Create()) {}

virtual ~ConditionalModelBuilder() {
if (m_impl) {
delete m_impl;
m_impl = 0;
}
}

template <class F>
typename boost::result_of<F()>::type callstatismoImpl(F f) const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe decltype(F()), instead of boost::result_of?

try {
return f();
} catch (statismo::StatisticalModelException& s) {
itkExceptionMacro(<< s.what());
}
}


typename StatisticalModel<Representer>::Pointer
BuildNewModel(SampleDataStructureListType SampleDataStructureList,
const typename statismo::ConditionalModelBuilder<Representer>::SurrogateTypeVectorType& surrogateTypes,
const typename statismo::ConditionalModelBuilder<Representer>::CondVariableValueVectorType& conditioningInfo,
float noiseVariance,
double modelVarianceRetained
) {
statismo::StatisticalModel<Representer>* model_statismo = callstatismoImpl(boost::bind(&ImplType::BuildNewModel, this->m_impl, SampleDataStructureList, surrogateTypes, conditioningInfo, noiseVariance, modelVarianceRetained));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of boost::bind, maybe use std::bind...?

typename StatisticalModel<Representer>::Pointer model_itk = StatisticalModel<Representer>::New();
model_itk->SetstatismoImplObj(model_statismo);
return model_itk;
}


private:
ConditionalModelBuilder(const ConditionalModelBuilder& orig);
ConditionalModelBuilder& operator=(const ConditionalModelBuilder& rhs);

ImplType* m_impl;
};


}

#endif /* ITKMODELBUILDER_H_ */
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* This file is part of the statismo library.
*
* Author: Marcel Luethi ([email protected])
*
* Copyright (c) 2011 University of Basel
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 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.
*
* Neither the name of the project's author nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* 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 ITK_DATAMANAGER_H_
#define ITK_DATAMANAGER_H_

#include <boost/bind.hpp>
#include <boost/utility/result_of.hpp>

#include <itkObject.h>
#include <itkObjectFactory.h>

#include "DataManager.h"
#include "statismoITKConfig.h"

namespace itk {


/**
* \brief ITK Wrapper for the statismo::DataManager class.
* \see statismo::DataManager for detailed documentation.
*/
template <class T>
class DataManager : public Object {
public:


typedef DataManager Self;
typedef Object Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;

itkNewMacro( Self );
itkTypeMacro( DataManager, Object );


typedef statismo::DataManager<T> ImplType;
typedef typename statismo::DataManager<T>::DataItemType DataItemType;
typedef typename statismo::DataManager<T>::DataItemListType DataItemListType;
typedef statismo::Representer<T> RepresenterType;

template <class F>
typename boost::result_of<F()>::type callstatismoImpl(F f) const {
if (m_impl == 0) {
itkExceptionMacro(<< "Model not properly initialized. Maybe you forgot to call SetRepresenter");
}
try {
return f();
} catch (statismo::StatisticalModelException& s) {
itkExceptionMacro(<< s.what());
}
}


DataManager() : m_impl(0) {}

virtual ~DataManager() {
if (m_impl) {
delete m_impl;
m_impl = 0;
}
}

ImplType* GetstatismoImplObj() const {
return m_impl;
}


void SetstatismoImplObj(ImplType* impl) {
if (m_impl) {
delete m_impl;
}
m_impl = impl;
}

void SetRepresenter(const RepresenterType* representer) {
SetstatismoImplObj(ImplType::Create(representer));
}

void AddDataset(typename RepresenterType::DatasetType* ds, const char* filename) {
callstatismoImpl(boost::bind(&ImplType::AddDataset, this->m_impl, ds, filename));
}

void Load(const char* filename) {
try {
SetstatismoImplObj(ImplType::Load(filename));
} catch (statismo::StatisticalModelException& s) {
itkExceptionMacro(<< s.what());
}
}

void Save(const char* filename) {
callstatismoImpl(boost::bind(&ImplType::Save, this->m_impl, filename));
}

typename statismo::DataManager<T>::DataItemListType GetData() const {
return callstatismoImpl(boost::bind(&ImplType::GetData, this->m_impl));
}


private:
DataManager(const DataManager& orig);
DataManager& operator=(const DataManager& rhs);

ImplType* m_impl;
};


}

#endif /* ITK_DATAMANAGER_H_ */
Loading