File: SVMasterObjectImplA.mesa
Last edited by: Eric Bier on August 29, 1987 2:28:04 pm PDT
Copyright © 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.
DIRECTORY
SVCoordSys, Feedback, GGParseIn, Imager, IO, SVMatrix3d, SVObjectCast, SVPredefSweeps, Real, Rope, SV2d, SV3d, SVAssembly, SVBasicTypes, SVBoundBox, SVDraw3d, SVFaces, SVLines3d, SVMasterObject, SVMasterObjectTypes, SVModelTypes, SVScene, SVSceneTypes, SVVector3d, SVSweepCast, SVSweepGeometry;
SVMasterObjectImplA: CEDAR PROGRAM
IMPORTS SVCoordSys, GGParseIn, IO, SVMatrix3d, SVObjectCast, SVPredefSweeps, Rope, SVBoundBox, SVDraw3d, SVMasterObject, SVScene, SVSweepGeometry
EXPORTS SVMasterObject =
BEGIN
OPEN SVMasterObject;
GENERAL TYPES
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;
CoordSysList: TYPE = SVModelTypes.CoordSysList;
Cylinder: TYPE = SVFaces.Cylinder;
DiskRing: TYPE = SVFaces.DiskRing;
DiskSurface: TYPE = REF DiskSurfaceObj;
DiskSurfaceObj: TYPE = SVObjectCast.DiskSurfaceObj;
Edge3d: TYPE = SV3d.Edge3d;
FeedbackData: TYPE = Feedback.FeedbackData;
LightSourceList: TYPE = SVModelTypes.LightSourceList;
LinearMesh: TYPE = REF LinearMeshRecord;
LinearMeshArray: TYPE = SVSweepGeometry.LinearMeshArray;
LinearMeshRecord: TYPE = SVSweepGeometry.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 = SVSweepCast.RevoFace;
RevoluteMesh: TYPE = REF RevoluteMeshRecord;
RevoluteMeshArray: TYPE = SVSweepGeometry.RevoluteMeshArray;
RevoluteMeshRecord: TYPE = SVSweepGeometry.RevoluteMeshRecord;
SelectMode: TYPE = SVSceneTypes.SelectMode;
Shape: TYPE = SVSceneTypes.Shape;
ShellSurface: TYPE = REF ShellSurfaceObj;
ShellSurfaceObj: TYPE = SVObjectCast.ShellSurfaceObj;
Slice: TYPE = SVSceneTypes.Slice;
SliceDescriptor: TYPE = SVSceneTypes.SliceDescriptor;
SliceParts: TYPE = SVSceneTypes.SliceParts;
SubBoxesBody: TYPE = REF SubBoxesBodyObj;
SubBoxesBodyObj: TYPE = SVSweepCast.SubBoxesBodyObj;
SubSpheresBody: TYPE = REF SubSpheresBodyObj;
SubSpheresBodyObj: TYPE = SVSweepCast.SubSpheresBodyObj;
SurfaceArray: TYPE = REF SurfaceArrayObj;
SurfaceArrayObj: TYPE = SVSceneTypes.SurfaceArrayObj;
ToroidalMesh: TYPE = REF ToroidalMeshRecord;
ToroidalMeshRecord: TYPE = SVSweepGeometry.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;
GLOBAL VARIABLES
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 ← SVPredefSweeps.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 ← SVPredefSweeps.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, positiveTOnly: BOOLTRUE] RETURNS [class: Classification] = {
mo: MasterObject ← prim.mo;
RETURN[SVObjectCast.SphereCast[localRay, NARROW[mo.rayCastBody], prim, positiveTOnly]];
};
SphereRayCastNoBBoxes: PUBLIC PROC [localRay: Ray, sliceD: SliceDescriptor, prim: Primitive, positiveTOnly: BOOLTRUE] RETURNS [class: Classification] = {
mo: MasterObject ← prim.mo;
RETURN[SVObjectCast.SphereCast[localRay, NARROW[mo.rayCastBody], prim, positiveTOnly]];
};
SphereRayCastBoundingSpheres: PUBLIC PROC [localRay: Ray, sliceD: SliceDescriptor, prim: Primitive, positiveTOnly: BOOLTRUE] RETURNS [class: Classification] = {
mo: MasterObject ← prim.mo;
RETURN[SVObjectCast.SphereCast[localRay, NARROW[mo.rayCastBody], prim, positiveTOnly]];
};
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];
SVSweepGeometry.LineDrawRevoluteSweep[dc, revMesh, camera, localCS];
};
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;
SVSweepGeometry.DrawNormalsRevoluteSweep[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 ← SVCoordSys.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 ← SVMatrix3d.LocalRotateY[transform, deltaTheta];
SVDraw3d.DrawTransformedShape[dc: dc, csCAMERA: transform, camera: camera, path: CirclePath];
ENDLOOP;
transform ← csCamera;
transform ← SVMatrix3d.LocalRotateX[transform, 90];
SVDraw3d.DrawTransformedShape[dc: dc, csCAMERA: transform, camera: camera, path: CirclePath];
FOR j: NAT IN [1..linesOfLatitude-1] DO
ENDLOOP;
};
SphereCountSurf: PUBLIC PROC [masterObject: MasterObject] RETURNS [len: NAT] = {
revMesh: RevoluteMesh ← NARROW[masterObject.shadeBody];
len ← SVSweepGeometry.CountPlanarSurfacesRevoluteSweep[revMesh];
};
SphereCountVert: PUBLIC PROC [masterObject: MasterObject] RETURNS [len: NAT] = {
revMesh: RevoluteMesh ← NARROW[masterObject.shadeBody];
len ← SVSweepGeometry.CountVerticesRevoluteSweep[revMesh];
};
SphereGetSurf: PUBLIC PROC [slice: Slice, camera: CoordSystem, eyeWorld: Point3d] RETURNS [psl: PlanarSurfaceList] = {
shape: Shape ← NARROW[slice.shape];
masterObject: MasterObject ← shape.mo;
revMesh: RevoluteMesh ← NARROW[masterObject.shadeBody];
psl ← SVSweepGeometry.PlanarSurfacesRevoluteSweep[revMesh, slice, camera];
};
SphereDrawSurf: PUBLIC PROC [dc: Imager.Context, ps: PlanarSurface, lightSources: LightSourceList, camera: Camera, eyeWorld: Point3d, hiddenLine: BOOL] = {
SVSweepGeometry.DrawPlanarSurfaceRevoluteSweep[dc, ps, lightSources, camera, hiddenLine];
};
SphereFilein: PUBLIC PROC [f: IO.STREAM, name: Rope.ROPE, csList: CoordSysList, defaultCS: CoordSystem, wdir: Rope.ROPE, version: REAL, feedback: FeedbackData] RETURNS [mo: MasterObject] = {
GGParseIn.ReadWRope[f, "data: procedural"];
GGParseIn.ReadBlank[f];
mo ← SphereMakeMasterObject[name];
};
SphereFileout: PUBLIC PROC [f: IO.STREAM, mo: MasterObject] = {
Spheres can be recovered from scratch.
f.PutChar[IO.TAB];
f.PutF["data: procedural\n"];
};
SphereFileoutPoly: PUBLIC PROC [f: IO.STREAM, mo: MasterObject] = {
revMesh: RevoluteMesh ← NARROW[mo.shadeBody];
SVSweepGeometry.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 ← SVPredefSweeps.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 ← SVPredefSweeps.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, positiveTOnly: BOOLTRUE] RETURNS [class: Classification] = {
mo: MasterObject ← prim.mo;
RETURN[SVObjectCast.CylinderCast[localRay, NARROW[mo.rayCastBody], prim, positiveTOnly]];
};
CylinderRayCastNoBBoxes: PUBLIC PROC [localRay: Ray, sliceD: SliceDescriptor, prim: Primitive, positiveTOnly: BOOLTRUE] RETURNS [class: Classification] = {
mo: MasterObject ← prim.mo;
RETURN[SVObjectCast.CylinderCast[localRay, NARROW[mo.rayCastBody], prim, positiveTOnly]];
};
CylinderRayCastBoundingSpheres: PUBLIC PROC [localRay: Ray, sliceD: SliceDescriptor, prim: Primitive, positiveTOnly: BOOLTRUE] RETURNS [class: Classification] = {
mo: MasterObject ← prim.mo;
RETURN[SVObjectCast.CylinderCast[localRay, NARROW[mo.rayCastBody], prim, positiveTOnly]];
};
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];
SVSweepGeometry.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;
SVSweepGeometry.DrawNormalsRevoluteSweep[dc, revMesh, camera, localCS];
};
CylinderCountSurf: PUBLIC PROC [masterObject: MasterObject] RETURNS [len: NAT] = {
revMesh: RevoluteMesh ← NARROW[masterObject.shadeBody];
len ← SVSweepGeometry.CountPlanarSurfacesRevoluteSweep[revMesh];
};
CylinderCountVert: PUBLIC PROC [masterObject: MasterObject] RETURNS [len: NAT] = {
revMesh: RevoluteMesh ← NARROW[masterObject.shadeBody];
len ← SVSweepGeometry.CountVerticesRevoluteSweep[revMesh];
};
CylinderGetSurf: PUBLIC PROC [slice: Slice, camera: CoordSystem, eyeWorld: Point3d] RETURNS [psl: PlanarSurfaceList] = {
shape: Shape ← NARROW[slice.shape];
masterObject: MasterObject ← shape.mo;
revMesh: RevoluteMesh ← NARROW[masterObject.shadeBody];
psl ← SVSweepGeometry.PlanarSurfacesRevoluteSweep[revMesh, slice, camera];
};
CylinderDrawSurf: PUBLIC PROC [dc: Imager.Context, ps: PlanarSurface, lightSources: LightSourceList, camera: Camera, eyeWorld: Point3d, hiddenLine: BOOL] = {
SVSweepGeometry.DrawPlanarSurfaceRevoluteSweep[dc, ps, lightSources, camera, hiddenLine];
};
CylinderFilein: PUBLIC PROC [f: IO.STREAM, name: Rope.ROPE, csList: CoordSysList, defaultCS: CoordSystem, wdir: Rope.ROPE, version: REAL, feedback: FeedbackData] RETURNS [mo: MasterObject] = {
GGParseIn.ReadWRope[f, "data: procedural"];
GGParseIn.ReadBlank[f];
mo ← CylinderMakeMasterObject[name];
};
CylinderFileout: PUBLIC PROC [f: IO.STREAM, mo: MasterObject] = {
Cylinder can be recovered from scratch.
f.PutF["data: procedural\n"];
};
CylinderFileoutPoly: PUBLIC PROC [f: IO.STREAM, mo: MasterObject] = {
revMesh: RevoluteMesh ← NARROW[mo.shadeBody];
SVSweepGeometry.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 ← SVPredefSweeps.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 ← SVPredefSweeps.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, positiveTOnly: BOOLTRUE] RETURNS [class: Classification] = {
mo: MasterObject ← prim.mo;
RETURN[SVObjectCast.ConeCast[localRay, NARROW[mo.rayCastBody], prim, positiveTOnly]];};
ConeRayCastNoBBoxes: PUBLIC PROC [localRay: Ray, sliceD: SliceDescriptor, prim: Primitive, positiveTOnly: BOOLTRUE] RETURNS [class: Classification] = {
mo: MasterObject ← prim.mo;
RETURN[SVObjectCast.ConeCast[localRay, NARROW[mo.rayCastBody], prim, positiveTOnly]];};
ConeRayCastBoundingSpheres: PUBLIC PROC [localRay: Ray, sliceD: SliceDescriptor, prim: Primitive, positiveTOnly: BOOLTRUE] RETURNS [class: Classification] = {
mo: MasterObject ← prim.mo;
RETURN[SVObjectCast.ConeCast[localRay, NARROW[mo.rayCastBody], prim, positiveTOnly]];};
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];
SVSweepGeometry.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;
SVSweepGeometry.DrawNormalsRevoluteSweep[dc, revMesh, camera, localCS];
};
ConeCountSurf: PUBLIC PROC [masterObject: MasterObject] RETURNS [len: NAT] = {
revMesh: RevoluteMesh ← NARROW[masterObject.shadeBody];
len ← SVSweepGeometry.CountPlanarSurfacesRevoluteSweep[revMesh];
};
ConeCountVert: PUBLIC PROC [masterObject: MasterObject] RETURNS [len: NAT] = {
revMesh: RevoluteMesh ← NARROW[masterObject.shadeBody];
len ← SVSweepGeometry.CountVerticesRevoluteSweep[revMesh];
};
ConeGetSurf: PUBLIC PROC [slice: Slice, camera: CoordSystem, eyeWorld: Point3d] RETURNS [psl: PlanarSurfaceList] = {
shape: Shape ← NARROW[slice.shape];
masterObject: MasterObject ← shape.mo;
revMesh: RevoluteMesh ← NARROW[masterObject.shadeBody];
psl ← SVSweepGeometry.PlanarSurfacesRevoluteSweep[revMesh, slice, camera];
};
ConeDrawSurf: PUBLIC PROC [dc: Imager.Context, ps: PlanarSurface, lightSources: LightSourceList, camera: Camera, eyeWorld: Point3d, hiddenLine: BOOL] = {
SVSweepGeometry.DrawPlanarSurfaceRevoluteSweep[dc, ps, lightSources, camera, hiddenLine];
};
ConeFilein: PUBLIC PROC [f: IO.STREAM, name: Rope.ROPE, csList: CoordSysList, defaultCS: CoordSystem, wdir: Rope.ROPE, version: REAL, feedback: FeedbackData] RETURNS [mo: MasterObject] = {
GGParseIn.ReadWRope[f, "data: procedural"];
GGParseIn.ReadBlank[f];
mo ← ConeMakeMasterObject[name];
};
ConeFileout: PUBLIC PROC [f: IO.STREAM, mo: MasterObject] = {
Cone can be recovered from scratch.
f.PutF["data: procedural\n"];
};
ConeFileoutPoly: PUBLIC PROC [f: IO.STREAM, mo: MasterObject] = {
revMesh: RevoluteMesh ← NARROW[mo.shadeBody];
SVSweepGeometry.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 ← SVPredefSweeps.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 ← SVPredefSweeps.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, positiveTOnly: BOOLTRUE] RETURNS [class: Classification] = {
mo: MasterObject ← prim.mo;
surfaceArray: SurfaceArray ← NARROW[mo.rayCastBody];
RETURN[SVObjectCast.ToroidCast[localRay, prim, mo.mainBody, surfaceArray[1], positiveTOnly]];
};
TorusRayCastNoBBoxes: PUBLIC PROC [localRay: Ray, sliceD: SliceDescriptor, prim: Primitive, positiveTOnly: BOOLTRUE] RETURNS [class: Classification] = {
mo: MasterObject ← prim.mo;
surfaceArray: SurfaceArray ← NARROW[mo.rayCastBody];
RETURN[SVObjectCast.ToroidCast[localRay, prim, mo.mainBody, surfaceArray[1], positiveTOnly]];
};
TorusRayCastBoundingSpheres: PUBLIC PROC [localRay: Ray, sliceD: SliceDescriptor, prim: Primitive, positiveTOnly: BOOLTRUE] RETURNS [class: Classification] = {
mo: MasterObject ← prim.mo;
surfaceArray: SurfaceArray ← NARROW[mo.rayCastBody];
RETURN[SVObjectCast.ToroidCast[localRay, prim, mo.mainBody, surfaceArray[1], positiveTOnly]];
};
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];
SVSweepGeometry.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;
SVSweepGeometry.DrawNormalsToroidalSweep[dc, torMesh, camera, localCS];
};
TorusCountSurf: PUBLIC PROC [masterObject: MasterObject] RETURNS [len: NAT] = {
torMesh: ToroidalMesh ← NARROW[masterObject.shadeBody];
len ← SVSweepGeometry.CountPlanarSurfacesToroidalSweep[torMesh];
};
TorusCountVert: PUBLIC PROC [masterObject: MasterObject] RETURNS [len: NAT] = {
torMesh: ToroidalMesh ← NARROW[masterObject.shadeBody];
len ← SVSweepGeometry.CountVerticesToroidalSweep[torMesh];
};
TorusGetSurf: PUBLIC PROC [slice: Slice, camera: CoordSystem, eyeWorld: Point3d] RETURNS [psl: PlanarSurfaceList] = {
shape: Shape ← NARROW[slice.shape];
masterObject: MasterObject ← shape.mo;
torMesh: ToroidalMesh ← NARROW[masterObject.shadeBody];
psl ← SVSweepGeometry.PlanarSurfacesToroidalSweep[torMesh, slice, camera];
};
TorusDrawSurf: PUBLIC PROC [dc: Imager.Context, ps: PlanarSurface, lightSources: LightSourceList, camera: Camera, eyeWorld: Point3d, hiddenLine: BOOL] = {
SVSweepGeometry.DrawPlanarSurfaceToroidalSweep[dc, ps, lightSources, camera, hiddenLine];
};
TorusFilein: PUBLIC PROC [f: IO.STREAM, name: Rope.ROPE, csList: CoordSysList, defaultCS: CoordSystem, wdir: Rope.ROPE, version: REAL, feedback: FeedbackData] RETURNS [mo: MasterObject] = {
bigRadius, sectionRadius: REAL;
GGParseIn.ReadWRope[f, "bigRadius:"];
bigRadius ← GGParseIn.ReadWReal[f];
GGParseIn.ReadWRope[f, ","];
GGParseIn.ReadWRope[f, "sectionRadius:"];
sectionRadius ← GGParseIn.ReadWReal[f];
mo ← TorusMakeMasterObject[name, bigRadius, sectionRadius];
};
TorusFileout: PUBLIC PROC [f: IO.STREAM, mo: MasterObject] = {
Torus can be recovered from bigRadius and sectionRadius.
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];
SVSweepGeometry.PolyListToroidal[f, torMesh];
};
Set Up the System
AppendClassToList: PROC [moc: MasterObjectClass, list: MasterObjectClassList] RETURNS [MasterObjectClassList] = {
A copy of List.Nconc1 for MasterObjectClassList instead of LIST OF REF ANY
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] = {
A copy of List.Nconc1 for MasterObjectList instead of LIST OF REF ANY
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.