Beispiel #1
0
def main():
    #circles = [(1.9,0,0,0),(1.0,0.95,0,0)]

    tree = Octree(rootnode, resolution, circles)
    print('so many leaves:%d' % len(tree.branches))
    draw_lines([rootnode], [0, 0, 255])
    renderWindowInteractor.Start()
def step_leapfrog_barnes_hut(x, v, a, m, np, dt, theta,
                             bounding_cube: BoundingCube):
    ot = Octree(bounding_cube)
    max_dim = -inf
    for i in range(np):
        ot.add_object(x[i], m[i])
    for i in range(np):
        v[i] = v[i] + (0.5 * dt * a[i])
        x[i] = x[i] + (dt * v[i])
        a[i] = [0, 0, 0]
        max_dim = max(max_dim, max(abs(x[i])))
        points_masses = zip(*ot.get_points_masses(x[i], theta))
        for point, mass in points_masses:
            dx = subtract(x[i], point)
            r2 = dot(dx, dx)
            r = sqrt(r2)
            if r == 0.0:
                continue
            a[i] = a[i] - mass * dx / (r**3)
        v[i] = v[i] + (0.5 * dt * a[i])
    return x, v, a, max_dim
Beispiel #3
0
def main():
    #circles = [(1.9,0,0,0),(1.0,0.95,0,0)]
    circles = [(2.0,0,0,0)]
    points = parse_stl('plane.stl')
    rootcube = [-1.0, -11.0, 10.0, 22.0, 11.0, 26.0]
    resolution = 1.5
    green = [0, 255, 0]
    red = [255, 0, 0]
    blue = [0, 0, 255]
    
    rootnode = Node(None, rootcube)
    tree = Octree(rootnode, resolution, circles, points)
    print('so many leaves:%d' % len(tree.branches))
    objects = {}
    
    objects['branches'] = draw_lines(tree.branches,green)
    objects['leaves'] = draw_lines(tree.leaves,red)

    #objects.append(draw_sphere(2.0,0,0,0))
    
    # Setup render window, renderer, and interactor
    #renderer = vtk.vtkRenderer()
    renderWindow.AddRenderer(renderer)
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)
    renderWindowInteractor.AddObserver("KeyPressEvent", keypress)

    stlWriter = vtk.vtkSTLWriter()
    stlWriter.SetFileName("testout.stl")
    stlWriter.SetInputConnection(objects['leaves'].GetOutputPort())
    stlWriter.Write()
    
    for name in objects:
        obj = objects[name]
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInput(obj)
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.name = name
        actor.shown = True
        renderer.AddActor(actor)

    renderWindow.Render()
    renderWindowInteractor.Start()
Beispiel #4
0
def main():
    circles = [(2.0, 0, 0, 0)]
    points = parse_ply('damesmall.ply')
    ranges = get_maxmin(points)

    rootcube = [
        ranges['minx'], ranges['miny'], ranges['minz'], ranges['maxx'],
        ranges['maxy'], ranges['maxz'] + 400
    ]
    resolution = 10.0
    green = [0, 255, 0]
    red = [255, 0, 0]
    blue = [0, 0, 255]

    rootnode = Node(None, rootcube)
    tree = Octree(rootnode, resolution, circles, points)
    print('so many leaves:%d' % len(tree.branches))
    objects = {}

    objects['branches'] = draw_lines(tree.branches, green)
    objects['leaves'] = draw_lines(tree.leaves, red)
Beispiel #5
0
def main():
    #points = parse_asc('building.asc')
    #points = parse_asc('richview.asc')
    points = parse_asc('church.asc')

    stats = get_stats(points)

    rootcube = [
        stats['minx'], stats['miny'], stats['minz'], stats['maxx'],
        stats['maxy'], stats['maxz']
    ]

    rootnode = Node(None, rootcube)
    tree = Octree(rootnode, rootcube, points)
    objects = {}

    objects['branches'] = draw_lines(tree.branches)
    objects['leaves'] = draw_lines(tree.leaves)
    #objects['points'] = draw_points(points)
    #draw_cubes(tree.leaves)
    write_ply(tree.leaves)
    vtkrender(objects)
Beispiel #6
0
def main():
    #circles = [(1.9,0,0,0),(1.0,0.95,0,0)]
    circles = [(2.0, 0, 0, 0)]
    rootcube = [-4.0, -4.0, -4.0, 4.0, 4.0, 4.0]
    resolution = 0.1
    green = [0, 255, 0]
    red = [255, 0, 0]
    blue = [0, 0, 255]

    rootnode = Node(None, rootcube)
    tree = Octree(rootnode, resolution, circles)
    print('so many leaves:%d' % len(tree.branches))
    objects = {}

    objects['branches'] = draw_lines(tree.branches, green)
    objects['leaves'] = draw_lines(tree.leaves, red)

    #objects.append(draw_sphere(2.0,0,0,0))

    # Setup render window, renderer, and interactor
    #renderer = vtk.vtkRenderer()
    renderWindow.AddRenderer(renderer)
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)
    renderWindowInteractor.AddObserver("KeyPressEvent", keypress)

    for name in objects:
        obj = objects[name]
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInput(obj)
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.name = name
        actor.shown = True
        renderer.AddActor(actor)

    renderWindow.Render()
    renderWindowInteractor.Start()
Beispiel #7
0
def main():
    #circles = [(1.9,0,0,0),(1.0,0.95,0,0)]
    circles = [(2.0, 0, 0, 0)]

    rootcube = [-4.0, -4.0, -4.0, 4.0, 4.0, 4.0]
    resolution = 0.1

    rootnode = Node(None, rootcube)
    tree = Octree(rootnode, resolution, circles)
    print len(tree.leaves)
    print('so many leaves:%d' % len(tree.leaves))

    points = vtk.vtkPoints()
    lines = vtk.vtkCellArray()
    nodecnt = 0

    for node in tree.leaves:
        edges = node.getedges()

        for edge in edges:
            x0, y0, z0 = edge[0]
            x1, y1, z1 = edge[1]

            points.InsertNextPoint(edge[0])
            points.InsertNextPoint(edge[1])

            line = vtk.vtkLine()
            line.GetPointIds().SetId(0, nodecnt)
            line.GetPointIds().SetId(1, nodecnt + 1)
            lines.InsertNextCell(line)
            nodecnt += 2

    # Create a polydata to store everything in
    linesPolyData = vtk.vtkPolyData()

    # Add the points to the dataset
    linesPolyData.SetPoints(points)

    # Add the lines to the dataset
    linesPolyData.SetLines(lines)

    # create sphere source
    source = vtk.vtkSphereSource()
    source.SetCenter(0, 0, 0)
    source.SetRadius(2.0)

    # Setup actor and mapper
    mapper = vtk.vtkPolyDataMapper()
    mapper2 = vtk.vtkPolyDataMapper()

    if vtk.VTK_MAJOR_VERSION <= 5:
        mapper.SetInput(linesPolyData)
        mapper2.SetInput(source.GetOutput())
    else:
        mapper.SetInputData(linesPolyData)
        mapper2.SetInputConnection(source.GetOutputPort())

    actor = vtk.vtkActor()
    actor2 = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor2.SetMapper(mapper2)

    # Setup render window, renderer, and interactor
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)
    renderer.AddActor(actor)
    #actor2.GetProperty().SetRepresentationToWireframe()
    #renderer.AddActor(actor2)
    renderWindow.Render()
    renderWindowInteractor.Start()
Beispiel #8
0
                    help="field of view of the camera",
                    type=int,
                    default=45)

args = parser.parse_args()

if args.fov <= 0 or args.fov >= 180:
    print("Error: fov must be in (0; 180)")
    sys.exit(1)

fov_tan = math.tan(args.fov / 2 * math.pi / 180)
cam_r = 2.1 * args.r / math.sin(args.fov / 2 * math.pi / 180)

t = time.time()

map = Octree(args.r * 2)


def rand_c():
    while True:
        r = random.randrange(0, 0xff)
        g = random.randrange(0, 0xff)
        b = random.randrange(0, 0xff)
        s = r + g + b
        if s > 0x60:
            return r << 16 | g << 8 | b


screen = LedScreen(args.ip, args.port)

panel_x = screen.size_x
from point import Point
import numpy as np
from pointCloud import PointCloud
from octree import Octree


def load_ply(filename):
    points = []
    with open(filename) as f:
        while 'end_header' not in f.readline():
            pass
        #for line in f.readlines()[::100]:
        for line in f.readlines()[:6]:
            data = line.split()
            data = map(float, data)
            x, y, z = data[:3]
            nx, ny, nz = data[3:6]
            pt = Point(x, y, z)
            pt.normal = np.array([x, y, z])
            points.append(pt)
    return points


if __name__ == '__main__':
    points = load_ply('../../Rift/temple.ply')
    octree = Octree(points, 3)
    #octree.display()
    octree._saveOFF()
from point import Point
import numpy as np
from pointCloud import PointCloud
from octree import Octree

def load_ply(filename):
    points = []
    with open(filename) as f:
        while 'end_header' not in f.readline():
            pass
        #for line in f.readlines()[::100]:
        for line in f.readlines()[:6]:
            data = line.split()
            data = map(float, data)
            x, y, z = data[:3]
            nx, ny, nz = data[3:6]
            pt = Point(x,y,z)
            pt.normal = np.array([x, y, z])
            points.append(pt)
    return points

if __name__ == '__main__':
    points = load_ply('../../Rift/temple.ply')
    octree = Octree(points, 3)
    #octree.display()
    octree._saveOFF()

Beispiel #11
0
from pyvox.parser import VoxParser
from octree import Octree
from argparse import ArgumentParser

if __name__ == '__main__':
    parser = ArgumentParser("Parse a magica voxel file into an octree format")
    parser.add_argument('input', help="input octree filename")
    parser.add_argument('size', type=int, help="cells per octree side")
    parser.add_argument('-oc', help="output .oc file representing the tree")
    parser.add_argument('-mat',
                        help="output .mat file representing the materials")
    args = parser.parse_args()

    m = VoxParser(args.input).parse()
    oc = Octree(args.size)

    for model in m.models:
        for voxel in model.voxels:
            oc.set(voxel.x, voxel.y, voxel.z, voxel.c)

    if args.oc:
        with open(args.oc, 'w') as f:
            f.write(oc.toOC())

    if args.mat:
        output = "0x000000\n"
        for color in m.palette:
            output += f"0x{color.b:0{2}x}{color.g:0{2}x}{color.r:0{2}x}\n"

        with open(args.mat, 'w') as f:
Beispiel #12
0
        branches()
    elif key == "s":
        start_anim()


renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
renderWindowInteractor.AddObserver("KeyPressEvent", keypress)
circles = [(2.0, 0, 0, 0)]
rootcube = [-4.0, -4.0, -4.0, 4.0, 4.0, 4.0]
resolution = 0.1
rootnode = Node(None, rootcube)
tree = Octree(rootnode, resolution, circles)


def draw_lines(nodes, color):
    colors = vtk.vtkUnsignedCharArray()
    colors.SetNumberOfComponents(3)
    colors.SetName("Colors")
    cnt = 0
    noderange = 100
    mod = 1
    edges = nodes[0].getedges()
    points = vtk.vtkPoints()
    lines = vtk.vtkCellArray()
    nodecnt = 0

    while cnt < len(nodes):
        neighbors = pc.nearest_neighbors(pt, 1)
        d = 0
        for pt2 in neighbors:
            diff = pt.position - pt2.position
            d += np.dot(diff, pt2.normal)
        return d

    return dist


if __name__ == '__main__':
    pc = get_plane()
    pc.compute_normals(k=5)
    # pc.display(normals=True)
    dist = get_dist_func(pc)
    octree = Octree(pc.points, 2)
    octree.display()
    contour = octree.compute_contour(dist)
    print 'Found %d faces' % len(contour)
    fig = plt.figure()
    axis = fig.gca(projection='3d')
    #
    # min_x = min_y = min_z = float('inf')
    # max_x = max_y = max_z = float('-inf')
    for (pt1, pt2, pt3) in contour:
        v1 = pt1.position.tolist()
        v2 = pt2.position.tolist()
        v3 = pt3.position.tolist()
        face = Poly3DCollection([[v1, v2, v3]])
        axis.add_collection3d(face)
Beispiel #14
0
 def setup_octree(self):
     with benchmark('build octree'):
         self.octree = Octree(self.scene)
Beispiel #15
0
def make_octree(stars):
    octree = Octree(0, 0, 0, 2000, 4)
    for star in stars:
        octree.insert(star)
    return octree
Beispiel #16
0
def make_octree(stars):
    octree = Octree(0, 0, 0, 2000, 4)
    for star in stars:
        octree.insert(star)
    return octree