Define a volume by boundary planes

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
yorik
Founder
Posts: 13597
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Define a volume by boundary planes

Post by yorik »

Hi there,

I'd like to introduce the concept of space in the arch module. A space is an empty volume defined by boundary faces (selected faces of walls, floors or ceilings, that don't necessarily intersect). The thing is, how to build such space?

Maybe OCC has some tool to do that automatically? But I haven't seen any... (BOP_SolidBuilder maybe? I'm not sure if the faces must not already form a shell...)
Other idea I had, is to start with a big box encompassing all the objects I want as boundaries, then slicing it with each of the boundary planes, removing outside parts. But that won't work in case there are convex angles.

Any better idea?
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Define a volume by boundary planes

Post by jriegel »

In not to complicated cases (as I assume in Arch) you can use vector calculus.
Basically the task is to calculate all the vertexes and build up a BRep from the ground up.

E.g. you have a ceiling and a floor. So you go through the walls and calculate the intersection of you wall boundaries with you floor and ceiling.
With this vertexes you can create edges and wires for floor and ceiling. Then add edges to the corosponding vertexes and you basically done.

If its more complicated you can surly use boolean operation and use the planes to create cut volumes. That will lead to a secure solution, but slower...
Stop whining - start coding!
User avatar
yorik
Founder
Posts: 13597
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Define a volume by boundary planes

Post by yorik »

Hm interesting, I hadn't thought of building edges and wires like that... Very good solution, thanks!
crashfridh
Posts: 143
Joined: Thu Jan 03, 2013 1:42 pm

Re: Define a volume by boundary planes

Post by crashfridh »

Interesting that you brought this up. I am also thinking of this for noise transmission from a structural component to a cavity/space. At first I thought of filling the space manually with an object and using that volume, but it would of course be much nicer if required would be at most the addition of one or more planes to close the cavity.

From an acoustic/architectural point of view it is also nice to have the volume of the cavity in order to quickly calculate the reverberation time using Sabine or Eyring. I don't know what your application is Yorik but considering you're working with the Arch module I suppose it might be relevant for you as well.

Freddy
Frederik
User avatar
yorik
Founder
Posts: 13597
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Define a volume by boundary planes

Post by yorik »

Wow, it would, indeed... Do you work with acoustic? That's an area from which still nobody had appeared here...
I made a mantis issue for this here: https://sourceforge.net/apps/mantisbt/f ... php?id=982
There you'll also find a sketch with kind of plan of what I intend to do. After some thought I think the method of trimming
bounding boxes with booleans will be better in this case, because in many cases there will be "holes", and it will be hard to
determine where the intersections are... With this method you always get a valid volume.
crashfridh
Posts: 143
Joined: Thu Jan 03, 2013 1:42 pm

Re: Define a volume by boundary planes

Post by crashfridh »

yes, I am about to finish my study in acoustics.

I think the cavity is something of a virtual solid. It should have a volume which is determined by the adjacent faces, and it has a shape of itself, where all the vertices and faces are links/references to those of the actual geometry. If the surrounding geometry changes, then this cavity is preferably updated as well.

Why would I like the cavity to have references to the adjacent geometry?
For acoustics there are three things:
  • By giving the actual geometry absorption values it will be very simple to calculate the reverberation times.
  • For boundary element methods it is easy to calculate the radiation from the surfaces to any point in the volume.
  • When one would like to use a raytracer within a cavity it is nice to have an object which contains all the faces already on which a reflection could occur. The raytracer for acoustics can be used for all kinds of room acoustical quantities.
For any raytracer in general working within the cavity I think it is good to have such an object which basically has a list of all faces it could possibly reflect on.

How I see it it should be placing an object on a certain position, and then it automagicallly determines the right shape.
I'll have a closer look at your idea of how to achieve such a volume.
Frederik
crashfridh
Posts: 143
Joined: Thu Jan 03, 2013 1:42 pm

Re: Define a volume by boundary planes

Post by crashfridh »

Just thought of a possibility for obtaining the volume of closed cavities. It works fine.

Put your entire geometry in a Union. Create a huge solid/space, covering your entire geometry (and then hide it). Then perform a cut. The solids the Cut has contain the volumes inside and outside your geometry. Next step is to determine which Shape belongs at which position. How I see it you put a marker in the cavity of interest, which will be our Cavity object. Then, you can detect whether this point is within any of the Cut solids. If so, then this Cavity object will link to the Solid of the Cut.

Not sure whether FreeCAD is already capable of detecting whether a point lies within a volume, but OpenCascade sure is:
Decide, whether a point lies inside or outside face/body
Open CASCADE provides services to classify a point with respect to a face or a body using the following classes
BRepClass3d_SolidClassifier
BRepClass_FaceClassifier
@yorik
Is this how you meant it with the big box?


Example function that works with the attached model.

Code: Select all


def getCavities(doc):
    """
    Return cavities in document.
    
    :param doc: :class:`FreeCAD.Document`
    """
    
    """
    First, create a union of the geometry.
    """
    objects = doc.Objects
    fusion = doc.addObject("Part::MultiFuse", "Fusion")    
    fusion.Shapes = objects
    
    """
    Second, create an infinite space.
    """
    space = doc.addObject("Part::Box", "Space")
    space.Length=space.Height=space.Width=1e10
    
    
    """
    Third, perform the cut.
    """
    cut = doc.addObject("Part::Cut","Cut")
    cut.Base = space
    cut.Tool = fusion
    doc.recompute()
    
    """
    Fourth, remove the outside space from the list.
    """    
    solids = cut.Shape.Solids
    solids.remove(max(solids))
    return solids
    
    
def main():
    
    doc = App.open("room2.FCStd")

    solids = getCavities(doc)
    for solid in solids:
        print solid.Volume


if __name__=='__main__':
   main()

Attachments
room2.FCStd
(7.77 KiB) Downloaded 84 times
Frederik
jrheinlaender
Posts: 554
Joined: Sat Apr 07, 2012 2:42 am

Re: Define a volume by boundary planes

Post by jrheinlaender »

Just thought of a possibility for obtaining the volume of closed cavities. It works fine.
Isn't it possible to take any face on the inside of the cavity, and then find all faces adjacent to this face, and again all faces adjacent to those faces etc. until you have a complete shell? Then create a solid from that shell.
crashfridh
Posts: 143
Joined: Thu Jan 03, 2013 1:42 pm

Re: Define a volume by boundary planes

Post by crashfridh »

jrheinlaender wrote:
Just thought of a possibility for obtaining the volume of closed cavities. It works fine.
Isn't it possible to take any face on the inside of the cavity, and then find all faces adjacent to this face, and again all faces adjacent to those faces etc. until you have a complete shell? Then create a solid from that shell.
That should be possible as well. But I think it would be relatively slow. Since how I see it you then would have to do a commons operation with all objects in your document every iteration, to see whether they are adjacent.
Frederik
User avatar
yorik
Founder
Posts: 13597
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Define a volume by boundary planes

Post by yorik »

Great thoughts!
The problem I see is that not always you will have all the faces, means not always you will get a tight shell or solid. For example imagine there is a kitchen and a dining room separated by a bar, not an entire wall. So I would like to be able to get the volume of the kitchen by taking only 3 walls. So the idea I had is a method that always returns a solid. But I must still test a bit. Still, crashfridh's method might serve for some specific cases... Maybe once I have the object we can give it several calculations algorithms...
Post Reply