DIRECTORY CoordSys, Imager, IO, Matrix3d, SVObjectCast, PredefSweeps, Real, Rope, SV2d, SV3d, SVAssembly, SVBasicTypes, SVBoundBox, SVDraw3d, SVFaces, SVLines3d, SVMasterObject, SVMasterObjectTypes, SVModelTypes, SVScene, SVSceneTypes, SVVector3d, SweepCast, SweepGeometry, TFI3d; SVMasterObjectImplA: CEDAR PROGRAM IMPORTS CoordSys, IO, Matrix3d, SVObjectCast, PredefSweeps, Rope, SVBoundBox, SVDraw3d, SVMasterObject, SVScene, SweepGeometry, TFI3d EXPORTS SVMasterObject = BEGIN OPEN SVMasterObject; Slice: TYPE = SVSceneTypes.Slice; BoundBox: TYPE = SVBasicTypes.BoundBox; BoundHedron: TYPE = SVBasicTypes.BoundHedron; Camera: TYPE = SVModelTypes.Camera; Classification: TYPE = SVSceneTypes.Classification; Composite: TYPE = SVSceneTypes.Composite; Cone: TYPE = SVFaces.Cone; ConeSurface: TYPE = REF ConeSurfaceObj; ConeSurfaceObj: TYPE = SVObjectCast.ConeSurfaceObj; CoordSystem: TYPE = SVModelTypes.CoordSystem; Cylinder: TYPE = SVFaces.Cylinder; DiskRing: TYPE = SVFaces.DiskRing; DiskSurface: TYPE = REF DiskSurfaceObj; DiskSurfaceObj: TYPE = SVObjectCast.DiskSurfaceObj; Edge3d: TYPE = SV3d.Edge3d; LightSourceList: TYPE = SVModelTypes.LightSourceList; LinearMesh: TYPE = REF LinearMeshRecord; LinearMeshArray: TYPE = SweepGeometry.LinearMeshArray; LinearMeshRecord: TYPE = SweepGeometry.LinearMeshRecord; Line3d: TYPE = SV3d.Line3d; MasterObject: TYPE = SVSceneTypes.MasterObject; MasterObjectClass: TYPE = SVSceneTypes.MasterObjectClass; MasterObjectClassList: TYPE = SVSceneTypes.MasterObjectClassList; MasterObjectClassObj: TYPE = SVSceneTypes.MasterObjectClassObj; MasterObjectList: TYPE = SVSceneTypes.MasterObjectList; Matrix4by4: TYPE = SV3d.Matrix4by4; Path: TYPE = SV2d.Path; PlanarSurface: TYPE = SVSceneTypes.PlanarSurface; PlanarSurfaceList: TYPE = SVSceneTypes.PlanarSurfaceList; Point2d: TYPE = SV2d.Point2d; Point3d: TYPE = SV3d.Point3d; PointAndDone: TYPE = SVSceneTypes.PointAndDone; PointGenerator: TYPE = REF PointGeneratorObj; PointGeneratorObj: TYPE = SVSceneTypes.PointGeneratorObj; Poly3d: TYPE = SV3d.Poly3d; Polygon: TYPE = SV2d.Polygon; Primitive: TYPE = SVSceneTypes.Primitive; Ray: TYPE = SVSceneTypes.Ray; RectSurface: TYPE = REF RectSurfaceObj; RectSurfaceObj: TYPE = SVObjectCast.RectSurfaceObj; RevoFace: TYPE = SweepCast.RevoFace; RevoluteMesh: TYPE = REF RevoluteMeshRecord; RevoluteMeshArray: TYPE = SweepGeometry.RevoluteMeshArray; RevoluteMeshRecord: TYPE = SweepGeometry.RevoluteMeshRecord; SelectMode: TYPE = SVSceneTypes.SelectMode; Shape: TYPE = SVSceneTypes.Shape; ShellSurface: TYPE = REF ShellSurfaceObj; ShellSurfaceObj: TYPE = SVObjectCast.ShellSurfaceObj; SliceDescriptor: TYPE = SVSceneTypes.SliceDescriptor; SliceParts: TYPE = SVSceneTypes.SliceParts; SubBoxesBody: TYPE = REF SubBoxesBodyObj; SubBoxesBodyObj: TYPE = SweepCast.SubBoxesBodyObj; SubSpheresBody: TYPE = REF SubSpheresBodyObj; SubSpheresBodyObj: TYPE = SweepCast.SubSpheresBodyObj; SurfaceArray: TYPE = REF SurfaceArrayObj; SurfaceArrayObj: TYPE = SVSceneTypes.SurfaceArrayObj; ToroidalMesh: TYPE = REF ToroidalMeshRecord; ToroidalMeshRecord: TYPE = SweepGeometry.ToroidalMeshRecord; ToroidalSurface: TYPE = REF ToroidalSurfaceObj; ToroidalSurfaceObj: TYPE = SVObjectCast.ToroidalSurfaceObj; TubeSurface: TYPE = REF TubeSurfaceObj; TubeSurfaceObj: TYPE = SVObjectCast.TubeSurfaceObj; GetHedronProc: TYPE = SVSceneTypes.GetHedronProc; LineDrawProc: TYPE = SVSceneTypes.LineDrawProc; NormalsDrawProc: TYPE = SVSceneTypes.NormalsDrawProc; PreprocessProc: TYPE = SVSceneTypes.PreprocessProc; RayCastProc: TYPE = SVSceneTypes.RayCastProc; RayCastNoBBoxesProc: TYPE = SVSceneTypes.RayCastNoBBoxesProc; RayCastBoundingSpheresProc: TYPE = SVSceneTypes.RayCastBoundingSpheresProc; DrawPlanarSurfaceProc: TYPE = SVSceneTypes.DrawPlanarSurfaceProc; DrawSubBoxesProc: TYPE = SVSceneTypes.DrawSubBoxesProc; DrawSubSpheresProc: TYPE = SVSceneTypes.DrawSubSpheresProc; FileinProc: TYPE = SVSceneTypes.FileinProc; FileoutProc: TYPE = SVSceneTypes.FileoutProc; FileoutPolyProc: TYPE = SVSceneTypes.FileoutPolyProc; CountSurfProc: TYPE = SVSceneTypes.CountSurfProc; GetSurfProc: TYPE = SVSceneTypes.GetSurfProc; PointsInDescriptorProc: TYPE = SVSceneTypes.PointsInDescriptorProc; NextPointProc: TYPE = SVSceneTypes.NextPointProc; UpdateProc: TYPE = SVSceneTypes.UpdateProc; sphereClass, cylinderClass, coneClass, torusClass: MasterObjectClass; globalClassList: MasterObjectClassList _ NIL; globalMOList: MasterObjectList _ NIL; WrongTypeOfData: PUBLIC SIGNAL = CODE; SphereRec: TYPE = REF SphereRecObj; SphereRecObj: TYPE = SVMasterObjectTypes.SphereRecObj; SphereBody: PROC RETURNS [sphereRec: SphereRec] = { sphereRec _ NEW[SphereRecObj]; sphereRec.radius _ 1; }; SphereMakeMasterObject: PUBLIC PROC [name: Rope.ROPE] RETURNS [mo: MasterObject] = { mainBody: SphereRec _ SphereBody[]; lineBody: REF ANY _ PredefSweeps.GetUnitSphere[]; shadeBody: REF ANY _ lineBody; rayCastBody: REF ANY _ SphereGetRayCastBody[]; mo _ SVScene.CreateMasterObject[name, sphereClass, mainBody, lineBody, shadeBody, rayCastBody]; }; SphereUpdate: PUBLIC PROC [mo: MasterObject, updateData: REF ANY] = { mo.lineBody _ PredefSweeps.GetUnitSphere[]; mo.shadeBody _ mo.lineBody; mo.rayCastBody _ SphereGetRayCastBody[]; }; SphereBoundHedron: PUBLIC PROC [mo: MasterObject] RETURNS [hedron: BoundHedron] = { hedron _ SVBoundBox.HexagonalBoundHedron[1, 1]; }; SphereGetRayCastBody: PROC [] RETURNS [shellS: ShellSurface] = { shellS _ NEW[ShellSurfaceObj]; }; SphereRayCast: PUBLIC PROC [cameraPoint: Point2d, localRay: Ray, sliceD: SliceDescriptor, prim: Primitive] RETURNS [class: Classification] = { mo: MasterObject _ prim.mo; RETURN[SVObjectCast.SphereCast[localRay, NARROW[mo.rayCastBody], prim]]; }; SphereRayCastNoBBoxes: PUBLIC PROC [localRay: Ray, sliceD: SliceDescriptor, prim: Primitive] RETURNS [class: Classification] = { mo: MasterObject _ prim.mo; RETURN[SVObjectCast.SphereCast[localRay, NARROW[mo.rayCastBody], prim]]; }; SphereRayCastBoundingSpheres: PUBLIC PROC [localRay: Ray, sliceD: SliceDescriptor, prim: Primitive] RETURNS [class: Classification] = { mo: MasterObject _ prim.mo; RETURN[SVObjectCast.SphereCast[localRay, NARROW[mo.rayCastBody], prim]]; }; SphereLineDraw: PUBLIC PROC[slice: Slice, dc: Imager.Context, camera: Camera] = { localCS: CoordSystem _ slice.coordSys; mo: MasterObject _ NARROW[slice.shape, Shape].mo; revMesh: RevoluteMesh; revMesh _ NARROW[mo.lineBody]; SweepGeometry.LineDrawRevoluteSweep[dc, revMesh, camera, localCS]; }; SphereDrawNormals: PUBLIC PROC[dc: Imager.Context, data: REF ANY, camera: Camera, localCS: CoordSystem] = { CirclePath: Imager.PathProc = { moveTo[[-1.0, 0.0]]; arcTo[[1.0, 0.0], [-1.0, 0.0]]; }; revMesh: RevoluteMesh; linesOfLatitude, linesOfLongitude: NAT; deltaTheta: REAL; transform, csCamera: Matrix4by4; IF ISTYPE[data, RevoluteMesh] THEN revMesh _ NARROW[data] ELSE SIGNAL WrongTypeOfData; linesOfLatitude _ revMesh.linesOfLatitude; linesOfLongitude _ revMesh.linesOfLongitude; transform _ csCamera _ CoordSys.WRTCamera[localCS, camera.coordSys]; SVDraw3d.DrawTransformedShape[dc: dc, csCAMERA: transform, camera: camera, path: CirclePath]; deltaTheta _ 360.0/linesOfLongitude; FOR i: NAT IN [1..linesOfLongitude-1] DO transform _ Matrix3d.LocalRotateY[transform, deltaTheta]; SVDraw3d.DrawTransformedShape[dc: dc, csCAMERA: transform, camera: camera, path: CirclePath]; ENDLOOP; transform _ csCamera; transform _ Matrix3d.LocalRotateX[transform, 90]; SVDraw3d.DrawTransformedShape[dc: dc, csCAMERA: transform, camera: camera, path: CirclePath]; }; SphereCountSurf: PUBLIC PROC [masterObject: MasterObject] RETURNS [len: NAT] = { revMesh: RevoluteMesh _ NARROW[masterObject.shadeBody]; len _ SweepGeometry.CountPlanarSurfacesRevoluteSweep[revMesh]; }; SphereCountVert: PUBLIC PROC [masterObject: MasterObject] RETURNS [len: NAT] = { revMesh: RevoluteMesh _ NARROW[masterObject.shadeBody]; len _ SweepGeometry.CountVerticesRevoluteSweep[revMesh]; }; SphereGetSurf: PUBLIC PROC [slice: Slice, camera: CoordSystem] RETURNS [psl: PlanarSurfaceList] = { shape: Shape _ NARROW[slice.shape]; masterObject: MasterObject _ shape.mo; revMesh: RevoluteMesh _ NARROW[masterObject.shadeBody]; psl _ SweepGeometry.PlanarSurfacesRevoluteSweep[revMesh, slice, camera]; }; SphereDrawSurf: PUBLIC PROC [dc: Imager.Context, ps: PlanarSurface, lightSources: LightSourceList, camera: Camera] = { SweepGeometry.DrawPlanarSurfaceRevoluteSweep[dc, ps, lightSources, camera]; }; SphereFilein: PUBLIC PROC [f: IO.STREAM, name: Rope.ROPE, version: REAL] RETURNS [mo: MasterObject] = { TFI3d.ReadRope[f, "data: procedural"]; TFI3d.ReadBlank[f]; mo _ SphereMakeMasterObject[name]; }; SphereFileout: PUBLIC PROC [f: IO.STREAM, mo: MasterObject] = { f.PutChar[IO.TAB]; f.PutF["data: procedural\n"]; }; SphereFileoutPoly: PUBLIC PROC [f: IO.STREAM, mo: MasterObject] = { revMesh: RevoluteMesh _ NARROW[mo.shadeBody]; SweepGeometry.PolyListRevolute[f, revMesh]; }; CylinderRec: TYPE = REF CylinderRecObj; CylinderRecObj: TYPE = SVMasterObjectTypes.CylinderRecObj; CylinderBody: PROC RETURNS [cylinderRec: CylinderRec] = { cylinderRec _ NEW[CylinderRecObj]; cylinderRec.radius _ 1; cylinderRec.height _ 2; }; CylinderMakeMasterObject: PUBLIC PROC [name: Rope.ROPE] RETURNS [mo: MasterObject] = { mainBody: CylinderRec _ CylinderBody[]; lineBody: REF ANY _ PredefSweeps.GetUnitCylinder[]; shadeBody: REF ANY _ lineBody; rayCastBody: REF ANY _ CylinderGetRayCastBody[]; mo _ SVScene.CreateMasterObject[name, cylinderClass, mainBody, lineBody, shadeBody, rayCastBody]; }; CylinderUpdate: PUBLIC PROC [mo: MasterObject, updateData: REF ANY] = { mo.lineBody _ PredefSweeps.GetUnitCylinder[]; mo.shadeBody _ mo.lineBody; mo.rayCastBody _ CylinderGetRayCastBody[]; }; CylinderBoundHedron: PUBLIC PROC [mo: MasterObject] RETURNS [hedron: BoundHedron] = { hedron _ SVBoundBox.HexagonalBoundHedron[1,1]; }; CylinderGetRayCastBody: PROC [] RETURNS [surfaceArray: SurfaceArray] = { topS, bottomS: DiskSurface; tubeS: TubeSurface; surfaceArray _ NEW[SurfaceArrayObj]; topS _ NEW[DiskSurfaceObj _ [top]]; bottomS _ NEW[DiskSurfaceObj _ [bottom]]; tubeS _ NEW[TubeSurfaceObj]; surfaceArray[1] _ topS; surfaceArray[2] _ bottomS; surfaceArray[3] _ tubeS; }; -- end of CylinderGetRayCastBody CylinderRayCast: PUBLIC PROC [cameraPoint: Point2d, localRay: Ray, sliceD: SliceDescriptor, prim: Primitive] RETURNS [class: Classification] = { mo: MasterObject _ prim.mo; RETURN[SVObjectCast.CylinderCast[localRay, NARROW[mo.rayCastBody], prim]]; }; CylinderRayCastNoBBoxes: PUBLIC PROC [localRay: Ray, sliceD: SliceDescriptor, prim: Primitive] RETURNS [class: Classification] = { mo: MasterObject _ prim.mo; RETURN[SVObjectCast.CylinderCast[localRay, NARROW[mo.rayCastBody], prim]]; }; CylinderRayCastBoundingSpheres: PUBLIC PROC [localRay: Ray, sliceD: SliceDescriptor, prim: Primitive] RETURNS [class: Classification] = { mo: MasterObject _ prim.mo; RETURN[SVObjectCast.CylinderCast[localRay, NARROW[mo.rayCastBody], prim]]; }; CylinderLineDraw: PUBLIC PROC[slice: Slice, dc: Imager.Context, camera: Camera] = { localCS: CoordSystem _ slice.coordSys; mo: MasterObject _ NARROW[slice.shape, Shape].mo; revMesh: RevoluteMesh; revMesh _ NARROW[mo.lineBody]; SweepGeometry.LineDrawRevoluteSweep[dc, revMesh, camera, localCS]; }; CylinderDrawNormals: PUBLIC PROC[dc: Imager.Context, data: REF ANY, camera: Camera, localCS: CoordSystem] = { revMesh: RevoluteMesh; IF ISTYPE[data, RevoluteMesh] THEN revMesh _ NARROW[data] ELSE SIGNAL WrongTypeOfData; SweepGeometry.DrawNormalsRevoluteSweep[dc, revMesh, camera, localCS]; }; CylinderCountSurf: PUBLIC PROC [masterObject: MasterObject] RETURNS [len: NAT] = { revMesh: RevoluteMesh _ NARROW[masterObject.shadeBody]; len _ SweepGeometry.CountPlanarSurfacesRevoluteSweep[revMesh]; }; CylinderCountVert: PUBLIC PROC [masterObject: MasterObject] RETURNS [len: NAT] = { revMesh: RevoluteMesh _ NARROW[masterObject.shadeBody]; len _ SweepGeometry.CountVerticesRevoluteSweep[revMesh]; }; CylinderGetSurf: PUBLIC PROC [slice: Slice, camera: CoordSystem] RETURNS [psl: PlanarSurfaceList] = { shape: Shape _ NARROW[slice.shape]; masterObject: MasterObject _ shape.mo; revMesh: RevoluteMesh _ NARROW[masterObject.shadeBody]; psl _ SweepGeometry.PlanarSurfacesRevoluteSweep[revMesh, slice, camera]; }; CylinderDrawSurf: PUBLIC PROC [dc: Imager.Context, ps: PlanarSurface, lightSources: LightSourceList, camera: Camera] = { SweepGeometry.DrawPlanarSurfaceRevoluteSweep[dc, ps, lightSources, camera]; }; CylinderFilein: PUBLIC PROC [f: IO.STREAM, name: Rope.ROPE, version: REAL] RETURNS [mo: MasterObject] = { TFI3d.ReadRope[f, "data: procedural"]; TFI3d.ReadBlank[f]; mo _ CylinderMakeMasterObject[name]; }; CylinderFileout: PUBLIC PROC [f: IO.STREAM, mo: MasterObject] = { f.PutF["data: procedural\n"]; }; CylinderFileoutPoly: PUBLIC PROC [f: IO.STREAM, mo: MasterObject] = { revMesh: RevoluteMesh _ NARROW[mo.shadeBody]; SweepGeometry.PolyListRevolute[f, revMesh]; }; ConeRec: TYPE = REF ConeRecObj; ConeRecObj: TYPE = SVMasterObjectTypes.ConeRecObj; ConeBody: PROC RETURNS [coneRec: ConeRec] = { coneRec _ NEW[ConeRecObj]; coneRec.radius _ 1; coneRec.height _ 1; }; ConeMakeMasterObject: PUBLIC PROC [name: Rope.ROPE] RETURNS [mo: MasterObject] = { mainBody: ConeRec _ ConeBody[]; lineBody: REF ANY _ PredefSweeps.GetUnitCone[]; shadeBody: REF ANY _ lineBody; rayCastBody: REF ANY _ ConeGetRayCastBody[]; mo _ SVScene.CreateMasterObject[name, coneClass, mainBody, lineBody, shadeBody, rayCastBody]; }; ConeUpdate: PUBLIC PROC [mo: MasterObject, updateData: REF ANY] = { mo.lineBody _ PredefSweeps.GetUnitCone[]; mo.shadeBody _ mo.lineBody; mo.rayCastBody _ ConeGetRayCastBody[]; }; ConeBoundHedron: PUBLIC PROC [mo: MasterObject] RETURNS [hedron: BoundHedron] = { hedron _ SVBoundBox.HexPyramidBoundHedron[1,1]; }; ConeGetRayCastBody: PROC [] RETURNS [surfaceArray: SurfaceArray] = { coneS: ConeSurface; diskS: DiskSurface; surfaceArray _ NEW[SurfaceArrayObj]; coneS _ NEW[ConeSurfaceObj]; diskS _ NEW[DiskSurfaceObj]; surfaceArray[1] _ coneS; surfaceArray[2] _ diskS; }; -- end of ConeGetRayCastBody ConeRayCast: PUBLIC PROC [cameraPoint: Point2d, localRay: Ray, sliceD: SliceDescriptor, prim: Primitive] RETURNS [class: Classification] = { mo: MasterObject _ prim.mo; RETURN[SVObjectCast.ConeCast[localRay, NARROW[mo.rayCastBody], prim]];}; ConeRayCastNoBBoxes: PUBLIC PROC [localRay: Ray, sliceD: SliceDescriptor, prim: Primitive] RETURNS [class: Classification] = { mo: MasterObject _ prim.mo; RETURN[SVObjectCast.ConeCast[localRay, NARROW[mo.rayCastBody], prim]];}; ConeRayCastBoundingSpheres: PUBLIC PROC [localRay: Ray, sliceD: SliceDescriptor, prim: Primitive] RETURNS [class: Classification] = { mo: MasterObject _ prim.mo; RETURN[SVObjectCast.ConeCast[localRay, NARROW[mo.rayCastBody], prim]];}; ConeLineDraw: PUBLIC PROC[slice: Slice, dc: Imager.Context, camera: Camera] = { localCS: CoordSystem _ slice.coordSys; mo: MasterObject _ NARROW[slice.shape, Shape].mo; revMesh: RevoluteMesh; revMesh _ NARROW[mo.lineBody]; SweepGeometry.LineDrawRevoluteSweep[dc, revMesh, camera, localCS]; }; ConeDrawNormals: PUBLIC PROC[dc: Imager.Context, data: REF ANY, camera: Camera, localCS: CoordSystem] = { revMesh: RevoluteMesh; IF ISTYPE[data, RevoluteMesh] THEN revMesh _ NARROW[data] ELSE SIGNAL WrongTypeOfData; SweepGeometry.DrawNormalsRevoluteSweep[dc, revMesh, camera, localCS]; }; ConeCountSurf: PUBLIC PROC [masterObject: MasterObject] RETURNS [len: NAT] = { revMesh: RevoluteMesh _ NARROW[masterObject.shadeBody]; len _ SweepGeometry.CountPlanarSurfacesRevoluteSweep[revMesh]; }; ConeCountVert: PUBLIC PROC [masterObject: MasterObject] RETURNS [len: NAT] = { revMesh: RevoluteMesh _ NARROW[masterObject.shadeBody]; len _ SweepGeometry.CountVerticesRevoluteSweep[revMesh]; }; ConeGetSurf: PUBLIC PROC [slice: Slice, camera: CoordSystem] RETURNS [psl: PlanarSurfaceList] = { shape: Shape _ NARROW[slice.shape]; masterObject: MasterObject _ shape.mo; revMesh: RevoluteMesh _ NARROW[masterObject.shadeBody]; psl _ SweepGeometry.PlanarSurfacesRevoluteSweep[revMesh, slice, camera]; }; ConeDrawSurf: PUBLIC PROC [dc: Imager.Context, ps: PlanarSurface, lightSources: LightSourceList, camera: Camera] = { SweepGeometry.DrawPlanarSurfaceRevoluteSweep[dc, ps, lightSources, camera]; }; ConeFilein: PUBLIC PROC [f: IO.STREAM, name: Rope.ROPE, version: REAL] RETURNS [mo: MasterObject] = { TFI3d.ReadRope[f, "data: procedural"]; TFI3d.ReadBlank[f]; mo _ ConeMakeMasterObject[name]; }; ConeFileout: PUBLIC PROC [f: IO.STREAM, mo: MasterObject] = { f.PutF["data: procedural\n"]; }; ConeFileoutPoly: PUBLIC PROC [f: IO.STREAM, mo: MasterObject] = { revMesh: RevoluteMesh _ NARROW[mo.shadeBody]; SweepGeometry.PolyListRevolute[f, revMesh]; }; TorusRec: TYPE = REF TorusRecObj; TorusRecObj: TYPE = SVMasterObjectTypes.TorusRecObj; TorusBody: PROC [bigRadius: REAL, sectionRadius: REAL] RETURNS [torusRec: TorusRec] = { torusRec _ NEW[TorusRecObj]; torusRec.bigRadius _ bigRadius; torusRec.sectionRadius _ sectionRadius; }; TorusMakeMasterObject: PUBLIC PROC [name: Rope.ROPE, bigRadius: REAL, sectionRadius: REAL] RETURNS [mo: MasterObject] = { mainBody: TorusRec _ TorusBody[bigRadius, sectionRadius]; lineBody: REF ANY _ PredefSweeps.CreateTorus[mainBody.bigRadius, mainBody.sectionRadius]; shadeBody: REF ANY _ lineBody; rayCastBody: REF ANY _ TorusGetRayCastBody[]; mo _ SVScene.CreateMasterObject[name, torusClass, mainBody, lineBody, shadeBody, rayCastBody]; }; TorusUpdate: PUBLIC PROC [mo: MasterObject, updateData: REF ANY] = { mainBody: TorusRec _ NARROW[mo.mainBody]; mo.lineBody _ PredefSweeps.CreateTorus[mainBody.bigRadius, mainBody.sectionRadius]; mo.shadeBody _ mo.lineBody; mo.rayCastBody _ TorusGetRayCastBody[]; }; TorusBoundHedron: PUBLIC PROC [mo: MasterObject] RETURNS [hedron: BoundHedron] = { torusRec: TorusRec _ NARROW[mo.mainBody]; hedron _ SVBoundBox.HexagonalBoundHedron[torusRec.bigRadius + torusRec.sectionRadius, torusRec.sectionRadius]; }; TorusGetRayCastBody: PROC [] RETURNS [surfaceArray: SurfaceArray] = { torusS: ToroidalSurface; surfaceArray _ NEW[SurfaceArrayObj]; torusS _ NEW[ToroidalSurfaceObj]; surfaceArray[1] _ torusS; }; -- end of TorusGetRayCastBody TorusRayCast: PUBLIC PROC [cameraPoint: Point2d, localRay: Ray, sliceD: SliceDescriptor, prim: Primitive] RETURNS [class: Classification] = { mo: MasterObject _ prim.mo; surfaceArray: SurfaceArray _ NARROW[mo.rayCastBody]; RETURN[SVObjectCast.ToroidCast[localRay, prim, mo.mainBody, surfaceArray[1]]]; }; TorusRayCastNoBBoxes: PUBLIC PROC [localRay: Ray, sliceD: SliceDescriptor, prim: Primitive] RETURNS [class: Classification] = { mo: MasterObject _ prim.mo; surfaceArray: SurfaceArray _ NARROW[mo.rayCastBody]; RETURN[SVObjectCast.ToroidCast[localRay, prim, mo.mainBody, surfaceArray[1]]]; }; TorusRayCastBoundingSpheres: PUBLIC PROC [localRay: Ray, sliceD: SliceDescriptor, prim: Primitive] RETURNS [class: Classification] = { mo: MasterObject _ prim.mo; surfaceArray: SurfaceArray _ NARROW[mo.rayCastBody]; RETURN[SVObjectCast.ToroidCast[localRay, prim, mo.mainBody, surfaceArray[1]]]; }; TorusLineDraw: PUBLIC PROC [slice: Slice, dc: Imager.Context, camera: Camera] = { localCS: CoordSystem _ slice.coordSys; mo: MasterObject _ NARROW[slice.shape, Shape].mo; torMesh: ToroidalMesh; torMesh _ NARROW[mo.lineBody]; SweepGeometry.LineDrawToroidalSweep[dc, torMesh, camera, localCS]; }; TorusDrawNormals: PUBLIC PROC[dc: Imager.Context, data: REF ANY, camera: Camera, localCS: CoordSystem] = { torMesh: ToroidalMesh; IF ISTYPE[data, ToroidalMesh] THEN torMesh _ NARROW[data] ELSE SIGNAL WrongTypeOfData; SweepGeometry.DrawNormalsToroidalSweep[dc, torMesh, camera, localCS]; }; TorusCountSurf: PUBLIC PROC [masterObject: MasterObject] RETURNS [len: NAT] = { torMesh: ToroidalMesh _ NARROW[masterObject.shadeBody]; len _ SweepGeometry.CountPlanarSurfacesToroidalSweep[torMesh]; }; TorusCountVert: PUBLIC PROC [masterObject: MasterObject] RETURNS [len: NAT] = { torMesh: ToroidalMesh _ NARROW[masterObject.shadeBody]; len _ SweepGeometry.CountVerticesToroidalSweep[torMesh]; }; TorusGetSurf: PUBLIC PROC [slice: Slice, camera: CoordSystem] RETURNS [psl: PlanarSurfaceList] = { shape: Shape _ NARROW[slice.shape]; masterObject: MasterObject _ shape.mo; torMesh: ToroidalMesh _ NARROW[masterObject.shadeBody]; psl _ SweepGeometry.PlanarSurfacesToroidalSweep[torMesh, slice, camera]; }; TorusDrawSurf: PUBLIC PROC [dc: Imager.Context, ps: PlanarSurface, lightSources: LightSourceList, camera: Camera] = { SweepGeometry.DrawPlanarSurfaceToroidalSweep[dc, ps, lightSources, camera]; }; TorusFilein: PUBLIC PROC [f: IO.STREAM, name: Rope.ROPE, version: REAL] RETURNS [mo: MasterObject] = { bigRadius, sectionRadius: REAL; TFI3d.ReadBlankAndRope[f, "bigRadius:"]; bigRadius _ TFI3d.ReadBlankAndReal[f]; TFI3d.ReadBlankAndRope[f, ","]; TFI3d.ReadBlankAndRope[f, "sectionRadius:"]; sectionRadius _ TFI3d.ReadBlankAndReal[f]; mo _ TorusMakeMasterObject[name, bigRadius, sectionRadius]; }; TorusFileout: PUBLIC PROC [f: IO.STREAM, mo: MasterObject] = { torusRec: TorusRec _ NARROW[mo.mainBody]; f.PutF["bigRadius: %g, sectionRadius: %g\n", [real[torusRec.bigRadius]], [real[torusRec.sectionRadius]] ]; };-- end of TorusFileout TorusFileoutPoly: PUBLIC PROC [f: IO.STREAM, mo: MasterObject] = { torMesh: ToroidalMesh _ NARROW[mo.shadeBody]; SweepGeometry.PolyListToroidal[f, torMesh]; }; AppendClassToList: PROC [moc: MasterObjectClass, list: MasterObjectClassList] RETURNS [MasterObjectClassList] = { z: MasterObjectClassList _ list; IF z = NIL THEN RETURN[CONS[moc,NIL]]; UNTIL z.rest = NIL DO z _ z.rest; ENDLOOP; z.rest _ CONS[moc,NIL]; RETURN[list]; }; RegisterMasterObjectClass: PUBLIC PROC [moClass: MasterObjectClass] = { globalClassList _ AppendClassToList[moClass, globalClassList]; }; AppendToMasterObjects: PUBLIC PROC [mo: MasterObject, list: MasterObjectList] RETURNS [MasterObjectList] = { z: MasterObjectList _ list; IF z = NIL THEN RETURN[CONS[mo,NIL]]; UNTIL z.rest = NIL DO z _ z.rest; ENDLOOP; z.rest _ CONS[mo,NIL]; RETURN[list]; }; RegisterMasterObject: PUBLIC PROC [mo: MasterObject] = { globalMOList _ AppendToMasterObjects[mo, globalMOList]; }; GetMasterObjectList: PUBLIC PROC [] RETURNS [moList: MasterObjectList] = { moList _ globalMOList; }; FindClassFromName: PUBLIC PROC [name: Rope.ROPE] RETURNS [moClass: MasterObjectClass, success: BOOL] = { FOR moClassList: MasterObjectClassList _ globalClassList, moClassList.rest UNTIL moClassList = NIL DO IF Rope.Equal[moClassList.first.name, name, TRUE] THEN RETURN [moClassList.first, TRUE]; ENDLOOP; RETURN[NIL, FALSE]; }; Init: PROC = { sphere, cylinder, cone: MasterObject; sphereClass _ NEW[MasterObjectClassObj _ [ name: "sphere", update: SphereUpdate, filein: SphereFilein, fileout: SphereFileout, fileoutPoly: SphereFileoutPoly, rayCast: SphereRayCast, rayCastNoBBoxes: SphereRayCastNoBBoxes, rayCastBoundingSpheres: SphereRayCastBoundingSpheres, getHedron: SphereBoundHedron, preprocess: NoOpPreprocess, lineDraw: SphereLineDraw, normalsDraw: SphereDrawNormals, countSurf: SphereCountSurf, getSurf: SphereGetSurf, pointsInDescriptor: NoOpPointsInDescriptor, nextPoint: NoOpNextPoint, drawSurf: SphereDrawSurf, drawSubBoxes: NoOpDrawSubBoxes, drawSubSpheres: NoOpDrawSubSpheres]]; cylinderClass _ NEW[MasterObjectClassObj _ [ name: "cylinder", update: CylinderUpdate, filein: CylinderFilein, fileout: CylinderFileout, fileoutPoly: CylinderFileoutPoly, rayCast: CylinderRayCast, rayCastNoBBoxes: CylinderRayCastNoBBoxes, rayCastBoundingSpheres: CylinderRayCastBoundingSpheres, getHedron: CylinderBoundHedron, preprocess: NoOpPreprocess, lineDraw: CylinderLineDraw, normalsDraw: CylinderDrawNormals, countSurf: CylinderCountSurf, getSurf: CylinderGetSurf, pointsInDescriptor: NoOpPointsInDescriptor, nextPoint: NoOpNextPoint, drawSurf: CylinderDrawSurf, drawSubBoxes: NoOpDrawSubBoxes, drawSubSpheres: NoOpDrawSubSpheres]]; coneClass _ NEW[MasterObjectClassObj _ [ name: "cone", update: ConeUpdate, filein: ConeFilein, fileout: ConeFileout, fileoutPoly: ConeFileoutPoly, rayCast: ConeRayCast, rayCastNoBBoxes: ConeRayCastNoBBoxes, rayCastBoundingSpheres: ConeRayCastBoundingSpheres, getHedron: ConeBoundHedron, preprocess: NoOpPreprocess, lineDraw: ConeLineDraw, normalsDraw: ConeDrawNormals, countSurf: ConeCountSurf, getSurf: ConeGetSurf, pointsInDescriptor: NoOpPointsInDescriptor, nextPoint: NoOpNextPoint, drawSurf: ConeDrawSurf, drawSubBoxes: NoOpDrawSubBoxes, drawSubSpheres: NoOpDrawSubSpheres]]; torusClass _ NEW[MasterObjectClassObj _ [ name: "torus", update: TorusUpdate, filein: TorusFilein, fileout: TorusFileout, fileoutPoly: TorusFileoutPoly, rayCast: TorusRayCast, rayCastNoBBoxes: TorusRayCastNoBBoxes, rayCastBoundingSpheres: TorusRayCastBoundingSpheres, getHedron: TorusBoundHedron, preprocess: NoOpPreprocess, lineDraw: TorusLineDraw, normalsDraw: TorusDrawNormals, countSurf: TorusCountSurf, getSurf: TorusGetSurf, pointsInDescriptor: NoOpPointsInDescriptor, nextPoint: NoOpNextPoint, drawSurf: TorusDrawSurf, drawSubBoxes: NoOpDrawSubBoxes, drawSubSpheres: NoOpDrawSubSpheres]]; SVMasterObject.RegisterMasterObjectClass[sphereClass]; SVMasterObject.RegisterMasterObjectClass[cylinderClass]; SVMasterObject.RegisterMasterObjectClass[coneClass]; SVMasterObject.RegisterMasterObjectClass[torusClass]; sphere _ SphereMakeMasterObject["sphere"]; cylinder _ CylinderMakeMasterObject["cylinder"]; cone _ ConeMakeMasterObject["cone"]; RegisterMasterObject[sphere]; RegisterMasterObject[cylinder]; RegisterMasterObject[cone]; }; Init[]; END. κFile: SVMasterObjectImplA.mesa Last edited by: Eric Bier on June 1, 1987 1:08:48 pm PDT Copyright c 1984 by Xerox Corporation. All rights reserved. Contents: Defines a simple set of objects which can be display with ray casting, line drawing, or shaded planar-surface approximation. GENERAL TYPES GLOBAL VARIABLES OldSphereDrawNormals: PUBLIC PROC[dc: Imager.Context, data: REF ANY, camera: Camera, localCS: CoordSystem] = { revMesh: RevoluteMesh; IF ISTYPE[data, RevoluteMesh] THEN revMesh _ NARROW[data] ELSE SIGNAL WrongTypeOfData; SweepGeometry.DrawNormalsRevoluteSweep[dc, revMesh, camera, localCS]; }; FOR j: NAT IN [1..linesOfLatitude-1] DO ENDLOOP; Spheres can be recovered from scratch. Cylinder can be recovered from scratch. Cone can be recovered from scratch. Torus can be recovered from bigRadius and sectionRadius. Set Up the System A copy of List.Nconc1 for MasterObjectClassList instead of LIST OF REF ANY A copy of List.Nconc1 for MasterObjectList instead of LIST OF REF ANY Κέ– "cedar" style˜Iheadšœ™Iprocšœ8™8Jšœ Οmœ1™˜>Lšœ˜—š  œžœžœžœžœ˜PLšœžœ˜7Lšœ8˜8Lšœ˜—š  œžœžœ%žœ˜cLšœžœ˜#Lšœ&˜&Lšœžœ˜7LšœH˜HLšœ˜—š œžœžœ[˜vLšœK˜KLšœ˜—š  œžœžœžœžœ žœ žœžœ˜gLšœ&˜&Lšœ˜Lšœ"˜"Lšœ˜—š   œžœžœžœžœ˜?Lšœ&™&Lšœ žœžœ˜Lšœ˜Lšœ˜—š  œžœžœžœžœ˜CLšœžœ˜-Lšœ+˜+L˜L˜—L˜L˜Lšœ žœžœ˜'Lšœžœ&˜:š  œžœžœ˜9Lšœžœ˜"Lšœ/˜/Lšœ˜—š  œžœžœ žœžœ˜VLšœ'˜'Lšœ žœžœ"˜3Lšœ žœžœ ˜Lšœ žœžœ˜0Lšœa˜aLšœ˜—š  œžœžœ žœžœ˜GLšœ-˜-Lšœ˜Lšœ*˜*Lšœ˜—š œžœžœžœ˜ULšœ.˜.Lšœ˜—š œžœžœ!˜HLšœ˜Lšœ˜Lšœžœ˜%Lšœžœ˜#Lšœ žœ˜)Lšœžœ˜Lšœ˜Lšœ˜Lšœ˜LšœΟc ˜#—š œžœžœQžœ˜Lšœ˜Lšžœ%žœ˜JLšœ˜—š œžœžœ;žœ˜‚Lšœ˜Lšžœ%žœ˜JLšœ˜L˜—š œžœžœ;žœ˜‰Lšœ˜Lšžœ%žœ˜JLšœ˜—š œžœžœ6˜SLšœ&˜&Lšœžœ˜1Lšœ˜Lšœ žœ˜LšœC˜CLšœ˜—š  œžœžœžœžœ+˜mLšœ˜Lšžœžœ˜Lšžœ žœ˜Lšžœžœ˜LšœF˜FLšœ˜—š  œžœžœžœžœ˜RLšœžœ˜7Lšœ>˜>Lšœ˜—š  œžœžœžœžœ˜RLšœžœ˜7Lšœ8˜8Lšœ˜—š œžœžœ%žœ˜eLšœžœ˜#Lšœ&˜&Lšœžœ˜7LšœH˜HLšœ˜—š œžœžœ[˜xLšœK˜KLšœ˜—š œžœžœžœžœ žœ žœžœ˜iLšœ&˜&Lšœ˜Lšœ$˜$Lšœ˜—š  œžœžœžœžœ˜ALšœ'™'Lšœ˜L˜—š  œžœžœžœžœ˜ELšœžœ˜-Lšœ+˜+L˜—L˜Lšœ žœžœ ˜Lšœ žœ"˜2L˜š œžœžœ˜-Lšœ žœ ˜Lšœ'˜'Lšœ˜—š  œžœžœ žœžœ˜RLšœ˜Lšœ žœžœ˜/Lšœ žœžœ ˜Lšœ žœžœ˜,Lšœ]˜]Lšœ˜—š   œžœžœ žœžœ˜CLšœ)˜)Lšœ˜Lšœ&˜&Lšœ˜—š œžœžœžœ˜QLšœ/˜/Lšœ˜—š œžœžœ!˜DLšœ˜Lšœ˜Lšœžœ˜%Lšœžœ˜Lšœžœ˜Lšœ˜Lšœ˜Lšœ’˜—š  œžœžœQžœ˜ŒLšœ˜Lšžœ!žœ˜H—š œžœžœ;žœ˜~Lšœ˜Lšžœ!žœ˜H—š œžœžœ;žœ˜…Lšœ˜Lšžœ!žœ˜HL˜—š  œžœžœ6˜OLšœ&˜&Lšœžœ˜1Lšœ˜Lšœ žœ˜LšœB˜BLšœ˜—š  œžœžœžœžœ+˜iLšœ˜Lšžœžœ˜Lšžœ žœ˜Lšžœžœ˜LšœE˜ELšœ˜—š   œžœžœžœžœ˜NLšœžœ˜7Lšœ>˜>Lšœ˜—š   œžœžœžœžœ˜NLšœžœ˜7Lšœ8˜8Lšœ˜—š  œžœžœ%žœ˜aLšœžœ˜#Lšœ&˜&Lšœžœ˜7LšœH˜HLšœ˜—š  œžœžœ[˜tLšœK˜KLšœ˜—š  œžœžœžœžœ žœ žœžœ˜eLšœ&˜&Lšœ˜Lšœ ˜ Lšœ˜—š   œžœžœžœžœ˜=Lšœ#™#Lšœ˜Lšœ˜—š  œžœžœžœžœ˜ALšœžœ˜-Lšœ+˜+L˜—L˜Lšœ žœžœ ˜!Lšœ žœ#˜4L˜š   œžœ žœžœžœ˜WLšœ žœ˜Lšœ˜Lšœ'˜'Lšœ˜—š œžœžœ žœ žœžœžœ˜yLšœ9˜9Lšœ žœžœH˜YLšœ žœžœ ˜Lšœ žœžœ˜-Lšœ^˜^Lšœ˜—š   œžœžœ žœžœ˜DJšœ)˜)JšœS˜SJšœ˜Jšœ'˜'J˜—š œžœžœžœ˜RLšœžœ˜)Lšœ˜LšœL˜LLšœ˜Lšœ˜—š œžœžœ!˜ELšœ˜Lšœžœ˜%Lšœ žœ˜!Lšœ˜Lšœ’˜ —š  œžœžœQžœ˜Lšœ˜Lšœžœ˜4LšžœH˜NLšœ˜—š œžœžœ;žœ˜Lšœ˜Lšœžœ˜4LšžœH˜NLšœ˜—š œžœžœ;žœ˜†Lšœ˜Lšœžœ˜4LšžœH˜NLšœ˜—š  œžœžœ6˜QLšœ&˜&Lšœžœ˜1Lšœ˜Lšœ žœ˜LšœB˜BLšœ˜—š  œžœžœžœžœ+˜jLšœ˜Lšžœžœ˜Lšžœ žœ˜Lšžœžœ˜LšœE˜ELšœ˜—š  œžœžœžœžœ˜OLšœžœ˜7Lšœ>˜>Lšœ˜—š  œžœžœžœžœ˜OLšœžœ˜7Lšœ8˜8Lšœ˜—š  œžœžœ%žœ˜bLšœžœ˜#Lšœ&˜&Lšœžœ˜7LšœH˜HLšœ˜—š  œžœžœ[˜uLšœK˜KLšœ˜—š  œžœžœžœžœ žœ žœžœ˜fLšœžœ˜Lšœ(˜(Lšœ&˜&Lšœ˜Lšœ,˜,Lšœ*˜*Lšœ;˜;Lšœ˜—š   œžœžœžœžœ˜>Lšœ8™8Lšœžœ˜)LšœH˜HLšœ!˜!Lšœ’˜—š  œžœžœžœžœ˜BLšœžœ˜-Lšœ+˜+L˜—Ihead1šœ™š œžœ7žœ˜qJšœJ™JJšœ ˜ Jš žœžœžœžœžœžœ˜&Jšžœ žœžœ žœ˜*Jšœ žœžœ˜Jšžœ˜ Jšœ˜—J™– "Cedar" styleš œžœžœ!˜GJšœ>˜>J– "Cedar" style˜—š œžœžœ,žœ˜lJšœE™EJšœ˜Jš žœžœžœžœžœžœ˜%Jšžœ žœžœ žœ˜*Jšœ žœžœ˜Jšžœ˜ Jšœ˜—š œžœžœ˜8Jšœ7˜7Jšœ˜—– "Cedar" styleš œž œžœ˜JJ– "Cedar" stylešœ˜J– "Cedar" style˜—š  œžœžœ žœžœ'žœ˜hšžœG˜JJšžœžœž˜Jš žœ*žœžœžœžœ˜X—Jšžœ˜Jšžœžœžœ˜Jšœ˜—š œžœ˜Lšœ%˜%L˜šœžœ˜*LšŸœ ˜LšŸœ˜LšŸœ˜LšŸœ˜LšŸ œ˜LšŸœ˜LšŸœ˜'LšŸœ˜5LšŸ œ˜LšŸ œ˜LšŸœ˜LšŸ œ˜LšŸ œ˜LšŸœ˜LšŸœ˜+LšŸ œ˜LšŸœ˜LšŸ œ˜LšŸœ˜%L˜—šœžœ˜,LšŸœ ˜LšŸœ˜LšŸœ˜LšŸ œ˜LšŸ œ˜!LšŸœ˜LšŸœ˜)LšŸœ!˜7LšŸ œ˜LšŸ œ˜LšŸœ˜LšŸ œ˜!LšŸ œ˜LšŸœ˜LšŸœ˜+LšŸ œ˜LšŸœ˜LšŸ œ˜LšŸœ˜%L˜—šœ žœ˜(LšŸœ ˜ LšŸœ ˜LšŸœ ˜LšŸœ˜LšŸ œ˜LšŸœ˜LšŸœ˜%LšŸœ˜3LšŸ œ˜LšŸ œ˜LšŸœ˜LšŸ œ˜LšŸ œ˜LšŸœ˜LšŸœ˜+LšŸ œ˜LšŸœ˜LšŸ œ˜LšŸœ˜%L˜—šœ žœ˜)LšŸœ ˜LšŸœ˜LšŸœ˜LšŸœ˜LšŸ œ˜LšŸœ˜LšŸœ˜&LšŸœ˜4LšŸ œ˜LšŸ œ˜LšŸœ˜LšŸ œ˜LšŸ œ˜LšŸœ˜LšŸœ˜+LšŸ œ˜LšŸœ˜LšŸ œ˜LšŸœ˜%L˜—L˜Lšœ6˜6Lšœ8˜8Lšœ4˜4Lšœ5˜5L˜Lšœ*˜*Lšœ0˜0Lšœ$˜$L˜Lšœ˜Lšœ˜Lšœ˜Lšœ˜—L˜Lšœ˜L˜Lšžœ˜L˜—…—cŒ„S