go home Home | Main Page | Topics | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
Loading...
Searching...
No Matches
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
43
44template <typename 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 {
159
160 // Should point to the first sample for this specific work unit.
162
163 // The number of samples retrieved by this work unit. Only used when a mask is specified.
165 };
166
167 struct UserData
168 {
170 const MaskType * const Mask{};
172 std::vector<WorkUnit> WorkUnits{};
173 };
174
175 template <elastix::MaskCondition VMaskCondition>
176 static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
177 ThreaderCallback(void * arg);
178
180 template <unsigned int VIndex>
181 static unsigned int
183 {
184 if constexpr (VIndex < InputImageDimension)
185 {
186 return gridSize[VIndex];
187 }
188 else
189 {
190 return 1;
191 }
192 }
193
195 template <unsigned int VIndex>
196 static void
198 const SampleGridIndexType & gridIndex,
199 const SampleGridSpacingType & gridSpacing)
200 {
201 static_assert(VIndex > 0);
202
203 if constexpr (VIndex < InputImageDimension)
204 {
205 index[VIndex - 1] = gridIndex[VIndex - 1];
206 index[VIndex] += gridSpacing[VIndex];
207 }
208 }
209
210
212 static std::pair<SampleGridIndexType, SampleGridSizeType>
213 DetermineGridIndexAndSize(const InputImageRegionType & croppedInputImageRegion,
214 const SampleGridSpacingType & gridSpacing);
215
217 static std::vector<WorkUnit>
218 GenerateWorkUnits(const ThreadIdType numberOfWorkUnits,
219 const InputImageRegionType & croppedInputImageRegion,
220 const SampleGridIndexType gridIndex,
221 const SampleGridSpacingType gridSpacing,
222 std::vector<ImageSampleType> & samples);
223
224 static void
225 SingleThreadedGenerateData(const TInputImage & inputImage,
226 const MaskType * const mask,
227 const InputImageRegionType & croppedInputImageRegion,
228 const SampleGridSpacingType & gridSpacing,
229 std::vector<ImageSampleType> & samples);
230 static void
231 MultiThreadedGenerateData(MultiThreaderBase & multiThreader,
232 const ThreadIdType numberOfWorkUnits,
233 const TInputImage & inputImage,
234 const MaskType * const mask,
235 const InputImageRegionType & croppedInputImageRegion,
236 const SampleGridSpacingType & gridSpacing,
237 std::vector<ImageSampleType> & samples);
238
240 template <elastix::MaskCondition VMaskCondition>
241 static void
243
245 SampleGridSpacingType m_SampleGridSpacing{ itk::MakeFilled<SampleGridSpacingType>(1) };
246
248 unsigned long m_RequestedNumberOfSamples{ 0 };
249};
250
251} // end namespace itk
252
253#ifndef ITK_MANUAL_INSTANTIATION
254# include "itkImageGridSampler.hxx"
255#endif
256
257#endif // end #ifndef itkImageGridSampler_h
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
ImageSample< InputImageType > ImageSampleType
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
itkOverrideGetNameOfClassMacro(ImageGridSampler)
void SetSampleGridSpacing(const SampleGridSpacingType &arg)
ImageSamplerBase< TInputImage > Superclass
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)
SmartPointer< Self > Pointer
void SetNumberOfSamples(unsigned long nrofsamples) override
typename OutputVectorContainerType::Pointer OutputVectorContainerPointer
VectorDataContainer< ImageSampleType > ImageSampleContainerType
typename InputImageType::ConstPointer InputImageConstPointer
ImageSample< InputImageType > ImageSampleType
typename InputImageType::PointType InputImagePointType
typename InputImageType::IndexType InputImageIndexType
typename InputImageType::RegionType InputImageRegionType
typename ImageSampleContainerType::Pointer ImageSampleContainerPointer
VectorDataContainer< ImageSample< TInputImage > > OutputVectorContainerType
typename InputImageType::Pointer InputImagePointer
ImageMaskSpatialObject< Self::InputImageDimension > MaskType
typename InputImageType::PixelType InputImagePixelType
const SampleGridSpacingType GridSpacing
const SampleGridSizeType GridSize
const SampleGridIndexType GridIndex


Generated on 1774142652 for elastix by doxygen 1.15.0 elastix logo