Commit bbadfae8 authored by Will Schroeder's avatar Will Schroeder
Browse files

Initial revision

parent 8654bd94
/*=========================================================================
Program: Visualization Library
Module: Cone.hh
Language: C++
Date: $Date$
Version: $Revision$
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
=========================================================================*/
// .NAME vlCone - implicit function for a cone
// .SECTION Description
// vlCone computes the implicit function and surface normal for a cone.
// vlCone is a concrete implementation of vlImplicitFunction.
#ifndef __vlCone_h
#define __vlCone_h
#include "ImpFunc.hh"
class vlCone : public vlImplicitFunction
{
public:
vlCone();
char *GetClassName() {return "vlCone";};
void PrintSelf(ostream& os, vlIndent indent);
// ImplicitFunction interface
float Evaluate(float x, float y, float z);
void EvaluateNormal(float x, float y, float z, float n[3]);
vlSetVector3Macro(Apex,float);
vlGetVectorMacro(Apex,float,3);
vlSetVector3Macro(Base,float);
vlGetVectorMacro(Base,float,3);
vlSetMacro(BaseRadius,float);
vlGetMacro(BaseRadius,float);
protected:
float Apex[3];
float Base[3];
float BaseRadius;
};
#endif
/*=========================================================================
Program: Visualization Library
Module: Cylinder.hh
Language: C++
Date: $Date$
Version: $Revision$
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
=========================================================================*/
// .NAME vlCylinder - implicit function for a cylinder
// .SECTION Description
// vlCylinder computes the implicit function and surface normal for a cylinder.
// vlCylinder is a concrete implementation of vlImplicitFunction.
#ifndef __vlCylinder_h
#define __vlCylinder_h
#include "ImpFunc.hh"
class vlCylinder : public vlImplicitFunction
{
public:
vlCylinder();
char *GetClassName() {return "vlCylinder";};
void PrintSelf(ostream& os, vlIndent indent);
// ImplicitFunction interface
float Evaluate(float x, float y, float z);
void EvaluateNormal(float x, float y, float z, float n[3]);
vlSetMacro(Radius,float);
vlGetMacro(Radius,float);
vlSetVector3Macro(Top,float);
vlGetVectorMacro(Top,float,3);
vlSetVector3Macro(Bottom,float);
vlGetVectorMacro(Bottom,float,3);
protected:
float Radius;
float Top[3];
float Bottom[3];
};
#endif
/*=========================================================================
Program: Visualization Library
Module: DArray.hh
Language: C++
Date: $Date$
Version: $Revision$
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
=========================================================================*/
// .NAME vlDoubleArray - dynamic, self adjusting double precision array
// .SECTION Description
// vlDoubleArray is an array of double precision numbers. It provides methods
// for insertion and retrieval of double precision values, and will
// automatically resize itself to hold new data.
#ifndef __vlDoubleArray_h
#define __vlDoubleArray_h
#include "Object.hh"
class vlDoubleArray : public vlObject
{
public:
vlDoubleArray():Array(NULL),Size(0),MaxId(-1),Extend(1000) {};
int Allocate(const int sz, const int ext=1000);
void Initialize();
vlDoubleArray(const int sz, const int ext=1000);
vlDoubleArray(const vlDoubleArray& fa);
~vlDoubleArray();
virtual char *GetClassName() {return "vlDoubleArray";};
void PrintSelf(ostream& os, vlIndent indent);
// access/insertion methods
double GetValue(const int id);
vlDoubleArray &InsertValue(const int id, const double f);
int InsertNextValue(const double f);
double *GetPtr(const int id);
double *WritePtr(const int id, const int number);
// special operators
vlDoubleArray &operator=(const vlDoubleArray& fa);
void operator+=(const vlDoubleArray& fa);
void operator+=(const double f);
double& operator[](const int i);
// miscellaneous methods
void Squeeze();
int GetSize();
int GetMaxId();
void Reset();
private:
double *Array; // pointer to data
int Size; // allocated size of data
int MaxId; // maximum index inserted thus far
int Extend; // grow array by this point
double *Resize(const int sz); // function to resize data
};
// Description:
// Get the data at a particular index.
inline double vlDoubleArray::GetValue(const int id) {return this->Array[id];};
// Description:
// Get the address of a particular data index.
inline double *vlDoubleArray::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 double *vlDoubleArray::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 vlDoubleArray& vlDoubleArray::InsertValue(const int id, const double f)
{
if ( id >= this->Size ) this->Resize(id);
this->Array[id] = f;
if ( id > this->MaxId ) this->MaxId = id;
return *this;
}
// Description:
// Insert data at the end of the array. Return its location in the array.
inline int vlDoubleArray::InsertNextValue(const double f)
{
this->InsertValue (++this->MaxId,f);
return this->MaxId;
}
inline void vlDoubleArray::operator+=(const double f)
{
this->InsertNextValue(f);
}
// Description:
// Does insert or get (depending on location on lhs or rhs of statement). Does
// not do automatic resizing - user's responsibility to range check.
inline double& vlDoubleArray::operator[](const int i)
{
if (i > this->MaxId) this->MaxId = i;
return this->Array[i];
}
// Description:
// Resize object to just fit data requirement. Reclaims extra memory.
inline void vlDoubleArray::Squeeze() {this->Resize (this->MaxId+1);};
// Description:
// Get the allocated size of the object in terms of number of data items.
inline int vlDoubleArray::GetSize() {return this->Size;};
// Description:
// Returning the maximum index of data inserted so far.
inline int vlDoubleArray::GetMaxId() {return this->MaxId;};
// Description:
// Reuse the memory allocated by this object. Objects appears like
// no data has been previously inserted.
inline void vlDoubleArray::Reset() {this->MaxId = -1;};
#endif
/*=========================================================================
Program: Visualization Library
Module: ImpBool.hh
Language: C++
Date: $Date$
Version: $Revision$
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
=========================================================================*/
// .NAME vlImplicitBoolean - implicit function consisting of boolean combinations of implicit functions
// .SECTION Description
// vlImplicitBoolean is an implicit function consisting of boolean combinations
// of implicit functions. The class has a list of functions (FunctionList) that
// are combined according to a specified operator (UNION or INTERSECTION or
// DIFFERENCE). You can use nested combinations of vlImplicitFunctions
// (and/or vlImplicitBoolean) to create elaborate implicit functions.
// vlImplicitBoolean is a concrete implementation of vlImplicitFunction.
// The operators work as follows. The UNION operator takes the minimum value
// of all implicit functions. The INTERSECTION operator takes the maximum value
// of all implicit functions. The DIFFERENCE operator substracts the 2cnd
// through last implicit functions from the first.
#ifndef __vlImplicitBoolean_h
#define __vlImplicitBoolean_h
#include "ImpFunc.hh"
#include "ImpFuncC.hh"
#define UNION 0
#define INTERSECTION 1
#define DIFFERENCE 2
class vlImplicitBoolean : public vlImplicitFunction
{
public:
vlImplicitBoolean();
~vlImplicitBoolean();
char *GetClassName() {return "vlImplicitBoolean";};
void PrintSelf(ostream& os, vlIndent indent);
// ImplicitFunction interface
float Evaluate(float x, float y, float z);
void EvaluateNormal(float x, float y, float z, float n[3]);
// Override modified time retrieval because of object dependencies.
unsigned long int GetMTime();
void AddFunction(vlImplicitFunction *in);
void AddFunction(vlImplicitFunction &in) {this->AddFunction(&in);};
void RemoveFunction(vlImplicitFunction *in);
void RemoveFunction(vlImplicitFunction &in) {this->RemoveFunction(&in);};
vlImplicitFunctionCollection *GetFunction() {return &(this->FunctionList);};
// Description:
// Specify the type of boolean operation.
vlSetClampMacro(OperationType,int,UNION,DIFFERENCE);
vlGetMacro(OperationType,int);
protected:
vlImplicitFunctionCollection FunctionList;
int OperationType;
};
#endif
/*=========================================================================
Program: Visualization Library
Module: Cone.cc
Language: C++
Date: $Date$
Version: $Revision$
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
=========================================================================*/
#include "Cone.hh"
// Description
// Construct cone with apex at (0,0,1), base at (0,0,0) and base radius=0.5.
vlCone::vlCone()
{
this->Apex[0] = 0.0;
this->Apex[1] = 0.0;
this->Apex[2] = 0.0;
this->Base[0] = 0.0;
this->Base[1] = 0.0;
this->Base[2] = 0.0;
this->BaseRadius = 0.5;
}
// Description
// Evaluate cone equation.
float vlCone::Evaluate(float x, float y, float z)
{
return 0;
}
// Description
// Evaluate cone normal.
void vlCone::EvaluateNormal(float x, float y, float z, float n[3])
{
}
void vlCone::PrintSelf(ostream& os, vlIndent indent)
{
vlImplicitFunction::PrintSelf(os,indent);
os << indent << "Apex: (" << this->Apex[0] << ", "
<< this->Apex[1] << ", " << this->Apex[2] << ")\n";
os << indent << "Base: (" << this->Base[0] << ", "
<< this->Base[1] << ", " << this->Base[2] << ")\n";
os << indent << "BaseRadius: " << this->BaseRadius << "\n";
}
/*=========================================================================
Program: Visualization Library
Module: Cylinder.cc
Language: C++
Date: $Date$
Version: $Revision$
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
=========================================================================*/
#include "Cylinder.hh"
// Description
// Construct cylinder with top at (0,0,1), bottom at (0,0,0) and radius=0.5.
vlCylinder::vlCylinder()
{
this->Radius = 0.5;
this->Top[0] = 0.0;
this->Top[1] = 0.0;
this->Top[2] = 1.0;
this->Bottom[0] = 0.0;
this->Bottom[1] = 0.0;
this->Bottom[2] = 1.0;
}
// Description
// Evaluate cylinder equation R^2 - ((x-x0)^2 + (y-y0)^2 + (z-z0)^2) = 0.
float vlCylinder::Evaluate(float x, float y, float z)
{
return 0;
}
// Description
// Evaluate cylinder normal.
void vlCylinder::EvaluateNormal(float x, float y, float z, float n[3])
{
}
void vlCylinder::PrintSelf(ostream& os, vlIndent indent)
{
vlImplicitFunction::PrintSelf(os,indent);
os << indent << "Radius: " << this->Radius << "\n";
os << indent << "Top: (" << this->Top[0] << ", "
<< this->Top[1] << ", " << this->Top[2] << ")\n";
os << indent << "Bottom: (" << this->Bottom[0] << ", "
<< this->Bottom[1] << ", " << this->Bottom[2] << ")\n";
}
/*=========================================================================
Program: Visualization Library
Module: DArray.cc
Language: C++
Date: $Date$
Version: $Revision$
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
=========================================================================*/
#include "DArray.hh"
// Description:
// Allocate memory for this array. Delete old storage if present.
int vlDoubleArray::Allocate(const int sz, const int ext)
{
if ( this->Array ) delete [] this->Array;
this->Size = ( sz > 0 ? sz : 1);
if ( (this->Array = new double[sz]) == NULL ) return 0;
this->Extend = ( ext > 0 ? ext : 1);
this->MaxId = -1;
return 1;
}
// Description:
// Release storage and reset array to initial state.
void vlDoubleArray::Initialize()
{
if ( this->Array != NULL )
{
delete [] this->Array;
this->Array = NULL;
}
this->Size = 0;
this->MaxId = -1;
}
// Description:
// Construct with specified storage and extend value.
vlDoubleArray::vlDoubleArray(const int sz, const int ext)
{
this->Size = ( sz > 0 ? sz : 1);
this->Array = new double[sz];
this->Extend = ( ext > 0 ? ext : 1);
this->MaxId = -1;
}
vlDoubleArray::~vlDoubleArray()
{
delete [] this->Array;
}
// Description:
// Construct array from another array. Copy each element of other array.
vlDoubleArray::vlDoubleArray(const vlDoubleArray& fa)
{
int i;
this->MaxId = fa.MaxId;
this->Size = fa.Size;
this->Extend = fa.Extend;
this->Array = new double[this->Size];
for (i=0; i<this->MaxId; i++)
this->Array[i] = fa.Array[i];
}
// Description:
// Deep copy of another array.
vlDoubleArray& vlDoubleArray::operator=(const vlDoubleArray& fa)
{
int i;
if ( this != &fa )
{
delete [] this->Array;
this->MaxId = fa.MaxId;
this->Size = fa.Size;
this->Extend = fa.Extend;
this->Array = new double[this->Size];
for (i=0; i<=this->MaxId; i++)
this->Array[i] = fa.Array[i];
}
return *this;
}
// Description:
// Append one array onto the end of this array.
void vlDoubleArray::operator+=(const vlDoubleArray& fa)
{
int i, sz;
if ( this->Size <= (sz = this->MaxId + fa.MaxId + 2) ) this->Resize(sz);
for (i=0; i<=fa.MaxId; i++)
{
this->Array[this->MaxId+1+i] = fa.Array[i];
}
this->MaxId += fa.MaxId + 1;
}
void vlDoubleArray::PrintSelf(ostream& os, vlIndent indent)
{
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";
}
// Protected function does "reallocate"
//
double *vlDoubleArray::Resize(const int sz)
{
double *newArray;
int newSize;
if (sz >= this->Size) newSize = this->Size +
this->Extend*(((sz-this->Size)/this->Extend)+1);
else newSize = sz;
if ( (newArray = new double[newSize]) == NULL )
{
vlErrorMacro(<< "Cannot allocate memory\n");
return 0;
}
memcpy(newArray, this->Array,
(sz < this->Size ? sz : this->Size) * sizeof(double));
this->Size = newSize;
delete [] this->Array;
this->Array = newArray;
return this->Array;
}
/*=========================================================================
Program: Visualization Library
Module: ImpBool.cc
Language: C++
Date: $Date$
Version: $Revision$
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
=========================================================================*/
#include "ImpBool.hh"
// Description:
//
vlImplicitBoolean::vlImplicitBoolean()
{
this->OperationType = UNION;
}
vlImplicitBoolean::~vlImplicitBoolean()
{
}
unsigned long int vlImplicitBoolean::GetMTime()
{
unsigned long int fMtime;
unsigned long int mtime = this->vlImplicitFunction::GetMTime();
vlImplicitFunction *f;
for (this->FunctionList.InitTraversal(); f=this->FunctionList.GetNextItem(); )
{
fMtime = f->GetMTime();
if ( fMtime > mtime ) mtime = fMtime;
}
return mtime;
}
// Description:
// Add another implicit function to the list of functions.
void vlImplicitBoolean::AddFunction(vlImplicitFunction *f)
{
if ( ! this->FunctionList.IsItemPresent(f) )