org.proteinshader.structure
Class Drawable

java.lang.Object
  extended by org.proteinshader.structure.Drawable
All Implemented Interfaces:
Visitable
Direct Known Subclasses:
Atom, Bond, Segment

public abstract class Drawable
extends Object
implements Visitable

This abstract class defines attributes and methods that are shared by all drawable objects, including the xyz-coordinates for the Drawable's center and methods that will allow each object to be sorted based on distance from the camera.

Known subclasses are Atom, Bond, and Region (Helix and BetaStrand).


Field Summary
static float DEFAULT_ALPHA
          The default value for alpha is 0.0.
static float DEFAULT_BLUE
          The default value for blue is 0.0.
static float DEFAULT_GREEN
          The default value for green is 0.0.
static double DEFAULT_RADIUS
          The default radius is 1.0.
static float DEFAULT_RED
          The default value for red is 0.0.
static float DEFAULT_SPECULAR_EXP
          The default value for the specular exponent is 20.0.
 
Constructor Summary
Drawable(double x, double y, double z, VisibilityEnum visibility, DrawableEnum drawableType)
          Constructor for use by subclasses.
Drawable(double x, double y, double z, VisibilityEnum visibility, DrawableEnum drawableType, float red, float green, float blue, float alpha)
          Constructor for use by subclasses.
 
Method Summary
abstract  void accept(Visitor visitor)
          Accepts a Visitor and does a callback.
 double distance(Drawable other)
          Returns the distance in angstroms between the xyz-center of the calling Drawable object and the xyz-center of the Drawable object given as an argument.
 float getAlpha()
          Returns the alpha component of the RGBA color.
 double getAngstromsPerPixel()
          Returns the angstrom per pixel conversion factor, which is expected to be set by the Camera class after the object to camera distance has been calculated.
 float getBlue()
          Returns the blue component of the RGBA color.
 double getCameraDepth()
          Returns the camera depth (z-coordinate in camera space).
 double getCameraDistance()
          Returns the camera distance (based on xyz-coordinates in camera space).
 float[] getColor()
          Returns a copy of the RGBA color as an array.
 DrawableEnum getDrawableType()
          Returns the Drawable type (ATOM, BOND, HELIX, or BETA_STRAND).
 float getGreen()
          Returns the green component of the RGBA color.
 Point3d getPoint()
          Returns the xyz-center of the Drawable as a point.
 double getRadius()
          Returns the radius.
 float getRed()
          Returns the red component of the RGBA color.
 float getSpecularExp()
          Returns the specular exponent for use in lighting calculations.
 Vec3d getTranslation()
          Returns the xyz-center of the Drawable as a vector.
 VisibilityEnum getVisibility()
          Returns the visibility status of the Drawable object.
 double getX()
          Returns the x-coordinate of the Drawable's center.
 double getY()
          Returns the y-coordinate of the Drawable's center.
 double getZ()
          Returns the z-coordinate of the Drawable's center.
 Vec3d minus(Drawable other)
          Returns a vector created by subtracting the xyz-center of the Drawable given as an argument from the xyz-center of the calling Drawable object.
 void scaleRadius(double scaleFactor)
          Multiplies the default radius by the scale factor given as an argument.
 void setAlpha(float alpha)
          Sets the alpha component of the RGBA color.
 void setAlphaToDefault()
          Sets the alpha component of the RGBA color to DEFAULT_ALPHA.
 void setAngstromsPerPixel(double angstromsPerPixel)
          The Camera class should use this method to set a conversion factor that will allow an x or y axis distance in viewport pixels be converted to an x or y distance in world coordinates (angstroms) at the current object to camera distance.
 void setCameraDepth(double cameraDepth)
          The camera class should use this method to set a memory of the camera depth (z-coordinate of Drawable object in camera space).
 void setCameraDistance(double cameraDistance)
          The camera class should use this method to set a memory of the distance between the xyz-center of this object and the camera.
 void setColor(float[] color)
          Sets the RGBA color by copying the values from the color array given as an argument.
 void setColor(float red, float green, float blue)
          Sets the (red, green, blue) components of the RGBA color.
 void setColor(float red, float green, float blue, float alpha)
          Sets the (red, green, blue, alpha ) components of the RGBA color.
 void setRadius(double radius)
          Sets the radius.
 void setRadiusToDefault()
          Sets the radius to DEFAULT_RADIUS.
 void setRGBAToDefault()
          Sets the color by calling on setRGBToDefault() and setAlphaToDefault().
 void setRGBToDefault()
          Sets the (red, green, blue) components of the color to DEFAULT_RED, DEFAULT_GREEN, and DEFAULT_BLUE, respectively.
 void setSpecularExp(float specularExp)
          Sets the specular exponent to be used in lighting calculations.
 void setSpecularExpToDefault()
          Sets the specular exponent to the default value, DEFAULT_SPECULAR_EXP.
 void setVisibility(VisibilityEnum visibility)
          Sets the visibility status of the Drawable object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_RED

public static final float DEFAULT_RED
The default value for red is 0.0.

See Also:
Constant Field Values

DEFAULT_GREEN

public static final float DEFAULT_GREEN
The default value for green is 0.0.

See Also:
Constant Field Values

DEFAULT_BLUE

public static final float DEFAULT_BLUE
The default value for blue is 0.0.

See Also:
Constant Field Values

DEFAULT_ALPHA

public static final float DEFAULT_ALPHA
The default value for alpha is 0.0.

See Also:
Constant Field Values

DEFAULT_SPECULAR_EXP

public static final float DEFAULT_SPECULAR_EXP
The default value for the specular exponent is 20.0.

See Also:
Constant Field Values

DEFAULT_RADIUS

public static final double DEFAULT_RADIUS
The default radius is 1.0.

See Also:
Constant Field Values
Constructor Detail

Drawable

public Drawable(double x,
                double y,
                double z,
                VisibilityEnum visibility,
                DrawableEnum drawableType)
Constructor for use by subclasses. The xyz-coordinates have to be set by the constructor because they are read-only attributes.

The color values are initialized to DEFAULT_RED, DEFAULT_GREEN, DEFAULT_BLUE, and DEFAULT_ALPHA, and the radius is initialized to DEFAULT_RADIUS. In most cases, the constructor of a concrete subclass should probably reset these values to something more meaningful.

The depth attribute is somewhat arbitrarily set to 0.0, and needs to be determined later with the calculateDepth() method, which is explained further below.

Parameters:
x - coordinate of the Drawable's center.
y - coordinate of the Drawable's center.
z - coordinate of the Drawable's center.
visibility - visiblity status (OPAQUE, TRANSLUCENT, or INVISIBLE)
drawableType - drawable type (ATOM, BOND, HELIX, or BETASTRAND)

Drawable

public Drawable(double x,
                double y,
                double z,
                VisibilityEnum visibility,
                DrawableEnum drawableType,
                float red,
                float green,
                float blue,
                float alpha)
         throws ColorOutOfRangeException
Constructor for use by subclasses. The xyz-coordinates have to be set by the constructor because they are read-only attributes.

The values for red, green, blue, and alpha must be between 0.0 and 1.0, inclusive, or a ColorOutOfRangeException will be thrown.

The depth attribute is set to 0.0, and the radius is set to DEFAULT_RADIUS.

Parameters:
x - coordinate of the Drawable's center.
y - coordinate of the Drawable's center.
z - coordinate of the Drawable's center.
visibility - visiblity status (OPAQUE, TRANSLUCENT, or INVISIBLE)
drawableType - drawable type (ATOM, BOND, HELIX, BETASTRAND)
red - component of RGBA color
green - component of RGBA color
blue - component of RGBA color
alpha - component of RGBA color
Throws:
ColorOutOfRangeException - if a color value is less than 0.0 or greater than 1.0.
Method Detail

accept

public abstract void accept(Visitor visitor)
                     throws VisitorException
Accepts a Visitor and does a callback.

Specified by:
accept in interface Visitable
Parameters:
visitor - the Visitor to do a callback with.
Throws:
VisitorException - if an error occurs while an object is being visited.

setCameraDistance

public void setCameraDistance(double cameraDistance)
The camera class should use this method to set a memory of the distance between the xyz-center of this object and the camera.

Parameters:
cameraDistance - the distance to the camera in angstroms.

getCameraDistance

public double getCameraDistance()
Returns the camera distance (based on xyz-coordinates in camera space).

Returns:
The camera distance as a double.

setCameraDepth

public void setCameraDepth(double cameraDepth)
The camera class should use this method to set a memory of the camera depth (z-coordinate of Drawable object in camera space).

Parameters:
cameraDepth - the depth in angstroms.

getCameraDepth

public double getCameraDepth()
Returns the camera depth (z-coordinate in camera space).

Returns:
The camera depth in angstroms.

setAngstromsPerPixel

public void setAngstromsPerPixel(double angstromsPerPixel)
The Camera class should use this method to set a conversion factor that will allow an x or y axis distance in viewport pixels be converted to an x or y distance in world coordinates (angstroms) at the current object to camera distance. This conversion factor may be needed for using the glTranslate() method to jitter a translucent black silhouette of a Drawable object as a way of antialiasing (smoothing out) object edges.

Parameters:
angstromsPerPixel - the angstroms per pixel conversion factor.

getAngstromsPerPixel

public double getAngstromsPerPixel()
Returns the angstrom per pixel conversion factor, which is expected to be set by the Camera class after the object to camera distance has been calculated.

Returns:
An angstroms per pixel conversion factor.

getX

public double getX()
Returns the x-coordinate of the Drawable's center.

Returns:
The x-coordinate as a double.

getY

public double getY()
Returns the y-coordinate of the Drawable's center.

Returns:
The y-coordinate as a double.

getZ

public double getZ()
Returns the z-coordinate of the Drawable's center.

Returns:
The z-coordinate as a double.

getVisibility

public VisibilityEnum getVisibility()
Returns the visibility status of the Drawable object.

Returns:
The visibility as an enum.

getDrawableType

public DrawableEnum getDrawableType()
Returns the Drawable type (ATOM, BOND, HELIX, or BETA_STRAND).

Returns:
The Drawable type as an enum.

getColor

public float[] getColor()
Returns a copy of the RGBA color as an array. The array to be returned is a newly created copy of the RGBA values, so changes to the array will not in any way affect the values held by the Drawable object.

Returns:
An array of floats with the RGBA color.

getRed

public float getRed()
Returns the red component of the RGBA color.

Returns:
The red value as a float.

getGreen

public float getGreen()
Returns the green component of the RGBA color.

Returns:
The green value as a float.

getBlue

public float getBlue()
Returns the blue component of the RGBA color.

Returns:
The blue value as a float.

getAlpha

public float getAlpha()
Returns the alpha component of the RGBA color.

Returns:
The alpha value as a float.

getSpecularExp

public float getSpecularExp()
Returns the specular exponent for use in lighting calculations.

Returns:
The specular exponent as a float.

getRadius

public double getRadius()
Returns the radius. This value should be useful for most concrete subclasses of Drawable.

Returns:
The radius as a double.

setVisibility

public void setVisibility(VisibilityEnum visibility)
Sets the visibility status of the Drawable object.

Parameters:
visibility - the visibility as an enum.

setColor

public void setColor(float red,
                     float green,
                     float blue,
                     float alpha)
              throws ColorOutOfRangeException
Sets the (red, green, blue, alpha ) components of the RGBA color.

Parameters:
red - component of the RGBA color.
green - component of the RGBA color.
blue - component of the RGBA color.
alpha - component of the RGBA color.
Throws:
ColorOutOfRangeException - if a color value is less than 0.0 or greater than 1.0.

setColor

public void setColor(float red,
                     float green,
                     float blue)
              throws ColorOutOfRangeException
Sets the (red, green, blue) components of the RGBA color.

Parameters:
red - component of the RGBA color.
green - component of the RGBA color.
blue - component of the RGBA color.
Throws:
ColorOutOfRangeException - if a color value is less than 0.0 or greater than 1.0.

setAlpha

public void setAlpha(float alpha)
              throws ColorOutOfRangeException
Sets the alpha component of the RGBA color. The value must be between 0.0 and 1.0, inclusive.

Parameters:
alpha - component of the RGBA color.
Throws:
ColorOutOfRangeException - if alpha is less than 0.0 or greater than 1.0.

setColor

public void setColor(float[] color)
              throws ColorOutOfRangeException
Sets the RGBA color by copying the values from the color array given as an argument. If the array has 4 values, then it is used to set red, green, blue, and alpha. If the array has only 3 values, alpha will be set to the default of 1.0. If the array has less than 3 values, an IllegalArgumentException (a runtime exception) is thrown. A ColorOutOfRangeException (a checked exception) is thrown if a red, green, blue, or alpha value is outside the range of 0.0 to 1.0, inclusive.

Parameters:
color - an array of floats with the RGBA color.
Throws:
ColorOutOfRangeException - if a value is less than 0.0 or more than 1.0.
IllegalArgumentException - if the color array has a length less than 3.

setRGBAToDefault

public void setRGBAToDefault()
Sets the color by calling on setRGBToDefault() and setAlphaToDefault(). To override in a subclass, only the helper methods need to be overridden.


setRGBToDefault

public void setRGBToDefault()
Sets the (red, green, blue) components of the color to DEFAULT_RED, DEFAULT_GREEN, and DEFAULT_BLUE, respectively. Where possible, subclasses should override this method to provide a more meaningful default color based on something such as AtomEnum type or BondEnum type. The default color values must always be in the range of 0.0 to 1.0, inclusive.


setAlphaToDefault

public void setAlphaToDefault()
Sets the alpha component of the RGBA color to DEFAULT_ALPHA. If this method is overriden in a subclass, the default alpha value must always be in the range of 0.0 to 1.0, inclusive.


setSpecularExp

public void setSpecularExp(float specularExp)
Sets the specular exponent to be used in lighting calculations. A value somewhere in the range of 1 to 200 usually works best.

Parameters:
specularExp - the specular exponent for Phong lighting calculations.

setSpecularExpToDefault

public void setSpecularExpToDefault()
Sets the specular exponent to the default value, DEFAULT_SPECULAR_EXP.


scaleRadius

public void scaleRadius(double scaleFactor)
Multiplies the default radius by the scale factor given as an argument. If the scale factor is 0 or less, the radius is left unchanged.

Parameters:
scaleFactor - the scale factor to multiply the default radius by.

setRadius

public void setRadius(double radius)
Sets the radius. This value should be useful for most concrete subclasses of Drawable.

Parameters:
radius - the radius as a double.

setRadiusToDefault

public void setRadiusToDefault()
Sets the radius to DEFAULT_RADIUS. Where possible, subclasses should override this method to provide a more meaningful default radius such as an Atom or Bond radius based on AtomEnum type or BondEnum type,respectively.


distance

public double distance(Drawable other)
Returns the distance in angstroms between the xyz-center of the calling Drawable object and the xyz-center of the Drawable object given as an argument.

Parameters:
other - the Drawable to measure the distance from.
Returns:
The distance between the calling and argument Drawable objects.

minus

public Vec3d minus(Drawable other)
Returns a vector created by subtracting the xyz-center of the Drawable given as an argument from the xyz-center of the calling Drawable object.

Parameters:
other - the other Drawable object.
Returns:
A direction vector with its tail at the Drawable given as an argument and its point at the calling Drawable.

getPoint

public Point3d getPoint()
Returns the xyz-center of the Drawable as a point.

The xyz-values are copied into a new Point3d object (and a reference to the Point3d object is not kept).

Returns:
The xyz-center as a point.

getTranslation

public Vec3d getTranslation()
Returns the xyz-center of the Drawable as a vector.

The xyz-values are copied into a new Vec3d object (and a reference to the Vec3d object is not kept).

Returns:
The xyz-center as a vector with its tail at the origin and its point at the xyz-center of this Drawable object.


Copyright © 2007-2008