Esempio n. 1
0
 def test_sphere_union(self):
     a = CSG.sphere(center=(0., 0., 0.), radius=1.0, slices=64, stacks=32)
     b = CSG.sphere(center=(1.99, 0., 0.), radius=1.0, slices=64, stacks=32)
     c = a + b
     a.saveVTK('test_sphere_union_a.vtk')
     b.saveVTK('test_sphere_union_b.vtk')
     c.saveVTK('test_sphere_union.vtk')
Esempio n. 2
0
 def test_sphere_union(self):
     a = CSG.sphere(center=(0., 0., 0.), radius=1.0, slices=64, stacks=32)
     b = CSG.sphere(center=(1.99, 0., 0.), radius=1.0, slices=64, stacks=32)
     c = a + b
     a.saveVTK('test_sphere_union_a.vtk')
     b.saveVTK('test_sphere_union_b.vtk')
     c.saveVTK('test_sphere_union.vtk')
Esempio n. 3
0
 def test_toPolygons(self):
     a = CSG.cube([0.5, 0.5, 0.0])
     aPolys = a.toPolygons()
     b = CSG.sphere()
     bPolys = b.toPolygons()
     c = CSG.cylinder()
     cPolys = c.toPolygons()
Esempio n. 4
0
 def test_sphere_cylinder_subtract(self):
     a = CSG.sphere(center=[0.5, 0.5, 0.5], radius=0.5, slices=8, stacks=4)
     b = CSG.cylinder(start=[0., 0., 0.],
                      end=[1., 0., 0.],
                      radius=0.3,
                      slices=16)
     a.subtract(b).saveVTK('test_sphere_cylinder_subtract.vtk')
Esempio n. 5
0
 def test_toPolygons(self):
     a = CSG.cube([0.5, 0.5, 0.0])
     aPolys = a.toPolygons()
     b = CSG.sphere()
     bPolys = b.toPolygons()
     c = CSG.cylinder()
     cPolys = c.toPolygons()
Esempio n. 6
0
 def __init__(self, operation):
     self.faces = []
     self.normals = []
     self.vertices = []
     self.colors = []
     self.vnormals = []
     self.list = -1
     
     c = CSG.cube()
     b = CSG.sphere()#slices=32,stacks=16)
     a = CSG.tetra()
     #b = CSG.cylinder(radius=0.5, start=[0., 0., 0.], end=[0., 2., 0.])#,slices=16)
     #c = CSG.cylinder(radius=0.5, start=[0., 0., 0.], end=[0., 2., 0.]).rotate([0,0,1],90)#,slices=16)
     for p in a.polygons:
         p.shared = [1.0, 0.0, 0.0, 1.0]
     for p in b.polygons:
         p.shared = [0.0, 1.0, 0.0, 1.0]
         
     recursionlimit = sys.getrecursionlimit()
     sys.setrecursionlimit(10000)
     try:
         if operation == 'subtract':
             polygons = a.subtract(b).toPolygons()
         elif operation == 'union':
             polygons =a.union(c).toPolygons()
         elif operation == 'intersect':
             polygons = a.intersect(b).toPolygons()
         else:
             raise Exception('Unknown operation: \'%s\'' % operation)
     except RuntimeError as e:
         raise RuntimeError(e)
     sys.setrecursionlimit(recursionlimit)
     
     for polygon in polygons:
         n = polygon.plane.normal
         indices = []
         for v in polygon.vertices:
             pos = [v.pos.x, v.pos.y, v.pos.z]
             if not pos in self.vertices:
                 self.vertices.append(pos)
                 self.vnormals.append([])
             index = self.vertices.index(pos)
             indices.append(index)
             self.vnormals[index].append(v.normal)
         self.faces.append(indices)
         self.normals.append([n.x, n.y, n.z])
         self.colors.append(polygon.shared)
     
     # setup vertex-normals
     ns = []
     for vns in self.vnormals:
         n = Vector(0.0, 0.0, 0.0)
         for vn in vns:
             n = n.plus(vn)
         n = n.dividedBy(len(vns))
         ns.append([a for a in n])
     self.vnormals = ns
Esempio n. 7
0
def sphere_csg(inst):
    r = inst[1]
    center = inst[2:]
    key = "%f,%f,%f,%f,sphere" % (r, center[0], center[1], center[2])

    obj = cache_find(key)
    if obj is not None:
        mesh_push(obj, key)
        return
    obj = CSG.sphere(center=center, radius=r)
    cache_put(key, obj)
    mesh_push(obj, key)
Esempio n. 8
0
def Sphere(radius, origin, n_theta=16, n_phi=8):
    """
    Create sphere
    @param radius radius
    @param origin center of the sphere
    @param n_theta number of theta cells
    @param n_phi number of azimuthal cells
    """
    return CSG.sphere(center=origin,
                      radius=radius,
                      slices=n_theta,
                      stacks=n_phi)
Esempio n. 9
0
 def test_sphere_cylinder_subtract(self):
     a = CSG.sphere(center=[0.5, 0.5, 0.5], radius=0.5, slices=8, stacks=4)
     b = CSG.cylinder(start=[0.,0.,0.], end=[1.,0.,0.], radius=0.3, slices=16)
     a.subtract(b).saveVTK('test_sphere_cylinder_subtract.vtk')
Esempio n. 10
0
 def test_sphere(self):
     a = CSG.sphere(center=[0., 0., 0.], radius=1., slices=4, stacks=3)
    	a.saveVTK('test_sphere.vtk')
     b = a.refine()
     b.saveVTK('test_sphere_refined.vtk')
Esempio n. 11
0
 def test_sphere(self):
     a = CSG.sphere(center=[0., 0., 0.], radius=1., slices=4, stacks=3)
    	a.saveVTK('test_sphere.vtk')
     b = a.refine()
     b.saveVTK('test_sphere_refined.vtk')
Esempio n. 12
0
 def test_sphere(self):
     a = CSG.sphere(center=[0.0, 0.0, 0.0], radius=1.0, slices=4, stacks=3)
     a.saveVTK("test_sphere.vtk")
     b = a.refine()
     b.saveVTK("test_sphere_refined.vtk")