Skip to content
Snippets Groups Projects
Commit e373de8d authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

ENH: Adding ObjectList hierarchy

parent f43e6d49
Branches
Tags
No related merge requests found
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbObjectListSource_h
#define __otbObjectListSource_h
#include "otbObjectList.h"
namespace otb
{
/** \class ObjectListSource
* \brief Base class for all process objects that output ObjectList data.
*
*
* ObjectListSource is the base class for all process objects that output ObjectList data.
* Specifically, this class defines the GetOutput() method that returns a pointer to the
* output ObjectList.
*
*
* \ingroup ObjectListFilter
*/
template <class TOutputList >
class ITK_EXPORT ObjectListSource : public itk::ProcessObject
{
public:
/** Standard class typedefs. */
typedef ObjectListSource Self;
typedef itk::ProcessObject Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(ObjectListSource, InPlaceImageFilter);
/** Some typedefs. */
typedef TOutputList OutputListType;
typedef typename TOutputList::Pointer OutputListPointer;
typedef itk::DataObject::Pointer DataObjectPointer;
virtual DataObjectPointer MakeOutput(unsigned int idx);
void GraftOutput(itk::DataObject *graft);
void GraftNthOutput(unsigned int idx, itk::DataObject *graft);
OutputListType * GetOutput(void);
protected:
ObjectListSource();
virtual ~ObjectListSource() {};
/** ObjectListSource can be implemented as a multithreaded filter.
* Therefore, this implementation provides a ThreadedGenerateData() routine
* which is called for each processing thread. The output image data is
* allocated automatically by the superclass prior to calling
* ThreadedGenerateData(). ThreadedGenerateData can only write to the
* portion of the output image specified by the parameter
* "outputRegionForThread"
*
* \sa ImageToImageFilter::ThreadedGenerateData(),
* ImageToImageFilter::GenerateData() */
void GenerateData(void);
private:
ObjectListSource(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
};
} // end namespace otb
#ifndef ITK_MANUAL_INSTANTIATION
#include "otbObjectListSource.txx"
#endif
#endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbObjectListSource_txx
#define __otbObjectListSource_txx
#include "otbObjectListSource.h"
#include "itkProgressReporter.h"
namespace otb
{
/**
* Constructor
*/
template <class TOutputList>
ObjectListSource<TOutputList>
::ObjectListSource()
{
// Create the output. We use static_cast<> here because we know the default
// output must be of type TOutputImage
typename TOutputList::Pointer output
= static_cast<TOutputList*>(this->MakeOutput(0).GetPointer());
this->ProcessObject::SetNumberOfRequiredOutputs(1);
this->ProcessObject::SetNthOutput(0, output.GetPointer());
}
template<class TOutputList>
typename ObjectListSource<TOutputList>::DataObjectPointer
ObjectListSource<TOutputList>
::MakeOutput(unsigned int)
{
return static_cast<itk::DataObject*>(TOutputList::New().GetPointer());
}
template <class TOutputList>
typename ObjectListSource<TOutputList>::OutputListType *
ObjectListSource<TOutputList>
::GetOutput()
{
if (this->GetNumberOfOutputs() < 1)
{
return 0;
}
return static_cast<TOutputList*>
(this->ProcessObject::GetOutput(0));
}
template<class TOutputList>
void
ObjectListSource<TOutputList>
::GraftOutput(itk::DataObject *graft)
{
this->GraftNthOutput(0, graft);
}
template<class TOutputList>
void
ObjectListSource<TOutputList>
::GraftNthOutput(unsigned int idx, itk::DataObject *graft)
{
if ( idx >= this->GetNumberOfOutputs() )
{
itkExceptionMacro(<<"Requested to graft output " << idx <<
" but this filter only has " << this->GetNumberOfOutputs() << " Outputs.");
}
if ( !graft )
{
itkExceptionMacro(<<"Requested to graft output that is a NULL pointer" );
}
itk::DataObject * output = this->GetOutput(idx);
// Call GraftImage to copy meta-information, regions, and the pixel container
output->Graft( graft );
}
/**
* GenerateData Performs the pixel-wise addition
*/
template <class TOutputList>
void
ObjectListSource<TOutputList>
::GenerateData(void)
{
itkExceptionMacro("subclass should override this method!!!");
}
} // end namespace otb
#endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbObjectListToObjectListFilter_h
#define __otbObjectListToObjectListFilter_h
#include "otbObjectListSource.h"
namespace otb
{
/** \class ObjectListToObjectListFilter
* \brief Base class for filters that take an ObjectList as input and produce an ObjectList as output.
*
* ObjectListToObjectListFilter is the base class for all process objects that output
* ObjectList data and require ObjectList data as input. Specifically, this class
* defines the SetInput() method for defining the input to a filter.
*
*
* \ingroup ObjectListFilter
*/
template <class TInputList, class TOutputList >
class ITK_EXPORT ObjectListToObjectListFilter : public otb::ObjectListSource<TOutputList>
{
public:
/** Standard class typedefs. */
typedef ObjectListToObjectListFilter Self;
typedef otb::ObjectListSource<TOutputList> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(ObjectListToObjectListFilter, InPlaceImageFilter);
/** Some typedefs. */
typedef TInputList InputListType;
typedef TOutputList OutputListType;
typedef typename TInputList::ConstPointer InputListPointer;
typedef typename TOutputList::Pointer OutputListPointer;
typedef typename TInputList::ConstIterator InputListIterator;
typedef itk::DataObject::Pointer DataObjectPointer;
virtual void SetInput( const InputListType *input);
const InputListType * GetInput(void);
protected:
ObjectListToObjectListFilter();
virtual ~ObjectListToObjectListFilter() {};
private:
ObjectListToObjectListFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
};
} // end namespace otb
#ifndef ITK_MANUAL_INSTANTIATION
#include "otbObjectListToObjectListFilter.txx"
#endif
#endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbObjectListToObjectListFilter_txx
#define __otbObjectListToObjectListFilter_txx
#include "otbObjectListToObjectListFilter.h"
#include "itkProgressReporter.h"
namespace otb
{
/**
* Constructor
*/
template <class TInputList, class TOutputList>
ObjectListToObjectListFilter<TInputList,TOutputList>
::ObjectListToObjectListFilter()
{
this->SetNumberOfRequiredInputs( 1 );
}
template <class TInputList, class TOutputList>
void
ObjectListToObjectListFilter<TInputList,TOutputList>
::SetInput(const InputListType *input)
{
// Process object is not const-correct so the const_cast is required here
this->itk::ProcessObject::SetNthInput(0,
const_cast< InputListType * >( input ) );
}
template <class TInputList, class TOutputList>
const typename ObjectListToObjectListFilter<TInputList,TOutputList>::InputListType *
ObjectListToObjectListFilter<TInputList,TOutputList>
::GetInput(void)
{
if (this->GetNumberOfInputs() < 1)
{
return 0;
}
return static_cast<const TInputList * >
(this->itk::ProcessObject::GetInput(0) );
}
} // end namespace otb
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment