illegal polygon in fec corrected
Sylvestre Koumar [Mon, 9 Jun 2008 11:38:00 +0000 (11:38 +0000)]
+ colormap gap corrected
+ help on xs2* updated

13 files changed:
scilab/modules/graphic_export/help/en_US/xs2pdf.xml
scilab/modules/graphic_export/help/en_US/xs2svg.xml
scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/GL2PSGL.java
scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/GL2PSRenderer.java
scilab/modules/gui/src/java/org/scilab/modules/gui/graphicWindow/ScilabRendererProperties.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/DrawableObjectGL.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/fecDrawing/FecFacetDrawerGL.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/figureDrawing/SciRenderer.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/polylineDrawing/GL2PSShadeFacetDrawer.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/polylineDrawing/JOGLShadeFacetDrawer.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/surfaceDrawing/LinearShadedFacetDrawerGL.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/geom3D/ColoredTriangle.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/geom3D/TriangleDecomposition.java

index d66b5a1..b9648af 100644 (file)
@@ -24,7 +24,7 @@
   <refnamediv>
     <refname>xs2pdf</refname>
 
-    <refpurpose>save graphics to a Postscript file.</refpurpose>
+    <refpurpose>save graphics to a PDF file.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
@@ -41,7 +41,7 @@
         <term>win_num</term>
 
         <listitem>
-          <para>integer scalar or vector .</para>
+          <para>integer scalar .</para>
         </listitem>
       </varlistentry>
 
     <title>Description</title>
 
     <para><literal>xs2pdf</literal> saves the recorded graphics of the window
-    <literal>win_num</literal> to file <literal>filen</literal> in Postscript
-    syntax. Note that <literal>filen</literal> must not have extension.</para>
-
-    <para><literal>xs2pdf</literal> produces a complete encapsulated Postscrip
-    file.</para>
+    <literal>win_num</literal> to file <literal>filen</literal> in PDF syntax.
+    Note that <literal>filen</literal> must not have extension.</para>
   </refsection>
 
   <refsection>
index 8cb8b8e..72740c3 100644 (file)
@@ -24,7 +24,7 @@
   <refnamediv>
     <refname>xs2svg</refname>
 
-    <refpurpose>save graphics to a Postscript file.</refpurpose>
+    <refpurpose>save graphics to a SVG file.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
     <title>Description</title>
 
     <para><literal>xs2svg</literal> saves the recorded graphics of the window
-    <literal>win_num</literal> to file <literal>filen</literal> in Postscript
-    syntax. Note that <literal>filen</literal> must not have extension.</para>
-
-    <para><literal>xs2svg</literal> produces a complete encapsulated Postscrip
-    file.</para>
+    <literal>win_num</literal> to file <literal>filen</literal> in SVG syntax.
+    Note that <literal>filen</literal> must not have extension.</para>
   </refsection>
 
   <refsection>
index 424c3bb..b3436cd 100644 (file)
@@ -70,9 +70,9 @@ public class GL2PSGL extends DebugGL {
                case GL.GL_LINE_STIPPLE:
                        gl2ps.gl2psEnable(GL2PS.GL2PS_LINE_STIPPLE);
                        break;
-               case GL.GL_POLYGON_OFFSET_FILL:
+               /*case GL.GL_POLYGON_OFFSET_FILL:
                        gl2ps.gl2psEnable(GL2PS.GL2PS_POLYGON_OFFSET_FILL);
-                       break;
+                       break;*/
                case GL.GL_BLEND:
                        gl2ps.gl2psEnable(GL2PS.GL2PS_BLEND);
                        break;
index fd693b0..9cb5240 100644 (file)
@@ -15,6 +15,7 @@
 import java.io.File;
 import java.io.IOException;
 
+import javax.media.opengl.DebugGL;
 import javax.media.opengl.GL;
 import javax.media.opengl.GLAutoDrawable;
 
@@ -86,7 +87,9 @@ public class GL2PSRenderer extends ExportRenderer {
         * @param gLDrawable gLDrawable
         */
        public void display(GLAutoDrawable gLDrawable) {
+               
                GL2PS gl2ps = new GL2PS();
+               
 
                int buffsize = BUFFER_WIDTH * BUFFER_HEIGHT;                    
                sciRend = new SciRenderer(this.figureIndex);
@@ -111,7 +114,7 @@ public class GL2PSRenderer extends ExportRenderer {
                        
                        int gl2psBeginPageStatut = gl2ps.gl2psBeginPage(exportedFigure.getTitle(), "Scilab", null, format, 
                                        GL2PS.GL2PS_SIMPLE_SORT, GL2PS.GL2PS_USE_CURRENT_VIEWPORT | GL2PS.GL2PS_BEST_ROOT 
-                                       | exportOrientation, GL.GL_RGBA, 0, null, null, null, null, 
+                                       | GL2PS.GL2PS_SIMPLE_LINE_OFFSET | exportOrientation, GL.GL_RGBA, 0, null, null, null, null, 
                                        0, 0, 0, buffsize, ExportRenderer.getFileName());       
 
                        if (gl2psBeginPageStatut != GL2PS.GL2PS_SUCCESS) {
@@ -131,6 +134,12 @@ public class GL2PSRenderer extends ExportRenderer {
 
                        sciRend.init(gLDrawable);
                        sciRend.display(gLDrawable);
+                       
+                       
+                       DebugGL debug = new DebugGL(newGL);
+                       
+                       
+                       
 
                        int gl2psEndPageStatut = gl2ps.gl2psEndPage();
 
index ce75997..4c3f27f 100644 (file)
@@ -49,7 +49,8 @@ public class ScilabRendererProperties implements RendererProperties {
         * @see org.scilab.modules.renderer.figureDrawing.RendererProperties#forceDisplay()
         */
        public void forceDisplay() {
-               parentTab.draw();
+               //parentTab.draw();
+               parentCanvas.display();
        }
 
        /**
index f109eb0..ebb90ed 100644 (file)
@@ -115,7 +115,7 @@ public abstract class DrawableObjectGL extends ObjectGL {
                dlIndex = getGL().glGenLists(1);
                // as advised in OpenGL web site, don't use GL_COMPILE_AND_EXECUTE
                // but instead compile and then call the display list.
-               getGL().glNewList(dlIndex, GL.GL_COMPILE);
+               getGL().glNewList(dlIndex, GL.GL_COMPILE/*_AND_EXECUTE*/);
        }
        
        /**
index 7d8baeb..f48e999 100644 (file)
@@ -106,7 +106,11 @@ public class FecFacetDrawerGL extends AutoDrawableObjectGL {
         * @return double
         */
        protected double fecValueToColorMapIndex(double value, double zMin, double zMax) {
-               return ((value - zMin) / (zMax - zMin) * (colMax - colMin + 1.0) + colMin);
+               //return ((value - zMin) / (zMax - zMin) * (colMax - colMin + 1.0) + colMin);
+               return (colMax - colMin) / (zMax - zMin) * (value - zMax) + colMax;
+               
+               //return (colMax - colMin - 1) / (zMax - zMin) * (value - zMax) + colMax;
+               //return (colMax - colMin - zMin) / (zMax - zMin) * (value - zMax) + colMax;
        }       
        
        /**
@@ -145,7 +149,7 @@ public class FecFacetDrawerGL extends AutoDrawableObjectGL {
                        triangleColors[0] = fecValueToColorMapIndex(values[firstPoints[i]], zMin, zMax);
                        triangleColors[1] = fecValueToColorMapIndex(values[secondPoints[i]], zMin, zMax);
                        triangleColors[2] = fecValueToColorMapIndex(values[thirdPoints[i]], zMin, zMax);
-                       
+                                                               
                        ColoredTriangle ct = new ColoredTriangle(triangleCoords[0],
                                                                                                         triangleCoords[1],
                                                                                                         triangleCoords[2],
index b472888..fb0e0f6 100644 (file)
@@ -14,6 +14,7 @@
 
 package org.scilab.modules.renderer.figureDrawing;
 
+import javax.media.opengl.DebugGL;
 import javax.media.opengl.GLEventListener;
 import javax.media.opengl.GLAutoDrawable;
 import javax.media.opengl.GL;
@@ -52,6 +53,10 @@ public class SciRenderer
 
        DrawableFigureGL curFigure = FigureMapper.getCorrespondingFigure(renderedFigure);
        
+       GL curGL = gLDrawable.getGL();
+       DebugGL newGL = new DebugGL(curGL);
+       gLDrawable.setGL(newGL);
+       
        if (curFigure == null) {
                // figure has been destroyed
                // nothing to render
@@ -73,7 +78,9 @@ public class SciRenderer
 //     if (!gLDrawable.getAutoSwapBufferMode()) {
 //             gLDrawable.swapBuffers();
 //     }
+       gLDrawable.setGL(curGL);
           
+       curGL.glFlush();
 
   }
     
index e9cd34b..2716698 100644 (file)
@@ -80,8 +80,9 @@ public class GL2PSShadeFacetDrawer implements ShadeFacetDrawer {
         * @param color3 color of the polylines vertices
         */
        public void paintTriangle(Vector3D a, Vector3D b, Vector3D c, double color1, double color2, double color3) {            
-
+               
                //Calling this class will decompose triangle in colored polygons
+               
                ColoredTriangle ct = new ColoredTriangle(a, b, c, color1, color2, color3);
                TriangleDecomposition td = ct.decomposeTriangle();      
 
@@ -92,7 +93,7 @@ public class GL2PSShadeFacetDrawer implements ShadeFacetDrawer {
                        // we use gl.glBegin(GL.GL_TRIANGLES)
                        // so we decompose the polygon into triangles
 
-                       double[] polyColor = colorMaps.getColor(colorMaps.convertScilabToColorMapIndex(color));
+                       double[] polyColor = colorMaps.getColor(color);
                        gl.glColor3d(polyColor[0], polyColor[1], polyColor[2]);
                        Vector3D[] polygon = td.getPolygon(i);
                        
@@ -113,6 +114,13 @@ public class GL2PSShadeFacetDrawer implements ShadeFacetDrawer {
                }
        }
 
+       /**
+        * Paint the polygon given with the table of color
+        * @param triangleCoords coordinates of triangle & square
+        * @param triangleColors table of color
+        * @param gl GL 
+        * @param colorMap TexturedColorMap
+        */
        public void paintPolygon(Vector3D[] triangleCoords,
                        double[] triangleColors, GL gl, TexturedColorMap colorMap) {
 
index a52608e..7d94cdf 100644 (file)
@@ -42,6 +42,14 @@ public class JOGLShadeFacetDrawer implements ShadeFacetDrawer {
                
        }
 
+       
+       /**
+        * Paint the polygon given with the table of color
+        * @param triangleCoords coordinates of triangle & square
+        * @param triangleColors table of color
+        * @param gl GL 
+        * @param colorMap TexturedColorMap
+        */
        public void paintPolygon(Vector3D[] triangleCoords,
                        double[] triangleColors, GL gl, TexturedColorMap colorMap) {
                
index a8a5b75..10b573c 100644 (file)
@@ -94,7 +94,7 @@ public class LinearShadedFacetDrawerGL extends FacetDrawerGL {
                //Paint the polygon given with the table of color
                
                // if all the colors within the facet are 0, the don't draw it
-               boolean paintFacet = false;
+               boolean paintFacet = true;
                
                for (int i = 0; i < colors.length; i++) {
                        if (colors[i] > 0) {
index cc46348..d3ea067 100644 (file)
@@ -158,6 +158,7 @@ public class ColoredTriangle {
                } else {
                        
                        int nbPolygons = getNbPolygons(colorA, colorB, colorC);
+                       double curColor = min;
                        res.setNbPolygons(nbPolygons);
                        
                        //starting the polygon decomposition with the smallest color
@@ -170,7 +171,7 @@ public class ColoredTriangle {
 
                        for (int i = 0; i < nbPolygons - 1; i++) {                      
                                // color of the next polygon
-                               double curColor = min + i;                      
+                               
 
                                res.setPolygonColor(curColor, i);                       
                                Vector3D[] polygonDecomposed = getPolygon(prevI1, prevI2, prevSideI1, prevSideI2, curColor);
@@ -181,6 +182,9 @@ public class ColoredTriangle {
                                prevI2 = nextI2;
                                prevSideI1 = nextSideI1;
                                prevSideI2 = nextSideI2;
+                               
+                               
+                               curColor += 1;
                        }       
 
                        //ending the polygon decomposition with the biggest color
@@ -205,7 +209,7 @@ public class ColoredTriangle {
                                lastPoly[2] = tempOrientation;                          
                        }
                        
-                       res.setPolygonColor(max, nbPolygons - 1);
+                       res.setPolygonColor(curColor, nbPolygons - 1);
                        res.setPolygon(lastPoly, nbPolygons - 1);
                }
                return res;
@@ -219,9 +223,21 @@ public class ColoredTriangle {
         * @return number of polygons
         */
        public int getNbPolygons(double colorA, double colorB, double colorC) {
-               double min = Math.min(Math.min(colorA, colorB), colorC);
-               double max = Math.max(Math.max(colorA, colorB), colorC);
-               return (int) Math.round(max - min + 1);
+               // find lowest and highest colors
+               double colMin = Math.min(Math.min(colorA, colorB), colorC);
+               double colMax = Math.max(Math.max(colorA, colorB), colorC);
+               
+               // the number of polygon is the number of x,5 (x integer)
+               // which is between colMin and colMax plus 1.
+               // find x,5 which is just greater than colMin
+               colMin = getSuperiorHalf(colMin);
+               
+               // find x,5 which is just lower than colMax
+               colMax = getInferiorHalf(colMax);
+               
+               int res = (int) (colMax - colMin) + 2;
+               
+               return res;
        }
        
        /**  
@@ -276,8 +292,8 @@ public class ColoredTriangle {
                
                int nbIntersections = 0;                
 
-               /** Test for (P1, P2) & (BC) */
-               if (colorB != colorC) {
+               /* Test for (P1, P2) & (BC) */
+               if (colorB != colorC && colorB != curColor) {
                        double res1 = (colorC - curColor) / (colorC - colorB);
                        if (res1 >= 0 && res1 <= 1) {
                                Vector3D i1 = new Vector3D(res1, 0.0, 0.0);
@@ -287,11 +303,11 @@ public class ColoredTriangle {
                        }
                }               
                
-               /** Test for (P1, P2) & (AC) */
-               if (colorA != colorC) {
+               /* Test for (P1, P2) & (AC) */
+               if (colorA != colorC && colorA != curColor) {
                        double res2 = (colorC - curColor) / (colorC - colorA);
 
-                       if (res2 >= 0 && res2 <= 1 && colorC != colorA) {
+                       if (res2 >= 0 && res2 <= 1) {
                                Vector3D i2 = new Vector3D(0.0, res2, 0.0);
                                intersections[nbIntersections] = i2;
                                intersectionSides[nbIntersections] = Side.SIDE_AC;
@@ -299,12 +315,14 @@ public class ColoredTriangle {
                        }
                }
                
-               /** Test for (P1, P2) & (AB) */
+               /* Test for (P1, P2) & (AB) */
+               // If colorA or colorB equals curColor, then the intersection
+               // is on B or A. So the two previous tests have already been true.
                if (colorA != colorB) {
                        double res3 = (colorA - curColor) / (colorA - colorB);
                        double res4 = (colorB - curColor) / (colorB - colorA);
 
-                       if (res3 >= 0 && res4 >= 0 && colorA != colorB) {
+                       if (res3 >= 0 && res4 >= 0) {
                                Vector3D i3 = new Vector3D(res3, res4, 0.0);
                                intersections[nbIntersections] = i3;
                                intersectionSides[nbIntersections] = Side.SIDE_AB;
@@ -312,6 +330,15 @@ public class ColoredTriangle {
                        }
                }
                
+               
+               
+//             if (nbIntersections == 3) {//                   
+//                     if (intersections[0].equals(intersections[1])) {
+//                             intersections[1] = intersections[2];
+//                             intersectionSides[1] = intersectionSides[2];
+//                     }                       
+//             }
+               
                //Convert barycentric intersections coordinates to 3D coordinates 
                for (int i = 0; i < nbIntersections; i++) {
                        intersections[i] = barycentricCoordTo3D(intersections[i].getX(), intersections[i].getY());
@@ -332,11 +359,12 @@ public class ColoredTriangle {
                Vector3D[] polygons = null;
                Vector3D p = new Vector3D();    
                
-               Vector3D[] intersections = new Vector3D[2];
-               Side[] intersectionsSides = new Side[2];                
+               Vector3D[] intersections = new Vector3D[3];
+               Side[] intersectionsSides = new Side[3];                
                
                //finding nextI1 and nextI2     
-               intersectionsManager(curColor + GAP, intersections, intersectionsSides);                
+               double color = getSuperiorHalf(curColor);
+               intersectionsManager(color, intersections, intersectionsSides);         
                nextI1 = intersections[0];
                nextI2 = intersections[1];
                nextSideI1 = intersectionsSides[0];
@@ -455,6 +483,40 @@ public class ColoredTriangle {
                Vector3D AB = b.substract(a);
                Vector3D AC = c.substract(a);           
                return (AB.crossProduct(AC)).dotProduct(orientation) >= 0;
-       }       
+       }
+       
+       /**
+        * Compute the lowest value under the way of x.5 where x is an integer which is greater
+        * than the input value.
+        * @param value input value
+        * @return result of the function.
+        */
+       private double getSuperiorHalf(double value) {
+               double res = Math.ceil(value - 0.5) + 0.5;
+               
+               // if value is under the way x.5, res will be equal to value
+               if (res == value) {
+                       res += 1.0;
+               }
+               return res;
+       }
+       
+       /**
+        * Compute the highest value under the way of x.5 where x is an integer which is lower
+        * than the input value.
+        * @param value input value
+        * @return result of the function.
+        */
+       private double getInferiorHalf(double value) {
+               double res = Math.floor(value + 0.5) - 0.5;
+               
+               // if value is under the way x.5, res will be equal to value
+               if (res == value) {
+                       res -= 1.0;
+               }
+               return res;
+       }
+       
+       
 
 }
index 5f57e36..8029de2 100644 (file)
@@ -73,7 +73,7 @@ public class TriangleDecomposition {
         * @param polygonIndex of the polygon
         */
        protected void setPolygonColor(double color, int polygonIndex) {
-               this.polygonColors[polygonIndex] = (int) color;
+               this.polygonColors[polygonIndex] = (int) Math.round(color);
        }