path_string node

john's Avatar

john

18 Jun, 2017 12:46 AM

Attached is a custom node: path_string. It converts a path to SVG notation. I have also provided a subnetwork, path_table, that converts that path string into a table of points with attributes (contour number and point type).

NodeBox paths consist of both line segments and curves, but information about the curves is hidden. You can see the difference by checking the Points checkbox above the canvas: blue dots are normal points, red dots are curve control points. If you convert a path to points, all you get are the normal points.

Nodebox also fails to provide a way of separating paths into distinct contours. When morphing or resampling text paths you get an unwanted line connecting the insides of multi-contour letters with their outsides.

Path_string and path_table provide a way around both of these limitations. By filtering the path table you can extract clean contours, and by accessing point types (P for normal point, C for control point) you can finally see (and potentially manipulate) what's been hidden.

The demo network shows how path_string illuminates three example shapes: a text path ("ab"), a quad curve, and an arc.

The first screenshot shows the output of the path_table subnetwork, in this case showing some of the "ab" points. The other three screenshots show the three sample shapes with normal points shown as blue dots and control points shown as red dots.

It's fun to adjust the T and Distance parameters of the quad curve, or the degrees of the arc to see how the control points change.

Now that we can see and work with curves and contours, my goal is to provide a way of reversing the process: turn strings back into paths. This would make it possible to precisely morph curves, draw a whole new class of curves with asymmetric control points, and who knows what else. Thanks to Frederik for pointing me to the location of the RenderPathData function.

  1. Support Staff 1 Posted by john on 19 Jun, 2017 09:31 AM

    john's Avatar

    A correction and some new tricks...

    I said Nodebox hides the information about curves. This is not entirely true. When you convert a path to points, you do get all the points (including the control points). I meant that Nodebox hides which points are which.

    But it turns out there is a way to make Nodebox reveal this secret. The trick is to do a lookup on "type". If you do this to a list of points you will see 1, 2, or 3 for each point.

    1 = LINE_TO (normal point)
    2 = CURVE_TO (normal point at end of curve)
    3 = CURVE_DATA (control point)

    Using this trick, you could compute the type column in my path_table without having to convert the path to an SVG path string.

    I also said that NodeBox fails to provide a way of separating paths into distinct contours. It doesn't provide a node to do this, but after some experimentation, I did find a way of doing this using ordinary nodes.

    The trick is the Resample node, the only node that acknowledges the existence of contours. If you give this node a path with multiple contours, set method to "By amount" and points to 1, then check "Per Contour", you will get the starting point of each contour. You can then locate the first occurrence of each starting point and use that information to slice the path into individual contours.

    I demonstrate this technique here:

    http://support.nodebox.net/discussions/show-your-work/205-replace-i...

    I realize this is very arcane. But insights like this can help you gain full control over NodeBox paths.

  2. Support Staff 2 Posted by john on 22 Jun, 2017 07:49 AM

    john's Avatar

    One more update and another gift...

    I just used the path_string node to solve a problem I encountered at work. I needed to import an SVG file into NodeBox of a flowchart made of boxes, ellipses, straight lines, curved lines, and arrows. When NodeBox reads in an SVG it sometimes looses the fill and stroke colors, forcing you to colorize them yourself.

    Each of these objects have to be colorized in a different way, so in order to reconstruct the SVG I had to be able to tell the objects apart. I had been using point count, but I discovered that some curves had the same number of points as the ellipses. So how could I tell them apart?

    The most obvious difference is that curves are open and ellipses are closed. So how could I tell if a given path was open or closed? Doing a lookup on the closed property doesn't work.

    path_string to the rescue! The SVG path string of a path contains a "Z" for each closed contour. So all I had to do was feed each path into path_string and feed that string into a simple subnetwork I wrote to detect the presence of a "Z". Problem solved.

    Demo with "is_closed" subnetwork attached. Enjoy!

  3. Support Staff 3 Posted by Frederik De Ble... on 29 Jun, 2017 09:18 AM

    Frederik De Bleser's Avatar

    Wow, this is great! The SVG import trick really sounds like "hacks upon hacks", we should figure out a better way to retain more information on the path...

  4. Support Staff 4 Posted by john on 29 Jun, 2017 10:07 AM

    john's Avatar

    I agree: mucking with SVG notation departs from the true spirit of NodeBox which is to liberate right-brained artists from the tedium of cryptic code stuff.

    The goal should be to give the artist full control over paths. It should be easy to pull multiple contours out of a path, tell curves from lines, see if contours are closed and be able to close or open them, etc.

    NodeBox should also provide the ability to make curves with arbitrary control points, not just the pre-determined control points of arcs and quads. I have already made a custom curve node to do this, but am still looking for something interesting to do with it. I found an open source algorithm for finding control points which follow a sequence of points but have not yet found the time to adapt it.

    I was hoping that if you could make your release process more automatic we would see the improvements to CSV export you promised and then a whole cascade of other long-requested features. How is that coming?

  5. Support Staff 5 Posted by Frederik De Ble... on 29 Jun, 2017 10:41 AM

    Frederik De Bleser's Avatar

    The process is certainly automated now, which does make it easier to make releases.

    However I've been caught up in end-of-academic year meetings and discussions.

    I'll try to make a release with the latest CSV updates before I leave on holiday next week.

  6. Support Staff 6 Posted by Frederik De Ble... on 29 Jun, 2017 03:48 PM

    Frederik De Bleser's Avatar
  7. Support Staff 7 Posted by john on 29 Jun, 2017 10:25 PM

    john's Avatar

    Thanks, Frederik!

    Installed on my Mac and it works perfectly:

    • default comma means I can just double-click to open in Excel
    • opting out of quotes means my Graphviz file opened perfectly
    • column order is no longer scrambled

    However, when I tried downloading the .EXE on my work PC and launching the installer from the desktop, I got a cascade of errors:

    Failed to find library,
    C:<my_domain>\AppData\Local\NodeBox\runtime\bin\client\jvm.dll

    Failed to locate JNI_CreateJavaVM

    Failed to launch JVM

    I tried uninstalling, rebooting, to no avail. During the install process I think I saw it saying it was installing jvm.dll, but when I look in runtime\bin\client it is not there - or anywhere else on my machine.

    At that point, NodeBox was completely hosed on my PC. But I had an old 3.46 exe file and running that restored the older version. There is still no jam.dll file on my machine.

    Perhaps some other PC user can verify. But for me, the PC install did not work.

    John

  8. Support Staff 8 Posted by john on 29 Jun, 2017 10:51 PM

    john's Avatar

    Update:

    I tried uninstalling Java on my PC, reinstalling Java, then reinstalling NodeBox 3.0.48. No change. Still failed to find the jvm.dll. Once I reinstalled 3.0.46 I was able to run the older version again.

  9. 9 Posted by rioch on 30 Jun, 2017 01:36 AM

    rioch's Avatar

    this time it just worked fine for me, but I remember after uninstalling you had to delete the C:\Users\X\AppData\Local\NodeBox folder also, at least at some moment, check this thread: http://support.nodebox.net/discussions/general-discussion/14713-cant-start-nodebox-3045

  10. Support Staff 10 Posted by john on 30 Jun, 2017 02:00 AM

    john's Avatar

    Rioch,

    That did the trick! I deleted the NodeBox folder, re-ran the installer, and now 3.0.48 works fine on my PC. I celebrated by hooking seven strings to a concatenate node.

    Thanks. And thanks again, Frederik.

    John

  11. Support Staff 11 Posted by Frederik De Ble... on 30 Jun, 2017 07:23 AM

    Frederik De Bleser's Avatar

    Hmm, I should find a way to fix this so installs are always "clean" installs.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • path_string_shot1.png 527 KB
  • path_string_shot2.png 366 KB
  • path_string_shot3.png 308 KB
  • path_string_shot4.png 346 KB
  • path_string.zip 2.95 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

16 Jun, 2022 05:30 AM
15 Jun, 2022 06:03 AM
06 Jun, 2022 01:07 PM
02 Jun, 2022 11:58 PM
30 May, 2022 07:48 AM

 

24 May, 2022 06:27 PM
20 May, 2022 04:12 PM
05 May, 2022 02:25 AM
03 May, 2022 04:46 AM
01 May, 2022 09:22 AM
18 Apr, 2022 09:01 PM