Example #1
0
 def on_compute_change(self, change):
     if change['type'] == 'change' and change['name'] == 'value':
         selection = change['new']
         output = ""
         if 'Inertia' in selection:
             cog, mass, mass_property = measure_shape_mass_center_of_gravity(
                 self._current_shape_selection)
             # display this point (type gp_Pnt)
             self.DisplayShape([cog])
             output += "<u><b>Center of Gravity</b></u>:<br><b>Xcog=</b>%.3f<br><b>Ycog=</b>%.3f<br><b>Zcog=</b>%.3f<br>" % (
                 cog.X(), cog.Y(), cog.Z())
             output += "<u><b>%s=</b></u>:<b>%.3f</b><br>" % (mass_property,
                                                              mass)
         elif 'Oriented' in selection:
             center, dim, oobb_shp = get_oriented_boundingbox(
                 self._current_shape_selection)
             self.DisplayShape(oobb_shp,
                               render_edges=True,
                               transparency=True,
                               opacity=0.2,
                               selectable=False)
             output += "<u><b>OOBB center</b></u>:<br><b>X=</b>%.3f<br><b>Y=</b>%.3f<br><b>Z=</b>%.3f<br>" % (
                 center.X(), center.Y(), center.Z())
             output += "<u><b>OOBB dimensions</b></u>:<br><b>dX=</b>%.3f<br><b>dY=</b>%.3f<br><b>dZ=</b>%.3f<br>" % (
                 dim[0], dim[1], dim[2])
             output += "<u><b>OOBB volume</b></u>:<br><b>V=</b>%.3f<br>" % (
                 dim[0] * dim[1] * dim[2])
         elif 'Aligned' in selection:
             center, dim, albb_shp = get_aligned_boundingbox(
                 self._current_shape_selection)
             self.DisplayShape(albb_shp,
                               render_edges=True,
                               transparency=True,
                               opacity=0.2,
                               selectable=False)
             output += "<u><b>ABB center</b></u>:<br><b>X=</b>%.3f<br><b>Y=</b>%.3f<br><b>Z=</b>%.3f<br>" % (
                 center.X(), center.Y(), center.Z())
             output += "<u><b>ABB dimensions</b></u>:<br><b>dX=</b>%.3f<br><b>dY=</b>%.3f<br><b>dZ=</b>%.3f<br>" % (
                 dim[0], dim[1], dim[2])
             output += "<u><b>ABB volume</b></u>:<br><b>V=</b>%.3f<br>" % (
                 dim[0] * dim[1] * dim[2])
         elif 'Recognize' in selection:
             # try featrue recognition
             kind, pnt, vec = recognize_face(self._current_shape_selection)
             output += "<u><b>Type</b></u>: %s<br>" % kind
             if kind == "Plane":
                 self.DisplayShape([pnt])
                 output += "<u><b>Properties</b></u>:<br>"
                 output += "<u><b>Point</b></u>:<br><b>X=</b>%.3f<br><b>Y=</b>%.3f<br><b>Z=</b>%.3f<br>" % (
                     pnt.X(), pnt.Y(), pnt.Z())
                 output += "<u><b>Normal</b></u>:<br><b>u=</b>%.3f<br><b>v=</b>%.3f<br><b>w=</b>%.3f<br>" % (
                     vec.X(), vec.Y(), vec.Z())
             elif kind == "Cylinder":
                 self.DisplayShape([pnt])
                 output += "<u><b>Properties</b></u>:<br>"
                 output += "<u><b>Axis point</b></u>:<br><b>X=</b>%.3f<br><b>Y=</b>%.3f<br><b>Z=</b>%.3f<br>" % (
                     pnt.X(), pnt.Y(), pnt.Z())
                 output += "<u><b>Axis direction</b></u>:<br><b>u=</b>%.3f<br><b>v=</b>%.3f<br><b>w=</b>%.3f<br>" % (
                     vec.X(), vec.Y(), vec.Z())
         self.html.value = output
Example #2
0
def GetOrientedBoundingBoxShapeCompound_old(shapes_compound):
    aBaryCenter, [aHalfX, aHalfY, aHalfZ], aBox = get_oriented_boundingbox(shapes_compound, 1)
    print("box center point, X Y Z size", aBaryCenter.X(), aBaryCenter.Y(), aBaryCenter.Z(), aHalfX, aHalfY, aHalfZ)
    corner_bot, corner_top = get_oriented_boundingbox_coor(shapes_compound, 1)

    center_pt = OCC.Core.gp.gp_Pnt(aBaryCenter)
    return aBox, center_pt, [aHalfX, aHalfY,
                             aHalfZ], corner_bot, corner_top  # type(aBox)) #class 'OCC.Core.TopoDS.TopoDS_Solid', gp_Pnt, [float,float,float]
Example #3
0
def GetOrientedBoundingBox(ifc_elements):
    shapes = CreateShape(ifc_elements)
    shapes_compound, if_all_compound = list_of_shapes_to_compound(shapes)
    aBaryCenter, [aHalfX, aHalfY, aHalfZ], aBox = get_oriented_boundingbox(shapes_compound, 1)
    print("box center point, X Y Z size",aBaryCenter.X(), aBaryCenter.Y(), aBaryCenter.Z(), aHalfX, aHalfY, aHalfZ)
    corner_bot,corner_top = get_oriented_boundingbox_coor(shapes_compound,1)

    center_pt = OCC.Core.gp.gp_Pnt(aBaryCenter)
    return aBox, center_pt, [aHalfX, aHalfY, aHalfZ], corner_bot, corner_top #type(aBox)) #class 'OCC.Core.TopoDS.TopoDS_Solid', gp_Pnt, [float,float,float]
Example #4
0
def GetShapesOBB(shapes):

    ''' Get the oriented bounding box of the input shape'''

    shapes_compound, if_all_compound = list_of_shapes_to_compound(shapes)
    aBaryCenter, [aHalfX, aHalfY, aHalfZ], aBox = get_oriented_boundingbox(shapes_compound, 1)
    print("box center point, X Y Z size", aBaryCenter.X(), aBaryCenter.Y(), aBaryCenter.Z(), aHalfX, aHalfY, aHalfZ)
    corner_bot, corner_top = get_oriented_boundingbox_coor(shapes_compound, 1)
    center_pt = OCC.Core.gp.gp_Pnt(aBaryCenter)
    return aBox, center_pt, [aHalfX, aHalfY,aHalfZ], corner_bot, corner_top  # type(aBox)) #class 'OCC.Core.TopoDS.TopoDS_Solid', gp_Pnt, [float,float,float]
Example #5
0
    def add_insert(self, insert: "WallInsert", wall_segment: int, off_x, off_z):
        """

        :param insert:
        :param wall_segment:
        :param off_x:
        :param off_z:
        :return:
        """
        from OCC.Extend.ShapeFactory import get_oriented_boundingbox

        xvec, yvec, zvec = self.get_segment_props(wall_segment)
        p1, p2 = self._segments[wall_segment]

        start = p1 + yvec * (self._thickness / 2 + self.offset) + xvec * off_x + zvec * off_z
        insert._depth = self._thickness
        insert.placement = Placement(origin=start, xdir=xvec, ydir=zvec, zdir=yvec)

        frame = insert.shapes[0]
        center, dim, oobb_shp = get_oriented_boundingbox(frame.geom)
        x, y, z = center.X(), center.Y(), center.Z()
        dx, dy, dz = dim[0], dim[1], dim[2]

        x0 = x - abs(dx / 2)
        y0 = y - abs(dy / 2)
        z0 = z - abs(dz / 2)

        x1 = x + abs(dx / 2)
        y1 = y + abs(dy / 2)
        z1 = z + abs(dz / 2)

        self._inserts.append(insert)
        self._openings.append([wall_segment, insert, (x0, y0, z0), (x1, y1, z1)])

        tol = 0.4
        wi = insert

        p1 = wi.placement.origin - yvec * (wi.depth / 2 + tol)
        p2 = wi.placement.origin + yvec * (wi.depth / 2 + tol) + xvec * wi.width + zvec * wi.height

        self._penetrations.append(PrimBox("my_pen", p1, p2))