File: SVPreprocess3dImpl.mesa
Last edited by Bier on September 24, 1987 1:28:03 pm 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
CodeTimer, SVCoordSys, SVPreprocess3d, Real, Rope, SV3d, SVArtwork, SVAssembly, SVBasicTypes, SVBoundBox, SVBoundSphere, SVModelTypes, SVRay, SVSceneTypes;
SVPreprocess3dImpl: CEDAR PROGRAM
IMPORTS CodeTimer, SVCoordSys, SVArtwork, SVAssembly, SVBoundBox, SVBoundSphere, SVRay
EXPORTS SVPreprocess3d =
BEGIN
BoundBox: TYPE = SVBasicTypes.BoundBox;
Camera: TYPE = SVModelTypes.Camera;
Composite: TYPE = SVSceneTypes.Composite;
CoordSystem: TYPE = SVModelTypes.CoordSystem;
CSGTree: TYPE = SVSceneTypes.CSGTree;
LightSourceList: TYPE = SVModelTypes.LightSourceList;
MasterObject: TYPE = SVSceneTypes.MasterObject;
PointSetOp: TYPE = SVSceneTypes.PointSetOp;
Primitive: TYPE = SVSceneTypes.Primitive;
Slice: TYPE = SVSceneTypes.Slice;
Sphere: TYPE = SV3d.Sphere;
SurfaceArray: TYPE = SVSceneTypes.SurfaceArray;
Surface: TYPE = REF ANY;
Vector3d: TYPE = SV3d.Vector3d;
PreprocessForImage: PUBLIC PROC [tree: CSGTree, camera: Camera] RETURNS [bb: BoundBox, bs: Sphere] = {
Before doing anything with a SVRay 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];
};
PreprocessForCatScan: PUBLIC PROC [tree: CSGTree, camera: Camera] RETURNS [bs: Sphere] = {
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.
CodeTimer.StartInt[$PreprocessForInteraction, $Solidviews];
IF tree.son = NIL THEN RETURN[ NIL ];
bb ← FindBoundingBoxesInNode[tree.son, camera];
CodeTimer.StopInt[$PreprocessForInteraction, $Solidviews];
};
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
computeBoxes: BOOLFALSE;
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 ← SVRay.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;
IF computeBoxes THEN prim.boundBox ← SVBoundBox.BoundBoxFromBoundHedron[prim.boundHedron, camera, prim.localCS]
ELSE {
slice: Slice ← NARROW[prim.assembly];
prim.boundBox ← SVAssembly.GetBoundBox[assem: slice, parts: NIL, camera: camera];
};
mo ← NARROW[prim.mo];
mo.class.preprocess[prim, camera]; -- e.g. compute the sub-boxes of a sweep shape
RETURN[prim.boundBox];
};
ENDCASE => ERROR;
}; -- end of FindBoundingBoxesInNode
FindBoundingSpheresInNode: PRIVATE PROC [node: REF ANY, camera: Camera] RETURNS [Sphere] = {
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 ← SVCoordSys.Parent[camera.coordSys];
WITH node SELECT FROM
comp: Composite => {
The bounding sphere is the combination of the bounding spheres of the children.
comp.boundSphere ← SVRay.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.localCS];
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 = {
RETURN[DisplayMap.GetIndex[r,g,b, globalTable]];
};
Init: PROC = {
};
InitStats: PROC = {
interval: CodeTimer.Interval;
interval ← CodeTimer.CreateInterval[$PreprocessForInteraction];
CodeTimer.AddInt[interval, $Solidviews];
};
Init[];
InitStats[];
END.