Class BoundedVoronoiDrawingUtility


  • public class BoundedVoronoiDrawingUtility
    extends Object
    Provides utilities for drawing graphical representations of a BoundedVoronoiDiagram instance.

    Note: This class is under construction and not yet fully tested. Use with caution.

    • Constructor Detail

      • BoundedVoronoiDrawingUtility

        public BoundedVoronoiDrawingUtility​(BoundedVoronoiDiagram diagram,
                                            int width,
                                            int height,
                                            int pad,
                                            Rectangle2D optionalBounds)
        Constructs drawing utility instance for the specified Bounded Voronoi Diagram. An affine transform is created that will scale the diagram to the specified graphics surface.

        The width and height define the size of the intended graphics surface. An affine transform will be created to map the coordinate system of the Voronoi Diagram to the specified graphics surface. The aspect ratio of the diagram will be preserved and fit to use the maximum available space. If desired, an application may specify a padding factor to reserve some blank space around the edges of the diagram.

        Normally, the transform will be initialized using the a rectangle slightly larger than the sample bounds of the diagram, but if desired an application may specify an alternate alternate bounds specification.

        Parameters:
        diagram - a valid instance of a Voronoi Diagram structure
        width - the width of the graphics surface
        height - the height of the graphics surface
        pad - an optional padding factor
        optionalBounds - an alternate bounds specification, or a null if the defaults are to be used.
      • BoundedVoronoiDrawingUtility

        public BoundedVoronoiDrawingUtility​(BoundedVoronoiDiagram diagram,
                                            Rectangle2D clipBounds,
                                            AffineTransform af)
        Constructs an instance for the specified Voronoi diagram
        Parameters:
        diagram - a valid instance
        clipBounds - the bounds for clipping the rendered image, may be larger than those of the diagram instance.
        af - a valid affine transform mapping Cartesian coordinates to pixels.
    • Method Detail

      • getTransform

        public AffineTransform getTransform()
        Gets an affine transform mapping the Cartesian coordinates of the Voronoi Diagram to the pixel coordinates of the graphics surface.
        Returns:
        a valid transform
      • getInverseTransform

        public AffineTransform getInverseTransform()
        Gets an affine transform mapping the pixel coordinates of the graphics surface to the Cartesian coordinates of the Voronoi Diagram.
        Returns:
        a valid transform
      • drawWireframe

        public void drawWireframe​(Graphics g,
                                  Color foreground,
                                  double strokeWidth,
                                  Font font)
        Draws a the edges and vertices of the Voronoi Diagram. The font specification is optional. If it is specified, the vertices will be labeled. If it is null, the vertices will not be labeled. All other specifications are mandatory
        Parameters:
        g - the graphics surface for drawing
        foreground - the color for drawing the graphics
        strokeWidth - the width of the line features to be draw (typically, a value of 2).
        font - an optional font specification for labeling vertices; or null if no labeling is to be performed.
      • drawVertices

        public void drawVertices​(Graphics g,
                                 Color foreground,
                                 Font font,
                                 List<Vertex> vertexList)
        Draws a the vertices of the specified list. The font specification is optional. If it is specified, the vertices will be labeled. If it is null, the vertices will not be labeled. All other specifications are mandatory
        Parameters:
        g - the graphics surface for drawing
        foreground - the color for drawing the graphics
        font - an optional font specification for labeling vertices; or null if no labeling is to be performed.
        vertexList - the list of vertices to be drawn
      • drawPolygons

        public void drawPolygons​(Graphics g,
                                 Paint[] paintSpec,
                                 boolean assignAutomaticColors)
        Performs area-fill operations on the polygons that are defined by the Voronoi Diagram. The polygons are colored according to the specifications in an array of Java Paint or Color objects. The color index from the vertices is used to decide which color to use for rendering. If color indices have not been previously assigned, the calling application may request that this method assign them automatically. If the automatic option is specified, the Paint array must contain at least six object (unique colors are highly recommended).

        Recall that in Java, the Color object implemented the Paint interface. So an array of Color objects is a valid input.

        Parameters:
        g - the graphics surface for drawing
        paintSpec - an array of paint instances corresponding to the color index values of each vertex
        assignAutomaticColors - indicates that the vertices are to be assigned color index values automatically. Doing so will override any color-index values previously stored in the vertices.
      • drawEdges

        public void drawEdges​(Graphics g,
                              Color foreground,
                              double strokeWidth,
                              List<IQuadEdge> edgeList)
        Draws a the edges from the specified list.
        Parameters:
        g - the graphics surface for drawing
        foreground - the color for drawing the graphics
        strokeWidth - the width of the line features to be draw (typically, a value of 2).
        edgeList - the edges to be drawn
      • assignAutomaticColors

        public void assignAutomaticColors()
        Assigns automatic color selections to the vertices and associated polygons in the bounded Voronoi diagram stored when this instance was constructed.

        This method is potentially costly for diagrams containing a large number of vertices. Therefore, it should only be called once when rendering.

        This method assigns six color indices to polygons (in the range 0 to 5). If applications that use automatic color assignment require a custom palette, they must specify and array of Color or Paint instances with at least six elements. If a smaller palette is supplied, the results are undefined.

      • draw

        public void draw​(Graphics g,
                         IBoundedVoronoiStyler specifiedStyler)
        Draws the Bounded Voronoi Diagram using the specified styler

        This method is under development. It is not yet ready for use and may be subject to changes.

        Parameters:
        g - a valid graphic surface
        specifiedStyler - a valid styler implementation, or a null if defaults are to be used