ImplicitSurface.mesa
Copyright Ó 1985, 1990 by Xerox Corporation. All rights reserved.
Bloomenthal, February 26, 1993 3:16 pm PST
DIRECTORY G3dBasic, G3dMatrix, G3dOctree, G3dShape, ImplicitDefs;
ImplicitSurface: CEDAR DEFINITIONS
~ BEGIN
Triple:   TYPE ~ G3dBasic.Triple;
Matrix:   TYPE ~ G3dMatrix.Matrix;
Viewport:   TYPE ~ G3dMatrix.Viewport;
Corner:   TYPE ~ G3dOctree.Corner;
Cube:    TYPE ~ G3dOctree.Cube;
Direction:   TYPE ~ G3dOctree.Direction;
Octree:   TYPE ~ G3dOctree.Octree;
OctreeMode:  TYPE ~ G3dOctree.OctreeMode;
Shape:    TYPE ~ G3dShape.Shape;
ColorProc:   TYPE ~ ImplicitDefs.ColorProc;
EdgeMode:  TYPE ~ ImplicitDefs.EdgeMode;
Surface:   TYPE ~ ImplicitDefs.Surface;
NormalProc:  TYPE ~ ImplicitDefs.NormalProc;
PolygonOkProc: TYPE ~ ImplicitDefs.PolygonOkProc;
StatusProc:  TYPE ~ ImplicitDefs.StatusProc;
SurfaceProc:  TYPE ~ ImplicitDefs.SurfaceProc;
Target:   TYPE ~ ImplicitDefs.Target;
TextureProc:  TYPE ~ ImplicitDefs.TextureProc;
ValueProc:  TYPE ~ ImplicitDefs.ValueProc;
VertexOkProc: TYPE ~ ImplicitDefs.VertexOkProc;
NoSurfacePoint: ERROR;
Note
A point is considered inside a surface if its value is greater than 0.
Surface Creation
MakeSurface: PROC [
surface: Surface,
octreeMode: OctreeMode,
valueProc: ValueProc,
threshold: REAL ← 1.0,
triangulate: BOOL ¬ FALSE,
vertexOkProc: VertexOkProc ← NIL,
polygonOkProc: PolygonOkProc ← NIL,
normalProc: NormalProc ← NIL,
colorProc: ColorProc ← NIL,
textureProc: TextureProc ← NIL,
statusProc: StatusProc ← NIL,
tolerance: REAL ← 0.0001,
edgeMode: EdgeMode ← binarySectioning,
clientData: REF ANYNIL];
Polygonize the surface by performing the following steps:
create surface.octree according to octreeMode
adaptively subdivide the octree
create the surface according to the steps given in SurfaceFromOctree, below.
statusProc is called with each cube as it is processed during each step.
MakePolygons: PROC [
surface: Surface,
valueProc: ValueProc,
threshold: REAL ← 1.0,
triangulate: BOOL ¬ FALSE,
vertexOkProc: VertexOkProc ← NIL,
polygonOkProc: PolygonOkProc ← NIL,
normalProc: NormalProc ← NIL,
colorProc: ColorProc ← NIL,
textureProc: TextureProc ← NIL,
statusProc: StatusProc ← NIL,
tolerance: REAL ← 0.0001,
edgeMode: EdgeMode ← binarySectioning,
clientData: REF ANYNIL]
RETURNS [nEvaluations: INT];
Return the polygonized surface given surface.octree according to the following steps:
compute the surface vertices and their normals (even if normalProc is NIL)
polygonize the vertices
compute the polygon face normals
compute the vertex textures (only if textureProc is non-NIL).
tolerance controls the convergence along the cube edges.
statusProc is called with an ATOM after each of the above steps.
statusProc is called with each cube as it is processed during each step.
nEvaluations is just for the setting of all corners and does not include edge converge.
Octree Creation
MakeOctree: PROC [
octreeMode: OctreeMode,
valueProc: ValueProc,
threshold: REAL ← 1.0,
normalProc: NormalProc ← NIL,
statusProc: StatusProc ← NIL,
clientData: REF ANYNIL]
RETURNS [Octree];
Return the octree given the octree mode and implicit function evaluators.
If octreeMode.type = track and statusProc is called with a Cube and it returns $RejectCube,
the Cube will be eliminated from the octree, effectively truncating the implicit function.
If statusProc returns $Abort, the octree is immediately returned in its partial state.
TrackOctree: PROC [
cubeSize: REAL,
surfacePoint: Triple,
valueProc: ValueProc,
threshold: REAL ← 1.0,
statusProc: StatusProc ← NIL,
clientData: REF ANYNIL]
RETURNS [Octree];
Return the ``aggregated'' octree given the size of a seed cube and a point on the surface.
If stausProc is non-nil, it is called after every top-level octant has been processed; if it
returns $Abort, ConvergeToSurface will terminate processing and completed will be FALSE.
If it returns $RejectCube, then the current cube will not appear in the final octree.
ConvergeOctree: PROC [
rootSize: REAL,
recurseMin: NAT ← 1,
recurseMax: NAT ← 5,
valueProc: ValueProc,
threshold: REAL ← 1.0,
surfaceProc: SurfaceProc ← NIL,
statusProc: StatusProc ← NIL,
clientData: REF ANYNIL]
RETURNS [octree: Octree];
Create the ``decomposed'' octree, subdividing those cubes that contain the surface.
The root cube is subdivided a minimum of recurseMin and a maximum of recurseMax;
usually recurseMin is 1 but for some surfaces (such as a torus) it must be greater.
If surfaceProc is NIL, a default surface proc is used.
If stausProc is non-nil, it is called after every top-level octant has been processed; if it
returns $Abort, ConvergeToSurface will terminate processing and completed will be FALSE.
The terminal field of a surface-containing cube is set true if the cube level is recurseMax.
Surface Computation
PointOnSurface: PROC [
surfaceHull: Cube,
valueProc: ValueProc,
threshold: REAL ← 1.0,
recurseLimit: NAT,
clientData: REF ANYNIL]
RETURNS [point: Triple];
Return a point on the surface; may raise ERROR NoSurfacePoint.
SurfacePoint: PROC [
in, out: Triple,
valueProc: ValueProc,
threshold: REAL ← 1.0,
clientData: REF ANYNIL]
RETURNS [Triple];
Return a point on the surface; may raise ERROR NoSurfacePoint.
FindStart: PUBLIC PROC [
ballpark: Triple,
valueProc: ValueProc,
size, level: REAL,
clientData: REF ANY ¬ NIL]
RETURNS [Triple];
Attempt to find a starting point. ! NoSurfacePoint.
SegmentConverge: PROC [
pIn, pOut: Triple,
vIn, vOut: REAL,
valueProc: ValueProc,
threshold: REAL ← 1.0,
clientData: REF ANYNIL,
direction: Direction ← none,
tolerance: REAL ← 0.0001,
edgeMode: EdgeMode ← binarySectioning,
nTriesLimit: NAT ← 15]
RETURNS [Target];
Given points pIn (inside the surface) and pOut (outside the surface) and their respective
octree, converge on the surface lying between them. If the points are along a grid (i.e.,
they share a coordinate), providing direction d will speed the convergence.
Conversions
ShapeFromSurface: PROC [surface: Surface] RETURNS [Shape];
Create a Shape from the surface.
SetSurfaceCurves: PROC [surface: Surface];
Set surface.curves to be splines connecting surface vertices.
Attributes
NPolygons: PROC [surface: Surface] RETURNS [CARDINAL];
Return the number of polygons in surface.
NEdges: PROC [surface: Surface] RETURNS [CARDINAL];
Return the number of edges in surface.
NVertices: PROC [surface: Surface] RETURNS [CARDINAL];
Return the number of vertices in surface.
EulerNumber: PROC [surface: Surface] RETURNS [CARDINAL];
Return NPolygons-NEdges+NVertices.
Miscellany
SurfaceOK: PROC [surface: Surface] RETURNS [BOOL];
True if surface has vertices and polygons defined.
VerticesOK: PROC [surface: Surface, view: Matrix, viewport: Viewport] RETURNS [BOOL];
True if surface ok; sets vertex screen coordinates.
VertexNormalsOK: PROC [surface: Surface] RETURNS [BOOL];
True if surface ok; sets vertex normals if invalid.
FaceNormalsCentersOK: PROC [surface: Surface] RETURNS [BOOL];
True if surface ok; sets face normals if invalid.
SetNearest: PROC [corner: Corner, nearest: Triple, squareDistance: REAL ← 0.0];
Set the nearest field of corner to nearest, set nearestSet TRUE.
CornerWithMaxValue: PROC [cube: Cube] RETURNS [Corner];
Return the corner of the cube with the maximum value.
END.