Commit 74bd55b4 authored by David C. Lonie's avatar David C. Lonie

Update documentation for array classes, clean up template classes.

Most of the changes to Abstract and DataArray were to fix up
ambiguous references to 'id' and 'number' and clarify whether they
refer to tuples or values.

Many docstrings were removed for overridden virtuals. Doxygen will use
the base class's docstring for the virtual, which prevents inconsistencies
where one instance of the docstring changes but the others are left
untouched.

Also removed vtkSOADataArrayTemplate::Resizable. This can be reimplemented
later in a more general way if needed.
parent a025c550
......@@ -12,100 +12,110 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkAOSDataArrayTemplate - vtkGenericDataArray specialization that
// stores data array in the traditional VTK memory layout where a 3 component is
// stored in contiguous memory as \c A1A2A2B1B2B3C1C2C3 ... where A,B,C,... are
// tuples.
// .NAME vtkAOSDataArrayTemplate - Array-Of-Structs implementation of
// vtkGenericDataArray.
//
// .SECTION Description
// vtkGenericDataArray specialization that stores data array in the traditional
// VTK memory layout where a 3 component is stored in contiguous memory as
// \c A1A2A2B1B2B3C1C2C3 ... where A,B,C,... are tuples.
//
// This replaces vtkDataArrayTemplate.
//
// .SECTION See Also
// vtkGenericDataArray vtkSOADataArrayTemplate
#ifndef vtkAOSDataArrayTemplate_h
#define vtkAOSDataArrayTemplate_h
#include "vtkCommonCoreModule.h" // For export macro
#include "vtkGenericDataArray.h"
#include "vtkBuffer.h"
#include "vtkBuffer.h" // For storage buffer.
// The export macro below makes no sense, but is necessary for older compilers
// when we export instantiations of this class from vtkCommonCore.
template <class ValueTypeT>
class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate :
public vtkGenericDataArray<vtkAOSDataArrayTemplate<ValueTypeT>, ValueTypeT>
{
typedef vtkGenericDataArray<vtkAOSDataArrayTemplate<ValueTypeT>, ValueTypeT >
typedef vtkGenericDataArray<vtkAOSDataArrayTemplate<ValueTypeT>, ValueTypeT>
GenericDataArrayType;
public:
typedef vtkAOSDataArrayTemplate<ValueTypeT> SelfType;
vtkTemplateTypeMacro(SelfType, GenericDataArrayType)
typedef typename Superclass::ValueType ValueType;
// Description:
// 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)); }
enum DeleteMethod
{
VTK_DATA_ARRAY_FREE=vtkBuffer<ValueType>::VTK_DATA_ARRAY_FREE,
VTK_DATA_ARRAY_DELETE=vtkBuffer<ValueType>::VTK_DATA_ARRAY_DELETE
};
static vtkAOSDataArrayTemplate* New();
// **************************************************************************
// Methods that are needed to be implemented by every vtkGenericDataArray
// subclass.
// **************************************************************************
// Description:
// Get the value at @a valueIdx. @a valueIdx assumes AOS ordering.
inline ValueType GetValue(vtkIdType valueIdx) const
{
{
return this->Buffer->GetBuffer()[valueIdx];
}
}
// Description:
// Set the value at @a valueIdx to @a value. @a valueIdx assumes AOS ordering.
inline void SetValue(vtkIdType valueIdx, ValueType value)
{
this->Buffer->GetBuffer()[valueIdx] = value;
}
// Description:
// Copy the tuple at @a tupleIdx into @a tuple.
inline void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
{
{
const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents;
std::copy(this->Buffer->GetBuffer() + valueIdx,
this->Buffer->GetBuffer() + valueIdx + this->NumberOfComponents,
tuple);
}
inline ValueType GetTypedComponent(vtkIdType index, int comp) const
{
return this->Buffer->GetBuffer()[this->NumberOfComponents*index + comp];
}
inline void SetValue(vtkIdType valueIdx, ValueType value)
{
this->Buffer->GetBuffer()[valueIdx] = value;
}
}
// Description:
// Set this array's tuple at @a tupleIdx to the values in @a tuple.
inline void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
{
{
const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents;
std::copy(tuple, tuple + this->NumberOfComponents,
this->Buffer->GetBuffer() + valueIdx);
}
}
// Description:
// Get component @a comp of the tuple at @a tupleIdx.
inline ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
{
return this->Buffer->GetBuffer()[this->NumberOfComponents*tupleIdx + comp];
}
// Description:
// Set component @a comp of the tuple at @a tupleIdx to @a value.
inline void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
{
{
const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents + comp;
this->SetValue(valueIdx, value);
}
virtual void ShallowCopy(vtkDataArray *other);
}
// **************************************************************************
// Description:
// 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 id, vtkIdType number);
virtual void* WriteVoidPointer(vtkIdType id, vtkIdType number)
{ return this->WritePointer(id, number); }
ValueType* WritePointer(vtkIdType valueIdx, vtkIdType numValues);
virtual void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues);
// Description:
// Get the address of a particular data index. Performs no checks
// to verify that the memory has been allocated etc.
// If the data is simply being iterated over, consider using
// vtkDataArrayIteratorMacro for safety and efficiency, rather than using this
// member directly.
ValueType* GetPointer(vtkIdType id) { return this->Buffer->GetBuffer() + id; }
virtual void* GetVoidPointer(vtkIdType id) { return this->GetPointer(id); }
enum DeleteMethod
{
VTK_DATA_ARRAY_FREE=vtkBuffer<ValueType>::VTK_DATA_ARRAY_FREE,
VTK_DATA_ARRAY_DELETE=vtkBuffer<ValueType>::VTK_DATA_ARRAY_DELETE
};
// 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);
virtual void* GetVoidPointer(vtkIdType valueIdx);
// Description:
// This method lets the user specify data to be held by the array. The
......@@ -118,15 +128,10 @@ public:
// VTK_DATA_ARRAY_FREE, free() will be used. If the delete method is
// DELETE, delete[] will be used. The default is FREE.
void SetArray(ValueType* array, vtkIdType size, int save, int deleteMethod);
void SetArray(ValueType* array, vtkIdType size, int save)
{ this->SetArray(array, size, save, VTK_DATA_ARRAY_FREE); }
virtual void SetVoidArray(void* array, vtkIdType size, int save)
{ this->SetArray(static_cast<ValueType*>(array), size, save); }
void SetArray(ValueType* array, vtkIdType size, int save);
virtual void SetVoidArray(void* array, vtkIdType size, int save);
virtual void SetVoidArray(void* array, vtkIdType size, int save,
int deleteMethod)
{
this->SetArray(static_cast<ValueType*>(array), size, save, deleteMethod);
}
int deleteMethod);
// Description:
// Tell the array explicitly that a single data element has
......@@ -135,12 +140,16 @@ public:
// @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.
virtual void DataElementChanged(vtkIdType)
{
this->DataChanged();
}
// TODO this is only defined for AOS (vtkDataArrayTemplate leftover).
// Deprecate to favor DataChanged?
void DataElementChanged(vtkIdType) { this->DataChanged(); }
virtual vtkArrayIterator *NewIterator();
// Description:
// 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)); }
// Description:
// Perform a fast, safe cast from a vtkAbstractArray to a
......@@ -164,42 +173,42 @@ public:
return NULL;
}
// Description:
// Method for type-checking in FastDownCast implementations.
virtual int GetArrayType() { return vtkAbstractArray::AoSDataArrayTemplate; }
virtual vtkArrayIterator *NewIterator();
virtual bool HasStandardMemoryLayout() { return true; }
virtual void ShallowCopy(vtkDataArray *other);
//BTX
//BTX
protected:
vtkAOSDataArrayTemplate();
~vtkAOSDataArrayTemplate();
// **************************************************************************
// Methods that are needed to be implemented by every vtkGenericDataArray
// subclass.
// **************************************************************************
// Implement the memory management interface.
// Description:
// Allocate space for numTuples. Old data is not preserved. If numTuples == 0,
// all data is freed.
bool AllocateTuples(vtkIdType numTuples);
// Description:
// Allocate space for numTuples. Old data is preserved. If numTuples == 0,
// all data is freed.
bool ReallocateTuples(vtkIdType numTuples);
// **************************************************************************
vtkBuffer<ValueType> *Buffer;
ValueType ValueRange[2]; // XXX
private:
vtkAOSDataArrayTemplate(const vtkAOSDataArrayTemplate&); // Not implemented.
void operator=(const vtkAOSDataArrayTemplate&); // Not implemented.
friend class vtkGenericDataArray<vtkAOSDataArrayTemplate<ValueTypeT>,
ValueTypeT>;
//ETX
//ETX
};
// Declare vtkArrayDownCast implementations for AoS containers:
vtkArrayDownCast_TemplateFastCastMacro(vtkAOSDataArrayTemplate)
# define VTK_AOS_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
template class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate< T >
template class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate< T >
// This macro is used by the subclasses to create dummy
// declarations for these functions such that the wrapper
......
......@@ -19,34 +19,33 @@
#include "vtkArrayIteratorTemplate.h"
#define vtkAOSDataArrayTemplateT(returnType) \
template <class ValueType> \
returnType vtkAOSDataArrayTemplate<ValueType>
//-----------------------------------------------------------------------------
vtkAOSDataArrayTemplateT(vtkAOSDataArrayTemplate<ValueType>*)::New()
template <class ValueTypeT>
vtkAOSDataArrayTemplate<ValueTypeT>*
vtkAOSDataArrayTemplate<ValueTypeT>::New()
{
VTK_STANDARD_NEW_BODY(vtkAOSDataArrayTemplate<ValueType>);
}
//-----------------------------------------------------------------------------
template <class ValueType>
vtkAOSDataArrayTemplate<ValueType>::vtkAOSDataArrayTemplate()
template <class ValueTypeT>
vtkAOSDataArrayTemplate<ValueTypeT>::vtkAOSDataArrayTemplate()
{
this->Buffer = vtkBuffer<ValueType>::New();
}
//-----------------------------------------------------------------------------
template <class ValueType>
vtkAOSDataArrayTemplate<ValueType>::~vtkAOSDataArrayTemplate()
template <class ValueTypeT>
vtkAOSDataArrayTemplate<ValueTypeT>::~vtkAOSDataArrayTemplate()
{
this->SetArray(NULL, 0, 0);
this->Buffer->Delete();
}
//-----------------------------------------------------------------------------
vtkAOSDataArrayTemplateT(void)::SetArray(
ValueType* array, vtkIdType size, int save, int deleteMethod)
template <class ValueTypeT>
void vtkAOSDataArrayTemplate<ValueTypeT>
::SetArray(ValueType* array, vtkIdType size, int save, int deleteMethod)
{
this->Buffer->SetBuffer(array, size, save != 0, deleteMethod);
this->Size = size;
......@@ -55,7 +54,32 @@ vtkAOSDataArrayTemplateT(void)::SetArray(
}
//-----------------------------------------------------------------------------
vtkAOSDataArrayTemplateT(vtkArrayIterator*)::NewIterator()
template <class ValueTypeT>
void vtkAOSDataArrayTemplate<ValueTypeT>
::SetArray(ValueType *array, vtkIdType size, int save)
{
this->SetArray(array, size, save, VTK_DATA_ARRAY_FREE);
}
//-----------------------------------------------------------------------------
template <class ValueTypeT>
void vtkAOSDataArrayTemplate<ValueTypeT>
::SetVoidArray(void *array, vtkIdType size, int save)
{
this->SetArray(static_cast<ValueType*>(array), size, save);
}
//-----------------------------------------------------------------------------
template <class ValueTypeT>
void vtkAOSDataArrayTemplate<ValueTypeT>
::SetVoidArray(void *array, vtkIdType size, int save, int deleteMethod)
{
this->SetArray(static_cast<ValueType*>(array), size, save, deleteMethod);
}
//-----------------------------------------------------------------------------
template <class ValueTypeT>
vtkArrayIterator* vtkAOSDataArrayTemplate<ValueTypeT>::NewIterator()
{
vtkArrayIterator *iter = vtkArrayIteratorTemplate<ValueType>::New();
iter->Initialize(this);
......@@ -91,10 +115,10 @@ void vtkAOSDataArrayTemplate<ValueTypeT>::ShallowCopy(vtkDataArray *other)
//-----------------------------------------------------------------------------
template <class ValueTypeT>
typename vtkAOSDataArrayTemplate<ValueTypeT>::ValueType*
vtkAOSDataArrayTemplate<ValueTypeT>::WritePointer(vtkIdType id,
vtkIdType number)
vtkAOSDataArrayTemplate<ValueTypeT>
::WritePointer(vtkIdType valueIdx, vtkIdType numValues)
{
vtkIdType newSize = id + number;
vtkIdType newSize = valueIdx + numValues;
if (newSize > this->Size)
{
if (!this->Resize(newSize / this->NumberOfComponents + 1))
......@@ -108,11 +132,35 @@ vtkAOSDataArrayTemplate<ValueTypeT>::WritePointer(vtkIdType id,
this->MaxId = std::max(this->MaxId, newSize - 1);
this->DataChanged();
return this->GetPointer(id);
return this->GetPointer(valueIdx);
}
//-----------------------------------------------------------------------------
template <class ValueTypeT>
void* vtkAOSDataArrayTemplate<ValueTypeT>
::WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues)
{
return this->WritePointer(valueIdx, numValues);
}
//-----------------------------------------------------------------------------
vtkAOSDataArrayTemplateT(bool)::AllocateTuples(vtkIdType numTuples)
template <class ValueTypeT>
typename vtkAOSDataArrayTemplate<ValueTypeT>::ValueType *
vtkAOSDataArrayTemplate<ValueTypeT>::GetPointer(vtkIdType valueIdx)
{
return this->Buffer->GetBuffer() + valueIdx;
}
//-----------------------------------------------------------------------------
template <class ValueTypeT>
void* vtkAOSDataArrayTemplate<ValueTypeT>::GetVoidPointer(vtkIdType valueIdx)
{
return this->GetPointer(valueIdx);
}
//-----------------------------------------------------------------------------
template <class ValueTypeT>
bool vtkAOSDataArrayTemplate<ValueTypeT>::AllocateTuples(vtkIdType numTuples)
{
vtkIdType numValues = numTuples * this->GetNumberOfComponents();
if (this->Buffer->Allocate(numValues))
......@@ -124,7 +172,8 @@ vtkAOSDataArrayTemplateT(bool)::AllocateTuples(vtkIdType numTuples)
}
//-----------------------------------------------------------------------------
vtkAOSDataArrayTemplateT(bool)::ReallocateTuples(vtkIdType numTuples)
template <class ValueTypeT>
bool vtkAOSDataArrayTemplate<ValueTypeT>::ReallocateTuples(vtkIdType numTuples)
{
if (this->Buffer->Reallocate(numTuples * this->GetNumberOfComponents()))
{
......
......@@ -185,12 +185,12 @@ int vtkAbstractArray::CopyComponentNames( vtkAbstractArray *da )
}
//----------------------------------------------------------------------------
void vtkAbstractArray::SetNumberOfValues(vtkIdType number)
void vtkAbstractArray::SetNumberOfValues(vtkIdType numValues)
{
if (this->Resize(std::ceil(number /
if (this->Resize(std::ceil(numValues /
static_cast<float>(this->NumberOfComponents))))
{
this->MaxId = number - 1;
this->MaxId = numValues - 1;
}
}
......@@ -214,7 +214,7 @@ void vtkAbstractArray::SetInformation(vtkInformation *args)
}
//----------------------------------------------------------------------------
void vtkAbstractArray::GetTuples(vtkIdList* ptIds, vtkAbstractArray* aa)
void vtkAbstractArray::GetTuples(vtkIdList* tupleIds, vtkAbstractArray* aa)
{
if (aa->GetNumberOfComponents() != this->GetNumberOfComponents())
{
......@@ -223,10 +223,10 @@ void vtkAbstractArray::GetTuples(vtkIdList* ptIds, vtkAbstractArray* aa)
}
// Here we give the slowest implementation. Subclasses can override
// to use the knowledge about the data.
vtkIdType num = ptIds->GetNumberOfIds();
vtkIdType num = tupleIds->GetNumberOfIds();
for (vtkIdType i = 0; i < num; i++)
{
aa->SetTuple(i, ptIds->GetId(i), this);
aa->SetTuple(i, tupleIds->GetId(i), this);
}
}
......@@ -411,13 +411,13 @@ vtkVariant vtkAbstractArrayGetVariantValue(T* arr, vtkIdType index)
}
//----------------------------------------------------------------------------
vtkVariant vtkAbstractArray::GetVariantValue(vtkIdType i)
vtkVariant vtkAbstractArray::GetVariantValue(vtkIdType valueIdx)
{
vtkVariant val;
switch(this->GetDataType())
{
vtkExtraExtendedTemplateMacro(val = vtkAbstractArrayGetVariantValue(
static_cast<VTK_TT*>(this->GetVoidPointer(0)), i));
static_cast<VTK_TT*>(this->GetVoidPointer(0)), valueIdx));
}
return val;
}
......
......@@ -35,6 +35,19 @@
// change this name using the SetName() method. (The array name is
// used for data manipulation.)
//
// This class (and subclasses) use two forms of addressing elements:
// - Value Indexing: The index of an element assuming an array-of-structs
// memory layout.
// - Tuple/Component Indexing: Explicitly specify the tuple and component
// indices.
//
// It is also worth pointing out that the behavior of the "Insert*" methods
// of classes in this hierarchy may not behave as expected. They work exactly
// as the corresponding "Set*" methods, except that memory allocation will
// be performed if acting on a value past the end of the array. If the data
// already exists, "inserting" will overwrite existing values, rather than shift
// the array contents and insert the new data at the specified location.
//
// .SECTION See Also
// vtkDataArray vtkStringArray vtkCellArray
......@@ -125,16 +138,16 @@ public:
// Also note that if allocation is performed no copy is performed so
// existing data will be lost (if data conservation is sought, one may
// use the Resize method instead).
virtual void SetNumberOfTuples(vtkIdType number) = 0;
virtual void SetNumberOfTuples(vtkIdType numTuples) = 0;
// Description:
// Specify the number of values for this object to hold. Does an
// allocation as well as setting the MaxId ivar. Used in conjunction with
// SetValue() method for fast insertion.
virtual void SetNumberOfValues(vtkIdType number);
// Specify the number of values (tuples * components) for this object to hold.
// Does an allocation as well as setting the MaxId ivar. Used in conjunction
// with SetValue() method for fast insertion.
virtual void SetNumberOfValues(vtkIdType numValues);
// Description:
// Get the number of tuples (a component group) in the array.
// Get the number of complete tuples (a component group) in the array.
vtkIdType GetNumberOfTuples()
{return (this->MaxId + 1)/this->NumberOfComponents;}
......@@ -149,16 +162,19 @@ public:
}
// Description:
// Set the tuple at the ith location using the jth tuple in the source array.
// This method assumes that the two arrays have the same type
// and structure. Note that range checking and memory allocation is not
// Set the tuple at dstTupleIdx in this array to the tuple at srcTupleIdx in
// the source array. This method assumes that the two arrays have the same
// type and structure. Note that range checking and memory allocation is not
// performed; use in conjunction with SetNumberOfTuples() to allocate space.
virtual void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source) = 0;
virtual void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
vtkAbstractArray *source) = 0;
// Description:
// Insert the jth tuple in the source array, at ith location in this array.
// Insert the tuple at srcTupleIdx in the source array into this array at
// dstTupleIdx.
// Note that memory allocation is performed as necessary to hold the data.
virtual void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source) = 0;
virtual void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
vtkAbstractArray* source) = 0;
// Description:
// Copy the tuples indexed in srcIds from the source array to the tuple
......@@ -175,19 +191,20 @@ public:
vtkAbstractArray* source) = 0;
// Description:
// Insert the jth tuple in the source array, at the end in this array.
// Note that memory allocation is performed as necessary to hold the data.
// Returns the location at which the data was inserted.
virtual vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray* source) = 0;
// Insert the tuple from srcTupleIdx in the source array at the end of this
// array. Note that memory allocation is performed as necessary to hold the
// data. Returns the tuple index at which the data was inserted.
virtual vtkIdType InsertNextTuple(vtkIdType srcTupleIdx,
vtkAbstractArray* source) = 0;
// Description:
// Given a list of point ids, return an array of tuples.
// Given a list of tuple ids, return an array of tuples.
// You must insure that the output array has been previously
// allocated with enough space to hold the data.
virtual void GetTuples(vtkIdList *ptIds, vtkAbstractArray* output);
virtual void GetTuples(vtkIdList *tupleIds, vtkAbstractArray* output);
// Description:
// Get the tuples for the range of points ids specified
// Get the tuples for the range of tuple ids specified
// (i.e., p1->p2 inclusive). You must insure that the output array has
// been previously allocated with enough space to hold the data.
virtual void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray *output);
......@@ -197,23 +214,15 @@ public:
// VTK user guide, e.g. a contiguous array:
// {t1c1, t1c2, t1c3, ... t1cM, t2c1, ... tNcM}
// where t1c2 is the second component of the first tuple.
//
// If the array does not have the standard memory layout GetVoidPointer should
// not be used, as a deep copy of the data must be made. Instead, use a
// vtkTypedDataArrayIterator to get pointer-like semantics that can safely
// access the data values.
//
// Subclasses that return false here must derive from vtkMappedDataArray
// to ensure that they will work safely with the rest of the pipeline.
virtual bool HasStandardMemoryLayout();
// Description:
// Return a void pointer. For image pipeline interface and other
// special pointer manipulation.
// If the data is simply being iterated over, consider using
// vtkDataArrayIteratorMacro for safety and efficiency, rather than using this
// member directly.
virtual void *GetVoidPointer(vtkIdType id) = 0;
// 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.
virtual void *GetVoidPointer(vtkIdType valueIdx) = 0;
// Description:
// Deep copy of data. Implementation left to subclasses, which
......@@ -225,24 +234,24 @@ public:
virtual void DeepCopy(vtkAbstractArray* da);
// Description:
// Set the ith tuple in this array as the interpolated tuple value,
// given the ptIndices in the source array and associated
// interpolation weights.
// Set the tuple at dstTupleIdx in this array to the interpolated tuple value,
// given the ptIndices in the source array and associated interpolation
// weights.
// This method assumes that the two arrays are of the same type
// and strcuture.
virtual void InterpolateTuple(vtkIdType i, vtkIdList *ptIndices,
vtkAbstractArray* source, double* weights) = 0;
virtual void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList *ptIndices,
vtkAbstractArray* source, double* weights) = 0;
// Description
// Insert the ith tuple in this array as interpolated from the two values,
// p1 and p2, and an interpolation factor, t.
// The interpolation factor ranges from (0,1),
// with t=0 located at p1. This method assumes that the three arrays are of
// the same type. p1 is value at index id1 in source1, while, p2 is
// value at index id2 in source2.
virtual void InterpolateTuple(vtkIdType i,
vtkIdType id1, vtkAbstractArray* source1,
vtkIdType id2, vtkAbstractArray* source2, double t) =0;
// Insert the tuple at dstTupleIdx in this array to the tuple interpolated
// from the two tuple indices, srcTupleIdx1 and srcTupleIdx2, and an
// interpolation factor, t. The interpolation factor ranges from (0,1),
// with t=0 located at the tuple described by srcTupleIdx1. This method
// assumes that the three arrays are of the same type, srcTupleIdx1 is an
// index to array source1, and srcTupleIdx2 is an index to array source2.
virtual void InterpolateTuple(vtkIdType dstTupleIdx,
vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) =0;
// Description:
// Free any unnecessary memory.
......@@ -359,23 +368,23 @@ public:
}
// Description:
// Return the indices where a specific value appears.
// Return the value indices where a specific value appears.
virtual vtkIdType LookupValue(vtkVariant value) = 0;
virtual void LookupValue(vtkVariant value, vtkIdList* ids) = 0;
virtual void LookupValue(vtkVariant value, vtkIdList* valueIds) = 0;
// Description:
// Retrieve value from the array as a variant.
virtual vtkVariant GetVariantValue(vtkIdType idx);
virtual vtkVariant GetVariantValue(vtkIdType valueIdx);
// Description:
// Insert a value into the array from a variant. This method does
// bounds checking.
virtual void InsertVariantValue(vtkIdType idx, vtkVariant value) = 0;
virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value) = 0;
// Description:
// Set a value in the array from a variant. This method does NOT do
// bounds checking.
virtual void SetVariantValue(vtkIdType idx, vtkVariant value) = 0;
virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value) = 0;
// Description:
// Tell the array explicitly that the data has changed.
......
......@@ -23,6 +23,19 @@
// implementations, and provide tools to lower compilation time and binary
// size (i.e. avoiding 'template explosions').
//
// vtkArrayDispatch is also intended to replace code that currently relies on
// the encapsulation-breaking vtkDataArray::GetVoidPointer method. Not all
// subclasses of vtkDataArray use the memory layout assumed by GetVoidPointer;
// calling this method on, e.g. a vtkSOADataArrayTemplate will trigger a deep
// copy of the array data into an AOS buffer. This is very inefficient and
// should be avoided.
//
// The vtkDataArrayAccessor wrapper is worth mentioning here, as it allows
// vtkArrayDispatch workers to operate on selected concrete subclasses for
// 'fast paths', yet fallback to using the slower vtkDataArray API for uncommon
// array types. This helps mitigate the "template explosion" issues that can
// result from instantiating a large worker functions for many array types.
//
// These dispatchers extend the basic functionality of vtkTemplateMacro with
// the following features:
// - Multiarray dispatch: A single call can dispatch up to 3 arrays at once.
......@@ -125,7 +138,7 @@
// Examples:
// See TestArrayDispatchers.cxx for examples of each dispatch type.
//
// .SEE ALSO
// .SECTION See Also
// vtkDataArrayAccessor
#ifndef vtkArrayDispatch_h
......
......@@ -25,6 +25,12 @@
// *always* be true. Beware that if cond is false at runtime, the results are
// unpredictable (and likely catastrophic). A runtime assertion is added so
// that debugging builds may easily catch violations of the condition.
//
// A useful application of this macro is when a vtkGenericDataArray subclass has
// a known number of components at compile time. Adding, for example,
// VTK_ASSUME(array->GetNumberOfComponents() == 3); allows the compiler to
// provide faster access through the GetTypedComponent method, as the fixed data
// stride in AOS arrays allows advanced optimization of the accesses.
#define VTK_ASSUME(cond) \
do { \
const bool c = cond; \
......
......@@ -511,7 +511,7 @@ void vtkDataArray::ShallowCopy(vtkDataArray *other)
}
//------------------------------------------------------------------------------
void vtkDataArray::SetTuple(vtkIdType thisTupleIdx, vtkIdType sourceTupleIdx,
void vtkDataArray::SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
vtkAbstractArray *source)
{
vtkDataArray *srcDA = vtkDataArray::FastDownCast(source);
......@@ -537,7 +537,7 @@ void vtkDataArray::SetTuple(vtkIdType thisTupleIdx, vtkIdType sourceTupleIdx,
return;
}
SetTupleArrayWorker worker(sourceTupleIdx, thisTupleIdx);
SetTupleArrayWorker worker(srcTupleIdx, dstTupleIdx);
if (!vtkArrayDispatch::Dispatch2SameValueType::Execute(srcDA, this, worker))
{
worker(srcDA, this);
......@@ -563,13 +563,13 @@ void vtkDataArray::SetTuple(vtkIdType i, const double *source)
}
//----------------------------------------------------------------------------
void vtkDataArray::InsertTuple(vtkIdType dstTuple, vtkIdType srcTuple,
void vtkDataArray::InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
vtkAbstractArray *source)
{
vtkIdType newSize = (dstTuple + 1) * this->NumberOfComponents;
vtkIdType newSize = (dstTupleIdx + 1) * this->NumberOfComponents;
if (this->Size < newSize)
{
if (!this->Resize(dstTuple + 1))
if (!this->Resize(dstTupleIdx + 1))
{
vtkErrorMacro("Resize failed.");
return;
......@@ -578,14 +578,15 @@ void vtkDataArray::InsertTuple(vtkIdType dstTuple, vtkIdType srcTuple,
this->MaxId = std::max(this->MaxId, newSize - 1);
this->SetTuple(dstTuple, srcTuple, source);
this->SetTuple(dstTupleIdx, srcTupleIdx, source);
}
//----------------------------------------------------------------------------
vtkIdType vtkDataArray::InsertNextTuple(vtkIdType j, vtkAbstractArray *source)
vtkIdType vtkDataArray::InsertNextTuple(vtkIdType srcTupleIdx,
vtkAbstractArray *source)
{
vtkIdType tupleIdx = this->GetNumberOfTuples();
this->InsertTuple(tupleIdx, j, source);
this->InsertTuple(tupleIdx, srcTupleIdx, source);
return tupleIdx;
}
......@@ -721,25 +722,25 @@ void vtkDataArray::InsertTuples(vtkIdType dstStart, vtkIdType n,