Ejemplo n.º 1
0
 def test_cube_union(self):
     a = CSG.cube()
     b = CSG.cube([0.5, 0.5, 0.0])
     c = a + b
     c.saveVTK('test_cube_union.vtk')
     d = c.refine().refine()
     d.saveVTK('test_cube_union_refined_2x.vtk')
Ejemplo n.º 2
0
 def test_bolt(self):
     shaft = CSG.cylinder(start=[0., 0., 0.], end=[1., 0., 0.], radius=0.1, slices=32)
     head = CSG.cone(start=[-0.12, 0., 0.], end=[0.10, 0., 0.], radius=0.25)
     notch1 = CSG.cube(center=[-0.10, 0., 0.], radius=[0.02, 0.20, 0.02])
     notch2 = CSG.cube(center=[-0.10, 0., 0.], radius=[0.02, 0.02, 0.20])
     bolt = shaft + head - notch1 - notch2
     bolt.saveVTK('test_bolt.vtk')
Ejemplo n.º 3
0
 def test_bolt(self):
     shaft = CSG.cylinder(start=[0., 0., 0.], end=[1., 0., 0.], radius=0.1, slices=32)
     head = CSG.cone(start=[-0.12, 0., 0.], end=[0.10, 0., 0.], radius=0.25)
     notch1 = CSG.cube(center=[-0.10, 0., 0.], radius=[0.02, 0.20, 0.02])
     notch2 = CSG.cube(center=[-0.10, 0., 0.], radius=[0.02, 0.02, 0.20])
     bolt = shaft + head - notch1 - notch2
     bolt.saveVTK('test_bolt.vtk')
Ejemplo n.º 4
0
 def test_cube_union(self):
     a = CSG.cube()
     b = CSG.cube([0.5, 0.5, 0.0])
     c = a + b
     c.saveVTK('test_cube_union.vtk')
     d = c.refine().refine()
     d.saveVTK('test_cube_union_refined_2x.vtk')
Ejemplo 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()
Ejemplo n.º 6
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()
Ejemplo n.º 7
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
Ejemplo n.º 8
0
def Box(origin, lengths):
    """
    Create box
    @param  origin/low  end  of  the  box
    @param  lengths  lengths  in  x,  y,  and  z
    """
    center = [origin[i] + 0.5*lengths[i] for i in range(len(origin))]
    radius = [0.5*le for le in lengths]
    return CSG.cube(center=center, radius=radius)
Ejemplo n.º 9
0
 def __init__(self, operation):
     self.faces = []
     self.normals = []
     self.vertices = []
     self.colors = []
     self.vnormals = []
     self.list = -1
     
     a = CSG.cube()
     b = CSG.cylinder(radius=0.5, start=[0., -2., 0.], end=[0., 2., 0.])
     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(b).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
Ejemplo n.º 10
0
def cube_csg(inst):
    dim = inst[1:4]

    key = "%f,%f,%fcube" % (dim[0], dim[1], dim[2])
    obj = cache_find(key)
    if obj is not None:
        mesh_push(obj, key)
        return
    half = [dim[0] / 2.0, dim[1] / 2.0, dim[2] / 2.0]
    obj = CSG.cube(center=half, radius=half)
    cache_put(key, obj)
    mesh_push(obj, key)
Ejemplo n.º 11
0
from __future__ import print_function
from icqsol.shapes.icqShapeManager import ShapeManager
from csg.core import CSG
from icqsol import util

"""
Test construction of shape from a list of polygons
@author [email protected]
"""
shape_mgr = ShapeManager(file_format=util.VTK_FORMAT, vtk_dataset_type=util.POLYDATA)
cube = CSG.cube()
# Should we test if shp == cube?
shp = shape_mgr.shapeFromPolygons(cube)
Ejemplo n.º 12
0
 def test_translate_cube(self):
     a = CSG.cube()
     a.saveVTK('a.vtk')
     a.translate(disp=[0.1, 0.2, 0.3])
     a.saveVTK('aTranslated.vtk')
Ejemplo n.º 13
0
 def test_cube_union(self):
     a = CSG.cube()
     b = CSG.cube([0.5, 0.5, 0.0])
     c = a + b
     c.saveVTK('test_cube_union.vtk')
Ejemplo n.º 14
0
 def test_cube_subtract(self):
     a = CSG.cube()
     b = CSG.cube([0.5, 0.5, 0.0])
     c = a - b
     c.saveVTK('test_cube_subtract.vtk')
Ejemplo n.º 15
0
 def test_cube_union(self):
     a = CSG.cube()
     b = CSG.cube([0.5, 0.5, 0.0])
     c = a + b
     c.saveVTK('test_cube_union.vtk')
Ejemplo n.º 16
0
 def test_cube_intersect(self):
     a = CSG.cube()
     b = CSG.cube([0.5, 0.5, 0.0])
     c = a * b
     c.saveVTK('test_cube_intersect.vtk')
Ejemplo n.º 17
0
 def test_cube(self):
     a = CSG.cube(center=[0., 0., 0.], radius=[1., 2., 3.])
     a.saveVTK('test_cube.vtk')
Ejemplo n.º 18
0
def get_target_object_polygon(min_x, min_y, min_z, max_x, max_y, max_z):

    res = CSG.cube([(min_x + max_x) / 2, (min_y + max_y) / 2, (min_z + max_z) / 2],
             [(max_x - min_x) / 2, (max_y - min_y) / 2, (max_z - min_z) / 2])
    return res
Ejemplo n.º 19
0
 def test_rotate_cube(self):
     a = CSG.cube()
     a.saveVTK('a.vtk')
     a.rotate(axis=[0.1, 0.2, 0.3], angleDeg=20.0)
     a.saveVTK('aRotated.vtk')
Ejemplo n.º 20
0
 def test_translate_cube(self):
     a = CSG.cube()
     a.saveVTK('a.vtk')
     a.translate(disp=[0.1, 0.2, 0.3])
     a.saveVTK('aTranslated.vtk')
Ejemplo n.º 21
0
 def test_rotate_cube(self):
     a = CSG.cube()
     a.saveVTK('a.vtk')
     a.rotate(axis=[0.1, 0.2, 0.3], angleDeg=20.0)
     a.saveVTK('aRotated.vtk')
Ejemplo n.º 22
0
    glutDisplayFunc(renderable.display)
    glutKeyboardFunc(renderable.keypress)
    glutSpecialFunc(renderable.special_keypress)

    renderable.init()

    glutMainLoop()


def show_matplotlib(csg):
    verts = []
    polygons = csg.toPolygons()
    for polygon in polygons:
        poly_verts = list()
        for v in polygon.vertices:
            poly_verts.append((v.pos.x, v.pos.y, v.pos.z))
        verts.append(poly_verts)
    ax = gcf().add_subplot(111, projection='3d')
    c = Poly3DCollection(verts)
    c.set_edgecolor("black")
    ax.add_collection3d(c)


if __name__ == '__main__':
    a = CSG.cube(radius=[0.5] * 3)
    from matplotlib.pyplot import show
    show_matplotlib(a)
    show()
    show_OpenGL(a)
    print("Done")
Ejemplo n.º 23
0
 def test_cube_subtract(self):
     a = CSG.cube()
     b = CSG.cube([0.5, 0.5, 0.0])
     c = a - b
     c.saveVTK('test_cube_subtract.vtk')
Ejemplo n.º 24
0
 def test_cube_intersect(self):
     a = CSG.cube()
     b = CSG.cube([0.5, 0.5, 0.0])
     c = a * b
     c.saveVTK('test_cube_intersect.vtk')
Ejemplo n.º 25
0
 def test_cube(self):
     a = CSG.cube(center=[0., 0., 0.], radius=[1., 2., 3.])
     a.saveVTK('test_cube.vtk')