Commit 218a3737 authored by Will Schroeder's avatar Will Schroeder
Browse files

ENH: Created uniform pointer interface.

parent ef781a47
......@@ -38,7 +38,6 @@ public:
// vlScalar interface
vlScalars *MakeObject(int sze, int ext=1000);
int GetNumberOfValuesPerPoint() {return 1;};
int GetNumberOfScalars() {return (this->S.GetMaxId()+1);};
void Squeeze() {this->S.Squeeze();};
......@@ -48,6 +47,7 @@ public:
void Reset() {this->S.Reset();};
unsigned char *GetPtr(const int id);
unsigned char *WritePtr(const int id, const int number);
void WrotePtr();
// vlColorScalar interface.
unsigned char *GetColor(int id);
......@@ -61,20 +61,25 @@ protected:
};
// Description:
// Get pointer to rgb data at location "id" in the array. Meant for reading
// data.
// Get pointer to array of data starting at data position "id".
inline unsigned char *vlGraymap::GetPtr(const int id)
{
return this->S.GetPtr(id);
}
// Description:
// Get pointer to data. Useful for direct writes into object. MaxId is bumped
// by number (and memory allocated if necessary). Id is the locaation you
// wish to write into; number is the number of rgb triplets to write.
// Get pointer to data array. Useful for direct writes of data. MaxId is
// bumped by number (and memory allocated if necessary). Id is the
// location you wish to write into; number is the number of scalars to
// write. Use the method WrotePtr() to mark completion of write.
inline unsigned char *vlGraymap::WritePtr(const int id, const int number)
{
return this->S.WritePtr(id,number);
}
// Description:
// Terminate direct write of data. Although dummy routine now, reserved for
// future use.
inline void vlGraymap::WrotePtr() {}
#endif
......@@ -51,7 +51,9 @@ public:
void GetPoints(vlIdList& ptId, vlFloatPoints& fp);
// miscellaneous
int *GetPtr(const int id);
int *WritePtr(const int id, const int number);
void WrotePtr();
vlIntPoints &operator=(const vlIntPoints& fp);
void operator+=(const vlIntPoints& fp) {this->P += fp.P;};
void Reset() {this->P.Reset();};
......@@ -61,14 +63,27 @@ protected:
};
// Description:
// Get pointer to data. Useful for direct writes into object. MaxId is bumped
// by number (and memory allocated if necessary). Id is the location you
// wish to write into; number is the number of points to write.
// Get pointer to array of data starting at data position "id".
inline int *vlIntPoints::GetPtr(const int id)
{
return this->P.GetPtr(id);
}
// Description:
// Get pointer to data array. Useful for direct writes of data. MaxId is
// bumped by number (and memory allocated if necessary). Id is the
// location you wish to write into; number is the number of points to
// write. Use the method WrotePtr() to mark completion of write.
inline int *vlIntPoints::WritePtr(const int id, const int number)
{
return this->P.WritePtr(id,3*number);
}
// Description:
// Terminate direct write of data. Although dummy routine now, reserved for
// future use.
inline void vlIntPoints::WrotePtr() {}
inline void vlIntPoints::GetPoint(int id, float x[3])
{
int *p=this->P.GetPtr(3*id);
......
......@@ -50,22 +50,37 @@ public:
void GetScalars(vlIdList& ptIds, vlFloatScalars& fs);
// miscellaneous
int *GetPtr(const int id);
int *WritePtr(const int id, const int number);
void WrotePtr();
vlIntScalars &operator=(const vlIntScalars& is);
void operator+=(const vlIntScalars& is) {this->S += is.S;};
void Reset() {this->S.Reset();};
private:
protected:
vlIntArray S;
};
// Description:
// Get pointer to data. Useful for direct writes into object. MaxId is bumped
// by number (and memory allocated if necessary). Id is the locaation you
// wish to write into; number is the number of scalars to write.
// Get pointer to array of data starting at data position "id".
inline int *vlIntScalars::GetPtr(const int id)
{
return this->S.GetPtr(id);
}
// Description:
// Get pointer to data array. Useful for direct writes of data. MaxId is
// bumped by number (and memory allocated if necessary). Id is the
// location you wish to write into; number is the number of scalars to
// write. Use the method WrotePtr() to mark completion of write.
inline int *vlIntScalars::WritePtr(const int id, const int number)
{
return this->S.WritePtr(id,number);
}
// Description:
// Terminate direct write of data. Although dummy routine now, reserved for
// future use.
inline void vlIntScalars::WrotePtr() {}
#endif
......@@ -82,6 +82,7 @@ public:
unsigned char *GetPtr(const int id);
unsigned char *WritePtr(const int id, const int number);
void WrotePtr();
protected:
int NumberOfColors;
......@@ -106,11 +107,17 @@ inline unsigned char *vlLookupTable::GetPtr(const int id)
// Get pointer to data. Useful for direct writes into object. MaxId is bumped
// by number (and memory allocated if necessary). Id is the location you
// wish to write into; number is the number of rgba values to write.
// Use the method WrotePtr() to mark completion of write.
inline unsigned char *vlLookupTable::WritePtr(const int id, const int number)
{
return this->Table.WritePtr(id,number);
}
// Description:
// Terminate direct write of data. Although dummy routine now, reserved for
// future use.
inline void vlLookupTable::WrotePtr() {}
#endif
......@@ -40,7 +40,7 @@ public:
vlScalars *MakeObject(int sze, int ext=1000);
int GetNumberOfScalars() {return (this->S.GetMaxId()+1)/3;};
void Squeeze() {this->S.Squeeze();};
int GetNumberOfValuesPerPoint() {return 3;};
int GetNumberOfValuesPerScalar() {return 3;};
// miscellaneous
vlPixmap &operator=(const vlPixmap& fs);
......@@ -48,6 +48,7 @@ public:
void Reset() {this->S.Reset();};
unsigned char *GetPtr(const int id);
unsigned char *WritePtr(const int id, const int number);
void WrotePtr();
// vlColorScalar interface.
unsigned char *GetColor(int id);
......@@ -94,20 +95,25 @@ inline int vlPixmap::InsertNextColor(unsigned char *rgba)
}
// Description:
// Get pointer to rgba data at location "id" in the array. Meant for reading
// data.
// Get pointer to array of data starting at data position "id".
inline unsigned char *vlPixmap::GetPtr(const int id)
{
return this->S.GetPtr(3*id);
}
// Description:
// Get pointer to data. Useful for direct writes into object. MaxId is bumped
// by number (and memory allocated if necessary). Id is the locaation you
// wish to write into; number is the number of rgba triplets to write.
// Get pointer to data array. Useful for direct writes of data. MaxId is
// bumped by number (and memory allocated if necessary). Id is the
// location you wish to write into; number is the number of scalars to
// write. Use the method WrotePtr() to mark completion of write.
inline unsigned char *vlPixmap::WritePtr(const int id, const int number)
{
return this->S.WritePtr(3*id,3*number);
}
// Description:
// Terminate direct write of data. Although dummy routine now, reserved for
// future use.
inline void vlPixmap::WrotePtr() {}
#endif
......@@ -50,22 +50,37 @@ public:
void GetScalars(vlIdList& ptIds, vlFloatScalars& fs);
// miscellaneous
short *GetPtr(const int id);
short *WritePtr(const int id, const int number);
void WrotePtr();
vlShortScalars &operator=(const vlShortScalars& ss);
void operator+=(const vlShortScalars& ss) {this->S += ss.S;};
void Reset() {this->S.Reset();};
private:
protected:
vlShortArray S;
};
// Description:
// Get pointer to data. Useful for direct writes into object. MaxId is bumped
// by number (and memory allocated if necessary). Id is the locaation you
// wish to write into; number is the number of scalars to write.
// Get pointer to array of data starting at data position "id".
inline short *vlShortScalars::GetPtr(const int id)
{
return this->S.GetPtr(id);
}
// Description:
// Get pointer to data array. Useful for direct writes of data. MaxId is
// bumped by number (and memory allocated if necessary). Id is the
// location you wish to write into; number is the number of scalars to
// write. Use the method WrotePtr() to mark completion of write.
inline short *vlShortScalars::WritePtr(const int id, const int number)
{
return this->S.WritePtr(id,number);
}
// Description:
// Terminate direct write of data. Although dummy routine now, reserved for
// future use.
inline void vlShortScalars::WrotePtr() {}
#endif
......@@ -56,13 +56,18 @@ public:
virtual char *GetDataType() = 0;
// Description:
// Return number of points in array.
virtual int GetNumberOfScalars() = 0;
// Return the type of scalar. Want to differentiate between
// single-valued scalars and multiple-valued (e.g., "color" scalars).
// Returns either "SingleValued" or "ColorScalar".
virtual char *GetScalarType() {return "SingleValued";};
// Description:
// Return the number of values per scalar. Should range between (1,4).
virtual int GetNumberOfValuesPerScalar() {return 1;};
// Description:
// Return the number of values per point. Should range between (1,4).
// Used to distinguish between color scalars and single-valued ones.
virtual int GetNumberOfValuesPerPoint() {return 1;};
// Return number of scalars in this object.
virtual int GetNumberOfScalars() = 0;
// Description:
// Return a float scalar value for a particular point id.
......@@ -85,19 +90,13 @@ public:
// Reclaim any extra memory.
virtual void Squeeze() = 0;
// Description:
// Get data as pointer to unsigned char at specified location. Used for
// high performance texture and color manipulation. Not supported for
// all scalar types: check for NULL return value.
virtual unsigned char *GetPtr(const int id) {return NULL;};
// Description:
// Get the scalar values for the point ids specified.
virtual void GetScalars(vlIdList& ptIds, vlFloatScalars& fs);
virtual void ComputeRange();
float *GetRange();
void GetRange(float range[8]);
void GetRange(float range[2]);
// Description:
// Create default lookup table. Generally used to create one when none
......
......@@ -52,6 +52,9 @@ public:
void GetPointCells(int ptId, vlIdList& cellIds);
void ComputeBounds();
void GetVoxelGradient(int i, int j, int k, vlScalars *s, vlFloatVectors& g);
void GetPointGradient(int i, int j, int k, vlScalars *s, float g[3]);
// Description:
// Set the aspect ratio of the cubical cells that compose the structured
// point set.
......
......@@ -48,6 +48,8 @@ protected:
float Storage[MAXDIM*MAXDIM];
};
// Description:
// Construct tensor initially pointing to internal storage.
inline vlTensor::vlTensor(int dim)
{
this->T = this->Storage;
......@@ -57,16 +59,22 @@ inline vlTensor::vlTensor(int dim)
this->T[i+j*this->Dimension] = 0.0;
}
// Description:
// Set the dimensions of the tensor.
inline void vlTensor::SetDimension(int dim)
{
this->Dimension = (dim < 1 ? 1 : (dim > MAXDIM ? MAXDIM : dim));
}
// Description:
// Get the dimensions of the tensor.
inline int vlTensor::GetDimension()
{
return this->Dimension;
}
// Description:
// Initialize tensor components to 0.0.
inline void vlTensor::Initialize()
{
for (int j=0; j<this->Dimension; j++)
......@@ -74,21 +82,30 @@ inline void vlTensor::Initialize()
this->T[i+j*this->Dimension] = 0.0;
}
// Description:
// Get the tensor component (i,j).
inline float vlTensor::GetComponent(int i, int j)
{
return this->T[i+this->Dimension*j];
}
// Description:
// Set the value of the tensor component (i,j).
inline void vlTensor::SetComponent(int i, int j, float v)
{
this->T[i+this->Dimension*j] = v;
}
// Description:
// Add to the value of the tensor component at location (i,j).
inline void vlTensor::AddComponent(int i, int j, float v)
{
this->T[i+this->Dimension*j] += v;
}
// Description:
// Assign tensors to a float array. Float array must be sized
// Dimension*Dimension.
inline void vlTensor::operator=(float *t)
{
for (int j=0; j < this->Dimension; j++)
......@@ -96,6 +113,8 @@ inline void vlTensor::operator=(float *t)
this->T[i+this->Dimension*j] = t[i+this->Dimension*j];
}
// Description:
// Assign tensor to another tensor.
inline void vlTensor::operator=(vlTensor &t)
{
for (int j=0; j < this->Dimension; j++)
......
......@@ -64,13 +64,16 @@ void vlScalars::ComputeRange()
}
// Description:
// Return the range of scalar values.
// Return the range of scalar values. Data returned as pointer to float array
// of length 2.
float *vlScalars::GetRange()
{
this->ComputeRange();
return this->Range;
}
// Description:
// Return the range of scalar values. Range copied into array provided.
void vlScalars::GetRange(float range[2])
{
this->ComputeRange();
......
......@@ -286,6 +286,119 @@ void vlStructuredPoints::ComputeBounds()
(this->Dimensions[2]-1) * this->AspectRatio[2];
}
// Description:
// Given structured coordinates (i,j,k) for a voxel cell, compute the eight
// gradient values for the voxel corners. The order in which the gradient
// vectors are arranged corresponds to the ordering of the voxel points.
// Gradient vector is computed by central differences (except on edges of
// volume where forward difference is used). The scalars s are the scalars
// from which the gradient is to be computed. This method will treat
// only 3D structured point datasets (i.e., volumes).
void vlStructuredPoints::GetVoxelGradient(int i, int j, int k, vlScalars *s,
vlFloatVectors& g)
{
float gv[3];
int ii, jj, kk, idx;
for ( kk=0; kk < 2; kk++)
{
for ( jj=0; jj < 2; jj++)
{
for ( ii=0; ii < 2; ii++)
{
this->GetPointGradient(i+ii, j+jj, k+kk, s, gv);
g.SetVector(idx++, gv);
}
}
}
}
// Description:
// Given structured coordinates (i,j,k) for a point in a structured point
// dataset, compute the gradient vector from the scalar data at that point.
// The scalars s are the scalars from which the gradient is to be computed.
// This method will treat structured point datasets of any dimension.
void vlStructuredPoints::GetPointGradient(int i,int j,int k, vlScalars *s,
float g[3])
{
int *dims=this->Dimensions;
float *ar=this->AspectRatio;
int ijsize=dims[0]*dims[1];
float sp, sm;
// x-direction
if ( dims[0] == 1 )
{
g[0] = 0.0;
}
else if ( i == 0 )
{
sp = s->GetScalar(i+1 + j*dims[0] + k*ijsize);
sm = s->GetScalar(i + j*dims[0] + k*ijsize);
g[0] = (sp - sm) / ar[0];
}
else if ( i == (dims[0]-1) )
{
sp = s->GetScalar(i + j*dims[0] + k*ijsize);
sm = s->GetScalar(i-1 + j*dims[0] + k*ijsize);
g[0] = (sp - sm) / ar[0];
}
else
{
sp = s->GetScalar(i+1 + j*dims[0] + k*ijsize);
sm = s->GetScalar(i-1 + j*dims[0] + k*ijsize);
g[0] = 0.5 * (sp - sm) / ar[0];
}
// y-direction
if ( dims[1] == 1 )
{
g[1] = 0.0;
}
else if ( j == 0 )
{
sp = s->GetScalar(i + (j+1)*dims[0] + k*ijsize);
sm = s->GetScalar(i + j*dims[0] + k*ijsize);
g[1] = (sp - sm) / ar[1];
}
else if ( j == (dims[1]-1) )
{
sp = s->GetScalar(i + j*dims[0] + k*ijsize);
sm = s->GetScalar(i + (j-1)*dims[0] + k*ijsize);
g[1] = (sp - sm) / ar[1];
}
else
{
sp = s->GetScalar(i + (j+1)*dims[0] + k*ijsize);
sm = s->GetScalar(i + (j-1)*dims[0] + k*ijsize);
g[1] = 0.5 * (sp - sm) / ar[1];
}
// z-direction
if ( dims[1] == 1 )
{
g[2] = 0.0;
}
else if ( k == 0 )
{
sp = s->GetScalar(i + j*dims[0] + (k+1)*ijsize);
sm = s->GetScalar(i + j*dims[0] + k*ijsize);
g[2] = (sp - sm) / ar[2];
}
else if ( k == (dims[1]-1) )
{
sp = s->GetScalar(i + j*dims[0] + k*ijsize);
sm = s->GetScalar(i + j*dims[0] + (k-1)*ijsize);
g[2] = (sp - sm) / ar[2];
}
else
{
sp = s->GetScalar(i + j*dims[0] + (k+1)*ijsize);
sm = s->GetScalar(i + j*dims[0] + (k-1)*ijsize);
g[2] = 0.5 * (sp - sm) / ar[2];
}
}
void vlStructuredPoints::PrintSelf(ostream& os, vlIndent indent)
{
vlDataSet::PrintSelf(os,indent);
......
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