1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
|
/*
* Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* 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
*
* 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.
*/
#ifndef otbStreamingShrinkImageFilter_h
#define otbStreamingShrinkImageFilter_h
#include "otbPersistentImageFilter.h"
#include "otbPersistentFilterStreamingDecorator.h"
#include "otbStreamingManager.h"
#include "otbMacro.h"
namespace otb
{
class ITK_EXPORT StreamingShrinkImageRegionSplitter : public itk::ImageRegionSplitter<2>
{
public:
/** Standard class typedefs. */
typedef StreamingShrinkImageRegionSplitter Self;
typedef itk::ImageRegionSplitter<2> 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(StreamingShrinkImageRegionSplitter, itk::Object);
/** Dimension of the image available at compile time. */
itkStaticConstMacro(ImageDimension, unsigned int, 2);
/** Dimension of the image available at run time. */
static unsigned int GetImageDimension()
{
return ImageDimension;
}
/** Index typedef support. An index is used to access pixel values. */
typedef itk::Index<ImageDimension> IndexType;
typedef IndexType::IndexValueType IndexValueType;
/** Size typedef support. A size is used to define region bounds. */
typedef itk::Size<ImageDimension> SizeType;
typedef SizeType::SizeValueType SizeValueType;
/** Region typedef support. */
typedef itk::ImageRegion<ImageDimension> RegionType;
/** 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.
*/
unsigned int GetNumberOfSplits(const RegionType& region,
unsigned int requestedNumber) override;
/** 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. */
RegionType GetSplit(unsigned int i, unsigned int numberOfPieces,
const RegionType& region) override;
itkGetMacro(TileSizeAlignment, unsigned int);
itkGetMacro(TileDimension, unsigned int);
itkSetMacro(ShrinkFactor, unsigned int);
itkGetMacro(ShrinkFactor, unsigned int);
protected:
StreamingShrinkImageRegionSplitter() : m_SplitsPerDimension(0U), m_TileDimension(0), m_TileSizeAlignment(0), m_ShrinkFactor(10) {}
~StreamingShrinkImageRegionSplitter() override {}
void PrintSelf(std::ostream& os, itk::Indent indent) const override;
private:
StreamingShrinkImageRegionSplitter(const StreamingShrinkImageRegionSplitter &); //purposely not implemented
void operator =(const StreamingShrinkImageRegionSplitter&); //purposely not implemented
itk::FixedArray<unsigned int, ImageDimension> m_SplitsPerDimension;
unsigned int m_TileDimension;
unsigned int m_TileSizeAlignment;
unsigned int m_ShrinkFactor;
};
template <class TInputImage>
class ITK_EXPORT StreamingShrinkStreamingManager : public StreamingManager<TInputImage>
{
public:
/** Standard class typedefs. */
typedef StreamingShrinkStreamingManager Self;
typedef StreamingManager<TInputImage> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Runtime information support. */
itkTypeMacro(StreamingShrinkStreamingManager, StreamingManager);
typedef TInputImage ImageType;
typedef typename ImageType::Pointer ImagePointerType;
typedef typename ImageType::RegionType RegionType;
typedef typename RegionType::IndexType IndexType;
typedef typename RegionType::SizeType SizeType;
typedef typename ImageType::InternalPixelType PixelType;
itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
/** Actually computes the stream divisions, according to the specified streaming mode,
* eventually using the input parameter to estimate memory consumption */
void PrepareStreaming(itk::DataObject * input, const RegionType ®ion) override;
void SetShrinkFactor(unsigned int val)
{
m_ShrinkFactor = val;
}
unsigned int GetShrinkFactor() const
{
return m_ShrinkFactor;
}
protected:
StreamingShrinkStreamingManager();
~StreamingShrinkStreamingManager() override;
private:
StreamingShrinkStreamingManager(const StreamingShrinkStreamingManager &); //purposely not implemented
void operator =(const StreamingShrinkStreamingManager&); //purposely not implemented
unsigned int m_ShrinkFactor;
};
/** \class PersistentShrinkImageFilter
* \brief
*
* \sa PersistentImageFilter
* \ingroup Streamed
* \ingroup Multithreaded
*
*
* \ingroup OTBImageManipulation
*/
template<class TInputImage, class TOutputImage = TInputImage>
class ITK_EXPORT PersistentShrinkImageFilter :
public PersistentImageFilter<TInputImage, TOutputImage>
{
public:
/** Standard Self typedef */
typedef PersistentShrinkImageFilter Self;
typedef PersistentImageFilter<TInputImage, TOutputImage> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Runtime information support. */
itkTypeMacro(PersistentShrinkImageFilter, PersistentImageFilter);
/** Image related typedefs. */
typedef TInputImage InputImageType;
typedef typename TInputImage::Pointer InputImagePointer;
typedef typename TInputImage::RegionType RegionType;
typedef typename TInputImage::SizeType SizeType;
typedef typename TInputImage::IndexType IndexType;
typedef typename TInputImage::PixelType PixelType;
/** Image related typedefs. */
typedef TOutputImage OutputImageType;
typedef typename TOutputImage::Pointer OutputImagePointer;
itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
/** Smart Pointer type to a DataObject. */
typedef typename itk::DataObject::Pointer DataObjectPointer;
OutputImageType * GetShrunkOutput()
{
return m_ShrunkOutput;
}
void Synthetize(void) override;
void Reset(void) override;
itkSetMacro(ShrinkFactor, unsigned int);
itkGetMacro(ShrinkFactor, unsigned int);
protected:
PersistentShrinkImageFilter();
~PersistentShrinkImageFilter() override;
void PrintSelf(std::ostream& os, itk::Indent indent) const override;
void BeforeThreadedGenerateData() override;
/** Multi-thread version GenerateData. */
void ThreadedGenerateData(const RegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
void AfterThreadedGenerateData() override;
/** Pass the input through unmodified. Do this by Grafting in the
* AllocateOutputs method.
*/
void AllocateOutputs() override;
void GenerateOutputInformation() override;
private:
PersistentShrinkImageFilter(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
/* the output shrunk image */
OutputImagePointer m_ShrunkOutput;
/** The shrink factor */
unsigned int m_ShrinkFactor;
/** The offset to get the cell center */
IndexType m_Offset;
}; // end of class PersistentStatisticsVectorImageFilter
/** \class StreamingShrinkImageFilter
* \brief Generates a quicklook of the input image
*
* This filter computes a subsampled version of the input image with streaming capabilities
*
* The subsampling ration is set with SetShrinkFactor
*
* \sa PersistentImageFilter
* \ingroup Streamed
* \ingroup Multithreaded
*
*
* \ingroup OTBImageManipulation
*/
template<class TInputImage, class TOutputImage = TInputImage>
class ITK_EXPORT StreamingShrinkImageFilter :
public PersistentFilterStreamingDecorator< PersistentShrinkImageFilter<TInputImage, TOutputImage> >
{
public:
/** Standard Self typedef */
typedef StreamingShrinkImageFilter Self;
typedef PersistentFilterStreamingDecorator
<PersistentShrinkImageFilter<TInputImage, TOutputImage> > Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Type macro */
itkNewMacro(Self);
/** Creation through object factory macro */
itkTypeMacro(StreamingShrinkImageFilter, PersistentFilterStreamingDecorator);
typedef TInputImage InputImageType;
typedef TOutputImage OutputImageType;
typedef typename Superclass::FilterType PersistentFilterType;
typedef StreamingShrinkStreamingManager<InputImageType> StreamingShrinkStreamingManagerType;
typedef typename StreamingShrinkStreamingManagerType::Pointer StreamingShrinkStreamingManagerPointerType;
using Superclass::SetInput;
void SetInput(InputImageType * input)
{
this->GetFilter()->SetInput(input);
}
const InputImageType * GetInput()
{
return this->GetFilter()->GetInput();
}
OutputImageType * GetOutput()
{
return this->GetFilter()->GetShrunkOutput();
}
otbSetObjectMemberMacro(Filter, ShrinkFactor, unsigned int);
otbGetObjectMemberMacro(Filter, ShrinkFactor, unsigned int);
void Update(void) override
{
m_StreamingManager->SetShrinkFactor( this->GetFilter()->GetShrinkFactor() );
Superclass::Update();
}
protected:
/** Constructor */
StreamingShrinkImageFilter()
{
// Use a specific StreamingManager implementation
m_StreamingManager = StreamingShrinkStreamingManagerType::New();
this->GetStreamer()->SetStreamingManager( m_StreamingManager );
}
/** Destructor */
~StreamingShrinkImageFilter() override {}
private:
StreamingShrinkImageFilter(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
StreamingShrinkStreamingManagerPointerType m_StreamingManager;
};
} // End namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbStreamingShrinkImageFilter.txx"
#endif
#endif
|