Commit 50698d5e authored by Will Schroeder's avatar Will Schroeder
Browse files

ENH: Unified write/read pointers to data.

parent 844ccc11
......@@ -42,64 +42,73 @@ public:
int GetNumberOfScalars() {return (this->S.GetMaxId()+1)/2;};
void Squeeze() {this->S.Squeeze();};
int GetNumberOfValuesPerPoint() {return 2;};
unsigned char *GetUCharPtr() {return S.GetPtr(0);};
// miscellaneous
vlAGraymap &operator=(const vlAGraymap& fs);
void operator+=(const vlAGraymap& fs) {this->S += fs.S;};
void Reset() {this->S.Reset();};
unsigned char *WriteInto(int id, int number);
unsigned char *GetPtr(const int id);
unsigned char *WritePtr(const int id, const int number);
// vlColorScalar interface.
unsigned char *GetColor(int id);
void GetColor(int id, unsigned char rgb[3]);
void SetColor(int id, unsigned char rgb[3]);
void InsertColor(int id, unsigned char rgb[3]);
int InsertNextColor(unsigned char rgb[3]);
void SetColor(int id, unsigned char ga[2]);
void InsertColor(int id, unsigned char ga[2]);
int InsertNextColor(unsigned char ga[2]);
protected:
vlCharArray S;
};
// Description:
// Set a rgb value at a particular array location. Does not do range
// checking.
inline void vlAGraymap::SetColor(int i, unsigned char rgb[3])
// Set a intensity/alpha value at a particular array location. Does not do
// range checking.
inline void vlAGraymap::SetColor(int i, unsigned char ga[2])
{
i *= 2;
this->S[i] = rgb[0];
this->S[i+1] = rgb[1];
this->S[i+2] = rgb[2];
this->S[i] = ga[0];
this->S[i+1] = ga[1];
}
// Description:
// Insert a rgb value at a particular array location. Does range checking
// and will allocate additional memory if necessary.
inline void vlAGraymap::InsertColor(int i, unsigned char *rgb)
// Insert a intensity/alpha value at a particular array location. Does range
// checking and will allocate additional memory if necessary.
inline void vlAGraymap::InsertColor(int i, unsigned char *ga)
{
this->S.InsertValue(2*i+2, rgb[2]);
this->S[2*i] = rgb[0];
this->S[2*i+1] = rgb[1];
this->S.InsertValue(2*i+1, ga[1]);
this->S[2*i] = ga[0];
}
// Description:
// Insert a rgb value at the next available slot in the array. Will allocate
// memory if necessary.
inline int vlAGraymap::InsertNextColor(unsigned char *rgb)
// Insert a intensity/alpha value at the next available slot in the array. Will
// allocate memory if necessary.
inline int vlAGraymap::InsertNextColor(unsigned char *ga)
{
int id = this->S.GetMaxId() + 2;
this->S.InsertValue(id,rgb[2]);
this->S[id-2] = rgb[0];
this->S[id-1] = rgb[1];
int id = this->S.GetMaxId() + 1;
this->S.InsertValue(id,ga[1]);
this->S[id-1] = ga[0];
return id/2;
}
// Description:
// Get pointer to ga data at location "id" in the array. Meant for reading
// data.
inline unsigned char *vlAGraymap::GetPtr(const int id)
{
return this->S.GetPtr(2*id);
}
// Description:
// Get pointer to data. Useful for direct writes into object. MaxId is bumped
// by number (and memory allocated if necessary).
inline unsigned char *vlAGraymap::WriteInto(int id, int number)
// by number (and memory allocated if necessary). Id is the locaation you
// wish to write into; number is the number of ga colors to write.
inline unsigned char *vlAGraymap::WritePtr(const int id, const int number)
{
return this->S.WriteInto(id, number);
return this->S.WritePtr(2*id,2*number);
}
#endif
......@@ -42,12 +42,13 @@ public:
int GetNumberOfScalars() {return (this->S.GetMaxId()+1)/4;};
void Squeeze() {this->S.Squeeze();};
int GetNumberOfValuesPerPoint() {return 4;};
unsigned char *GetUCharPtr() {return S.GetPtr(0);};
// miscellaneous
vlAPixmap &operator=(const vlAPixmap& fs);
void operator+=(const vlAPixmap& fs) {this->S += fs.S;};
void Reset() {this->S.Reset();};
unsigned char *GetPtr(const int id);
unsigned char *WritePtr(const int id, const int number);
// vlColorScalar interface.
unsigned char *GetColor(int id);
......@@ -60,4 +61,21 @@ protected:
vlCharArray S;
};
// Description:
// Get pointer to rgba data at location "id" in the array. Meant for reading
// data.
inline unsigned char *vlAPixmap::GetPtr(const int id)
{
return this->S.GetPtr(4*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 colors to write.
inline unsigned char *vlAPixmap::WritePtr(const int id, const int number)
{
return this->S.WritePtr(4*id,4*number);
}
#endif
......@@ -39,9 +39,10 @@ public:
// access/insertion methods
int GetValue(const int id);
unsigned char *GetPtr(const int id);
vlBitArray &InsertValue(const int id, const int i);
int InsertNextValue(const int i);
unsigned char *GetPtr(const int id);
unsigned char *WritePtr(const int id, const int number);
// special operators
vlBitArray &operator=(const vlBitArray& ia);
......@@ -53,7 +54,6 @@ public:
void Squeeze();
int GetSize();
int GetMaxId();
unsigned char *GetArray();
void Reset();
private:
......@@ -66,11 +66,22 @@ private:
// Description:
// Get the address of a particular data index.
inline unsigned char *vlBitArray::GetPtr(const int id)
inline unsigned char *vlBitArray::GetPtr(const int id)
{
return this->Array + id/8;
};
// 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.
inline unsigned char *vlBitArray::WritePtr(const int id, const int number)
{
if ( (id + number) > this->Size ) this->Resize(id+number);
this->MaxId = id + number - 1;
return this->Array + id/8;
}
// Description:
// Insert data at a specified position in the array. Does not perform
// range checking.
......@@ -117,11 +128,6 @@ inline int vlBitArray::GetSize() {return this->Size;}
// Returning the maximum index of data inserted so far.
inline int vlBitArray::GetMaxId() {return this->MaxId;}
// Description:
// Get the pointer to the array. Useful for interfacing to C or
// FORTRAN routines.
inline unsigned char *vlBitArray::GetArray() {return this->Array;}
// Description:
// Reuse the memory allocated by this object. Objects appears like
// no data has been previously inserted.
......
......@@ -45,6 +45,8 @@ public:
vlBitmap &operator=(const vlBitmap& fs);
void operator+=(const vlBitmap& fs) {this->S += fs.S;};
void Reset() {this->S.Reset();};
unsigned char *GetPtr(const int id);
unsigned char *WritePtr(const int id, const int number);
// vlColorScalar interface.
unsigned char *GetColor(int id);
......@@ -57,4 +59,21 @@ protected:
vlBitArray S;
};
// Description:
// Get pointer to byte containing bit in question. You will have to decompose
// byte to obtain appropriate bit value.
inline unsigned char *vlBitmap::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 rgba colors to write.
inline unsigned char *vlBitmap::WritePtr(const int id, const int number)
{
return this->S.WritePtr(id,number);
}
#endif
......@@ -38,22 +38,21 @@ public:
// access/insertion methods
unsigned char GetValue(const int id);
unsigned char *GetPtr(const int id);
vlCharArray &InsertValue(const int id, const unsigned char c);
int InsertNextValue(const unsigned char c);
unsigned char *GetPtr(const int id);
unsigned char *WritePtr(const int id, const int number);
// special operators
vlCharArray &operator=(const vlCharArray& ia);
void operator+=(const vlCharArray& ia);
void operator+=(const unsigned char c);
unsigned char& operator[](const int i);
unsigned char *WriteInto(const int i, const int number);
// miscellaneous methods
void Squeeze();
int GetSize();
int GetMaxId();
unsigned char *GetArray();
void Reset();
private:
......@@ -72,6 +71,17 @@ inline unsigned char vlCharArray::GetValue(const int id) {return this->Array[id]
// Get the address of a particular data index.
inline unsigned char *vlCharArray::GetPtr(const int id) {return this->Array + id;};
// 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.
inline unsigned char *vlCharArray::WritePtr(const int id, const int number)
{
if ( (id + number) > this->Size ) this->Resize(id+number);
this->MaxId = id + number - 1;
return this->Array + id;
}
// Description:
// Insert data at a specified position in the array.
inline vlCharArray& vlCharArray::InsertValue(const int id, const unsigned char c)
......@@ -115,24 +125,9 @@ inline int vlCharArray::GetSize() {return this->Size;};
// Returning the maximum index of data inserted so far.
inline int vlCharArray::GetMaxId() {return this->MaxId;};
// Description:
// Get the pointer to the array. Useful for interfacing to C or
// FORTRAN routines.
inline unsigned char *vlCharArray::GetArray() {return this->Array;};
// Description:
// Reuse the memory allocated by this object. Objects appears like
// no data has been previously inserted.
inline void vlCharArray::Reset() {this->MaxId = -1;};
// Description:
// Get pointer to data. Useful for direct writes into object. MaxId is bumped
// by number (and memory allocated if necessary).
inline unsigned char *vlCharArray::WriteInto(const int id, const int number)
{
if ( (id + number) >= this->Size ) this->Resize(id+number);
this->MaxId = id + number - 1;
return this->Array + id;
}
#endif
......@@ -38,9 +38,10 @@ public:
// access/insertion methods
float GetValue(const int id);
float *GetPtr(const int id);
vlFloatArray &InsertValue(const int id, const float f);
int InsertNextValue(const float f);
float *GetPtr(const int id);
float *WritePtr(const int id, const int number);
// special operators
vlFloatArray &operator=(const vlFloatArray& fa);
......@@ -52,7 +53,6 @@ public:
void Squeeze();
int GetSize();
int GetMaxId();
float *GetArray();
void Reset();
private:
......@@ -71,6 +71,17 @@ inline float vlFloatArray::GetValue(const int id) {return this->Array[id];};
// Get the address of a particular data index.
inline float *vlFloatArray::GetPtr(const int id) {return this->Array + id;};
// 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.
inline float *vlFloatArray::WritePtr(const int id, const int number)
{
if ( (id + number) > this->Size ) this->Resize(id+number);
this->MaxId = id + number - 1;
return this->Array + id;
}
// Description:
// Insert data at a specified position in the array.
inline vlFloatArray& vlFloatArray::InsertValue(const int id, const float f)
......@@ -114,11 +125,6 @@ inline int vlFloatArray::GetSize() {return this->Size;};
// Returning the maximum index of data inserted so far.
inline int vlFloatArray::GetMaxId() {return this->MaxId;};
// Description:
// Get the pointer to the array. Useful for interfacing to C or
// FORTRAN routines.
inline float *vlFloatArray::GetArray() {return this->Array;};
// Description:
// Reuse the memory allocated by this object. Objects appears like
// no data has been previously inserted.
......
......@@ -41,13 +41,13 @@ public:
int GetNumberOfValuesPerPoint() {return 1;};
int GetNumberOfScalars() {return (this->S.GetMaxId()+1);};
void Squeeze() {this->S.Squeeze();};
unsigned char *GetUCharPtr() {return S.GetPtr(0);};
// miscellaneous
vlGraymap &operator=(const vlGraymap& fs);
void operator+=(const vlGraymap& fs) {this->S += fs.S;};
void Reset() {this->S.Reset();};
unsigned char *WriteInto(int id, int number);
unsigned char *GetPtr(const int id);
unsigned char *WritePtr(const int id, const int number);
// vlColorScalar interface.
unsigned char *GetColor(int id);
......@@ -60,12 +60,21 @@ protected:
vlCharArray S;
};
// Description:
// Get pointer to rgb data at location "id" in the array. Meant for reading
// data.
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).
inline unsigned char *vlGraymap::WriteInto(int id, int number)
// 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.
inline unsigned char *vlGraymap::WritePtr(const int id, const int number)
{
return this->S.WriteInto(id, number);
return this->S.WritePtr(id,number);
}
#endif
......@@ -38,9 +38,10 @@ public:
// access/insertion methods
int GetValue(const int id);
int *GetPtr(const int id);
vlIntArray &InsertValue(const int id, const int i);
int InsertNextValue(const int i);
int *GetPtr(const int id);
int *WritePtr(const int id, const int number);
// special operators
vlIntArray &operator=(const vlIntArray& ia);
......@@ -52,7 +53,6 @@ public:
void Squeeze();
int GetSize();
int GetMaxId();
int *GetArray();
void Reset();
private:
......@@ -71,6 +71,17 @@ inline int vlIntArray::GetValue(const int id) {return this->Array[id];};
// Get the address of a particular data index.
inline int *vlIntArray::GetPtr(const int id) {return this->Array + id;};
// 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.
inline int *vlIntArray::WritePtr(const int id, const int number)
{
if ( (id + number) > this->Size ) this->Resize(id+number);
this->MaxId = id + number - 1;
return this->Array + id;
}
// Description:
// Insert data at a specified position in the array.
inline vlIntArray& vlIntArray::InsertValue(const int id, const int i)
......@@ -114,11 +125,6 @@ inline int vlIntArray::GetSize() {return this->Size;};
// Returning the maximum index of data inserted so far.
inline int vlIntArray::GetMaxId() {return this->MaxId;};
// Description:
// Get the pointer to the array. Useful for interfacing to C or
// FORTRAN routines.
inline int *vlIntArray::GetArray() {return this->Array;};
// Description:
// Reuse the memory allocated by this object. Objects appears like
// no data has been previously inserted.
......
......@@ -41,13 +41,13 @@ public:
int GetNumberOfScalars() {return (this->S.GetMaxId()+1)/3;};
void Squeeze() {this->S.Squeeze();};
int GetNumberOfValuesPerPoint() {return 3;};
unsigned char *GetUCharPtr() {return S.GetPtr(0);};
// miscellaneous
vlPixmap &operator=(const vlPixmap& fs);
void operator+=(const vlPixmap& fs) {this->S += fs.S;};
void Reset() {this->S.Reset();};
unsigned char *WriteInto(int id, int number);
unsigned char *GetPtr(const int id);
unsigned char *WritePtr(const int id, const int number);
// vlColorScalar interface.
unsigned char *GetColor(int id);
......@@ -97,12 +97,21 @@ inline int vlPixmap::InsertNextColor(unsigned char *rgb)
return id/3;
}
// Description:
// Get pointer to rgb data at location "id" in the array. Meant for reading
// data.
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).
inline unsigned char *vlPixmap::WriteInto(int id, int number)
// 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.
inline unsigned char *vlPixmap::WritePtr(const int id, const int number)
{
return this->S.WriteInto(id, number);
return this->S.WritePtr(3*id,3*number);
}
#endif
......@@ -38,9 +38,10 @@ public:
// access/insertion methods
short GetValue(const int id);
short *GetPtr(const int id);
vlShortArray &InsertValue(const int id, const short i);
int InsertNextValue(const int short);
short *GetPtr(const int id);
short *WritePtr(const int id, const int number);
// special operators
vlShortArray &operator=(const vlShortArray& ia);
......@@ -71,6 +72,17 @@ inline short vlShortArray::GetValue(const int id) {return this->Array[id];};
// Get the address of a particular data index.
inline short *vlShortArray::GetPtr(const int id) {return this->Array + id;};
// 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.
inline short *vlShortArray::WritePtr(const int id, const int number)
{
if ( (id + number) > this->Size ) this->Resize(id+number);
this->MaxId = id + number - 1;
return this->Array + id;
}
// Description:
// Insert data at a specified position in the array.
inline vlShortArray& vlShortArray::InsertValue(const int id, const short i)
......
......@@ -81,10 +81,10 @@ public:
virtual void Squeeze() = 0;
// Description:
// Get data as pointer to unsigned char. Used for high performance texture
// and color manipulation. Not supported for all scalar types: check for
// NULL return value.
virtual unsigned char *GetUCharPtr() {return NULL;};
// 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;};
void GetScalars(vlIdList& ptId, vlFloatScalars& fs);
virtual void ComputeRange();
......
......@@ -38,9 +38,10 @@ public:
// access/insertion methods
void* GetValue(const int id);
void** GetPtr(const int id);
vlVoidArray &InsertValue(const int id, void* p);
int InsertNextValue(void* v);
void** GetPtr(const int id);
void** WritePtr(const int id, const int number);
// special operators
vlVoidArray &operator=(const vlVoidArray& fa);
......@@ -52,7 +53,6 @@ public:
void Squeeze();
int GetSize();
int GetMaxId();
void** GetArray();
void Reset();
private:
......@@ -71,6 +71,17 @@ inline void* vlVoidArray::GetValue(const int id) {return this->Array[id];};
// Get the address of a particular data index.
inline void** vlVoidArray::GetPtr(const int id) {return this->Array + id;};
// 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.
inline void** vlVoidArray::WritePtr(const int id, const int number)
{
if ( (id + number) > this->Size ) this->Resize(id+number);
this->MaxId = id + number - 1;
return this->Array + id;
}
// Description:
// Insert data at a specified position in the array.
inline vlVoidArray& vlVoidArray::InsertValue(const int id, void* p)
......@@ -114,11 +125,6 @@ inline int vlVoidArray::GetSize() {return this->Size;};
// Returning the maximum index of data inserted so far.
inline int vlVoidArray::GetMaxId() {return this->MaxId;};
// Description:
// Get the pointer to the array. Useful for interfacing to C or
// FORTRAN routines.
inline void** vlVoidArray::GetArray() {return this->Array;};
// Description:
// Reuse the memory allocated by this object. Objects appears like
// no data has been previously inserted.
......
......@@ -129,8 +129,8 @@ void vlBitArray::PrintSelf(ostream& os, vlIndent indent)
}
//
// Private function does "reallocate"
//
// Private function does "reallocate". Sz is the number of "bits", and we
// can allocate only 8-bit bytes.
unsigned char *vlBitArray::Resize(const int sz)
{
unsigned char *newArray;
......
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