DIRECTORY CodeTimer, SVCoordSys, Preprocess3d, Real, Rope, SV3d, SVArtwork, SVAssembly, SVBasicTypes, SVBoundBox, SVBoundSphere, SVModelTypes, SVRay, SVSceneTypes; Preprocess3dImpl: CEDAR PROGRAM IMPORTS CodeTimer, SVCoordSys, SVArtwork, SVAssembly, SVBoundBox, SVBoundSphere, SVRay EXPORTS Preprocess3d = BEGIN BoundBox: TYPE = SVBasicTypes.BoundBox; BoundSphere: TYPE = SVBasicTypes.BoundSphere; 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; SurfaceArray: TYPE = SVSceneTypes.SurfaceArray; Surface: TYPE = REF ANY; Vector3d: TYPE = SV3d.Vector3d; PreprocessForImage: PUBLIC PROC [tree: CSGTree, camera: Camera] RETURNS [bb: BoundBox, bs: BoundSphere] = { 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: BoundSphere] = { IF tree.son = NIL THEN RETURN[ NIL ]; bs _ FindBoundingSpheresInNode[tree.son, camera]; }; PreprocessForInteraction: PUBLIC PROC [tree: CSGTree, camera: Camera] RETURNS [bb: BoundBox] = { 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] = { 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: BOOL _ FALSE; FindBoundingBoxesInNode: PRIVATE PROC [node: REF ANY, camera: Camera] RETURNS [BoundBox] = { 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 [BoundSphere] = { worldCS: CoordSystem _ SVCoordSys.Parent[camera.coordSys]; WITH node SELECT FROM comp: Composite => { 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] = { 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 Init: PROC = { }; InitStats: PROC = { interval: CodeTimer.Interval; interval _ CodeTimer.CreateInterval[$PreprocessForInteraction]; CodeTimer.AddInt[interval, $Solidviews]; }; Init[]; InitStats[]; END. pFile: Preprocess3dImpl.mesa Last edited by Bier on August 6, 1987 11:54:02 pm PDT Copyright c 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. 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. Computes bounding spheres, but not bounding boxes. Opens no AIS files. Computes bounding boxes, but no bounding spheres. Opens no AIS files. Tree walk through to the leaves and find the position of each primitive. Tree walk find the bound box of each primitive and composite. primWRTWorld and worldWRTPrim should be available. ie FindTransformsInNode must be done first. Tree walk find the bound sphere of each primitive and composite. primWRTWorld and worldWRTPrim should be available. ie FindTransformsInNode must be done first. The bounding sphere is the combination of the bounding spheres of the children. Do this before casting any rays so that we only have to do it once. finds 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]]; }; ΚF– "cedar" style˜Ihead1šœ™Iprocšœ5™5Jšœ Οmœ1™