2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2012 - DIGITEO - Manuel Juliachs
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
13 package org.scilab.modules.renderer;
15 import org.scilab.modules.graphic_objects.axes.Axes;
16 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
17 import org.scilab.modules.graphic_objects.graphicObject.GraphicObject;
18 import org.scilab.modules.graphic_objects.textObject.Text;
20 import org.scilab.modules.renderer.JoGLView.DrawerVisitor;
21 import org.scilab.modules.renderer.JoGLView.axes.AxesDrawer;
22 import org.scilab.modules.renderer.JoGLView.text.TextManager;
25 * This is a static class to access the renderer module directly
26 * from C/C++ code through JNI.
27 * See SCI/modules/renderer/src/jni/renderer.giws.xml for other details.
29 public final class CallRenderer {
32 * Start an interactive zoom.
33 * @param id the uid of the figure where the zoom happen.
35 public static void startInteractiveZoom(String id) {
36 DrawerVisitor visitor = DrawerVisitor.getVisitor(id);
37 if (visitor != null) {
38 visitor.getInteractionManager().startInteractiveZoom();
42 public static double[] clickRubberBox(String id, double initialRect[]) {
43 DrawerVisitor visitor = DrawerVisitor.getVisitor(id);
44 if (visitor != null) {
45 return visitor.getInteractionManager().startClickRubberBox(initialRect);
47 return new double[] {-1,-1,-1,-1,-1,-1,-1};
50 public static double[] dragRubberBox(String id) {
51 DrawerVisitor visitor = DrawerVisitor.getVisitor(id);
52 if (visitor != null) {
53 return visitor.getInteractionManager().startDragRubberBox();
55 return new double[] {-1,-1,-1,-1,-1,-1,-1};
58 * Updates the coordinate transformation of the Axes object given by the identifier.
59 * @param id the Axes' identifier.
61 public static void updateSubwinScale(String id) {
62 GraphicObject object = GraphicController.getController().getObjectFromId(id);
64 if (object != null && object instanceof Axes) {
65 AxesDrawer.updateAxesTransformation((Axes) object);
70 * Updates the corners of the text object corresponding to the identifier.
71 * @param id the text object's identifier.
73 public static void updateTextBounds(String id) {
74 GraphicObject object = GraphicController.getController().getObjectFromId(id);
76 if (object != null && object instanceof Text) {
77 TextManager.updateTextCorners((Text) object);
82 * Computes and returns the coordinates of a point projected onto the default 2d view plane.
83 * The obtained coordinates correspond to the point's object coordinates in the default 2d view
84 * coordinate frame (the point's position being fixed in window coordinates).
85 * The projected point's z coordinate is set to 0, as only x and y are relevant.
86 * @param id the identifier of the Axes object.
87 * @param coords the input object coordinates (3-element array).
88 * @return the 2d view coordinates (3-element array).
90 public static double[] get2dViewCoordinates(String id, double[] coords) {
91 double[] point2d = new double[]{0.0, 0.0, 0.0};
93 GraphicObject object = GraphicController.getController().getObjectFromId(id);
95 if (object != null && object instanceof Axes) {
96 double[] tmp = AxesDrawer.compute2dViewCoordinates((Axes) object, coords);
106 * Computes and returns the pixel coordinates from a point's coordinates expressed
107 * in the default 2d view coordinate frame, using the given Axes.
108 * The returned pixel coordinates are expressed in the AWT's 2d coordinate frame.
109 * @param id the Axes' identifier.
110 * @param coords the 2d view coordinates (3-element array: x, y, z).
111 * @return the pixel coordinates (2-element array: x, y).
113 public static double[] getPixelFrom2dViewCoordinates(String id, double[] coords) {
114 double[] pointPix = new double[]{0.0, 0.0};
116 GraphicObject object = GraphicController.getController().getObjectFromId(id);
118 if (object != null && object instanceof Axes) {
119 double[] tmp = AxesDrawer.computePixelFrom2dViewCoordinates((Axes) object, coords);
121 pointPix[0] = tmp[0];
122 pointPix[1] = tmp[1];
129 * Computes and returns the coordinates of a point projected onto the default 2d view plane
130 * from its pixel coordinates, using the given Axes. The pixel coordinates are expressed in
131 * the AWT's 2d coordinate frame.
132 * The returned point's z component is set to 0, as we only have x and y as an input.
133 * @param id the Axes' identifier.
134 * @param coords the pixel coordinates (2-element array: x, y).
135 * @return the 2d view coordinates (3-element array: x, y, z).
137 public static double[] get2dViewFromPixelCoordinates(String id, double[] coords) {
138 double[] point2d = new double[]{0.0, 0.0, 0.0};
140 GraphicObject object = GraphicController.getController().getObjectFromId(id);
142 if (object != null && object instanceof Axes) {
143 double[] tmp = AxesDrawer.compute2dViewFromPixelCoordinates((Axes) object, coords);
153 * Computes and returns the viewing area of the Axes object given by the identifier.
154 * The viewing area is defined by its upper-left corner and its dimensions, all values
155 * are in pixels. It is expressed in the AWT's 2d coordinate frame.
156 * @param id the Axes' identifier.
157 * @return the Axes' viewing area (4-element array: x, y, width, height).
159 public static double[] getViewingArea(String id) {
160 double[] viewingArea = new double[]{0.0, 0.0, 0.0, 0.0};
161 GraphicObject object = GraphicController.getController().getObjectFromId(id);
163 if (object != null && object instanceof Axes) {
164 double[] tmp = AxesDrawer.getViewingArea((Axes) object);
166 viewingArea[0] = tmp[0];
167 viewingArea[1] = tmp[1];
168 viewingArea[2] = tmp[2];
169 viewingArea[3] = tmp[3];