de.jreality.geometry
Class BallAndStickFactory

java.lang.Object
  extended by de.jreality.geometry.BallAndStickFactory

public class BallAndStickFactory
extends Object

This class constructs a ball-and-stick representation of an instance of IndexedLineSet and returns it in the form of an instance of SceneGraphComponent.

In the default behavior, around each edge (vertex) of the IndexedLineSet is placed a cylinder (sphere). The radius can be separately controlled for the cylinders and for the spheres, as can the colors. Additionally, one can specify that arrow symbols be positioned along the tubes; here one can control the relative position, the size, and the steepness of the arrow head (which is essentially a cone).

The cross section of the tube is currently fixed to be an octagon. The returned SceneGraphComponent has two children, containing the sticks and the balls, respectively.

The general cycle of use is illustrated in the following code snippet:

                BallAndStickFactory basf = new BallAndStickFactory(Primitives.sharedIcosahedron);
                basf.setBallRadius(.04);
                basf.setStickRadius(.02);
                basf.setDrawArrows(true);
                basf.setArrowScale(.1);
                basf.setArrowSlope(1.5);
                basf.setArrowPosition(.9);
                basf.update();
                SceneGraphComponent tubedIcosa = basf.getSceneGraphComponent();
 

Note: The same effect (without the arrows) can be achieved with the standard line and point shaders (DefaultLineShader, etc), by setting CommonAttributes.TUBES_DRAW and CommonAttributes.SPHERES_DRAW, resp., to true and setting the other shader parameters to control the color and radius of the rusulting tubes and spheres. However, there are some constraints on this; for example, it isn't possible to turn on flat shading and separate control of the transparency is not possible.

Author:
Charles Gunn
See Also:
TubeUtility.tubeOneEdge(double[], double[], double, double[][], int)

Constructor Summary
BallAndStickFactory(IndexedLineSet i)
           
 
Method Summary
 double getArrowPosition()
           
 double getArrowScale()
           
 double getArrowSlope()
           
 Geometry getBallGeometry()
           
 double[][] getCrossSection()
           
 SceneGraphComponent getSceneGraphComponent()
           
 Geometry getStickGeometry()
           
 boolean isShowArrows()
           
 boolean isShowBalls()
           
 boolean isShowSticks()
           
 void setArrowPosition(double arrowPosition)
           
 void setArrowScale(double arrowScale)
           
 void setArrowSlope(double arrowSlope)
           
 void setBallColor(Color ballColor)
           
 void setBallGeometry(Geometry ballGeometry)
           
 void setBallRadius(double ballRadius)
           
 void setCrossSection(double[][] crossSection)
           
 void setShowArrows(boolean drawArrows)
           
 void setShowBalls(boolean showBalls)
           
 void setShowSticks(boolean showSticks)
           
 void setSignature(int signature)
           
 void setStickColor(Color stickColor)
           
 void setStickGeometry(Geometry stickGeometry)
           
 void setStickRadius(double r)
           
static SceneGraphComponent sticks(SceneGraphComponent sgc, IndexedLineSet ifs, double rad, int signature)
           
 void update()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BallAndStickFactory

public BallAndStickFactory(IndexedLineSet i)
Method Detail

update

public void update()

setStickRadius

public void setStickRadius(double r)

setBallColor

public void setBallColor(Color ballColor)

setBallRadius

public void setBallRadius(double ballRadius)

setStickColor

public void setStickColor(Color stickColor)

setSignature

public void setSignature(int signature)

getSceneGraphComponent

public SceneGraphComponent getSceneGraphComponent()

sticks

public static SceneGraphComponent sticks(SceneGraphComponent sgc,
                                         IndexedLineSet ifs,
                                         double rad,
                                         int signature)

getArrowPosition

public double getArrowPosition()

setArrowPosition

public void setArrowPosition(double arrowPosition)

getArrowScale

public double getArrowScale()

setArrowScale

public void setArrowScale(double arrowScale)

getArrowSlope

public double getArrowSlope()

setArrowSlope

public void setArrowSlope(double arrowSlope)

isShowArrows

public boolean isShowArrows()

setShowArrows

public void setShowArrows(boolean drawArrows)

isShowBalls

public boolean isShowBalls()

setShowBalls

public void setShowBalls(boolean showBalls)

isShowSticks

public boolean isShowSticks()

setShowSticks

public void setShowSticks(boolean showSticks)

getCrossSection

public double[][] getCrossSection()

setCrossSection

public void setCrossSection(double[][] crossSection)

getBallGeometry

public Geometry getBallGeometry()

setBallGeometry

public void setBallGeometry(Geometry ballGeometry)

getStickGeometry

public Geometry getStickGeometry()

setStickGeometry

public void setStickGeometry(Geometry stickGeometry)