go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkImageGridSampler.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright UMC Utrecht and contributors
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 * http://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 itkImageGridSampler_h
19#define itkImageGridSampler_h
20
21#include "itkImageSamplerBase.h"
23
24namespace itk
25{
26
44template <class TInputImage>
45class ITK_TEMPLATE_EXPORT ImageGridSampler : public ImageSamplerBase<TInputImage>
46{
47public:
49
53 using Pointer = SmartPointer<Self>;
54 using ConstPointer = SmartPointer<const Self>;
55
57 itkNewMacro(Self);
58
61
63 using typename Superclass::DataObjectPointer;
66 using typename Superclass::InputImageType;
67 using typename Superclass::InputImagePointer;
71 using typename Superclass::ImageSampleType;
74
75 // Clang/macos-12/Xcode_14.2 does not like `using typename Superclass::MaskType`, saying "error: 'MaskType' is not a
76 // class, namespace, or enumeration"
78
80 itkStaticConstMacro(InputImageDimension, unsigned int, Superclass::InputImageDimension);
81
84 // using typename Superclass::InputImageSpacingType;
86
88 using SampleGridSpacingType = typename InputImageType::OffsetType;
89 using SampleGridSpacingValueType = typename SampleGridSpacingType::OffsetValueType;
90 using SampleGridSizeType = typename InputImageType::SizeType;
92 using InputImageSizeType = typename InputImageType::SizeType;
93
99 void
101
102 itkGetConstReferenceMacro(SampleGridSpacing, SampleGridSpacingType);
103
120 void
121 SetNumberOfSamples(unsigned long nrofsamples) override;
122
124 bool
126 {
127 return false;
128 }
129
130
132 bool
134 {
135 return false;
136 }
137
138
139protected:
141 ImageGridSampler() = default;
142
144 ~ImageGridSampler() override = default;
145
147 void
148 PrintSelf(std::ostream & os, Indent indent) const override;
149
151 void
152 GenerateData() override;
153
154private:
155 struct WorkUnit
156 {
157 const SampleGridIndexType GridIndex{};
158 const SampleGridSizeType GridSize{};
159
160 // Should point to the first sample for this specific work unit.
161 ImageSampleType * const Samples{};
162
163 // The number of samples retrieved by this work unit. Only used when a mask is specified.
164 size_t NumberOfSamples{};
165 };
166
167 struct UserData
168 {
170
172 const MaskType * const Mask{};
173 const SampleGridSpacingType GridSpacing{};
174 std::vector<WorkUnit> WorkUnits{};
175 };
176
177 template <elastix::MaskCondition VMaskCondition>
178 static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
179 ThreaderCallback(void * arg);
180
182 template <unsigned int VIndex>
183 static unsigned int
185 {
186 if constexpr (VIndex < InputImageDimension)
187 {
188 return gridSize[VIndex];
189 }
190 else
191 {
192 return 1;
193 }
194 }
195
197 template <unsigned int VIndex>
198 static void
200 const SampleGridIndexType & gridIndex,
201 const SampleGridSpacingType & gridSpacing)
202 {
203 static_assert(VIndex > 0);
204
205 if constexpr (VIndex < InputImageDimension)
206 {
207 index[VIndex - 1] = gridIndex[VIndex - 1];
208 index[VIndex] += gridSpacing[VIndex];
209 }
210 }
211
212
214 static std::pair<SampleGridIndexType, SampleGridSizeType>
215 DetermineGridIndexAndSize(const InputImageRegionType & croppedInputImageRegion,
216 const SampleGridSpacingType & gridSpacing);
217
219 static std::vector<WorkUnit>
220 GenerateWorkUnits(const ThreadIdType numberOfWorkUnits,
221 const InputImageRegionType & croppedInputImageRegion,
222 const SampleGridIndexType gridIndex,
223 const SampleGridSpacingType gridSpacing,
224 std::vector<ImageSampleType> & samples);
225
226 static void
227 SingleThreadedGenerateData(const TInputImage & inputImage,
228 const MaskType * const mask,
229 const InputImageRegionType & croppedInputImageRegion,
230 const SampleGridSpacingType & gridSpacing,
231 std::vector<ImageSampleType> & samples);
232 static void
233 MultiThreadedGenerateData(MultiThreaderBase & multiThreader,
234 const ThreadIdType numberOfWorkUnits,
235 const TInputImage & inputImage,
236 const MaskType * const mask,
237 const InputImageRegionType & croppedInputImageRegion,
238 const SampleGridSpacingType & gridSpacing,
239 std::vector<ImageSampleType> & samples);
240
242 template <elastix::MaskCondition VMaskCondition>
243 static void
245
247 SampleGridSpacingType m_SampleGridSpacing{ itk::MakeFilled<SampleGridSpacingType>(1) };
248
250 unsigned long m_RequestedNumberOfSamples{ 0 };
251};
252
253} // end namespace itk
254
255#ifndef ITK_MANUAL_INSTANTIATION
256# include "itkImageGridSampler.hxx"
257#endif
258
259#endif // end #ifndef itkImageGridSampler_h
Samples image voxels on a regular grid.
SmartPointer< const Self > ConstPointer
static void MultiThreadedGenerateData(MultiThreaderBase &multiThreader, const ThreadIdType numberOfWorkUnits, const TInputImage &inputImage, const MaskType *const mask, const InputImageRegionType &croppedInputImageRegion, const SampleGridSpacingType &gridSpacing, std::vector< ImageSampleType > &samples)
typename Superclass::MaskType MaskType
static void GenerateDataForWorkUnit(WorkUnit &, const InputImageType &, const MaskType *, const SampleGridSpacingType &)
itkStaticConstMacro(InputImageDimension, unsigned int, Superclass::InputImageDimension)
~ImageGridSampler() override=default
typename InputImageType::OffsetType SampleGridSpacingType
bool SelectNewSamplesOnUpdate() override
static unsigned int GetGridSizeValue(const SampleGridSizeType &gridSize)
typename InputImageType::SizeType SampleGridSizeType
static std::vector< WorkUnit > GenerateWorkUnits(const ThreadIdType numberOfWorkUnits, const InputImageRegionType &croppedInputImageRegion, const SampleGridIndexType gridIndex, const SampleGridSpacingType gridSpacing, std::vector< ImageSampleType > &samples)
static void SingleThreadedGenerateData(const TInputImage &inputImage, const MaskType *const mask, const InputImageRegionType &croppedInputImageRegion, const SampleGridSpacingType &gridSpacing, std::vector< ImageSampleType > &samples)
static std::pair< SampleGridIndexType, SampleGridSizeType > DetermineGridIndexAndSize(const InputImageRegionType &croppedInputImageRegion, const SampleGridSpacingType &gridSpacing)
bool SelectingNewSamplesOnUpdateSupported() const override
void GenerateData() override
void SetSampleGridSpacing(const SampleGridSpacingType &arg)
ImageGridSampler()=default
void PrintSelf(std::ostream &os, Indent indent) const override
typename InputImageType::IndexType InputImageIndexType
ITK_DISALLOW_COPY_AND_MOVE(ImageGridSampler)
static void JumpToNextGridPosition(SampleGridIndexType &index, const SampleGridIndexType &gridIndex, const SampleGridSpacingType &gridSpacing)
InputImageIndexType SampleGridIndexType
typename InputImageType::SizeType InputImageSizeType
typename InputImageType::RegionType InputImageRegionType
typename SampleGridSpacingType::OffsetValueType SampleGridSpacingValueType
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ThreaderCallback(void *arg)
void SetNumberOfSamples(unsigned long nrofsamples) override
A class that defines an image sample, which is the coordinates of a point and its value.
This class is a base class for any image sampler.
typename InputImageType::ConstPointer InputImageConstPointer
typename InputImageType::PointType InputImagePointType
typename InputImageType::IndexType InputImageIndexType
typename InputImageType::RegionType InputImageRegionType
typename ImageSampleContainerType::Pointer ImageSampleContainerPointer
typename InputImageType::Pointer InputImagePointer
ImageMaskSpatialObject< Self::InputImageDimension > MaskType
typename InputImageType::PixelType InputImagePixelType
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.


Generated on 2024-07-17 for elastix by doxygen 1.11.0 (9b424b03c9833626cd435af22a444888fbbb192d) elastix logo