Пример #1
0
 def triangle3d_for_face(self, fh):
     if self.cdt.is_infinite(fh):
         return None
     else:
         t = Triangle_3(*(self.point3d_for_vertex(fh.vertex(i))
                          for i in range(3)))
         return t
Пример #2
0
def sample_distance(mesh, points, q):
    triangles = []
    for tri in mesh.triangles:
        a = Point_3(tri[0][0], tri[0][1], tri[0][2])
        b = Point_3(tri[1][0], tri[1][1], tri[1][2])
        c = Point_3(tri[2][0], tri[2][1], tri[2][2])
        triangles.append(Triangle_3(a, b, c))
    tree = AABB_tree_Triangle_3_soup(triangles)
    tree.accelerate_distance_queries()

    vecs = []
    i = 0
    for query in points:
        i += 1
        if i % 5000 == 0:
            q.put(1)

        p = Point_3(query[0], query[1], query[2])
        nearest = tree.closest_point(p)
        vec = p - nearest
        vecs.append([vec.x(), vec.y(), vec.z()])

    # absolute value because loss is for unsigned data
    out = np.array(vecs)
    distances = np.linalg.norm(out, axis=1)[:, None]
    grads = np.abs(out / distances)
    return distances, grads
Пример #3
0
def gen_triangle_soup(vertices_cgal, faces):
    t0 = time.time()
    soup = [
        Triangle_3(vertices_cgal[f[0]], vertices_cgal[f[1]],
                   vertices_cgal[f[2]]) for f in faces
    ]
    print('{:<21} {:>9.5f}'.format('gen_triangle_soup', time.time() - t0))
    return soup
def verticesToTriangles(
    verts, triangleIndices, transforms
):  #Transforms list of triangles, and then saves them as Triangle_3, a format used for morphing points onto meshes
    triangles = []
    for i in range(0, len(triangleIndices)):
        ax, ay, az = transformPoint(
            transforms[1],
            transformPoint(transforms[0],
                           verts[triangleIndices[i][0]])[0:3])[0:3]
        bx, by, bz = transformPoint(
            transforms[1],
            transformPoint(transforms[0],
                           verts[triangleIndices[i][1]])[0:3])[0:3]
        cx, cy, cz = transformPoint(
            transforms[1],
            transformPoint(transforms[0],
                           verts[triangleIndices[i][2]])[0:3])[0:3]
        triangles.append(
            Triangle_3(Point_3(ax, ay, az), Point_3(bx, by, bz),
                       Point_3(cx, cy, cz)))
    return numpy.array(triangles)
Пример #5
0
    tree.insert_from_array(soup)
    print('{:<21} {:>9.5f}'.format('gen_segment_tree_Nx6', time.time() - t0))
    return tree


#end

# Set sizes.
nx = 100
ny = 100
sepstring = '*' * 31
# Set up some testing primitives
p1 = Point_3(-1, -1, -1)
p2 = Point_3(1, 1, 1)
p3 = Point_3(1, 1, -1)
tri0 = Triangle_3(p1, p2, p3)
seg0 = Segment_3(p1, p2)

# Generate an initial set of points, faces, and edges.
verts = gen_vertices(nx, ny)
faces = gen_faces(nx, ny)
edges = gen_edges(faces)

nverts = len(verts)
nfaces = len(faces)
nedges = len(edges)

# Convert points to list of CGAL Point_3 objects.
t0 = time.time()
verts_cgal = gen_vertices_cgal(verts)
tverts = time.time() - t0
Пример #6
0
poly.make_tetrahedron(Point_3(0, 0, 0), Point_3(1, 0, 0), Point_3(0, 1, 0),
                      Point_3(0, 0, 1))
tree = AABB_tree_Polyhedron_3_Facet_handle()

lst = []
for f in poly.facets():
    lst.append(f)

tree.rebuild(lst)
tree = AABB_tree_Polyhedron_3_Facet_handle(lst)
print(tree.size())

lst = []

for f in poly.facets():
    p1 = f.halfedge().vertex().point()
    p2 = f.halfedge().next().vertex().point()
    p3 = f.halfedge().next().next().vertex().point()
    t = Triangle_3(p1, p2, p3)
    lst.append(t)

tree2 = AABB_tree_Triangle_3_soup(lst)

s = Segment_3(Point_3(-0.5, -0.5, 0.5), Point_3(0.5, 0.5, 0.5))

primitives = []
tree2.all_intersected_primitives(s, primitives)

for primitive in primitives:
    print(primitive)
from __future__ import print_function
from CGAL.CGAL_Kernel import Point_3
from CGAL.CGAL_Kernel import Triangle_3
from CGAL.CGAL_Kernel import Ray_3
from CGAL.CGAL_AABB_tree import AABB_tree_Triangle_3_soup

a = Point_3(1.0, 0.0, 0.0)
b = Point_3(0.0, 1.0, 0.0)
c = Point_3(0.0, 0.0, 1.0)
d = Point_3(0.0, 0.0, 0.0)

triangles = []
triangles.append(Triangle_3(a, b, c))
triangles.append(Triangle_3(a, b, d))
triangles.append(Triangle_3(a, d, c))

# constructs AABB tree
tree = AABB_tree_Triangle_3_soup(triangles)

# counts #intersections
ray_query = Ray_3(a, b)
print(tree.number_of_intersected_primitives(ray_query),
      " intersections(s) with ray query")

# compute closest point and squared distance
point_query = Point_3(2.0, 2.0, 2.0)
closest_point = tree.closest_point(point_query)
sqd = tree.squared_distance(point_query)
print("squared distance: ", sqd)
Пример #8
0
                        pnts = pnts - np.expand_dims(center, axis=0)
                        scale = 1
                        pnts = pnts / scale
                        triangles = []
                        for tri in mesh.triangles:

                            a = Point_3((tri[0][0] - center[0]) / scale,
                                        (tri[0][1] - center[1]) / scale,
                                        (tri[0][2] - center[2]) / scale)
                            b = Point_3((tri[1][0] - center[0]) / scale,
                                        (tri[1][1] - center[1]) / scale,
                                        (tri[1][2] - center[2]) / scale)
                            c = Point_3((tri[2][0] - center[0]) / scale,
                                        (tri[2][1] - center[1]) / scale,
                                        (tri[2][2] - center[2]) / scale)
                            triangles.append(Triangle_3(a, b, c))
                        tree = AABB_tree_Triangle_3_soup(triangles)

                        sigmas = []
                        ptree = cKDTree(pnts)
                        i = 0
                        for p in np.array_split(pnts, 100, axis=0):
                            d = ptree.query(p, 51)
                            sigmas.append(d[0][:, -1])

                            i = i + 1

                        sigmas = np.concatenate(sigmas)
                        sigmas_big = opt.sigma * np.ones_like(sigmas)

                        np.save(output_file + '.npy', pnts)
Пример #9
0
    #print("result:", vn[a[i]])
    fucking_ray.append(ray)
    back_ray.append(ray_back)
count = 0
nomiss_points_ind = []
for i in range(len(fucking_ray)):
    tmp = []
    Points = []
    for j in range(len(faces)):
        a = Point_3(vertics[faces[j][0] - 1][0], vertics[faces[j][0] - 1][1],
                    vertics[faces[j][0] - 1][2])
        b = Point_3(vertics[faces[j][1] - 1][0], vertics[faces[j][1] - 1][1],
                    vertics[faces[j][1] - 1][2])
        c = Point_3(vertics[faces[j][2] - 1][0], vertics[faces[j][2] - 1][1],
                    vertics[faces[j][2] - 1][2])
        tri = Triangle_3(a, b, c)
        result = intersection(fucking_ray[i], tri)
        if result.is_Point_3():
            #print("before: ", str(vertics[faces[j][0]-1]))
            #print("after: ", str(result.get_Point_3()))
            inter = str(result.get_Point_3)
            tmp.append(str(result.get_Point_3()))
            break

    try:
        Points.append(tmp[len(tmp) - 1])
        #print(tmp[len(tmp)-1])
        nomiss_points_ind.append(i)
    except:
        for j in range(len(faces)):
            a = Point_3(vertics[faces[j][0] - 1][0],