- Description
- Constructor Summary
- Method Summary
- Constructor Details
- Method Details
- getComponentId()
- getNumVolumePoints()
- getVolumePoint(int)
- addVolumePoint(Point3D)
- getNumVolumeEdges()
- getVolumeEdge(int)
- addVolumeEdge(int, int)
- getVolumeShape()
- addVolumeTriangleFace(int, int, int)
- getVolumeCrossSection(Transformation3D)
- getMidpoint()
- translateXYZ(double, double, double)
- rotateX(double)
- rotateY(double)
- rotateZ(double)
- onTranslateXYZ(double, double, double)
- onRotateX(double)
- onRotateY(double)
- onRotateZ(double)
- show()
- toString()
Class AbstractComponent
- All Implemented Interfaces:
Component
,Transformable
,Showable
- Direct Known Subclasses:
ConcaveComponent
,PrismaticComponent
Component
interface to minimize the effort
required to implement a Component
.
To implement a Component
, the programmer needs only to extend this
class and provide implementations for the
Component.getType()
and
Component.getLength()
methods.
Initially, the Component
will contain no volume points, lines, or
faces and the Shape3D
will be empty, so volume points, lines, and
faces must be added to the Component
after
AbstractComponent
's constructor has been invoked via the addVolumePoint(org.jlab.geom.prim.Point3D)
,
addVolumeEdge(int, int)
, and addVolumeTriangleFace(int, int, int)
methods.
To set the midpoint, use getMidpoint()
to retrieve the point and
modify it accordingly.
If the subtyped Component
contains additional geometry data, then, to
ensure that the additional geometry is properly rotated and translated with
the Component
, the programmer must also override onTranslateXYZ(double, double, double)
,
onRotateX(double)
, onRotateY(double)
, and
onRotateZ(double)
, which are invoked after the
AbstractComponent
implementations of the
Transformable
methods are invoked.
- Author:
- jhankins
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractComponent
(int componentId) Initializes an empty AbstractComponent with the given id. -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
addVolumeEdge
(int pointIndex0, int pointIndex1) Adds an edge from the point at the first index to the point at the second.protected final void
addVolumePoint
(Point3D point) Adds points to the component's volume.protected final void
addVolumeTriangleFace
(int pointIndex0, int pointIndex1, int pointIndex2) Adds aTriangle3D
face to the volume shape such that the shape is composed of the points corresponding to the three given point indexes.final int
Returns the component's id number.final Point3D
Returns the midpoint of this component.final int
Returns the number of edges between the points that define thevolume
.final int
Returns the number of points that define thevolume
.getVolumeCrossSection
(Transformation3D transformation) Returns the cross section of a plane through the the component'svolume
as a list of lines in the xy-plane.final Line3D
getVolumeEdge
(int edgeIndex) Returns the edge on thevolume
with the specified index.final Point3D
getVolumePoint
(int pointIndex) Returns the point on thevolume
with the specified index.final Shape3D
Returns the volume of the component.protected void
onRotateX
(double angle) Classes extending AbstractComponent should implement onRotateX so that any additional geometric data they contain is rotated appropriately when AbstractComponent's rotateX method is invoke.protected void
onRotateY
(double angle) Classes extending AbstractComponent should implement onRotateY so that any additional geometric data they contain is rotated appropriately when AbstractComponent's rotateY method is invoke.protected void
onRotateZ
(double angle) Classes extending AbstractComponent should implement onRotateZ so that any additional geometric data they contain is rotated appropriately when AbstractComponent's rotateZ method is invoke.protected void
onTranslateXYZ
(double dx, double dy, double dz) Classes extending AbstractComponent should implement onTranslateXYZ so that any additional geometric data they contain is translated appropriately when AbstractComponent's translateXYZ method is invoked.final void
rotateX
(double angle) Rotates this object clockwise around the x axis.final void
rotateY
(double angle) Rotates this object clockwise around the y axis.final void
rotateZ
(double angle) Rotates this object clockwise around the z axis.void
show()
InvokesSystem.out.println(this)
.toString()
final void
translateXYZ
(double dx, double dy, double dz) Translates this object linearly by the amounts specified.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.jlab.geom.base.Component
getLength, getType, getVolumeIntersection
-
Constructor Details
-
Method Details
-
getComponentId
public final int getComponentId()Description copied from interface:Component
Returns the component's id number.- Specified by:
getComponentId
in interfaceComponent
- Returns:
- the id
-
getNumVolumePoints
public final int getNumVolumePoints()Description copied from interface:Component
Returns the number of points that define thevolume
.- Specified by:
getNumVolumePoints
in interfaceComponent
- Returns:
- the number of volume points
-
getVolumePoint
Description copied from interface:Component
Returns the point on thevolume
with the specified index.- Specified by:
getVolumePoint
in interfaceComponent
- Parameters:
pointIndex
- the index of the point- Returns:
- the point on the volume
-
addVolumePoint
Adds points to the component's volume.Intended for use by constructors of classes extending AbstractComponent.
- Parameters:
point
- the point to add- See Also:
-
getNumVolumeEdges
public final int getNumVolumeEdges()Description copied from interface:Component
Returns the number of edges between the points that define thevolume
.- Specified by:
getNumVolumeEdges
in interfaceComponent
- Returns:
- the number of volume edges
-
getVolumeEdge
Description copied from interface:Component
Returns the edge on thevolume
with the specified index.Though edges are returned as
Line3D
objects and a majority components have edges which are all straight line segments, edges are not required to be straight lines. The edge may, in reality, be curved, in which case the returnedLine3D
is merely storing the two points bounding a curved path segment. Thus, special care must be taken to ensure that the edge is in fact a straight line segment if one intends to use it as such.- Specified by:
getVolumeEdge
in interfaceComponent
- Parameters:
edgeIndex
- the index of the edge- Returns:
- the edge on the volume
-
addVolumeEdge
protected final void addVolumeEdge(int pointIndex0, int pointIndex1) Adds an edge from the point at the first index to the point at the second.Intended for use by constructors of classes extending AbstractComponent.
- Parameters:
pointIndex0
- the first point indexpointIndex1
- the second point index- See Also:
-
getVolumeShape
Description copied from interface:Component
Returns the volume of the component.A volume is represented by a
Shape3D
object which contains a list of triangularFace3D
objects. This these triangles bound a closed closed volume.- Specified by:
getVolumeShape
in interfaceComponent
- Returns:
- the volume
-
addVolumeTriangleFace
protected final void addVolumeTriangleFace(int pointIndex0, int pointIndex1, int pointIndex2) Adds aTriangle3D
face to the volume shape such that the shape is composed of the points corresponding to the three given point indexes.Intended for use by constructors of classes extending AbstractComponent.
Though not required, by convention the points defining a face should be given in counterclockwise order from th perspective of an observer outside the volume. This allows 3D-rendering applications to use back-face culling to increase performance.
- Parameters:
pointIndex0
- the first point indexpointIndex1
- the second point indexpointIndex2
- the third point index- See Also:
-
getVolumeCrossSection
Description copied from interface:Component
Returns the cross section of a plane through the the component'svolume
as a list of lines in the xy-plane.This method takes a Transformation3D object as an argument, then constructs a new
Plane3D
object in the xy-plane and applies the transformation to the plane. The intersection of the volume's shape with the transformed plane is then calculated and stored in a list of lines. The inverse of the transformation is then applied to each line in the list ensuring that each line in the returned list is in the xy-plane.- Specified by:
getVolumeCrossSection
in interfaceComponent
- Parameters:
transformation
- the transformation to apply to the plane- Returns:
- a list of lines in the xy-plane representing the cross section
-
getMidpoint
Description copied from interface:Component
Returns the midpoint of this component. By convention, the midpoint of a component is normally the geometric center of the component's volume but the definition of midpoint may vary by component type.- Specified by:
getMidpoint
in interfaceComponent
- Returns:
- the midpoint
-
translateXYZ
public final void translateXYZ(double dx, double dy, double dz) Description copied from interface:Transformable
Translates this object linearly by the amounts specified.- Specified by:
translateXYZ
in interfaceTransformable
- Parameters:
dx
- amount to translate along the x axisdy
- amount to translate along the y axisdz
- amount to translate along the z axis
-
rotateX
public final void rotateX(double angle) Description copied from interface:Transformable
Rotates this object clockwise around the x axis.- Specified by:
rotateX
in interfaceTransformable
- Parameters:
angle
- rotation angle in radians
-
rotateY
public final void rotateY(double angle) Description copied from interface:Transformable
Rotates this object clockwise around the y axis.- Specified by:
rotateY
in interfaceTransformable
- Parameters:
angle
- rotation angle in radians
-
rotateZ
public final void rotateZ(double angle) Description copied from interface:Transformable
Rotates this object clockwise around the z axis.- Specified by:
rotateZ
in interfaceTransformable
- Parameters:
angle
- rotation angle in radians
-
onTranslateXYZ
protected void onTranslateXYZ(double dx, double dy, double dz) Classes extending AbstractComponent should implement onTranslateXYZ so that any additional geometric data they contain is translated appropriately when AbstractComponent's translateXYZ method is invoked. This method is called at the end of AbstractComponent's translateXYZ method.- Parameters:
dx
- amount to translate along the x axisdy
- amount to translate along the y axisdz
- amount to translate along the z axis- See Also:
-
onRotateX
protected void onRotateX(double angle) Classes extending AbstractComponent should implement onRotateX so that any additional geometric data they contain is rotated appropriately when AbstractComponent's rotateX method is invoke. This method is called at the end of AbstractComponent's rotateX method.- Parameters:
angle
- rotation angle in radians- See Also:
-
onRotateY
protected void onRotateY(double angle) Classes extending AbstractComponent should implement onRotateY so that any additional geometric data they contain is rotated appropriately when AbstractComponent's rotateY method is invoke. This method is called at the end of AbstractComponent's rotateY method.- Parameters:
angle
- rotation angle in radians- See Also:
-
onRotateZ
protected void onRotateZ(double angle) Classes extending AbstractComponent should implement onRotateZ so that any additional geometric data they contain is rotated appropriately when AbstractComponent's rotateZ method is invoke. This method is called at the end of AbstractComponent's rotateZ method.- Parameters:
angle
- rotation angle in radians- See Also:
-
show
-
toString
-