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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkAOSDataArrayTemplate.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 vtkAOSDataArrayTemplate
* @brief Array-Of-Structs implementation of
* vtkGenericDataArray.
*
*
* vtkGenericDataArray specialization that stores data array in the traditional
* VTK memory layout where a 3 component is stored in contiguous memory as
* \c A1A2A3B1B2B3C1C2C3 ... where A,B,C,... are tuples.
*
* This replaces vtkDataArrayTemplate.
*
* @sa
* vtkGenericDataArray vtkSOADataArrayTemplate
*/
#ifndef vtkAOSDataArrayTemplate_h
#define vtkAOSDataArrayTemplate_h
#include "vtkBuffer.h" // For storage buffer.
#include "vtkBuild.h" // For VTK_BUILD_SHARED_LIBS
#include "vtkCommonCoreModule.h" // For export macro
#include "vtkCompiler.h" // for VTK_USE_EXTERN_TEMPLATE
#include "vtkGenericDataArray.h"
// The export macro below makes no sense, but is necessary for older compilers
// when we export instantiations of this class from vtkCommonCore.
VTK_ABI_NAMESPACE_BEGIN
template <class ValueTypeT>
class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate
: public vtkGenericDataArray<vtkAOSDataArrayTemplate<ValueTypeT>, ValueTypeT>
{
typedef vtkGenericDataArray<vtkAOSDataArrayTemplate<ValueTypeT>, ValueTypeT> GenericDataArrayType;
public:
typedef vtkAOSDataArrayTemplate<ValueTypeT> SelfType;
vtkTemplateTypeMacro(SelfType, GenericDataArrayType);
typedef typename Superclass::ValueType ValueType;
enum DeleteMethod
{
VTK_DATA_ARRAY_FREE = vtkAbstractArray::VTK_DATA_ARRAY_FREE,
VTK_DATA_ARRAY_DELETE = vtkAbstractArray::VTK_DATA_ARRAY_DELETE,
VTK_DATA_ARRAY_ALIGNED_FREE = vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
VTK_DATA_ARRAY_USER_DEFINED = vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
};
static vtkAOSDataArrayTemplate* New();
/**
* Get the value at @a valueIdx. @a valueIdx assumes AOS ordering.
*/
ValueType GetValue(vtkIdType valueIdx) const
VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues())
{
return this->Buffer->GetBuffer()[valueIdx];
}
/**
* Set the value at @a valueIdx to @a value. @a valueIdx assumes AOS ordering.
*/
void SetValue(vtkIdType valueIdx, ValueType value)
VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues())
{
this->Buffer->GetBuffer()[valueIdx] = value;
}
///@{
/**
* Copy the tuple at @a tupleIdx into @a tuple.
*/
void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
{
const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents;
std::copy(this->Buffer->GetBuffer() + valueIdx,
this->Buffer->GetBuffer() + valueIdx + this->NumberOfComponents, tuple);
}
///@}
///@{
/**
* Set this array's tuple at @a tupleIdx to the values in @a tuple.
*/
void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
{
const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents;
std::copy(tuple, tuple + this->NumberOfComponents, this->Buffer->GetBuffer() + valueIdx);
}
///@}
/**
* Get component @a comp of the tuple at @a tupleIdx.
*/
ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const VTK_EXPECTS(0 <= tupleIdx &&
tupleIdx < GetNumberOfTuples()) VTK_EXPECTS(0 <= comp && comp < GetNumberOfComponents())
{
return this->Buffer->GetBuffer()[this->NumberOfComponents * tupleIdx + comp];
}
///@{
/**
* Set component @a comp of the tuple at @a tupleIdx to @a value.
*/
void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value) VTK_EXPECTS(0 <= tupleIdx &&
tupleIdx < GetNumberOfTuples()) VTK_EXPECTS(0 <= comp && comp < GetNumberOfComponents())
{
const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents + comp;
this->SetValue(valueIdx, value);
}
///@}
///@{
/**
* Set component @a comp of all tuples to @a value.
*/
void FillTypedComponent(int compIdx, ValueType value) override;
///@}
///@{
/**
* Set all the values in array to @a value.
*/
void FillValue(ValueType value) override;
void Fill(double value) override;
///@}
///@{
/**
* Get the address of a particular data index. Make sure data is allocated
* for the number of items requested. Set MaxId according to the number of
* data values requested.
*/
ValueType* WritePointer(vtkIdType valueIdx, vtkIdType numValues);
void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) override;
///@}
///@{
/**
* Get the address of a particular data index. Performs no checks
* to verify that the memory has been allocated etc.
* Use of this method is discouraged, as newer arrays require a deep-copy of
* the array data in order to return a suitable pointer. See vtkArrayDispatch
* for a safer alternative for fast data access.
*/
ValueType* GetPointer(vtkIdType valueIdx);
void* GetVoidPointer(vtkIdType valueIdx) override;
///@}
///@{
/**
* This method lets the user specify data to be held by the array. The
* array argument is a pointer to the data. size is the size of the
* array supplied by the user (as number of values, not in bytes).
* Set save to 1 to prevent the class from
* deleting the array when it cleans up or reallocates memory. The class
* uses the actual array provided; it does not copy the data from the
* suppled array. If specified, the delete method determines how the data
* array will be deallocated. If the delete method is
* VTK_DATA_ARRAY_FREE, free() will be used. If the delete method is
* VTK_DATA_ARRAY_DELETE, delete[] will be used. If the delete method is
* VTK_DATA_ARRAY_ALIGNED_FREE _aligned_free() will be used on Windows, while
* free() will be used everywhere else. The default is FREE.
*/
void SetArray(VTK_ZEROCOPY ValueType* array, vtkIdType size, int save, int deleteMethod);
void SetArray(VTK_ZEROCOPY ValueType* array, vtkIdType size, int save);
void SetVoidArray(void* array, vtkIdType size, int save) override;
void SetVoidArray(void* array, vtkIdType size, int save, int deleteMethod) override;
///@}
/**
* This method allows the user to specify a custom free function to be
* called when the array is deallocated. Calling this method will implicitly
* mean that the given free function will be called when the class
* cleans up or reallocates memory.
**/
void SetArrayFreeFunction(void (*callback)(void*)) override;
// Overridden for optimized implementations:
void SetTuple(vtkIdType tupleIdx, const float* tuple) override;
void SetTuple(vtkIdType tupleIdx, const double* tuple) override;
// MSVC doesn't like 'using' here (error C2487). Just forward instead:
// using Superclass::SetTuple;
void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override
{
this->Superclass::SetTuple(dstTupleIdx, srcTupleIdx, source);
}
void InsertTuple(vtkIdType tupleIdx, const float* source) override;
void InsertTuple(vtkIdType tupleIdx, const double* source) override;
// MSVC doesn't like 'using' here (error C2487). Just forward instead:
// using Superclass::InsertTuple;
void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override
{
this->Superclass::InsertTuple(dstTupleIdx, srcTupleIdx, source);
}
void InsertComponent(vtkIdType tupleIdx, int compIdx, double value) override;
vtkIdType InsertNextTuple(const float* tuple) override;
vtkIdType InsertNextTuple(const double* tuple) override;
// MSVC doesn't like 'using' here (error C2487). Just forward instead:
// using Superclass::InsertNextTuple;
vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray* source) override
{
return this->Superclass::InsertNextTuple(srcTupleIdx, source);
}
void GetTuple(vtkIdType tupleIdx, double* tuple) override;
double* GetTuple(vtkIdType tupleIdx) override;
/**
* Tell the array explicitly that a single data element has
* changed. Like DataChanged(), then is only necessary when you
* modify the array contents without using the array's API.
* @note This is a legacy method from vtkDataArrayTemplate, and is only
* implemented for array-of-struct arrays. It currently just calls
* DataChanged() and does nothing clever.
* TODO this is only defined for AOS (vtkDataArrayTemplate leftover).
* Deprecate to favor DataChanged?
*/
void DataElementChanged(vtkIdType) { this->DataChanged(); }
/**
* Legacy support for array-of-structs value iteration.
* TODO Deprecate?
*/
typedef ValueType* Iterator;
Iterator Begin() { return Iterator(this->GetVoidPointer(0)); }
Iterator End() { return Iterator(this->GetVoidPointer(this->MaxId + 1)); }
///@{
/**
* Perform a fast, safe cast from a vtkAbstractArray to a
* vtkAOSDataArrayTemplate.
* This method checks if source->GetArrayType() returns AOSDataArrayTemplate
* or a more derived type, checks the data types, and performs a static_cast
* to return source as a vtkDataArray pointer. Otherwise, nullptr is returned.
*/
static vtkAOSDataArrayTemplate<ValueType>* FastDownCast(vtkAbstractArray* source);
///@}
int GetArrayType() const override { return vtkAbstractArray::AoSDataArrayTemplate; }
VTK_NEWINSTANCE vtkArrayIterator* NewIterator() override;
bool HasStandardMemoryLayout() const override { return true; }
void ShallowCopy(vtkDataArray* other) override;
// Reimplemented for efficiency:
void InsertTuples(
vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
// MSVC doesn't like 'using' here (error C2487). Just forward instead:
// using Superclass::InsertTuples;
void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override
{
this->Superclass::InsertTuples(dstIds, srcIds, source);
}
void InsertTuplesStartingAt(
vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override
{
this->Superclass::InsertTuplesStartingAt(dstStart, srcIds, source);
}
protected:
vtkAOSDataArrayTemplate();
~vtkAOSDataArrayTemplate() override;
/**
* Allocate space for numTuples. Old data is not preserved. If numTuples == 0,
* all data is freed.
*/
bool AllocateTuples(vtkIdType numTuples);
/**
* Allocate space for numTuples. Old data is preserved. If numTuples == 0,
* all data is freed.
*/
bool ReallocateTuples(vtkIdType numTuples);
vtkBuffer<ValueType>* Buffer;
private:
vtkAOSDataArrayTemplate(const vtkAOSDataArrayTemplate&) = delete;
void operator=(const vtkAOSDataArrayTemplate&) = delete;
friend class vtkGenericDataArray<vtkAOSDataArrayTemplate<ValueTypeT>, ValueTypeT>;
};
// Declare vtkArrayDownCast implementations for AoS containers:
vtkArrayDownCast_TemplateFastCastMacro(vtkAOSDataArrayTemplate);
VTK_ABI_NAMESPACE_END
// This macro is used by the subclasses to create dummy
// declarations for these functions such that the wrapper
// can see them. The wrappers ignore vtkAOSDataArrayTemplate.
#define vtkCreateWrappedArrayInterface(T) \
int GetDataType() const override; \
void GetTypedTuple(vtkIdType i, T* tuple) VTK_EXPECTS(0 <= i && i < GetNumberOfTuples()); \
void SetTypedTuple(vtkIdType i, const T* tuple) VTK_EXPECTS(0 <= i && i < GetNumberOfTuples()); \
void InsertTypedTuple(vtkIdType i, const T* tuple) VTK_EXPECTS(0 <= i); \
vtkIdType InsertNextTypedTuple(const T* tuple); \
T GetValue(vtkIdType id) const VTK_EXPECTS(0 <= id && id < GetNumberOfValues()); \
void SetValue(vtkIdType id, T value) VTK_EXPECTS(0 <= id && id < GetNumberOfValues()); \
bool SetNumberOfValues(vtkIdType number) override; \
void InsertValue(vtkIdType id, T f) VTK_EXPECTS(0 <= id); \
vtkIdType InsertNextValue(T f); \
T* GetValueRange(int comp) VTK_SIZEHINT(2); \
T* GetValueRange() VTK_SIZEHINT(2); \
T* WritePointer(vtkIdType id, vtkIdType number); \
T* GetPointer(vtkIdType id); \
void SetArray(VTK_ZEROCOPY T* array, vtkIdType size, int save); \
void SetArray(VTK_ZEROCOPY T* array, vtkIdType size, int save, int deleteMethod)
#endif // header guard
// This portion must be OUTSIDE the include blockers. This is used to tell
// libraries other than vtkCommonCore that instantiations of
// vtkAOSDataArrayTemplate can be found externally. This prevents each library
// from instantiating these on their own.
#ifdef VTK_AOS_DATA_ARRAY_TEMPLATE_INSTANTIATING
#define VTK_AOS_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
namespace vtkDataArrayPrivate \
{ \
VTK_ABI_NAMESPACE_BEGIN \
VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkAOSDataArrayTemplate<T>, double); \
VTK_ABI_NAMESPACE_END \
} \
VTK_ABI_NAMESPACE_BEGIN \
template class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate<T>; \
VTK_ABI_NAMESPACE_END
#elif defined(VTK_USE_EXTERN_TEMPLATE)
#ifndef VTK_AOS_DATA_ARRAY_TEMPLATE_EXTERN
#define VTK_AOS_DATA_ARRAY_TEMPLATE_EXTERN
#ifdef _MSC_VER
#pragma warning(push)
// The following is needed when the vtkAOSDataArrayTemplate is declared
// dllexport and is used from another class in vtkCommonCore
#pragma warning(disable : 4910) // extern and dllexport incompatible
#endif
VTK_ABI_NAMESPACE_BEGIN
vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate);
VTK_ABI_NAMESPACE_END
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // VTK_AOS_DATA_ARRAY_TEMPLATE_EXTERN
// The following clause is only for MSVC
#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
#pragma warning(push)
// C4091: 'extern ' : ignored on left of 'int' when no variable is declared
#pragma warning(disable : 4091)
// Compiler-specific extension warning.
#pragma warning(disable : 4231)
// We need to disable warning 4910 and do an extern dllexport
// anyway. When deriving vtkCharArray and other types from an
// instantiation of this template the compiler does an explicit
// instantiation of the base class. From outside the vtkCommon
// library we block this using an extern dllimport instantiation.
// For classes inside vtkCommon we should be able to just do an
// extern instantiation, but VS complains about missing
// definitions. We cannot do an extern dllimport inside vtkCommon
// since the symbols are local to the dll. An extern dllexport
// seems to be the only way to convince VS to do the right
// thing, so we just disable the warning.
#pragma warning(disable : 4910) // extern and dllexport incompatible
// Use an "extern explicit instantiation" to give the class a DLL
// interface. This is a compiler-specific extension.
VTK_ABI_NAMESPACE_BEGIN
vtkInstantiateTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate);
VTK_ABI_NAMESPACE_END
#pragma warning(pop)
#endif
// VTK-HeaderTest-Exclude: vtkAOSDataArrayTemplate.h
|