org.gwoptics.graphics.graph3D
Class SurfaceGraph3D

java.lang.Object
  extended by org.gwoptics.graphics.Renderable
      extended by org.gwoptics.graphics.graph3D.SurfaceGraph3D
All Implemented Interfaces:
IRenderable

public final class SurfaceGraph3D
extends Renderable

This class incorporates the Axis3D and SurfaceTrace3D objects to construct a 3D Cartesian surface graph. It is possible to draw several surface traces, but care must be taken not to incorporate to many points if the graph is to be rendered with a moving camera, otherwise slower system will struggle to render the graph.

Once the graph is created, it is possible to add traces using the addSurfaceTrace() function. You must specify a callback for the trace which defines the equation it represents. The callback must implement the IGraph3DCallback interface, which allows it to work with the SurfaceTrace3D class by providing a function to compute the values of each point on the surface. It is also possible to specify a colourmap to colour the trace. Several presets can be found in org.gwoptics.graphics.colourmap.presets, or unique ones can be created using the RGBColourmap object. Once the trace is added it must be plotted everytime it is changed using plotSurfaceTrace() otherwise changes will not be seen.

The graphs position denotes the point where all 3 axes meet, the x,y and z axes then all extend in the positive direction by the length values supplied. If in the constructor setAxisCrossAtZero is true, position denotes the location of the minimum point of the z-axis. Axis x and y will then alter themselves automatically to get as close to zero on the z-axis as possible. Due to screen space defining the y axis as 'down' the screen from the top corner, it is recommended that PApplet.scale(1,-1,1) is applied before drawing the graph or a suitable rotation. Or use the Camera3D class which defines the upwards direction to be -y automatically.

Important Note: Due to notation the x and y directions should relate to the grid plane the the height in the z direction. Though due to the way screen space works y is the up direction. This must be taken into account throughout this class.

History
Version 0.3.6 Added functionality to auto-range Z-Axis for a given surface. Can now alter colour of tick and fonts of axis

Version 0.3.0 Altered to ensure labels were correctly aligned and that the graph was right-handed.

Version 0.2.4 sees a breaking change of notation relating z as the up direction, see important note above for more implications of this change. Also changed class to final, so it cant be extended.

Version 0.2.2 sees the introduction of traces, before only one surface was plotted. This is not backwards compatiable.

 
        //Example Code for simple sin graph.
        g3d = new SurfaceGraph3D(this, 500, 100,500);   
        g3d.setXAxisMin(-2);            
        g3d.setXAxisMax(2);
        g3d.setYAxisMin(-2);
        g3d.setYAxisMax(2);             
        g3d.setZAxisMin(-1);            
        g3d.setZAxisMax(1);
                
        //Plot sin graph using preset hot colourmap 
        g3d.addSurfaceTrace(new IGraph3DCallback(){
                public float computePoint(float X, float Y) {
                        return Math.sin(X) * Math.sin(Y);
                }}, 100, 100, new HotColourmap(true));
                
        //Once trace is added it must be plotted.
        g3d.plotSurfaceTrace(0);
 
 

Since:
0.1.1
Author:
Daniel Brown 8/6/09
See Also:
Axis3D, SurfaceTrace3D, RGBColourmap, org.gwoptics.graphics.colourmap.presets, IGraph3DCallback

Field Summary
 
Fields inherited from class org.gwoptics.graphics.Renderable
position
 
Constructor Summary
SurfaceGraph3D(processing.core.PApplet p, float xLength, float yLength, float zLength)
          All that needs to be specified to generate a graph is its dimensions.
SurfaceGraph3D(processing.core.PApplet p, float xLength, float yLength, float zLength, boolean setAxisCrossAtZero)
          All that needs to be specified to generate a graph is its dimensions.
 
Method Summary
 void addSurfaceTrace(IGraph3DCallback cb, int XRes, int YRes, IColourmap map)
          Adds a surface trace to the graph.
 void draw()
          Draws each segment of the graph, all the traces and axes.
 int getTraceCount()
           
 float getZAxisMax()
           
 void plotSurfaceTrace(int index)
          This function starts the surface calling the callback object to generate the surface
 void removeSurfaceTrace(int index)
          Removes trace from the graph.
 void setAutoRanging(int surfaceIndex)
          Use this to set a surface to automatically set the min and max values of the Z-axis to match the computed values, resulting in no clipping of surface points.
 void setAxisColour(GWColour c)
           
 void setAxisColour(int R, int G, int B)
           
 void setBillboarding(boolean value)
           
 void setDrawAxisLabel(boolean value)
           
 void setDrawLines(boolean value)
           
 void setDrawTickLabels(boolean value)
           
 void setDrawTicks(boolean value)
           
 void setFontColour(GWColour c)
           
 void setFontColour(int R, int G, int B)
           
 void setTraceFill(int index, GWColour c)
          Fills the trace with a solid colour if no colourmap is specified
 void setTraceStroke(int index, GWColour c)
          sets the colour of the wireframe of a trace if no colourmap is specified
 void setXAxisLabel(java.lang.String s)
           
 void setXAxisLabelAccuracy(int l)
           
 void setXAxisLabelType(ValueType l)
           
 void setXAxisMajorTicks(int n)
           
 void setXAxisMax(float l)
           
 void setXAxisMin(float l)
           
 void setXAxisMinorTicks(int n)
           
 void setYAxisLabel(java.lang.String s)
           
 void setYAxisLabelAccuracy(int l)
           
 void setYAxisLabelType(ValueType l)
           
 void setYAxisMajorTicks(int n)
           
 void setYAxisMax(float l)
           
 void setYAxisMin(float l)
           
 void setYAxisMinorTicks(int n)
           
 void setZAxisLabel(java.lang.String s)
           
 void setZAxisLabelAccuracy(int l)
           
 void setZAxisLabelType(ValueType l)
           
 void setZAxisMajorTicks(int n)
           
 void setZAxisMax(float l)
           
 void setZAxisMin(float l)
           
 void setZAxisMinorTicks(int n)
           
 
Methods inherited from class org.gwoptics.graphics.Renderable
setParent
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SurfaceGraph3D

public SurfaceGraph3D(processing.core.PApplet p,
                      float xLength,
                      float yLength,
                      float zLength)
All that needs to be specified to generate a graph is its dimensions. This sets a default state for all the axes, like which direction the labels are drawn in and label sizes etc. Some of these properties are changeable using the various axis setter functions.

Parameters:
p - PApplet that will render this object
xLength - Length of the X-Axis
yLength - Length of the Y-Axis
zLength - Length of the Z-Axis

SurfaceGraph3D

public SurfaceGraph3D(processing.core.PApplet p,
                      float xLength,
                      float yLength,
                      float zLength,
                      boolean setAxisCrossAtZero)
All that needs to be specified to generate a graph is its dimensions. This sets a default state for all the axes, like which direction the labels are drawn in and label sizes etc. Some of these properties are changeable using the various axis setter functions.

Parameters:
p - PApplet that will render this object
xLength - Length of the X-Axis
yLength - Length of the Y-Axis
zLength - Length of the Z-Axis
setAxisCrossAtZero - boolean stating whether to make axes cross at zero
Method Detail

getZAxisMax

public float getZAxisMax()

setXAxisMin

public void setXAxisMin(float l)

setYAxisMin

public void setYAxisMin(float l)

setZAxisMin

public void setZAxisMin(float l)

setXAxisMax

public void setXAxisMax(float l)

setYAxisMax

public void setYAxisMax(float l)

setZAxisMax

public void setZAxisMax(float l)

setXAxisLabel

public void setXAxisLabel(java.lang.String s)

setYAxisLabel

public void setYAxisLabel(java.lang.String s)

setZAxisLabel

public void setZAxisLabel(java.lang.String s)

setXAxisLabelAccuracy

public void setXAxisLabelAccuracy(int l)

setYAxisLabelAccuracy

public void setYAxisLabelAccuracy(int l)

setZAxisLabelAccuracy

public void setZAxisLabelAccuracy(int l)

setXAxisLabelType

public void setXAxisLabelType(ValueType l)

setYAxisLabelType

public void setYAxisLabelType(ValueType l)

setZAxisLabelType

public void setZAxisLabelType(ValueType l)

setXAxisMajorTicks

public void setXAxisMajorTicks(int n)

setXAxisMinorTicks

public void setXAxisMinorTicks(int n)

setYAxisMajorTicks

public void setYAxisMajorTicks(int n)

setYAxisMinorTicks

public void setYAxisMinorTicks(int n)

setZAxisMajorTicks

public void setZAxisMajorTicks(int n)

setZAxisMinorTicks

public void setZAxisMinorTicks(int n)

setBillboarding

public void setBillboarding(boolean value)

setDrawLines

public void setDrawLines(boolean value)

setDrawTickLabels

public void setDrawTickLabels(boolean value)

setDrawTicks

public void setDrawTicks(boolean value)

setDrawAxisLabel

public void setDrawAxisLabel(boolean value)

setAxisColour

public void setAxisColour(int R,
                          int G,
                          int B)

setAxisColour

public void setAxisColour(GWColour c)

setFontColour

public void setFontColour(int R,
                          int G,
                          int B)

setFontColour

public void setFontColour(GWColour c)

setAutoRanging

public void setAutoRanging(int surfaceIndex)
Use this to set a surface to automatically set the min and max values of the Z-axis to match the computed values, resulting in no clipping of surface points. Set index to -1 if no auto-ranging is required.

Parameters:
surfaceIndex - The index of the surface to autorange the z axis

getTraceCount

public int getTraceCount()

addSurfaceTrace

public void addSurfaceTrace(IGraph3DCallback cb,
                            int XRes,
                            int YRes,
                            IColourmap map)
Adds a surface trace to the graph.

Parameters:
cb - IGraph3DCallback that represents the equation of the trace
XRes - Number of squares along x side of grid, the higher the more detailed the graph
YRes - Number of squares along z side of grid, the higher the more detailed the graph
map - Null for wireframe rendering. Otherwise specifies how to colour the surface.

removeSurfaceTrace

public void removeSurfaceTrace(int index)
Removes trace from the graph.

Parameters:
index - Index of trace to remove

plotSurfaceTrace

public void plotSurfaceTrace(int index)
This function starts the surface calling the callback object to generate the surface

Parameters:
index - index of trace the generate

setTraceStroke

public void setTraceStroke(int index,
                           GWColour c)
sets the colour of the wireframe of a trace if no colourmap is specified

Parameters:
index - index of trace
c - colour of wireframe

setTraceFill

public void setTraceFill(int index,
                         GWColour c)
Fills the trace with a solid colour if no colourmap is specified

Parameters:
index - index of trace
c - colour to fill surface

draw

public void draw()
Draws each segment of the graph, all the traces and axes.

Specified by:
draw in interface IRenderable
Specified by:
draw in class Renderable


processing library gwoptics by Daniel Brown and Andreas Freise. (c) 2009 onwards