File: SVMasterObjectImplA.mesa
Last edited by: Eric Bier on June 1, 1987 1:08:48 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
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;
GENERAL TYPES
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;
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 ← 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];
};
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];
};
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];
FOR j: NAT IN [1..linesOfLatitude-1] DO
ENDLOOP;
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] = {
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];
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] = {
Cylinder can be recovered from scratch.
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] = {
Cone can be recovered from scratch.
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] = {
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];
SweepGeometry.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.