Class DefaultCamera
- All Implemented Interfaces:
org.graphstream.ui.view.camera.Camera
The camera is in charge of projecting the graph spaces in graph units (GU) into user spaces (often in pixels). It defines the transformation (an affine matrix) to passe from the first to the second. It also contains the graph metrics, a set of values that give the overall dimensions of the graph in graph units, as well as the view port, the area on the screen (or any rendering surface) that will receive the results in pixels (or rendering units).
The camera defines a centre at which it always points. It can zoom on the graph, pan in any direction and rotate along two axes.
Knowing the transformation also allows to provide services like "what element is not invisible ?" (not in the camera view) or "on what element is the mouse cursor actually ?".
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanAutomatic centring of the view.protected org.graphstream.ui.geom.Point3The camera centre of view.protected org.graphstream.ui.graphicGraph.GraphicGraphThe graph.protected double[]The graph view port, if any.protected doubleprotected org.graphstream.ui.view.util.GraphMetricsInformation on the graph overall dimension and position.Which node is visible.protected AffineTransformThe previous affine transform.protected org.graphstream.ui.graphicGraph.stylesheet.ValuesPadding around the graph.protected doubleThe rotation angle.protected AffineTransformThe graph-space -> pixel-space transformation.protected AffineTransformThe inverse transform of Tx.protected doubleThe camera zoom. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultCamera(org.graphstream.ui.graphicGraph.GraphicGraph graph) New camera. -
Method Summary
Modifier and TypeMethodDescriptionCollection<org.graphstream.ui.graphicGraph.GraphicElement>allGraphicElementsIn(org.graphstream.ui.graphicGraph.GraphicGraph graph, EnumSet<org.graphstream.ui.view.util.InteractiveElement> types, double x1, double y1, double x2, double y2) protected voidCompute a transformation matrix that pass from graph units (user space) to pixel units (device space) so that the whole graph is visible.voidcheckVisibility(org.graphstream.ui.graphicGraph.GraphicGraph graph) Process each node to check if it is in the actual view port, and mark invisible nodes.protected booleanedgeContains(org.graphstream.ui.graphicGraph.GraphicElement elt, double x, double y) Check if an edge contains the given point (x,y).org.graphstream.ui.graphicGraph.GraphicElementfindGraphicElementAt(org.graphstream.ui.graphicGraph.GraphicGraph graph, EnumSet<org.graphstream.ui.view.util.InteractiveElement> types, double x, double y) Search for the first GraphicElement among those specified.doubledouble[]org.graphstream.ui.view.util.GraphMetricsprotected doubleprotected doubleprotected doubleprotected doublegetSpritePosition(org.graphstream.ui.graphicGraph.GraphicSprite sprite, Point2D.Double pos, org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units units) Compute the real position of a sprite according to its eventual attachment in graph units.protected Point2D.DoublegetSpritePositionEdge(org.graphstream.ui.graphicGraph.GraphicSprite sprite, Point2D.Double pos, org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units units) Compute the position of a sprite if attached to an edge.protected Point2D.DoublegetSpritePositionFree(org.graphstream.ui.graphicGraph.GraphicSprite sprite, Point2D.Double pos, org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units units) Compute the position of a sprite if it is not attached.protected Point2D.DoublegetSpritePositionNode(org.graphstream.ui.graphicGraph.GraphicSprite sprite, Point2D.Double pos, org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units units) Compute the position of a sprite if attached to a node.org.graphstream.ui.geom.Point3doubledoubleprotected booleanisEdgeIn(org.graphstream.ui.graphicGraph.GraphicEdge edge, double X1, double Y1, double X2, double Y2) Is the given sprite visible in the given area.protected booleanisEdgeVisible(org.graphstream.ui.graphicGraph.GraphicEdge edge) Check if an edge is visible in the current view port.protected booleanisNodeIn(org.graphstream.ui.graphicGraph.GraphicNode node, double X1, double Y1, double X2, double Y2) Is the given node visible in the given area.protected booleanisSpriteIn(org.graphstream.ui.graphicGraph.GraphicSprite sprite, double X1, double Y1, double X2, double Y2) Is the given sprite visible in the given area.protected booleanisSpriteVisible(org.graphstream.ui.graphicGraph.GraphicSprite sprite) Check if a sprite is visible in the current view port.booleanisVisible(org.graphstream.ui.graphicGraph.GraphicElement element) True if the element should be visible on screen.protected booleannodeContains(org.graphstream.ui.graphicGraph.GraphicElement elt, double x, double y) Check if a node contains the given point (x,y).voidpopView(Graphics2D g2) Restore the transform that was used beforepushView(GraphicGraph, Graphics2D)is used.voidpushView(org.graphstream.ui.graphicGraph.GraphicGraph graph, Graphics2D g2) Set the camera view in the given graphics and backup the previous transform of the graphics.voidvoidvoidsetAutoFitView(boolean on) Enable or disable automatic adjustment of the view to see the entire graph.voidsetBounds(double minx, double miny, double minz, double maxx, double maxy, double maxz) voidsetGraphViewport(double minx, double miny, double maxx, double maxy) voidsetPadding(org.graphstream.ui.graphicGraph.GraphicGraph graph) Set the graph padding.voidsetViewCenter(double x, double y) voidsetViewCenter(double x, double y, double z) voidsetViewPercent(double percent) voidsetViewport(double viewportX, double viewportY, double viewportWidth, double viewportHeight) Set the output view port size in pixels.voidsetViewRotation(double theta) Set the rotation angle around the centre.voidsetZoom(double z) Set the zoom (or percent of the graph visible), 1 means the graph is fully visible.protected booleanspriteContains(org.graphstream.ui.graphicGraph.GraphicElement elt, double x, double y) Check if a sprite contains the given point (x,y).protected Point2D.DoublespritePositionPx(org.graphstream.ui.graphicGraph.GraphicSprite sprite) toString()org.graphstream.ui.geom.Point3transformGuToPx(double x, double y, double z) org.graphstream.ui.geom.Point3transformPxToGu(double x, double y) protected voiduserView(Graphics2D g2) Compute a transformation that pass from graph units (user space) to a pixel units (device space) so that the view (zoom and centre) requested by the user is produced.
-
Field Details
-
graph
protected org.graphstream.ui.graphicGraph.GraphicGraph graphThe graph. -
metrics
protected org.graphstream.ui.view.util.GraphMetrics metricsInformation on the graph overall dimension and position. -
autoFit
protected boolean autoFitAutomatic centring of the view. -
center
protected org.graphstream.ui.geom.Point3 centerThe camera centre of view. -
zoom
protected double zoomThe camera zoom. -
Tx
The graph-space -> pixel-space transformation. -
xT
The inverse transform of Tx. -
oldTx
The previous affine transform. -
rotation
protected double rotationThe rotation angle. -
padding
protected org.graphstream.ui.graphicGraph.stylesheet.Values paddingPadding around the graph. -
nodeInvisible
Which node is visible. This allows to mark invisible nodes to fasten visibility tests for nodes, attached sprites and edges. -
gviewport
protected double[] gviewportThe graph view port, if any. The graph view port is a view inside the graph space. It allows to compute the view according to a specified area of the graph space instead of the graph dimensions. -
gviewportDiagonal
protected double gviewportDiagonal
-
-
Constructor Details
-
DefaultCamera
public DefaultCamera(org.graphstream.ui.graphicGraph.GraphicGraph graph) New camera.
-
-
Method Details
-
getViewCenter
public org.graphstream.ui.geom.Point3 getViewCenter()- Specified by:
getViewCenterin interfaceorg.graphstream.ui.view.camera.Camera
-
setViewCenter
public void setViewCenter(double x, double y, double z) - Specified by:
setViewCenterin interfaceorg.graphstream.ui.view.camera.Camera
-
setViewCenter
public void setViewCenter(double x, double y) -
getViewPercent
public double getViewPercent()- Specified by:
getViewPercentin interfaceorg.graphstream.ui.view.camera.Camera
-
setViewPercent
public void setViewPercent(double percent) - Specified by:
setViewPercentin interfaceorg.graphstream.ui.view.camera.Camera
-
getViewRotation
public double getViewRotation()- Specified by:
getViewRotationin interfaceorg.graphstream.ui.view.camera.Camera
-
getMetrics
public org.graphstream.ui.view.util.GraphMetrics getMetrics()- Specified by:
getMetricsin interfaceorg.graphstream.ui.view.camera.Camera
-
toString
-
resetView
public void resetView()- Specified by:
resetViewin interfaceorg.graphstream.ui.view.camera.Camera
-
setBounds
public void setBounds(double minx, double miny, double minz, double maxx, double maxy, double maxz) - Specified by:
setBoundsin interfaceorg.graphstream.ui.view.camera.Camera
-
getGraphDimension
public double getGraphDimension()- Specified by:
getGraphDimensionin interfaceorg.graphstream.ui.view.camera.Camera
-
isVisible
public boolean isVisible(org.graphstream.ui.graphicGraph.GraphicElement element) True if the element should be visible on screen. The method used is to transform the center of the element (which is always in graph units) using the camera actual transformation to put it in pixel units. Then to look in the style sheet the size of the element and to test if its enclosing rectangle intersects the view port. For edges, its two nodes are used. As a speed-up by default if the camera is in automatic fitting mode, all element should be visible, and the test always returns true.- Specified by:
isVisiblein interfaceorg.graphstream.ui.view.camera.Camera- Parameters:
element- The element to test.- Returns:
- True if the element is visible and therefore must be rendered.
-
transformPxToGu
public org.graphstream.ui.geom.Point3 transformPxToGu(double x, double y) - Specified by:
transformPxToGuin interfaceorg.graphstream.ui.view.camera.Camera
-
transformGuToPx
public org.graphstream.ui.geom.Point3 transformGuToPx(double x, double y, double z) - Specified by:
transformGuToPxin interfaceorg.graphstream.ui.view.camera.Camera
-
checkVisibility
public void checkVisibility(org.graphstream.ui.graphicGraph.GraphicGraph graph) Process each node to check if it is in the actual view port, and mark invisible nodes. This method allows for fast node, sprite and edge visibility checking when drawing. This must be called before each rendering (if the view port changed). -
findGraphicElementAt
public org.graphstream.ui.graphicGraph.GraphicElement findGraphicElementAt(org.graphstream.ui.graphicGraph.GraphicGraph graph, EnumSet<org.graphstream.ui.view.util.InteractiveElement> types, double x, double y) Search for the first GraphicElement among those specified. Multiple elements are resolved by priority-InteractiveElement.NODE>InteractiveElement.EDGE>InteractiveElement.SPRITE, (in that order) that contains the point at coordinates (x, y).- Specified by:
findGraphicElementAtin interfaceorg.graphstream.ui.view.camera.Camera- Parameters:
graph- The graph to search for.x- The point abscissa.y- The point ordinate.- Returns:
- The first node or sprite at the given coordinates or null if nothing found.
-
allGraphicElementsIn
public Collection<org.graphstream.ui.graphicGraph.GraphicElement> allGraphicElementsIn(org.graphstream.ui.graphicGraph.GraphicGraph graph, EnumSet<org.graphstream.ui.view.util.InteractiveElement> types, double x1, double y1, double x2, double y2) - Specified by:
allGraphicElementsInin interfaceorg.graphstream.ui.view.camera.Camera
-
getSpritePosition
public Point2D.Double getSpritePosition(org.graphstream.ui.graphicGraph.GraphicSprite sprite, Point2D.Double pos, org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units units) Compute the real position of a sprite according to its eventual attachment in graph units.- Parameters:
sprite- The sprite.pos- Receiver for the sprite 2D position, can be null.units- The units in which the position must be computed (the sprite already contains units).- Returns:
- The same instance as the one given by parameter pos or a new one if pos was null, containing the computed position in the given units.
-
getGraphViewport
public double[] getGraphViewport() -
setGraphViewport
public void setGraphViewport(double minx, double miny, double maxx, double maxy) - Specified by:
setGraphViewportin interfaceorg.graphstream.ui.view.camera.Camera
-
removeGraphViewport
public void removeGraphViewport()- Specified by:
removeGraphViewportin interfaceorg.graphstream.ui.view.camera.Camera
-
pushView
Set the camera view in the given graphics and backup the previous transform of the graphics. CallpopView(Graphics2D)to restore the saved transform. You can only push one time the view.- Parameters:
g2- The Swing graphics to change.
-
popView
Restore the transform that was used beforepushView(GraphicGraph, Graphics2D)is used.- Parameters:
g2- The Swing graphics to restore.
-
autoFitView
Compute a transformation matrix that pass from graph units (user space) to pixel units (device space) so that the whole graph is visible.- Parameters:
g2- The Swing graphics.
-
userView
Compute a transformation that pass from graph units (user space) to a pixel units (device space) so that the view (zoom and centre) requested by the user is produced.- Parameters:
g2- The Swing graphics.
-
setAutoFitView
public void setAutoFitView(boolean on) Enable or disable automatic adjustment of the view to see the entire graph.- Specified by:
setAutoFitViewin interfaceorg.graphstream.ui.view.camera.Camera- Parameters:
on- If true, automatic adjustment is enabled.
-
setZoom
public void setZoom(double z) Set the zoom (or percent of the graph visible), 1 means the graph is fully visible.- Parameters:
z- The zoom.
-
setViewRotation
public void setViewRotation(double theta) Set the rotation angle around the centre.- Specified by:
setViewRotationin interfaceorg.graphstream.ui.view.camera.Camera- Parameters:
theta- The rotation angle in degrees.
-
setViewport
public void setViewport(double viewportX, double viewportY, double viewportWidth, double viewportHeight) Set the output view port size in pixels.- Parameters:
viewportWidth- The width in pixels of the view port.viewportHeight- The width in pixels of the view port.
-
setPadding
public void setPadding(org.graphstream.ui.graphicGraph.GraphicGraph graph) Set the graph padding.- Parameters:
graph- The graphic graph.
-
getPaddingXgu
protected double getPaddingXgu() -
getPaddingYgu
protected double getPaddingYgu() -
getPaddingXpx
protected double getPaddingXpx() -
getPaddingYpx
protected double getPaddingYpx() -
isSpriteVisible
protected boolean isSpriteVisible(org.graphstream.ui.graphicGraph.GraphicSprite sprite) Check if a sprite is visible in the current view port.- Parameters:
sprite- The sprite to check.- Returns:
- True if visible.
-
isEdgeVisible
protected boolean isEdgeVisible(org.graphstream.ui.graphicGraph.GraphicEdge edge) Check if an edge is visible in the current view port.- Parameters:
edge- The edge to check.- Returns:
- True if visible.
-
isNodeIn
protected boolean isNodeIn(org.graphstream.ui.graphicGraph.GraphicNode node, double X1, double Y1, double X2, double Y2) Is the given node visible in the given area.- Parameters:
node- The node to check.X1- The min abscissa of the area.Y1- The min ordinate of the area.X2- The max abscissa of the area.Y2- The max ordinate of the area.- Returns:
- True if the node lies in the given area.
-
isEdgeIn
protected boolean isEdgeIn(org.graphstream.ui.graphicGraph.GraphicEdge edge, double X1, double Y1, double X2, double Y2) Is the given sprite visible in the given area.- Parameters:
edge- The edge to check.X1- The min abscissa of the area.Y1- The min ordinate of the area.X2- The max abscissa of the area.Y2- The max ordinate of the area.- Returns:
- True if the edge lies in the given area.
-
isSpriteIn
protected boolean isSpriteIn(org.graphstream.ui.graphicGraph.GraphicSprite sprite, double X1, double Y1, double X2, double Y2) Is the given sprite visible in the given area.- Parameters:
sprite- The sprite to check.X1- The min abscissa of the area.Y1- The min ordinate of the area.X2- The max abscissa of the area.Y2- The max ordinate of the area.- Returns:
- True if the node lies in the given area.
-
spritePositionPx
-
nodeContains
protected boolean nodeContains(org.graphstream.ui.graphicGraph.GraphicElement elt, double x, double y) Check if a node contains the given point (x,y).- Parameters:
elt- The node.x- The point abscissa.y- The point ordinate.- Returns:
- True if (x,y) is in the given element.
-
edgeContains
protected boolean edgeContains(org.graphstream.ui.graphicGraph.GraphicElement elt, double x, double y) Check if an edge contains the given point (x,y).- Parameters:
elt- The edge.x- The point abscissa.y- The point ordinate.- Returns:
- True if (x,y) is in the given element.
-
spriteContains
protected boolean spriteContains(org.graphstream.ui.graphicGraph.GraphicElement elt, double x, double y) Check if a sprite contains the given point (x,y).- Parameters:
elt- The sprite.x- The point abscissa.y- The point ordinate.- Returns:
- True if (x,y) is in the given element.
-
getSpritePositionFree
protected Point2D.Double getSpritePositionFree(org.graphstream.ui.graphicGraph.GraphicSprite sprite, Point2D.Double pos, org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units units) Compute the position of a sprite if it is not attached.- Parameters:
sprite- The sprite.pos- Where to stored the computed position, if null, the position is created.units- The units the computed position must be given into.- Returns:
- The same instance as pos, or a new one if pos was null.
-
getSpritePositionNode
protected Point2D.Double getSpritePositionNode(org.graphstream.ui.graphicGraph.GraphicSprite sprite, Point2D.Double pos, org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units units) Compute the position of a sprite if attached to a node.- Parameters:
sprite- The sprite.pos- Where to stored the computed position, if null, the position is created.units- The units the computed position must be given into.- Returns:
- The same instance as pos, or a new one if pos was null.
-
getSpritePositionEdge
protected Point2D.Double getSpritePositionEdge(org.graphstream.ui.graphicGraph.GraphicSprite sprite, Point2D.Double pos, org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units units) Compute the position of a sprite if attached to an edge.- Parameters:
sprite- The sprite.pos- Where to stored the computed position, if null, the position is created.units- The units the computed position must be given into.- Returns:
- The same instance as pos, or a new one if pos was null.
-