File: Preprocess3dImpl.mesa
Last edited by Bier on August 10, 1984 1:41:58 am PDT
Copyright © 1984 by Xerox Corporation. All rights reserved.
Contents: File CSGImpl.mesa overflowed storage so I will put the preprocessing phases of ray casting in this interface. Preprocessing may include calculation transforms and their inverses, bounding boxes, unit rays in each instance coordinate system, and so forth.
DIRECTORY
ColorMap,
ColorPackagePrivate,
CSG,
DisplayMap,
Preprocess3d,
Real,
Rope,
SV3d,
SVArtwork,
SVBoundBox,
SVBoundSphere,
SVModelTypes,
SVRayTypes,
SVSceneTypes;
Preprocess3dImpl: PROGRAM
IMPORTS ColorMap, ColorPackagePrivate, CSG, DisplayMap, SVArtwork, SVBoundBox, SVBoundSphere
EXPORTS Preprocess3d =
BEGIN
BoundBox: TYPE = SVModelTypes.BoundBox;
BoundSphere: TYPE = SVModelTypes.BoundSphere;
Camera: TYPE = SVModelTypes.Camera;
Composite: TYPE = SVRayTypes.Composite;
CoordSystem: TYPE = SVModelTypes.CoordSystem;
CSGTree: TYPE = SVRayTypes.CSGTree;
LightSourceList: TYPE = SVModelTypes.LightSourceList;
MasterObject: TYPE = SVSceneTypes.MasterObject;
PointSetOp: TYPE = SVRayTypes.PointSetOp;
Primitive: TYPE = SVRayTypes.Primitive;
SurfaceArray: TYPE = SVRayTypes.SurfaceArray;
Surface: TYPE = REF ANY;
Vector: TYPE = SV3d.Vector;
PreprocessForImage: PUBLIC PROC [tree: CSGTree, camera: Camera] RETURNS [bb: BoundBox, bs: BoundSphere] = {
Before doing anything with a CSG tree, do this. Computes bounding spheres and bounding boxes as needed. Opens AIS files for use with texture mapping.
IF tree.son = NIL THEN RETURN[ NIL, NIL ];
OpenArtworksInNode[tree.son];
bb ← FindBoundingBoxesInNode[tree.son, camera];
bs ← FindBoundingSpheresInNode[tree.son, camera];
};
PreprocessForSlice: PUBLIC PROC [tree: CSGTree, camera: Camera] RETURNS [bs: BoundSphere] = {
Computes bounding spheres, but not bounding boxes. Opens no AIS files.
IF tree.son = NIL THEN RETURN[ NIL ];
bs ← FindBoundingSpheresInNode[tree.son, camera];
};
PreprocessForInteraction: PUBLIC PROC [tree: CSGTree, camera: Camera] RETURNS [bb: BoundBox] = {
Computes bounding boxes, but no bounding spheres. Opens no AIS files.
IF tree.son = NIL THEN RETURN[ NIL ];
bb ← FindBoundingBoxesInNode[tree.son, camera];
};
OpenArtworksInNode: PRIVATE PROC [node: REF ANY] = {
Tree walk through to the leaves and find the position of each primitive.
WITH node SELECT FROM
comp: Composite => {
OpenArtworksInNode[comp.leftSolid];
OpenArtworksInNode[comp.rightSolid];
};
prim: Primitive => {
SVArtwork.OpenArtwork[prim.artwork];
RETURN;
};
ENDCASE => ERROR;
}; -- end of OpenArtworksInNode
FindBoundingBoxesInNode: PRIVATE PROC [node: REF ANY, camera: Camera] RETURNS [BoundBox] = {
Tree walk find the bound box of each primitive and composite.
primWRTWorld and worldWRTPrim should be available. ie FindTransformsInNode must be done first.
WITH node SELECT FROM
comp: Composite => {-- bounding box is the combination of the bounding boxes of the children.
comp.boundBox ← CSG.CombineBoundBoxes[
FindBoundingBoxesInNode[comp.leftSolid, camera],
FindBoundingBoxesInNode[comp.rightSolid, camera],
comp.operation];
RETURN[comp.boundBox];
};
prim: Primitive => {-- bounding box is found from the bounding poly hedron
mo: MasterObject;
prim.boundBox ← SVBoundBox.BoundBoxFromBoundHedron[prim.boundHedron, camera, prim.primWRTAssembly];
mo ← NARROW[prim.mo];
mo.class.preprocess[prim, camera]; -- compute the sub-boxes
RETURN[prim.boundBox];
};
ENDCASE => ERROR;
}; -- end of FindBoundingBoxesInNode
FindBoundingSpheresInNode: PRIVATE PROC [node: REF ANY, camera: Camera] RETURNS [BoundSphere] = {
Tree walk find the bound sphere of each primitive and composite.
primWRTWorld and worldWRTPrim should be available. ie FindTransformsInNode must be done first.
worldCS: CoordSystem ← camera.coordSys.parent;
WITH node SELECT FROM
comp: Composite => {
The bounding sphere is the combination of the bounding spheres of the children.
comp.boundSphere ← CSG.CombineBoundSpheres[
FindBoundingSpheresInNode[comp.leftSolid, camera],
FindBoundingSpheresInNode[comp.rightSolid, camera],
comp.operation];
RETURN[comp.boundSphere];
};
prim: Primitive => {-- bounding sphere is found from the bounding poly hedron
mo: MasterObject;
prim.boundSphere ← SVBoundSphere.BoundSphereFromBoundHedron[prim.boundHedron, worldCS, prim.primWRTAssembly];
mo ← NARROW[prim.mo];
mo.class.preprocess[prim, camera]; -- compute the sub-spheres
RETURN[prim.boundSphere];
};
ENDCASE => ERROR;
}; -- end of FindBoundingSpheresInNode
FindRayStepXInPrimitives: PUBLIC PROC [node: REF ANY] = {
Do this before casting any rays so that we only have to do it once.
finds
WITH node SELECT FROM
comp: Composite => { -- keep walking we only care about primitives
FindRayStepXInPrimitives[comp.leftSolid];
FindRayStepXInPrimitives[comp.rightSolid];
};
prim: Primitive => {-- here
};
ENDCASE => ERROR;
}; -- end of FindRayStepXInPrimitives
globalTable: DisplayMap.ColorTable;
globalPalette: DisplayMap.PalTable;
GetGlobalTable: PUBLIC PROC RETURNS [DisplayMap.ColorTable] = {
RETURN[globalTable];
};
SetUpColorMap: PUBLIC PROC [tableName: Rope.ROPE] = {
[globalTable, globalPalette] ← DisplayMap.Restore[tableName]; -- get the standard color map from this file
ColorPackagePrivate.SetNewColorMapProc[PaletteMapper];
FOR palix: CARDINAL IN[0..globalPalette.size) DO
ColorMap.SetRGBColor[palix,
globalPalette[palix].r, globalPalette[palix].g, globalPalette[palix].b];
ENDLOOP;
};
PaletteMapper: ColorPackagePrivate.ColorMapProc = TRUSTED {
RETURN[DisplayMap.GetIndex[r,g,b, globalTable]];
};
Init: PROC = {
};
Init[];
END.