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

*** empty log message ***

parent d800d758
......@@ -16,7 +16,15 @@ Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
//
// Define cell array
// Define cell array. The cell array is a raw integer list representing many
// cells. The form of the list is: (n,id1,id2,...,idn, n,id1,id2,...,idn, ...)
// where n is the number of points in the cell, and id is a zero-offset index
// into an associated point list.
//
// Advantages of this data structure are its compactness, simplicity, and easy
// interface to external data. However, it is totally inadequate for random
// access. This functionality (when necessary) is accomplished by using the
// CellList and LinkList objects to extend the definition of data structure.
//
#ifndef __vlCellArray_h
#define __vlCellArray_h
......@@ -36,36 +44,11 @@ public:
~vlCellArray() {};
char *GetClassName() {return "vlCellArray";};
// return number of cells represented by this list
int GetNumberOfCells() {return this->NumberOfCells;};
// utility routines to help manage memory of cell data structure. EstimateSize()
// returns a value used to initialize cell array based on number of cells and
// maximum number of points making up cell. If every cell is the same size (in
// terms of number of points) then the estimate is guaranteed exact.
// The Squeeze() function recovers memory from estimated size.
int EstimateSize(int numCells, int maxPtsPerCell)
{return numCells*(1+maxPtsPerCell);};
void Squeeze() {this->Ia.Squeeze();};
// efficient method of traversing cell array. Use InitTraveral() and then repeated
// calls to GetNextCell()
void InitTraversal() {this->Location=0;};
int GetNextCell(int& npts, int* &pts)
{
if ( this->Ia.GetMaxId() >= 0 && this->Location <= this->Ia.GetMaxId() )
{
npts = this->Ia.GetValue(this->Location++);
pts = this->Ia.GetPtr(this->Location);
this->Location += npts;
return 1;
}
else
{
return 0;
}
}
// create a cell by specifying the number of pts and an array of point id's
// Methods to create cells from different inputs.
// Create a cell by specifying the number of pts and an array of point id's
void InsertNextCell(int npts, int* pts)
{
int id = this->Ia.GetMaxId() + npts + 1;
......@@ -76,7 +59,7 @@ public:
this->Location += npts + 1;
}
// create cells by specifying count, and then adding points one at a time using
// Create cells by specifying count, and then adding points one at a time using
// method InsertCellPoint()
void InsertNextCell(int npts)
{
......@@ -86,7 +69,7 @@ public:
void InsertCellPoint(int id)
{this->Ia.InsertValue(this->Location++,id);};
// create a cell from a cell object
// Create a cell from a cell object
void InsertNextCell(vlCell *cell)
{
int npts = cell->GetNumberOfPoints();
......@@ -98,12 +81,57 @@ public:
this->Location += npts + 1;
}
// utility routines to help manage memory of cell data structure. EstimateSize()
// returns a value used to initialize cell array based on number of cells and
// maximum number of points making up cell. If every cell is the same size (in
// terms of number of points) then the estimate is guaranteed exact.
// The Squeeze() function recovers memory from estimated size.
int EstimateSize(int numCells, int maxPtsPerCell)
{return numCells*(1+maxPtsPerCell);};
void Squeeze() {this->Ia.Squeeze();};
// These are cell traversal methods. More efficient than DataSet traversal
// methods. Both traversal methods can be used together, if necessary.
// Cell traversal methods are initialized with InitTraveral() and then
// followed by repeated calls to GetNextCell()
void InitTraversal() {this->Location=0;};
int GetNextCell(int& npts, int* &pts)
{
if ( this->Ia.GetMaxId() >= 0 && this->Location <= this->Ia.GetMaxId() )
{
npts = this->Ia.GetValue(this->Location++);
pts = this->Ia.GetPtr(this->Location);
this->Location += npts;
return 1;
}
else
{
return 0;
}
}
// access methods for building data structures
int GetSize() {return Ia.GetSize();};
void GetCell(int loc, int &npts, int* &pts)
{npts=this->Ia.GetValue(loc++); pts=this->Ia.GetPtr(loc);};
// Use only in conjunction with cell traversal methods
int GetLocation(int npts) {return (this->Location - npts - 1);};
// Special method flips ordering of current cell. Works in conjunction with
// cell traversal methods.
void ReverseOrder(int npts)
{
int i, tmp, loc=this->Location - npts;
int *pts=this->Ia.GetPtr(loc);
for (i=0; i < (npts/2); i++)
{
tmp = pts[i];
pts[i] = pts[npts-i-1];
pts[npts-i-1] = tmp;
}
}
protected:
int NumberOfCells;
int Location;
......
......@@ -14,7 +14,10 @@ Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
//
// Define cell array
// Supplemental object to CellArray to allow random access into cells.
// The "location" field is the location in the CellArray list in terms of an
// integer offset. An integer offset was used instead of a pointer for easy
// storage and inter-process communication.
//
#ifndef __vlCellList_h
#define __vlCellList_h
......@@ -22,8 +25,8 @@ Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
#include "Object.hh"
struct vlCell_s {
unsigned char type;
int loc;
unsigned char type; //from CellTypes.hh
int loc; //location in associated CellArray object
};
class vlCellList : public vlObject {
......@@ -36,7 +39,7 @@ public:
unsigned char GetCellType(const int id) {return this->Array[id].type;};
int GetCellLocation(const int id) {return this->Array[id].loc;};
void InsertCell(const int id, const unsigned char type, const int loc);
int InsertNextCell(const unsigned char type, const int pos);
int InsertNextCell(const unsigned char type, const int loc);
void Squeeze();
void Reset();
......
......@@ -39,6 +39,8 @@ public:
vlCell *GetCell(int cellId) {return this->DataSet->GetCell(cellId);}
int GetCellType(int cellId) {return this->DataSet->GetCellType(cellId);}
void Initialize();
void GetCellPoints(int cellId, vlIdList *ptIds)
{this->DataSet->GetCellPoints(cellId, ptIds);};
void GetPointCells(int ptId, vlIdList *cellIds)
{this->DataSet->GetPointCells(ptId, cellIds);};
int FindCell(float x[3], vlCell *cell, float tol2)
......
......@@ -55,6 +55,7 @@ public:
virtual int GetCellType(int cellId) = 0;
// topological inquiries to get neighbors and cells that use a point
virtual void GetCellPoints(int cellId, vlIdList *ptIds) = 0;
virtual void GetPointCells(int ptId, vlIdList *cellIds) = 0;
virtual void GetCellNeighbors(int cellId, vlIdList *ptIds,
vlIdList *cellIds);
......
......@@ -14,7 +14,11 @@ Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
//
// Define link array
// Supplemental object to CellArray and CellList to allow access from points
// to cells using the points. LinkList is a collection of Links, each link
// representing a dynamic list of cell id's using the point. The information
// provided by this object can be used to determine neighbors and construct
// other local topological information.
//
#ifndef __vlLinkList_h
#define __vlLinkList_h
......
......@@ -42,6 +42,7 @@ public:
int GetCellType(int cellId);
vlMapper *MakeMapper();
void Initialize();
void GetCellPoints(int cellId, vlIdList *ptIds);
void GetPointCells(int ptId, vlIdList *cellIds);
// Can't use macros to set/get following cell arrays. This is due to tricks
......
......@@ -45,6 +45,7 @@ public:
int GetNumberOfCells();
int GetNumberOfPoints();
void Initialize();
void GetCellPoints(int cellId, vlIdList *ptIds);
void GetPointCells(int ptId, vlIdList *cellIds);
void SetDimensions(int i, int j, int k);
......
......@@ -49,6 +49,7 @@ public:
void Initialize();
int GetNumberOfCells();
vlCell *GetCell(int cellId);
void GetCellPoints(int cellId, vlIdList *ptIds);
void GetPointCells(int ptId, vlIdList *cellIds);
int GetCellType(int cellId);
......
......@@ -440,6 +440,53 @@ void vlPolyData::BuildLinks()
this->Links->BuildLinks(this);
}
void vlPolyData::GetCellPoints(int cellId, vlIdList *ptIds)
{
int i, loc, numPts, *pts;
unsigned char type;
if ( this->Cells == NULL ) this->BuildCells();
type = this->Cells->GetCellType(cellId);
loc = this->Cells->GetCellLocation(cellId);
switch (type)
{
case vlPOINT:
this->Verts->GetCell(loc,numPts,pts);
break;
case vlPOLY_POINTS:
this->Verts->GetCell(loc,numPts,pts);
break;
case vlLINE:
this->Lines->GetCell(loc,numPts,pts);
break;
case vlPOLY_LINE:
this->Lines->GetCell(loc,numPts,pts);
break;
case vlTRIANGLE:
this->Polys->GetCell(loc,numPts,pts);
break;
case vlQUAD:
this->Polys->GetCell(loc,numPts,pts);
break;
case vlPOLYGON:
this->Polys->GetCell(loc,numPts,pts);
break;
case vlTRIANGLE_STRIP:
this->Strips->GetCell(loc,numPts,pts);
break;
}
for (i=0; i<numPts; i++) ptIds->SetId(i,pts[i]);
}
void vlPolyData::GetPointCells(int ptId, vlIdList *cellIds)
{
int *cells;
......@@ -479,6 +526,9 @@ void vlPolyData::InsertNextCell(int type, int npts, int pts[MAX_CELL_SIZE])
case vlTRIANGLE_STRIP:
this->Strips->InsertNextCell(npts,pts);
break;
default:
vlErrorMacro(<<"Bad cell type! Can't insert!");
}
}
......@@ -176,6 +176,86 @@ void vlStructuredDataSet::Initialize()
}
}
void vlStructuredDataSet::GetCellPoints(int cellId, vlIdList *ptIds)
{
int i, j, k, idx, loc[3], npts;
int iMin, iMax, jMin, jMax, kMin, kMax;
int d01 = this->Dimensions[0]*this->Dimensions[1];
ptIds->Reset();
switch (this->DataDescription)
{
case SINGLE_POINT: // cellId can only be = 0
iMin = iMax = jMin = jMax = kMin = kMax = 0;
break;
case X_LINE:
jMin = jMax = kMin = kMax = 0;
iMin = cellId;
iMax = cellId + 1;
break;
case Y_LINE:
iMin = iMax = kMin = kMax = 0;
jMin = cellId;
jMax = cellId + 1;
break;
case Z_LINE:
iMin = iMax = jMin = jMax = 0;
kMin = cellId;
kMax = cellId + 1;
break;
case XY_PLANE:
kMin = kMax = 0;
iMin = cellId % (this->Dimensions[0]-1);
iMax = iMin + 1;
jMin = cellId / (this->Dimensions[0]-1);
jMax = jMin + 1;
break;
case YZ_PLANE:
iMin = iMax = 0;
jMin = cellId % (this->Dimensions[1]-1);
jMax = jMin + 1;
kMin = cellId / (this->Dimensions[1]-1);
kMax = kMin + 1;
break;
case XZ_PLANE:
jMin = jMax = 0;
iMin = cellId % (this->Dimensions[0]-1);
iMax = iMin + 1;
kMin = cellId / (this->Dimensions[0]-1);
kMax = kMin + 1;
break;
case XYZ_GRID:
iMin = cellId % (this->Dimensions[0] - 1);
iMax = iMin + 1;
jMin = (cellId / (this->Dimensions[0] - 1)) % (this->Dimensions[1] - 1);
jMax = jMin + 1;
kMin = cellId / ((this->Dimensions[0] - 1) * (this->Dimensions[1] - 1));
kMax = kMin + 1;
break;
}
// Extract point ids
for (npts=0,loc[2]=kMin; loc[2]<=kMax; loc[2]++)
{
for (loc[1]=jMin; loc[1]<=jMax; loc[1]++)
{
for (loc[0]=iMin; loc[0]<=iMax; loc[0]++)
{
idx = loc[0] + loc[1]*this->Dimensions[0] + loc[2]*d01;
ptIds->InsertId(npts++,idx);
}
}
}
}
void vlStructuredDataSet::GetPointCells(int ptId, vlIdList *cellIds)
{
int ptDim[3], cellDim[3];
......
......@@ -238,6 +238,16 @@ void vlUnstructuredGrid::BuildLinks()
this->Links->BuildLinks(this);
}
void vlUnstructuredGrid::GetCellPoints(int cellId, vlIdList *ptIds)
{
int i, loc, numPts, *pts;
loc = this->Cells->GetCellLocation(cellId);
this->Connectivity->GetCell(loc,numPts,pts);
for (i=0; i<numPts; i++) ptIds->SetId(i,pts[i]);
}
void vlUnstructuredGrid::GetPointCells(int ptId, vlIdList *cellIds)
{
int *cells;
......
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