def test_point_from_projections(self):
     """Test: point from projections"""
     P = gp_Pnt(7.0, 8.0, 9.0)
     radius = 5
     SP = Geom_SphericalSurface(gp_Ax3(gp_XOY()), radius)
     PPS = GeomAPI_ProjectPointOnSurf(P, SP)
     N = PPS.NearestPoint()
     self.assertTrue(isinstance(N, gp_Pnt))
     NbResults = PPS.NbPoints()
     if NbResults > 0:
         for i in range(1, NbResults + 1):
             Q = PPS.Point(i)
             self.assertTrue(isinstance(Q, gp_Pnt))
             distance = PPS.Distance(i)
             # in any case, it should be > 1
             self.assertGreater(distance, 1.0)
     lower_d = PPS.LowerDistance()
     self.assertGreater(lower_d, 1.0)
     if NbResults > 0:
         for i in range(1, NbResults + 1):
             Q = PPS.Point(i)
             distance = PPS.Distance(i)
             pstring = "Q" + repr(i) + ": at Distance :" + repr(
                 PPS.Distance(i))
             print(pstring)
Ejemplo n.º 2
0
def get_deg(axs, vec):
    vx = dir_to_vec(axs.XDirection())
    vy = dir_to_vec(axs.YDirection())
    vz = dir_to_vec(axs.Direction())
    pln_x = Geom_Plane(axs.Location(), axs.YDirection())
    pln_y = Geom_Plane(axs.Location(), axs.XDirection())
    vec_p = gp_Pnt((gp_Vec(axs.Location().XYZ()) + vec).XYZ())
    pnt_x = GeomAPI_ProjectPointOnSurf(vec_p, pln_x).Point(1)
    pnt_y = GeomAPI_ProjectPointOnSurf(vec_p, pln_y).Point(1)
    vec_x = gp_Vec(axs.Location(), pnt_x)
    vec_y = gp_Vec(axs.Location(), pnt_y)
    deg_x = vec_x.AngleWithRef(vz, vy)
    deg_y = vec_y.AngleWithRef(vz, vx)
    print(np.rad2deg(deg_x), np.rad2deg(deg_y))
    return deg_x, deg_y
Ejemplo n.º 3
0
    def project_vertex(self, pnt, tol=TOLERANCE):
        '''projects self with a point, curve, edge, face, solid
        method wraps dealing with the various topologies

        if other is a point:
            returns uv, point

        '''
        if isinstance(pnt, TopoDS_Vertex):
            pnt = BRep_Tool.Pnt(pnt)

        proj = GeomAPI_ProjectPointOnSurf(pnt, self.surface_handle, tol)
        uv = proj.LowerDistanceParameters()
        proj_pnt = proj.NearestPoint()

        return uv, proj_pnt
Ejemplo n.º 4
0
 def sxy_tar(self):
     prf = self.dir + self.tar.name + "_" + "sz" + "_profile.txt"
     sx = float(getline(prf, 7).split()[1])
     sy = float(getline(prf, 8).split()[1])
     sxy = gp_Pnt(sx, sy, 0).Transformed(self.tar.trf)
     h_srf = BRep_Tool.Surface(self.tar.srf)
     self.tar.sxy = GeomAPI_ProjectPointOnSurf(sxy, h_srf).Point(1)
Ejemplo n.º 5
0
def setup_sxy(filename, ext="ex"):
    axs, srf, trf = set_axs_pln(filename)
    prf = filename + "_" + ext + "_profile.txt"
    sx = float(getline(prf, 7).split()[1])
    sy = float(getline(prf, 8).split()[1])
    sxy = gp_Pnt(sx, sy, 0).Transformed(trf)
    h_srf = BRep_Tool.Surface(srf)
    sxy = GeomAPI_ProjectPointOnSurf(sxy, h_srf).Point(1)
    return axs, srf, trf, sxy
 def test_point_from_projections(self):
     '''Test: point from projections'''
     P = gp_Pnt(7., 8., 9.)
     radius = 5
     SP = Geom_SphericalSurface(gp_Ax3(gp_XOY()), radius)
     PPS = GeomAPI_ProjectPointOnSurf(P, SP)
     N = PPS.NearestPoint()
     NbResults = PPS.NbPoints()
     if NbResults > 0:
         for i in range(1, NbResults + 1):
             Q = PPS.Point(i)
             distance = PPS.Distance(i)
     pstring = "N  : at Distance : " + repr(PPS.LowerDistance())
     if NbResults > 0:
         for i in range(1, NbResults + 1):
             Q = PPS.Point(i)
             distance = PPS.Distance(i)
             pstring = "Q" + repr(i) + ": at Distance :" + repr(
                 PPS.Distance(i))
Ejemplo n.º 7
0
    def closest_point(self, point, return_parameters=False):
        """Compute the closest point on the curve to a given point.

        Parameters
        ----------
        point : Point
            The point to project to the surface.
        return_parameters : bool, optional
            If True, return the surface UV parameters in addition to the closest point.

        Returns
        -------
        :class:`~compas.geometry.Point` | tuple[:class:`~compas.geometry.Point`, tuple[float, float]]
            If `return_parameters` is False, the nearest point on the surface.
            If `return_parameters` is True, the UV parameters in addition to the nearest point on the surface.

        """
        projector = GeomAPI_ProjectPointOnSurf(point.to_occ(),
                                               self.occ_surface)
        point = Point.from_occ(projector.NearestPoint())
        if not return_parameters:
            return point
        return point, projector.LowerDistanceParameters()
Ejemplo n.º 8
0
def project_mesh_to_cad_3d(mesh, cad):

    from OCC.Core.BRepAdaptor import BRepAdaptor_Surface, BRepAdaptor_Curve
    from OCC.Core.gp import gp_Pnt
    from OCC.Core.GeomAPI import GeomAPI_ProjectPointOnSurf, GeomAPI_ProjectPointOnCurve

    coorddata = mesh.coordinates.dat.data
    ids = mesh.exterior_facets.unique_markers

    filt = lambda arr: arr[numpy.where(arr < mesh.coordinates.dof_dset.size)[0]
                           ]
    boundary_nodes = {
        id: filt(mesh.coordinates.function_space().boundary_nodes(
            int(id), "topological"))
        for id in ids
    }

    for (id, face) in zip(ids, cad.faces()):
        owned_nodes = boundary_nodes[id]
        for other_id in ids:
            if id == other_id:
                continue
            owned_nodes = numpy.setdiff1d(owned_nodes,
                                          boundary_nodes[other_id])

        surf = BRepAdaptor_Surface(face)

        for node in owned_nodes:
            pt = gp_Pnt(*coorddata[node, :])

            proj = GeomAPI_ProjectPointOnSurf(pt, surf.Surface().Surface())
            if proj.NbPoints() > 0:
                projpt = proj.NearestPoint()
                coorddata[node, :] = projpt.Coord()
            else:
                warnings.warn("Projection of point %s onto face %d failed" %
                              (coorddata[node, :], id))

        edges = set(cad.edges_from_face(face))

        for (other_id, other_face) in zip(ids, cad.faces()):
            if other_id <= id:
                continue

            intersecting_nodes = numpy.intersect1d(boundary_nodes[id],
                                                   boundary_nodes[other_id])
            if len(intersecting_nodes) == 0:
                continue

            other_edges = set(cad.edges_from_face(other_face))

            intersecting_edges = []
            for edge in edges:
                s = str(
                    edge
                )  # FIXME: is there a more elegant way to get the OCC id?
                for other_edge in other_edges:
                    other_s = str(other_edge)
                    if s == other_s:
                        intersecting_edges.append(edge)

            if len(intersecting_edges) == 0:
                warnings.warn(
                    "face: %s other_face: %s intersecting_edges: %s" %
                    (face, other_face, intersecting_edges))
                warnings.warn(
                    "Warning: no intersecting edges in CAD, even though vertices on both faces?"
                )
                continue

            for node in intersecting_nodes:
                pt = gp_Pnt(*coorddata[node, :])

                projections = []
                for edge in intersecting_edges:
                    curve = BRepAdaptor_Curve(edge)

                    proj = GeomAPI_ProjectPointOnCurve(pt,
                                                       curve.Curve().Curve())
                    if proj.NbPoints() > 0:
                        projpt = proj.NearestPoint()
                        sqdist = projpt.SquareDistance(pt)
                        projections.append((projpt, sqdist))
                    else:
                        warnings.warn(
                            "Projection of point %s onto curve failed" %
                            coorddata[node, :])

                (projpt, sqdist) = min(projections, key=lambda x: x[1])
                coorddata[node, :] = projpt.Coord()
Ejemplo n.º 9
0
    ax0 = gp_Ax3(gp_Pnt(100, 100, 20),
                 gp_Dir(0.1, 0.2, 1.0),
                 gp_Dir(0.0, 0.5, 1.0))
    px = np.linspace(-1, 1, 500) * 100 + 50
    py = np.linspace(-1, 1, 700) * 100 - 50
    mesh = np.meshgrid(px, py)
    data = mesh[0]**2 / 1000 + mesh[1]**2 / 2000
    face = spl_face(*mesh, data, ax0)
    surf = BRep_Tool.Surface(face)
    surf.Rotate(gp_Ax1(ax0.Location(), ax0.Direction()), np.deg2rad(15))

    ax1 = gp_Ax3(gp_Pnt(150, 150, -20),
                 gp_Dir(0.5, 0.1, 1.0),
                 gp_Dir(0.0, 0.1, 1.0))
    pnt = ax1.Location()
    api = GeomAPI_ProjectPointOnSurf(pnt, surf)
    print(api.NbPoints(), api.NearestPoint())
    for i in range(api.NbPoints()):
        idx = i + 1
        u, v = api.Parameters(idx)
        obj.display.DisplayShape(api.Point(idx))
        print(idx, u, v)

    print(GeomAPI_IntCS(Geom_Line(ax1.Axis()), surf).NbPoints())
    u, v, w = GeomAPI_IntCS(Geom_Line(ax1.Axis()), surf).Parameters(1)
    p, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
    api = GeomLProp_SLProps(surf, u, v, 1, 0.1E-03)
    pnt = api.Value()
    dst = pnt.Distance(ax1.Location())
    ax2 = obj.prop_axs(ax1, dst)
    rim_u = surf.UIso(u)