Commit 878930bf authored by Charles Law's avatar Charles Law
Browse files

Array objects are ref counted.

parent 4fe54ed9
......@@ -40,6 +40,31 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
=========================================================================*/
#include "vtkAGraymap.h"
vtkAGraymap::vtkAGraymap()
{
this->S = new vtkUnsignedCharArray;
}
vtkAGraymap::vtkAGraymap(const vtkAGraymap& fs)
{
this->S = new vtkUnsignedCharArray;
*(this->S) = *(fs.S);
}
vtkAGraymap::vtkAGraymap(const int sz, const int ext=1000)
{
this->S = new vtkUnsignedCharArray(2*sz,2*ext);
}
vtkAGraymap::~vtkAGraymap()
{
this->S->Delete();
}
vtkScalars *vtkAGraymap::MakeObject(int sze, int ext)
{
return new vtkAGraymap(sze,ext);
......@@ -47,7 +72,7 @@ vtkScalars *vtkAGraymap::MakeObject(int sze, int ext)
float vtkAGraymap::GetScalar(int i)
{
return (float)(this->S.GetValue(2*i));
return (float)(this->S->GetValue(2*i));
}
// Description:
......@@ -55,8 +80,8 @@ float vtkAGraymap::GetScalar(int i)
unsigned char *vtkAGraymap::GetColor(int id)
{
static unsigned char rgba[4];
rgba[0] = rgba[1] = rgba[2] = this->S.GetValue(2*id);
rgba[3] = this->S.GetValue(2*id+1);
rgba[0] = rgba[1] = rgba[2] = this->S->GetValue(2*id);
rgba[3] = this->S->GetValue(2*id+1);
return rgba;
}
......@@ -66,15 +91,15 @@ unsigned char *vtkAGraymap::GetColor(int id)
// point id.
void vtkAGraymap::GetColor(int id, unsigned char rgba[4])
{
rgba[0] = rgba[1] = rgba[2] = this->S.GetValue(2*id);
rgba[3] = this->S.GetValue(2*id+1);
rgba[0] = rgba[1] = rgba[2] = this->S->GetValue(2*id);
rgba[3] = this->S->GetValue(2*id+1);
}
// Description:
// Deep copy of scalars.
vtkAGraymap& vtkAGraymap::operator=(const vtkAGraymap& fs)
{
this->S = fs.S;
*(this->S) = *(fs.S);
return *this;
}
......@@ -83,8 +108,8 @@ vtkAGraymap& vtkAGraymap::operator=(const vtkAGraymap& fs)
unsigned char *vtkAGraymap::GetAGrayValue(int id)
{
static unsigned char ga[2];
ga[0] = this->S.GetValue(2*id);
ga[1] = this->S.GetValue(2*id+1);
ga[0] = this->S->GetValue(2*id);
ga[1] = this->S->GetValue(2*id+1);
return ga;
}
......@@ -95,13 +120,13 @@ unsigned char *vtkAGraymap::GetAGrayValue(int id)
void vtkAGraymap::GetAGrayValue(int id, unsigned char ga[2])
{
id *= 2;
ga[0] = this->S.GetValue(id);
ga[1] = this->S.GetValue(id+1);
ga[0] = this->S->GetValue(id);
ga[1] = this->S->GetValue(id+1);
}
void vtkAGraymap::SetNumberOfColors(int number)
{
this->S.SetNumberOfValues(number*2);
this->S->SetNumberOfValues(number*2);
}
// Description:
......@@ -111,8 +136,8 @@ void vtkAGraymap::SetNumberOfColors(int number)
void vtkAGraymap::SetAGrayValue(int i, unsigned char ga[2])
{
i *= 2;
this->S.SetValue(i, ga[0]);
this->S.SetValue(i+1, ga[1]);
this->S->SetValue(i, ga[0]);
this->S->SetValue(i+1, ga[1]);
}
// Description:
......@@ -121,8 +146,8 @@ void vtkAGraymap::SetAGrayValue(int i, unsigned char ga[2])
void vtkAGraymap::InsertAGrayValue(int i, unsigned char ga[2])
{
i *= 2;
this->S.InsertValue(i+1, ga[1]);
this->S.SetValue(i, ga[0]);
this->S->InsertValue(i+1, ga[1]);
this->S->SetValue(i, ga[0]);
}
// Description:
......@@ -132,8 +157,8 @@ int vtkAGraymap::InsertNextAGrayValue(unsigned char ga[2])
{
int id;
id = this->S.InsertNextValue(ga[0]);
this->S.InsertNextValue(ga[1]);
id = this->S->InsertNextValue(ga[0]);
this->S->InsertNextValue(ga[1]);
return id/2;
}
......@@ -60,24 +60,26 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
class VTK_EXPORT vtkAGraymap : public vtkColorScalars
{
public:
vtkAGraymap() {};
vtkAGraymap(const vtkAGraymap& fs) {this->S = fs.S;};
vtkAGraymap(const int sz, const int ext=1000):S(2*sz,2*ext){};
int Allocate(const int sz, const int ext=1000) {return this->S.Allocate(2*sz,2*ext);};
void Initialize() {this->S.Initialize();};
vtkAGraymap();
vtkAGraymap(const vtkAGraymap& fs);
vtkAGraymap(const int sz, const int ext=1000);
~vtkAGraymap();
int Allocate(const int sz, const int ext=1000) {return this->S->Allocate(2*sz,2*ext);};
void Initialize() {this->S->Initialize();};
char *GetClassName() {return "vtkAGraymap";};
// vtkScalar interface
vtkScalars *MakeObject(int sze, int ext=1000);
int GetNumberOfScalars() {return (this->S.GetMaxId()+1)/2;};
void Squeeze() {this->S.Squeeze();};
int GetNumberOfScalars() {return (this->S->GetMaxId()+1)/2;};
void Squeeze() {this->S->Squeeze();};
int GetNumberOfValuesPerScalar() {return 2;};
float GetScalar(int i);
// miscellaneous
vtkAGraymap &operator=(const vtkAGraymap& fs);
void operator+=(const vtkAGraymap& fs) {this->S += fs.S;};
void Reset() {this->S.Reset();};
void operator+=(const vtkAGraymap& 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);
......@@ -97,7 +99,7 @@ public:
int InsertNextAGrayValue(unsigned char ga[2]);
protected:
vtkUnsignedCharArray S;
vtkUnsignedCharArray *S;
};
// Description:
......@@ -110,8 +112,8 @@ inline void vtkAGraymap::SetColor(int i, unsigned char rgba[4])
g = (g > 255.0 ? 255.0 : g);
i *= 2;
this->S.SetValue(i, (unsigned char)g);
this->S.SetValue(i+1, rgba[3]);
this->S->SetValue(i, (unsigned char)g);
this->S->SetValue(i+1, rgba[3]);
}
// Description:
......@@ -122,8 +124,8 @@ inline void vtkAGraymap::InsertColor(int i, unsigned char rgba[4])
float g = 0.30*rgba[0] + 0.59*rgba[1] + 0.11*rgba[2];
g = (g > 255.0 ? 255.0 : g);
this->S.InsertValue(2*i+1, rgba[3]);
this->S.SetValue(2*i, (unsigned char)g);
this->S->InsertValue(2*i+1, rgba[3]);
this->S->SetValue(2*i, (unsigned char)g);
}
// Description:
......@@ -135,8 +137,8 @@ inline int vtkAGraymap::InsertNextColor(unsigned char rgba[4])
float g = 0.30*rgba[0] + 0.59*rgba[1] + 0.11*rgba[2];
g = (g > 255.0 ? 255.0 : g);
id = this->S.InsertNextValue((unsigned char)g);
this->S.InsertNextValue(rgba[3]);
id = this->S->InsertNextValue((unsigned char)g);
this->S->InsertNextValue(rgba[3]);
return id/2;
}
......@@ -146,7 +148,7 @@ inline int vtkAGraymap::InsertNextColor(unsigned char rgba[4])
// data is a list of repeated intensity/alpha pairs.
inline unsigned char *vtkAGraymap::GetPtr(const int id)
{
return this->S.GetPtr(2*id);
return this->S->GetPtr(2*id);
}
// Description:
......@@ -156,7 +158,7 @@ inline unsigned char *vtkAGraymap::GetPtr(const int id)
// write.
inline unsigned char *vtkAGraymap::WritePtr(const int id, const int number)
{
return this->S.WritePtr(2*id,2*number);
return this->S->WritePtr(2*id,2*number);
}
#endif
......@@ -40,6 +40,27 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
=========================================================================*/
#include "vtkAPixmap.h"
vtkAPixmap::vtkAPixmap()
{
this->S = new vtkUnsignedCharArray;
}
vtkAPixmap::vtkAPixmap(const vtkAPixmap& fs)
{
this->S = new vtkUnsignedCharArray;
*(this->S) = *(fs.S);
}
vtkAPixmap::vtkAPixmap(const int sz, const int ext=1000)
{
this->S = new vtkUnsignedCharArray(4*sz,4*ext);
}
vtkAPixmap::~vtkAPixmap()
{
this->S->Delete();
}
vtkScalars *vtkAPixmap::MakeObject(int sze, int ext)
{
return new vtkAPixmap(sze,ext);
......@@ -49,7 +70,7 @@ vtkScalars *vtkAPixmap::MakeObject(int sze, int ext)
// Deep copy of scalars.
vtkAPixmap& vtkAPixmap::operator=(const vtkAPixmap& fs)
{
this->S = fs.S;
*(this->S) = *(fs.S);
return *this;
}
......@@ -60,7 +81,7 @@ void vtkAPixmap::GetColor(int id, unsigned char rgba[4])
{
unsigned char *_rgba;
_rgba = this->S.GetPtr(4*id);
_rgba = this->S->GetPtr(4*id);
rgba[0] = _rgba[0];
rgba[1] = _rgba[1];
rgba[2] = _rgba[2];
......@@ -69,7 +90,7 @@ void vtkAPixmap::GetColor(int id, unsigned char rgba[4])
void vtkAPixmap::SetNumberOfColors(int number)
{
this->S.SetNumberOfValues(number*4);
this->S->SetNumberOfValues(number*4);
}
// Description:
......@@ -77,7 +98,7 @@ void vtkAPixmap::SetNumberOfColors(int number)
void vtkAPixmap::SetColor(int id, unsigned char rgba[4])
{
id *= 4;
memcpy (this->S.GetPtr(id), rgba, 4);
memcpy (this->S->GetPtr(id), rgba, 4);
}
// Description:
......@@ -86,15 +107,15 @@ void vtkAPixmap::SetColor(int id, unsigned char rgba[4])
void vtkAPixmap::InsertColor(int id, unsigned char rgba[4])
{
id *= 4;
for(int j=0; j<4; j++) this->S.InsertValue(id+j,rgba[j]);
for(int j=0; j<4; j++) this->S->InsertValue(id+j,rgba[j]);
}
// Description:
// Insert color into next available slot. Returns point id of slot.
int vtkAPixmap::InsertNextColor(unsigned char rgba[4])
{
int id = this->S.InsertNextValue(rgba[0]);
for(int j=1; j<4; j++) this->S.InsertNextValue(rgba[j]);
int id = this->S->InsertNextValue(rgba[0]);
for(int j=1; j<4; j++) this->S->InsertNextValue(rgba[j]);
return id/4;
}
......@@ -56,23 +56,25 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
class VTK_EXPORT vtkAPixmap : public vtkColorScalars
{
public:
vtkAPixmap() {};
vtkAPixmap(const vtkAPixmap& fs) {this->S = fs.S;};
vtkAPixmap(const int sz, const int ext=1000):S(4*sz,4*ext){};
int Allocate(const int sz, const int ext=1000) {return this->S.Allocate(4*sz,4*ext);};
void Initialize() {this->S.Initialize();};
vtkAPixmap();
vtkAPixmap(const vtkAPixmap& fs);
vtkAPixmap(const int sz, const int ext=1000);
~vtkAPixmap();
int Allocate(const int sz, const int ext=1000) {return this->S->Allocate(4*sz,4*ext);};
void Initialize() {this->S->Initialize();};
char *GetClassName() {return "vtkAPixmap";};
// vtkScalar interface
vtkScalars *MakeObject(int sze, int ext=1000);
int GetNumberOfScalars() {return (this->S.GetMaxId()+1)/4;};
void Squeeze() {this->S.Squeeze();};
int GetNumberOfScalars() {return (this->S->GetMaxId()+1)/4;};
void Squeeze() {this->S->Squeeze();};
int GetNumberOfValuesPerScalar() {return 4;};
// miscellaneous
vtkAPixmap &operator=(const vtkAPixmap& fs);
void operator+=(const vtkAPixmap& fs) {this->S += fs.S;};
void Reset() {this->S.Reset();};
void operator+=(const vtkAPixmap& 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);
......@@ -85,21 +87,21 @@ public:
int InsertNextColor(unsigned char rgba[4]);
protected:
vtkUnsignedCharArray S;
vtkUnsignedCharArray *S;
};
// Description:
// Return a rgba color at array location i.
inline unsigned char *vtkAPixmap::GetColor(int i)
{
return this->S.GetPtr(4*i);
return this->S->GetPtr(4*i);
}
// Description:
// Get pointer to array of data starting at data position "id".
inline unsigned char *vtkAPixmap::GetPtr(const int id)
{
return this->S.GetPtr(4*id);
return this->S->GetPtr(4*id);
}
// Description:
......@@ -109,7 +111,7 @@ inline unsigned char *vtkAPixmap::GetPtr(const int id)
// write.
inline unsigned char *vtkAPixmap::WritePtr(const int id, const int number)
{
return this->S.WritePtr(4*id,4*number);
return this->S->WritePtr(4*id,4*number);
}
#endif
......@@ -40,6 +40,27 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
=========================================================================*/
#include "vtkBitScalars.h"
vtkBitScalars::vtkBitScalars()
{
this->S = new vtkBitArray;
}
vtkBitScalars::vtkBitScalars(const vtkBitScalars& cs)
{
this->S = new vtkBitArray;
*(this->S) = *(cs.S);
}
vtkBitScalars::vtkBitScalars(const int sz, const int ext=1000)
{
this->S = new vtkBitArray(sz,ext);
}
vtkBitScalars::~vtkBitScalars()
{
this->S->Delete();
}
vtkScalars *vtkBitScalars::MakeObject(int sze, int ext)
{
return new vtkBitScalars(sze,ext);
......@@ -49,7 +70,7 @@ vtkScalars *vtkBitScalars::MakeObject(int sze, int ext)
// Deep copy of scalars.
vtkBitScalars& vtkBitScalars::operator=(const vtkBitScalars& cs)
{
this->S = cs.S;
*(this->S) = *(cs.S);
return *this;
}
......@@ -57,6 +78,6 @@ void vtkBitScalars::GetScalars(vtkIdList& ptId, vtkFloatScalars& fs)
{
for (int i=0; i<ptId.GetNumberOfIds(); i++)
{
fs.InsertScalar(i,(float)this->S.GetValue(ptId.GetId(i)));
fs.InsertScalar(i,(float)this->S->GetValue(ptId.GetId(i)));
}
}
......@@ -53,49 +53,51 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
class VTK_EXPORT vtkBitScalars : public vtkScalars
{
public:
vtkBitScalars() {};
vtkBitScalars(const vtkBitScalars& cs) {this->S = cs.S;};
vtkBitScalars(const int sz, const int ext=1000):S(sz,ext){};
int Allocate(const int sz, const int ext=1000) {return this->S.Allocate(sz,ext);};
void Initialize() {this->S.Initialize();};
vtkBitScalars();
vtkBitScalars(const vtkBitScalars& cs);
vtkBitScalars(const int sz, const int ext=1000);
~vtkBitScalars();
int Allocate(const int sz, const int ext=1000) {return this->S->Allocate(sz,ext);};
void Initialize() {this->S->Initialize();};
char *GetClassName() {return "vtkBitScalars";};
// vtkScalar interface
vtkScalars *MakeObject(int sze, int ext=1000);
char *GetDataType() {return "bit";};
int GetNumberOfScalars() {return (this->S.GetMaxId()+1);};
void Squeeze() {this->S.Squeeze();};
float GetScalar(int i) {return (float)this->S.GetValue(i);};
int GetNumberOfScalars() {return (this->S->GetMaxId()+1);};
void Squeeze() {this->S->Squeeze();};
float GetScalar(int i) {return (float)this->S->GetValue(i);};
void SetNumberOfScalars(int number);
void SetScalar(int i, int s) {this->S.SetValue(i,s);};
void SetScalar(int i, float s) {this->S.SetValue(i,(int)s);};
void InsertScalar(int i, float s) {S.InsertValue(i,(int)s);};
void InsertScalar(int i, int s) {S.InsertValue(i,s);};
int InsertNextScalar(int s) {return S.InsertNextValue(s);};
int InsertNextScalar(float s) {return S.InsertNextValue((int)s);};
void SetScalar(int i, int s) {this->S->SetValue(i,s);};
void SetScalar(int i, float s) {this->S->SetValue(i,(int)s);};
void InsertScalar(int i, float s) {S->InsertValue(i,(int)s);};
void InsertScalar(int i, int s) {S->InsertValue(i,s);};
int InsertNextScalar(int s) {return S->InsertNextValue(s);};
int InsertNextScalar(float s) {return S->InsertNextValue((int)s);};
void GetScalars(vtkIdList& ptIds, vtkFloatScalars& fs);
// miscellaneous
unsigned char *GetPtr(const int id);
unsigned char *WritePtr(const int id, const int number);
vtkBitScalars &operator=(const vtkBitScalars& cs);
void operator+=(const vtkBitScalars& cs) {this->S += cs.S;};
void Reset() {this->S.Reset();};
void operator+=(const vtkBitScalars& cs) {*(this->S) += *(cs.S);};
void Reset() {this->S->Reset();};
protected:
vtkBitArray S;
vtkBitArray *S;
};
inline void vtkBitScalars::SetNumberOfScalars(int number)
{
this->S.SetNumberOfValues(number);
this->S->SetNumberOfValues(number);
}
// Description:
// Get pointer to array of data starting at data position "id".
inline unsigned char *vtkBitScalars::GetPtr(const int id)
{
return this->S.GetPtr(id);
return this->S->GetPtr(id);
}
// Description:
......@@ -105,7 +107,7 @@ inline unsigned char *vtkBitScalars::GetPtr(const int id)
// write.
inline unsigned char *vtkBitScalars::WritePtr(const int id, const int number)
{
return this->S.WritePtr(id,number);
return this->S->WritePtr(id,number);
}
#endif
......@@ -40,6 +40,27 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
=========================================================================*/
#include "vtkBitmap.h"
vtkBitmap::vtkBitmap()
{
this->S = new vtkBitArray;
}
vtkBitmap::vtkBitmap(const vtkBitmap& fs)
{
this->S = new vtkBitArray;
*(this->S) = *(fs.S);
}
vtkBitmap::vtkBitmap(const int sz, const int ext=1000)
{
this->S = new vtkBitArray(sz,ext);
}
vtkBitmap::~vtkBitmap()
{
this->S->Delete();
}
vtkScalars *vtkBitmap::MakeObject(int sze, int ext)
{
return new vtkBitmap(sze,ext);
......@@ -49,7 +70,7 @@ vtkScalars *vtkBitmap::MakeObject(int sze, int ext)
// Deep copy of scalars.
vtkBitmap& vtkBitmap::operator=(const vtkBitmap& fs)
{
this->S = fs.S;
*(this->S) = *(fs.S);
return *this;
}
......@@ -58,7 +79,7 @@ vtkBitmap& vtkBitmap::operator=(const vtkBitmap& fs)
unsigned char *vtkBitmap::GetColor(int id)
{
static unsigned char rgba[4];
rgba[0] = rgba[1] = rgba[2] = this->S.GetValue(id);
rgba[0] = rgba[1] = rgba[2] = this->S->GetValue(id);
rgba[3] = 255;
return rgba;
}
......@@ -67,7 +88,7 @@ unsigned char *vtkBitmap::GetColor(int id)
// Get rgba color value for id indicated.
void vtkBitmap::GetColor(int id, unsigned char rgba[4])
{
rgba[0] = rgba[1] = rgba[2] = this->S.GetValue(id);
rgba[0] = rgba[1] = rgba[2] = this->S->GetValue(id);
rgba[3] = 255;
}
......@@ -76,7 +97,7 @@ void vtkBitmap::GetColor(int id, unsigned char rgba[4])
void vtkBitmap::SetColor(int id, unsigned char rgba[4])
{
unsigned char b=rgba[0]|rgba[1]|rgba[2];
this->S.SetValue(id,b);
this->S->SetValue(id,b);
}
// Description:
......@@ -85,7 +106,7 @@ void vtkBitmap::SetColor(int id, unsigned char rgba[4])
void vtkBitmap::InsertColor(int id, unsigned char rgba[4])
{
unsigned char b=rgba[0]|rgba[1]|rgba[2];
this->S.InsertValue(id,b);
this->S->InsertValue(id,b);
}
// Description:
......@@ -93,7 +114,7 @@ void vtkBitmap::InsertColor(int id, unsigned char rgba[4])
int vtkBitmap::InsertNextColor(unsigned char rgba[4])
{
unsigned char b=rgba[0]|rgba[1]|rgba[2];
int id = this->S.InsertNextValue(b);
int id = this->S->InsertNextValue(b);
return id;
}
......@@ -57,22 +57,24 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
class VTK_EXPORT vtkBitmap : public vtkColorScalars
{
public:
vtkBitmap() {};
vtkBitmap(const vtkBitmap& fs) {this->S = fs.S;};
vtkBitmap(const int sz, const int ext=1000):S(sz,ext){};
int Allocate(const int sz, const int ext=1000) {return this->S.Allocate(sz,ext);};
void Initialize() {this->S.Initialize();};
vtkBitmap();
vtkBitmap(const vtkBitmap& fs);
vtkBitmap(const int sz, const int ext=1000);
~vtkBitmap();
int Allocate(const int sz, const int ext=1000) {return this->S->Allocate(sz,ext);};
void Initialize() {this->S->Initialize();};
char *GetClassName() {return "vtkBitmap";};
// vtkScalar interface
vtkScalars *MakeObject(int sze, int ext=1000);
int GetNumberOfScalars() {return (this->S.GetMaxId()+1);};
void Squeeze() {this->S.Squeeze();};
int GetNumberOfScalars() {return (this->S->GetMaxId()+1);};
void Squeeze() {this->S->Squeeze();};
// miscellaneous
vtkBitmap &operator=(const vtkBitmap& fs);
void operator+=(const vtkBitmap& fs) {this->S += fs.S;};
void Reset() {this->S.