forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkThreadedImageAlgorithm.h
180 lines (152 loc) · 5.74 KB
/
vtkThreadedImageAlgorithm.h
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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkThreadedImageAlgorithm.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkThreadedImageAlgorithm
* @brief Generic filter that has one input.
*
* vtkThreadedImageAlgorithm is a filter superclass that hides much of the
* pipeline complexity. It handles breaking the pipeline execution
* into smaller extents so that the vtkImageData limits are observed. It
* also provides support for multithreading. If you don't need any of this
* functionality, consider using vtkSimpleImageToImageAlgorithm instead.
* @sa
* vtkSimpleImageToImageAlgorithm
*/
#ifndef vtkThreadedImageAlgorithm_h
#define vtkThreadedImageAlgorithm_h
#include "vtkCommonExecutionModelModule.h" // For export macro
#include "vtkImageAlgorithm.h"
#include "vtkThreads.h" // for VTK_MAX_THREADS
class vtkImageData;
class vtkMultiThreader;
class VTKCOMMONEXECUTIONMODEL_EXPORT vtkThreadedImageAlgorithm : public vtkImageAlgorithm
{
public:
vtkTypeMacro(vtkThreadedImageAlgorithm, vtkImageAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* If the subclass does not define an Execute method, then the task
* will be broken up, multiple threads will be spawned, and each thread
* will call this method. It is public so that the thread functions
* can call this method.
*/
virtual void ThreadedRequestData(vtkInformation* request, vtkInformationVector** inputVector,
vtkInformationVector* outputVector, vtkImageData*** inData, vtkImageData** outData,
int extent[6], int threadId);
// also support the old signature
virtual void ThreadedExecute(
vtkImageData* inData, vtkImageData* outData, int extent[6], int threadId);
///@{
/**
* Enable/Disable SMP for threading.
*/
vtkGetMacro(EnableSMP, bool);
vtkSetMacro(EnableSMP, bool);
///@}
///@{
/**
* Global Disable SMP for all derived Imaging filters.
*/
static void SetGlobalDefaultEnableSMP(bool enable);
static bool GetGlobalDefaultEnableSMP();
///@}
///@{
/**
* The minimum piece size when volume is split for execution.
* By default, the minimum size is (16,1,1).
*/
vtkSetVector3Macro(MinimumPieceSize, int);
vtkGetVector3Macro(MinimumPieceSize, int);
///@}
///@{
/**
* The desired bytes per piece when volume is split for execution.
* When SMP is enabled, this is used to subdivide the volume into pieces.
* Smaller pieces allow for better dynamic load balancing, but increase
* the total overhead. The default is 65536 bytes.
*/
vtkSetMacro(DesiredBytesPerPiece, vtkIdType);
vtkGetMacro(DesiredBytesPerPiece, vtkIdType);
///@}
///@{
/**
* Set the method used to divide the volume into pieces.
* Slab mode splits the volume along the Z direction first,
* Beam mode splits evenly along the Z and Y directions, and
* Block mode splits evenly along all three directions.
* Most filters use Slab mode as the default.
*/
vtkSetClampMacro(SplitMode, int, 0, 2);
void SetSplitModeToSlab() { this->SetSplitMode(SLAB); }
void SetSplitModeToBeam() { this->SetSplitMode(BEAM); }
void SetSplitModeToBlock() { this->SetSplitMode(BLOCK); }
vtkGetMacro(SplitMode, int);
///@}
///@{
/**
* Get/Set the number of threads to create when rendering.
* This is ignored if EnableSMP is On.
*/
vtkSetClampMacro(NumberOfThreads, int, 1, VTK_MAX_THREADS);
vtkGetMacro(NumberOfThreads, int);
///@}
/**
* Putting this here until I merge graphics and imaging streaming.
*/
virtual int SplitExtent(int splitExt[6], int startExt[6], int num, int total);
protected:
vtkThreadedImageAlgorithm();
~vtkThreadedImageAlgorithm() override;
vtkMultiThreader* Threader;
int NumberOfThreads;
bool EnableSMP;
static bool GlobalDefaultEnableSMP;
enum SplitModeEnum
{
SLAB = 0,
BEAM = 1,
BLOCK = 2
};
int SplitMode;
int SplitPath[3];
int SplitPathLength;
int MinimumPieceSize[3];
vtkIdType DesiredBytesPerPiece;
/**
* This is called by the superclass.
* This is the method you should override.
*/
int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
vtkInformationVector* outputVector) override;
/**
* Execute ThreadedRequestData for the given set of pieces.
* The extent will be broken into the number of pieces specified,
* and ThreadedRequestData will be called for all pieces starting
* at "begin" and up to but not including "end".
*/
virtual void SMPRequestData(vtkInformation* request, vtkInformationVector** inputVector,
vtkInformationVector* outputVector, vtkImageData*** inData, vtkImageData** outData,
vtkIdType begin, vtkIdType end, vtkIdType pieces, int extent[6]);
/**
* Allocate space for output data and copy attributes from first input.
* If the inDataObjects and outDataObjects are not passed as zero, then
* they must be large enough to store the data objects for all inputs and
* outputs.
*/
virtual void PrepareImageData(vtkInformationVector** inputVector,
vtkInformationVector* outputVector, vtkImageData*** inDataObjects = nullptr,
vtkImageData** outDataObjects = nullptr);
private:
vtkThreadedImageAlgorithm(const vtkThreadedImageAlgorithm&) = delete;
void operator=(const vtkThreadedImageAlgorithm&) = delete;
friend class vtkThreadedImageAlgorithmFunctor;
};
#endif