Package nub.core

Class Graph

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Graph.Type
      Enumerates the graph types.
      static class  Graph.Visibility
      Enumerates the different visibility states an object may have respect to the bounding volume.
    • Constructor Summary

      Constructors 
      Constructor Description
      Graph​(Object context, int width, int height)
      Same as this(context, width, height, Type.PERSPECTIVE).
      Graph​(Object context, int width, int height, Node eye)
      Same as this(context, width, height, eye, Type.PERSPECTIVE).
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addBehavior​(Node node, BiConsumer<Graph,​Node> behavior)
      Adds a custom node behavior to be executed for this scene render() algorithm.
      void addBehavior​(Node node, Consumer<Node> behavior)
      Same as setBehavior(node, (g, n) -> behavior.accept(n)).
      void align()
      Same as align((String)null).
      void align​(String tag)
      Same as if (tag == null || node(tag) != null) align(node(tag)).
      void align​(Node node)
      Aligns the node (use null for the world) with the eye().
      float aspectRatio()
      Returns the width() to height() aspect ratio of the display window.
      Vector at()
      2D eyes return the position.
      Graph.Visibility ballVisibility​(Vector center, float radius)
      Returns Graph.Visibility.VISIBLE, Graph.Visibility.INVISIBLE, or Graph.Visibility.SEMIVISIBLE, depending whether the ball (of radius radius and center center) is visible, invisible, or semi-visible, respectively.
      float ballZFar()
      The far clipping plane is positioned at a distance equal to zClippingCoefficient() * radius() behind the center():
      float ballZNear()
      The clipping planes' positions depend on the radius() and center() rather than being fixed small-enough and large-enough values.
      void beginHUD()
      Begin Heads Up Display (HUD) so that drawing can be done using 2D screen coordinates.
      float[][] bounds()
      Returns the bounds plane equations.
      Graph.Visibility boxVisibility​(Vector corner1, Vector corner2)
      Returns Graph.Visibility.VISIBLE, Graph.Visibility.INVISIBLE, or Graph.Visibility.SEMIVISIBLE, depending whether the axis aligned box (defined by corners p1 and p2) is visible, invisible, or semi-visible, respectively.
      static List<Node> branch​(Node node)
      Collects node and all its descendant nodes.
      void cad​(float roll, float pitch)
      Same as rotateCAD(roll, pitch, new Vector(0, 1, 0), Graph.inertia).
      void cad​(float roll, float pitch, Vector upVector)
      Same as rotateCAD(roll, pitch, upVector, Graph.inertia).
      void cad​(float roll, float pitch, Vector upVector, float inertia)
      Defines an axis which the eye rotates around.
      static Float castToFloat​(Object o)
      Cast o to a Float.
      static Integer castToInt​(Object o)
      Cast o to an Integer.
      Vector center()
      Center of the ball (defined in world coordinates) used in eye motions interaction (e.g., shift(float, float, float), spin(int, int, int, int), turn(float, float, float)) and interpolation routines (e.g., fit()).
      void clearTags()
      Removes all tags so that node(String) returns null.
      static void clearTree()
      Same as for(Node node : _leadingNodes()) detach(node).
      void closeContext()
      Ends the rendering process (see render(Node)).
      Object context()
      Returns the main renderer context.
      void disableTagging​(Node node)
      Disables tagging the node.
      Vector displacement​(Vector vector)
      Same as return displacement(vector, null).
      Vector displacement​(Vector vector, Node node)
      Converts vector displacement given in screen space to the node coordinate system.
      float distanceToBound​(int index, Vector position)
      Returns the signed distance between point position and plane index in world units.
      void draw()
      Paint method which is called just after your main event loop.
      void endHUD()
      Ends Heads Up Display (HUD).
      Node eye()
      Returns the associated eye.
      void fit()
      Moves the eye so that the ball defined by center() and radius() is visible and fits the window.
      void fit​(float duration)
      Moves the eye during duration milliseconds so that the ball defined by center() and radius() is visible and fits the window.
      void fit​(int x, int y, int width, int height)
      Moves the eye so that the rectangular screen region defined by x, y, width, height (pixel units, with origin in the upper left corner) fits the screen.
      void fit​(int x, int y, int width, int height, float duration)
      Smoothly moves the eye during duration milliseconds so that the rectangular screen region defined by rectangle (pixel units, with origin in the upper left corner) fits the screen.
      void fit​(Node node)
      Convenience function that simply calls fit(node, 0).
      void fit​(Node node, float duration)
      Smoothly interpolates the eye on a interpolator path so that it goes to node.
      void fit​(Vector corner1, Vector corner2)
      Moves the eye so that the world axis aligned box defined by corner1 and corner2 is entirely visible.
      void fit​(Vector corner1, Vector corner2, float duration)
      Smoothly moves the eye during duration milliseconds so that the world axis aligned box defined by corner1 and corner2 is entirely visible.
      void fitFOV()
      Changes the eye() fov() so that the entire scene (defined by center() and radius()) is visible.
      void fitFOV​(float duration)
      Rescales the fov() duration milliseconds so that the ball defined by center and radius is visible and fits the window.
      void focus()
      Same as focus((String)null).
      void focus​(String tag)
      Same as if (tag == null || node(tag) != null) focus(node(tag)).
      void focus​(Node node)
      Focuses the node (use null for the world) with the eye().
      float fov()
      Retrieves the scene field-of-view in radians.
      boolean hasFocus​(int pixelX, int pixelY)
      Returns whether or not the scene has focus or not under the given pixel.
      boolean hasTag​(String tag, Node node)
      Returns true if node(tag) (see node(String)) returns node and false otherwise.
      boolean hasTag​(Node node)
      Same as return hasTag(null, node).
      int height()
      Returns height of the screen window.
      float hfov()
      Same as return type() == Type.PERSPECTIVE ? radians(eye().magnitude() * aspectRatio()) : eye().magnitude().
      void interact​(Object... gesture)
      Same as interact((String)null, gesture).
      void interact​(String tag, Object... gesture)
      Same as if (tag == null || node(tag) != null) interact(node(tag), gesture).
      void interact​(Node node, Object... gesture)
      Call the node (or the eye() if node is null) interact gesture parser function set either with Node.setInteraction(Consumer) or Node.setInteraction(BiConsumer).
      boolean is2D()  
      boolean is3D()  
      boolean isConeBackFacing​(Vector vertex, ArrayList<Vector> normals)
      Returns true if the given cone is back-facing the eye and false otherwise.
      boolean isConeBackFacing​(Vector vertex, Vector[] normals)
      Returns true if the given cone is back-facing the eye and false otherwise.
      boolean isConeBackFacing​(Vector vertex, Vector axis, float angle)
      Returns true if the given cone is back-facing the eye and false otherwise.
      boolean isConeFrontFacing​(Vector vertex, ArrayList<Vector> normals)
      Same as return !isConeBackFacing(vertex, normals).
      boolean isConeFrontFacing​(Vector vertex, Vector[] normals)
      Same as !isConeBackFacing(vertex, normals).
      boolean isConeFrontFacing​(Vector vertex, Vector axis, float angle)
      Same as return !isConeBackFacing(vertex, axis, angle).
      boolean isEye​(Node node)
      Checks whether or not the given node is the eye().
      boolean isFaceBackFacing​(Vector vertex, Vector normal)
      Returns true if the given face is back-facing the camera.
      boolean isFaceBackFacing​(Vector a, Vector b, Vector c)
      Returns true if the given face is back-facing the eye.
      boolean isFaceFrontFacing​(Vector vertex, Vector normal)
      Same as return !isFaceBackFacing(vertex, normal).
      boolean isFaceFrontFacing​(Vector a, Vector b, Vector c)
      Same as return !isFaceBackFacing(a, b, c).
      static boolean isNumInstance​(Object o)
      Returns true if o is instance of Integer, Float or Double, and false otherwise.
      boolean isOffscreen()
      Returns true if this scene is off-screen and false otherwise.
      boolean isPointVisible​(float x, float y, float z)
      Same as return isPointVisible(new Vector(x, y, z)).
      boolean isPointVisible​(Vector point)
      Returns true if point is visible (i.e, lies within the eye bounds) and false otherwise.
      boolean isTagged​(Node node)
      Returns true if the node is currently being tagged and false otherwise.
      boolean isTagValid()
      Same as isTagValid(null).
      boolean isTagValid​(String tag)
      Returns true if some node is tagged with tag (which may be {code null}) and false otherwise.
      long lastUpdate()
      Vector location​(Vector pixel)
      Convenience function that simply returns location(pixel, null).
      Vector location​(Vector pixel, Node node)
      Returns the node coordinates of pixel.
      void lookAround​(float deltaX, float deltaY)
      Same as lookAround(deltaX, deltaY, Graph.inertia).
      void lookAround​(float deltaX, float deltaY, float inertia)
      Look around (without translating the eye) according to angular displacements deltaX and deltaY expressed in radians.
      void lookAt​(Vector target)
      2D eyes simply call node().setPosition(target.x(), target.y()).
      void moveForward​(float delta)
      Same as moveForward(delta, Graph.inertia).
      void moveForward​(float delta, float inertia)
      Same as translateEye(0, 0, delta / (zNear() - zFar())).
      Vector ndcToScreenDisplacement​(Vector vector)
      Converts vector displacement from normalized device coordinates (NDC) to screen space.
      Vector ndcToScreenLocation​(Vector vector)
      Converts vector location from normalized device coordinates (NDC) to screen space.
      Node node()
      Same as return node(null).
      Node node​(String tag)
      Returns the node tagged with tag (which may be null) which is usually set by ray casting (see updateTag(String, int, int)).
      static List<Node> nodes()
      Returns a list of all the nodes that are reachable by the render() algorithm.
      void openContext()
      Begins the rendering process (see render(Node)).
      void pixelToLine​(int pixelX, int pixelY, Vector origin, Vector direction)
      Gives the coefficients of a 3D half-line passing through the eye position and pixel (pixelX,pixelY).
      float pixelToSceneRatio​(Vector position)
      Returns the pixel to scene (units) ratio at position.
      void pre()
      Paint method which is called just before your main event loop starts.
      Matrix projection()
      Returns the cached projection matrix computed at openContext().
      Matrix projectionView()
      Returns the projection times view cached matrix computed at openContext()}.
      Matrix projectionViewInverse()
      Returns the projection times view inverse matrix.
      float radius()
      Radius of the ball (defined in world coordinates) used in eye motions interaction (e.g., shift(float, float, float), spin(int, int, int, int), turn(float, float, float)) and interpolation routines (e.g., fit()).
      void randomize​(Node node)
      Same as node.randomize(center(), radius(), is3D()).
      Node randomNode()
      Same as return Node.random(this).
      void removeTag()
      Same as removeTag(null).
      void removeTag​(String tag)
      Removes the tag so that a call to isTagValid(String) will return false.
      void render()
      Renders the node tree onto the context() from the eye() viewpoint.
      void render​(Node subtree)
      Calls openContext(), then renders the node subtree (or the whole tree when subtree is null) onto the context() from the eye() viewpoint, and calls closeContext().
      void resetBehavior​(Node node)
      Resets the node custom behavior which is set with addBehavior(Node, BiConsumer).
      Vector rightVector()
      Returns the normalized right vector of the eye, defined in the world coordinate system.
      float sceneToPixelRatio​(Vector position)
      Returns the ratio of scene (units) to pixel at position.
      Vector screenDisplacement​(Vector vector)
      Same as return screenDisplacement(vector, null).
      Vector screenDisplacement​(Vector vector, Node node)
      Converts the node vector displacement to screen space.
      Vector screenLocation​(Node node)
      Converts the node origin location to screen space.
      Vector screenLocation​(Vector vector)
      Converts vector location from world to screen space.
      Vector screenLocation​(Vector vector, Node node)
      Converts vector location from node to screen.
      Vector screenToNDCDisplacement​(Vector vector)
      Converts vector displacement from screen space to normalized device coordinates (NDC).
      Vector screenToNDCLocation​(Vector vector)
      Converts vector location from screen space to normalized device coordinates (NDC).
      void setBoundingBall​(Vector center, float radius)
      Sets the ball for zNear() and zFar() computations within the ballZNear() and ballZFar() functions.
      void setCenter​(Vector center)
      Sets center().
      void setEye​(Node eye)
      Replaces the current eye() with eye.
      void setFOV​(float fov)
      Sets the eye() Node.worldMagnitude(), according to fov (field-of-view) which is expressed in radians.
      void setHeight​(int height)
      Sets the graph height() in pixels.
      void setHFOV​(float hfov)
      Sets the hfov() of the eye() (in radians).
      void setRadius​(float radius)
      Sets radius().
      void setType​(Graph.Type type)
      Defines the graph _type according to the projection of the scene.
      void setUpVector​(Vector up)
      Convenience function that simply calls setUpVector(up, true).
      void setUpVector​(Vector up, boolean noMove)
      Rotates the eye so that its upVector() becomes up (defined in the world coordinate system).
      void setViewDirection​(Vector direction)
      Rotates the eye so that its viewDirection() is direction (defined in the world coordinate system).
      void setWidth​(int width)
      Sets the graph width() in pixels.
      void setZFar​(Supplier<Float> zFar)
      Sets the zFar() computation routine.
      void setZNear​(Supplier<Float> zNear)
      Sets the zNear() computation routine.
      void shift​(float dx, float dy, float dz)
      Same as shift(dx, dy, dz, Graph.inertia).
      void shift​(float dx, float dy, float dz, float inertia)
      Same as shift((String)null, dx, dy, dz, inertia).
      void shift​(String tag, float dx, float dy, float dz)
      Same as shift(tag, dx, dy, dz, Graph.inertia).
      void shift​(String tag, float dx, float dy, float dz, float inertia)
      Same as if (tag == null || node(tag) != null) shift(node(tag), dx, dy, dz, inertia).
      void shift​(Node node, float dx, float dy, float dz)
      Same as shift(node, dx, dy, dz, Graph.inertia).
      void shift​(Node node, float dx, float dy, float dz, float inertia)
      Translates the node (use null for the world) according to (dx, dy, dz) defined in screen-space ((a box of width() * height() * 1 dimensions), and inertia which should be in [0..1], 0 no inertia & 1 no friction.
      void spin​(int pixel1X, int pixel1Y, int pixel2X, int pixel2Y)
      Same as spin(pixel1X, pixel1Y, pixel2X, pixel2Y, Graph.inertia).
      void spin​(int pixel1X, int pixel1Y, int pixel2X, int pixel2Y, float inertia)
      Same as spin((String)null, pixel1X, pixel1Y, pixel2X, pixel2Y, inertia).
      void spin​(String tag, int pixel1X, int pixel1Y, int pixel2X, int pixel2Y)
      Same as spin(tag, pixel1X, pixel1Y, pixel2X, pixel2Y, Graph.inertia).
      void spin​(String tag, int pixel1X, int pixel1Y, int pixel2X, int pixel2Y, float inertia)
      Same as if (tag == null || node(tag) != null) spin(node(tag), pixel1X, pixel1Y, pixel2X, pixel2Y, inertia).
      void spin​(Node node, int pixel1X, int pixel1Y, int pixel2X, int pixel2Y)
      Same as spin(node, pixel1X, pixel1Y, pixel2X, pixel2Y, Graph.inertia).
      void spin​(Node node, int pixel1X, int pixel1Y, int pixel2X, int pixel2Y, float inertia)
      Rotates the node (use null for the world) using an arcball interface, from points (pixel1X, pixel1Y) to (pixel2X, pixel2Y) pixel positions.
      void tag​(int pixelX, int pixelY)
      Same as tag(null, pixelX, pixelY).
      void tag​(String tag, int pixelX, int pixelY)
      Same as updateTag(String, int, int) but doesn't return immediately the tagged node.
      void tag​(String tag, Node node)
      Tags the node (with tag which may be null) (see node(String)).
      void tag​(Node node)
      Same as tag(null, node).
      void togglePerspective()
      Shifts the graph _type between Graph.Type.PERSPECTIVE and Graph.Type.ORTHOGRAPHIC while trying to keep the fov().
      boolean tracks​(Node node, int pixelX, int pixelY)
      Casts a ray at pixel position (pixelX, pixelY) and returns true if the ray picks the node and false otherwise.
      void turn​(float roll, float pitch, float yaw)
      Same as turn(roll, pitch, yaw, Graph.inertia).
      void turn​(float roll, float pitch, float yaw, float inertia)
      Same as turn((String)null, roll, pitch, yaw, inertia).
      void turn​(String tag, float roll, float pitch, float yaw)
      Same as turn(tag, roll, pitch, yaw, Graph.inertia).
      void turn​(String tag, float roll, float pitch, float yaw, float inertia)
      Same as if (tag == null || node(tag) != null) turn(node(tag), roll, pitch, yaw, inertia).
      void turn​(Node node, float roll, float pitch, float yaw)
      Same as turn(node, roll, pitch, yaw, Graph.inertia).
      void turn​(Node node, float roll, float pitch, float yaw, float inertia)
      Rotates the node (use null for the world) around the x-y-z screen axes according to roll, pitch and yaw radians, resp., and according to inertia which should be in [0..1], 0 no inertia & 1 no friction.
      Graph.Type type()
      Returns the graph type.
      void untag​(Node node)
      Removes all tags pointing to the node.
      Node updateTag​(int pixelX, int pixelY)
      Same as return updateTag(null, null, pixelX, pixelY).
      Node updateTag​(int pixelX, int pixelY, List<Node> nodeList)
      Same as return track(null, pixelX, pixelY, nodeList).
      Node updateTag​(int pixelX, int pixelY, Node[] nodeArray)
      Same as return track(null, pixelX, pixelY, nodeArray).
      Node updateTag​(String tag, int pixelX, int pixelY)
      Tags (with tag which may be null) the node in nodes() picked with ray-casting at pixel pixelX, pixelY and returns it (see node(String)).
      Node updateTag​(String tag, int pixelX, int pixelY, List<Node> nodeList)
      Same as updateTag(String, int, int, Node[]) but using a node list instead of an array.
      Node updateTag​(String tag, int pixelX, int pixelY, Node[] nodeArray)
      Tags (with tag which may be null) the node in nodeArray picked with ray-casting at pixel pixelX, pixelY and returns it (see node(String)).
      Node updateTag​(Node subtree, int pixelX, int pixelY)
      Same as return return updateTag(subtree, null, pixelX, pixelY).
      Node updateTag​(Node subtree, String tag, int pixelX, int pixelY)
      Tags (with tag which may be null) the node in the subtree (or the whole tree when subtree is null) picked with ray-casting at pixel pixelX, pixelY and returns it (see node(String)).
      Vector upVector()
      Returns the normalized up vector of the eye, defined in the world coordinate system.
      Matrix view()
      Returns the cached view matrix computed at _bind().
      Vector viewDirection()
      Returns the normalized view direction of the eye, defined in the world coordinate system.
      int width()
      Returns width of the screen window.
      float zFar()
      Returns the far clipping plane distance used to compute the projection() matrix.
      Supplier<Float> zFarSupplier()
      Retrieves the current zFar() computation routine.
      float zNear()
      Returns the near clipping plane distance used to compute the projection() matrix.
      Supplier<Float> zNearSupplier()
      Retrieves the current zNear() computation routine.
      void zoom​(float delta)
      Same as zoom(delta, Graph.inertia).
      void zoom​(float delta, float inertia)
      Same as zoom((String)null, delta, inertia).
      void zoom​(String tag, float delta)
      Same as zoom(tag, delta, Graph.inertia).
      void zoom​(String tag, float delta, float inertia)
      Same as if (tag == null || node(tag) != null) zoom(node(tag), delta, inertia).
      void zoom​(Node node, float delta)
      Same as zoom(node, delta, Graph.inertia).
      void zoom​(Node node, float delta, float inertia)
      Scales the node (use null for the world) according to delta and inertia which should be in [0..1], 0 no inertia & 1 no friction.