JClass DesktopViews 6.3.0 API
Documentation

com.klg.jclass.chart3d
Class JCContour

java.lang.Object
  |
  +--com.klg.jclass.chart3d.ParentTrackChange
        |
        +--com.klg.jclass.chart3d.JCContour
All Implemented Interfaces:
JCContourMapping, Serializable

public class JCContour
extends ParentTrackChange
implements JCContourMapping

Object used to deal with information about contours and zones. It has methods to compute and to draw the contours/zones.

See Also:
Serialized Form

Field Summary
protected  com.klg.jclass.chart3d.ColorBin[] bins
          An array of color bins for faster rendering of 2D projections.
protected static int BOTTOM_EDGE
           
protected static int BOTTOM_LEFT_CORNER
           
protected static int BOTTOM_RIGHT_CORNER
           
protected  com.klg.jclass.chart3d.ContourCell[] contourCells
          Contouring information by cell.
protected  boolean contoured
          Asks if the contour lines are drawn.
protected  com.klg.jclass.chart3d.JCContourLevels contourLevels
          A list of contour levels.
protected  ArrayList contourLines
          A list of contour lines.
protected  com.klg.jclass.chart3d.JCContourMapping contourMapping
          A mapping of contour levels to contour styles.
protected  ArrayList contourStyles
          List of contour styles which determine how zones and contour lines are drawn.
protected  com.klg.jclass.chart3d.ContourSegment curSegment
           
protected static int CYCLE_CLOCKWISE
           
protected static int CYCLE_COUNTER_CLOCKWISE
           
protected  com.klg.jclass.chart3d.Chart3dGridData data
           
protected  double dataHoleValue
           
protected  com.klg.jclass.chart3d.Chart3dDataView dataView
          The parent dataView object.
protected  com.klg.jclass.chart3d.DefaultColors defaultColors
          A list of default colors (for default contour styles generation).
protected  int firstIndex
           
protected  com.klg.jclass.chart3d.PolygonChain[] fixedChain
           
protected  com.klg.jclass.chart3d.PolygonChain freeList
           
protected static int LEFT_EDGE
           
protected  int nHorizontalSides
           
protected  int numX
           
protected  int numY
           
protected  int nVerticalSides
           
protected  int pCount
           
protected static int RIGHT_EDGE
           
protected  com.klg.jclass.chart3d.CellSide[] sides
           
protected static int TOP_EDGE
           
protected static int TOP_LEFT_CORNER
           
protected static int TOP_RIGHT_CORNER
           
protected  int xOffset
           
protected  int[] xPoints
           
protected  int yOffset
           
protected  int[] yPoints
           
static int ZONE_CELLS_AVERAGE
          Instructs zoning to be done by cells using the average of the four corners of the cell.
static int ZONE_CELLS_CORNER
          Instructs zoning to be done by cells using the value at the bottom left corner of the cell.
static int ZONE_CONTOURS
          Instructs zoning to be done by contours.
protected  boolean zoned
          Asks if the contour zones are drawn.
protected  com.klg.jclass.chart3d.Chart3dGridData zoneData
           
protected  double zoneHoleValue
           
protected  int zoneMethod
          Zoning filling method.
 
Fields inherited from class com.klg.jclass.chart3d.ParentTrackChange
parents
 
Constructor Summary
JCContour()
          No args constructor.
JCContour(com.klg.jclass.chart3d.Chart3dDataView dataView)
          Constructor which specifies the parent dataView.
 
Method Summary
protected  void addContourCell(int xIndex, int yIndex, int level, int side)
          A contour line is entering this cell, this side.
protected  void addPoint(int xIndex, int yIndex, double x, double y)
          Adds this point to the current contour line.
protected  void allocatePoints(int n)
          Allocates points only when necessary.
protected  void allocColorBins(Graphics gc)
          Allocates a color bin for each level.
protected  com.klg.jclass.chart3d.PolygonChain appendChain(com.klg.jclass.chart3d.PolygonChain pChain1, com.klg.jclass.chart3d.PolygonChain pChain2)
          Appends chain pchain2 to the end of pchain1.
protected  boolean avail(int xIndex, int yIndex, int side, int level, double right, double left)
          Is the side of the cell at (x_index, y_index) available to cross a contour at this level? Make sure no other contour of this level has crossed; if not, see if a contour does cross it.
protected  int bottomSide(int x, int y)
          Gets the index of the bottom side of cell (x, y) in the sides array.
 void calcContours()
          Calculates the contours for this data.
protected  int cellIndex(int x, int y)
          Returns the index in the ContourCells array for this cell.
protected  void contour(int cycle, int xIndex, int yIndex, int level, int side)
          Generates a complete contour that starts at (xIndex, yIndex).
 int contourIndex(int level)
          Returns the contour style index that corresponds to this level.
protected  com.klg.jclass.chart3d.PolygonChain copyChain(com.klg.jclass.chart3d.PolygonChain pChain)
          Copies an entire chain to a new one, and returns the new one.
protected  void cycleArray(Object[] array, int n)
          Cycles the array's lower most four elements by n.
protected  void defaultContourStyles()
          Resets the contour styles to their default value.
protected  void destroyChain(com.klg.jclass.chart3d.PolygonChain pChain)
          Gets rid of this chain.
 void destroyContours()
          Destroys the contour information.
protected  void draw2dZones(Graphics gc)
          Draws flat zones in a 2D projection.
protected  void draw3dZones(Graphics gc)
          Draws flat zones in a 3D projection ( projecting zones onto either the top or bottom of the cube).
protected  void drawCellContours(Graphics gc, int xIndex, int yIndex)
          Draws all contours for the specified cell.
protected  void drawContours(Graphics gc)
          Draws flat contours.
protected  boolean fillCell(Graphics gc, int xIndex, int yIndex)
          Fills in the cell at (xIndex, yIndex) by breaking it into smaller polygons that must be filled individually.
protected  void fillCellCorners(Graphics gc, com.klg.jclass.chart3d.PolygonChain[] chainArray, int index)
          Fills the zoned cell at each of the four corners.
protected  void fillCellSide(Graphics gc, com.klg.jclass.chart3d.PolygonChain[] chainArray, int corner1, int corner2, int index)
          Fills the portions of the zoned cell relating to the left-to-right or bottom-to-top crossings.
protected  void fillChain(Graphics gc, com.klg.jclass.chart3d.PolygonChain pChain)
          Fills in a PolygonChain.
protected  void fillRectangle(int xIndex, int yIndex, boolean useAverage)
          Fills a zoned rectangle, using either the value at the given grid point or the average of the four corner values of the cell.
protected  void flushColorBins()
          Flushes the color bins.
 com.klg.jclass.chart3d.ContourCell[] getContourCells()
          Returns the contour cell array.
 com.klg.jclass.chart3d.JCContourLevels getContourLevels()
          Returns the contourLevels object.
 ArrayList getContourLines()
          Returns the list of contour lines (internal use only).
 com.klg.jclass.chart3d.JCContourMapping getContourMapping()
          Returns the object which currently implements the mapping between contour levels and contour styles (by default this is the JCContour object).
 com.klg.jclass.chart3d.JCContourStyle getContourStyleFromLevel(int level)
          Returns the contour style used for a given contour level.
 ArrayList getContourStyles()
          Returns the current contour styles.
 com.klg.jclass.chart3d.Chart3dPointDataModel getDataContours(int first, int last, int filter, boolean combineLevels)
          Returns the contour lines in point data format.
 com.klg.jclass.chart3d.Chart3dDataView getDataView()
          Returns the parent dataView.
protected  com.klg.jclass.chart3d.DefaultColors getDefaultColors()
          Retrieves the default colors object which stores the list of default contour style colors.
protected  int getSide(int x, int y, int side)
          Gets the index of a given side in the sides array for cell (x, y).
 int getZoneMethod()
          Returns the zone method - by ZONE_CONTOURS, ZONE_CELLS_AVERAGE, or ZONE_CELLS_CORNER.
protected  boolean horizontalSide(int x)
          Is side x a horizontal side? It is if it is odd.
protected  double interp(double a1, double a2, double o1, double o2, double av)
          Interpolates in 2D along the line running from (a1, o1) to (a2, o2) and point a = av.
 boolean isContoured()
          Returns whether this data view is contoured.
 boolean isZoned()
          Returns whether this data view is zoned.
protected  int leftSide(int x, int y)
          Gets the index of the left side of cell (x, y) in the sides array.
protected  com.klg.jclass.chart3d.PolygonChain makePChain(int xPixel, int yPixel, double zValue, double cValue)
          Makes a new chain, containing this single point.
protected  void modifyContourCell(int xIndex, int yIndex, int side)
          Adds the second crossing point for the current segment across this cell.
protected  void precompContours()
          Goes through each contour point and transforms it.
 void processPolygon(Graphics gc, int count, int level)
          Given a list of points and a contour level, process the polygon that the list of points defines.
 void recalcContours()
          Checks whether to calculate or destroy the contours based on the contour and zone flags from this object, and the floor and ceiling projections.
 void resetContourStyles()
          Allows the user to reset the contour styles to their default.
protected  void reverseArray(Object[] array, int n)
          Reverses an array of length n.
protected  com.klg.jclass.chart3d.PolygonChain reverseChain(com.klg.jclass.chart3d.PolygonChain pChain)
          Reverses the order of points in this chain.
protected  int rightSide(int x, int y)
          Gets the index of the right side of cell (x, y) in the sides array.
protected  void setContourCellHole(int xIndex, int yIndex)
          A zone hole has been detected during the contour search at point (xIndex, yIndex).
 void setContoured(boolean contoured)
          Sets flag which determine whether this data view is contoured.
protected  void setContouredNoUpdate(boolean contoured)
          Sets flag which determines whether this data view is contoured, but doesn't update the dataView.
 void setContourLevels(com.klg.jclass.chart3d.JCContourLevels contourLevels)
          Sets the contourLevels object.
 void setContourMapping(com.klg.jclass.chart3d.JCContourMapping contourMapping)
          Provides an object that implements the JCContourMapping interface.
 void setContourStyles(ArrayList contourStyles)
          Sets the contour styles array.
protected  void setDataView(com.klg.jclass.chart3d.Chart3dDataView dataView)
          Sets the parent dataView.
protected  void setFillStyle(Graphics gc, int level)
          Sets the fill style for this level.
protected  void setInternalValues()
          Sets some internal values (for easier access).
protected  boolean setLineStyle(Graphics gc, int level)
          Sets the line style for this level.
protected  void setZLineColor(Graphics gc, int level)
          Sets the line color for this level based on the fill (zone) style color (rather than the line style color).
 void setZoned(boolean zoned)
          Sets flag which determines whether this data view is zoned.
protected  void setZonedNoUpdate(boolean zoned)
          Sets flag which determines whether this data view is zoned, but doesn't update the dataView.
 void setZoneMethod(int zoneMethod)
          Sets the zone method - by ZONE_CONTOURS or ZONE_CELLS.
protected  void startContour(int xIndex, int yIndex, int level, Point3d p1, Point3d p2)
          Starts a new contour at this level.
protected  int topSide(int x, int y)
          Gets the index of the top side of cell (x, y) in the sides array.
protected  boolean verticalSide(int x)
          Is side x a vertical side? It is if it is even.
protected  boolean zoneMeshCell(Graphics gc, int xIndex, int yIndex)
          Draws a zoned mesh for this cell.
protected  double zoneMeshIntersection(Graphics gc, ArrayList intersectionList, Point right, double zr, boolean doSeg1, boolean increasing)
          Draws the zoned mesh for this intersection list for a given mesh line.
 
Methods inherited from class com.klg.jclass.chart3d.ParentTrackChange
addParent, clearParents, removeParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZONE_CONTOURS

public static final int ZONE_CONTOURS
Instructs zoning to be done by contours.

See Also:
Constant Field Values

ZONE_CELLS_AVERAGE

public static final int ZONE_CELLS_AVERAGE
Instructs zoning to be done by cells using the average of the four corners of the cell.

See Also:
Constant Field Values

ZONE_CELLS_CORNER

public static final int ZONE_CELLS_CORNER
Instructs zoning to be done by cells using the value at the bottom left corner of the cell.

See Also:
Constant Field Values

CYCLE_CLOCKWISE

protected static final int CYCLE_CLOCKWISE
See Also:
Constant Field Values

CYCLE_COUNTER_CLOCKWISE

protected static final int CYCLE_COUNTER_CLOCKWISE
See Also:
Constant Field Values

LEFT_EDGE

protected static final int LEFT_EDGE
See Also:
Constant Field Values

RIGHT_EDGE

protected static final int RIGHT_EDGE
See Also:
Constant Field Values

BOTTOM_EDGE

protected static final int BOTTOM_EDGE
See Also:
Constant Field Values

TOP_EDGE

protected static final int TOP_EDGE
See Also:
Constant Field Values

BOTTOM_LEFT_CORNER

protected static final int BOTTOM_LEFT_CORNER
See Also:
Constant Field Values

TOP_LEFT_CORNER

protected static final int TOP_LEFT_CORNER
See Also:
Constant Field Values

TOP_RIGHT_CORNER

protected static final int TOP_RIGHT_CORNER
See Also:
Constant Field Values

BOTTOM_RIGHT_CORNER

protected static final int BOTTOM_RIGHT_CORNER
See Also:
Constant Field Values

contoured

protected boolean contoured
Asks if the contour lines are drawn.


zoned

protected boolean zoned
Asks if the contour zones are drawn.


zoneMethod

protected int zoneMethod
Zoning filling method. Fills according to contours or on a per cell basis.


contourLevels

protected com.klg.jclass.chart3d.JCContourLevels contourLevels
A list of contour levels.


contourStyles

protected ArrayList contourStyles
List of contour styles which determine how zones and contour lines are drawn.


contourMapping

protected com.klg.jclass.chart3d.JCContourMapping contourMapping
A mapping of contour levels to contour styles.


dataView

protected com.klg.jclass.chart3d.Chart3dDataView dataView
The parent dataView object.


defaultColors

protected com.klg.jclass.chart3d.DefaultColors defaultColors
A list of default colors (for default contour styles generation).


data

protected com.klg.jclass.chart3d.Chart3dGridData data

zoneData

protected com.klg.jclass.chart3d.Chart3dGridData zoneData

xOffset

protected int xOffset

yOffset

protected int yOffset

numX

protected int numX

numY

protected int numY

dataHoleValue

protected double dataHoleValue

zoneHoleValue

protected double zoneHoleValue

contourLines

protected ArrayList contourLines
A list of contour lines.


contourCells

protected com.klg.jclass.chart3d.ContourCell[] contourCells
Contouring information by cell.


bins

protected com.klg.jclass.chart3d.ColorBin[] bins
An array of color bins for faster rendering of 2D projections.


fixedChain

protected com.klg.jclass.chart3d.PolygonChain[] fixedChain

freeList

protected com.klg.jclass.chart3d.PolygonChain freeList

pCount

protected int pCount

sides

protected com.klg.jclass.chart3d.CellSide[] sides

nHorizontalSides

protected int nHorizontalSides

nVerticalSides

protected int nVerticalSides

firstIndex

protected int firstIndex

curSegment

protected com.klg.jclass.chart3d.ContourSegment curSegment

xPoints

protected int[] xPoints

yPoints

protected int[] yPoints
Constructor Detail

JCContour

public JCContour()
No args constructor. Sets default contour styles.


JCContour

public JCContour(com.klg.jclass.chart3d.Chart3dDataView dataView)
Constructor which specifies the parent dataView. There can be only one dataView parent since the contours are heavily dependent on the data.

Parameters:
dataView - the parent dataView
Method Detail

setDataView

protected void setDataView(com.klg.jclass.chart3d.Chart3dDataView dataView)
Sets the parent dataView. There can be only one dataView parent since the contours are heavily dependent on the data.

Parameters:
dataView - the new parent dataView

getDataView

public com.klg.jclass.chart3d.Chart3dDataView getDataView()
Returns the parent dataView.

Returns:
parent dataView

setContoured

public void setContoured(boolean contoured)
Sets flag which determine whether this data view is contoured.

Parameters:
contoured - the new value of the contoured flag

setContouredNoUpdate

protected void setContouredNoUpdate(boolean contoured)
Sets flag which determines whether this data view is contoured, but doesn't update the dataView. This is used in drawing projections where the value of contoured needs to be set to a temporary value while drawing the projection.

Parameters:
contoured - the new value of the contoured flag

isContoured

public boolean isContoured()
Returns whether this data view is contoured.

Returns:
the value of the contoured flag

setZoned

public void setZoned(boolean zoned)
Sets flag which determines whether this data view is zoned.

Parameters:
zoned - the new value of the zoned flag

setZonedNoUpdate

protected void setZonedNoUpdate(boolean zoned)
Sets flag which determines whether this data view is zoned, but doesn't update the dataView. This is used in drawing projections where the value of zoned needs to be set to a temporary value while drawing the projection.

Parameters:
zoned - the new value of the zoned flag

isZoned

public boolean isZoned()
Returns whether this data view is zoned.

Returns:
the value of the zoned flag

setZoneMethod

public void setZoneMethod(int zoneMethod)
Sets the zone method - by ZONE_CONTOURS or ZONE_CELLS.

Parameters:
zoneMethod - the new zone method

getZoneMethod

public int getZoneMethod()
Returns the zone method - by ZONE_CONTOURS, ZONE_CELLS_AVERAGE, or ZONE_CELLS_CORNER.

Returns:
the current zone method

setContourLevels

public void setContourLevels(com.klg.jclass.chart3d.JCContourLevels contourLevels)
Sets the contourLevels object.

Parameters:
contourLevels - the new contourLevels object

getContourLevels

public com.klg.jclass.chart3d.JCContourLevels getContourLevels()
Returns the contourLevels object.

Returns:
the contourLevels object

setContourMapping

public void setContourMapping(com.klg.jclass.chart3d.JCContourMapping contourMapping)
Provides an object that implements the JCContourMapping interface. This object provides a mapping between contour levels and contour styles.

Parameters:
contourMapping - the new contour mapping

getContourMapping

public com.klg.jclass.chart3d.JCContourMapping getContourMapping()
Returns the object which currently implements the mapping between contour levels and contour styles (by default this is the JCContour object).

Returns:
the current contour mapping

setContourStyles

public void setContourStyles(ArrayList contourStyles)
Sets the contour styles array. Passing in null resets the contour styles to their default.
Note: It is assumed that all entries of the contour styles array are non-null.

Parameters:
contourStyles - the new list of contour styles

getContourStyles

public ArrayList getContourStyles()
Returns the current contour styles. If no contour styles are currently available, a new set of default contours styles is generated and returned.

Returns:
the current set of contour styles

resetContourStyles

public void resetContourStyles()
Allows the user to reset the contour styles to their default.
Note: This is identical to setContourStyles(null);.


getDefaultColors

protected com.klg.jclass.chart3d.DefaultColors getDefaultColors()
Retrieves the default colors object which stores the list of default contour style colors.

Returns:
default colors object

getContourLines

public ArrayList getContourLines()
Returns the list of contour lines (internal use only).

Returns:
list of contour lines

getContourCells

public com.klg.jclass.chart3d.ContourCell[] getContourCells()
Returns the contour cell array.
Note: This is a linear array used for a cell grid. The cellIndex(x, y) method will return the correct position in the array for a given (x, y). For internal use only.

Returns:
the contour cell array

verticalSide

protected boolean verticalSide(int x)
Is side x a vertical side? It is if it is even.

Parameters:
x - the side in question
Returns:
Is the side vertical?

horizontalSide

protected boolean horizontalSide(int x)
Is side x a horizontal side? It is if it is odd.

Parameters:
x - the side in question
Returns:
Is the side horizontal?

leftSide

protected int leftSide(int x,
                       int y)
Gets the index of the left side of cell (x, y) in the sides array.

Parameters:
x - the x index of the cell
y - the y index of the cell
Returns:
the index of the left side of cell (x, y)

rightSide

protected int rightSide(int x,
                        int y)
Gets the index of the right side of cell (x, y) in the sides array.

Parameters:
x - the x index of the cell
y - the y index of the cell
Returns:
the index of the right side of cell (x, y)

bottomSide

protected int bottomSide(int x,
                         int y)
Gets the index of the bottom side of cell (x, y) in the sides array.

Parameters:
x - the x index of the cell
y - the y index of the cell
Returns:
the index of the bottom side of cell (x, y)

topSide

protected int topSide(int x,
                      int y)
Gets the index of the top side of cell (x, y) in the sides array.

Parameters:
x - the x index of the cell
y - the y index of the cell
Returns:
the index of the top side of cell (x, y)

getSide

protected int getSide(int x,
                      int y,
                      int side)
Gets the index of a given side in the sides array for cell (x, y).

Parameters:
x - the x index of the cell
y - the y index of the cell
side - the side in question
Returns:
the index of the passed in side of cell (x, y)

cellIndex

protected int cellIndex(int x,
                        int y)
Returns the index in the ContourCells array for this cell.

Parameters:
x - the x index of the cell
y - the y index of the cell
Returns:
the index in the ContourCells array for this cell

setInternalValues

protected void setInternalValues()
Sets some internal values (for easier access).


avail

protected boolean avail(int xIndex,
                        int yIndex,
                        int side,
                        int level,
                        double right,
                        double left)
Is the side of the cell at (x_index, y_index) available to cross a contour at this level? Make sure no other contour of this level has crossed; if not, see if a contour does cross it.

Parameters:
xIndex - xIndex of the cell
yIndex - yIndex of the cell
side - the side whose availability is in question
level - the contour level who wants to cross the given side
right - the z value on the "right" side of the contour level value
left - the z value on the "left" side of the contour level value
Returns:
Is side available?

interp

protected double interp(double a1,
                        double a2,
                        double o1,
                        double o2,
                        double av)
Interpolates in 2D along the line running from (a1, o1) to (a2, o2) and point a = av.

Parameters:
a1 - x value for first point
a2 - x value for second point
av -
o1 - y value for first point
o2 - y value for second point
Returns:

addContourCell

protected void addContourCell(int xIndex,
                              int yIndex,
                              int level,
                              int side)
A contour line is entering this cell, this side. Records it for filling purposes.

Parameters:
xIndex - xIndex of the cell
yIndex - yIndex of the cell
level - the contour level entering cell
side - the side of the cell being entered

modifyContourCell

protected void modifyContourCell(int xIndex,
                                 int yIndex,
                                 int side)
Adds the second crossing point for the current segment across this cell. Makes sure the line is oriented so that the higher y value or higher x value is in the rightmost point.

Parameters:
xIndex - the xIndex of the cell
yIndex - the yIndex of the cell
side - the side which the contour line is crossing

reverseArray

protected void reverseArray(Object[] array,
                            int n)
Reverses an array of length n.

Parameters:
array - the array to reverse
n - The number of elements of the array to reverse. May not be equal to array.length.

cycleArray

protected void cycleArray(Object[] array,
                          int n)
Cycles the array's lower most four elements by n.

Parameters:
array - the array to cycle
n - The number of elements to cycle. May not be equal to array.length.

addPoint

protected void addPoint(int xIndex,
                        int yIndex,
                        double x,
                        double y)
Adds this point to the current contour line.

Parameters:
xIndex - the x grid index of the point
yIndex - the y grid index of the point
x - the x value of the point to add
y - the y value of the point to add

startContour

protected void startContour(int xIndex,
                            int yIndex,
                            int level,
                            Point3d p1,
                            Point3d p2)
Starts a new contour at this level. The starting point crosses the line joining p1 and p2.

Parameters:
xIndex - the x grid index of the start point
yIndex - the y grid index of the start point
level - the contour level to start
p1 - point 1 of the line the start point crosses
p2 - point 2 of the line the start point crosses

contour

protected void contour(int cycle,
                       int xIndex,
                       int yIndex,
                       int level,
                       int side)
Generates a complete contour that starts at (xIndex, yIndex). We are coming into the 'side' of the cell, and are contouring at the 'level'. (See diagram at top of file).

We reorient everything to make it look like we're coming in side 3. The order we search the sides is determined by 'cycle' - either clockwise or counter-clockwise.

Parameters:
cycle - the order we search the sides, either equal to CYCLE_CLOCKWISE or CYCLE_COUNTER_CLOCKWISE
xIndex - the x grid index of the start point
yIndex - the y grid index of the start point
level - the contour level
side - the side of the cell to start contouring

setContourCellHole

protected void setContourCellHole(int xIndex,
                                  int yIndex)
A zone hole has been detected during the contour search at point (xIndex, yIndex). Mark all adjoining cells as having a hole.

Parameters:
xIndex - the x grid index of the contour cell
yIndex - the y grid index of the contour cell

calcContours

public void calcContours()
Calculates the contours for this data. This is done by scanning the grid from bottom-to-top, and at each step looking for crossings on the bottom line of the cell, and the left line.

Once we have found a crossing, this generates a starting point for the contouring. The method contour() will either search for a new cell in either a clockwise or counter-clockwise fashion (this is done to ensure that no two contour lines intersect).

All crossings are searched either clockwise or counter-clockwise; this maintains symmetry, and ensures the non-intersection rule (but see the Known Bugs section at the top of this file).


recalcContours

public void recalcContours()
Checks whether to calculate or destroy the contours based on the contour and zone flags from this object, and the floor and ceiling projections.


destroyContours

public void destroyContours()
Destroys the contour information.


precompContours

protected void precompContours()
Goes through each contour point and transforms it. This is precomputed so that rendering the transformation is already done and there is no need to transform a point more than once.


allocatePoints

protected void allocatePoints(int n)
Allocates points only when necessary.

Parameters:
n - the number of points to allocate

defaultContourStyles

protected void defaultContourStyles()
Resets the contour styles to their default value. Note that the fill colors are intialized to null because only some of the contour styles may be used. The initContourStyles method will assign colors later.


allocColorBins

protected void allocColorBins(Graphics gc)
Allocates a color bin for each level.

Parameters:
gc - the graphics object to use for drawing

flushColorBins

protected void flushColorBins()
Flushes the color bins. The objects in each bin are drawn.


contourIndex

public int contourIndex(int level)
Returns the contour style index that corresponds to this level. This mapping is based on an even distribution of contour styles through the number of levels.

Specified by:
contourIndex in interface JCContourMapping
Parameters:
level - the level for which the contour style index is desired
Returns:
the index of the contour style for this level

getContourStyleFromLevel

public com.klg.jclass.chart3d.JCContourStyle getContourStyleFromLevel(int level)
Returns the contour style used for a given contour level. This method uses the current contourMapping's contourIndex method to get the index of the contour style in the contourStyles array.

Parameters:
level - the level for which the contour style index is desired
Returns:
the contour style for the given index

setLineStyle

protected boolean setLineStyle(Graphics gc,
                               int level)
Sets the line style for this level. If the width of the line is 0, or the line pattern is none, then return false (nothing should be drawn); otherwise, return true.

Parameters:
gc - the graphics object to use for drawing
level - the level whose line style info you want to set on the gc
Returns:
whether the gc was updated with the lineStyle info

setFillStyle

protected void setFillStyle(Graphics gc,
                            int level)
Sets the fill style for this level.

Parameters:
gc - the graphics object to use for drawing
level - the level whose fill style info you want to set on the gc

setZLineColor

protected void setZLineColor(Graphics gc,
                             int level)
Sets the line color for this level based on the fill (zone) style color (rather than the line style color).

Parameters:
gc - the graphics object to use for drawing
level - the level whose fill color you want to set on the gc

fillRectangle

protected void fillRectangle(int xIndex,
                             int yIndex,
                             boolean useAverage)
Fills a zoned rectangle, using either the value at the given grid point or the average of the four corner values of the cell. The average is used when zoneMethod is ZONE_CELL_AVERAGE. This fills one grid cell, at (xIndex, yIndex).

Parameters:
xIndex - the x grid index of the cell
yIndex - the y grid index of the cell
useAverage - use the average of the four corners of the cell to zone, or just the value at the bottom left corner

makePChain

protected com.klg.jclass.chart3d.PolygonChain makePChain(int xPixel,
                                                         int yPixel,
                                                         double zValue,
                                                         double cValue)
Makes a new chain, containing this single point. The zValue comes from elevation data, cValue from zone data.

Parameters:
xPixel - the x pixel value for this point
yPixel - the y pixel value for this point
zValue - elevation data z value
cValue - zone (or contour) data value
Returns:

copyChain

protected com.klg.jclass.chart3d.PolygonChain copyChain(com.klg.jclass.chart3d.PolygonChain pChain)
Copies an entire chain to a new one, and returns the new one.

Parameters:
pChain - the chain to be copied
Returns:

appendChain

protected com.klg.jclass.chart3d.PolygonChain appendChain(com.klg.jclass.chart3d.PolygonChain pChain1,
                                                          com.klg.jclass.chart3d.PolygonChain pChain2)
Appends chain pchain2 to the end of pchain1. Returns a reference to the start of the combined chain.

Parameters:
pChain1 - the initial chain
pChain2 - the chain to be appended
Returns:

reverseChain

protected com.klg.jclass.chart3d.PolygonChain reverseChain(com.klg.jclass.chart3d.PolygonChain pChain)
Reverses the order of points in this chain.

Parameters:
pChain - the chain to be reversed
Returns:

destroyChain

protected void destroyChain(com.klg.jclass.chart3d.PolygonChain pChain)
Gets rid of this chain. Prepends it to the free-list.

Parameters:
pChain - the chain to be destroyed

processPolygon

public void processPolygon(Graphics gc,
                           int count,
                           int level)
Given a list of points and a contour level, process the polygon that the list of points defines. If drawing a 3D chart, draw the polygon. If doing a 2D projection, add the polygon to the bin for this level so it can be drawn later.

Parameters:
gc - the graphics object to use for drawing
count - the number of points in the list
level - the contour level for this polygon

fillChain

protected void fillChain(Graphics gc,
                         com.klg.jclass.chart3d.PolygonChain pChain)
Fills in a PolygonChain. This chain represents a polygon, which should be filled in one solid color. We determine that value by taking the average value of all the points, unless the zoneMethod is ZONE_CELLS_CORNER, in which case we take the value of the bottom left corner of the cell.

Parameters:
gc - the graphics object to use for drawing
pChain - the polygon chain to be filled

fillCellCorners

protected void fillCellCorners(Graphics gc,
                               com.klg.jclass.chart3d.PolygonChain[] chainArray,
                               int index)
Fills the zoned cell at each of the four corners.

Parameters:
gc - the graphics object to use for drawing
chainArray - the array of polygon chains to fill (one per corner)
index - the index of the contourCell whose corners are to be filled

fillCellSide

protected void fillCellSide(Graphics gc,
                            com.klg.jclass.chart3d.PolygonChain[] chainArray,
                            int corner1,
                            int corner2,
                            int index)
Fills the portions of the zoned cell relating to the left-to-right or bottom-to-top crossings. When this is called, the corner polygons have already been processed. What is left for each corner is a line segment or a point (if no crossings for that corner) that form a polygon with the line crossing.

Parameters:
gc - the graphics object to use for drawing
chainArray - the array of polygons chains to fill
corner1 - the first corner
corner2 - the second corner
index - the index of the contourCell whose cell sides are to be filled

fillCell

protected boolean fillCell(Graphics gc,
                           int xIndex,
                           int yIndex)
Fills in the cell at (xIndex, yIndex) by breaking it into smaller polygons that must be filled individually.

All the contour crossings have been computed for this cell, and are stored in the ContourCell intersection lists. There are 5 lists. The first four represent those lines which cross the 4 corners and are stored in the corners array. The last represents those lines which cross side-to-side or top-to-bottom (note that no cell can contain contour lines which both cross side-to-side and top-to-bottom).

All those segments which cross the corners have been sorted (see sortIntersectionLists() method in ContourCells for the particulars). We construct a polygon chain for each corner that consists only of the corner value, and then possible extend the polygons after that, by growing outward from the corner. After that, do the side-to-side crossings.

If this is a zone hole, return false and the caller will fill the cell normally (4D).

Parameters:
gc - the graphics object to use for drawing
xIndex - the x index of the cell to be filled
yIndex - the y index of the cell to be filled
Returns:

drawCellContours

protected void drawCellContours(Graphics gc,
                                int xIndex,
                                int yIndex)
Draws all contours for the specified cell. This should only be used in 3D; otherwise, drawing the entire contour chain at once would be much quicker (drawContours()).

Parameters:
gc - the graphics object to use for drawing
xIndex - the x index of the cell to be drawn
yIndex - the y index of the cell to be drawn

zoneMeshIntersection

protected double zoneMeshIntersection(Graphics gc,
                                      ArrayList intersectionList,
                                      Point right,
                                      double zr,
                                      boolean doSeg1,
                                      boolean increasing)
Draws the zoned mesh for this intersection list for a given mesh line. The point right and value zr are passed in and updated as the intersection list is traversed. Go forward or backward through the list based on the value of the increasing flag.

Parameters:
gc - the graphics object to use for drawing
intersectionList - the intersection list to draw line segments from
right - the starting point - updated as the list is traversed
zr - the starting value - updated as the list is traversed
doSeg1 - draw the points in segment1 or segment2
increasing - draw forwards or backwards in list
Returns:
the final zr value

zoneMeshCell

protected boolean zoneMeshCell(Graphics gc,
                               int xIndex,
                               int yIndex)
Draws a zoned mesh for this cell. If its a zone hole, return false and the caller will draw a normal mesh in its place (4D).

Basic algorithm is to follow along each side of the mesh, from corner to corner, taking each contour intersection as they occur.

Parameters:
gc - the graphics object to use for drawing
xIndex - the x index of the cell to draw
yIndex - the y index of the cell to draw
Returns:

draw2dZones

protected void draw2dZones(Graphics gc)
Draws flat zones in a 2D projection. Everything should have been precomputed so it only needs to be drawn.

Parameters:
gc - the graphics object to use for drawing

draw3dZones

protected void draw3dZones(Graphics gc)
Draws flat zones in a 3D projection ( projecting zones onto either the top or bottom of the cube). Everything should have been precomputed so it only needs to be drawn.

Parameters:
gc - the graphics object to use for drawing

drawContours

protected void drawContours(Graphics gc)
Draws flat contours. There is no surface to obscure them, so we can optimize drawing by just looping through all the precompute vectors, and drawing them.

Parameters:
gc - the graphics object to use for drawing

getDataContours

public com.klg.jclass.chart3d.Chart3dPointDataModel getDataContours(int first,
                                                                    int last,
                                                                    int filter,
                                                                    boolean combineLevels)
Returns the contour lines in point data format. Each contour level is stored in a series. The user can select a subset of the contour lines by specifying the first and last contour. Every nth contour line (between first and last) can be chosen by setting the filter to be n.

Parameters:
first - the first contour line to be in the data set
last - the last contour line to be in the data set (by setting this parameter to be Integer.MAX_VALUE you will get all the contours from first to the end of the contour line array).
filter - by setting this value to be n, you get every nth contour line starting at first
combineLevels - A contour level can be specified by more than one distinct line segment. If combineLevels is false, each segment will be stored in its own series. If combineLevels is true, all segements from the same level will be stored in one series.
Returns:
A Chart3dPointDataModel (stored in a JCDefault3dPointDataSource object) that contains the point data. If an error occurs, or no contour lines match the inputted values of first, last, and filter, null is returned.
Note: Either the contoured or zoned property of this JCContour object must be true for the contours to be generated.

Copyright © 2004 Quest Software Inc..
All rights reserved.