2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2009-2012 - DIGITEO - Pierre Lando
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
12 package org.scilab.modules.renderer.JoGLView.interaction.util;
14 import org.scilab.forge.scirenderer.DrawingTools;
15 import org.scilab.forge.scirenderer.buffers.BuffersManager;
16 import org.scilab.forge.scirenderer.buffers.ElementsBuffer;
17 import org.scilab.forge.scirenderer.shapes.geometry.DefaultGeometry;
18 import org.scilab.forge.scirenderer.shapes.geometry.Geometry;
19 import org.scilab.forge.scirenderer.tranformations.Vector3d;
20 import org.scilab.modules.graphic_objects.axes.Axes;
21 import org.scilab.modules.renderer.JoGLView.interaction.RubberBox;
23 import java.nio.FloatBuffer;
26 * @author Pierre Lando
28 public class HelpersGeometry extends DefaultGeometry {
30 /** The helper size */
31 private static final double HELPERS_SIZE = .05;
36 * - 2 segments per marks.
37 * - 2 vertex per segments.
38 * - 4 coordinate per vertex.
40 private static final int VERTEX_BUFFER_SIZE = 64;
42 private final BuffersManager bufferManager;
43 private final ElementsBuffer vertexBuffer;
45 public HelpersGeometry(DrawingTools drawingTools) {
46 bufferManager = drawingTools.getCanvas().getBuffersManager();
47 vertexBuffer = bufferManager.createElementsBuffer();
49 setLineDrawingMode(Geometry.LineDrawingMode.SEGMENTS);
50 setFillDrawingMode(Geometry.FillDrawingMode.NONE);
51 setVertices(vertexBuffer);
55 public void finalize() throws Throwable {
57 bufferManager.dispose(vertexBuffer);
60 public void updateVertex(Axes axes, PointComputer pointAComputer, Vector3d secondPoint, RubberBox.Status status) {
61 if ((pointAComputer != null) && (pointAComputer.getFirstAxisIndex() != -1)) {
64 if ((status == RubberBox.Status.WAIT_POINT_A) || (status == RubberBox.Status.WAIT_POINT_B)) {
66 data = FloatBuffer.allocate(VERTEX_BUFFER_SIZE * 2);
69 data = FloatBuffer.allocate(VERTEX_BUFFER_SIZE);
72 Double[] bounds = axes.getDisplayedBounds();
73 int mainAxisIndex = (pointAComputer.getFirstAxisIndex() + 1) % 3;
74 for (int axisIndex = 0; axisIndex < 3; axisIndex++) {
75 if ((mainAxisIndex != axisIndex) ^ oneAxis) {
76 for (int u = 0; u < 2; u++) {
77 for (int v = 0; v < 2; v++) {
78 double base[] = secondPoint.getData();
79 base[axisIndex] = bounds[axisIndex * 2 + u];
80 int nextAxisIndex = (axisIndex + 1) % 3;
81 base[nextAxisIndex] = bounds[nextAxisIndex * 2 + v];
82 float[] buffer = asFloatArray(base);
85 buffer[axisIndex] = buffer[axisIndex] + (float) (HELPERS_SIZE * (bounds[axisIndex * 2 + (1 - u)] - bounds[axisIndex * 2 + u]));
88 buffer[axisIndex] = bounds[axisIndex * 2 + u].floatValue();
91 buffer[nextAxisIndex] = buffer[nextAxisIndex] + (float) (HELPERS_SIZE * (bounds[nextAxisIndex * 2 + (1 - v)] - bounds[nextAxisIndex * 2 + v]));
99 getVertices().setData(data, 3);
101 getVertices().setData(new Float[0], 4);
105 private float[] asFloatArray(double[] base) {
106 float data[] = new float[base.length];
107 for (int i = 0; i < base.length; i++) {
108 data[i] = (float) base[i];