Class ContourPlot.CoordSysRenderer
- java.lang.Object
-
- gov.nih.mipav.model.algorithms.ContourPlot.CoordSysRenderer
-
- All Implemented Interfaces:
ContourPlot.PDFRenderer,ContourPlot.Renderer
- Enclosing class:
- ContourPlot
public class ContourPlot.CoordSysRenderer extends java.lang.Object implements ContourPlot.Renderer
The CoordSysRenderer is aContourPlot.Rendererthat displays a coordinate system. This coordinate system is enclosed by 4 axes that form a rectangle around the area that displays the contents of the coordinate system.The upper x-axis and right y-axis feature the labels (names) of the axes. The lower x-axis and the left y-axis feature tick marks and labels that help to orientate and read off coordinates. The positioning and labeling of the tick marks is done by a
ContourPlot.TickMarkGeneratorwhich is per default an instance ofContourPlot.ExtendedWilkinson. For each tick a vertical or horizontal guide line is drawn across the area of the coordinate system.What coordinate range the coordinate system area corresponds to is controlled by the coordinate view (see
setCoordinateView(double, double, double, double)) and defaults to [-1,1] for both axes. The contents that are drawn inside the coordinate area are rendered by the content renderer (seesetContent(Renderer)). If that renderer implements theContourPlot.AdaptableViewinterface it will be passed the view matrix corresponding to the coordinate view. The content renderer will be able to draw within the viewport defined by the coordinate system area of this CoordSysRenderer.Optionally a
ContourPlot.Rendererfor drawing a legend (such as theContourPlot.Legendclass) can be set to either the bottom or right hand side of the coordinate system (can also use both areas at once). Use#setLegendBottom(Renderer)orsetLegendRight(Renderer)to do so. The legend area size can be partially controlled by#setLegendBottomHeight(int)andsetLegendRightWidth(int)if this is needed.The overlay renderer (
#setOverlay(Renderer)) can be used to finally draw over all of the renderer viewport.For interacting with this
ContourPlot.CoordSysRendererthere already exist implementations of MouseListeners for panning and zooming (seeContourPlot.CoordSysPanningandContourPlot.CoordSysScrollZoom).- Author:
- hageldave
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description CoordSysRenderer()Sets up a CoordSysRenderer with the default color scheme
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ContourPlot.CoordSysRendereraddCoordinateViewListener(ContourPlot.CoordinateViewListener l)Adds aContourPlot.CoordinateViewListenerto this renderer which will be notified whenever the coordinate view changes (i.e. whensetCoordinateView(double, double, double, double)is called)ContourPlot.ColorSchemegetColorScheme()java.awt.geom.Rectangle2DgetCoordinateView()Returns the coordinate view, which is the range of x and y coordinates visible in the coordinate system.java.awt.geom.Rectangle2DgetCoordSysArea()java.lang.StringgetxAxisLabel()java.lang.StringgetyAxisLabel()booleanisEnabled()Whether this renderer is enabled or not.ContourPlot.CoordSysRendererremoveActionListener(ContourPlot.CoordinateViewListener l)Removes the specifiedContourPlot.CoordinateViewListenerfrom this renderer.voidrenderFallback(java.awt.Graphics2D g, java.awt.Graphics2D p, int w, int h)Renders thisContourPlot.Renderer's 'scene'.voidrenderPDF(org.apache.pdfbox.pdmodel.PDDocument doc, org.apache.pdfbox.pdmodel.PDPage page, int x, int y, int w, int h)Renders this PDFRenderers contents, that is creating pdf elements and appending them to the specified page within the corresponding document.ContourPlot.RenderersetContent(ContourPlot.Renderer content)Sets the content renderer that will draw into the area of the coordinate system.ContourPlot.CoordSysRenderersetCoordinateView(double minX, double minY, double maxX, double maxY)Sets the coordinate view.ContourPlot.CoordSysRenderersetCoordinateView(java.awt.geom.Rectangle2D viewRect)Sets the coordinate view.protected ContourPlot.CoordSysRenderersetCoordinateViewRect(double x, double y, double w, double h)voidsetDirty()Sets theisDirtystate of this CoordSysRenderer to true.ContourPlot.RenderersetLegendRight(ContourPlot.Renderer legend)Sets the renderer that will draw the legend to the right of the coordinate system.ContourPlot.CoordSysRenderersetLegendRightWidth(int legendRightWidth)Sets the width of the legend area right to the coordinate system.protected voidsetupAndLayout()Sets up pretty much everything.protected voidsetupCoordSysRenderer()Helper method to setup the CoordSysRendererjava.awt.geom.Point2DtransformAWT2CoordSys(java.awt.geom.Point2D awtPoint, int canvasheight)Transforms a location in AWT coordinates (y axis extends to bottom) on this renderer to the corresponding coordinates in the coordinate system view (in GL coords).java.awt.geom.Point2DtransformGL2CoordSys(java.awt.geom.Point2D point)Transforms a location in GL coordinates on this renderer to the corresponding coordinates in the coordinate system view.protected ContourPlot.CoordSysRendererupdateColors()Helper method to update the colors if the color scheme is changed.protected voidupdateLegendColorScheme(ContourPlot.Renderer legend)
-
-
-
Field Detail
-
preContentLinesR
protected ContourPlot.LinesRenderer preContentLinesR
-
preContentTextR
protected ContourPlot.TextRenderer preContentTextR
-
postContentLinesR
protected ContourPlot.LinesRenderer postContentLinesR
-
postContentTextR
protected ContourPlot.TextRenderer postContentTextR
-
overlay
protected ContourPlot.Renderer overlay
-
content
protected ContourPlot.Renderer content
-
legendRight
protected ContourPlot.Renderer legendRight
-
legendBottom
protected ContourPlot.Renderer legendBottom
-
legendRightWidth
protected int legendRightWidth
-
legendBottomHeight
protected int legendBottomHeight
-
legendRightViewPort
protected java.awt.Rectangle legendRightViewPort
-
legendBottomViewPort
protected java.awt.Rectangle legendBottomViewPort
-
currentViewPort
protected java.awt.Rectangle currentViewPort
-
coordinateView
protected java.awt.geom.Rectangle2D coordinateView
-
tickMarkGenerator
protected ContourPlot.TickMarkGenerator tickMarkGenerator
-
axes
protected ContourPlot.Lines axes
-
ticks
protected ContourPlot.Lines ticks
-
guides
protected ContourPlot.Lines guides
-
tickMarkLabels
protected java.util.LinkedList<ContourPlot.Text> tickMarkLabels
-
xAxisLabelText
protected ContourPlot.Text xAxisLabelText
-
yAxisLabelText
protected ContourPlot.Text yAxisLabelText
-
xticks
protected double[] xticks
-
yticks
protected double[] yticks
-
viewportwidth
protected int viewportwidth
-
viewportheight
protected int viewportheight
-
isDirty
protected boolean isDirty
-
tickColor
protected java.util.function.IntSupplier tickColor
-
guideColor
protected java.util.function.IntSupplier guideColor
-
textColor
protected java.util.function.IntSupplier textColor
-
paddingLeft
protected int paddingLeft
-
paddingRight
protected int paddingRight
-
paddingTop
protected int paddingTop
-
paddingBot
protected int paddingBot
-
coordsysAreaLB
protected ContourPlot.PointeredPoint2D coordsysAreaLB
-
coordsysAreaRT
protected ContourPlot.PointeredPoint2D coordsysAreaRT
-
coordsysAreaLT
protected ContourPlot.PointeredPoint2D coordsysAreaLT
-
coordsysAreaRB
protected ContourPlot.PointeredPoint2D coordsysAreaRB
-
xAxisLabel
protected java.lang.String xAxisLabel
-
yAxisLabel
protected java.lang.String yAxisLabel
-
coordviewListener
protected java.awt.event.ActionListener coordviewListener
-
isEnabled
protected boolean isEnabled
-
colorScheme
protected ContourPlot.ColorScheme colorScheme
-
-
Method Detail
-
setupCoordSysRenderer
protected void setupCoordSysRenderer()
Helper method to setup the CoordSysRenderer
-
updateColors
protected ContourPlot.CoordSysRenderer updateColors()
Helper method to update the colors if the color scheme is changed.- Returns:
- this for chaining
-
setDirty
public void setDirty()
Sets theisDirtystate of this CoordSysRenderer to true. This indicates that axis locations, tick marks, labels and guides have to be recomputed. The recomputing will be done during#render(int, int, int, int)which will set the isDirty state back to false.
-
updateLegendColorScheme
protected void updateLegendColorScheme(ContourPlot.Renderer legend)
- Parameters:
legend- color scheme of the legend will be updated if it is from typeContourPlot.Legend
-
getColorScheme
public ContourPlot.ColorScheme getColorScheme()
- Returns:
- the
ContourPlot.ColorSchemeof the CoordSysRenderer.
-
setupAndLayout
protected void setupAndLayout()
Sets up pretty much everything.- the bounds of the coordinate system frame (
coordsysAreaLB,coordsysAreaRT) - the tick mark values and labels
- the tick mark guides
- the location of the axis labels
- the areas for the legends (right and bottom legend)
- the bounds of the coordinate system frame (
-
renderFallback
public void renderFallback(java.awt.Graphics2D g, java.awt.Graphics2D p, int w, int h)Description copied from interface:ContourPlot.RendererRenders thisContourPlot.Renderer's 'scene'. This is the fallback path in case OpenGL based rendering through#render(int, int, int, int)is not available.- Specified by:
renderFallbackin interfaceContourPlot.Renderer- Parameters:
g- main graphics object for drawing onto the framebufferp- graphics object for drawing onto the picking framebuffer (invisible but used for picking)w- width of the current viewport in pixelsh- height of the current viewport in pixels
-
renderPDF
public void renderPDF(org.apache.pdfbox.pdmodel.PDDocument doc, org.apache.pdfbox.pdmodel.PDPage page, int x, int y, int w, int h)Description copied from interface:ContourPlot.PDFRendererRenders this PDFRenderers contents, that is creating pdf elements and appending them to the specified page within the corresponding document.- Specified by:
renderPDFin interfaceContourPlot.PDFRenderer- Parameters:
doc- the PDF document holding the pagepage- page in pdf doc to which elements are to be appendedx- x coordinate of the current viewporty- y coordinate of the current viewportw- width of the current viewporth- height of the current viewport
-
isEnabled
public boolean isEnabled()
Description copied from interface:ContourPlot.RendererWhether this renderer is enabled or not. By default a renderer is enabled and will render upon#render(int, int, int, int)or#renderSVG(org.w3c.dom.Document, org.w3c.dom.Element, int, int). When disabled those methods return right away and will not render anything.- Specified by:
isEnabledin interfaceContourPlot.Renderer- Returns:
- true when active
-
getxAxisLabel
public java.lang.String getxAxisLabel()
- Returns:
- "X" if
xAxisLabelis null or the actual axis label.
-
getyAxisLabel
public java.lang.String getyAxisLabel()
- Returns:
- "Y" if
yAxisLabelis null or the actual axis label.
-
setCoordinateView
public ContourPlot.CoordSysRenderer setCoordinateView(double minX, double minY, double maxX, double maxY)
Sets the coordinate view. This is the range of x and y coordinates that is displayed by thisContourPlot.CoordSysRenderer. It is not the rectangular area in which the content appears on screen but what coordinates that area corresponds to as a coordinate system.This determines what range of coordinates is visible when rendering the
content. By default the coordinate view covers the range [-1,1] for both x and y coordinates. When the resulting value ranges maxX-minX or maxY-minY fall below 1e-9, the method refuses to set the view accordingly to prevent unrecoverable zooming and inaccurate or broken renderings due to floating point precision.This method also sets the
isDirtystate of thisContourPlot.CoordSysRendererto true.When
ContourPlot.CoordinateViewListenerare registered to this renderer, they will be notified before this method returns.- Parameters:
minX- minimum x coordinate visible in the coordinate systemminY- minimum y coordinate visible in the coordinate systemmaxX- maximum x coordinate visible in the coordinate systemmaxY- maximum y coordinate visible in the coordinate system- Returns:
- this for chaining
-
setCoordinateView
public ContourPlot.CoordSysRenderer setCoordinateView(java.awt.geom.Rectangle2D viewRect)
Sets the coordinate view. This is the range of x and y coordinates that is displayed by thisContourPlot.CoordSysRenderer. It is not the rectangular area in which the content appears on screen but what coordinates that area corresponds to as a coordinate system.- Parameters:
viewRect- to set the view to- Returns:
- this for chaining
-
setCoordinateViewRect
protected ContourPlot.CoordSysRenderer setCoordinateViewRect(double x, double y, double w, double h)
-
addCoordinateViewListener
public ContourPlot.CoordSysRenderer addCoordinateViewListener(ContourPlot.CoordinateViewListener l)
Adds aContourPlot.CoordinateViewListenerto this renderer which will be notified whenever the coordinate view changes (i.e. whensetCoordinateView(double, double, double, double)is called)- Parameters:
l- listener- Returns:
- this for chaining
-
removeActionListener
public ContourPlot.CoordSysRenderer removeActionListener(ContourPlot.CoordinateViewListener l)
Removes the specifiedContourPlot.CoordinateViewListenerfrom this renderer.- Parameters:
l- listener- Returns:
- this for chaining
-
getCoordinateView
public java.awt.geom.Rectangle2D getCoordinateView()
Returns the coordinate view, which is the range of x and y coordinates visible in the coordinate system. SeesetCoordinateView(double, double, double, double).- Returns:
- the coordinate view
-
setContent
public ContourPlot.Renderer setContent(ContourPlot.Renderer content)
Sets the content renderer that will draw into the area of the coordinate system.- Parameters:
content- the content renderer- Returns:
- the previous content renderer (which may need to be closed to free GL resources), null if none was set
-
setLegendRight
public ContourPlot.Renderer setLegendRight(ContourPlot.Renderer legend)
Sets the renderer that will draw the legend to the right of the coordinate system. The view port area for this renderer will start at the top edge of the coordinate system, be#getLegendRightWidth()wide and extend to the bottom (-padding).- Parameters:
legend- renderer for right side of coordinate system- Returns:
- the previous legend renderer (which may need to be closed to free GL resources), null if none was set
-
setLegendRightWidth
public ContourPlot.CoordSysRenderer setLegendRightWidth(int legendRightWidth)
Sets the width of the legend area right to the coordinate system. (height is determined by the space available until the bottom of the renderer's viewport)- Parameters:
legendRightWidth- width of the right legend area. (default is 70 px)- Returns:
- this for chaining
-
getCoordSysArea
public java.awt.geom.Rectangle2D getCoordSysArea()
- Returns:
- the area of this renderer in which the coordinate system contents are rendered.
It is the viewPort for the
contentrenderer which is enclosed by the coordinate system axes.
-
transformAWT2CoordSys
public java.awt.geom.Point2D transformAWT2CoordSys(java.awt.geom.Point2D awtPoint, int canvasheight)Transforms a location in AWT coordinates (y axis extends to bottom) on this renderer to the corresponding coordinates in the coordinate system view (in GL coords).- Parameters:
awtPoint- to be transformedcanvasheight- height of the canvas thisContourPlot.CoordSysRendereris drawn to- Returns:
- transformed location
-
transformGL2CoordSys
public java.awt.geom.Point2D transformGL2CoordSys(java.awt.geom.Point2D point)
Transforms a location in GL coordinates on this renderer to the corresponding coordinates in the coordinate system view.- Parameters:
point- to be transformed- Returns:
- transformed location
-
-