2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008 - INRIA - Jean-Baptiste Silvy
4 * desc : Class containing the driver dependant routines to draw a
5 * grayplot object with JoGL
7 * This file must be used under the terms of the CeCILL.
8 * This source file is licensed as described in the file COPYING, which
9 * you should have received as part of this distribution. The terms
10 * are also available at
11 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
15 package org.scilab.modules.renderer.grayplotDrawing;
17 import javax.media.opengl.GL;
19 import org.scilab.modules.renderer.DrawableClippedObjectGL;
22 * Class containing functions called by DrawableGrayplotJoGL.cpp
23 * @author Jean-Baptiste Silvy
25 public class DrawableGrayplotGL extends DrawableClippedObjectGL {
30 public DrawableGrayplotGL() {
35 * Display the object by displaying its display list
36 * @param parentFigureIndex index of the parent figure in which the object will be drawn
38 public void show(int parentFigureIndex) {
43 * Draw the grayplot or matplot object. The object is composed of set of facets.
44 * Each facet is a rectangle whose edges are between (xGrid[i], yGrid[j]) and
45 * (xGrid[i + 1], yGrid[j + 1]) and its color is color[i][j].
46 * @param xGrid array containing the abscissas of the grid
47 * @param yGrid array containing the ordinates of the grid
48 * @param zCoord zCoordinate used to draw the grayplot
49 * @param colors array considered as a matrix containing the color index for each facet
50 * its size is (xGrid.length - 1) x (yGrid.length - 1)
52 public void drawGrayplot(double[] xGrid, double[] yGrid, double zCoord, int[] colors) {
55 int nbCol = xGrid.length - 1;
56 int nbRow = yGrid.length - 1;
58 // rectangles are used to render each pixel
59 // Using textures would be much faster
60 // hower it would not be compatible with GL2PS, so for now we keep the slow version
63 gl.glBegin(GL.GL_QUADS);
64 for (int j = 0; j < nbRow; j++) {
65 for (int i = 0; i < nbCol; i++) {
66 double[] curColor = getColorMap().getColor(getColorMap().convertScilabToColorMapIndex(colors[i + nbCol * j]));
67 gl.glColor3d(curColor[0], curColor[1], curColor[2]);
68 gl.glVertex3d(xGrid[i], yGrid[j], zCoord);
69 gl.glVertex3d(xGrid[i], yGrid[j + 1], zCoord);
70 gl.glVertex3d(xGrid[i + 1], yGrid[j + 1], zCoord);
71 gl.glVertex3d(xGrid[i + 1], yGrid[j], zCoord);