Identifyin and Splitting separate geometry elements

Have jReality programming problems or questions? Post them here.
Post Reply
NormanGraf
Posts: 18
Joined: Wed 1. Sep 2010, 23:53

Identifyin and Splitting separate geometry elements

Post by NormanGraf » Mon 1. Aug 2011, 20:50

Hello,
I'm working on a project which requires me to read in files in the STL format. Oftentimes these files contain more than one discrete object, so I would like to split them up, or be able to create an element hierarchy and access them separately in the viewer. I've written some code which allows me to identify simple objects in small files, but the algorithm does not scale well for larger or more complicated files. I'm wondering if there are any existing tools which would allow me to efficiently identify separate geometry elements in the scene?

As a concrete example, here's an stl file containing two cubes (it seems files with an stl extension are not accepted as attachments). I'd like to be able to read this in, identify the two separate cubes and then either create a scene hierarchy with the two separate cubes, or simply write each out as a separate file.

Any help would be appreciated.
Thank you very much,
Norman

  • solid stl file generated by hand
    facet normal 0.000000 -1.000000 0.000000
    outer loop
    vertex -2.500000 -0.500000 -0.500000
    vertex -1.500000 -0.500000 0.500000
    vertex -2.500000 -0.500000 0.500000
    endloop
    endfacet
    facet normal 0.000000 -1.000000 0.000000
    outer loop
    vertex -1.500000 -0.500000 0.500000
    vertex -2.500000 -0.500000 -0.500000
    vertex -1.500000 -0.500000 -0.500000
    endloop
    endfacet
    facet normal 0.000000 1.000000 0.000000
    outer loop
    vertex -1.500000 0.500000 -0.500000
    vertex -2.500000 0.500000 0.500000
    vertex -1.500000 0.500000 0.500000
    endloop
    endfacet
    facet normal 0.000000 1.000000 0.000000
    outer loop
    vertex -2.500000 0.500000 0.500000
    vertex -1.500000 0.500000 -0.500000
    vertex -2.500000 0.500000 -0.500000
    endloop
    endfacet
    facet normal 0.000000 0.000000 1.000000
    outer loop
    vertex -2.500000 0.500000 0.500000
    vertex -1.500000 -0.500000 0.500000
    vertex -1.500000 0.500000 0.500000
    endloop
    endfacet
    facet normal 0.000000 0.000000 1.000000
    outer loop
    vertex -1.500000 -0.500000 0.500000
    vertex -2.500000 0.500000 0.500000
    vertex -2.500000 -0.500000 0.500000
    endloop
    endfacet
    facet normal 0.000000 0.000000 -1.000000
    outer loop
    vertex -2.500000 -0.500000 -0.500000
    vertex -1.500000 0.500000 -0.500000
    vertex -1.500000 -0.500000 -0.500000
    endloop
    endfacet
    facet normal 0.000000 0.000000 -1.000000
    outer loop
    vertex -1.500000 0.500000 -0.500000
    vertex -2.500000 -0.500000 -0.500000
    vertex -2.500000 0.500000 -0.500000
    endloop
    endfacet
    facet normal -1.000000 0.000000 0.000000
    outer loop
    vertex -2.500000 -0.500000 -0.500000
    vertex -2.500000 0.500000 0.500000
    vertex -2.500000 0.500000 -0.500000
    endloop
    endfacet
    facet normal -1.000000 0.000000 0.000000
    outer loop
    vertex -2.500000 0.500000 0.500000
    vertex -2.500000 -0.500000 -0.500000
    vertex -2.500000 -0.500000 0.500000
    endloop
    endfacet
    facet normal 1.000000 0.000000 0.000000
    outer loop
    vertex -1.500000 -0.500000 0.500000
    vertex -1.500000 0.500000 -0.500000
    vertex -1.500000 0.500000 0.500000
    endloop
    endfacet
    facet normal 1.000000 0.000000 0.000000
    outer loop
    vertex -1.500000 0.500000 -0.500000
    vertex -1.500000 -0.500000 0.500000
    vertex -1.500000 -0.500000 -0.500000
    endloop
    endfacet
    facet normal 0.000000 -1.000000 0.000000
    outer loop
    vertex 1.500000 -0.500000 -0.500000
    vertex 2.500000 -0.500000 0.500000
    vertex 1.500000 -0.500000 0.500000
    endloop
    endfacet
    facet normal 0.000000 -1.000000 0.000000
    outer loop
    vertex 2.500000 -0.500000 0.500000
    vertex 1.500000 -0.500000 -0.500000
    vertex 2.500000 -0.500000 -0.500000
    endloop
    endfacet
    facet normal 0.000000 1.000000 0.000000
    outer loop
    vertex 2.500000 0.500000 -0.500000
    vertex 1.500000 0.500000 0.500000
    vertex 2.500000 0.500000 0.500000
    endloop
    endfacet
    facet normal 0.000000 1.000000 0.000000
    outer loop
    vertex 1.500000 0.500000 0.500000
    vertex 2.500000 0.500000 -0.500000
    vertex 1.500000 0.500000 -0.500000
    endloop
    endfacet
    facet normal 0.000000 0.000000 1.000000
    outer loop
    vertex 1.500000 0.500000 0.500000
    vertex 2.500000 -0.500000 0.500000
    vertex 2.500000 0.500000 0.500000
    endloop
    endfacet
    facet normal 0.000000 0.000000 1.000000
    outer loop
    vertex 2.500000 -0.500000 0.500000
    vertex 1.500000 0.500000 0.500000
    vertex 1.500000 -0.500000 0.500000
    endloop
    endfacet
    facet normal 0.000000 0.000000 -1.000000
    outer loop
    vertex 1.500000 -0.500000 -0.500000
    vertex 2.500000 0.500000 -0.500000
    vertex 2.500000 -0.500000 -0.500000
    endloop
    endfacet
    facet normal 0.000000 0.000000 -1.000000
    outer loop
    vertex 2.500000 0.500000 -0.500000
    vertex 1.500000 -0.500000 -0.500000
    vertex 1.500000 0.500000 -0.500000
    endloop
    endfacet
    facet normal -1.000000 0.000000 0.000000
    outer loop
    vertex 1.500000 -0.500000 -0.500000
    vertex 1.500000 0.500000 0.500000
    vertex 1.500000 0.500000 -0.500000
    endloop
    endfacet
    facet normal -1.000000 0.000000 0.000000
    outer loop
    vertex 1.500000 0.500000 0.500000
    vertex 1.500000 -0.500000 -0.500000
    vertex 1.500000 -0.500000 0.500000
    endloop
    endfacet
    facet normal 1.000000 0.000000 0.000000
    outer loop
    vertex 2.500000 -0.500000 0.500000
    vertex 2.500000 0.500000 -0.500000
    vertex 2.500000 0.500000 0.500000
    endloop
    endfacet
    facet normal 1.000000 0.000000 0.000000
    outer loop
    vertex 2.500000 0.500000 -0.500000
    vertex 2.500000 -0.500000 0.500000
    vertex 2.500000 -0.500000 -0.500000
    endloop
    endfacet
    endsolid

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: Identifyin and Splitting separate geometry elements

Post by gunn » Wed 3. Aug 2011, 21:28

Does the STL format support more than one geometry explicitly, or does one have to figure it out by hand (notice for example that there are two cubes by tracing out the combinatorics of the faces and noticing that there are two connected components in the groups of faces)? If the latter is the case, then I wouldn't expect that the ReaderSTL class (in de.jreality.io) would be able to help. I gave a quick look into the class de.jreality.geometry.IndexedFaceSetUtility to see if there is a method which carries out the search for independent "pieces" outlined above, but I don't see anything that looks like it does that.

If nobody else posts a better answer and you end up having to write a "splitter" yourself, please consider posting the result on this thread so we can possibly add it to jReality source.

You also write:
it seems files with an stl extension are not accepted as attachments
What do you mean by that? That jReality won't read in .stl files?
jReality core developer

NormanGraf
Posts: 18
Joined: Wed 1. Sep 2010, 23:53

Re: Identifyin and Splitting separate geometry elements

Post by NormanGraf » Tue 9. Aug 2011, 18:41

Thank you for your prompt reply.
Technically, the STL file format description does not allow more than one "solid" per file, but I have come across files which have been exported from some CAD programs which do so. (I have modified the STL file reader for my own use in testing these types of files, and intend to feed this back once I have a robust implementation.) But in general, one would have to identify separate meshes by hand. The algorithm I implemented for simple geometries started with a node and simply walked through all the connected vertices. It's neither efficient, nor frugal with memory, so does not scale to larger, more complicated geometries. I was hoping that there might be some nice topological mesh splitting functions or classes in the geometry packages, but did not find anything obvious, which is why I posted here.
I will continue to work on this and post any new developments, but would appreciate any hints or suggestions for solving what I assumed was a more general problem.
I tried to attach the .stl file to my post, but the forum software claimed that files with an extension .stl were not accepted. The jReality code reads and parses the file just fine.

Andre
Posts: 226
Joined: Fri 18. Sep 2009, 11:30

Re: Identifyin and Splitting separate geometry elements

Post by Andre » Fri 19. Aug 2011, 21:10

what about renaming the file from .stl to .txt and uploading it?

Post Reply