RCombiner.mesa
Last Edited by: Arnon, November 26, 1985 10:49:05 am PST
DIRECTORY
RVHandleUtils USING [Point, VertexHandle],
ClientStateInfo USING [State, StateCombiner],
IO,
Imager;
RCombiner: CEDAR DEFINITIONS = BEGIN OPEN RVHU: RVHandleUtils, CSI: ClientStateInfo;
Variables and Types
in, out: IO.STREAM; -- global variables for log writing
OutsideCurrentTrilean: TYPE = {INTERSECTSOUTLINE, EXTERNAL, ENCLOSES};
InsideCurrentTrilean: TYPE = {INTERSECTSOUTLINE, INSINGLEPOLYGON, INMULTIPLEPOLYGONS};
9/19/85 - we will declare the INMULTIPLEPOLYGONS case for a polygon which is contained in the closure of a single internal polygon, but which intersects its boundary?
LensTransitionType: TYPE = {EXTERIORTOINTERIOR, INTERIORTOEXTERIOR, INTERIORTOINTERIOR };
Main procedures
Combiner: PROC[ currentw, inputw: RVHU.VertexHandle, inputState: CSI.State, stateCombiner: CSI.StateCombiner ] RETURNS [combinedw: RVHU.VertexHandle];
currentw is a vertex on the (convex) outline of the current figure. inputw is a vertex on the input polygon. combinedw is a vertex on the (convex) outline of the combined figure.
CombineGeometry: PROC[ currentw, inputw: RVHU.VertexHandle, setIntersectionPolygonEdges: BOOLTRUE] RETURNS [combinedw, intersectionPolygonv, intersectionPolygonw: RVHU.VertexHandle];
currentw is a vertex on the (convex) outline of the current figure. inputw is a vertex on the input polygon. combinedw is a vertex on the (convex) outline of the combined figure. [intersectionPolygonv, intersectionPolygonw] is a (directed) edge in the new (i.e. combined) geometry which is contained in the intersection polygon (of current figure and input polygon), and such that the interior of the intersection polygon lies to its left. If the intersection polygon is empty, then both intersectionPolygonv and intersectionPolygonw are set to NIL.
If setIntersectionPolygonEdges, then CombineGeometry sets the intersectionPolygonEdge fields of all (directed) edges in the new (i.e. combined) geometry which are contained in the intersection polygon (of current figure and input polygon), and such that the interior of the intersection polygon lies to their left. Although this functionality is provided as an essential preprocessing step for CombineState, note that it is a purely geometrical operation. It can be undone with ClearIntersectionPolygonEdges.
CombineState: PROC[ intersectionPolygonv, intersectionPolygonw: RVHU.VertexHandle, inputState: CSI.State, stateCombiner: CSI.StateCombiner];
Combiner case analysis
[intersectionPolygonv, intersectionPolygonw] is a counterclockwise oriented (directed) edge in the current (i.e. combined) geometry which is contained in the intersection polygon (of current figure and input polygon), and such that the interior of the intersection polygon lies to its left. inputState is the state of the input polygon. stateCombiner is the rule for state combination.
The leftState fields of the edges of all polygons interior to the intersection polygon are set to the result of state combining inputState with the states those polygons had in the current figure. The algorithm uses Depth First Search.
CombineState assumes that the intersectionPolygonEdge fields of all (directed) edges in the new (i.e. combined) geometry which are contained in the intersection polygon (of current figure and input polygon), and such that the interior of the intersection polygon lies to their left, are set. It doesn't clear them.
InputvOutsideCurrentOutline: PROC[ currentfigurecom: RVHU.Point, v1, w1, v2, w2: RVHU.VertexHandle ] RETURNS [outsideCurrentStatus: OutsideCurrentTrilean, v3, w3, v4, w4: RVHU.VertexHandle];
InputvInsideCurrentOutline: PROC[ currentfigurecom: RVHU.Point, v1, w1, v2, w2: RVHU.VertexHandle ] RETURNS [intsideCurrentStatus: InsideCurrentTrilean, v3, w3, v4, w4: RVHU.VertexHandle ];
InputIntersectsCurrent: PROC[ lensTransitionType: LensTransitionType, currentv, currentw, inputv, inputw: RVHU.VertexHandle, setIntersectionPolygonEdges: BOOLTRUE ] RETURNS [voutline, woutline: RVHU.VertexHandle ← NIL, intersectionPolygonv, intersectionPolygonw: RVHU.VertexHandle];
[intersectionPolygonv, intersectionPolygonw] is a (directed) edge in the current (i.e. combined) geometry which is contained in the intersection polygon (of current figure and input polygon), and such that the interior of the intersection polygon lies to its left. The intersection polygon is followed around and the intersectionPolygonEdge fields of its edges cleared.
InputExternalToCurrent: PROC[ currentv, currentw, inputv, inputw: RVHU.VertexHandle, currentoutlinecom, inputfigurecom: RVHU.Point] RETURNS [combinedv, combinedw: RVHU.VertexHandle];
PolygonEnclosesPolygon : PROC[ innercom: RVHU.Point, innerv, innerw, outerv, outerw: RVHU.VertexHandle];
Convex decomposers
LensDecomposition: PROC[ firstv, v, pj, qi: RVHU.VertexHandle, lensInExterior: BOOL, setIntersectionPolygonEdges: BOOLTRUE] RETURNS [ returnedToFirstv: BOOL, vending, pj1ending, pjending, qi1ending, qiending: RVHU.VertexHandle];
GrowToConvexOutline: PROC[w2, v, w1: RVHU.VertexHandle, outline: BOOLFALSE] RETURNS [v3,w3: RVHU.VertexHandle];
Vertex and adjacency insertion
InsertIntersectionPoint: PROC[pj1, pj, qi, qip1: RVHU.VertexHandle] RETURNS [vh: RVHU.VertexHandle];
JoinVerticesOnOutline: PROC[ prew2, w2, w1, forw1: RVHU.VertexHandle, setLRE: BOOLTRUE];
JoinVerticesInLens: PROC[ pj1, pj, qi1, qi: RVHU.VertexHandle];
Boolean field modification
SetFigureVisitedValues: PROC[v: RVHU.VertexHandle, visitedValue: BOOLEAN];
ClearIntersectPolygonFields: PROC [v, w: RVHU.VertexHandle];
END.