コード例 #1
0
ファイル: calculate.py プロジェクト: CES-MDE/py4design
def project_shape_on_shape(occtopo_proj, occtopo_projon, tolerance=1e-06):
    """
    This function project the occtopoproj (OCCtopology) onto the occtopoprojon (OCCtopology), and returns the list of projected points.
 
    Parameters
    ----------
    occtopo_proj : OCCtopology
        The OCCtopology to to project.
        OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex 
        
    occtopo_projon : OCCtopology
        The OCCtopology to be projected on.
        OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex 
        
    tolerance : float, optional
        The precision of the projection, Default = 1e-06.
        
    Returns
    -------
    list of projected points : pyptlist
        The list of projected points.
    """

    interpyptlist = []
    dss = BRepExtrema_DistShapeShape(occtopo_proj, occtopo_projon)
    dss.SetDeflection(tolerance)
    dss.Perform()
    min_dist = dss.Value()
    npts = dss.NbSolution()
    for i in range(npts):
        gppt = dss.PointOnShape2(i + 1)
        pypt = (gppt.X(), gppt.Y(), gppt.Z())
        interpyptlist.append(pypt)

    return interpyptlist
コード例 #2
0
ファイル: calculate.py プロジェクト: CES-MDE/py4design
def intersect_edge_with_edge(occedge1, occedge2, tolerance=1e-06):
    """
    This function intersects two OCCedges and obtain a list of intersection points.
 
    Parameters
    ----------
    occedge1 : OCCedge
        The first edge to be intersected.
        
    occedge2 : OCCedge
        The second edge to be intersected.
        
    tolerance : float, optional
        The minimum distance between the two edges to determine if the edges are intersecting, Default = 1e-06.

    Returns
    -------
    list of intersection points : pyptlist
        The list of points where the two edges intersect.
    """
    interpyptlist = []
    dss = BRepExtrema_DistShapeShape(occedge1, occedge2)
    dss.SetDeflection(tolerance)
    dss.Perform()
    min_dist = dss.Value()
    if min_dist < tolerance:
        npts = dss.NbSolution()
        for i in range(npts):
            gppt = dss.PointOnShape1(i + 1)
            pypt = (gppt.X(), gppt.Y(), gppt.Z())
            interpyptlist.append(pypt)

    return interpyptlist
コード例 #3
0
    def __init__(self, shape_1, shape_2):
        dist_shape_shape = BRepExtrema_DistShapeShape(shape_1, shape_2)
        dist_shape_shape.Perform()

        with AssertIsDone(dist_shape_shape,
                          'Failed computing minimum distances'):
            self._min_dist = dist_shape_shape.Value()
            self._points_pairs = list()
            self._nb_solutions = dist_shape_shape.NbSolution()
            for i in range(1, dist_shape_shape.NbSolution() + 1):
                self._points_pairs.append((dist_shape_shape.PointOnShape1(i),
                                           dist_shape_shape.PointOnShape2(i)))
コード例 #4
0
ファイル: calculate.py プロジェクト: Linwal/pyliburo
def intersect_edge_with_edge(occedge1, occedge2, tolerance=1e-06):
    interpyptlist = []
    dss = BRepExtrema_DistShapeShape(occedge1, occedge2)
    dss.SetDeflection(tolerance)
    dss.Perform()
    min_dist = dss.Value()
    if min_dist < tolerance:
        npts = dss.NbSolution()
        for i in range(npts):
            gppt = dss.PointOnShape1(i + 1)
            pypt = (gppt.X(), gppt.Y(), gppt.Z())
            interpyptlist.append(pypt)

    return interpyptlist
コード例 #5
0
def nearest_vertex(edge1, edge2):

    # v11 = topexp.FirstVertex(edge1)
    # v12 = topexp.LastVertex(edge1)

    lut = types_lut.brep_extrema_lut
    bdss = BRepExtrema_DistShapeShape(edge1, edge2)
    bdss.Perform()
    with assert_isdone(bdss, 'failed computing minimum distances'):
        for i in range(1, bdss.NbSolution() + 1):
            if ['vertex', 'vertex'] == [
                    lut[bdss.SupportTypeShape1(i)],
                    lut[bdss.SupportTypeShape2(i)]
            ]:

                return topods.Vertex(bdss.SupportOnShape1(i)), \
                       topods.Vertex(bdss.SupportOnShape2(i))
コード例 #6
0
ファイル: pythonoce-test.py プロジェクト: jayjaybillings/fire
def sampleSolid(n, solid, vertexList=None):
    # Create a bounding box for the shape
    boundingBox = Bnd_Box()
    brepbndlib_Add(solid, boundingBox)
    xMin, yMin, zMin, xMax, yMax, zMax = boundingBox.Get()
    xSideLength = xMax - xMin
    ySideLength = yMax - yMin
    zSideLength = zMax - zMin

    # Create extrema sampler to measure if the point is in the shape. For now,
    # just initialize it with the same shape. We'll load the vertex later.
    brepDistShapeShape = BRepExtrema_DistShapeShape(solid, solid)

    # Create a random number of vertices and check to see which ones are
    # in the shape.
    vertices = createPointsDataFrame(n)
    vertices.inShape = vertices.inShape.astype('int')
    # Loop over the vertices
    for i in range(0, n):
        # Pick a random point
        x = xMin + random() * xSideLength
        y = yMin + random() * ySideLength
        z = zMin + random() * zSideLength
        # Create a vertex from a geometric point
        gpPoint = gp_Pnt(x, y, z)
        vertexBuilder = BRepBuilderAPI_MakeVertex(gpPoint)
        vertex = vertexBuilder.Vertex()
        # Load the vertex into the extrema calculator
        brepDistShapeShape.LoadS2(vertex)
        brepDistShapeShape.Perform()
        # Compute the containment with the box and store the value
        inShape = 1 if brepDistShapeShape.InnerSolution() else 0
        # Store the shape value
        vertices.set_value(i, 'x', x)
        vertices.set_value(i, 'y', y)
        vertices.set_value(i, 'z', z)
        vertices.set_value(i, 'inShape', inShape)
        if inShape != 0:
            vertexList.append(vertex)

    # Slice the data frame so that only the x,y,z variables for points in the box are saved.
    innerVertices = vertices[vertices.inShape == 1]
    innerCoords = innerVertices[['x', 'y', 'z']]

    return innerCoords
コード例 #7
0
def compute_minimal_distance_between_cubes():
    """ compute the minimal distance between 2 cubes

    the line between the 2 points is rendered in cyan

    """
    b1 = BRepPrimAPI_MakeBox(gp_Pnt(100, 0, 0), 10., 10., 10.).Shape()
    b2 = BRepPrimAPI_MakeBox(gp_Pnt(45, 45, 45), 10., 10., 10.).Shape()
    display.DisplayShape([b1, b2])

    dss = BRepExtrema_DistShapeShape()
    dss.LoadS1(b1)
    dss.LoadS2(b2)
    dss.Perform()

    assert dss.IsDone()

    edg = make_edge(dss.PointOnShape1(1), dss.PointOnShape2(1))
    display.DisplayColoredShape([edg], color="CYAN")
コード例 #8
0
def minimum_distance(shp1, shp2):
    """
    compute minimum distance between 2 BREP's
    @param shp1:    any TopoDS_*
    @param shp2:    any TopoDS_*

    @return: minimum distance,
             minimum distance points on shp1
             minimum distance points on shp2
    """
    bdss = BRepExtrema_DistShapeShape(shp1, shp2)
    bdss.Perform()
    with assert_isdone(bdss, 'failed computing minimum distances'):
        min_dist = bdss.Value()
        min_dist_shp1, min_dist_shp2 = [], []
        for i in range(1, bdss.NbSolution() + 1):
            min_dist_shp1.append(bdss.PointOnShape1(i))
            min_dist_shp2.append(bdss.PointOnShape2(i))
    return min_dist, min_dist_shp1, min_dist_shp2
コード例 #9
0
ファイル: calculate.py プロジェクト: Linwal/pyliburo
def project_shape_on_shape(occshape1, occshape2, tolerance=1e-06):
    '''
    occshape1: shape to project
    type: occshape
    
    occshape2: shape to be projected on
    type: occshape
    
    tolerance: precision of the projection
    type: float
    '''
    interpyptlist = []
    dss = BRepExtrema_DistShapeShape(occshape1, occshape2)
    dss.SetDeflection(tolerance)
    dss.Perform()
    min_dist = dss.Value()
    npts = dss.NbSolution()
    for i in range(npts):
        gppt = dss.PointOnShape2(i + 1)
        pypt = (gppt.X(), gppt.Y(), gppt.Z())
        interpyptlist.append(pypt)

    return interpyptlist
コード例 #10
0
ファイル: blade.py プロジェクト: ztotal/BladeX
    def _write_blade_errors(self, upper_face, lower_face, errors):
        """
        Private method to write the errors between the generated foil points in
        3D space from the parametric transformations, and their projections on
        the generated blade faces from the OCC algorithm.

        :param string upper_face: if string is passed then the method generates
            the blade upper surface using the BRepOffsetAPI_ThruSections
            algorithm, then exports the generated CAD into .iges file holding
            the name <upper_face_string>.iges
        :param string lower_face: if string is passed then the method generates
            the blade lower surface using the BRepOffsetAPI_ThruSections
            algorithm, then exports the generated CAD into .iges file holding
            the name <lower_face_string>.iges
        :param string errors: if string is passed then the method writes out
            the distances between each discrete point used to construct the
            blade and the nearest point on the CAD that is perpendicular to
            that point
        """
        from OCC.gp import gp_Pnt
        from OCC.BRepBuilderAPI import BRepBuilderAPI_MakeVertex
        from OCC.BRepExtrema import BRepExtrema_DistShapeShape

        output_string = '\n'
        with open(errors + '.txt', 'w') as f:
            if upper_face:
                output_string += '########## UPPER FACE ##########\n\n'
                output_string += 'N_section\t\tN_point\t\t\tX_crds\t\t\t\t'
                output_string += 'Y_crds\t\t\t\t\tZ_crds\t\t\t\t\tDISTANCE'
                output_string += '\n\n'
                for i in range(self.n_sections):
                    alength = len(self.blade_coordinates_up[i][0])
                    for j in range(alength):
                        vertex = BRepBuilderAPI_MakeVertex(
                            gp_Pnt(
                                1000 * self.blade_coordinates_up[i][0][j],
                                1000 * self.blade_coordinates_up[i][1][j],
                                1000 *
                                self.blade_coordinates_up[i][2][j])).Vertex()
                        projection = BRepExtrema_DistShapeShape(
                            self.generated_upper_face, vertex)
                        projection.Perform()
                        output_string += str(i) + '\t\t\t' + str(
                            j) + '\t\t\t' + str(
                                1000 *
                                self.blade_coordinates_up[i][0][j]) + '\t\t\t'
                        output_string += str(
                            1000 * self.blade_coordinates_up[i][1][j]
                        ) + '\t\t\t' + str(
                            1000 * self.blade_coordinates_up[i][2][j]
                        ) + '\t\t\t' + str(projection.Value())
                        output_string += '\n'

            if lower_face:
                output_string += '########## LOWER FACE ##########\n\n'
                output_string += 'N_section\t\tN_point\t\t\tX_crds\t\t\t\t'
                output_string += 'Y_crds\t\t\t\t\tZ_crds\t\t\t\t\tDISTANCE'
                output_string += '\n\n'
                for i in range(self.n_sections):
                    alength = len(self.blade_coordinates_down[i][0])
                    for j in range(alength):
                        vertex = BRepBuilderAPI_MakeVertex(
                            gp_Pnt(1000 * self.blade_coordinates_down[i][0][j],
                                   1000 * self.blade_coordinates_down[i][1][j],
                                   1000 * self.blade_coordinates_down[i][2][j])
                        ).Vertex()
                        projection = BRepExtrema_DistShapeShape(
                            self.generated_lower_face, vertex)
                        projection.Perform()
                        output_string += str(i) + '\t\t\t' + str(
                            j) + '\t\t\t' + str(
                                1000 * self.blade_coordinates_down[i][0][j]
                            ) + '\t\t\t'
                        output_string += str(
                            1000 * self.blade_coordinates_down[i][1][j]
                        ) + '\t\t\t' + str(
                            1000 * self.blade_coordinates_down[i][2][j]
                        ) + '\t\t\t' + str(projection.Value())
                        output_string += '\n'
            f.write(output_string)
コード例 #11
0
def collision(shp1, shp2):
    bdss = BRepExtrema_DistShapeShape(shp1, shp2)
    bdss.Perform()
    with assert_isdone(bdss, 'failed computing minimum distances'):
        min_dist = bdss.Value()
    return min_dist