Commit 9c95e412 authored by Will Schroeder's avatar Will Schroeder
Browse files

Initial revision

parent 76b181ba
/*=========================================================================
Program: Visualization Library
Module: CArray.hh
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the Visualization Library. No part of this file
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
//
// Dynamic, self adjusting char array
//
#ifndef __vlCharArray_h
#define __vlCharArray_h
#include "Object.hh"
class vlCharArray : public vlObject
{
public:
vlCharArray():Array(0),Size(0),MaxId(-1),Extend(1000) {};
int Initialize(const int sz, const int ext);
vlCharArray(const int sz, const int ext);
vlCharArray(const vlCharArray& ia);
~vlCharArray();
char GetValue(const int id) {return this->Array[id];};
char *GetPtr(const int id) {return this->Array + id;};
vlCharArray &InsertValue(const int id, const int i)
{if ( id >= this->Size ) this->Resize(id);
this->Array[id] = i;
if ( id > this->MaxId ) this->MaxId = id;
return *this;
}
int InsertNextValue(const int i)
{this->InsertValue (++this->MaxId,i); return this->MaxId;};
vlCharArray &operator=(vlCharArray& ia);
void operator+=(vlCharArray& ia);
void operator+=(const char i) {this->InsertNextValue(i);};
// operator[] can be used on both left and right side of expression;
// Note: if used on lh side, user's responsibility to do range checking
char& operator[](const int i) {return this->Array[i];};
void Squeeze() {this->Resize (this->MaxId+1);};
int GetSize() {return this->Size;};
int GetMaxId() {return this->MaxId;};
char *GetArray() {return this->Array;};
void Reset() {this->MaxId = -1;};
virtual char *GetClassName() {return "vlCharArray";};
void PrintSelf(ostream& os, vlIndent indent);
private:
char *Array; // pointer to data
int Size; // allocated size of data
int MaxId; // maximum index inserted thus iar
int Extend; // grow array by this point
char *Resize(const int sz); // function to resize data
};
#endif
/*=========================================================================
Program: Visualization Library
Module: CScalars.hh
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the Visualization Library. No part of this file
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
//
// Char representation of scalars
//
// use internal char array to represent data
//
#ifndef __vlCharScalars_h
#define __vlCharScalars_h
#include "Scalars.hh"
#include "CArray.hh"
class vlCharScalars : public vlScalars
{
public:
vlCharScalars() {};
vlScalars *MakeObject(int sze, int ext=1000);
int Initialize(const int sz, const int ext=1000)
{return S.Initialize(sz,ext);};
vlCharScalars(const vlCharScalars& cs) {this->S = cs.S;};
vlCharScalars(const int sz, const int ext=1000):S(sz,ext){};
~vlCharScalars() {};
char *GetClassName() {return "vlCharScalars";};
int NumberOfScalars() {return (this->S.GetMaxId()+1);};
void Reset() {this->S.Reset();};
void Squeeze() {this->S.Squeeze();};
vlCharScalars &operator=(const vlCharScalars& cs);
void operator+=(const vlCharScalars& cs) {this->S += cs.S;};
// float conversion for abstract computation
float GetScalar(int i) {return (float)this->S[i];};
void SetScalar(int i, char s) {this->S[i] = s;};
void SetScalar(int i, float s) {this->S[i] = (char)s;};
void InsertScalar(int i, float s) {S.InsertValue(i,(char)s);};
void InsertScalar(int i, char s) {S.InsertValue(i,s);};
int InsertNextScalar(char s) {return S.InsertNextValue(s);};
private:
vlCharArray S;
};
#endif
/*=========================================================================
Program: Visualization Library
Module: SArray.hh
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the Visualization Library. No part of this file
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
//
// Dynamic, self adjusting short array
//
#ifndef __vlShortArray_h
#define __vlShortArray_h
#include "Object.hh"
class vlShortArray : public vlObject
{
public:
vlShortArray():Array(0),Size(0),MaxId(-1),Extend(1000) {};
int Initialize(const int sz, const int ext=1000);
vlShortArray(const int sz, const int ext=1000);
vlShortArray(const vlShortArray& sa);
~vlShortArray();
short GetValue(const int id) {return this->Array[id];};
short *GetPtr(const int id) {return this->Array + id;};
vlShortArray &InsertValue(const int id, const short i)
{if ( id >= this->Size ) this->Resize(id);
this->Array[id] = i;
if ( id > this->MaxId ) this->MaxId = id;
return *this;
}
int InsertNextValue(const short i)
{this->InsertValue (++this->MaxId,i); return this->MaxId;};
vlShortArray &operator=(vlShortArray& sa);
vlShortArray operator+=(vlShortArray& sa);
void operator+=(const short i) {this->InsertNextValue(i);};
// operator[] can be used on both left and right side of expression;
// Note: if used on lh side, user's responsibility to do range checking
short& operator[](const int i) {return this->Array[i];};
void Squeeze() {this->Resize (this->MaxId+1);};
int GetSize() {return this->Size;};
int GetMaxId() {return this->MaxId;};
short *GetArray() {return this->Array;};
void Reset() {this->MaxId = -1;};
virtual char *GetClassName() {return "vlShortArray";};
void PrintSelf(ostream& os, vlIndent indent);
private:
short *Array; // pointer to data
int Size; // allocated size of data
int MaxId; // maximum index inserted thus far
int Extend; // grow array by this point
short *Resize(const int sz); // function to resize data
};
#endif
/*=========================================================================
Program: Visualization Library
Module: SScalars.hh
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the Visualization Library. No part of this file
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
//
// Short representation of scalars
//
// use internal short array to represent data
//
#ifndef __vlShortScalars_h
#define __vlShortScalars_h
#include "Scalars.hh"
#include "SArray.hh"
class vlShortScalars : public vlScalars
{
public:
vlShortScalars() {};
vlScalars *MakeObject(int sze, int ext=1000);
int Initialize(const int sz, const int ext=1000)
{return S.Initialize(sz,ext);};
vlShortScalars(const vlShortScalars& ss) {this->S = ss.S;};
vlShortScalars(const int sz, const int ext=1000):S(sz,ext){};
~vlShortScalars() {};
char *GetClassName() {return "vlShortScalars";};
int NumberOfScalars() {return (this->S.GetMaxId()+1);};
void Reset() {this->S.Reset();};
void Squeeze() {this->S.Squeeze();};
vlShortScalars &operator=(const vlShortScalars& ss);
void operator+=(const vlShortScalars& ss) {this->S += ss.S;};
// float conversion for abstract computation
float GetScalar(int i) {return (float)this->S[i];};
void SetScalar(int i, short s) {this->S[i] = s;};
void SetScalar(int i, float s) {this->S[i] = (short)s;};
void InsertScalar(int i, float s) {S.InsertValue(i,(short)s);};
void InsertScalar(int i, short s) {S.InsertValue(i,s);};
int InsertNextScalar(short s) {return S.InsertNextValue(s);};
private:
vlShortArray S;
};
#endif
/*=========================================================================
Program: Visualization Library
Module: CArray.cc
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the Visualization Library. No part of this file
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
//
// Dynamic, self adjusting char array
//
//
#include "CArray.hh"
vlCharArray::Initialize(const int sz, const int ext)
{
if ( this->Array != 0 ) delete [] this->Array;
this->Size = ( sz > 0 ? sz : 1);
if ( (this->Array = new char[sz]) == 0 ) return 0;
this->Extend = ( ext > 0 ? ext : 1);
this->MaxId = -1;
return 1;
}
vlCharArray::vlCharArray(const int sz, const int ext)
{
this->Size = ( sz > 0 ? sz : 1);
this->Array = new char[sz];
this->Extend = ( ext > 0 ? ext : 1);
this->MaxId = -1;
}
vlCharArray::~vlCharArray()
{
delete [] this->Array;
}
vlCharArray::vlCharArray(const vlCharArray& ia)
{
int i;
this->MaxId = ia.MaxId;
this->Size = ia.Size;
this->Extend = ia.Extend;
this->Array = new char[this->Size];
for (i=0; i<this->MaxId; i++)
this->Array[i] = ia.Array[i];
}
vlCharArray& vlCharArray::operator=(vlCharArray& ia)
{
int i;
if ( this != &ia )
{
delete [] this->Array;
this->MaxId = ia.MaxId;
this->Size = ia.Size;
this->Extend = ia.Extend;
this->Array = new char[this->Size];
for (i=0; i<=this->MaxId; i++)
this->Array[i] = ia.Array[i];
}
return *this;
}
//
// Copy on write if used by more than one object
//
void vlCharArray::operator+=(vlCharArray& ia)
{
int i, sz;
if ( this->Size <= (sz = this->MaxId + ia.MaxId + 2) ) this->Resize(sz);
for (i=0; i<=ia.MaxId; i++)
{
this->Array[this->MaxId+1+i] = ia.Array[i];
}
this->MaxId += ia.MaxId + 1;
}
void vlCharArray::PrintSelf(ostream& os, vlIndent indent)
{
if (this->ShouldIPrint(vlCharArray::GetClassName()))
{
vlObject::PrintSelf(os,indent);
os << indent << "Array: " << this->Array << "\n";
os << indent << "Size: " << this->Size << "\n";
os << indent << "MaxId: " << this->MaxId << "\n";
os << indent << "Extend size: " << this->Extend << "\n";
}
}
//
// Private function does "reallocate"
//
char *vlCharArray::Resize(const int sz)
{
int i;
char *newArray;
int newSize;
if ( sz >= this->Size ) newSize = this->Size +
this->Extend*(((sz-this->Size)/this->Extend)+1);
else newSize = sz;
if ( (newArray = new char[newSize]) == 0 )
{
cerr << "Cannot allocate memory\n";
return 0;
}
for (i=0; i<sz && i<this->Size; i++)
newArray[i] = this->Array[i];
this->Size = newSize;
delete [] this->Array;
this->Array = newArray;
return this->Array;
}
/*=========================================================================
Program: Visualization Library
Module: CScalars.cc
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the Visualization Library. No part of this file
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
//
// Scalar values, floating representation
//
#include "CScalars.hh"
vlScalars *vlCharScalars::MakeObject(int sze, int ext)
{
return new vlCharScalars(sze,ext);
}
vlCharScalars& vlCharScalars::operator=(const vlCharScalars& cs)
{
this->S = cs.S;
return *this;
}
/*=========================================================================
Program: Visualization Library
Module: SArray.cc
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the Visualization Library. No part of this file
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
//
// Dynamic, self adjusting short array
//
//
#include "SArray.hh"
vlShortArray::Initialize(const int sz, const int ext)
{
if ( this->Array != 0 ) delete [] this->Array;
this->Size = ( sz > 0 ? sz : 1);
if ( (this->Array = new short[sz]) == 0 ) return 0;
this->Extend = ( ext > 0 ? ext : 1);
this->MaxId = -1;
return 1;
}
vlShortArray::vlShortArray(const int sz, const int ext)
{
this->Size = ( sz > 0 ? sz : 1);
this->Array = new short[sz];
this->Extend = ( ext > 0 ? ext : 1);
this->MaxId = -1;
}
vlShortArray::~vlShortArray()
{
delete [] this->Array;
}
vlShortArray::vlShortArray(const vlShortArray& sa)
{
int i;
this->MaxId = sa.MaxId;
this->Size = sa.Size;
this->Extend = sa.Extend;
this->Array = new short[this->Size];
for (i=0; i<this->MaxId; i++)
this->Array[i] = sa.Array[i];
}
vlShortArray& vlShortArray::operator=(vlShortArray& sa)
{
int i;
if ( this != &sa )
{
delete [] this->Array;
this->MaxId = sa.MaxId;
this->Size = sa.Size;
this->Extend = sa.Extend;
this->Array = new short[this->Size];
for (i=0; i<=this->MaxId; i++)
this->Array[i] = sa.Array[i];
}
return *this;
}
//
// Copy on write if used by more than one object
//
void vlShortArray::operator+=(vlShortArray& sa)
{
int i, sz;
if ( this->Size <= (sz = this->MaxId + sa.MaxId + 2) ) this->Resize(sz);
for (i=0; i<=sa.MaxId; i++)
{
this->Array[this->MaxId+1+i] = sa.Array[i];
}
this->MaxId += sa.MaxId + 1;
return *this;
}
void vlShortArray::PrintSelf(ostream& os, vlIndent indent)
{
if (this->ShouldIPrint(vlShortArray::GetClassName()))
{
vlObject::PrintSelf(os,indent);
os << indent << "Array: " << this->Array << "\n";
os << indent << "Size: " << this->Size << "\n";
os << indent << "MaxId: " << this->MaxId << "\n";
os << indent << "Extend size: " << this->Extend << "\n";
}
}
//
// Private function does "reallocate"
//
short *vlShortArray::Resize(const int sz)
{
int i;
short *newArray;
int newSize;
if ( sz >= this->Size ) newSize = this->Size +
this->Extend*(((sz-this->Size)/this->Extend)+1);
else newSize = sz;
if ( (newArray = new short[newSize]) == 0 )
{
cerr << "Cannot allocate memory\n";
return 0;
}
for (i=0; i<sz && i<this->Size; i++)
newArray[i] = this->Array[i];
this->Size = newSize;
delete [] this->Array;
this->Array = newArray;
return this->Array;
}
/*=========================================================================
Program: Visualization Library
Module: SScalars.cc
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the Visualization Library. No part of this file
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
//
// Scalar values, floating representation
//
#include "SScalars.hh"
vlScalars *vlShortScalars::MakeObject(int sze, int ext)
{
return new vlShortScalars(sze,ext);
}
vlShortScalars& vlShortScalars::operator=(const vlShortScalars& ss)
{
this->S = ss.S;
return *this;
}
Supports Markdown
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