00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 package org.scilab.modules.renderer.polylineDrawing;
00017
00018 import javax.media.opengl.GL;
00019
00020 import org.scilab.modules.renderer.AutoDrawableObjectGL;
00021 import org.scilab.modules.renderer.utils.glTools.GLTools;
00022
00028 public class PolylineBarDrawerGL extends AutoDrawableObjectGL {
00029
00030 private int backColor;
00031 private int lineColor;
00032 private float thickness;
00033 private int lineStyle;
00034
00038 public PolylineBarDrawerGL() {
00039 super();
00040 backColor = -1;
00041 lineColor = -1;
00042 thickness = 1.0f;
00043 lineStyle = 1;
00044 }
00045
00050 public void setBackColorIndex(int colorIndex) {
00051 this.backColor = colorIndex;
00052 }
00053
00057 public double[] getBackColor() {
00058 return getColorMap().getColor(backColor);
00059 }
00060
00065 public void setLineColorIndex(int colorIndex) {
00066 this.lineColor = colorIndex;
00067 }
00068
00072 public double[] getLineColor() {
00073 return getColorMap().getColor(lineColor);
00074 }
00075
00080 public void setThickness(float thickness) {
00081 this.thickness = thickness;
00082 }
00083
00087 public float getThickness() {
00088 return thickness;
00089 }
00090
00095 public void setLineStyle(int styleIndex) {
00096 this.lineStyle = styleIndex;
00097 }
00098
00102 public int getLineStyle() {
00103 return lineStyle;
00104 }
00105
00113 public void setBarParameters(int background, int foreground, float thickness, int lineStyle) {
00114 setBackColorIndex(background);
00115 setLineColorIndex(foreground);
00116 setThickness(thickness);
00117 setLineStyle(lineStyle);
00118 }
00119
00129 public void drawPolyline(double[] left, double[] right,
00130 double[] bottom, double[] top,
00131 double[] zCoord) {
00132
00133 fillBars(left, right, bottom, top, zCoord);
00134 encloseBars(left, right, bottom, top, zCoord);
00135
00136 }
00137
00146 private void fillBars(double[] left, double[] right,
00147 double[] bottom, double[] top,
00148 double[] zCoord) {
00149
00150 GL gl = getGL();
00151
00152
00153
00154 double[] color = getBackColor();
00155 gl.glColor3d(color[0], color[1], color[2]);
00156
00157 gl.glBegin(GL.GL_QUADS);
00158 for (int i = 0; i < left.length; i++) {
00159 gl.glVertex3d(left[i], bottom[i], zCoord[i]);
00160 gl.glVertex3d(right[i], bottom[i], zCoord[i]);
00161 gl.glVertex3d(right[i], top[i], zCoord[i]);
00162 gl.glVertex3d(left[i], top[i], zCoord[i]);
00163 }
00164 gl.glEnd();
00165 }
00166
00175 private void encloseBars(double[] left, double[] right,
00176 double[] bottom, double[] top,
00177 double[] zCoord) {
00178
00179 GL gl = getGL();
00180
00181
00182
00183 double[] color = getLineColor();
00184 gl.glColor3d(color[0], color[1], color[2]);
00185
00186
00187 GLTools.beginDashMode(gl, getLineStyle(), getThickness());
00188
00189
00190 GLTools.pushPolygonsBack(gl);
00191
00192 for (int i = 0; i < left.length; i++) {
00193 gl.glBegin(GL.GL_LINE_LOOP);
00194 gl.glVertex3d(left[i], bottom[i], zCoord[i]);
00195 gl.glVertex3d(right[i], bottom[i], zCoord[i]);
00196 gl.glVertex3d(right[i], top[i], zCoord[i]);
00197 gl.glVertex3d(left[i], top[i], zCoord[i]);
00198 gl.glEnd();
00199 }
00200
00201 GLTools.endPushPolygonsBack(gl);
00202
00203 GLTools.endDashMode(gl);
00204
00205 }
00206
00207
00208 }