-
Notifications
You must be signed in to change notification settings - Fork 118
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
kaspermarstal
wants to merge
2
commits into
main
Choose a base branch
from
add-active-registration-model-metrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
2 changes: 2 additions & 0 deletions
2
Components/Metrics/ActiveRegistrationModel/Statismo/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
add_subdirectory(core) | ||
add_subdirectory(ITK) |
7 changes: 7 additions & 0 deletions
7
Components/Metrics/ActiveRegistrationModel/Statismo/ITK/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
116 changes: 116 additions & 0 deletions
116
Components/Metrics/ActiveRegistrationModel/Statismo/ITK/include/itkConditionalModelBuilder.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of |
||
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_ */ |
146 changes: 146 additions & 0 deletions
146
Components/Metrics/ActiveRegistrationModel/Statismo/ITK/include/itkDataManager.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
decltype(F())
, instead ofboost::result_of
?