Class Curveline

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----Curveline

class Curveline
extends Canvas
implements MouseListener, MouseMotionListener
The Curveline class is the canvas upon which the curve functions are drawn. This class contains numerous functions, including a Bezier algorithm and a B-Spline algorithm for parametric analysis of a 2D CAD curve. The same polygon control frame is used throughout. The user can modify the frame with a mouse grab and drag technique. The user can see immediately the affect of a control point movement on the shape of the curved line. Additionally, the user has the option to reset the polygon control frame to it's original values. Note: The mathmatical functions used in this program came from the text "Curves and Surfaces for CAGD" by Gerald Farin, c.1993, Academic Press, San Diego, CA. See the blossom technique for developing a Bezier Curve by subdivision. See Farin, pg. 51-53 for routine, and fig 3.1 on pg. 30 for an intuitive description of what is actually happening... Note: This first exercise in Java for the writer was not written with strict reuse in mind. To enable speed in development, many of the routines, which should be written as independent classes for reuse, are instead highly integrated within other classes. (How do you pass an array to another class within Java, anyway?) Additional info: This class was originally designed as private, but made public in the interest of the JavaDoc exercise.


Variable Index

 o CursorGrabSize
 o CurveColorDefault
 o CurveColorTemp
 o Debug
 o DragIndex
 o FrameColorDefault
 o FrameColorTemp
 o FrameControlPt
 o Knot
 o LineType
 o N
 o NumberOfControlPoints
 o NumberOfDots
 o Weight
 o WhichKnot
 o WhichWeight
 o Xtemp
 o Ytemp

Constructor Index

 o Curveline(String)
This sets up different variables required by the canvas sketch system

Method Index

 o bezierCalculate(Graphics)
This routine plots out a bezier curve, with multiple calls to hornbez()
 o BSplineCalculate(Graphics)
This routine does a uniform B-Spline evaluation.
 o deboor(int, int, float, int)
This routine taken from Gerald Farin, Curves and Surfaces for CAGD; This routine uses de Boor algorithm to compute one coordinate on B-spline curve for param.
 o drawBigPoint(Graphics, int, int)
This routine draws each curve 'dot' (highly visible).
 o drawBigPointDottedLine(Graphics, int, int, int, int, int)
This routine draws a dotted line between two points, using a large dot.
 o drawCursor(Graphics, int, int)
Draw a large cursor (an X plus a small circle)
 o drawDottedLine(Graphics, int, int, int, int, int)
This routine draws a dotted line between two points, using a small dot.
 o drawEllipseSegment(Graphics, int, int, int, int, int)
This routine draws a simple elliptical 1/4 segment.
 o drawPoint(Graphics, int, int)
This routine draws a small dot (one pixel!)
 o hornbez(int, int, float)
This routine uses Horner's scheme to compute one coordinate value of a Bezier curve.
 o initializeFrame()
Initialize and reset the original values of the control frame and of the curve line knot sequence.
 o mouseClicked(MouseEvent)
 o mouseDragged(MouseEvent)
This routine drags the cursor across the workspace.
 o mouseEntered(MouseEvent)
 o mouseExited(MouseEvent)
 o mouseMoved(MouseEvent)
 o mousePressed(MouseEvent)
This routine allows the user to 'grab' a polygon control vertice and drag it across the screen.
 o mouseReleased(MouseEvent)
 o paint(Graphics)
Paint and rePaint the screen with the control frame and with the 2D curves! As there are different curves shown with this class, there are numerous parametric tests to member variable "LineType".

Variables

 o FrameControlPt
 int FrameControlPt[][]
 o N
 int N
 o Knot
 float Knot[][]
 o WhichKnot
 int WhichKnot
 o Weight
 float Weight[][]
 o WhichWeight
 int WhichWeight
 o Xtemp
 int Xtemp
 o Ytemp
 int Ytemp
 o NumberOfControlPoints
 int NumberOfControlPoints
 o DragIndex
 int DragIndex
 o NumberOfDots
 int NumberOfDots
 o CursorGrabSize
 int CursorGrabSize
 o Debug
 boolean Debug
 o FrameColorDefault
 Color FrameColorDefault
 o FrameColorTemp
 Color FrameColorTemp
 o CurveColorDefault
 Color CurveColorDefault
 o CurveColorTemp
 Color CurveColorTemp
 o LineType
 String LineType

Constructors

 o Curveline
 public Curveline(String lt)
This sets up different variables required by the canvas sketch system

Methods

 o initializeFrame
 public void initializeFrame()
Initialize and reset the original values of the control frame and of the curve line knot sequence.

 o paint
 public void paint(Graphics g)
Paint and rePaint the screen with the control frame and with the 2D curves! As there are different curves shown with this class, there are numerous parametric tests to member variable "LineType".

Overrides:
paint in class Canvas
 o BSplineCalculate
 public void BSplineCalculate(Graphics g)
This routine does a uniform B-Spline evaluation. It looks closely at the order and control information and thru nested for loops, determines both X and Y coordinates for each point on the 2D curve of choice. This routine makes numerous calls to the routine deboor. The 2D curved line of interest is plotted directly from this routine.

 o deboor
 public float deboor(int degree,
                     int xORy,
                     float u,
                     int i)
This routine taken from Gerald Farin, Curves and Surfaces for CAGD; This routine uses de Boor algorithm to compute one coordinate on B-spline curve for param. value u in interval i. input: degree: polynomial degree of each piece of curve coeff: B-spline control points knot: knot sequence u: evaluation abscissa i: u's interval: u[i]<= u < u[i+1] output: coordinate value. for use of Farin's algorithm DeBoor algorithm, see bspl_to_points.c file... See also sketch in Farin, pg. 166

 o bezierCalculate
 public void bezierCalculate(Graphics g)
This routine plots out a bezier curve, with multiple calls to hornbez()

 o hornbez
 public float hornbez(int degree,
                      int xORy,
                      float t)
This routine uses Horner's scheme to compute one coordinate value of a Bezier curve. Has to be called for each coordinate (x,y, and/or z) of a control polygon. See Farin, pg 59,60. Note: This technique is also called "nested multiplication". Input: degree: degree of curve. coeff: array with coefficients of curve. t: parameter value. Output: coordinate value.

 o drawEllipseSegment
 public void drawEllipseSegment(Graphics tempGraphics,
                                int x1,
                                int y1,
                                int x2,
                                int y2,
                                int numOfDots)
This routine draws a simple elliptical 1/4 segment. It is a little different in that the control polygon defines the 1/4 segment endpoints instead of Ellipse center point and outer frame corner. This routine can be called four times to create a complete ellipse or circle.

 o mousePressed
 public void mousePressed(MouseEvent me)
This routine allows the user to 'grab' a polygon control vertice and drag it across the screen. The grab looks at each control point in an array and asks the question, 'Is this point within a certain distance from the initial mouse button press cursor? The window is fairly small. The loop routine (and breakout) allows for controlled stacking of control points, so the points can be stacked upon each other one at a time, and then removed again, one at a time.

 o mouseDragged
 public void mouseDragged(MouseEvent me)
This routine drags the cursor across the workspace. It repaints the window at each movement. This routine is magic, enabling the user to see what is happening within the curve algorithm. This routine is absolutely essential to the functioning of the program. Although there is some display blinking visible, this makes the examples come alive!

 o mouseMoved
 public void mouseMoved(MouseEvent me)
 o mouseReleased
 public void mouseReleased(MouseEvent me)
 o mouseEntered
 public void mouseEntered(MouseEvent me)
 o mouseExited
 public void mouseExited(MouseEvent me)
 o mouseClicked
 public void mouseClicked(MouseEvent me)
 o drawDottedLine
 public void drawDottedLine(Graphics tempGraphics,
                            int x1,
                            int y1,
                            int x2,
                            int y2,
                            int numOfDots)
This routine draws a dotted line between two points, using a small dot. All control polygon lines are drawn in this technique.

 o drawBigPointDottedLine
 public void drawBigPointDottedLine(Graphics tempGraphics,
                                    int x1,
                                    int y1,
                                    int x2,
                                    int y2,
                                    int numOfDots)
This routine draws a dotted line between two points, using a large dot.

 o drawPoint
 public void drawPoint(Graphics tempGraphics,
                       int x,
                       int y)
This routine draws a small dot (one pixel!)

 o drawBigPoint
 public void drawBigPoint(Graphics tempGraphics,
                          int x,
                          int y)
This routine draws each curve 'dot' (highly visible).

 o drawCursor
 public void drawCursor(Graphics tempGraphics,
                        int x,
                        int y)
Draw a large cursor (an X plus a small circle)