Class AbstractComponent

java.lang.Object
org.jlab.geom.abs.AbstractComponent
All Implemented Interfaces:
Component, Transformable, Showable
Direct Known Subclasses:
ConcaveComponent, PrismaticComponent

public abstract class AbstractComponent extends Object implements Component
This class provides a skeletal implementation of the 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 Link icon

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractComponent(int componentId)
    Initializes an empty AbstractComponent with the given id.
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    protected 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
    Adds points to the component's volume.
    protected final void
    addVolumeTriangleFace(int pointIndex0, int pointIndex1, int pointIndex2)
    Adds a Triangle3D 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 the volume.
    final int
    Returns the number of points that define the volume.
    Returns the cross section of a plane through the the component's volume as a list of lines in the xy-plane.
    final Line3D
    getVolumeEdge(int edgeIndex)
    Returns the edge on the volume with the specified index.
    final Point3D
    getVolumePoint(int pointIndex)
    Returns the point on the volume 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
    Invokes System.out.println(this).
     
    final void
    translateXYZ(double dx, double dy, double dz)
    Translates this object linearly by the amounts specified.

    Methods inherited from class java.lang.Object Link icon

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.jlab.geom.base.Component Link icon

    getLength, getType, getVolumeIntersection
  • Constructor Details Link icon

    • AbstractComponent Link icon

      protected AbstractComponent(int componentId)
      Initializes an empty AbstractComponent with the given id.
      Parameters:
      componentId - the id of this component
  • Method Details Link icon

    • getComponentId Link icon

      public final int getComponentId()
      Description copied from interface: Component
      Returns the component's id number.
      Specified by:
      getComponentId in interface Component
      Returns:
      the id
    • getNumVolumePoints Link icon

      public final int getNumVolumePoints()
      Description copied from interface: Component
      Returns the number of points that define the volume.
      Specified by:
      getNumVolumePoints in interface Component
      Returns:
      the number of volume points
    • getVolumePoint Link icon

      public final Point3D getVolumePoint(int pointIndex)
      Description copied from interface: Component
      Returns the point on the volume with the specified index.
      Specified by:
      getVolumePoint in interface Component
      Parameters:
      pointIndex - the index of the point
      Returns:
      the point on the volume
    • addVolumePoint Link icon

      protected final void addVolumePoint(Point3D point)
      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 Link icon

      public final int getNumVolumeEdges()
      Description copied from interface: Component
      Returns the number of edges between the points that define the volume.
      Specified by:
      getNumVolumeEdges in interface Component
      Returns:
      the number of volume edges
    • getVolumeEdge Link icon

      public final Line3D getVolumeEdge(int edgeIndex)
      Description copied from interface: Component
      Returns the edge on the volume 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 returned Line3D 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 interface Component
      Parameters:
      edgeIndex - the index of the edge
      Returns:
      the edge on the volume
    • addVolumeEdge Link icon

      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 index
      pointIndex1 - the second point index
      See Also:
    • getVolumeShape Link icon

      public final Shape3D 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 triangular Face3D objects. This these triangles bound a closed closed volume.

      Specified by:
      getVolumeShape in interface Component
      Returns:
      the volume
    • addVolumeTriangleFace Link icon

      protected final void addVolumeTriangleFace(int pointIndex0, int pointIndex1, int pointIndex2)
      Adds a Triangle3D 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 index
      pointIndex1 - the second point index
      pointIndex2 - the third point index
      See Also:
    • getVolumeCrossSection Link icon

      public List<Line3D> getVolumeCrossSection(Transformation3D transformation)
      Description copied from interface: Component
      Returns the cross section of a plane through the the component's volume 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 interface Component
      Parameters:
      transformation - the transformation to apply to the plane
      Returns:
      a list of lines in the xy-plane representing the cross section
    • getMidpoint Link icon

      public final Point3D 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 interface Component
      Returns:
      the midpoint
    • translateXYZ Link icon

      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 interface Transformable
      Parameters:
      dx - amount to translate along the x axis
      dy - amount to translate along the y axis
      dz - amount to translate along the z axis
    • rotateX Link icon

      public final void rotateX(double angle)
      Description copied from interface: Transformable
      Rotates this object clockwise around the x axis.
      Specified by:
      rotateX in interface Transformable
      Parameters:
      angle - rotation angle in radians
    • rotateY Link icon

      public final void rotateY(double angle)
      Description copied from interface: Transformable
      Rotates this object clockwise around the y axis.
      Specified by:
      rotateY in interface Transformable
      Parameters:
      angle - rotation angle in radians
    • rotateZ Link icon

      public final void rotateZ(double angle)
      Description copied from interface: Transformable
      Rotates this object clockwise around the z axis.
      Specified by:
      rotateZ in interface Transformable
      Parameters:
      angle - rotation angle in radians
    • onTranslateXYZ Link icon

      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 axis
      dy - amount to translate along the y axis
      dz - amount to translate along the z axis
      See Also:
    • onRotateX Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      public void show()
      Description copied from interface: Component
      Invokes System.out.println(this).
      Specified by:
      show in interface Component
      Specified by:
      show in interface Showable
    • toString Link icon

      public String toString()
      Overrides:
      toString in class Object