Commit 5bc5cc75 authored by David C. Lonie's avatar David C. Lonie

Move vtkPeriodicDataArray to inherit vtkGenericDataArray.

parent ea2e02e2
......@@ -18,7 +18,6 @@
#include "vtkTypedDataArray.h"
#include "vtkTypedDataArrayIterator.h"
#include "vtkNew.h"
#include "vtkPeriodicDataArray.h" // a typed data array subclass implementation
#include <cassert>
#include <iostream>
......@@ -26,19 +25,41 @@
// undefine this to print benchmark results:
#define SILENT
// Since vtkFloatArray etc are no longer derived from vtkTypedDataArray,
// create a simple class that is:
// Create a subclass of vtkTypedDataArray:
namespace
{
class MyArray : public vtkPeriodicDataArray<float>
class MyArray : public vtkTypedDataArray<float>
{
vtkFloatArray *Data;
public:
vtkTypeMacro(MyArray, vtkPeriodicDataArray<float>)
static MyArray *New();
void Transform(float *) const {/*no op*/}
vtkTypeMacro(MyArray, vtkTypedDataArray<float>)
static MyArray *New() { return new MyArray; }
void Init(vtkFloatArray *array)
{
this->Data = array;
this->NumberOfComponents = array->GetNumberOfComponents();
this->MaxId = array->GetMaxId();
}
ValueType& GetValueReference(vtkIdType idx)
{
return *this->Data->GetPointer(idx);
}
// These pure virtuals are no-op -- all we care about is GetValueReference
// to test the iterator.
void SetTypedTuple(vtkIdType, const ValueType *) {}
void InsertTypedTuple(vtkIdType, const ValueType *) {}
vtkIdType InsertNextTypedTuple(const ValueType *) { return 0; }
vtkIdType LookupTypedValue(ValueType) { return 0; }
void LookupTypedValue(ValueType, vtkIdList*) {}
ValueType GetValue(vtkIdType) const { return 0; }
void SetValue(vtkIdType, ValueType) {}
void GetTypedTuple(vtkIdType, ValueType*) const {}
vtkIdType InsertNextValue(ValueType) { return 0; }
void InsertValue(vtkIdType, ValueType) {}
int Allocate(vtkIdType, vtkIdType) { return 0; }
int Resize(vtkIdType) { return 0; }
};
vtkStandardNewMacro(MyArray)
}
int TestDataArrayIterators(int, char *[])
......@@ -61,7 +82,7 @@ int TestDataArrayIterators(int, char *[])
// Create the vtkTypedDataArray testing implementation:
vtkNew<MyArray> tdaContainer;
MyArray *tda = tdaContainer.GetPointer();
tda->InitializeArray(array);
tda->Init(array);
// should be vtkAOSDataArrayTemplate<float>::Iterator (float*):
vtkFloatArray::Iterator datBegin = array->Begin();
......@@ -114,7 +135,7 @@ int TestDataArrayIterators(int, char *[])
timer->StartTimer();
for (vtkIdType i = 0; i < numValues; ++i)
{
lookupSum += array->GetValueReference(i);
lookupSum += *array->GetPointer(i);
}
timer->StopTimer();
double lookupTime = timer->GetElapsedTime();
......@@ -131,8 +152,7 @@ int TestDataArrayIterators(int, char *[])
double datTime = timer->GetElapsedTime();
// vtkTypedDataArrayIterator:
vtkTypedDataArray<float>::Iterator tdaEnd =
vtkTypedDataArray<float>::FastDownCast(array)->End();
vtkTypedDataArray<float>::Iterator tdaEnd = tda->End();
float tdaSum = 0.f;
timer->StartTimer();
while (tdaBegin != tdaEnd)
......
......@@ -40,7 +40,7 @@ class vtkAngularPeriodicDataArray: public vtkPeriodicDataArray<Scalar>
public:
vtkAbstractTemplateTypeMacro(vtkAngularPeriodicDataArray<Scalar>,
vtkPeriodicDataArray<Scalar>)
vtkMappedDataArrayNewInstanceMacro(vtkAngularPeriodicDataArray<Scalar>);
vtkAOSArrayNewInstanceMacro(vtkAngularPeriodicDataArray<Scalar>)
static vtkAngularPeriodicDataArray *New();
virtual void PrintSelf(ostream &os, vtkIndent indent);
......
......@@ -75,6 +75,10 @@ public:
typedef ValueTypeT ValueType;
vtkTemplateTypeMacro(SelfType, vtkDataArray)
// Description:
// Compile time access to the VTK type identifier.
enum { VTK_DATA_TYPE = vtkTypeTraits<ValueType>::VTK_TYPE_ID };
/// @defgroup vtkGDAConceptMethods vtkGenericDataArray Concept Methods
/// These signatures must be reimplemented in subclasses as public,
/// non-virtual methods. Ideally, they should be inlined and as efficient as
......@@ -270,5 +274,25 @@ private:
};
#include "vtkGenericDataArray.txx"
// Adds an implementation of NewInstanceInternal() that returns an AoS
// (unmapped) VTK array, if possible. This allows the pipeline to copy and
// propagate the array when the array data is not modifiable. Use this in
// combination with vtkAbstractTypeMacro or vtkAbstractTemplateTypeMacro
// (instead of vtkTypeMacro) to avoid adding the default NewInstance
// implementation.
#define vtkAOSArrayNewInstanceMacro(thisClass) \
protected: \
vtkObjectBase *NewInstanceInternal() const \
{ \
if (vtkDataArray *da = \
vtkDataArray::CreateDataArray(thisClass::VTK_DATA_TYPE)) \
{ \
return da; \
} \
return thisClass::New(); \
} \
public:
#endif
// VTK-HeaderTest-Exclude: vtkGenericDataArray.h
......@@ -132,7 +132,7 @@ vtkArrayDownCast_TemplateFastCastMacro(vtkMappedDataArray)
#include "vtkMappedDataArray.txx"
// Adds an implementation of NewInstanceInternal() that returns a standard
// Adds an implementation of NewInstanceInternal() that returns an AoS
// (unmapped) VTK array, if possible. Use this in combination with
// vtkAbstractTemplateTypeMacro when your subclass is a template class.
// Otherwise, use vtkMappedDataArrayTypeMacro.
......
......@@ -26,14 +26,16 @@
#ifndef vtkPeriodicDataArray_h
#define vtkPeriodicDataArray_h
#include "vtkMappedDataArray.h" // Parent
#include "vtkGenericDataArray.h" // Parent
#include "vtkAOSDataArrayTemplate.h" // Template
template <class Scalar>
class vtkPeriodicDataArray: public vtkMappedDataArray<Scalar>
class vtkPeriodicDataArray:
public vtkGenericDataArray<vtkPeriodicDataArray<Scalar>, Scalar>
{
typedef vtkGenericDataArray<vtkPeriodicDataArray<Scalar>, Scalar> GenericBase;
public:
vtkTemplateTypeMacro(vtkPeriodicDataArray<Scalar>, vtkMappedDataArray<Scalar>)
vtkTemplateTypeMacro(vtkPeriodicDataArray<Scalar>, GenericBase)
typedef typename Superclass::ValueType ValueType;
virtual void PrintSelf(ostream &os, vtkIndent indent);
......@@ -111,6 +113,12 @@ public:
// Copy tuple value at location idx into provided array
void GetTypedTuple(vtkIdType idx, Scalar *t) const;
// Description:
// Return the requested component of the specified tuple.
// Warning, this internally calls GetTypedTuple, so it is an inefficient way
// of reading all data.
ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const;
// Description:
// Return the memory in kilobytes consumed by this data array.
unsigned long GetActualMemorySize();
......@@ -215,6 +223,10 @@ public:
// Read only container, not supported.
void SetTypedTuple(vtkIdType i, const Scalar *t);
// Description:
// Read only container, not supported.
void SetTypedComponent(vtkIdType t, int c, Scalar v);
// Description:
// Read only container, not supported.
void InsertTypedTuple(vtkIdType i, const Scalar *t);
......@@ -244,6 +256,11 @@ protected:
vtkPeriodicDataArray();
~vtkPeriodicDataArray();
// Description:
// Read only container, not supported.
bool AllocateTuples(vtkIdType numTuples);
bool ReallocateTuples(vtkIdType numTuples);
// Description:
// Transform the provided tuple
virtual void Transform(Scalar* tuple) const = 0;
......@@ -270,6 +287,8 @@ private:
vtkPeriodicDataArray(const vtkPeriodicDataArray &); // Not implemented.
void operator=(const vtkPeriodicDataArray &); // Not implemented.
friend class vtkGenericDataArray<vtkPeriodicDataArray<Scalar>, Scalar>;
Scalar* TempScalarArray; // Temporary array used by GetTypedTuple methods
double* TempDoubleArray; // Temporary array used by GetTuple vethods
vtkIdType TempTupleIdx; // Location of currently stored Temp Tuple to use as cache
......
......@@ -373,6 +373,22 @@ template <class Scalar> void vtkPeriodicDataArray<Scalar>
this->Transform(tuple);
}
//------------------------------------------------------------------------------
template <class Scalar>
typename vtkPeriodicDataArray<Scalar>::ValueType
vtkPeriodicDataArray<Scalar>::GetTypedComponent(vtkIdType tupleId,
int compId) const
{
if (tupleId != this->TempTupleIdx)
{
this->Data->GetTypedTuple(tupleId, this->TempScalarArray);
this->Transform(const_cast<Scalar*>(this->TempScalarArray));
*const_cast<vtkIdType*>(&this->TempTupleIdx) = tupleId;
}
return this->TempScalarArray[compId];
}
//------------------------------------------------------------------------------
template <class Scalar> unsigned long int vtkPeriodicDataArray<Scalar>
::GetActualMemorySize()
......@@ -556,6 +572,13 @@ template <class Scalar> void vtkPeriodicDataArray<Scalar>
vtkErrorMacro("Read only container.");
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkPeriodicDataArray<Scalar>
::SetTypedComponent(vtkIdType, int, Scalar)
{
vtkErrorMacro("Read only container.");
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkPeriodicDataArray<Scalar>
::InsertTypedTuple(vtkIdType, const Scalar*)
......@@ -593,6 +616,22 @@ template <class Scalar> void vtkPeriodicDataArray<Scalar>
vtkErrorMacro("Read only container.");
}
//------------------------------------------------------------------------------
template <class Scalar> bool vtkPeriodicDataArray<Scalar>
::AllocateTuples(vtkIdType)
{
vtkErrorMacro("Read only container.");
return false;
}
//------------------------------------------------------------------------------
template <class Scalar> bool vtkPeriodicDataArray<Scalar>
::ReallocateTuples(vtkIdType)
{
vtkErrorMacro("Read only container.");
return false;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkPeriodicDataArray<Scalar>
::InvalidateRange()
......
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