20
20
21
21
#include " itkInPlaceImageFilter.h"
22
22
#include " itkSmartPointer.h"
23
+ #include " itkSimpleDataObjectDecorator.h"
24
+ #include < numeric>
23
25
24
26
namespace itk
25
27
{
28
+
29
+
26
30
/* * \class PasteImageFilter
27
- * \brief Paste an image into another image
31
+ * \brief Paste an image (or a constant value) into another image.
32
+ *
33
+ * PasteImageFilter allows a region in a destination image to be filled with a source image or a constant pixel value.
34
+ * The SetDestinationIndex() method prescribes where in the destination input to start pasting data from the source
35
+ * input. The SetSourceRegion method prescribes the section of the second image to paste into the first. When a
36
+ * constant pixel value is set, the SourceRegion describes the size of the region filled. If the output requested
37
+ * region does not include the SourceRegion after it has been repositioned to DestinationIndex, then the output will
38
+ * just be a copy of the input.
28
39
*
29
- * PasteImageFilter allows you to take a section of one image and
30
- * paste into another image. The SetDestinationIndex() method
31
- * prescribes where in the first input to start pasting data from the
32
- * second input. The SetSourceRegion method prescribes the section of
33
- * the second image to paste into the first. If the output requested
34
- * region does not include the SourceRegion after it has been
35
- * repositioned to DestinationIndex, then the output will just be
36
- * a copy of the input.
40
+ * This filter supports running "InPlace" to efficiently reuse the destination image buffer for the output, removing
41
+ * the need to copy the destination pixels to the output.
42
+ *
43
+ * When the source image has a lower dimension than the destination image then the DestinationSkipAxes parameter
44
+ * specifies which axes in the destination image are set to 1 when copying the region or filling with a constant.
37
45
*
38
46
* The two inputs and output image will have the same pixel type.
39
47
*
@@ -90,6 +98,10 @@ class ITK_TEMPLATE_EXPORT PasteImageFilter : public InPlaceImageFilter<TInputIma
90
98
using InputImageSizeType = typename InputImageType::SizeType;
91
99
using SourceImageIndexType = typename SourceImageType::IndexType;
92
100
using SourceImageSizeType = typename SourceImageType::SizeType;
101
+ using DecoratedSourceImagePixelType = SimpleDataObjectDecorator<SourceImagePixelType>;
102
+
103
+ using InputSkipAxesArrayType = FixedArray<bool , InputImageType::ImageDimension>;
104
+
93
105
94
106
/* * ImageDimension enumeration */
95
107
static constexpr unsigned int InputImageDimension = InputImageType::ImageDimension;
@@ -101,6 +113,18 @@ class ITK_TEMPLATE_EXPORT PasteImageFilter : public InPlaceImageFilter<TInputIma
101
113
itkSetMacro (DestinationIndex, InputImageIndexType);
102
114
itkGetConstMacro (DestinationIndex, InputImageIndexType);
103
115
116
+ /* * Set/Get the array describing which axes in the destination image to skip
117
+ *
118
+ * The axes with true values are set to 1, to fill the difference between the dimension of the input and source image.
119
+ * The number of true values in DestinationSkipAxes plus the DestinationImageDimension must equal the
120
+ * InputImageDimension.
121
+ *
122
+ * By default this array contains SourceImageDimension false values followed by true values for the remainder.
123
+ */
124
+ itkSetMacro (DestinationSkipAxes, InputSkipAxesArrayType);
125
+ itkGetConstMacro (DestinationSkipAxes, InputSkipAxesArrayType);
126
+
127
+
104
128
/* * Set/Get the source region (what part of the second input will be
105
129
* pasted. */
106
130
itkSetMacro (SourceRegion, SourceImageRegionType);
@@ -116,6 +140,14 @@ class ITK_TEMPLATE_EXPORT PasteImageFilter : public InPlaceImageFilter<TInputIma
116
140
itkSetInputMacro (SourceImage, SourceImageType);
117
141
itkGetInputMacro (SourceImage, SourceImageType);
118
142
143
+ /* * Set/Get a constant value to fill the destination region.
144
+ *
145
+ * This input is an alternative input to the SourceImage.
146
+ */
147
+ itkSetDecoratedInputMacro (Constant, SourceImagePixelType);
148
+ itkGetDecoratedInputMacro (Constant, SourceImagePixelType);
149
+
150
+
119
151
/* * PasteImageFilter needs to set the input requested regions for its
120
152
* inputs. The first input's requested region will be set to match
121
153
* the output requested region. The second input's requested region
@@ -138,13 +170,23 @@ class ITK_TEMPLATE_EXPORT PasteImageFilter : public InPlaceImageFilter<TInputIma
138
170
VerifyInputInformation () ITKv5_CONST override
139
171
{}
140
172
173
+ void
174
+ VerifyPreconditions () ITKv5_CONST override ;
175
+
176
+ bool
177
+ CanRunInPlace () const override ;
178
+
141
179
protected:
142
180
PasteImageFilter ();
143
181
~PasteImageFilter () override = default ;
144
182
void
145
183
PrintSelf (std::ostream & os, Indent indent) const override ;
146
184
147
- /* * PasteImageFilter can be implemented as a multithreaded filter.
185
+ InputImageSizeType
186
+ GetPresumedDestinationSize () const ;
187
+
188
+
189
+ /* * NPasteImageFilter can be implemented as a multithreaded filter.
148
190
* Therefore, this implementation provides a DynamicThreadedGenerateData()
149
191
* routine which is called for each processing thread. The output
150
192
* image data is allocated automatically by the superclass prior to
@@ -159,7 +201,11 @@ class ITK_TEMPLATE_EXPORT PasteImageFilter : public InPlaceImageFilter<TInputIma
159
201
160
202
SourceImageRegionType m_SourceRegion;
161
203
162
- InputImageIndexType m_DestinationIndex;
204
+ InputImageIndexType m_DestinationIndex;
205
+ InputSkipAxesArrayType m_DestinationSkipAxes;
206
+
207
+ static_assert (InputImageDimension >= SourceImageDimension,
208
+ " The source image dimension is greater than the input image." );
163
209
};
164
210
} // end namespace itk
165
211
0 commit comments