ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkRLEImage.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkRLEImage_h
19#define itkRLEImage_h
20
21#include <itkImage.h>
22#include <itkImageBase.h>
23#include <utility> // std::pair
24#include <vector>
25
26namespace itk
27{
51template <typename TPixel, unsigned int VImageDimension = 3, typename CounterType = unsigned short>
52class RLEImage : public itk::ImageBase<VImageDimension>
53{
54public:
55 ITK_DISALLOW_COPY_AND_MOVE(RLEImage);
56
58 using Self = RLEImage;
63
65 itkNewMacro(Self);
66
68 itkOverrideGetNameOfClassMacro(RLEImage);
69
72 using PixelType = TPixel;
73
74 using RLCounterType = CounterType;
75
77 using ValueType = TPixel;
78
81 using RLSegment = std::pair<CounterType, PixelType>;
82
84 using RLLine = std::vector<RLSegment>;
85
91
92 // using IOPixelType = PixelType;
93
98 static constexpr unsigned int ImageDimension = VImageDimension;
99
103
106
110
113
117
122
126
129
133 void
134 Allocate(bool initialize = false) override;
135
138 void
139 Initialize() override
140 {
141 // Call the superclass which should initialize the BufferedRegion ivar.
143 m_OnTheFlyCleanup = true;
144 m_Buffer = BufferType::New();
145 }
146
149 void
150 FillBuffer(const TPixel & value);
151
152 void
153 SetLargestPossibleRegion(const RegionType & region) override
154 {
156 m_Buffer->SetLargestPossibleRegion(region.Slice(0));
157 }
158
159 void
160 SetBufferedRegion(const RegionType & region) override
161 {
163 m_Buffer->SetBufferedRegion(region.Slice(0));
164 }
165
166 using ImageBase<VImageDimension>::SetRequestedRegion;
167
168 void
169 SetRequestedRegion(const RegionType & region) override
170 {
172 m_Buffer->SetRequestedRegion(region.Slice(0));
173 }
174
180 void
181 SetPixel(const IndexType & index, const TPixel & value);
182
187 int
188 SetPixel(RLLine & line, IndexValueType & segmentRemainder, SizeValueType & m_RealIndex, const TPixel & value);
189
191 const TPixel &
192 GetPixel(const IndexType & index) const;
193
195 // TPixel & GetPixel(const IndexType & index);
196
198 // TPixel & operator[](const IndexType & index)
199 // {
200 // return this->GetPixel(index);
201 // }
202
205 const TPixel &
206 operator[](const IndexType & index) const
207 {
208 return this->GetPixel(index);
209 }
210
211 unsigned int
213 {
214 // use the GetLength() method which works with variable length arrays,
215 // to make it work with as much pixel types as possible
217 }
218
220 using BufferType = typename itk::Image<RLLine, VImageDimension - 1>;
221
223 typename BufferType::Pointer
225 {
226 return m_Buffer;
227 }
228
230 typename BufferType::ConstPointer
231 GetBuffer() const
232 {
233 return m_Buffer;
234 }
235
237 static inline typename BufferType::IndexType
238 truncateIndex(const IndexType & index);
239
242 void
243 CleanUp() const;
244
247 bool
249 {
250 return m_OnTheFlyCleanup;
251 }
252
255 void
257 {
258 if (value == m_OnTheFlyCleanup)
259 {
260 return;
261 }
262 m_OnTheFlyCleanup = value;
264 {
265 CleanUp(); // put the image into a clean state
266 }
267 }
268
269protected:
271 : itk::ImageBase<VImageDimension>()
272
273 {
274 m_Buffer = BufferType::New();
275 }
276
277 void
278 PrintSelf(std::ostream & os, itk::Indent indent) const override;
279
280 ~RLEImage() override = default;
286 void
291
293 void
294 CleanUpLine(RLLine & line) const;
295
296private:
297 bool m_OnTheFlyCleanup{ true }; // should same-valued segments be merged on the fly
298
300 mutable typename BufferType::Pointer m_Buffer;
301};
302} // namespace itk
303
304#ifndef ITK_MANUAL_INSTANTIATION
305# include "itkRLEImage.hxx"
306#endif
307
308#endif // itkRLEImage_h
Base class for templated image classes.
Vector< SpacingValueType, VImageDimension > SpacingType
virtual void SetRequestedRegion(const RegionType &region)
ImageRegion< VImageDimension > RegionType
SpacePrecisionType SpacingValueType
virtual void SetBufferedRegion(const RegionType &region)
Index< VImageDimension > IndexType
Offset< VImageDimension > OffsetType
typename OffsetType::OffsetValueType OffsetValueType
typename IndexType::IndexValueType IndexValueType
virtual void ComputeIndexToPhysicalPointMatrices()
Matrix< SpacePrecisionType, VImageDimension, VImageDimension > DirectionType
Size< VImageDimension > SizeType
Point< PointValueType, VImageDimension > PointType
virtual void SetLargestPossibleRegion(const RegionType &region)
typename SizeType::SizeValueType SizeValueType
Templated n-dimensional image class.
Definition itkImage.h:89
Control indentation during Print() invocation.
Definition itkIndent.h:53
static constexpr unsigned int GetLength()
void Allocate(bool initialize=false) override
std::vector< RLSegment > RLLine
Definition itkRLEImage.h:84
int SetPixel(RLLine &line, IndexValueType &segmentRemainder, SizeValueType &m_RealIndex, const TPixel &value)
typename itk::Image< RLLine, VImageDimension - 1 > BufferType
RLEImage Self
Definition itkRLEImage.h:58
BufferType::Pointer GetBuffer()
void SetPixel(const IndexType &index, const TPixel &value)
Set a pixel value.
typename Superclass::SizeType SizeType
typename Superclass::DirectionType DirectionType
CounterType RLCounterType
Definition itkRLEImage.h:74
typename Superclass::PointType PointType
void SetRequestedRegion(const RegionType &region) override
void PrintSelf(std::ostream &os, itk::Indent indent) const override
const TPixel & GetPixel(const IndexType &index) const
Get a pixel. SLOW! Better use iterators for pixel access.
void ComputeIndexToPhysicalPointMatrices() override
TPixel PixelType
Definition itkRLEImage.h:72
typename Superclass::OffsetType OffsetType
typename Superclass::RegionType RegionType
typename Superclass::SizeValueType SizeValueType
itk::SmartPointer< Self > Pointer
Definition itkRLEImage.h:60
itk::WeakPointer< const Self > ConstWeakPointer
Definition itkRLEImage.h:62
~RLEImage() override=default
unsigned int GetNumberOfComponentsPerPixel() const override
void SetLargestPossibleRegion(const RegionType &region) override
void CleanUp() const
itk::ImageBase< VImageDimension > Superclass
Definition itkRLEImage.h:59
BufferType::ConstPointer GetBuffer() const
void CleanUpLine(RLLine &line) const
TPixel ValueType
Definition itkRLEImage.h:77
typename Superclass::OffsetValueType OffsetValueType
void Initialize() override
static BufferType::IndexType truncateIndex(const IndexType &index)
itk::SmartPointer< const Self > ConstPointer
Definition itkRLEImage.h:61
void FillBuffer(const TPixel &value)
const TPixel & operator[](const IndexType &index) const
Access a pixel. Chaning it changes the whole RLE segment! *‍/ TPixel & operator[](const IndexType & i...
RLLine InternalPixelType
Definition itkRLEImage.h:90
typename Superclass::IndexType IndexType
typename Superclass::SpacingValueType SpacingValueType
typename Superclass::IndexValueType IndexValueType
typename Superclass::SpacingType SpacingType
bool GetOnTheFlyCleanup() const
void SetOnTheFlyCleanup(bool value)
void SetBufferedRegion(const RegionType &region) override
std::pair< CounterType, PixelType > RLSegment
Definition itkRLEImage.h:81
Implements transparent reference counting.
Implements a weak reference to an object.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....