Commit 721caded authored by Will Schroeder's avatar Will Schroeder
Browse files

ENH: Support clipping

parent ad07e3de
......@@ -102,8 +102,9 @@ inline unsigned char *vtkBitArray::GetPtr(const int id)
// data values requested.
inline unsigned char *vtkBitArray::WritePtr(const int id, const int number)
{
if ( (id + number) > this->Size ) this->Resize(id+number);
this->MaxId = id + number - 1;
int newSize=id+number;
if ( newSize > this->Size ) this->Resize(newSize);
if ( (--newSize) > this->MaxId ) this->MaxId = newSize;
return this->Array + id/8;
}
......
......@@ -69,6 +69,7 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
class vtkCellArray;
class vtkPointLocator;
class vtkPointData;
class vtkCell : public vtkObject
{
......@@ -156,12 +157,17 @@ public:
float x[3], float *weights) = 0;
// Description:
// Generate contouring primitives. The point locator is essentially a points list
// that merges points as they are inserted (i.e., prevents duplicates).
// Generate contouring primitives. The scalar list cellScalars are
// scalar values at each cell point. The point locator is essentially a
// points list that merges points as they are inserted (i.e., prevents
// duplicates). Contouring primitives can be vertices, lines, or
// polygons. It is possible to interpolate point data along the edge
// by providing input and output point data - if outPd is NULL, then
// no interpolation is performed.
virtual void Contour(float value, vtkFloatScalars *cellScalars,
vtkPointLocator *locator, vtkCellArray *verts,
vtkCellArray *lines, vtkCellArray *polys,
vtkFloatScalars *scalars) = 0;
vtkPointData *inPd, vtkPointData *outPd) = 0;
// Description:
// Intersect with a ray. Return parametric coordinates (both line and cell)
......@@ -177,7 +183,7 @@ public:
// cell dimension) defining a simplex. The index is a parameter that controls
// which triangulation to use (if more than one is possible). If numerical
// degeneracy encountered, 0 is returned, otherwise 1 is returned.
virtual int Triangulate(int index, vtkFloatPoints &pts) = 0;
virtual int Triangulate(int index, vtkIdList &ptIds, vtkFloatPoints &pts) = 0;
// Description:
// Compute derivatives given cell subId and parametric coordinates. The values
......
......@@ -121,10 +121,11 @@ inline int vtkCellArray::GetNumberOfCells() {return this->NumberOfCells;};
// Create a cell by specifying the number of points and an array of point id's.
inline int vtkCellArray::InsertNextCell(int npts, int* pts)
{
int id = this->Ia.GetMaxId() + npts + 1;
this->Ia.InsertValue(id,pts[npts-1]);
this->Ia[id-npts] = npts;
for (int i=0; i<npts-1; i++) this->Ia[id-npts+i+1] = pts[i];
int i = this->Ia.GetMaxId() + 1;
int *ptr = this->Ia.WritePtr(i,npts+1);
for ( *ptr++ = npts, i = 0; i < npts; i++) *ptr++ = *pts++;
this->NumberOfCells++;
this->Location += npts + 1;
......@@ -136,10 +137,11 @@ inline int vtkCellArray::InsertNextCell(int npts, int* pts)
inline int vtkCellArray::InsertNextCell(vtkIdList &pts)
{
int npts = pts.GetNumberOfIds();
int id = this->Ia.GetMaxId() + npts + 1;
this->Ia.InsertValue(id,pts.GetId(npts-1));
this->Ia[id-npts] = npts;
for (int i=0; i<npts-1; i++) this->Ia[id-npts+i+1] = pts.GetId(i);
int i = this->Ia.GetMaxId() + 1;
int *ptr = this->Ia.WritePtr(i,npts+1);
for ( *ptr++ = npts, i = 0; i < npts; i++) *ptr++ = pts.GetId(i);
this->NumberOfCells++;
this->Location += npts + 1;
......@@ -179,10 +181,11 @@ inline void vtkCellArray::UpdateCellCount(int npts)
inline int vtkCellArray::InsertNextCell(vtkCell *cell)
{
int npts = cell->GetNumberOfPoints();
int id = this->Ia.GetMaxId() + npts + 1;
this->Ia.InsertValue(id,cell->PointIds.GetId(npts-1));
this->Ia[id-npts] = npts;
for (int i=0; i<npts-1; i++) this->Ia[id-npts+i+1] = cell->PointIds.GetId(i);
int i = this->Ia.GetMaxId() + 1;
int *ptr = this->Ia.WritePtr(i,npts+1);
for ( *ptr++ = npts, i = 0; i < npts; i++) *ptr++ = cell->PointIds.GetId(i);
this->NumberOfCells++;
this->Location += npts + 1;
......
......@@ -102,8 +102,9 @@ inline double *vtkDoubleArray::GetPtr(const int id) {return this->Array + id;};
// data values requested.
inline double *vtkDoubleArray::WritePtr(const int id, const int number)
{
if ( (id + number) > this->Size ) this->Resize(id+number);
this->MaxId = id + number - 1;
int newSize=id+number;
if ( newSize > this->Size ) this->Resize(newSize);
if ( (--newSize) > this->MaxId ) this->MaxId = newSize;
return this->Array + id;
}
......
......@@ -102,8 +102,9 @@ inline float *vtkFloatArray::GetPtr(const int id) {return this->Array + id;};
// data values requested.
inline float *vtkFloatArray::WritePtr(const int id, const int number)
{
if ( (id + number) > this->Size ) this->Resize(id+number);
this->MaxId = id + number - 1;
int newSize=id+number;
if ( newSize > this->Size ) this->Resize(newSize);
if ( (--newSize) > this->MaxId ) this->MaxId = newSize;
return this->Array + id;
}
......
......@@ -107,26 +107,32 @@ inline void vtkFloatNormals::WrotePtr() {}
inline void vtkFloatNormals::SetNormal(int i, float n[3])
{
i*=3;
this->N[i]=n[0];
this->N[i+1]=n[1];
this->N[i+2]=n[2];
float *ptr = this->N.WritePtr(i*3,3);
*ptr++ = n[0];
*ptr++ = n[1];
*ptr = n[2];
}
inline void vtkFloatNormals::InsertNormal(int i, float n[3])
{
this->N.InsertValue(3*i+2, n[2]);
this->N[3*i] = n[0];
this->N[3*i+1] = n[1];
float *ptr = this->N.WritePtr(i*3,3);
*ptr++ = n[0];
*ptr++ = n[1];
*ptr = n[2];
}
inline int vtkFloatNormals::InsertNextNormal(float n[3])
{
int id = this->N.GetMaxId() + 3;
this->N.InsertValue(id,n[2]);
this->N[id-2] = n[0];
this->N[id-1] = n[1];
return id/3;
int id = this->N.GetMaxId() + 1;
float *ptr = this->N.WritePtr(id,3);
*ptr++ = n[0];
*ptr++ = n[1];
*ptr = n[2];
return (id+2)/3;
}
#endif
......@@ -113,26 +113,32 @@ inline void vtkFloatPoints::GetPoint(int id, float x[3])
inline void vtkFloatPoints::SetPoint(int id, float x[3])
{
id*=3;
this->P[id]=x[0];
this->P[id+1]=x[1];
this->P[id+2]=x[2];
float *ptr = this->P.WritePtr(id*3,3);
*ptr++ = x[0];
*ptr++ = x[1];
*ptr = x[2];
}
inline void vtkFloatPoints::InsertPoint(int id, float x[3])
{
this->P.InsertValue(3*id+2, x[2]); // only do range checking once
this->P[3*id] = x[0];
this->P[3*id+1] = x[1];
float *ptr = this->P.WritePtr(id*3,3);
*ptr++ = x[0];
*ptr++ = x[1];
*ptr = x[2];
}
inline int vtkFloatPoints::InsertNextPoint(float x[3])
{
int id = this->P.GetMaxId() + 3;
this->P.InsertValue(id,x[2]); // only do range checking once
this->P[id-2] = x[0];
this->P[id-1] = x[1];
return id/3;
int id = this->P.GetMaxId() + 1;
float *ptr = this->P.WritePtr(id,3);
*ptr++ = x[0];
*ptr++ = x[1];
*ptr = x[2];
return (id+2)/3;
}
#endif
......@@ -107,26 +107,32 @@ inline void vtkFloatVectors::WrotePtr() {}
inline void vtkFloatVectors::SetVector(int i, float v[3])
{
i*=3;
this->V[i]=v[0];
this->V[i+1]=v[1];
this->V[i+2]=v[2];
float *ptr = this->V.WritePtr(i*3,3);
*ptr++ = v[0];
*ptr++ = v[1];
*ptr = v[2];
}
inline void vtkFloatVectors::InsertVector(int i, float v[3])
{
this->V.InsertValue(3*i+2, v[2]);
this->V[3*i] = v[0];
this->V[3*i+1] = v[1];
float *ptr = this->V.WritePtr(i*3,3);
*ptr++ = v[0];
*ptr++ = v[1];
*ptr = v[2];
}
inline int vtkFloatVectors::InsertNextVector(float v[3])
{
int id = this->V.GetMaxId() + 3;
this->V.InsertValue(id,v[2]);
this->V[id-2] = v[0];
this->V[id-1] = v[1];
return id/3;
int id = this->V.GetMaxId() + 1;
float *ptr = this->V.WritePtr(id,3);
*ptr++ = v[0];
*ptr++ = v[1];
*ptr = v[2];
return (id+2)/3;
}
#endif
......@@ -328,7 +328,8 @@ void vtkHexahedron::Contour(float value, vtkFloatScalars *cellScalars,
vtkPointLocator *locator,
vtkCellArray *vtkNotUsed(verts),
vtkCellArray *vtkNotUsed(lines),
vtkCellArray *polys, vtkFloatScalars *scalars)
vtkCellArray *polys,
vtkPointData *inPd, vtkPointData *outPd)
{
static int CASE_MASK[8] = {1,2,4,8,16,32,64,128};
TRIANGLE_CASES *triCase;
......@@ -359,7 +360,12 @@ void vtkHexahedron::Contour(float value, vtkFloatScalars *cellScalars,
if ( (pts[i] = locator->IsInsertedPoint(x)) < 0 )
{
pts[i] = locator->InsertNextPoint(x);
scalars->InsertScalar(pts[i],value);
if ( outPd )
{
int p1 = this->PointIds.GetId(vert[0]);
int p2 = this->PointIds.GetId(vert[1]);
outPd->InterpolateEdge(inPd,pts[i],p1,p2,t);
}
}
}
polys->InsertNextCell(3,pts);
......@@ -465,66 +471,89 @@ int vtkHexahedron::IntersectWithLine(float p1[3], float p2[3], float tol,
return intersection;
}
int vtkHexahedron::Triangulate(int index, vtkFloatPoints &pts)
int vtkHexahedron::Triangulate(int index, vtkIdList &ptIds, vtkFloatPoints &pts)
{
int p[4], i;
ptIds.Reset();
pts.Reset();
//
// Create five tetrahedron. Triangulation varies depending upon index. This
// is necessary to insure compatible voxel triangulations.
//
if ( index % 2 )
if ( (index % 2) )
{
pts.InsertNextPoint(this->Points.GetPoint(0));
pts.InsertNextPoint(this->Points.GetPoint(1));
pts.InsertNextPoint(this->Points.GetPoint(4));
pts.InsertNextPoint(this->Points.GetPoint(3));
pts.InsertNextPoint(this->Points.GetPoint(1));
pts.InsertNextPoint(this->Points.GetPoint(4));
pts.InsertNextPoint(this->Points.GetPoint(7));
pts.InsertNextPoint(this->Points.GetPoint(5));
pts.InsertNextPoint(this->Points.GetPoint(1));
pts.InsertNextPoint(this->Points.GetPoint(4));
pts.InsertNextPoint(this->Points.GetPoint(3));
pts.InsertNextPoint(this->Points.GetPoint(6));
pts.InsertNextPoint(this->Points.GetPoint(1));
pts.InsertNextPoint(this->Points.GetPoint(3));
pts.InsertNextPoint(this->Points.GetPoint(2));
pts.InsertNextPoint(this->Points.GetPoint(6));
pts.InsertNextPoint(this->Points.GetPoint(3));
pts.InsertNextPoint(this->Points.GetPoint(6));
pts.InsertNextPoint(this->Points.GetPoint(4));
pts.InsertNextPoint(this->Points.GetPoint(7));
p[0] = 0; p[1] = 1; p[2] = 4; p[3] = 3;
for ( i=0; i < 4; i++ )
{
ptIds.InsertNextId(this->PointIds.GetId(p[i]));
pts.InsertNextPoint(this->Points.GetPoint(p[i]));
}
p[0] = 1; p[1] = 4; p[2] = 7; p[3] = 5;
for ( i=0; i < 4; i++ )
{
ptIds.InsertNextId(this->PointIds.GetId(p[i]));
pts.InsertNextPoint(this->Points.GetPoint(p[i]));
}
p[0] = 1; p[1] = 4; p[2] = 3; p[3] = 6;
for ( i=0; i < 4; i++ )
{
ptIds.InsertNextId(this->PointIds.GetId(p[i]));
pts.InsertNextPoint(this->Points.GetPoint(p[i]));
}
p[0] = 1; p[1] = 3; p[2] = 2; p[3] = 6;
for ( i=0; i < 4; i++ )
{
ptIds.InsertNextId(this->PointIds.GetId(p[i]));
pts.InsertNextPoint(this->Points.GetPoint(p[i]));
}
p[0] = 3; p[1] = 6; p[2] = 4; p[3] = 7;
for ( i=0; i < 4; i++ )
{
ptIds.InsertNextId(this->PointIds.GetId(p[i]));
pts.InsertNextPoint(this->Points.GetPoint(p[i]));
}
}
else
{
pts.InsertNextPoint(this->Points.GetPoint(2));
pts.InsertNextPoint(this->Points.GetPoint(1));
pts.InsertNextPoint(this->Points.GetPoint(0));
pts.InsertNextPoint(this->Points.GetPoint(5));
pts.InsertNextPoint(this->Points.GetPoint(0));
pts.InsertNextPoint(this->Points.GetPoint(2));
pts.InsertNextPoint(this->Points.GetPoint(7));
pts.InsertNextPoint(this->Points.GetPoint(3));
pts.InsertNextPoint(this->Points.GetPoint(2));
pts.InsertNextPoint(this->Points.GetPoint(5));
pts.InsertNextPoint(this->Points.GetPoint(7));
pts.InsertNextPoint(this->Points.GetPoint(6));
pts.InsertNextPoint(this->Points.GetPoint(0));
pts.InsertNextPoint(this->Points.GetPoint(7));
pts.InsertNextPoint(this->Points.GetPoint(5));
pts.InsertNextPoint(this->Points.GetPoint(4));
pts.InsertNextPoint(this->Points.GetPoint(1));
pts.InsertNextPoint(this->Points.GetPoint(2));
pts.InsertNextPoint(this->Points.GetPoint(5));
pts.InsertNextPoint(this->Points.GetPoint(7));
p[0] = 2; p[1] = 1; p[2] = 0; p[3] = 5;
for ( i=0; i < 4; i++ )
{
ptIds.InsertNextId(this->PointIds.GetId(p[i]));
pts.InsertNextPoint(this->Points.GetPoint(p[i]));
}
p[0] = 0; p[1] = 2; p[2] = 7; p[3] = 3;
for ( i=0; i < 4; i++ )
{
ptIds.InsertNextId(this->PointIds.GetId(p[i]));
pts.InsertNextPoint(this->Points.GetPoint(p[i]));
}
p[0] = 2; p[1] = 5; p[2] = 7; p[3] = 6;
for ( i=0; i < 4; i++ )
{
ptIds.InsertNextId(this->PointIds.GetId(p[i]));
pts.InsertNextPoint(this->Points.GetPoint(p[i]));
}
p[0] = 0; p[1] = 7; p[2] = 5; p[3] = 4;
for ( i=0; i < 4; i++ )
{
ptIds.InsertNextId(this->PointIds.GetId(p[i]));
pts.InsertNextPoint(this->Points.GetPoint(p[i]));
}
p[0] = 1; p[1] = 2; p[2] = 5; p[3] = 7;
for ( i=0; i < 4; i++ )
{
ptIds.InsertNextId(this->PointIds.GetId(p[i]));
pts.InsertNextPoint(this->Points.GetPoint(p[i]));
}
}
return 1;
......
......@@ -67,7 +67,8 @@ public:
int CellBoundary(int subId, float pcoords[3], vtkIdList& pts);
void Contour(float value, vtkFloatScalars *cellScalars,
vtkPointLocator *locator, vtkCellArray *verts,
vtkCellArray *lines, vtkCellArray *polys, vtkFloatScalars *s);
vtkCellArray *lines, vtkCellArray *polys,
vtkPointData *inPd, vtkPointData *outPd);
int EvaluatePosition(float x[3], float closestPoint[3],
int& subId, float pcoords[3],
float& dist2, float *weights);
......@@ -75,7 +76,7 @@ public:
float *weights);
int IntersectWithLine(float p1[3], float p2[3], float tol, float& t,
float x[3], float pcoords[3], int& subId);
int Triangulate(int index, vtkFloatPoints &pts);
int Triangulate(int index, vtkIdList &ptIds, vtkFloatPoints &pts);
void Derivatives(int subId, float pcoords[3], float *values,
int dim, float *derivs);
......
......@@ -45,21 +45,27 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
// operations are required: the ability to evaluate the function, and the
// function gradient at a given point.
//
// Implicit functions are very powerful. It is possible to represent almost
// any type of geometry with implicit functions, especially if you use
// boolean combinations implicit functions (see vtkImplicitBoolean).
//
// vtkImplicitFunction provides a mechanism to transform the implicit
// function(s) via a transformation matrix. This capability can be used to
// translate, orient, or scale implicit functions. For example, a sphere
// implicit function can be transformed into an oriented ellipse. This is
// accomplished by using an instance of vtkTransform.
// .SECTION Caveats
// The transformation matrix transforms a point into the space of the implicit
// function (i.e., the model space). Typically we want to transpose the
// function (i.e., the model space). Typically we want to transform the
// implicit model into world coordinates. In this case the inverse of the
// transform is required.
// transformation matrix is required.
// .SECTION See Also
// vtkTransform
// vtkCylinder vtkImplicitBoolean vtkPlane vtkPlanes
// vtkQuadric vtkSphere
// vtkSphere vtkCylinder vtkImplicitBoolean vtkPlane vtkPlanes
// vtkQuadric vtkImplicitVolume
// vtkSampleFunction vtkCutter vtkClipper
#ifndef __vtkImplicitFunction_h
#define __vtkImplicitFunction_h
......
......@@ -102,8 +102,9 @@ inline int *vtkIntArray::GetPtr(const int id) {return this->Array + id;};
// data values requested.
inline int *vtkIntArray::WritePtr(const int id, const int number)
{
if ( (id + number) > this->Size ) this->Resize(id+number);
this->MaxId = id + number - 1;
int newSize=id+number;
if ( newSize > this->Size ) this->Resize(newSize);
if ( (--newSize) > this->MaxId ) this->MaxId = newSize;
return this->Array + id;
}
......
......@@ -116,50 +116,62 @@ inline void vtkIntPoints::GetPoint(int id, float x[3])
inline void vtkIntPoints::SetPoint(int i, float x[3])
{
i*=3;
this->P[i]=(int)x[0];
this->P[i+1]=(int)x[1];
this->P[i+2]=(int)x[2];
int *ptr = this->P.WritePtr(i*3,3);
*ptr++ = (int) x[0];
*ptr++ = (int) x[1];
*ptr = (int) x[2];
}
inline void vtkIntPoints::SetPoint(int i, int x[3])
{
i *= 3;
this->P[i] = x[0];
this->P[i+1] = x[1];
this->P[i+2] = x[2];
int *ptr = this->P.WritePtr(i*3,3);
*ptr++ = x[0];
*ptr++ = x[1];
*ptr = x[2];
}
inline void vtkIntPoints::InsertPoint(int i, int x[3])
{
this->P.InsertValue(3*i+2, x[2]);
this->P[3*i] = x[0];
this->P[3*i+1] = x[1];
int *ptr = this->P.WritePtr(i*3,3);
*ptr++ = x[0];
*ptr++ = x[1];
*ptr = x[2];
}
inline void vtkIntPoints::InsertPoint(int i, float x[3])
{
this->P.InsertValue(3*i+2, (int)x[2]);
this->P[3*i] = (int)x[0];
this->P[3*i+1] = (int)x[1];
int *ptr = this->P.WritePtr(i*3,3);
*ptr++ = (int) x[0];
*ptr++ = (int) x[1];
*ptr = (int) x[2];
}
inline int vtkIntPoints::InsertNextPoint(int x[3])
{
int id = this->P.GetMaxId() + 3;
this->P.InsertValue(id,x[2]);
this->P[id-2] = x[0];
this->P[id-1] = x[1];
return id/3;
int id = this->P.GetMaxId() + 1;
int *ptr = this->P.WritePtr(id,3);
*ptr++ = x[0];
*ptr++ = x[1];
*ptr = x[2];
return (id+2)/3;
}
inline int vtkIntPoints::InsertNextPoint(float x[3])
{
int id = this->P.GetMaxId() + 3;
this->P.InsertValue(id,(int)x[2]);
this->P[id-2] = (int)x[0];
this->P[id-1] = (int)x[1];
return id/3;
int id = this->P.GetMaxId() + 1;
int *ptr = this->P.WritePtr(id,3);
*ptr++ = (int) x[0];
*ptr++ = (int) x[1];
*ptr = (int) x[2];
return (id+2)/3;
}
#endif
......@@ -177,9 +177,9 @@ typedef int VERT_LIST;
typedef struct {
VERT_LIST verts[2];
} LINE_CASES;
} VERT_CASES;