VTK  9.7.1
vtkAffineArray.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Funded by CEA, DAM, DIF, F-91297 Arpajon, France
14 #ifndef vtkAffineArray_h
15 #define vtkAffineArray_h
16 
17 #include "vtkAffineImplicitBackend.h" // for the array backend
18 #include "vtkCommonCoreModule.h" // for export macro
19 #include "vtkCompiler.h" // for VTK_USE_EXTERN_TEMPLATE
20 #include "vtkImplicitArray.h"
21 
22 VTK_ABI_NAMESPACE_BEGIN
23 template <class ValueTypeT>
24 class VTKCOMMONCORE_EXPORT vtkAffineArray
25 #ifndef __VTK_WRAP__
26  : public vtkImplicitArray<vtkAffineImplicitBackend<ValueTypeT>, vtkArrayTypes::VTK_AFFINE_ARRAY>
27 {
28  using ImplicitArrayType =
30 #else // Fake the superclass for the wrappers.
31  : public vtkDataArray
32 {
33  using ImplicitArrayType = vtkDataArray;
34 #endif
35 public:
37  vtkImplicitArrayTypeMacro(SelfType, ImplicitArrayType);
38 #ifndef __VTK_WRAP__
39  using typename Superclass::ArrayTypeTag;
40  using typename Superclass::DataTypeTag;
41  using typename Superclass::ValueType;
42 #else
43  using ValueType = ValueTypeT;
44 #endif
45 
46  static vtkAffineArray* New();
47 
48  // This macro expands to the set of method declarations that
49  // make up the interface of vtkImplicitArray, which is ignored
50  // by the wrappers.
51 #if defined(__VTK_WRAP__) || defined(__WRAP_GCCXML__)
53 #endif
54 
59  {
60  return static_cast<vtkAffineArray<ValueType>*>(Superclass::FastDownCast(source));
61  }
62 
69  void ConstructBackend(ValueType slope, ValueType intercept);
70 
75  {
76  return const_cast<vtkAffineArray<ValueType>*>(this)->GetBackend()->Slope;
77  }
78 
83  {
84  return const_cast<vtkAffineArray<ValueType>*>(this)->GetBackend()->Intercept;
85  }
86 
90  bool IsBackendConstructed() const
91  {
92  return const_cast<vtkAffineArray<ValueType>*>(this)->GetBackend() != nullptr;
93  }
94 
95 protected:
96  vtkAffineArray() = default;
97  ~vtkAffineArray() override = default;
98 
99 private:
100  vtkAffineArray(const vtkAffineArray&) = delete;
101  void operator=(const vtkAffineArray&) = delete;
102 };
103 
104 // Declare vtkArrayDownCast implementations for Affine arrays:
106 
107 VTK_ABI_NAMESPACE_END
108 
109 // This macro is used by the subclasses to create dummy
110 // declarations for these functions such that the wrapper
111 // can see them. The wrappers ignore vtkAffineArray.
112 #define vtkCreateAffineWrappedArrayInterface(T) \
113  vtkCreateImplicitWrappedArrayInterface(T); \
114  void ConstructBackend(T slope, T intercept); \
115  T GetSlope() const; \
116  T GetIntercept() const; \
117  bool IsBackendConstructed() const;
118 
119 #endif // vtkAffineArray_h
120 
121 // This portion must be OUTSIDE the include blockers. This is used to tell
122 // libraries other than vtkCommonCore that instantiations of
123 // vtkAffineArray can be found externally. This prevents each library
124 // from instantiating these on their own.
125 #ifdef VTK_AFFINE_ARRAY_INSTANTIATING
126 #define VTK_AFFINE_ARRAY_INSTANTIATE(T) \
127  namespace vtkDataArrayPrivate \
128  { \
129  VTK_ABI_NAMESPACE_BEGIN \
130  VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkAffineArray<T>, double); \
131  VTK_ABI_NAMESPACE_END \
132  } \
133  VTK_ABI_NAMESPACE_BEGIN \
134  template class VTKCOMMONCORE_EXPORT vtkAffineArray<T>; \
135  VTK_ABI_NAMESPACE_END
136 // We only provide these specializations for the 64-bit integer types, since
137 // other types can reuse the double-precision mechanism in
138 // vtkDataArray::GetRange without losing precision.
139 #define VTK_AFFINE_ARRAY_INSTANTIATE_VALUERANGE(T) \
140  namespace vtkDataArrayPrivate \
141  { \
142  VTK_ABI_NAMESPACE_BEGIN \
143  VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkAffineArray<T>, T); \
144  VTK_ABI_NAMESPACE_END \
145  }
146 #elif defined(VTK_USE_EXTERN_TEMPLATE)
147 #ifndef VTK_AFFINE_ARRAY_EXTERN
148 #define VTK_AFFINE_ARRAY_EXTERN
149 #ifdef _MSC_VER
150 #pragma warning(push)
151 // The following is needed when the vtkAffineArray is declared
152 // dllexport and is used from another class in vtkCommonCore
153 #pragma warning(disable : 4910) // extern and dllexport incompatible
154 #endif
155 VTK_ABI_NAMESPACE_BEGIN
156 vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkAffineArray);
157 VTK_ABI_NAMESPACE_END
158 
160 {
161 VTK_ABI_NAMESPACE_BEGIN
162 // These are instantiated in vtkGenericDataArrayValueRange${i}.cxx
167 // These are instantiated by vtkAffineArrayInstantiate_double.cxx.inc, e.t.c.
181 
182 VTK_ABI_NAMESPACE_END
183 } // namespace vtkDataArrayPrivate
184 
185 #ifdef _MSC_VER
186 #pragma warning(pop)
187 #endif
188 #endif // VTK_AFFINE_ARRAY_EXTERN
189 
190 // The following clause is only for MSVC
191 #elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
192 #pragma warning(push)
193 
194 // C4091: 'extern ' : ignored on left of 'int' when no variable is declared
195 #pragma warning(disable : 4091)
196 
197 // Compiler-specific extension warning.
198 #pragma warning(disable : 4231)
199 
200 // We need to disable warning 4910 and do an extern dllexport
201 // anyway. When deriving new arrays from an
202 // instantiation of this template the compiler does an explicit
203 // instantiation of the base class. From outside the vtkCommon
204 // library we block this using an extern dllimport instantiation.
205 // For classes inside vtkCommon we should be able to just do an
206 // extern instantiation, but VS 2008 complains about missing
207 // definitions. We cannot do an extern dllimport inside vtkCommon
208 // since the symbols are local to the dll. An extern dllexport
209 // seems to be the only way to convince VS 2008 to do the right
210 // thing, so we just disable the warning.
211 #pragma warning(disable : 4910) // extern and dllexport incompatible
212 
213 // Use an "extern explicit instantiation" to give the class a DLL
214 // interface. This is a compiler-specific extension.
215 VTK_ABI_NAMESPACE_BEGIN
216 vtkInstantiateTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkAffineArray);
217 VTK_ABI_NAMESPACE_END
218 
219 #pragma warning(pop)
220 
221 #endif
222 
223 // VTK-HeaderTest-Exclude: vtkAffineArray.h
vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkAffineArray)
Abstract superclass for all arrays.
vtkImplicitArrayTypeMacro(SelfType, GenericDataArrayType)
ValueType GetIntercept() const
Get the intercept of the affine function.
ValueType GetSlope() const
Get the slope of the affine function.
#define VTK_DECLARE_VALUERANGE_ARRAYTYPE(ArrayType, ValueType)
std::shared_ptr< BackendT > GetBackend()
Setter/Getter for Backend.
static vtkAffineArray< ValueType > * FastDownCast(vtkAbstractArray *source)
A faster alternative to SafeDownCast for downcasting vtkAbstractArrays.
vtkInstantiateTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkArrayIteratorTemplate)
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
A read only array class that wraps an implicit function from integers to any value type supported by ...
bool IsBackendConstructed() const
Check whether the backend has been constructed.
A utility array for wrapping affine functions in implicit arrays.
vtkArrayDownCast_TemplateFastCastMacro(vtkAffineArray)
#define vtkCreateImplicitWrappedArrayInterface(T)
static vtkImplicitArray * New()
void ConstructBackend(Params &&...params)
Utility method for setting backend parameterization directly.