Skip to content

BooleanOperations

Functions to corefine triangulated surface meshes and compute triangulated surface meshes of the union, difference and intersection of the bounded volumes.

Target: CGALPlugin

namespace: cgal

parents:

  • DataEngine

Data

Name Description Default value
name object name unnamed
printLog if true, emits extra messages at runtime. 0
tags list of the subsets the object belongs to
bbox this object bounding box
componentState The state of the component among (Dirty, Valid, Undefined, Loading, Invalid). Undefined
listening if true, handle the events, otherwise ignore the events 0
operation Boolean operation union
Inputs
position1 Input positions of the first mesh
position2 Input positions of the second mesh
triangles1 Input triangles of the first mesh
triangles2 Input triangles of the second mesh
computeDistrubution If true, computes outputIndices1 and outputIndices2 1
Outputs
outputPosition Output positions of the surface mesh
outputTriangles Output triangles of the surface mesh
outputPosition1 Output positions of transformation on the first surface mesh
outputTriangles1 Output triangles of transformation on the first surface mesh
outputPosition2 Output positions of transformation on the second surface mesh
outputTriangles2 Output triangles of transformation on the second surface mesh
outputIndices1 Indices of the surface mesh points that are on the first object
outputIndices2 Indices of the surface mesh points that are on the second object
Name Description Destination type name
context Graph Node containing this object (or BaseContext::getDefault() if no graph is used) BaseContext
slaves Sub-objects used internally by this object BaseObject
master nullptr for regular objects, or master object for which this object is one sub-objects BaseObject

Examples

BooleanOperations.scn

<?xml version="1.0"?>
<Node name="root" gravity="0 0 0" dt="1"  >
    <RequiredPlugin pluginName="CGALPlugin"/>
  <RequiredPlugin pluginName='SofaOpenglVisual'/>

    <VisualStyle displayFlags="showWireframe showVisual" />

    <Node name="Mesh1">
        <MeshOBJLoader name="loader" filename="mesh/cube.obj" translation="50 50 50" scale="50"/>
        <OglModel src="@loader" color="1 0 0"/>
    </Node>

    <Node name="Mesh2">
        <MeshOBJLoader name="loader" filename="mesh/sphere_05.obj"/>
        <OglModel src="@loader" color="0 1 0"/>
    </Node>

    <Node name="Union">
        <BooleanOperations name="engine" position1="@../Mesh1/loader.position" triangles1="@../Mesh1/loader.triangles"
                                                                         position2="@../Mesh2/loader.position" triangles2="@../Mesh2/loader.triangles"
                                                                         operation="union"/>
        <MeshTopology position="@engine.outputPosition" triangles="@engine.outputTriangles"/>
        <OglModel color="0 0 1" translation="200 0 0"/>
    </Node>

    <Node name="Intersection">
        <BooleanOperations name="engine" position1="@../Mesh1/loader.position" triangles1="@../Mesh1/loader.triangles"
                                                                         position2="@../Mesh2/loader.position" triangles2="@../Mesh2/loader.triangles"
                                                                         operation="intersection"/>
        <MeshTopology position="@engine.outputPosition" triangles="@engine.outputTriangles"/>
        <OglModel color="0 0 1" translation="375 0 0"/>
    </Node>

    <Node name="Difference1">
        <BooleanOperations name="engine" position1="@../Mesh1/loader.position" triangles1="@../Mesh1/loader.triangles"
                                                                         position2="@../Mesh2/loader.position" triangles2="@../Mesh2/loader.triangles"
                                                                         operation="difference"/>
        <MeshTopology position="@engine.outputPosition" triangles="@engine.outputTriangles"/>
        <OglModel color="0 0 1" translation="500 0 0"/>
    </Node>

    <Node name="Difference2">
        <BooleanOperations name="engine" position1="@../Mesh2/loader.position" triangles1="@../Mesh2/loader.triangles"
                                                                         position2="@../Mesh1/loader.position" triangles2="@../Mesh1/loader.triangles"
                                                                         operation="difference"/>
        <MeshTopology position="@engine.outputPosition" triangles="@engine.outputTriangles"/>
        <OglModel color="0 0 1" translation="700 0 0"/>
    </Node>

</Node>
def createScene(root_node):

   root = root_node.addChild('root', gravity="0 0 0", dt="1")

   root.addObject('RequiredPlugin', pluginName="CGALPlugin")
   root.addObject('RequiredPlugin', pluginName="SofaOpenglVisual")
   root.addObject('VisualStyle', displayFlags="showWireframe showVisual")

   mesh1 = root.addChild('Mesh1')

   mesh1.addObject('MeshOBJLoader', name="loader", filename="mesh/cube.obj", translation="50 50 50", scale="50")
   mesh1.addObject('OglModel', src="@loader", color="1 0 0")

   mesh2 = root.addChild('Mesh2')

   mesh2.addObject('MeshOBJLoader', name="loader", filename="mesh/sphere_05.obj")
   mesh2.addObject('OglModel', src="@loader", color="0 1 0")

   union = root.addChild('Union')

   union.addObject('BooleanOperations', name="engine", position1="@../Mesh1/loader.position", triangles1="@../Mesh1/loader.triangles", position2="@../Mesh2/loader.position", triangles2="@../Mesh2/loader.triangles", operation="union")
   union.addObject('MeshTopology', position="@engine.outputPosition", triangles="@engine.outputTriangles")
   union.addObject('OglModel', color="0 0 1", translation="200 0 0")

   intersection = root.addChild('Intersection')

   intersection.addObject('BooleanOperations', name="engine", position1="@../Mesh1/loader.position", triangles1="@../Mesh1/loader.triangles", position2="@../Mesh2/loader.position", triangles2="@../Mesh2/loader.triangles", operation="intersection")
   intersection.addObject('MeshTopology', position="@engine.outputPosition", triangles="@engine.outputTriangles")
   intersection.addObject('OglModel', color="0 0 1", translation="375 0 0")

   difference1 = root.addChild('Difference1')

   difference1.addObject('BooleanOperations', name="engine", position1="@../Mesh1/loader.position", triangles1="@../Mesh1/loader.triangles", position2="@../Mesh2/loader.position", triangles2="@../Mesh2/loader.triangles", operation="difference")
   difference1.addObject('MeshTopology', position="@engine.outputPosition", triangles="@engine.outputTriangles")
   difference1.addObject('OglModel', color="0 0 1", translation="500 0 0")

   difference2 = root.addChild('Difference2')

   difference2.addObject('BooleanOperations', name="engine", position1="@../Mesh2/loader.position", triangles1="@../Mesh2/loader.triangles", position2="@../Mesh1/loader.position", triangles2="@../Mesh1/loader.triangles", operation="difference")
   difference2.addObject('MeshTopology', position="@engine.outputPosition", triangles="@engine.outputTriangles")
   difference2.addObject('OglModel', color="0 0 1", translation="700 0 0")