Class DefaultCamera
- All Implemented Interfaces:
org.graphstream.ui.view.camera.Camera
public class DefaultCamera
extends java.lang.Object
implements 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 ?".
-
Constructor Summary
Constructors Constructor Description DefaultCamera(org.graphstream.ui.graphicGraph.GraphicGraph graph)New camera. -
Method Summary
Modifier and Type Method Description java.util.Collection<org.graphstream.ui.graphicGraph.GraphicElement>allGraphicElementsIn(org.graphstream.ui.graphicGraph.GraphicGraph graph, java.util.EnumSet<org.graphstream.ui.view.util.InteractiveElement> types, double x1, double y1, double x2, double y2)voidcheckVisibility(org.graphstream.ui.graphicGraph.GraphicGraph graph)Process each node to check if it is in the actual view port, and mark invisible nodes.org.graphstream.ui.graphicGraph.GraphicElementfindGraphicElementAt(org.graphstream.ui.graphicGraph.GraphicGraph graph, java.util.EnumSet<org.graphstream.ui.view.util.InteractiveElement> types, double x, double y)Search for the first GraphicElement among those specified.doublegetGraphDimension()double[]getGraphViewport()org.graphstream.ui.view.util.GraphMetricsgetMetrics()java.awt.geom.Point2D.DoublegetSpritePosition(org.graphstream.ui.graphicGraph.GraphicSprite sprite, java.awt.geom.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.org.graphstream.ui.geom.Point3getViewCenter()doublegetViewPercent()doublegetViewRotation()booleanisVisible(org.graphstream.ui.graphicGraph.GraphicElement element)True if the element should be visible on screen.voidpopView(java.awt.Graphics2D g2)Restore the transform that was used beforepushView(GraphicGraph, Graphics2D)is used.voidpushView(org.graphstream.ui.graphicGraph.GraphicGraph graph, java.awt.Graphics2D g2)Set the camera view in the given graphics and backup the previous transform of the graphics.voidremoveGraphViewport()voidresetView()voidsetAutoFitView(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.java.lang.StringtoString()org.graphstream.ui.geom.Point3transformGuToPx(double x, double y, double z)org.graphstream.ui.geom.Point3transformPxToGu(double x, double y)
-
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
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
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, java.util.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 java.util.Collection<org.graphstream.ui.graphicGraph.GraphicElement> allGraphicElementsIn(org.graphstream.ui.graphicGraph.GraphicGraph graph, java.util.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 java.awt.geom.Point2D.Double getSpritePosition(org.graphstream.ui.graphicGraph.GraphicSprite sprite, java.awt.geom.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
public void pushView(org.graphstream.ui.graphicGraph.GraphicGraph graph, java.awt.Graphics2D g2)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
public void popView(java.awt.Graphics2D g2)Restore the transform that was used beforepushView(GraphicGraph, Graphics2D)is used.- Parameters:
g2- The Swing graphics to restore.
-
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.
-