From 0ba2eac8642c28f4449b82d9775803d8d6caed96 Mon Sep 17 00:00:00 2001 From: Calixte DENIZET Date: Thu, 28 Feb 2013 10:41:40 +0100 Subject: [PATCH] Graphics: xstringl returned bad values between drawlater/drawnow Change-Id: I3a64b7f0a123e299bf70df6512bc8819d31fb3ff --- .../modules/renderer/JoGLView/axes/AxesDrawer.java | 45 +++++++++++++------- .../renderer/JoGLView/text/TextManager.java | 41 +++++++++--------- 2 files changed, 50 insertions(+), 36 deletions(-) diff --git a/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/axes/AxesDrawer.java b/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/axes/AxesDrawer.java index bb02744..7a39aff 100644 --- a/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/axes/AxesDrawer.java +++ b/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/axes/AxesDrawer.java @@ -124,6 +124,19 @@ public class AxesDrawer { reversedBoundsIntervals = new double[3]; } + public Transformation getCurrentProjection(Axes axes) throws DegenerateMatrixException { + DrawingTools drawingTools = visitor.getDrawingTools(); + Canvas canvas = visitor.getCanvas(); + Transformation zoneProjection = computeZoneProjection(axes); + Transformation transformation = computeBoxTransformation(axes, canvas, false); + Transformation dataTransformation = computeDataTransformation(axes); + Transformation windowTrans = drawingTools.getTransformationManager().getWindowTransformation().getInverseTransformation(); + Transformation current = zoneProjection.rightTimes(transformation); + current = current.rightTimes(dataTransformation); + + return windowTrans.rightTimes(current); + } + /** * Draw the given {@see Axes}. * @param axes {@see Axes} to draw. @@ -277,10 +290,10 @@ public class AxesDrawer { double[] matrix = transformation.getMatrix(); try { return TransformationFactory.getScaleTransformation( - matrix[2] < 0 ? 1 : -1, - matrix[6] < 0 ? 1 : -1, - matrix[10] < 0 ? 1 : -1 - ); + matrix[2] < 0 ? 1 : -1, + matrix[6] < 0 ? 1 : -1, + matrix[10] < 0 ? 1 : -1 + ); } catch (DegenerateMatrixException e) { // Should never happen. return TransformationFactory.getIdentity(); @@ -347,26 +360,26 @@ public class AxesDrawer { // Reverse data if needed. Transformation transformation = TransformationFactory.getScaleTransformation( - axes.getAxes()[0].getReverse() ? 1 : -1, - axes.getAxes()[1].getReverse() ? 1 : -1, - axes.getAxes()[2].getReverse() ? 1 : -1 - ); + axes.getAxes()[0].getReverse() ? 1 : -1, + axes.getAxes()[1].getReverse() ? 1 : -1, + axes.getAxes()[2].getReverse() ? 1 : -1 + ); // Scale data. Transformation scaleTransformation = TransformationFactory.getScaleTransformation( - 2.0 / (bounds[1] - bounds[0]), - 2.0 / (bounds[3] - bounds[2]), - 2.0 / (bounds[5] - bounds[4]) - ); + 2.0 / (bounds[1] - bounds[0]), + 2.0 / (bounds[3] - bounds[2]), + 2.0 / (bounds[5] - bounds[4]) + ); transformation = transformation.rightTimes(scaleTransformation); // Translate data. Transformation translateTransformation = TransformationFactory.getTranslateTransformation( - -(bounds[0] + bounds[1]) / 2.0, - -(bounds[2] + bounds[3]) / 2.0, - -(bounds[4] + bounds[5]) / 2.0 - ); + -(bounds[0] + bounds[1]) / 2.0, + -(bounds[2] + bounds[3]) / 2.0, + -(bounds[4] + bounds[5]) / 2.0 + ); transformation = transformation.rightTimes(translateTransformation); return transformation; } diff --git a/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/text/TextManager.java b/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/text/TextManager.java index 993acd6..e859041 100644 --- a/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/text/TextManager.java +++ b/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/text/TextManager.java @@ -107,7 +107,7 @@ public class TextManager { drawingTools.getTransformationManager().useWindowCoordinate(); /* The Text object's rotation direction convention is opposite to the standard one, its angle is expressed in radians. */ - drawingTools.draw(texture, AnchorPosition.LOWER_LEFT, cornerPositions[0], -180.0*text.getFontAngle()/Math.PI); + drawingTools.draw(texture, AnchorPosition.LOWER_LEFT, cornerPositions[0], -180.0 * text.getFontAngle() / Math.PI); drawingTools.getTransformationManager().useSceneCoordinate(); @@ -145,7 +145,7 @@ public class TextManager { /* The text position vector before logarithmic scaling */ Vector3d unscaledTextPosition = new Vector3d(text.getPosition()); - boolean[] logFlags = new boolean[]{parentAxes.getXAxisLogFlag(), parentAxes.getYAxisLogFlag(), parentAxes.getZAxisLogFlag()}; + boolean[] logFlags = new boolean[] {parentAxes.getXAxisLogFlag(), parentAxes.getYAxisLogFlag(), parentAxes.getZAxisLogFlag()}; /* Apply logarithmic scaling and then project */ Vector3d textPosition = ScaleUtils.applyLogScale(unscaledTextPosition, logFlags); @@ -238,7 +238,7 @@ public class TextManager { private double[] computeRatios(Transformation projection, Text text, Vector3d[] textBoxVectors, Dimension spriteDimension, Dimension baseSpriteDimension) { /* 1st element: ratio for the current texture, 2nd element: ratio for the unscaled texture */ - double[] ratios = new double[]{1.0, 1.0}; + double[] ratios = new double[] {1.0, 1.0}; /* Ratios are relevant only to the filled text box mode */ if (text.getTextBoxMode() == 2) { @@ -278,7 +278,7 @@ public class TextManager { Axes parentAxes = (Axes) GraphicController.getController().getObjectFromId(parentAxesId); /* Apply logarithmic scaling */ - boolean[] logFlags = new boolean[]{parentAxes.getXAxisLogFlag(), parentAxes.getYAxisLogFlag(), parentAxes.getZAxisLogFlag()}; + boolean[] logFlags = new boolean[] {parentAxes.getXAxisLogFlag(), parentAxes.getYAxisLogFlag(), parentAxes.getZAxisLogFlag()}; textPosition = ScaleUtils.applyLogScale(textPosition, logFlags); @@ -324,11 +324,11 @@ public class TextManager { * Compute the final text box's and text's half-length vectors, * using the rotated text label vectors. */ - revTextBoxWidth = textWidth.getNormalized().times(0.5*revTextBoxWidth.getX()); - revTextBoxHeight = textHeight.getNormalized().times(0.5*revTextBoxHeight.getY()); + revTextBoxWidth = textWidth.getNormalized().times(0.5 * revTextBoxWidth.getX()); + revTextBoxHeight = textHeight.getNormalized().times(0.5 * revTextBoxHeight.getY()); - textBoxWidth = textWidth.getNormalized().times(0.5*textBoxWidth.getX()); - textBoxHeight = textHeight.getNormalized().times(0.5*textBoxHeight.getY()); + textBoxWidth = textWidth.getNormalized().times(0.5 * textBoxWidth.getX()); + textBoxHeight = textHeight.getNormalized().times(0.5 * textBoxHeight.getY()); textWidth = textWidth.times(0.5); textHeight = textHeight.times(0.5); @@ -397,7 +397,7 @@ public class TextManager { * Apparently uses the same convention as the texts (clockwise positive directions). * To be verified. */ - Transformation projRotation = TransformationFactory.getRotationTransformation(180.0*fontAngle/Math.PI, 0.0, 0.0, 1.0); + Transformation projRotation = TransformationFactory.getRotationTransformation(180.0 * fontAngle / Math.PI, 0.0, 0.0, 1.0); projCorners[0] = projPosition; @@ -423,7 +423,7 @@ public class TextManager { */ private Vector3d[] computeCorners(Transformation projection, Vector3d[] projCorners, Axes parentAxes) { Vector3d[] corners = new Vector3d[4]; - boolean[] logFlags = new boolean[]{parentAxes.getXAxisLogFlag(), parentAxes.getYAxisLogFlag(), parentAxes.getZAxisLogFlag()}; + boolean[] logFlags = new boolean[] {parentAxes.getXAxisLogFlag(), parentAxes.getYAxisLogFlag(), parentAxes.getZAxisLogFlag()}; corners[0] = projection.unproject(projCorners[0]); corners[1] = projection.unproject(projCorners[1]); @@ -596,14 +596,14 @@ public class TextManager { Vector3d[] projCorners = null; DrawerVisitor currentVisitor = DrawerVisitor.getVisitor(text.getParentFigure()); - Transformation currentProj = currentVisitor.getAxesDrawer().getProjection(text.getParentAxes()); - Axes parentAxes = (Axes) GraphicController.getController().getObjectFromId(text.getParentAxes()); - Dimension spriteDim = currentVisitor.getTextManager().getSpriteDims(currentVisitor.getColorMap(), text); - /* Compute the corners */ try { + Transformation currentProj = currentVisitor.getAxesDrawer().getCurrentProjection(parentAxes); + + Dimension spriteDim = currentVisitor.getTextManager().getSpriteDims(currentVisitor.getColorMap(), text); + Vector3d[] textBoxVectors = currentVisitor.getTextManager().computeTextBoxVectors(currentProj, text, spriteDim, parentAxes); Vector3d[] cornerPositions = currentVisitor.getTextManager().computeTextPosition(currentProj, text, textBoxVectors, spriteDim); @@ -612,15 +612,16 @@ public class TextManager { } else { projCorners = currentVisitor.getTextManager().computeProjCorners(cornerPositions[0], text.getFontAngle(), spriteDim); } + + Vector3d[] corners = currentVisitor.getTextManager().computeCorners(currentProj, projCorners, parentAxes); + Double[] coordinates = currentVisitor.getTextManager().cornersToCoordinateArray(corners); + + /* Set the computed coordinates */ + text.setCorners(coordinates); + } catch (DegenerateMatrixException e) { // TODO Auto-generated catch block e.printStackTrace(); } - - Vector3d[] corners = currentVisitor.getTextManager().computeCorners(currentProj, projCorners, parentAxes); - Double[] coordinates = currentVisitor.getTextManager().cornersToCoordinateArray(corners); - - /* Set the computed coordinates */ - text.setCorners(coordinates); } } -- 1.7.9.5