Ejemplo n.º 1
0
    def project_vertex(self, pnt_or_vertex):
        ''' returns the closest orthogonal project on `pnt` on edge
        '''
        if isinstance(pnt_or_vertex, TopoDS_Vertex):
            pnt_or_vertex = vertex2pnt(pnt_or_vertex)

        poc = GeomAPI_ProjectPointOnCurve(pnt_or_vertex, self.curve_handle)
        return poc.LowerDistanceParameter(), poc.NearestPoint()
Ejemplo n.º 2
0
def project_point_on_curve(crv, pnt):
    if isinstance(crv, TopoDS_Shape):
        # get the curve handle...
        crv = adapt_edge_to_curve(crv).Curve().Curve()
    else:
        raise NotImplementedError('expected a TopoDS_Edge...')
    rrr = GeomAPI_ProjectPointOnCurve(pnt, crv)
    return rrr.LowerDistanceParameter(), rrr.NearestPoint()
Ejemplo n.º 3
0
def project_point_on_curve(crv: TopoDS_Edge,
                           pnt: gp_Pnt) -> Tuple[float, gp_Pnt]:
    """

    :param crv: TopoDS_Edge
    :param pnt:
    :return:
    """
    if isinstance(crv, TopoDS_Shape):
        # get the curve handle...
        adaptor = BRepAdaptor_Curve(crv)
        crv = adaptor.Curve().Curve()
        rrr = GeomAPI_ProjectPointOnCurve(pnt, crv)
        return rrr.LowerDistanceParameter(), rrr.NearestPoint()
    else:
        raise NotImplementedError('expected a TopoDS_Edge...')
Ejemplo n.º 4
0
def project_point_on_curve():
    '''
    '''
    point_to_project = gp_Pnt(1., 2., 3.)
    radius = 5.

    # create a circle, centered at origin with a given radius
    circle = Geom_Circle(gp_XOY(), radius)
    display.DisplayShape(circle)
    display.DisplayShape(point_to_project, update=True)
    display.DisplayMessage(point_to_project, "P")

    # project the point P on the circle
    projection = GeomAPI_ProjectPointOnCurve(point_to_project,
                                             circle.GetHandle())
    # get the results of the projection
    # the point
    projected_point = projection.NearestPoint()
    # the number of possible results
    nb_results = projection.NbPoints()
    print("NbResults : %i" % nb_results)

    pstring = "N : at Distance : %f" % projection.LowerDistance()
    display.DisplayMessage(projected_point, pstring)

    # thre maybe many different possible solutions
    if nb_results > 0:
        for i in range(1, nb_results+1):
            Q = projection.Point(i)
            distance = projection.Distance(i)
            pstring = "Q%i: at Distance :%f" % (i, distance)
            display.DisplayShape(Q)
            display.DisplayMessage(Q, pstring)
Ejemplo n.º 5
0
def project_point_on_curve(crv, pnt):
    from OCC.GeomAPI import GeomAPI_ProjectPointOnCurve
    rrr = GeomAPI_ProjectPointOnCurve(pnt, crv)
    return rrr.LowerDistanceParameter(), rrr.NearestPoint()
Ejemplo n.º 6
0
    def mousePressEvent(self, event):

        self.lastPos = event.pos()

        super(GLWidget, self).mousePressEvent(event)
        """
        worldCoords = super(GLWidget, self).mapToGlobal( self.lastPos )
        print self.lastPos
        """

        print self.currentSpline
        corCurve = None  #curve corresponding to the selected spline

        if self.currentSpline is not None and self.currentSpline is not False:
            corCurve = self.lookupSpline(self.currentSpline)
            #self.currentSpline = self.shapesToCurves[self.currentSpline] #take the shape and get the real curve from it

        if event.buttons() & QtCore.Qt.LeftButton:
            #self.currentSpline = self._display.GetSelectedShape()
            #print self.currentSpline
            pass

        elif event.buttons() & QtCore.Qt.RightButton and not (
                event.modifiers() & QtCore.Qt.ShiftModifier):
            print 'first'

            (x, y, z, vx, vy,
             vz) = self._display.View.ConvertWithProj(self.lastPos.x(),
                                                      self.lastPos.y())

            if not self.shapesToCurves:
                #z' = vz*t + z, solve for where z' = 0
                t = -z / vz
                x = x + vx * t
                y = y + vy * t
                z = 0

            point = gp_Pnt(x, y, z)

            if corCurve is not None and corCurve is not False:  #something is selected
                print 'not none'
                #get project onto it
                projection = GeomAPI_ProjectPointOnCurve(point, corCurve)
                point = projection.NearestPoint()

                self.workingPoint = point  #TODO: should I just make this none-able?
                self.appendToDict(self.currentConnections, corCurve,
                                  point)  #Add a connection

            elif self.workingPoint is not None:
                view_dir = self._display.View.ViewOrientation(
                ).ViewReferencePlane().Coord()  #Note that this is backwards!
                d = -view_dir[0] * (self.workingPoint.X() - x) - view_dir[
                    1] * (self.workingPoint.Y() -
                          y) - view_dir[2] * (self.workingPoint.Z() - z)
                d /= (-view_dir[0] * vx) + (-view_dir[1] *
                                            vy) + (-view_dir[2] * vz)
                x = x + vx * d
                y = y + vy * d
                z = z + vz * d
                #TODO: WIP
                point = gp_Pnt(x, y, z)

            self._display.DisplayShape(point, update=False)

            self.pts.append(point)

        elif event.buttons() & QtCore.Qt.RightButton and (
                event.modifiers() & QtCore.Qt.ShiftModifier):
            print 'second'
            print self.pts
            curve = self.points_to_bspline(self.pts)

            #Add the curve to the network:
            self.buildGraph.add_node(curve)
            for s in self.currentConnections:
                self.buildGraph.add_edge(
                    s, curve, points=self.currentConnections[s]
                )  #from that spline to this current curve

            self._display.DisplayShape(curve, update=False)

            self._display.View.SetZoom(1.0)  #force a repaint

            self.pts = []  #clear it
            #self._display.View.SetZSize(1.0)

            self._display.SelectArea(
                0, 0, 2000, 2000)  #select everything and iterate through it

            shapes = self._display.GetSelectedShapes()

            for shape in shapes:
                known = False
                for knownShape in self.shapesToCurves:
                    if shape.IsEqual(knownShape):
                        known = True
                        break
                if known:
                    continue
                #Did not see it
                self.shapesToCurves[shape] = curve

            print self.shapesToCurves

            self.workingPoint = None  #reset this value
            self.currentConnections = {}  #reset this value