Class ContourPlot

    • Field Detail

      • cp

        private static ContourPlot cp
        Example from source ContourPlot.java draws contour plot of function surface correctly. Need to work on example in IsolinesViz.java.
    • Constructor Detail

      • ContourPlot

        public ContourPlot()
    • Method Detail

      • testIsolinesViz

        public void testIsolinesViz()
      • testContourPlot

        public void testContourPlot()
      • runAlgorithm

        public void runAlgorithm()
        Description copied from class: AlgorithmBase
        Actually runs the algorithm. Implemented by inheriting algorithms.
        Specified by:
        runAlgorithm in class AlgorithmBase
      • b

        public static final int b​(int color)
        Parameters:
        color - ARGB(32bit) or RGB(24bit) value
        Returns:
        blue component(8bit) of specified color.
        Since:
        1.0
        See Also:
        a(int), r(int), g(int), #argb(int, int, int, int), #rgb(int, int, int)
      • g

        public static final int g​(int color)
        Parameters:
        color - ARGB(32bit) or RGB(24bit) value
        Returns:
        green component(8bit) of specified color.
        Since:
        1.0
        See Also:
        a(int), r(int), b(int), #argb(int, int, int, int), #rgb(int, int, int)
      • r

        public static final int r​(int color)
        Parameters:
        color - ARGB(32bit) or RGB(24bit) value
        Returns:
        red component(8bit) of specified color.
        Since:
        1.0
        See Also:
        a(int), g(int), b(int), #argb(int, int, int, int), #rgb(int, int, int)
      • a

        public static final int a​(int color)
        Parameters:
        color - ARGB(32bit) value
        Returns:
        alpha component(8bit) of specified color.
        Since:
        1.0
        See Also:
        r(int), g(int), b(int), #argb(int, int, int, int), #rgb(int, int, int)
      • b_normalized

        public static final double b_normalized​(int color)
        Parameters:
        color - ARGB(32bit) or RGB(24bit) value
        Returns:
        normalized blue component of specified color
        (value in [0.0 .. 1.0]).
        Since:
        1.2
        See Also:
        #b(), r_normalized(int), g_normalized(int), a_normalized(int)
      • g_normalized

        public static final double g_normalized​(int color)
        Parameters:
        color - ARGB(32bit) or RGB(24bit) value
        Returns:
        normalized green component of specified color
        (value in [0.0 .. 1.0]).
        Since:
        1.2
        See Also:
        #g(), r_normalized(int), b_normalized(int), a_normalized(int)
      • r_normalized

        public static final double r_normalized​(int color)
        Parameters:
        color - ARGB(32bit) or RGB(24bit) value
        Returns:
        normalized red component of specified color
        (value in [0.0 .. 1.0]).
        Since:
        1.2
        See Also:
        #r(), b_normalized(int), g_normalized(int), a_normalized(int)
      • a_normalized

        public static final double a_normalized​(int color)
        Parameters:
        color - ARGB(32bit) value
        Returns:
        normalized alpha component of specified color
        (value in [0.0 .. 1.0]).
        Since:
        1.2
        See Also:
        #a(), r_normalized(int), g_normalized(int), a_normalized(int)
      • interpolateColor

        public static int interpolateColor​(int c1,
                                           int c2,
                                           double m)
        Linearly interpolates between the two specified colors.
        c = c1*(1-m) + c2*m
        Parameters:
        c1 - integer packed ARGB color value
        c2 - integer packed ARGB color value, e.g. 0xff00ff00 for opaque green
        m - in [0,1]
        Returns:
        interpolated color
      • computeContourLines

        public static java.util.List<ContourPlot.SegmentDetails> computeContourLines​(double[][] X,
                                                                                     double[][] Y,
                                                                                     double[][] Z,
                                                                                     double isoValue,
                                                                                     int color)
        Computes the contour lines from the grid samples of a bivariate function z(x,y). The resulting line segments are solutions to the equation { (x,y) | z(x,y)=iso } within the grid.

        About indices For cartesian or rectilinear grids, x varies with the inner index of the 2D array, y with the outer index:
        Xij=X[i][j]=X[?][j].
        Yij=Y[i][j]=Y[i][?]

        Parameters:
        X - x-coordinates of the grid points ( (x,y,z)ij = (Xij,Yij,Zij) )
        Y - y-coordinates of the grid points ( (x,y,z)ij = (Xij,Yij,Zij) )
        Z - z-coordinates of the grid points ( (x,y,z)ij = (Xij,Yij,Zij) )
        isoValue - the iso value for which the contour (iso) lines should be computed
        color - integer packed ARGB color value the returned line segments should have, e.g. 0xff00ff00 for opaque green.
        Returns:
        list of line segments that form the contour lines. There is no particular order so subsequent segments are not necessarily adjacent.
      • computeContourBands

        public static java.util.List<ContourPlot.TriangleDetails> computeContourBands​(double[][] X,
                                                                                      double[][] Y,
                                                                                      double[][] Z,
                                                                                      double isoValue1,
                                                                                      double isoValue2,
                                                                                      int c1,
                                                                                      int c2)
        Computes the contour bands from the grid samples of a bivariate function z(x,y). The resulting triangles are solutions to the equation { (x,y) | iso1 < z(x,y) < iso2 } within the grid.

        About indices For cartesian or rectilinear grids, x varies with the inner index of the 2D array, y with the outer index:
        Xij=X[i][j]=X[?][j].
        Yij=Y[i][j]=Y[i][?]

        Parameters:
        X - x-coordinates of the grid points ( (x,y,z)ij = (Xij,Yij,Zij) )
        Y - y-coordinates of the grid points ( (x,y,z)ij = (Xij,Yij,Zij) )
        Z - z-coordinates of the grid points ( (x,y,z)ij = (Xij,Yij,Zij) )
        isoValue1 - the lower bound for values of the iso bands
        isoValue2 - the upper bound for values of the iso bands
        c1 - color for the isoValue1
        c2 - color for the isoValue2, values in between iso1 and iso2 will have their color linearly interpolated
        Returns:
        list of triangles that form the iso bands. The order of triangles does NOT imply any adjacency between them.
      • computeContourLines

        public static java.util.List<ContourPlot.SegmentDetails> computeContourLines​(double[][] uniformGridSamples,
                                                                                     double isoValue,
                                                                                     int color)
        Computes the contour lines from the grid samples of a bivariate function z(x,y)
        with implicit integer valued (x,y) = (i,j).
        The resulting line segments are solutions to the equation { (x,y) | z(x,y)=iso } within the grid.

        The lines are computed using the Meandering Triangles algorithm which divides each square cell of the grid into 2 triangle cells first before computing isovalue intersections on the triangle sides. The more well known Marching Squares algorithm has significantly more cell cases to check, which is why Meandering Triangles was preferred here.

        Parameters:
        uniformGridSamples - z-coordinates of the grid points ( (x,y,z)ij = (i,j,Zij) )
        isoValue - the iso value for which the contour (iso) lines should be computed
        color - integer packed ARGB color value the returned line segments should have, e.g. 0xff00ff00 for opaque green.
        Returns:
        list of line segments that form the contour lines. There is no particular order so subsequent segments are not necessarily adjacent.
      • computeContourBands

        public static java.util.List<ContourPlot.TriangleDetails> computeContourBands​(double[][] uniformGridSamples,
                                                                                      double isoValue1,
                                                                                      double isoValue2,
                                                                                      int c1,
                                                                                      int c2)
        Computes the contour bands from the grid samples of a bivariate function z(x,y)
        with implicit integer valued (x,y) = (i,j).
        The resulting triangles are solutions to the equation { (x,y) | iso1 < z(x,y) < iso2 } within the grid.

        The triangles are computed using the Meandering Triangles algorithm which divides each square cell of the grid into 2 triangle cells first before computing isovalue intersections on the triangle sides. The more well known Marching Squares algorithm has significantly more cell cases to check, which is why Meandering Triangles was preferred here.

        Parameters:
        uniformGridSamples - z-coordinates of the grid points ( (x,y,z)ij = (i,j,Zij) )
        isoValue1 - the lower bound for values of the iso bands
        isoValue2 - the upper bound for values of the iso bands
        c1 - color for the isoValue1
        c2 - color for the isoValue2, values in between iso1 and iso2 will have their color linearly interpolated
        Returns:
        list of triangles that form the iso bands. The order of triangles does NOT imply any adjacency between them.
      • celltype

        static int celltype​(boolean v1,
                            boolean v2,
                            boolean v3)
      • celltype

        static int celltype​(boolean v11,
                            boolean v21,
                            boolean v31,
                            boolean v12,
                            boolean v22,
                            boolean v32)
      • interpolateToValue

        static double interpolateToValue​(double lower,
                                         double upper,
                                         double iso)
        Returns m of the equation: iso = lower*(1-m) + upper*m
        which is: m = (iso-lower)/(upper-lower)
        Parameters:
        lower - value
        upper - value
        iso - value in between lower and upper
        Returns:
        m
      • clamp_0_255

        public final int clamp_0_255​(int val)
        Clamps a value to the range [0,255]. Returns 0 for values less than 0, 255 for values greater than 255, and the value it self when in range.
        Parameters:
        val - value to be clamped
        Returns:
        value clamped to [0,255]
      • clamp_0_1

        public static double clamp_0_1​(double val)
        Clamps a value to the range [0.0, 1.0]. Returns 0.0 for values less than 0, 1.0 for values greater than 1.0, and the value it self when in range.
        Parameters:
        val - value to be clamped
        Returns:
        value clamped to [0.0, 1.0]
      • requireAreaInImageBounds

        public static void requireAreaInImageBounds​(int xStart,
                                                    int yStart,
                                                    int width,
                                                    int height,
                                                    ContourPlot.ImgBase<?> img)
        Throws an IllegalArgumentException when the specified area is not within the bounds of the specified image, or if the area is not positive. This is used for parameter evaluation.
        Parameters:
        xStart - left boundary of the area
        yStart - top boundary of the area
        width - of the area
        height - of the area
        img - the area has to fit in.
        Throws:
        java.lang.IllegalArgumentException - when area not in image bounds or not area not positive