Commit a025c550 authored by David C. Lonie's avatar David C. Lonie

Add vtkDataArray::ShallowCopy(vtkDataArray*).

Just copy vtkBuffer instances around, when possible.
Added reference counting to vtkBuffer (add vtkObject base).
Added test in TestDataArrayAPI.

Also removed some unused ivars from vtkAOSDataArrayTemplate
(SaveUserArray, DeleteMethod are stored in vtkBuffer).
parent 1688a73d
......@@ -109,6 +109,7 @@ int @VTK_TESTDATAARRAYAPI_TESTNAME@(int, char *[])
#define DataArrayAPIFinish() return errors
#define DataArrayAPICreateTestArray(name) vtkNew<ArrayT> name
#define DataArrayAPICreateTestArrayByType(name, type) vtkNew<type> name
#define DataArrayAPICreateReferenceArray(name) \
vtkSmartPointer<vtkDataArray> name##DA = CreateDataArray<ScalarT>(); \
......@@ -941,6 +942,169 @@ int Test_voidPtr_GetVoidPointer()
DataArrayAPIFinish();
}
// operator() returns true if the memory is shared between two arrays, if
// the arrays support true shallow copies.
// NOTE: This will NOT properly test the case where, e.g., vtkFloatArray is
// used, as template resolution will not cast vtkFloatArray into
// vtkAOSDataArrayTemplate<float>. This will go through the generic
// implementation which always returns true. This is fine, however, since
// we explicitly test vtkAOSDataArrayTemplates as well as the vtk{type}Arrays,
// so the explicit AOS tests will detect failures.
struct CheckShallowCopy
{
// Mismatched arrays -- these will not shallow copy, always return true.
template <typename Array1T, typename Array2T>
bool operator()(Array1T *, Array2T *) { return true; }
// AOS same-ValueType case:
template <typename ValueType>
bool operator()(vtkAOSDataArrayTemplate<ValueType> *a1,
vtkAOSDataArrayTemplate<ValueType> *a2)
{
return a1->GetPointer(0) == a2->GetPointer(0);
}
// SOA same-ValueType case:
template <typename ValueType>
bool operator()(vtkSOADataArrayTemplate<ValueType> *a1,
vtkSOADataArrayTemplate<ValueType> *a2)
{
assert(a1->GetNumberOfComponents() == a2->GetNumberOfComponents());
for (int c = 0; c < a1->GetNumberOfComponents(); ++c)
{
if (a1->GetComponentArrayPointer(c) != a2->GetComponentArrayPointer(c))
{
return false;
}
}
return true;
}
};
// void ShallowCopy(vtkDataArray *other)
// Shallow copies AOS/SOA arrays if and only if arrays are the same type,
// otherwise deep copies.
// Test copying into and from the target array type.
// Allocates memory as needed.
// ArgT switches between the two overloads.
// OtherT is the type of array that will be copied to/from.
template <typename ScalarT, typename ArrayT, typename OtherArrayT>
int Test_void_ShallowCopy_array()
{
DataArrayAPIInit("void ShallowCopy(vtkDataArray *other)");
typedef typename OtherArrayT::ValueType OtherScalarT;
std::string testType = vtkTypeTraits<ScalarT>::Name();
std::string otherType = vtkTypeTraits<OtherScalarT>::Name();
DataArrayAPICreateTestArray(source);
DataArrayAPICreateTestArrayByType(middle, OtherArrayT);
DataArrayAPICreateTestArray(target);
CheckShallowCopy memChecker;
// Initialize source array:
vtkIdType comps = 9;
vtkIdType tuples = 40;
source->SetNumberOfComponents(comps);
source->SetNumberOfTuples(tuples);
for (vtkIdType t = 0; t < tuples; ++t)
{
for (int c = 0; c < comps; ++c)
{
source->SetComponent(t, c, static_cast<double>(((t * comps) + c) % 17));
}
}
// Copy to intermediate:
middle->ShallowCopy(source.GetPointer());
// Verify intermediate:
if (middle->GetNumberOfComponents() != comps ||
middle->GetNumberOfTuples() != tuples)
{
DataArrayAPIError("Incorrect size of array after copying from test array "
"(scalar type: '" << testType << "') to reference array "
"(scalar type: '" << otherType << "'): Expected number "
"of (tuples, components): " << "(" << tuples << ", "
<< comps << "), got (" << middle->GetNumberOfTuples()
<< ", " << middle->GetNumberOfComponents() << ").");
}
for (vtkIdType t = 0; t < tuples; ++t)
{
for (int c = 0; c < comps; ++c)
{
double ref = ((t * comps) + c) % 17;
double test = middle->GetComponent(t, c);
if (ref != test)
{
DataArrayAPIError("Data mismatch after copying from test array (scalar "
"type: '" << testType << "') to reference array "
"(scalar type: '" << otherType << "'): " "Data "
"mismatch at tuple " << t << " component " << c
<< ": Expected " << ref << ", got " << test << ".");
}
}
}
if (!memChecker(source.GetPointer(), middle.GetPointer()))
{
DataArrayAPIError("Memory is not shared following shallow copy.\n"
"Copying source --> middle;\n"
"source = " << source->GetClassName() << " ("
<< testType << ")\n"
"middle = " << middle->GetClassName() << " ("
<< otherType << ")");
}
// Copy to final:
target->ShallowCopy(middle.GetPointer());
// Verify final:
if (target->GetNumberOfComponents() != comps ||
target->GetNumberOfTuples() != tuples)
{
DataArrayAPIError("Incorrect size of array after copying from reference "
"array (scalar type: '" << otherType << "') to test "
"array (scalar type: '" << testType << "'): "
"Expected number of (tuples, components): "
<< "(" << tuples << ", " << comps << "), got ("
<< target->GetNumberOfTuples() << ", "
<< target->GetNumberOfComponents() << ").");
}
for (vtkIdType t = 0; t < tuples; ++t)
{
for (int c = 0; c < comps; ++c)
{
double ref = ((t * comps) + c) % 17;
double test = target->GetComponent(t, c);
if (ref != test)
{
DataArrayAPIError("Data mismatch after copying from reference array "
"(scalar type: '" << otherType << "') to test array "
"(scalar type: '" << testType << "'): " "Data "
"mismatch at tuple " << t << " component " << c
<< ": Expected " << ref << ", got " << test << ".");
}
}
}
if (!memChecker(middle.GetPointer(), target.GetPointer()))
{
DataArrayAPIError("Memory is not shared following shallow copy.\n"
"Copying middle --> target;\n"
"middle = " << middle->GetClassName() << " ("
<< otherType << ")\n"
"target = " << target->GetClassName() << " ("
<< testType << ")");
}
DataArrayAPIFinish();
}
// void DeepCopy(vtkAbstractArray *aa)
// void DeepCopy(vtkDataArray *da)
// Test copying into and from the target array type.
......@@ -2948,6 +3112,34 @@ int ExerciseDataArray()
errors += Test_void_InsertComponent_i_j_c<ScalarT, ArrayT>();
errors += Test_voidptr_WriteVoidPointer_id_number<ScalarT, ArrayT>();
errors += Test_void_CreateDefaultLookupTable<ScalarT, ArrayT>();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkAOSDataArrayTemplate<char> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkAOSDataArrayTemplate<float> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkAOSDataArrayTemplate<double> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkAOSDataArrayTemplate<vtkIdType> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkAOSDataArrayTemplate<int> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkAOSDataArrayTemplate<long> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkAOSDataArrayTemplate<long long> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkAOSDataArrayTemplate<short> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkAOSDataArrayTemplate<signed char> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkAOSDataArrayTemplate<unsigned char> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkAOSDataArrayTemplate<unsigned int> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkAOSDataArrayTemplate<unsigned long> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkAOSDataArrayTemplate<unsigned long long> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkAOSDataArrayTemplate<unsigned short> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkSOADataArrayTemplate<char> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkSOADataArrayTemplate<float> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkSOADataArrayTemplate<double> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkSOADataArrayTemplate<vtkIdType> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkSOADataArrayTemplate<int> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkSOADataArrayTemplate<long> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkSOADataArrayTemplate<long long> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkSOADataArrayTemplate<short> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkSOADataArrayTemplate<signed char> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkSOADataArrayTemplate<unsigned char> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkSOADataArrayTemplate<unsigned int> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkSOADataArrayTemplate<unsigned long> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkSOADataArrayTemplate<unsigned long long> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkSOADataArrayTemplate<unsigned short> >();
errors += Test_doubleptr_GetTupleN_i<ScalarT, ArrayT, 1>();
errors += Test_doubleptr_GetTupleN_i<ScalarT, ArrayT, 2>();
errors += Test_doubleptr_GetTupleN_i<ScalarT, ArrayT, 3>();
......
......@@ -52,28 +52,28 @@ public:
// **************************************************************************
inline ValueType GetValue(vtkIdType valueIdx) const
{
return this->Buffer.GetBuffer()[valueIdx];
return this->Buffer->GetBuffer()[valueIdx];
}
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,
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];
return this->Buffer->GetBuffer()[this->NumberOfComponents*index + comp];
}
inline void SetValue(vtkIdType valueIdx, ValueType value)
{
this->Buffer.GetBuffer()[valueIdx] = value;
this->Buffer->GetBuffer()[valueIdx] = value;
}
inline void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
{
const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents;
std::copy(tuple, tuple + this->NumberOfComponents,
this->Buffer.GetBuffer() + valueIdx);
this->Buffer->GetBuffer() + valueIdx);
}
inline void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
{
......@@ -81,6 +81,8 @@ public:
this->SetValue(valueIdx, value);
}
virtual void ShallowCopy(vtkDataArray *other);
// **************************************************************************
// Description:
// Get the address of a particular data index. Make sure data is allocated
......@@ -96,7 +98,7 @@ public:
// 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; }
ValueType* GetPointer(vtkIdType id) { return this->Buffer->GetBuffer() + id; }
virtual void* GetVoidPointer(vtkIdType id) { return this->GetPointer(id); }
enum DeleteMethod
......@@ -182,10 +184,8 @@ protected:
bool ReallocateTuples(vtkIdType numTuples);
// **************************************************************************
vtkBuffer<ValueType> Buffer;
vtkBuffer<ValueType> *Buffer;
ValueType ValueRange[2]; // XXX
bool SaveUserArray;
int DeleteMethod;
private:
vtkAOSDataArrayTemplate(const vtkAOSDataArrayTemplate&); // Not implemented.
......
......@@ -33,8 +33,7 @@ vtkAOSDataArrayTemplateT(vtkAOSDataArrayTemplate<ValueType>*)::New()
template <class ValueType>
vtkAOSDataArrayTemplate<ValueType>::vtkAOSDataArrayTemplate()
{
this->SaveUserArray = false;
this->DeleteMethod = VTK_DATA_ARRAY_FREE;
this->Buffer = vtkBuffer<ValueType>::New();
}
//-----------------------------------------------------------------------------
......@@ -42,14 +41,14 @@ template <class ValueType>
vtkAOSDataArrayTemplate<ValueType>::~vtkAOSDataArrayTemplate()
{
this->SetArray(NULL, 0, 0);
this->Buffer.SetBuffer(NULL, 0);
this->Buffer->Delete();
}
//-----------------------------------------------------------------------------
vtkAOSDataArrayTemplateT(void)::SetArray(
ValueType* array, vtkIdType size, int save, int deleteMethod)
{
this->Buffer.SetBuffer(array, size, save != 0, deleteMethod);
this->Buffer->SetBuffer(array, size, save != 0, deleteMethod);
this->Size = size;
this->MaxId = this->Size - 1;
this->DataChanged();
......@@ -63,6 +62,32 @@ vtkAOSDataArrayTemplateT(vtkArrayIterator*)::NewIterator()
return iter;
}
//-----------------------------------------------------------------------------
template <class ValueTypeT>
void vtkAOSDataArrayTemplate<ValueTypeT>::ShallowCopy(vtkDataArray *other)
{
SelfType *o = SelfType::FastDownCast(other);
if (o)
{
this->Size = o->Size;
this->MaxId = o->MaxId;
this->SetName(o->Name);
this->SetNumberOfComponents(o->NumberOfComponents);
this->CopyComponentNames(o);
if (this->Buffer != o->Buffer)
{
this->Buffer->Delete();
this->Buffer = o->Buffer;
this->Buffer->Register(NULL);
}
this->DataChanged();
}
else
{
this->Superclass::ShallowCopy(other);
}
}
//-----------------------------------------------------------------------------
template <class ValueTypeT>
typename vtkAOSDataArrayTemplate<ValueTypeT>::ValueType*
......@@ -90,9 +115,9 @@ vtkAOSDataArrayTemplate<ValueTypeT>::WritePointer(vtkIdType id,
vtkAOSDataArrayTemplateT(bool)::AllocateTuples(vtkIdType numTuples)
{
vtkIdType numValues = numTuples * this->GetNumberOfComponents();
if (this->Buffer.Allocate(numValues))
if (this->Buffer->Allocate(numValues))
{
this->Size = this->Buffer.GetSize();
this->Size = this->Buffer->GetSize();
return true;
}
return false;
......@@ -101,9 +126,9 @@ vtkAOSDataArrayTemplateT(bool)::AllocateTuples(vtkIdType numTuples)
//-----------------------------------------------------------------------------
vtkAOSDataArrayTemplateT(bool)::ReallocateTuples(vtkIdType numTuples)
{
if (this->Buffer.Reallocate(numTuples * this->GetNumberOfComponents()))
if (this->Buffer->Reallocate(numTuples * this->GetNumberOfComponents()))
{
this->Size = this->Buffer.GetSize();
this->Size = this->Buffer->GetSize();
return true;
}
return false;
......
......@@ -23,11 +23,13 @@
#define vtkBuffer_h
#include "vtkObject.h"
#include "vtkObjectFactory.h" // New() implementation
template <class ScalarTypeT>
class vtkBuffer
class vtkBuffer : public vtkObject
{
public:
vtkTypeMacro(vtkBuffer, vtkObject)
typedef ScalarTypeT ScalarType;
enum DeleteMethod
{
......@@ -35,17 +37,7 @@ public:
VTK_DATA_ARRAY_DELETE
};
vtkBuffer()
: Pointer(NULL),
Size(0),
Save(false),
DeleteMethod(VTK_DATA_ARRAY_FREE)
{
}
~vtkBuffer()
{
}
static vtkBuffer<ScalarTypeT>* New();
inline ScalarType* GetBuffer() const
{ return this->Pointer; }
......@@ -136,11 +128,33 @@ public:
}
protected:
vtkBuffer()
: Pointer(NULL),
Size(0),
Save(false),
DeleteMethod(VTK_DATA_ARRAY_FREE)
{
}
~vtkBuffer()
{
this->SetBuffer(NULL, 0);
}
ScalarType *Pointer;
vtkIdType Size;
bool Save;
int DeleteMethod;
private:
vtkBuffer(const vtkBuffer&); // Not implemented.
void operator=(const vtkBuffer&); // Not implemented.
};
template <class ScalarT>
inline vtkBuffer<ScalarT> *vtkBuffer<ScalarT>::New()
{
VTK_STANDARD_NEW_BODY(vtkBuffer<ScalarT>)
}
#endif
// VTK-HeaderTest-Exclude: vtkBuffer.h
......@@ -503,6 +503,13 @@ void vtkDataArray::DeepCopy(vtkDataArray *da)
this->Squeeze();
}
//------------------------------------------------------------------------------
void vtkDataArray::ShallowCopy(vtkDataArray *other)
{
// Deep copy by default. Subclasses may override this behavior.
this->DeepCopy(other);
}
//------------------------------------------------------------------------------
void vtkDataArray::SetTuple(vtkIdType thisTupleIdx, vtkIdType sourceTupleIdx,
vtkAbstractArray *source)
......
......@@ -272,6 +272,16 @@ public:
virtual void DeepCopy(vtkAbstractArray *aa);
virtual void DeepCopy(vtkDataArray *da);
// Description:
// Create a shallow copy of other into this, if possible. Shallow copies are
// only possible:
// (a) if both arrays are the same data type
// (b) if both arrays are the same array type (e.g. AOS vs. SOA)
// (c) if both arrays support shallow copies (e.g. vtkBitArray currently
// does not.)
// If a shallow copy is not possible, a deep copy will be performed instead.
virtual void ShallowCopy(vtkDataArray *other);
// Description:
// Fill a component of a data array with a specified value. This method
// sets the specified component to specified value for all tuples in the
......
......@@ -51,12 +51,12 @@ public:
{
for (size_t cc=0; cc < this->Data.size(); cc++)
{
tuple[cc] = this->Data[cc].GetBuffer()[tupleIdx];
tuple[cc] = this->Data[cc]->GetBuffer()[tupleIdx];
}
}
inline ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
{
return this->Data[comp].GetBuffer()[tupleIdx];
return this->Data[comp]->GetBuffer()[tupleIdx];
}
inline void SetValue(vtkIdType valueIdx, ValueType value)
{
......@@ -69,16 +69,18 @@ public:
{
for (size_t cc=0; cc < this->Data.size(); ++cc)
{
this->Data[cc].GetBuffer()[tupleIdx] = tuple[cc];
this->Data[cc]->GetBuffer()[tupleIdx] = tuple[cc];
}
}
inline void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
{
this->Data[comp].GetBuffer()[tupleIdx] = value;
this->Data[comp]->GetBuffer()[tupleIdx] = value;
}
// **************************************************************************
virtual void ShallowCopy(vtkDataArray *other);
enum DeleteMethod
{
VTK_DATA_ARRAY_FREE=vtkBuffer<ValueType>::VTK_DATA_ARRAY_FREE,
......@@ -169,8 +171,8 @@ protected:
bool ReallocateTuples(vtkIdType numTuples);
// **************************************************************************
std::vector<vtkBuffer<ValueType> > Data;
vtkBuffer<ValueType> AoSCopy;
std::vector<vtkBuffer<ValueType>*> Data;
vtkBuffer<ValueType> *AoSCopy;
bool Resizeable;
double NumberOfComponentsReciprocal;
private:
......
......@@ -34,8 +34,9 @@ vtkSOADataArrayTemplate<ValueType>::New()
//-----------------------------------------------------------------------------
template<class ValueType>
vtkSOADataArrayTemplate<ValueType>::vtkSOADataArrayTemplate()
: Resizeable(true),
NumberOfComponentsReciprocal(1.0)
: AoSCopy(NULL),
Resizeable(true),
NumberOfComponentsReciprocal(1.0)
{
}
......@@ -45,7 +46,13 @@ vtkSOADataArrayTemplate<ValueType>::~vtkSOADataArrayTemplate()
{
for (size_t cc = 0; cc < this->Data.size(); ++cc)
{
this->Data[cc].SetBuffer(NULL, 0);
this->Data[cc]->Delete();
}
this->Data.clear();
if (this->AoSCopy)
{
this->AoSCopy->Delete();
this->AoSCopy = NULL;
}
}
......@@ -58,10 +65,13 @@ void vtkSOADataArrayTemplate<ValueType>::SetNumberOfComponents(int val)
assert(numComps >= 1);
while (this->Data.size() > numComps)
{
this->Data.back().SetBuffer(NULL, 0);
this->Data.back()->Delete();
this->Data.pop_back();
}
this->Data.resize(numComps);
while (this->Data.size() < numComps)
{
this->Data.push_back(vtkBuffer<ValueType>::New());
}
this->NumberOfComponentsReciprocal = 1.0 / this->NumberOfComponents;
}
......@@ -74,6 +84,38 @@ vtkArrayIterator* vtkSOADataArrayTemplate<ValueType>::NewIterator()
return iter;
}
//-----------------------------------------------------------------------------
template<class ValueType>
void vtkSOADataArrayTemplate<ValueType>::ShallowCopy(vtkDataArray *other)
{
SelfType *o = SelfType::FastDownCast(other);
if (o)
{
this->Size = o->Size;
this->MaxId = o->MaxId;
this->SetName(o->Name);
this->SetNumberOfComponents(o->NumberOfComponents);
this->CopyComponentNames(o);
assert(this->Data.size() == o->Data.size());
for (size_t cc = 0; cc < this->Data.size(); ++cc)
{
vtkBuffer<ValueType> *thisBuffer = this->Data[cc];
vtkBuffer<ValueType> *otherBuffer = o->Data[cc];
if (thisBuffer != otherBuffer)
{
thisBuffer->Delete();
this->Data[cc] = otherBuffer;
otherBuffer->Register(NULL);
}
}
this->DataChanged();
}
else
{
this->Superclass::ShallowCopy(other);
}
}
//-----------------------------------------------------------------------------
template<class ValueType>
void vtkSOADataArrayTemplate<ValueType>::SetArray(int comp, ValueType* array,
......@@ -89,7 +131,7 @@ void vtkSOADataArrayTemplate<ValueType>::SetArray(int comp, ValueType* array,
return;
}
this->Data[comp].SetBuffer(array, size, save, deleteMethod);
this->Data[comp]->SetBuffer(array, size, save, deleteMethod);
if (updateMaxId)
{
this->Size = numComps * size;
......@@ -110,7 +152,7 @@ vtkSOADataArrayTemplate<ValueType>::GetComponentArrayPointer(int comp)
return NULL;
}
return this->Data[comp].GetBuffer();
return this->Data[comp]->GetBuffer();
}
//-----------------------------------------------------------------------------
......@@ -122,7 +164,7 @@ bool vtkSOADataArrayTemplate<ValueType>::AllocateTuples(vtkIdType numTuples)
vtkIdType minTuples = VTK_ID_MAX;
for (size_t cc = 0, max = this->Data.size(); cc < max; cc++)
{
minTuples = std::min(minTuples, this->Data[cc].GetSize());
minTuples = std::min(minTuples, this->Data[cc]->GetSize());
}
if (numTuples <= minTuples)
{
......@@ -138,7 +180,7 @@ bool vtkSOADataArrayTemplate<ValueType>::AllocateTuples(vtkIdType numTuples)
for (size_t cc = 0, max = this->Data.size(); cc < max; ++cc)
{
if (!this->Data[cc].Allocate(numTuples))
if (!this->Data[cc]->Allocate(numTuples))
{
return false;
}
......@@ -155,7 +197,7 @@ bool vtkSOADataArrayTemplate<ValueType>::ReallocateTuples(vtkIdType numTuples)
vtkIdType minTuples = VTK_ID_MAX;
for (size_t cc = 0, max = this->Data.size(); cc < max; cc++)
{
minTuples = std::min(minTuples, this->Data[cc].GetSize());
minTuples = std::min(minTuples, this->Data[cc]->GetSize());
}
if (numTuples <= minTuples)
{
......@@ -167,7 +209,7 @@ bool vtkSOADataArrayTemplate<ValueType>::ReallocateTuples(vtkIdType numTuples)
for (size_t cc = 0, max = this->Data.size(); cc < max; ++cc)
{
if (!this->Data[cc].Reallocate(numTuples))
if (!this->Data[cc]->Reallocate(numTuples))
{
return false;
}
......@@ -194,16 +236,21 @@ void *vtkSOADataArrayTemplate<ValueType>::GetVoidPointer(vtkIdType id)
size_t numValues = this->GetNumberOfValues();
if (!this->AoSCopy.Allocate(numValues))
if (!this->AoSCopy)
{
this->AoSCopy = vtkBuffer<ValueType>::New();
}
if (!this->AoSCopy->Allocate(numValues))
{
vtkErrorMacro(<<"Error allocating a buffer of " << numValues << " '"
<< this->GetDataTypeAsString() << "' elements.");
return NULL;
}
this->ExportToVoidPointer(static_cast<void*>(this->AoSCopy.GetBuffer()));
this->ExportToVoidPointer(static_cast<void*>(this->AoSCopy->GetBuffer()));
return static_cast<void*>(this->AoSCopy.GetBuffer() + id);
return static_cast<void*>(this->AoSCopy->GetBuffer() + id);
}
//-----------------------------------------------------------------------------
......@@ -228,7 +275,7 @@ void vtkSOADataArrayTemplate<ValueType>::ExportToVoidPointer(void *voidPtr)
{
for (int c = 0; c < this->NumberOfComponents; ++c)
{
*ptr++ = this->Data[c].GetBuffer()[t];
*ptr++ = this->Data[c]->GetBuffer()[t];
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment