Package org.jzy3d.plot3d.rendering.view
Class View2DProcessing
java.lang.Object
org.jzy3d.plot3d.rendering.view.View2DProcessing
Process and store the layout of a 2D view having margins and axis labels defined by the
View2DLayout settings.
Storing the results is handy for classes needing to reuse intermediate processing of this margins
:
View.computeCamera2D_RenderingSquare(Camera, ViewportConfiguration, BoundingBox3d)AxisLabelProcessor.axisLabelPosition_2D(int, org.jzy3d.maths.Coord3d)AxisTickProcessor.getTickLength3D_OrComputeTickLength2D(org.jzy3d.painters.IPainter, int)
getModelToScreenRatio(Area, Area, Area)
which has an extended documentation providing mathematical demonstration.- Author:
- Martin Pernollet
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected floatprotected floatprotected floatprotected floatprotected Areaprotected floatprotected floatprotected floatprotected floatprotected floatprotected floatprotected floatprotected floatprotected floatprotected floatprotected floatprotected floatprotected Coord2dprotected Areaprotected Areaprotected floatprotected floatprotected floatprotected floatprotected View -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapply(ViewportConfiguration viewport, BoundingBox3d bounds) Apply current view'sView2DLayoutand process all margins in 3D.getArea()Return the overall margin that was processed at the latest call toaccording to the axis and view layout settingsinvalid @link
#apply()floatReturn the axis label height in pixel that was processed at the latest call toaccording to the axis and view layout settingsinvalid @link
#apply()floatReturn the axis label width in pixel that was processed at the latest call toaccording to the axis and view layout settingsinvalid @link
#apply()floatReturn the distance of axis label to tick labels, already scaled according to pixel scalefloatReturn the distance of tick labels to axis, already scaled according to pixel scaleReturn the margin in pixels, as defined in settingsReturn the margin in pixels, already scaled according to pixel scaleReturn the model-to-screen ratio that that was processed at the latest call toinvalid @link
#apply()getModelToScreenRatio(Area space, Area canvas, Area margins) A helper for processing 2D margins.floatReturn the tick label height in pixel that was processed at the latest call toaccording to the axis and view layout settingsinvalid @link
#apply()floatReturn the tick label width in pixel that was processed at the latest call toaccording to the axis and view layout settingsinvalid @link
#apply()floatReturn the distance of axis label to tick labels, already scaled according to pixel scalefloatReturn the distance of tick labels to axis, already scaled according to pixel scalegetView()protected booleanisXY()protected booleanisXZ()protected booleanisYZ()void
-
Field Details
-
view
-
tickTextWidth
protected float tickTextWidth -
tickTextHeight
protected float tickTextHeight -
axisTextWidth
protected float axisTextWidth -
axisTextHeight
protected float axisTextHeight -
horizontalTickDistance
protected float horizontalTickDistance -
horizontalAxisDistance
protected float horizontalAxisDistance -
verticalTickDistance
protected float verticalTickDistance -
verticalAxisDistance
protected float verticalAxisDistance -
marginLeftPxScaled
protected float marginLeftPxScaled -
marginRightPxScaled
protected float marginRightPxScaled -
marginTopPxScaled
protected float marginTopPxScaled -
marginBottomPxScaled
protected float marginBottomPxScaled -
marginLeftPx
protected float marginLeftPx -
marginRightPx
protected float marginRightPx -
marginTopPx
protected float marginTopPx -
marginBottomPx
protected float marginBottomPx -
marginLeftModel
protected float marginLeftModel -
marginRightModel
protected float marginRightModel -
marginTopModel
protected float marginTopModel -
marginBottomModel
protected float marginBottomModel -
marginArea
-
spaceArea
-
screenArea
-
modelToScreen
-
-
Constructor Details
-
View2DProcessing
public View2DProcessing() -
View2DProcessing
-
-
Method Details
-
apply
Apply current view'sView2DLayoutand process all margins in 3D. -
isYZ
protected boolean isYZ() -
isXZ
protected boolean isXZ() -
isXY
protected boolean isXY() -
getModelToScreenRatio
A helper for processing 2D margins. This method process a model-to-screen ratio able to indicate which range of real world coordinates will be mapped to a single pixel, both on the width and height of the viewport. It is used to evaluate the camera settings to apply to a 2D projection to allow keeping a white space for drawing 2D margins. The intuition lead to consider that this ratio R should be :
This would allow to compute an extra space to add to world coordinates specified in pixel units. However this ratio does not allow considering margins in world space AND screen space consistently (which then leads to inconsistent layout). Our need then become to ensure this ratio remains the same in 2D (pixel space) and 3D (scene space). To explain the formulae, we assuming the following case of 1000px wide canvas showing a scene with a range of 20 along the X dimension. The largest rectangle represents the canvas, the smallest represents the scene. We show a left and right margin made of 100px each.R.x = scene.bounds.xrange() / viewport.width R.y = scene.bounds.yrange() / viewport.height
Let's start with our naive ratio formulae100px 800px 100px |-----+------------------+-----| | | | |------------------| | | | | | | | xrange=20 | | | |------------------| | | x=-10 x=10 | |-----+------------------+-----|
Margins in scene space (3D) should then beR.x = scene.xrange() / viewport.width = 20/1000 = 2/100
Hence the range to consider to keep a white space around the 3D scene is x:[-12;12] instead of the initial x:[-10;10] We now want to ensure that the margin ratio in screen space remains the same than the one in scene space :margin3D.x = margin2D.x * R.x = 200 * 2/100 = 4
This constraint is represented by the following equationscene.xrange() / sceneWithMargin.xrange() = screen.xrange() / screenWithMargin.xrange() in our example : 20 / 24 = 800 / 1000
Solving this equation to get R.x yield toscene.xrange screen.xrange - margin2D.x ------------------------------- = -------------------------- R.x * margin2D.x + scene.xrange screen.xrange
Reasoning is the same for the Y dimension. NB : the ratio will be 1 in the case margin is 0 or if canvas size is equal to margin size.screen.xrange * scene.xrange ( ---------------------------- - scene.xrange ) * (1/margin2D.x) screen.xrange - margin2D.x- Parameters:
space-canvas-margins-- Returns:
-
getArea
Return the overall margin that was processed at the latest call toaccording to the axis and view layout settingsinvalid @link
#apply() -
getTickTextWidth
public float getTickTextWidth()Return the tick label width in pixel that was processed at the latest call toaccording to the axis and view layout settingsinvalid @link
#apply() -
getTickTextHeight
public float getTickTextHeight()Return the tick label height in pixel that was processed at the latest call toaccording to the axis and view layout settingsinvalid @link
#apply() -
getAxisTextWidth
public float getAxisTextWidth()Return the axis label width in pixel that was processed at the latest call toaccording to the axis and view layout settingsinvalid @link
#apply() -
getAxisTextHeight
public float getAxisTextHeight()Return the axis label height in pixel that was processed at the latest call toaccording to the axis and view layout settingsinvalid @link
#apply() -
getModelToScreen
Return the model-to-screen ratio that that was processed at the latest call toinvalid @link
#apply() -
getMarginPx
Return the margin in pixels, as defined in settings -
getMarginPxScaled
Return the margin in pixels, already scaled according to pixel scale -
getHorizontalTickDistance
public float getHorizontalTickDistance()Return the distance of tick labels to axis, already scaled according to pixel scale -
getHorizontalAxisDistance
public float getHorizontalAxisDistance()Return the distance of axis label to tick labels, already scaled according to pixel scale -
getVerticalTickDistance
public float getVerticalTickDistance()Return the distance of tick labels to axis, already scaled according to pixel scale -
getVerticalAxisDistance
public float getVerticalAxisDistance()Return the distance of axis label to tick labels, already scaled according to pixel scale -
getView
-
setView
-