Commit 893fb6ed authored by David C. Lonie's avatar David C. Lonie

Refactor data array APIs.

vtkDataArray subclasses now use

ComponentValue --> TypedComponent
TupleValue --> TypedValue

for their type-specific methods.

# Conflicts:
#	Rendering/Annotation/vtkScalarBarActor.cxx
parent 9e642707
......@@ -230,9 +230,9 @@ void vtkPlot3D::SetColors(vtkDataArray *colorArr)
double value = colorArr->GetComponent(i, 0);
unsigned char *rgb = lookupTable->MapValue(value);
const unsigned char constRGB[3] = { rgb[0], rgb[1], rgb[2] };
this->Colors->InsertNextTupleValue(&constRGB[0]);
this->Colors->InsertNextTupleValue(&constRGB[1]);
this->Colors->InsertNextTupleValue(&constRGB[2]);
this->Colors->InsertNextTypedTuple(&constRGB[0]);
this->Colors->InsertNextTypedTuple(&constRGB[1]);
this->Colors->InsertNextTypedTuple(&constRGB[2]);
}
this->Modified();
......
......@@ -203,10 +203,10 @@ private:
{
for (int compIdx = 0; compIdx < numComps; ++compIdx)
{
if (mask->GetComponentValue(tupleIdx, compIdx) != 0)
if (mask->GetTypedComponent(tupleIdx, compIdx) != 0)
{
typename ArrayT::ConstReferenceType val =
array->GetComponentValue(tupleIdx, compIdx);
typename ArrayT::ValueType val =
array->GetTypedComponent(tupleIdx, compIdx);
Result[0] = std::min(Result[0], static_cast<double>(val));
Result[1] = std::max(Result[1], static_cast<double>(val));
}
......@@ -225,8 +225,8 @@ private:
{
for (int compIdx = 0; compIdx < numComps; ++compIdx)
{
typename ArrayT::ConstReferenceType val =
array->GetComponentValue(tupleIdx, compIdx);
typename ArrayT::ValueType val =
array->GetTypedComponent(tupleIdx, compIdx);
Result[0] = std::min(Result[0], static_cast<double>(val));
Result[1] = std::max(Result[1], static_cast<double>(val));
}
......
......@@ -144,7 +144,7 @@ bool vtkPlotParallelCoordinates::Paint(vtkContext2D *painter)
selectionSize = this->Selection->GetNumberOfTuples();
if (selectionSize)
{
this->Selection->GetTupleValue(selection, &id);
this->Selection->GetTypedTuple(selection, &id);
}
}
......@@ -187,7 +187,7 @@ bool vtkPlotParallelCoordinates::Paint(vtkContext2D *painter)
{
for (size_t j = 0; j < cols; ++j)
{
this->Selection->GetTupleValue(i, &id);
this->Selection->GetTypedTuple(i, &id);
line[j].Set(this->Storage->AxisPos[j], (*this->Storage)[j][id]);
}
painter->DrawPoly(line[0].GetData(), static_cast<int>(cols));
......@@ -233,7 +233,7 @@ bool vtkPlotParallelCoordinates::SetSelectionRange(int axis, float low,
for (vtkIdType i = 0; i < this->Selection->GetNumberOfTuples(); ++i)
{
vtkIdType id = 0;
this->Selection->GetTupleValue(i, &id);
this->Selection->GetTypedTuple(i, &id);
if (col[id] >= low && col[id] <= high)
{
// Remove this point - no longer selected
......
......@@ -237,9 +237,9 @@ void vtkPlotSurface::InsertSurfaceVertex(float *data, float value, int i,
unsigned char *rgb = this->LookupTable->MapValue(data[pos-1]);
const unsigned char constRGB[3] = { rgb[0], rgb[1], rgb[2] };
this->Colors->InsertNextTupleValue(&constRGB[0]);
this->Colors->InsertNextTupleValue(&constRGB[1]);
this->Colors->InsertNextTupleValue(&constRGB[2]);
this->Colors->InsertNextTypedTuple(&constRGB[0]);
this->Colors->InsertNextTypedTuple(&constRGB[1]);
this->Colors->InsertNextTypedTuple(&constRGB[2]);
}
//-----------------------------------------------------------------------------
......
......@@ -43,9 +43,9 @@ int TestAngularPeriodicDataArray(int, char * [])
angularPeriodicDataArray2->SetAxis(VTK_PERIODIC_ARRAY_AXIS_Y);
double pTmp[3];
angularPeriodicDataArray->GetTupleValue(0, pTmp);
angularPeriodicDataArray->GetTypedTuple(0, pTmp);
float pTmp2[3];
angularPeriodicDataArray2->GetTupleValue(0, pTmp2);
angularPeriodicDataArray2->GetTypedTuple(0, pTmp2);
double dEpsilon = std::numeric_limits<double>::epsilon() * 20.0;
float fEpsilon = std::numeric_limits<float>::epsilon() * 20.f;
......@@ -85,7 +85,7 @@ int TestAngularPeriodicDataArray(int, char * [])
tmp[1] = 1.;
tmp[2] = 1.;
angularPeriodicDataArray2->SetCenter(tmp);
angularPeriodicDataArray2->GetTupleValue(0, pTmp2);
angularPeriodicDataArray2->GetTypedTuple(0, pTmp2);
if (std::abs(pTmp2[0] - 4.7902297) >= fEpsilon ||
std::abs(pTmp2[1] - 12.3) >= fEpsilon ||
......@@ -122,7 +122,7 @@ int TestAngularPeriodicDataArray(int, char * [])
tensorPArray->SetCenter(tmp);
double pTmp3[9];
tensorPArray->GetTupleValue(0, pTmp3);
tensorPArray->GetTypedTuple(0, pTmp3);
if (std::abs(pTmp3[0] - 2.0096597239047708783) >= dEpsilon ||
std::abs(pTmp3[1] - 13.555918489185591724) >= dEpsilon ||
std::abs(pTmp3[2] - -8.6693107531410973365) >= dEpsilon ||
......
......@@ -479,8 +479,8 @@ int Test_void_SetTuple_i_j_source()
std::vector<ScalarT> destTuple(comps);
for (vtkIdType i = 0; i < tuples; ++i)
{
source->GetTupleValue(i, &srcTuple[0]);
dest->GetTupleValue(tupleMap[i], &destTuple[0]);
source->GetTypedTuple(i, &srcTuple[0]);
dest->GetTypedTuple(tupleMap[i], &destTuple[0]);
if (!std::equal(srcTuple.begin(), srcTuple.end(), destTuple.begin()))
{
std::ostringstream srcTupleStr;
......@@ -549,8 +549,8 @@ int Test_void_InsertTuple_i_j_source()
std::vector<ScalarT> destTuple(comps);
for (vtkIdType i = 0; i < tuples; ++i)
{
source->GetTupleValue(i, &srcTuple[0]);
dest->GetTupleValue(tupleMap[i], &destTuple[0]);
source->GetTypedTuple(i, &srcTuple[0]);
dest->GetTypedTuple(tupleMap[i], &destTuple[0]);
if (!std::equal(srcTuple.begin(), srcTuple.end(), destTuple.begin()))
{
std::ostringstream srcTupleStr;
......@@ -625,8 +625,8 @@ int Test_void_InsertTuples_dstIds_srcIds_source()
{
vtkIdType srcTupleId = srcIds->GetId(t);
vtkIdType dstTupleId = dstIds->GetId(t);
src->GetTupleValue(srcTupleId, &srcTuple[0]);
dst->GetTupleValue(dstTupleId, &dstTuple[0]);
src->GetTypedTuple(srcTupleId, &srcTuple[0]);
dst->GetTypedTuple(dstTupleId, &dstTuple[0]);
DataArrayAPIAssert(std::equal(srcTuple.begin(), srcTuple.end(),
dstTuple.begin()),
"Copied tuple does not match input.");
......@@ -674,8 +674,8 @@ int Test_void_InsertTuples_dstStart_n_srcStart_source()
{
vtkIdType srcTupleId = srcStart + t;
vtkIdType dstTupleId = dstStart + t;
src->GetTupleValue(srcTupleId, &srcTuple[0]);
dst->GetTupleValue(dstTupleId, &dstTuple[0]);
src->GetTypedTuple(srcTupleId, &srcTuple[0]);
dst->GetTypedTuple(dstTupleId, &dstTuple[0]);
DataArrayAPIAssert(std::equal(srcTuple.begin(), srcTuple.end(),
dstTuple.begin()),
"Copied tuple does not match input.");
......@@ -738,8 +738,8 @@ int Test_vtkIdType_InsertNextTuple_j_source()
std::vector<ScalarT> destTuple(comps);
for (vtkIdType i = 0; i < tuples; ++i)
{
source->GetTupleValue(tupleMap[i], &srcTuple[0]);
dest->GetTupleValue(i, &destTuple[0]);
source->GetTypedTuple(tupleMap[i], &srcTuple[0]);
dest->GetTypedTuple(i, &destTuple[0]);
if (!std::equal(srcTuple.begin(), srcTuple.end(), destTuple.begin()))
{
std::ostringstream srcTupleStr;
......@@ -799,8 +799,8 @@ int Test_void_GetTuples_ptIds_output()
for (vtkIdType i = 0; i < ids->GetNumberOfIds(); ++i)
{
vtkIdType tupleIdx = ids->GetId(i);
source->GetTupleValue(tupleIdx, &srcTuple[0]);
output->GetTupleValue(i, &outTuple[0]);
source->GetTypedTuple(tupleIdx, &srcTuple[0]);
output->GetTypedTuple(i, &outTuple[0]);
if (!std::equal(srcTuple.begin(), srcTuple.end(), outTuple.begin()))
{
std::ostringstream srcTupleStr;
......@@ -860,8 +860,8 @@ int Test_void_GetTuples_p1_p2_output()
for (vtkIdType i = p1; i < outTupleCount; ++i)
{
vtkIdType tupleIdx = p1 + i;
source->GetTupleValue(tupleIdx, &srcTuple[0]);
output->GetTupleValue(i, &outTuple[0]);
source->GetTypedTuple(tupleIdx, &srcTuple[0]);
output->GetTypedTuple(i, &outTuple[0]);
if (!std::equal(srcTuple.begin(), srcTuple.end(), outTuple.begin()))
{
std::ostringstream srcTupleStr;
......@@ -901,7 +901,7 @@ int Test_voidPtr_GetVoidPointer()
{
tuple.push_back(static_cast<ScalarT>(((t * comps) + c) % 17));
}
source->SetTupleValue(t, &tuple[0]);
source->SetTypedTuple(t, &tuple[0]);
}
// Verify:
......@@ -1238,7 +1238,7 @@ int Test_int_Resize_numTuples()
{
for (int c = 0; c < comps; ++c)
{
array->SetComponentValue(t, c,
array->SetTypedComponent(t, c,
static_cast<ScalarT>((t * comps + c) % 17));
}
}
......@@ -1260,7 +1260,7 @@ int Test_int_Resize_numTuples()
for (int c = 0; c < comps; ++c)
{
ScalarT ref = static_cast<ScalarT>((t * comps + c) % 17);
ScalarT test = array->GetComponentValue(t, c);
ScalarT test = array->GetTypedComponent(t, c);
DataArrayAPIAssert(ref == test,
"Data changed after resize for tuple " << t
<< " component " << c << ": Expected " << ref
......@@ -1284,7 +1284,7 @@ int Test_int_Resize_numTuples()
for (int c = 0; c < comps; ++c)
{
ScalarT ref = static_cast<ScalarT>((t * comps + c) % 17);
ScalarT test = array->GetComponentValue(t, c);
ScalarT test = array->GetTypedComponent(t, c);
DataArrayAPIAssert(ref == test,
"Data changed after resize for tuple " << t
<< " component " << c << ": Expected " << ref
......@@ -1359,7 +1359,7 @@ int Test_void_ExportToVoidPointer_voidPtr()
{
tuple.push_back(static_cast<ScalarT>(((t * comps) + c) % 17));
}
source->SetTupleValue(t, &tuple[0]);
source->SetTypedTuple(t, &tuple[0]);
}
std::vector<ScalarT> buffer(comps * tuples);
......
......@@ -34,8 +34,8 @@ class TestArrayArguments(Testing.vtkTest):
a.SetNumberOfTuples(1)
ti = [0, a.GetDataTypeValueMin(), a.GetDataTypeValueMax()]
to = [0, 0, 0]
a.SetTupleValue(0, ti)
a.GetTupleValue(0, to);
a.SetTypedTuple(0, ti)
a.GetTypedTuple(0, to);
self.assertEqual(ti, to)
d1 = a.GetTuple(0)
d2 = [float(x) for x in ti]
......@@ -50,8 +50,8 @@ class TestArrayArguments(Testing.vtkTest):
a.SetNumberOfTuples(1)
ti = [0, a.GetDataTypeValueMin(), a.GetDataTypeValueMax()]
to = [0, 0, 0]
a.SetTupleValue(0, ti)
a.GetTupleValue(0, to);
a.SetTypedTuple(0, ti)
a.GetTypedTuple(0, to);
self.assertEqual(ti, to)
d1 = a.GetTuple(0)
d2 = [float(x) for x in ti]
......@@ -64,10 +64,10 @@ class TestArrayArguments(Testing.vtkTest):
a.SetNumberOfComponents(3)
a.SetNumberOfTuples(1)
ti = "opn"
a.SetTupleValue(0, ti)
a.SetTypedTuple(0, ti)
# python strings are immutable, so this should NOT work
#to = "***"
#a.GetTupleValue(0, to);
#a.GetTypedTuple(0, to);
d1 = list(a.GetTuple(0))
d2 = [ord(x) for x in ti]
self.assertEqual(d1, d2)
......
......@@ -85,8 +85,8 @@ class TestBuffer(Testing.vtkTest):
# bit array is actually stored as a byte array
a = vtk.vtkCharArray()
a.SetNumberOfComponents(5)
a.InsertNextTupleValue("hello")
a.InsertNextTupleValue("world")
a.InsertNextTypedTuple("hello")
a.InsertNextTypedTuple("world")
m = memoryview(a)
self.assertEqual(m.format, 'c')
self.assertEqual(m.itemsize, 1)
......
......@@ -36,8 +36,6 @@ public:
typedef vtkAOSDataArrayTemplate<ValueTypeT> SelfType;
vtkTemplateTypeMacro(SelfType, GenericDataArrayType)
typedef typename Superclass::ValueType ValueType;
typedef typename Superclass::ReferenceType ReferenceType;
typedef typename Superclass::ConstReferenceType ConstReferenceType;
// Description:
// Legacy support for array-of-structs value iteration.
......@@ -52,18 +50,18 @@ public:
// Methods that are needed to be implemented by every vtkGenericDataArray
// subclass.
// **************************************************************************
inline ConstReferenceType GetValue(vtkIdType valueIdx) const
inline ValueType GetValue(vtkIdType valueIdx) const
{
return this->Buffer.GetBuffer()[valueIdx];
}
inline void GetTupleValue(vtkIdType tupleIdx, ValueType* tuple) const
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 ConstReferenceType GetComponentValue(vtkIdType index, int comp) const
inline ValueType GetTypedComponent(vtkIdType index, int comp) const
{
return this->Buffer.GetBuffer()[this->NumberOfComponents*index + comp];
}
......@@ -71,13 +69,13 @@ public:
{
this->Buffer.GetBuffer()[valueIdx] = value;
}
inline void SetTupleValue(vtkIdType tupleIdx, const ValueType* 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);
}
inline void SetComponentValue(vtkIdType tupleIdx, int comp, ValueType value)
inline void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
{
const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents + comp;
this->SetValue(valueIdx, value);
......@@ -208,10 +206,10 @@ vtkArrayDownCast_TemplateFastCastMacro(vtkAOSDataArrayTemplate)
// can see them. The wrappers ignore vtkAOSDataArrayTemplate.
#define vtkCreateWrappedArrayInterface(T) \
int GetDataType(); \
void GetTupleValue(vtkIdType i, T* tuple); \
void SetTupleValue(vtkIdType i, const T* tuple); \
void InsertTupleValue(vtkIdType i, const T* tuple); \
vtkIdType InsertNextTupleValue(const T* tuple); \
void GetTypedTuple(vtkIdType i, T* tuple); \
void SetTypedTuple(vtkIdType i, const T* tuple); \
void InsertTypedTuple(vtkIdType i, const T* tuple); \
vtkIdType InsertNextTypedTuple(const T* tuple); \
T GetValue(vtkIdType id); \
void SetValue(vtkIdType id, T value); \
void SetNumberOfValues(vtkIdType number); \
......
......@@ -138,6 +138,16 @@ public:
vtkIdType GetNumberOfTuples()
{return (this->MaxId + 1)/this->NumberOfComponents;}
// Description:
// Get the total number of values in the array. This is typically equivalent
// to (numTuples * numComponents). The exception is during incremental array
// construction for subclasses that support component insertion, which may
// result in an incomplete trailing tuple.
inline vtkIdType GetNumberOfValues() const
{
return (this->MaxId + 1);
}
// 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
......
......@@ -83,9 +83,9 @@ struct DeepCopyWorker
{
for (int c = 0; c < comps; ++c)
{
dst->SetComponentValue(
dst->SetTypedComponent(
t, c, static_cast<typename Array2T::ValueType>(
src->GetComponentValue(t, c)));
src->GetTypedComponent(t, c)));
}
}
}
......@@ -141,11 +141,11 @@ struct InterpolateMultiTupleWorker
{
vtkIdType t = this->TupleIds[tupleId];
double weight = this->Weights[tupleId];
val += weight * static_cast<double>(src->GetComponentValue(t, c));
val += weight * static_cast<double>(src->GetTypedComponent(t, c));
}
typename Array2T::ValueType valT;
vtkDataArrayRoundIfNecessary(val, &valT);
dst->InsertComponentValue(this->DestTuple, c, valT);
dst->InsertTypedComponent(this->DestTuple, c, valT);
}
}
};
......@@ -172,10 +172,10 @@ struct InterpolateTupleWorker
typename Array3T::ValueType valT;
for (int c = 0; c < numComps; ++c)
{
val = src1->GetComponentValue(this->SrcTuple1, c) * oneMinusT +
src2->GetComponentValue(this->SrcTuple2, c) * this->Weight;
val = src1->GetTypedComponent(this->SrcTuple1, c) * oneMinusT +
src2->GetTypedComponent(this->SrcTuple2, c) * this->Weight;
vtkDataArrayRoundIfNecessary(val, &valT);
dst->InsertComponentValue(this->DstTuple, c, valT);
dst->InsertTypedComponent(this->DstTuple, c, valT);
}
}
};
......@@ -198,9 +198,9 @@ struct GetTuplesFromListWorker
{
for (int c = 0; c < numComps; ++c)
{
dst->SetComponentValue(dstTuple, c,
dst->SetTypedComponent(dstTuple, c,
static_cast<typename Array2T::ValueType>(
src->GetComponentValue(*srcTuple, c)));
src->GetTypedComponent(*srcTuple, c)));
}
++srcTuple;
++dstTuple;
......@@ -245,9 +245,9 @@ struct GetTuplesRangeWorker
{
for (int c = 0; c < numComps; ++c)
{
dst->SetComponentValue(dstT, c,
dst->SetTypedComponent(dstT, c,
static_cast<typename Array2T::ValueType>(
src->GetComponentValue(srcT, c)));
src->GetTypedComponent(srcT, c)));
}
}
}
......@@ -283,8 +283,8 @@ struct SetTupleArrayWorker
int numComps = src->GetNumberOfComponents();
for (int c = 0; c < numComps; ++c)
{
dst->SetComponentValue(this->DstTuple, c,
src->GetComponentValue(this->SrcTuple, c));
dst->SetTypedComponent(this->DstTuple, c,
src->GetTypedComponent(this->SrcTuple, c));
}
}
......@@ -320,7 +320,7 @@ struct SetTuplesIdListWorker
vtkIdType dstT = this->DstTuples->GetId(t);
for (int c = 0; c < numComps; ++c)
{
dst->SetComponentValue(dstT, c, src->GetComponentValue(srcT, c));
dst->SetTypedComponent(dstT, c, src->GetTypedComponent(srcT, c));
}
}
}
......@@ -369,7 +369,7 @@ struct SetTuplesRangeWorker
{
for (int c = 0; c < numComps; ++c)
{
dst->SetComponentValue(dstT, c, src->GetComponentValue(srcT, c));
dst->SetTypedComponent(dstT, c, src->GetTypedComponent(srcT, c));
}
}
++srcT;
......
......@@ -80,9 +80,9 @@ struct ComputeScalarRange
for(int compIdx = 0, j = 0; compIdx < NumComps; ++compIdx, j+=2)
{
tempRange[j] = detail::min(tempRange[j],
array->GetComponentValue(tupleIdx, compIdx));
array->GetTypedComponent(tupleIdx, compIdx));
tempRange[j+1] = detail::max(tempRange[j+1],
array->GetComponentValue(tupleIdx, compIdx));
array->GetTypedComponent(tupleIdx, compIdx));
}
}
......@@ -171,9 +171,9 @@ bool DoComputeScalarRange(ArrayT *array, double *ranges)
for(int compIdx = 0, j = 0; compIdx < numComp; ++compIdx, j+=2)
{
tempRange[j] = detail::min(tempRange[j],
array->GetComponentValue(tupleIdx, compIdx));
array->GetTypedComponent(tupleIdx, compIdx));
tempRange[j+1] = detail::max(tempRange[j+1],
array->GetComponentValue(tupleIdx, compIdx));
array->GetTypedComponent(tupleIdx, compIdx));
}
}
......@@ -247,7 +247,7 @@ bool DoComputeVectorRange(ArrayT *array, double range[2])
for (int compIdx = 0; compIdx < numComps; ++compIdx)
{
const double t =
static_cast<double>(array->GetComponentValue(tupleIdx, compIdx));
static_cast<double>(array->GetTypedComponent(tupleIdx, compIdx));
squaredSum += t * t;
}
range[0] = detail::min(range[0], squaredSum);
......
......@@ -34,40 +34,34 @@ class vtkGenericDataArray : public vtkDataArray
public:
vtkTemplateTypeMacro(SelfType, vtkDataArray)
typedef ValueTypeT ValueType;
typedef ValueTypeT& ReferenceType;
typedef const ValueTypeT& ConstReferenceType;
//----------------------------------------------------------------------------
// Methods that must be defined by the subclasses.
// Let's call these GenericDataArray concept methods.
inline ConstReferenceType GetValue(vtkIdType valueIdx) const
inline ValueType GetValue(vtkIdType valueIdx) const
{
// TODO this method shadows a non-const method in vtkDataArrayTemplate
// that returns a value. Prolly won't matter for most cases, but we should
// note it somewhere.
return static_cast<const DerivedT*>(this)->GetValue(valueIdx);
}
inline void GetTupleValue(vtkIdType tupleIdx, ValueType* tuple) const
inline void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
{
static_cast<const DerivedT*>(this)->GetTupleValue(tupleIdx, tuple);
static_cast<const DerivedT*>(this)->GetTypedTuple(tupleIdx, tuple);
}
inline ConstReferenceType GetComponentValue(vtkIdType tupleIdx,
int comp) const
inline ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
{
return static_cast<const DerivedT*>(this)->GetComponentValue(tupleIdx,
return static_cast<const DerivedT*>(this)->GetTypedComponent(tupleIdx,
comp);
}
inline void SetValue(vtkIdType valueIdx, ValueType value)
{
static_cast<DerivedT*>(this)->SetValue(valueIdx, value);
}
inline void SetTupleValue(vtkIdType tupleIdx, const ValueType* tuple)
inline void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
{
static_cast<DerivedT*>(this)->SetTupleValue(tupleIdx, tuple);
static_cast<DerivedT*>(this)->SetTypedTuple(tupleIdx, tuple);
}
inline void SetComponentValue(vtkIdType tupleIdx, int comp, ValueType value)
inline void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
{
static_cast<DerivedT*>(this)->SetComponentValue(tupleIdx, comp, value);
static_cast<DerivedT*>(this)->SetTypedComponent(tupleIdx, comp, value);
}
// Provide implementations for pure virtual methods in vtkDataArray.
......@@ -263,7 +257,7 @@ public:
virtual void SetComponent(vtkIdType i, int j, double c)
{
// Reimplemented for efficiency (base impl allocates heap memory)
this->SetComponentValue(i, j, static_cast<ValueType>(c));
this->SetTypedComponent(i, j, static_cast<ValueType>(c));
}
//----------------------------------------------------------------------------
......@@ -271,7 +265,7 @@ public:
virtual double GetComponent(vtkIdType i, int j)
{
// Reimplemented for efficiency (base impl allocates heap memory)
return static_cast<double>(this->GetComponentValue(i, j));
return static_cast<double>(this->GetTypedComponent(i, j));
}
//----------------------------------------------------------------------------
......@@ -328,15 +322,6 @@ public:
// to be virtual. They are no longer virtual and the vtkGenericDataArray
// concept methods defined above.
// Description:
// Get a reference to the scalar value at a particular index.
// Index is value/component index assuming
// traditional VTK memory layout (array-of-structures).
ReferenceType GetValueReference(vtkIdType idx)
{
return const_cast<ReferenceType>(this->GetValue(idx));
}
// Description:
// Insert data at the end of the array. Return its location in the array.
vtkIdType InsertNextValue(ValueType v)
......@@ -381,27 +366,27 @@ public:
// Description:
// Insert (memory allocation performed) the tuple into the ith location
// in the array.
void InsertTupleValue(vtkIdType tupleIdx, const ValueType *t)
void InsertTypedTuple(vtkIdType tupleIdx, const ValueType *t)
{
if (this->EnsureAccessToTuple(tupleIdx))
{
this->SetTupleValue(tupleIdx, t);
this->SetTypedTuple(tupleIdx, t);
}
}
// Description:
// Insert (memory allocation performed) the tuple onto the end of the array.
vtkIdType InsertNextTupleValue(const ValueType *t)
vtkIdType InsertNextTypedTuple(const ValueType *t)
{
vtkIdType nextTuple = this->GetNumberOfTuples();
this->InsertTupleValue(nextTuple, t);
this->InsertTypedTuple(nextTuple, t);
return nextTuple;
}
// Description:
// Insert (memory allocation performed) the value at the specified tuple and
// component location.
void InsertComponentValue(vtkIdType tupleIdx, int compIdx, ValueType val)
void InsertTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType val)
{
// Update MaxId to the inserted component (not the complete tuple) for
// compatibility with InsertNextValue.
......@@ -413,17 +398,9 @@ public:
this->EnsureAccessToTuple(tupleIdx);
assert("Sufficient space allocated." && this->MaxId >= newMaxId);
this->MaxId = newMaxId;
this->SetComponentValue(tupleIdx, compIdx, val);
this->SetTypedComponent(tupleIdx, compIdx, val);
}
// Description:
// Returns the number of values i.e.
// (this->NumberOfComponents*this->NumberOfTuples)
// TODO this can go in vtkAbstractArray.
inline vtkIdType GetNumberOfValues()
{
return (this->MaxId + 1);
}
// Description:
// Get the range of array values for the given component in the
......
......@@ -38,7 +38,7 @@ vtkGenericDataArrayT(void)::GetTuple(vtkIdType i, double *tuple)
{
for (int c = 0; c < this->NumberOfComponents; ++c)
{
tuple[c] = static_cast<double>(this->GetComponentValue(i, c));
tuple[c] = static_cast<double>(this->GetTypedComponent(i, c));
}
}
......@@ -69,8 +69,8 @@ vtkGenericDataArrayT(void)::RemoveTuple(vtkIdType id)
{
for (int comp=0; comp < numComps; ++comp)
{
this->SetComponentValue(toTuple, comp,
this->GetComponentValue(fromTuple, comp));
this->SetTypedComponent(toTuple, comp,
this->GetTypedComponent(fromTuple, comp));
}
}
this->SetNumberOfTuples(this->GetNumberOfTuples() - 1);
......
......@@ -40,8 +40,6 @@ class vtkMappedDataArray : public vtkTypedDataArray<Scalar>
public:
vtkTemplateTypeMacro(vtkMappedDataArray<Scalar>, vtkTypedDataArray<Scalar>)
typedef typename Superclass::ValueType ValueType;
typedef typename Superclass::ReferenceType ReferenceType;
typedef typename Superclass::ConstReferenceType ConstReferenceType;
// Description:
// Perform a fast, safe cast from a vtkAbstractArray to a vtkMappedDataArray.
......
......@@ -35,8 +35,7 @@ class vtkPeriodicDataArray: public vtkMappedDataArray<Scalar>
public:
vtkTemplateTypeMacro(vtkPeriodicDataArray<Scalar>, vtkMappedDataArray<Scalar>)
typedef typename Superclass::ValueType ValueType;
typedef typename Superclass::ReferenceType ReferenceType;
typedef typename Superclass::ConstReferenceType ConstReferenceType;
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
......@@ -98,19 +97,19 @@ public:
// Description:
// Get value at index idx.
// Warning, it internally call GetTupleValue,
// Warning, it internally call GetTypedTuple,
// so it is an inneficcient way if reading all data
ConstReferenceType GetValue(vtkIdType idx) const;
ValueType GetValue(vtkIdType idx) const;
// Description:
// Get value at index idx as reference.
// Warning, it internally call GetTupleValue,
// Warning, it internally call GetTypedTuple,
// so it is an inneficcient way if reading all data
ReferenceType GetValueReference(vtkIdType idx);
ValueType& GetValueReference(vtkIdType idx);
// Description:
// Copy tuple value at location idx into provided array
void GetTupleValue(vtkIdType idx, Scalar *t) const;
void GetTypedTuple(vtkIdType idx, Scalar *t) const;
// Description:
// Return the memory in kilobytes consumed by this data array.
......@@ -214,15 +213,15 @@ public:
// Description:
// Read only container, not supported.
void SetTupleValue(vtkIdType i, const Scalar *t);
void SetTypedTuple(vtkIdType i, const Scalar *t);