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
ConstructorsModifierConstructorDescriptionprotectedAbstractComponent(int componentId) Initializes an empty AbstractComponent with the given id. -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidaddVolumeEdge(int pointIndex0, int pointIndex1) Adds an edge from the point at the first index to the point at the second.protected final voidaddVolumePoint(Point3D point) Adds points to the component's volume.protected final voidaddVolumeTriangleFace(int pointIndex0, int pointIndex1, int pointIndex2) Adds aTriangle3Dface to the volume shape such that the shape is composed of the points corresponding to the three given point indexes.final intReturns the component's id number.final Point3DReturns the midpoint of this component.final intReturns the number of edges between the points that define thevolume.final intReturns the number of points that define thevolume.getVolumeCrossSection(Transformation3D transformation) Returns the cross section of a plane through the the component'svolumeas a list of lines in the xy-plane.final Line3DgetVolumeEdge(int edgeIndex) Returns the edge on thevolumewith the specified index.final Point3DgetVolumePoint(int pointIndex) Returns the point on thevolumewith the specified index.final Shape3DReturns the volume of the component.protected voidonRotateX(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 voidonRotateY(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 voidonRotateZ(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 voidonTranslateXYZ(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 voidrotateX(double angle) Rotates this object clockwise around the x axis.final voidrotateY(double angle) Rotates this object clockwise around the y axis.final voidrotateZ(double angle) Rotates this object clockwise around the z axis.voidshow()InvokesSystem.out.println(this).toString()final voidtranslateXYZ(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, waitMethods inherited from interface org.jlab.geom.base.Component
getLength, getType, getVolumeIntersection
-
Constructor Details
-
AbstractComponent
protected AbstractComponent(int componentId) Initializes an empty AbstractComponent with the given id.- Parameters:
componentId- the id of this component
-
-
Method Details
-
getComponentId
public final int getComponentId()Description copied from interface:ComponentReturns the component's id number.- Specified by:
getComponentIdin interfaceComponent- Returns:
- the id
-
getNumVolumePoints
public final int getNumVolumePoints()Description copied from interface:ComponentReturns the number of points that define thevolume.- Specified by:
getNumVolumePointsin interfaceComponent- Returns:
- the number of volume points
-
getVolumePoint
Description copied from interface:ComponentReturns the point on thevolumewith the specified index.- Specified by:
getVolumePointin 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:ComponentReturns the number of edges between the points that define thevolume.- Specified by:
getNumVolumeEdgesin interfaceComponent- Returns:
- the number of volume edges
-
getVolumeEdge
Description copied from interface:ComponentReturns the edge on thevolumewith the specified index.Though edges are returned as
Line3Dobjects 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 returnedLine3Dis 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:
getVolumeEdgein 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:ComponentReturns the volume of the component.A volume is represented by a
Shape3Dobject which contains a list of triangularFace3Dobjects. This these triangles bound a closed closed volume.- Specified by:
getVolumeShapein interfaceComponent- Returns:
- the volume
-
addVolumeTriangleFace
protected final void addVolumeTriangleFace(int pointIndex0, int pointIndex1, int pointIndex2) Adds aTriangle3Dface 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:ComponentReturns the cross section of a plane through the the component'svolumeas a list of lines in the xy-plane.This method takes a Transformation3D object as an argument, then constructs a new
Plane3Dobject 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:
getVolumeCrossSectionin 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:ComponentReturns 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:
getMidpointin interfaceComponent- Returns:
- the midpoint
-
translateXYZ
public final void translateXYZ(double dx, double dy, double dz) Description copied from interface:TransformableTranslates this object linearly by the amounts specified.- Specified by:
translateXYZin 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:TransformableRotates this object clockwise around the x axis.- Specified by:
rotateXin interfaceTransformable- Parameters:
angle- rotation angle in radians
-
rotateY
public final void rotateY(double angle) Description copied from interface:TransformableRotates this object clockwise around the y axis.- Specified by:
rotateYin interfaceTransformable- Parameters:
angle- rotation angle in radians
-
rotateZ
public final void rotateZ(double angle) Description copied from interface:TransformableRotates this object clockwise around the z axis.- Specified by:
rotateZin 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
public void show()Description copied from interface:ComponentInvokesSystem.out.println(this). -
toString
-