How do I combine many lines/points/curves into a single 'object'?

edited November 2016 in How To...

Apologies in advance if this has a trivially easy answer. Basically, I/my coworkers often run into the same problem with illustrating large datasets (say, a couple million points). Processing can handle it just fine and can export a vector image format just fine, but when importing the figure to another program (typically Adobe Illustrator or inkscape), they can't deal with each data point being a unique object, so they tend to crash.

My question, then, is is there a way in processing to combine all of the points, lines, etc. into a single object (object may not be the proper word), so when we open them in Illustrator it seems one object, rather than millions? I had hopes that PShapes would be the solution, but it seems that processing draws each child shape as its own object when exporting them. Thanks in advance for any help you can give!

Answers

  • If I understood your question properly, what you would need to do is get each of the vertices of you child PShapes and add them seperately to your parent PShape.

  • Hmm...this sort of works. I indeed end up with a single object to export for post-processing, but now there are lines that I don't want connecting all of the points that are supposed to be there. And it doesn't seem I can just turn off the stroke for these 'joiner lines,' unless I'm just missing something.

  • there was a bug in this area but it's fixed in the newest version, apparently

    or it could be something you are doing, but without seeing any code we can't tell...

  • Please give an example of the problem by sharing a sketch that produces a "broken" large vector image. Optionally, attach an example of the broken vector file output.

    What specific versions of Illustrator and Inkscape (and on what OS) are your broken files failing against?

  • Here's a simplified version of what I'm talking about. I tend to write most things in python mode, but if the java version would be easier I can go back and rework it.

    size(500,500)
    background(255)
    noFill()
    x1 = 100
    pair1 = 150
    x2 = 140
    pair2 = 190
    x3 = 175
    pair3 = 225
    
    #Option 1: Individual curves
    bezier(x1, 150, 100, 50, 200, 50, pair1, 150)
    bezier(x2, 150, 100, 50, 200, 50, pair2, 150)
    bezier(x3, 150, 100, 50, 200, 50, pair3, 150)
    
    #Option 2: Continuous shape
    pairs = createShape()
    pairs.beginShape()
    pairs.vertex(x1, 300)
    pairs.bezierVertex(100, 200, 200, 200, pair1, 300)
    pairs.vertex(x2, 300)
    pairs.bezierVertex(100, 200, 200, 200, pair2, 300)
    pairs.vertex(x3, 300)
    pairs.bezierVertex(100, 200, 200, 200, pair3, 300)
    pairs.endShape()
    shape(pairs)
    
    #Option 3: Group shapes
    parent = createShape(GROUP)
    parent.beginShape()
    child = createShape()
    child.beginShape()
    child.vertex(x1, 450)
    child.bezierVertex(100, 350, 200, 350, pair1, 450)
    child.endShape()
    parent.addChild(child)
    
    child = createShape()
    child.beginShape()
    child.vertex(x2, 450)
    child.bezierVertex(100, 350, 200, 350, pair2, 450)
    child.endShape()
    parent.addChild(child)
    
    child = createShape()
    child.beginShape()
    child.vertex(x3, 450)
    child.bezierVertex(100, 350, 200, 350, pair3, 450)
    child.endShape()
    parent.addChild(child)
    
    shape(parent)
    

    So option 1 ends up with just three individual curves as separate objects, option 2 outputs a single object, but with extra lines joining each bezierVertex with the following vertex, and option 3 outputs the same as option 1, since I create a new 'child' shape for each data point.

    The files aren't really 'broken' per se, they often aren't even that large, but when each curve is drawn as a separate object and there are hundreds of thousands or millions of curves, Inkscape (v. 0.91 on OS X 10.9.5, btw) can't handle it. So being able to draw all of the curves as a single object without the connecting lines would be awesome.

  • You don't have parent.endshape(); ? after line 30

    not sure if this relevant

  • You don't have parent.endshape(); ? after line 30

    adding one gets you an error: Cannot end GROUP shape

    image

  • that's how i'd expect things to look tbh - in option 2 it's all one shape. just because you are switching between vertex and bezierVertex doesn't mean the shape finishes.

  • Maybe use noStroke()? I'll test in a day and tell you.

  • that's how i'd expect things to look tbh - in option 2 it's all one shape. just because you are switching between vertex and bezierVertex doesn't mean the shape finishes.

    You're exactly right - I'm just trying to figure out how to get the best of both worlds by having the curves 'look' separate while actually being a single object.

    Maybe use noStroke()? I'll test in a day and tell you.

    I tried with no luck using noStroke() between each bezierVertex and the following vertex, but so far as I can tell it's not possible to change that between beginShape/endShape (at least not with the default renderer. There may be other workarounds though that I'm not familiar with.

  • Best of luck then. You could see this question.

Sign In or Register to comment.