Hi Thomas Thanks for that. I followed your advice and set all the triangles to be rendered in a clockwise direction. The problem is now solved.
Rob -----Original Message----- From: Thomas DeWeese [mailto:[EMAIL PROTECTED] Sent: Wednesday, 20 July 2005 12:12 To: [email protected] Subject: Re: Filling TriangleStripArrays Hi Rob, Well I can see a few options here. First the simplest is to just use 'shape-rendering="crispEdges"'. This turns off anti-aliasing so the drop outs disappear. The second option would be to ensure that the 'shared edge' is always drawn in opposite directions. so in your example the shared edge is the 120,120->130,140 but both triangles draw that the same direction if you reverse one of the directions then the fill appears to be seamless. For triangles it's pretty easy to ensure this, you just need to make sure that you always list the points them in the same direction (clock wise or counter clock wise around the triangle). You can tell which direction you are drawing by taking the cross product of the two out going vectors from a point, see: http://astronomy.swin.edu.au/~pbourke/geometry/clockwise/ Also since you say this is a triangleStripArray if you walk the array properly you can ensure this as well (although it may not be the most natural way to walk the strip). Anyway I hope this helps. <?xml version="1.0"?> <svg width="300" height="300" viewBox="0 0 300 300" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"> <path d="M120 120 L140 120 L130 140 z M100 140 L120 120 L130 140 z" fill="blue"/> </svg> Rob Hackett wrote: > - Platform Windows XP > - JDK 1.4.2 > - Batik 1.6 > > Hi > > I am attempting to render some data to an SVG file which is produced as a > Java3d > TriangleStripArray. I do this by parsing through the individual triangles > and appending them > to a GeneralPath as follows: > > path.moveTo(xTri1[0], yTri1[0]); > path.lineTo(xTri1[1], yTri1[1]); > path.lineTo(xTri1[2], yTri1[2]); > > Then I close and fill the GeneralPath > > The resulting SVG file looks great when viewed through the Adobe SVG plugin, > but when I view > it through squiggle, there are narrow gaps between all of the triangles. > When I use the > batik PNGTranscoder to convert the SVG file to a PNG, the narrow gaps become > a pixel wide and > the resulting image looks a mess. > > If I fill the triangles individually rather than by appending them to a > general path, the > result is fine, but over tens of thousands of triangles there is a massive > loss in > performance and increase in file size. Can anyone suggest a way forward? > > I have attached a segment of code which illustrates the problem: > > import java.awt.Dimension; > import java.awt.Polygon; > import java.awt.geom.GeneralPath; > > import java.io.BufferedOutputStream; > import java.io.FileNotFoundException; > import java.io.IOException; > import java.io.File; > import java.io.FileOutputStream; > import java.io.OutputStream; > import java.io.OutputStreamWriter; > import java.io.UnsupportedEncodingException; > import java.io.Writer; > > import org.apache.batik.svggen.SVGGraphics2D; > import org.apache.batik.svggen.SVGGraphics2DIOException; > import org.apache.batik.dom.GenericDOMImplementation; > import org.w3c.dom.Document; > import org.w3c.dom.DOMImplementation; > import org.w3c.dom.Element; > > public class SVGTest { > public SVGTest() > throws > SVGGraphics2DIOException, > IOException, > UnsupportedEncodingException > { > DOMImplementation domImpl = > GenericDOMImplementation.getDOMImplementation(); > Document document = > domImpl.createDocument(null, "svg", null); > SVGGraphics2D graphics2d = new SVGGraphics2D(document); > > int width = 200; > int height = 200; > Dimension size = new Dimension(width, height); > graphics2d.setSVGCanvasSize(size); > > GeneralPath path = > new GeneralPath(GeneralPath.WIND_EVEN_ODD); > > // Define triangle coordinates > int[] xTri1 = {120, 140, 130}; > int[] yTri1 = {120, 120, 140}; > int[] xTri2 = {120, 100, 130}; > int[] yTri2 = {120, 140, 140}; > > // Draw triangle1 > path.moveTo(xTri1[0], yTri1[0]); > path.lineTo(xTri1[1], yTri1[1]); > path.lineTo(xTri1[2], yTri1[2]); > > // Draw triangle2 > path.moveTo(xTri2[0], yTri2[0]); > path.lineTo(xTri2[1], yTri2[1]); > path.lineTo(xTri2[2], yTri2[2]); > > // Close and fill path > path.closePath(); > graphics2d.fill(path); > > Element svgRoot = ((SVGGraphics2D)graphics2d).getRoot(); > svgRoot.setAttributeNS(null, "viewBox", > "0, 0, " + String.valueOf(width) + ", " + > String.valueOf(height)); > BufferedOutputStream outStream = > new BufferedOutputStream( > new FileOutputStream("c:/test.svg")); > Writer outWriter = > new OutputStreamWriter(outStream, "UTF-8"); > > graphics2d.stream(svgRoot, outWriter, true); > > outWriter.flush(); > outWriter.close(); > } > > public static void main(String[] args) { > try { > SVGTest test = new SVGTest(); > } catch (IOException e) { > System.err.println("Doh! " + e); > } > > } > } > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
