Commit 5ecda59b authored by Julien Michel's avatar Julien Michel

ENH: Fresh start on region splitter (work in progress)

parent b96df563
/*=========================================================================
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 __otbImageRegionAdaptativeSplitter_h
#define __otbImageRegionAdaptativeSplitter_h
#include "itkObject.h"
#include "itkRegion.h"
#include "itkImageRegion.h"
#include "itkImageRegionSplitter.h"
#include "itkObjectFactory.h"
#include "itkIndex.h"
#include "itkSize.h"
namespace otb
{
/** \class ImageRegionSquareTileSplitter
* \brief Divide a region into several pieces.
*
*
* \sa ImageRegionMultidimensionalSplitter
*
* \ingroup ITKSystemObjects
* \ingroup DataProcessing
*/
template <unsigned int VImageDimension>
class ITK_EXPORT ImageRegionAdaptativeSplitter : public itk::ImageRegionSplitter<VImageDimension>
{
public:
/** Standard class typedefs. */
typedef ImageRegionAdaptativeSplitter Self;
typedef itk::ImageRegionSplitter<VImageDimension> 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(ImageRegionAdaptativeSplitter, itk::Object);
/** Dimension of the image available at compile time. */
itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
/** Dimension of the image available at run time. */
static unsigned int GetImageDimension()
{
return VImageDimension;
}
/** Index typedef support. An index is used to access pixel values. */
typedef itk::Index<VImageDimension> IndexType;
typedef typename IndexType::IndexValueType IndexValueType;
/** Size typedef support. A size is used to define region bounds. */
typedef itk::Size<VImageDimension> SizeType;
typedef typename SizeType::SizeValueType SizeValueType;
/** Region typedef support. */
typedef itk::ImageRegion<VImageDimension> RegionType;
typedef std::vector<RegionType> StreamVectorType;
itkSetMacro(TileHint,SizeType);
itkGetConstReferenceMacro(TileHint,SizeType);
itkSetMacro(ImageRegion,RegionType);
itkGetConstReferenceMacro(ImageRegion,RegionType);
itkSetMacro(RequestedNumberOfSplits,unsigned int);
itkGetConstReferenceMacro(RequestedNumberOfSplits,unsigned int);
/** How many pieces can the specified region be split? A given region
* cannot always be divided into the requested number of pieces. For
* instance, if the numberOfPieces exceeds the number of pixels along
* a certain dimensions, then some splits will not be possible.
*/
virtual unsigned int GetNumberOfSplits(const RegionType& region,
unsigned int requestedNumber);
/** Get a region definition that represents the ith piece a specified region.
* The "numberOfPieces" specified should be less than or equal to what
* GetNumberOfSplits() returns. */
virtual RegionType GetSplit(unsigned int i, unsigned int numberOfPieces,
const RegionType& region);
virtual void Modified()
{
// Call superclass implementation
Superclass::Modified();
// Invalidate up-to-date
m_IsUpToDate = false;
}
protected:
ImageRegionAdaptativeSplitter() : m_TileHint(),
m_ImageRegion(),
m_RequestedNumberOfSplits(0),
m_StreamVector(),
m_IsUpToDate(false)
{}
virtual ~ImageRegionAdaptativeSplitter() {}
void PrintSelf(std::ostream& os, itk::Indent indent) const;
private:
// Trigger split map estimation
void EstimateSplitMap();
ImageRegionAdaptativeSplitter(const ImageRegionAdaptativeSplitter &); //purposely not implemented
void operator =(const ImageRegionAdaptativeSplitter&); //purposely not implemented
// This reflects the input image tiling
SizeType m_TileHint;
// This contains the ImageRegion that is currently beeing split
RegionType m_ImageRegion;
// This contains the requested number of splits
unsigned int m_RequestedNumberOfSplits;
// This is a vector of all regions which will be split
StreamVectorType m_StreamVector;
// Is the splitter up-to-date ?
bool m_IsUpToDate;
};
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
# include "otbImageRegionAdaptativeSplitter.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 __otbImageRegionAdaptativeSplitter_txx
#define __otbImageRegionAdaptativeSplitter_txx
#include "otbImageRegionAdaptativeSplitter.h"
#include "otbMath.h"
#include "otbMacro.h"
namespace otb
{
template <unsigned int VImageDimension>
unsigned int
ImageRegionAdaptativeSplitter<VImageDimension>
::GetNumberOfSplits(const RegionType& region, unsigned int requestedNumber)
{
// Set parameters
this->SetImageRegion(region);
this->SetRequestedNumberOfSplits(requestedNumber);
// Check if we need to compute split map agagin
if(!m_IsUpToDate)
{
// Do so if we need to
this->EstimateSplitMap();
}
// Return the size of the split map
return m_StreamVector.size();
}
template <unsigned int VImageDimension>
itk::ImageRegion<VImageDimension>
ImageRegionAdaptativeSplitter<VImageDimension>
::GetSplit(unsigned int i, unsigned int itkNotUsed(numberOfPieces), const RegionType& region)
{
// Set parameters
this->SetImageRegion(region);
// Check if we need to compute split map agagin
if(!m_IsUpToDate)
{
// Do so if we need to
this->EstimateSplitMap();
}
// Return the requested split
return m_StreamVector.at(i);
}
template <unsigned int VImageDimension>
void
ImageRegionAdaptativeSplitter<VImageDimension>
::EstimateSplitMap()
{
}
/**
*
*/
template <unsigned int VImageDimension>
void
ImageRegionAdaptativeSplitter<VImageDimension>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
os<<indent<<"IsUpToDate: "<<(m_IsUpToDate ? "true" : "false")<<std::endl;
os<<indent<<"ImageRegion: "<<m_ImageRegion<<std::endl;
os<<indent<<"TileHint: "<<m_TileHint<<std::endl;
os<<indent<<"RequestedNumberOfSpits: "<<m_RequestedNumberOfSplits<<std::endl;
os<<indent<<"StreamVector size: "<<m_StreamVector.size()<<std::endl;
}
} // end namespace itk
#endif
......@@ -1099,7 +1099,9 @@ ADD_TEST(coTvRAMDrivenTiledStreamingManager ${COMMON_TESTS13}
${TEMP}/coTvRAMDrivenTiledStreamingManager.txt
)
ADD_TEST(coTuImageRegionAdaptativeSplitterNew ${COMMON_TESTS13}
otbImageRegionNonUniformMultidimensionalSplitterNew)
# ------- Fichiers sources CXX -----------------------------------
SET(BasicCommon_SRCS1
otbCommonTests1.cxx
......@@ -1263,6 +1265,7 @@ SET(BasicCommon_SRCS13
otbCommonTests13.cxx
otbPipelineMemoryPrintCalculatorTest.cxx
otbStreamingManager.cxx
otbImageRegionAdaptativeSplitter.cxx
)
OTB_ADD_EXECUTABLE(otbCommonTests1 "${BasicCommon_SRCS1}" "OTBIO;OTBTesting")
......
......@@ -31,4 +31,6 @@ void RegisterTests()
REGISTER_TEST(otbRAMDrivenStrippedStreamingManager);
REGISTER_TEST(otbTileDimensionTiledStreamingManager);
REGISTER_TEST(otbRAMDrivenTiledStreamingManager);
REGISTER_TEST(otbImageRegionAdaptativeSplitterNew);
REGISTER_TEST(otbImageRegionAdaptativeSplitter);
}
/*=========================================================================
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.
=========================================================================*/
#include "otbImageRegionAdaptativeSplitter.h"
#include <fstream>
const int Dimension = 2;
typedef otb::ImageRegionAdaptativeSplitter<Dimension> SplitterType;
typedef SplitterType::RegionType RegionType;
typedef RegionType::SizeType SizeType;
typedef RegionType::IndexType IndexType;
int otbImageRegionAdaptativeSplitterNew(int argc, char * argv[])
{
SplitterType::Pointer splitter = SplitterType::New();
std::cout<<splitter<<std::endl;
return EXIT_SUCCESS;
}
int otbImageRegionAdaptativeSplitter(int argc, char * argv[])
{
SizeType regionSize,tileHint;
IndexType regionIndex;
RegionType region;
unsigned int requestedNbSplits;
regionIndex[0] = atoi(argv[1]);
regionIndex[1] = atoi(argv[2]);
regionSize[0] = atoi(argv[3]);
regionSize[1] = atoi(argv[4]);
tileHint[0] = atoi(argv[5]);
tileHint[1] = atoi(argv[6]);
requestedNbSplits = atoi(argv[7]);
std::string outfname = argv[8];
std::ofstream outfile(outfname.c_str());
region.SetSize(regionSize);
region.SetIndex(regionIndex);
SplitterType::Pointer splitter = SplitterType::New();
unsigned int nbSplits = splitter->GetNumberOfSplits(region,requestedNbSplits);
outfile<<splitter<<std::endl;
outfile<<"Split map: "<<std::endl;
for(unsigned int i = 0; i < nbSplits;++i)
{
outfile<<"Split "<<i<<": "<<splitter->GetSplit(i,requestedNbSplits,region);
}
outfile.close();
return EXIT_SUCCESS;
}
Markdown is supported
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