Commit 1ce87383 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: switched to unique_ptr<Blueprint>

parent 77786d9d
......@@ -42,8 +42,8 @@ class ElastixComponentTest : public ::testing::Test
{
public:
typedef std::shared_ptr< Blueprint > BlueprintPointer;
typedef itk::SharedPointerDataObjectDecorator< Blueprint > BlueprintITKType;
typedef std::unique_ptr< Blueprint > BlueprintPointer;
typedef itk::UniquePointerDataObjectDecorator< Blueprint > BlueprintITKType;
typedef BlueprintITKType::Pointer BlueprintITKPointer;
typedef Blueprint::ParameterMapType ParameterMapType;
typedef Blueprint::ParameterValueType ParameterValueType;
......@@ -82,7 +82,6 @@ public:
superElastixFilter = nullptr;
}
// Blueprint holds a configuration for SuperElastix
BlueprintPointer blueprint;
SuperElastixFilterCustomComponents<RegisterComponents>::Pointer superElastixFilter;
// Data manager provides the paths to the input and output data for unit tests
DataManagerType::Pointer dataManager;
......@@ -91,7 +90,7 @@ public:
TEST_F( ElastixComponentTest, ImagesOnly )
{
/** make example blueprint configuration */
blueprint = BlueprintPointer( new Blueprint() );
BlueprintPointer blueprint = BlueprintPointer(new Blueprint());
ParameterMapType component0Parameters;
component0Parameters[ "NameOfClass" ] = { "ElastixComponent" };
......@@ -163,7 +162,7 @@ TEST_F( ElastixComponentTest, ImagesOnly )
TEST_F(ElastixComponentTest, MonolithicElastixTransformix)
{
/** make example blueprint configuration */
blueprint = BlueprintPointer(new Blueprint());
BlueprintPointer blueprint = BlueprintPointer(new Blueprint());
blueprint->SetComponent("RegistrationMethod", { { "NameOfClass", { "MonolithicElastixComponent" } },
{ "RegistrationSettings", { "rigid" } }, { "MaximumNumberOfIterations", { "2" } },
......
......@@ -33,8 +33,8 @@ class NiftyregComponentTest : public ::testing::Test
{
public:
typedef std::shared_ptr< Blueprint > BlueprintPointer;
typedef itk::SharedPointerDataObjectDecorator< Blueprint > BlueprintITKType;
typedef std::unique_ptr< Blueprint > BlueprintPointer;
typedef itk::UniquePointerDataObjectDecorator< Blueprint > BlueprintITKType;
typedef BlueprintITKType::Pointer BlueprintITKPointer;
typedef Blueprint::ParameterMapType ParameterMapType;
typedef Blueprint::ParameterValueType ParameterValueType;
......
......@@ -103,8 +103,8 @@ public:
ItkCompositeTransformComponent<double, 3>,
ItkCompositeTransformComponent<double, 2 >> RegisterComponents;
typedef std::shared_ptr< Blueprint > BlueprintPointer;
typedef itk::SharedPointerDataObjectDecorator< Blueprint > BlueprintITKType;
typedef std::unique_ptr< Blueprint > BlueprintPointer;
typedef itk::UniquePointerDataObjectDecorator< Blueprint > BlueprintITKType;
typedef BlueprintITKType::Pointer BlueprintITKPointer;
typedef SuperElastixFilter::BlueprintType SuperElastixFilterBlueprintType;
......
......@@ -62,7 +62,7 @@ public:
NetworkBuilder();
virtual ~NetworkBuilder() {};
virtual bool AddBlueprint(const std::shared_ptr<Blueprint> &blueprint);
virtual bool AddBlueprint(const std::unique_ptr<Blueprint> &blueprint);
/** Read configuration at the blueprints nodes and edges and return true if all components could be uniquely selected*/
virtual bool Configure();
......@@ -110,7 +110,7 @@ protected:
//NetworkBuilder should be constructed with a blueprint.
//Blueprint::ConstPointer m_Blueprint;
//Blueprint const * m_Blueprint;
std::shared_ptr< Blueprint > m_Blueprint;
std::unique_ptr< Blueprint > m_Blueprint;
// A selector for each node, that each can hold multiple instantiated components. Ultimately is should be 1 component each.
ComponentSelectorContainerType m_ComponentSelectorContainer;
......
......@@ -31,9 +31,10 @@ NetworkBuilder<ComponentList>::NetworkBuilder() : m_isConfigured(false)
template< typename ComponentList >
bool
NetworkBuilder<ComponentList>::AddBlueprint(const std::shared_ptr<Blueprint> &blueprint)
NetworkBuilder<ComponentList>::AddBlueprint(const std::unique_ptr<Blueprint> &blueprint)
{
m_Blueprint = std::make_shared< Blueprint >(*blueprint);
m_Blueprint->ComposeWith(blueprint);
//m_Blueprint = std::make_shared< Blueprint >(*blueprint);
return true;
}
......
......@@ -64,7 +64,7 @@ public:
virtual ~NetworkBuilderBase() {};
virtual bool AddBlueprint(const std::shared_ptr<Blueprint> &blueprint) = 0;
virtual bool AddBlueprint(const std::unique_ptr<Blueprint> &blueprint) = 0;
/** Read configuration at the blueprints nodes and edges and return true if all components could be uniquely selected*/
virtual bool Configure() = 0;
......
......@@ -38,7 +38,7 @@ class NetworkBuilderTest : public ::testing::Test
public:
typedef std::unique_ptr< NetworkBuilderBase > NetworkBuilderPointer;
typedef std::shared_ptr< Blueprint > BlueprintPointer;
typedef std::unique_ptr< Blueprint > BlueprintPointer;
typedef Blueprint::ParameterMapType ParameterMapType;
typedef Blueprint::ParameterValueType ParameterValueType;
......
/*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
/*=========================================================================
*
* Portions of this file are subject to the VTK Toolkit Version 3 copyright.
*
* Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
*
* For complete copyright, license and disclaimer of warranty information
* please refer to the NOTICE file at the top of the ITK source tree.
*
*=========================================================================*/
#ifndef selxUniquePointerDataObjectDecorator_h
#define selxUniquePointerDataObjectDecorator_h
#include <memory>
#include "itkDataObject.h"
#include "itkObjectFactory.h"
namespace itk
{
/** \class UniquePointerDataObjectDecorator
* \brief Decorates any std::unique_ptr to a simple object with a DataObject API.
*
* UniquePointerDataObjectDecorator decorates a std::unique_ptr to an object
* with a DataObject API. This allows a pointer to an object to be
* encapsulated in a DataObject and passed through the pipeline. This
* object differs from SimpleDataObjectDecorator in that the decorator
* takes control of deleting the pointer upon destruction.
*
* The decorator provides two methods Set() and Get() to access the
* decorated object (referred internally as the component).
* Using Set() will std::move the unique_ptr argument to the
* UniquePointerDataObjectDecorator component and invalidates the unique_ptr
* argument at the caller.
* Using Get() will std::move the UniquePointerDataObjectDecorator component
* and invalidates internal unique_ptr component.
*
* Note that when an instance of UniquePointerDataObjectDecorator is created,
* the component is initialized with its default constructor (i.e. a
* null pointer).
*
* \sa AutoPointerDataObjectDecorator
* \sa SimpleDataObjectDecorator
* \sa DataObjectDecorator
* \ingroup ITKSystemObjects
*
* \ingroup ITKCommon
*/
template< typename T >
class UniquePointerDataObjectDecorator:public DataObject
{
public:
/** Standard typedefs. */
typedef UniquePointerDataObjectDecorator Self;
typedef DataObject Superclass;
typedef SmartPointer< Self > Pointer;
typedef SmartPointer< const Self > ConstPointer;
/** Typedef for the component type (object being decorated) */
typedef T ComponentType;
typedef std::unique_ptr< T > ComponentPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(UniquePointerDataObjectDecorator, DataObject);
/** Set the contained object */
virtual void Set(std::unique_ptr< T > & val);
/** Get the contained object */
virtual std::unique_ptr< T > Get() { return std::move(m_Component); }
// Get() const cannot exist, since getting a unique_ptr to the component invalides the m_Component and alters the Decorator.
//virtual const std::unique_ptr< T > Get() const { return std::move(m_Component); }
protected:
UniquePointerDataObjectDecorator();
~UniquePointerDataObjectDecorator();
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
protected:
private:
// ITK_DISALLOW_COPY_AND_ASSIGN(UniquePointerDataObjectDecorator);
ComponentPointer m_Component;
};
} // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
#include "itkUniquePointerDataObjectDecorator.hxx"
#endif
#endif
\ No newline at end of file
/*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
/*=========================================================================
*
* Portions of this file are subject to the VTK Toolkit Version 3 copyright.
*
* Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
*
* For complete copyright, license and disclaimer of warranty information
* please refer to the NOTICE file at the top of the ITK source tree.
*
*=========================================================================*/
#ifndef selxUniquePointerDataObjectDecorator_hxx
#define selxUniquePointerDataObjectDecorator_hxx
#include "itkUniquePointerDataObjectDecorator.h"
namespace itk
{
/** Constructor */
template< typename T >
UniquePointerDataObjectDecorator< T >
::UniquePointerDataObjectDecorator():m_Component()
{}
/** Destructor */
template< typename T >
UniquePointerDataObjectDecorator< T >
::~UniquePointerDataObjectDecorator()
{}
/** Set value */
template< typename T >
void
UniquePointerDataObjectDecorator< T >
::Set(std::unique_ptr< T > & val)
{
if ( m_Component != val )
{
m_Component = std::move(val);
this->Modified();
}
}
/** PrintSelf method */
template< typename T >
void
UniquePointerDataObjectDecorator< T >
::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "Component: " << typeid( m_Component ).name() << std::endl;
}
} // end namespace itk
#endif
\ No newline at end of file
......@@ -25,7 +25,8 @@
#include "selxAnyFileReader.h"
#include "selxAnyFileWriter.h"
#include "itkSharedPointerDataObjectDecorator.h"
//#include "itkSharedPointerDataObjectDecorator.h"
#include "itkUniquePointerDataObjectDecorator.h"
/**
* \class SuperElastixFilter
......@@ -58,7 +59,7 @@ public:
typedef AnyFileReader AnyFileReaderType;
typedef AnyFileWriter AnyFileWriterType;
typedef itk::SharedPointerDataObjectDecorator< Blueprint > BlueprintType;
typedef itk::UniquePointerDataObjectDecorator< Blueprint > BlueprintType;
typedef BlueprintType::Pointer BlueprintPointer;
typedef BlueprintType::ConstPointer BlueprintConstPointer;
......
......@@ -19,7 +19,7 @@
#include "selxSuperElastixFilterCustomComponents.h"
#include "itkSharedPointerDataObjectDecorator.h"
#include "itkUniquePointerDataObjectDecorator.h"
#include "selxItkSmoothingRecursiveGaussianImageFilterComponent.h"
#include "selxItkImageSink.h"
......@@ -69,7 +69,7 @@ public:
using RegisterComponents = list_append<CustomComponents,DefaultComponents >::type;
typedef std::shared_ptr< Blueprint > BlueprintPointer;
typedef std::unique_ptr< Blueprint > BlueprintPointer;
typedef SuperElastixFilter::BlueprintType SuperElastixFilterBlueprintType;
typedef SuperElastixFilter::BlueprintPointer SuperElastixFilterBlueprintPointer;
......
......@@ -46,10 +46,10 @@ namespace selx
class itkImageFilterTest : public ::testing::Test
{
public:
using BlueprintITKType = itk::SharedPointerDataObjectDecorator< Blueprint >;
using BlueprintITKType = itk::UniquePointerDataObjectDecorator< Blueprint >;
typedef BlueprintITKType::Pointer BlueprintITKPointer;
typedef std::shared_ptr< Blueprint > BlueprintPointer;
typedef std::unique_ptr< Blueprint > BlueprintPointer;
typedef Blueprint::ParameterMapType ParameterMapType;
typedef Blueprint::ParameterValueType ParameterValueType;
typedef DataManager DataManagerType;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment