def intersect_shape_by_line(topods_shape,
                            line,
                            low_parameter=0.0,
                            hi_parameter=float("+inf")):
    """
    finds the intersection of a shape and a line
    :param shape: any TopoDS_*
    :param line: gp_Lin
    :param low_parameter:
    :param hi_parameter:
    :return: a list with a number of tuples that corresponds to the number
    of intersections found
    the tuple contains ( gp_Pnt, TopoDS_Face, u,v,w ), respectively the
    intersection point, the intersecting face
    and the <u,v,w parameters of the intersection point
    :raise:
    """
    from OCC.Core.IntCurvesFace import IntCurvesFace_ShapeIntersector
    shape_inter = IntCurvesFace_ShapeIntersector()
    shape_inter.Load(topods_shape, TOLERANCE)
    #shape_inter.PerformNearest(line, low_parameter, hi_parameter)

    with assert_isdone(shape_inter,
                       "failed to computer shape / line intersection"):
        return (shape_inter.Pnt(1), shape_inter.Face(1),
                shape_inter.UParameter(1), shape_inter.VParameter(1),
                shape_inter.WParameter(1))
Beispiel #2
0
def burn_buildings(geometry, elevation_map):
    if geometry.has_z:
        # remove elevation - we'll add it back later by intersecting with the topography
        point_list_2D = ((a, b) for (a, b, _) in geometry.exterior.coords)
    else:
        point_list_2D = geometry.exterior.coords
    point_list_3D = [(a, b, 0) for (a, b) in point_list_2D]  # add 0 elevation

    # creating floor surface in pythonocc
    face = construct.make_polygon(point_list_3D)
    # get the midpt of the face
    face_midpt = calculate.face_midpt(face)

    terrain_tin = elevation_map.generate_tin()
    # make shell out of tin_occface_list and create OCC object
    terrain_shell = construct.make_shell(terrain_tin)
    terrain_intersection_curves = IntCurvesFace_ShapeIntersector()
    terrain_intersection_curves.Load(terrain_shell, 1e-6)

    # project the face_midpt to the terrain and get the elevation
    inter_pt, inter_face = calc_intersection(terrain_intersection_curves,
                                             face_midpt, (0, 0, 1))

    # reconstruct the footprint with the elevation
    loc_pt = (inter_pt.X(), inter_pt.Y(), inter_pt.Z())
    face = fetch.topo2topotype(modify.move(face_midpt, loc_pt, face))
    return face
 def get_shape_line_intersections(cls, shape, line):
     """
     Seems to return the intersection for the first face the line runs into
     """
     shape_inter = IntCurvesFace_ShapeIntersector()
     shape_inter.Load(shape, 1e-3)
     shape_inter.PerformNearest(line, float("-inf"), float("+inf"))
     with assert_isdone(shape_inter,
                        "failed to computer shape / line intersection"):
         intersections = [(shape_inter.Pnt(i), shape_inter.Face(i), line)
                          for i in range(1,
                                         shape_inter.NbPnt() + 1)
                          ]  # Indices start at 1 :(
         return intersections
Beispiel #4
0
def intersect_shape_with_ptdir(occtopology, pypt, pydir):
    """
    This function projects a point in a direction and calculates the at which point does the point intersects the OCCtopology.
 
    Parameters
    ----------
    occtopology : OCCtopology
        The OCCtopology to be projected on.
        OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex 
        
    pypt : tuple of floats
        The point to be projected. A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z)
        
    pydir : tuple of floats
        The direction of the point to be projected. A pydir is a tuple that documents the xyz vector of a dir e.g. (x,y,z)
        
    Returns
    -------
    intersection point : pypt
        The point in which the projected point intersect the OCCtopology. If None means there is no intersection.
    
    intersection face : OCCface
        The OCCface in which the projected point hits. If None means there is no intersection.
    """
    occ_line = gp_Lin(
        gp_Ax1(gp_Pnt(pypt[0], pypt[1], pypt[2]),
               gp_Dir(pydir[0], pydir[1], pydir[2])))
    shape_inter = IntCurvesFace_ShapeIntersector()
    shape_inter.Load(occtopology, 1e-6)
    shape_inter.PerformNearest(occ_line, 0.0, float("+inf"))
    if shape_inter.IsDone():
        npts = shape_inter.NbPnt()
        if npts != 0:
            return modify.occpt_2_pypt(shape_inter.Pnt(1)), shape_inter.Face(1)
        else:
            return None, None
    else:
        return None, None
Beispiel #5
0
    def intersect_point(self, x, y):
        self.Select(x, y)

        viewLine = self.viewline(x, y)

        for i in range(len(self.selected_shapes)):
            hShape = AIS_Shape.DownCast(self.selected_ishapes[i])
            shape = hShape.Shape()

            loc = self.Context.Location(hShape)
            loc_shape = shape.Located(loc)

            shapeIntersector = IntCurvesFace_ShapeIntersector()
            shapeIntersector.Load(loc_shape, precision_Confusion())
            shapeIntersector.Perform(viewLine, float("-inf"), float("+inf"))

            if shapeIntersector.NbPnt() >= 1:
                ip = shapeIntersector.Pnt(1)
                return point3(ip), True
            else:
                continue

        return point3(), False
 def terrain_intersection_curves(self, geometry_terrain):
     # make shell out of tin_occface_list and create OCC object
     terrain_shell = construct.make_shell(geometry_terrain)
     terrain_intersection_curves = IntCurvesFace_ShapeIntersector()
     terrain_intersection_curves.Load(terrain_shell, 1e-6)
     return terrain_intersection_curves