当前位置: 首页>>代码示例>>Python>>正文


Python spatial.Delaunay方法代码示例

本文整理汇总了Python中scipy.spatial.Delaunay方法的典型用法代码示例。如果您正苦于以下问题:Python spatial.Delaunay方法的具体用法?Python spatial.Delaunay怎么用?Python spatial.Delaunay使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.spatial的用法示例。


在下文中一共展示了spatial.Delaunay方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_cls_boundary

# 需要导入模块: from scipy import spatial [as 别名]
# 或者: from scipy.spatial import Delaunay [as 别名]
def generate_cls_boundary(cls_input,cntr_id_field,boundary_output,cpu_core):
    arcpy.env.parallelProcessingFactor=cpu_core
    arcpy.SetProgressorLabel('Generating Delaunay Triangle...')
    arrays=arcpy.da.FeatureClassToNumPyArray(cls_input,['SHAPE@XY',cntr_id_field])
   
    cid_field_type=[f.type for f in arcpy.Describe(cls_input).fields if f.name==cntr_id_field][0]
    delaunay=Delaunay(arrays['SHAPE@XY']).simplices.copy()
    arcpy.CreateFeatureclass_management('in_memory','boundary_temp','POLYGON',spatial_reference=arcpy.Describe(cls_input).spatialReference)
    fc=r'in_memory\boundary_temp'
    arcpy.AddField_management(fc,cntr_id_field,cid_field_type)
    cursor = arcpy.da.InsertCursor(fc, [cntr_id_field,"SHAPE@"])
    arcpy.SetProgressor("step", "Copying Delaunay Triangle to Temp Layer...",0, delaunay.shape[0], 1)
    for tri in delaunay:
        arcpy.SetProgressorPosition()
        cid=arrays[cntr_id_field][tri[0]]
        if cid == arrays[cntr_id_field][tri[1]] and cid == arrays[cntr_id_field][tri[2]]:
            cursor.insertRow([cid,arcpy.Polygon(arcpy.Array([arcpy.Point(*arrays['SHAPE@XY'][i]) for i in tri]))])
    arcpy.SetProgressor('default','Merging Delaunay Triangle...')
    if '64 bit' in sys.version:
        arcpy.PairwiseDissolve_analysis(fc,boundary_output,cntr_id_field)
    else:
        arcpy.Dissolve_management(fc,boundary_output,cntr_id_field)
    arcpy.Delete_management(fc)
    
    return 
开发者ID:lopp2005,项目名称:HiSpatialCluster,代码行数:27,代码来源:section_cpu.py

示例2: generate_mask

# 需要导入模块: from scipy import spatial [as 别名]
# 或者: from scipy.spatial import Delaunay [as 别名]
def generate_mask(vertices, num_samples=128):
    """Create a filled convex polygon mask based on the given vertices.

    Parameters
    ----------
    vertices : `iterable`
        ensemble of vertice (x,y) coordinates, in array units
    num_samples : `int`
        number of points in the output array along each dimension

    Returns
    -------
    `numpy.ndarray`
        polygon mask

    """
    vertices = e.asarray(vertices)
    unit = e.arange(num_samples)
    xxyy = e.stack(e.meshgrid(unit, unit), axis=2)

    # use delaunay to fill from the vertices and produce a mask
    triangles = Delaunay(vertices, qhull_options='QJ Qf')
    mask = ~(triangles.find_simplex(xxyy) < 0)
    return mask 
开发者ID:brandondube,项目名称:prysm,代码行数:26,代码来源:geometry.py

示例3: _append_tmp_sources

# 需要导入模块: from scipy import spatial [as 别名]
# 或者: from scipy.spatial import Delaunay [as 别名]
def _append_tmp_sources(self):

    from scipy.spatial import cKDTree as kdt
    from scipy.spatial import Delaunay as triag

    sources = row_stack([self.sources]+self.tmp_sources)
    tree = kdt(sources)
    self.sources = sources
    self.tree = tree
    self.tmp_sources = []
    self.tri = triag(
      self.sources,
      incremental=False,
      qhull_options='QJ Qc'
    )
    self.num_sources = len(self.sources)

    return len(sources) 
开发者ID:inconvergent,项目名称:fracture,代码行数:20,代码来源:fracture.py

示例4: construct_simplices

# 需要导入模块: from scipy import spatial [as 别名]
# 或者: from scipy.spatial import Delaunay [as 别名]
def construct_simplices(self, points, labels, epsilon, distfcn):
        distdict = calculate_distmatrix(points, labels, distfcn)

        delaunayobj = Delaunay(points)

        simplices = []
        for simplexnda in delaunayobj.simplices:
            simplex = tuple(simplexnda)

            detached = [contain_detachededges(face, distdict, epsilon) for face in facesiter(simplex)]

            if True in detached and len(simplex) > 2:
                simplices += [face for face, notkeep in zip(facesiter(simplex), detached)
                              if not notkeep]
            else:
                simplices.append(simplex)
        simplices = map(lambda simplex: tuple(sorted(simplex)), simplices)
        simplices = list(set(simplices))

        allpts = get_allpoints(simplices)
        simplices += [(point,) for point in (set(labels)-allpts)]

        return simplices 
开发者ID:stephenhky,项目名称:MoguTDA,代码行数:25,代码来源:alphacomplex.py

示例5: plot_in_hull

# 需要导入模块: from scipy import spatial [as 别名]
# 或者: from scipy.spatial import Delaunay [as 别名]
def plot_in_hull(p, cloud):
    """
    plot relative to `in_hull` for 2d data
    """
    hull = Delaunay(cloud)

    # plot triangulation
    poly = PolyCollection(hull.points[hull.vertices], facecolors='grey',
                          edgecolors='grey', alpha=0.1)
    plt.clf()
    plt.title('in hull: green, out of hull: red')
    plt.gca().add_collection(poly)
    plt.plot(hull.points[:, 0], hull.points[:, 1], 'o', color='grey',
             alpha=0.2)

    # plot tested points `p` - green are inside hull, red outside
    inside = hull.find_simplex(p) >= 0
    plt.plot(p[inside, 0], p[inside, 1], 'og')
    plt.plot(p[~inside, 0], p[~inside, 1], 'or')
    plt.show() 
开发者ID:kklmn,项目名称:xrt,代码行数:22,代码来源:convexHull.py

示例6: triangulate_depthmap_points

# 需要导入模块: from scipy import spatial [as 别名]
# 或者: from scipy.spatial import Delaunay [as 别名]
def triangulate_depthmap_points(points2d, depth, pix_thresh=2, depth_thresh=0.2):
    tri = Delaunay(points2d)
    faces_ = tri.simplices.copy()
    faces = []

    for j in range(faces_.shape[0]):
        if np.linalg.norm(points2d[faces_[j, 0], :] - points2d[faces_[j, 1], :]) <= pix_thresh and \
                        np.linalg.norm(points2d[faces_[j, 2], :] - points2d[faces_[j, 1], :]) <= pix_thresh and \
                        np.linalg.norm(points2d[faces_[j, 0], :] - points2d[faces_[j, 2], :]) <= pix_thresh and \
                        np.linalg.norm(depth[faces_[j, 0]] - depth[faces_[j, 1]]) <= depth_thresh and \
                        np.linalg.norm(depth[faces_[j, 2]] - depth[faces_[j, 1]]) <= depth_thresh and \
                        np.linalg.norm(depth[faces_[j, 0]] - depth[faces_[j, 2]]) <= depth_thresh:
            # faces.append(faces_[j, :])
            faces.append(faces_[j, (2, 1, 0)])
    # faces = np.array(faces)
    return faces 
开发者ID:krematas,项目名称:soccerontable,代码行数:18,代码来源:mesh.py

示例7: from_vertices

# 需要导入模块: from scipy import spatial [as 别名]
# 或者: from scipy.spatial import Delaunay [as 别名]
def from_vertices(cls, data):
        """
        Uses Delauney triangulation to compute triangle simplices for
        each point.
        """
        try:
            from scipy.spatial import Delaunay
        except:
            raise ImportError("Generating triangles from points requires, "
                              "SciPy to be installed.")
        if not isinstance(data, Points):
            data = Points(data)
        if not len(data):
            return cls(([], []))
        tris = Delaunay(data.array([0, 1]))
        return cls((tris.simplices, data)) 
开发者ID:holoviz,项目名称:holoviews,代码行数:18,代码来源:graphs.py

示例8: build_globe

# 需要导入模块: from scipy import spatial [as 别名]
# 或者: from scipy.spatial import Delaunay [as 别名]
def build_globe(self):
        """Generates the globe as ``vtkPolyData``"""
        # NOTE: https://gitlab.kitware.com/paraview/paraview/issues/19417
        from scipy.spatial import Delaunay
        pos, tex = self.create_sphere()
        pts = self.spherical_to_cartesian(pos[:,0], pos[:,1])
        points = interface.points_to_poly_data(pts).GetPoints()
        texcoords = interface.convert_array(tex, name='Texture Coordinates')
        # Now generate triangles
        cell_connectivity = Delaunay(pos).simplices.astype(int)
        cells = vtk.vtkCellArray()
        cells.SetNumberOfCells(cell_connectivity.shape[0])
        cells.SetCells(cell_connectivity.shape[0], interface.convert_cell_conn(cell_connectivity))
        # Generate output
        output = vtk.vtkPolyData()
        output.SetPoints(points)
        output.GetPointData().SetTCoords(texcoords)
        output.SetPolys(cells)
        return output 
开发者ID:OpenGeoVis,项目名称:PVGeo,代码行数:21,代码来源:earth.py

示例9: __init__

# 需要导入模块: from scipy import spatial [as 别名]
# 或者: from scipy.spatial import Delaunay [as 别名]
def __init__(self, size, maxdim=1, complex="scipy"):
        super(LevelSetLayer, self).__init__()
        self.size = size
        self.maxdim = maxdim
        self.fnobj = levelsetdgm()

        # extract width and height
        width, height = size
        if complex == "scipy":
            # initialize complex to use for persistence calculations
            axis_x = np.arange(0, width)
            axis_y = np.arange(0, height)
            grid_axes = np.array(np.meshgrid(axis_x, axis_y))
            grid_axes = np.transpose(grid_axes, (1, 2, 0))

            # creation of a complex for calculations
            tri = Delaunay(grid_axes.reshape([-1, 2]))
            faces = tri.simplices.copy()
            self.complex = self.fnobj.init_filtration(faces)
        elif complex == "freudenthal":
            self.complex = init_freudenthal_2d(width, height)
        else:
            AssertionError("bad complex type") 
开发者ID:bruel-gabrielsson,项目名称:TopologyLayer,代码行数:25,代码来源:levelset_dionysus.py

示例10: __create_weights_delaunay_triangulation

# 需要导入模块: from scipy import spatial [as 别名]
# 或者: from scipy.spatial import Delaunay [as 别名]
def __create_weights_delaunay_triangulation(self, stimulus):
        """!
        @brief Create weight Denlauny triangulation structure between neurons in line with stimulus.
        
        @param[in] stimulus (list): External stimulus for the chaotic neural network.
        
        """
        
        points = numpy.array(stimulus)
        triangulation = Delaunay(points)
        
        for triangle in triangulation.simplices:
            for index_tri_point1 in range(len(triangle)):
                for index_tri_point2 in range(index_tri_point1 + 1, len(triangle)):
                    index_point1 = triangle[index_tri_point1]
                    index_point2 = triangle[index_tri_point2]
                    
                    weight = self.__calculate_weight(stimulus[index_point1], stimulus[index_point2])
                    
                    self.__weights[index_point1][index_point2] = weight
                    self.__weights[index_point2][index_point1] = weight
                    
                    self.__weights_summary[index_point1] += weight
                    self.__weights_summary[index_point2] += weight 
开发者ID:annoviko,项目名称:pyclustering,代码行数:26,代码来源:cnn.py

示例11: get_alpha_shape

# 需要导入模块: from scipy import spatial [as 别名]
# 或者: from scipy.spatial import Delaunay [as 别名]
def get_alpha_shape(pointcloud, alpha):
    pointcloud = np.asarray(pointcloud)

    print(pointcloud,'\n',pointcloud.shape[1])

    assert pointcloud.ndim == 2
    assert pointcloud.shape[1] == 3, "for now, only 3-dimensional analysis is implemented"

    triangulation = spat.Delaunay(pointcloud)

    tetrahedrons = pointcloud[triangulation.simplices]  # remove this copy step, could be fatal
    radii2 = r2_circumsphere_tetrahedron(tetrahedrons[:, 0, :], tetrahedrons[:, 1, :], tetrahedrons[:, 2, :],
                                         tetrahedrons[:, 3, :])
    reduced_triangulation = triangulation.simplices[radii2 < alpha ** 2]
    del radii2, triangulation, tetrahedrons

    outer_triangulation = get_single_faces(reduced_triangulation)

    return outer_triangulation 
开发者ID:GeoPyTool,项目名称:GeoPyTool,代码行数:21,代码来源:Alpah_Shape_3D.py

示例12: test_voronoi_name_mapping

# 需要导入模块: from scipy import spatial [as 别名]
# 或者: from scipy.spatial import Delaunay [as 别名]
def test_voronoi_name_mapping(xy_of_hex):
    """Test scipy Voronoi names are mapped to landlab-style names."""
    voronoi = Voronoi(xy_of_hex)
    delaunay = Delaunay(xy_of_hex)
    graph = VoronoiDelaunay(xy_of_hex)

    assert np.all(graph.x_of_node == approx(voronoi.points[:, 0]))
    assert np.all(graph.y_of_node == approx(voronoi.points[:, 1]))

    assert np.all(graph.x_of_corner == approx(voronoi.vertices[:, 0]))
    assert np.all(graph.y_of_corner == approx(voronoi.vertices[:, 1]))

    assert np.all(graph.nodes_at_link == voronoi.ridge_points)

    assert tuple(graph.n_corners_at_cell) == tuple(
        len(region) for region in voronoi.regions
    )
    for cell, corners in enumerate(graph.corners_at_cell):
        assert np.all(corners[: graph.n_corners_at_cell[cell]] == voronoi.regions[cell])
        assert np.all(corners[graph.n_corners_at_cell[cell] :] == -1)
    assert np.all(graph.corners_at_face == voronoi.ridge_vertices)
    assert np.all(graph.nodes_at_face == voronoi.ridge_points)
    assert np.all(graph.cell_at_node == voronoi.point_region)

    assert np.all(graph.nodes_at_patch == delaunay.simplices) 
开发者ID:landlab,项目名称:landlab,代码行数:27,代码来源:test_voronoi_to_graph.py

示例13: get_circle

# 需要导入模块: from scipy import spatial [as 别名]
# 或者: from scipy.spatial import Delaunay [as 别名]
def get_circle(batch_size, masks_size, num_points, device):
    half_dim = masks_size / 2
    half_width = half_dim
    half_height = half_dim

    vert = np.array([[
        half_width + math.floor(math.cos(2 * math.pi / num_points * x) * 10),
        half_height + math.floor(math.sin(2 * math.pi / num_points * x) * 10)]
        for x in range(0, num_points)])
    vert = (vert - half_dim) / half_dim

    tri = Delaunay(vert).simplices.copy()

    vert = torch.Tensor(vert)[None, None, ...].to(device).repeat(batch_size, 1, 1, 1)
    face = torch.Tensor(tri)[None, None, ...].to(device).repeat(batch_size, 1, 1, 1).type(torch.int32)

    vert[:, :, :, 1] = -vert[:, :, :, 1]

    return vert, face 
开发者ID:shirgur,项目名称:ACDRNet,代码行数:21,代码来源:topology.py

示例14: in_hull

# 需要导入模块: from scipy import spatial [as 别名]
# 或者: from scipy.spatial import Delaunay [as 别名]
def in_hull(p, hull):
    from scipy.spatial import Delaunay
    if not isinstance(hull,Delaunay):
        hull = Delaunay(hull)
    return hull.find_simplex(p)>=0 
开发者ID:zaiweizhang,项目名称:H3DNet,代码行数:7,代码来源:sunrgbd_utils.py

示例15: genPoints

# 需要导入模块: from scipy import spatial [as 别名]
# 或者: from scipy.spatial import Delaunay [as 别名]
def genPoints(qty, width, height):
	side = max(width, height)
	randPoints = np.random.choice(side, size=(qty, 2))

	og = side
	
	tri = Delaunay(randPoints) # calculate D triangulation of points
	points = tri.points[tri.simplices] # find all groups of points

	return points 
开发者ID:SubhrajitPrusty,项目名称:wallgen,代码行数:12,代码来源:points.py


注:本文中的scipy.spatial.Delaunay方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。