VTK  9.1.0
vtkSMPToolsInternal.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkSMPToolsInternal.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
15
16#ifndef vtkSMPToolsInternal_h
17#define vtkSMPToolsInternal_h
18
19#include <iterator> // For std::advance
20
21#ifndef DOXYGEN_SHOULD_SKIP_THIS
22namespace vtk
23{
24namespace detail
25{
26namespace smp
27{
28
29template <typename InputIt, typename OutputIt, typename Functor>
30class UnaryTransformCall
31{
32protected:
33 InputIt In;
34 OutputIt Out;
35 Functor& Transform;
36
37public:
38 UnaryTransformCall(InputIt _in, OutputIt _out, Functor& _transform)
39 : In(_in)
40 , Out(_out)
41 , Transform(_transform)
42 {
43 }
44
45 void Execute(vtkIdType begin, vtkIdType end)
46 {
47 InputIt itIn(In);
48 OutputIt itOut(Out);
49 std::advance(itIn, begin);
50 std::advance(itOut, begin);
51 for (vtkIdType it = begin; it < end; it++)
52 {
53 *itOut = Transform(*itIn);
54 ++itIn;
55 ++itOut;
56 }
57 }
58};
59
60template <typename InputIt1, typename InputIt2, typename OutputIt, typename Functor>
61class BinaryTransformCall : public UnaryTransformCall<InputIt1, OutputIt, Functor>
62{
63 InputIt2 In2;
64
65public:
66 BinaryTransformCall(InputIt1 _in1, InputIt2 _in2, OutputIt _out, Functor& _transform)
67 : UnaryTransformCall<InputIt1, OutputIt, Functor>(_in1, _out, _transform)
68 , In2(_in2)
69 {
70 }
71
72 void Execute(vtkIdType begin, vtkIdType end)
73 {
74 InputIt1 itIn1(this->In);
75 InputIt2 itIn2(In2);
76 OutputIt itOut(this->Out);
77 std::advance(itIn1, begin);
78 std::advance(itIn2, begin);
79 std::advance(itOut, begin);
80 for (vtkIdType it = begin; it < end; it++)
81 {
82 *itOut = this->Transform(*itIn1, *itIn2);
83 ++itIn1;
84 ++itIn2;
85 ++itOut;
86 }
87 }
88};
89
90template <typename T>
91struct FillFunctor
92{
93 const T& Value;
94
95public:
96 FillFunctor(const T& _value)
97 : Value(_value)
98 {
99 }
100
101 T operator()(T vtkNotUsed(inValue)) { return Value; }
102};
103
104} // namespace smp
105} // namespace detail
106} // namespace vtk
107#endif // DOXYGEN_SHOULD_SKIP_THIS
108
109#endif
@ Transform
Definition: vtkX3D.h:47
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
int vtkIdType
Definition: vtkType.h:332