Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 23

Thread: Weighted Centroidal Voronoi Stippling using JTS

  1. #11
      Redrobes is offline
    Software Dev/Rep Redrobes's Avatar
    Join Date
    Dec 2007
    Location
    England
    Posts
    4,765
    Blog Entries
    4

    Default

    You can do that in three lines of perl or sed using a regular expressions (and one of those was just to add extra spaces after the commas). If this is the sort of thing you are doing then you should ensure your well familiar with them cos it makes manipulation like this so easy.

    Code:
    $in = '<path d="M 258.59905,189.69191 80.812204,365.45845 264.65997,692.74788 220.21325,510.92042 519.21841,434.14883 385.87827,246.26045 z" />';
    $out = $in;
    
    $out =~ s/<path d="M /LINESTRING (/;
    $out =~ s/ z" \/>/)/;
    $out =~ s/,/, /g;
    
    print "Before: $in\n";
    print "After : $out\n";
    
    
    
    # Results:
    #
    # Before: <path d="M 258.59905,189.69191 80.812204,365.45845 264.65997,692.74788 220.21325,510.92042 519.21841,434.14883 385.87827,246.26045 z" />
    # After : LINESTRING (258.59905, 189.69191 80.812204, 365.45845 264.65997, 692.74788 220.21325, 510.92042 519.21841, 434.14883 385.87827, 246.26045)
    #

  2. #12
      Hai-Etlik is offline
    Guild Expert Gracious Donor Hai-Etlik's Avatar
    Join Date
    May 2009
    Location
    48° 28′ N 123° 8′ W
    Posts
    1,082
    Blog Entries
    1

    Default

    That might work in this very specific case, but not for SVG Path Data in general. Like I said, SVG is flexible and allows a lot of different ways of expressing things. Dealing with all those different ways is the hard part. You can express numbers as integers, decimals, or in scientific notiation, you can use commas or spaces as separators, commands and numbers don't need to be separated, but can be, commands can be omitted in which case you repeat the previous one with the next set of parameters, unless it was a moveto command in which case you treat the repetitions as lineto commands. Closed paths are handled differently between the two requiring that you keep track of the first point of any subpath, and just about every command has a relative form requiring you keep track of the most recent point as well.

    And that's not even getting into the problem of all the curved path sections like bezier curves and elliptic arcs.

    PS:
    That said, I am using Regexps, it just takes a fair bit beyond regexps. Also, I wanted to be able to load directly into JTS; the WKT export is just corollary of sorts since JTS already has WKT export. Ultimately I'd be aiming to use the Centroidal Voronoi algorithm from the start of the thread on shapes loaded from an SVG file.

    PPS: The topological issues with turning closed SVG paths into JTS Polygons or Multipolygons is going to be a lot of work too. SVG allows subpaths to intersect themselves and each other, and doesn't make topological distinctions between them. The The OGC Simple Features data model used by JTS doesn't allow intersecting rings, and does make a distinction between a polygons with an enclave, and a multipolygon with an exclave.
    Last edited by Hai-Etlik; 06-29-2011 at 05:57 PM.

  3. #13
      Master TMO is offline
    Guild Adept Master TMO's Avatar
    Join Date
    May 2010
    Posts
    368

    Default

    Lordy, I remember just barely touching on some things similar to these issues way back when in earlier software, and all the headaches it caused.

    Good luck, and you have my sympathies!
    My Finished Maps | My Planet Maps | My Challenge Entries | Album: Pre-generated Worlds

    ------
    Assuming I stick with fantasy cartography, I'd like to become a World Builder, laying out not only a realistic topography, but also the geopolitical boundaries and at least rough descriptions of the countries and societies.

  4. #14
    Guild Apprentice Terraformer_Author's Avatar
    Join Date
    Nov 2010
    Location
    Eastern U.S.A.
    Posts
    27

    Default

    Ok - who woke me up!!!! Lol.

  5. #15
      Hai-Etlik is offline
    Guild Expert Gracious Donor Hai-Etlik's Avatar
    Join Date
    May 2009
    Location
    48° 28′ N 123° 8′ W
    Posts
    1,082
    Blog Entries
    1

    Default

    Inspired by This post I've done a bit more work on this using the Wang Tile + Progressive Poisson Disc technique rather than Weighted Centroidal Voronoi.

    It still needs some work, and there are some bugs I'm feeling completely lost on, but It's producing something somewhat reasonable now, and it's FAR faster.

    Weighted Centroidal Voronoi Stippling using JTS-g382385.png

  6. #16
      Hai-Etlik is offline
    Guild Expert Gracious Donor Hai-Etlik's Avatar
    Join Date
    May 2009
    Location
    48° 28′ N 123° 8′ W
    Posts
    1,082
    Blog Entries
    1

    Default

    OK, much smoother now that I've got the re-ranking step done. It dies on the seam finding step at random, so there's something wrong there. I'll be saving the generated tiles and simply load them in future, but it still would be nice to not have to run the generator several times to get a tile set out of it.

    Weighted Centroidal Voronoi Stippling using JTS-g382385.png

  7. #17
      Hai-Etlik is offline
    Guild Expert Gracious Donor Hai-Etlik's Avatar
    Join Date
    May 2009
    Location
    48° 28′ N 123° 8′ W
    Posts
    1,082
    Blog Entries
    1

    Default

    Running a greyscale photo through it.

    Weighted Centroidal Voronoi Stippling using JTS-g4.png

  8. #18
      Lukc is offline
    Community Leader Gracious Donor Lukc's Avatar
    Join Date
    Sep 2011
    Location
    Lausanne, CH
    Posts
    1,506

    Default

    Stipple-icious indeed . Most of this goes a bit over my head, I fear ... but if it was easy to use, I would definitely use it!

  9. #19
      Hai-Etlik is offline
    Guild Expert Gracious Donor Hai-Etlik's Avatar
    Join Date
    May 2009
    Location
    48° 28′ N 123° 8′ W
    Posts
    1,082
    Blog Entries
    1

    Default

    Quote Originally Posted by Lukc View Post
    Stipple-icious indeed . Most of this goes a bit over my head, I fear ... but if it was easy to use, I would definitely use it!
    I'll probably try to wrap some kind of interface around it when I've got it cleaned up and tested. For now though, here's a test of a stippled coastline effect.

    Weighted Centroidal Voronoi Stippling using JTS-stipple.png

  10. #20
      Hai-Etlik is offline
    Guild Expert Gracious Donor Hai-Etlik's Avatar
    Join Date
    May 2009
    Location
    48° 28′ N 123° 8′ W
    Posts
    1,082
    Blog Entries
    1

    Default

    By using a function of distance inside the polygon for the density, making a simple arc shape as a stipple, and rotating it to face the nearest edge, I managed a fairly good looking forest symbol. It's not perfect, but I can probably improve it a bit.

    Weighted Centroidal Voronoi Stippling using JTS-path406447.png

Page 2 of 3 FirstFirst 123 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •