Example #1
0
def surfacescan(scene, density):
    result = []
    for shape in scene:
        position = pgl.Vector3(0, 0, 0)
        heading = pgl.Vector3(0, 0, 1)
        geometry = shape.geometry
        while isinstance(geometry, pgl.Transformed):
            if isinstance(geometry, pgl.Translated):
                position = geometry.translation
            if isinstance(geometry, pgl.Oriented):
                heading = cross(geometry.primary, geometry.secondary)
            geometry = geometry.geometry
        if isinstance(geometry, pgl.Cylinder):
            for p in range(
                    int((pi * (geometry.radius**2) * geometry.height) //
                        density)):
                v = pgl.Vector3(random.rand() * 2 - 1,
                                random.rand() * 2 - 1,
                                random.rand() * 2 - 1)
                pos = position + \
                    pgl.Vector3(cross(heading, v)).normed() * (geometry.radius)
                point = pos + heading * random.rand() * geometry.height
                result.append(point)
        elif isinstance(geometry, pgl.Extrusion):
            result.append(geometry.axis)
    result = pgl.PointSet(result)
    return result
Example #2
0
def projectedBBox(bbx, direction, up):
    from itertools import product
    proj = getProjectionMatrix(direction, up)
    pts = [
        proj * pt
        for pt in product([bbx.getXMin(), bbx.getXMax()],
                          [bbx.getYMin(), bbx.getYMax()],
                          [bbx.getZMin(), bbx.getZMax()])
    ]
    projbbx = pgl.BoundingBox(pgl.PointSet(pts))
    return projbbx
Example #3
0
def lidarscan(scene, a=90, z=1):
    pgl.Viewer.display(scene)
    sc = pgl.Viewer.getCurrentScene()
    bbx = pgl.BoundingBox(sc)
    c = bbx.getCenter()
    p, h, u = pgl.Viewer.camera.getPosition()
    pts = pgl.PointSet([], [])
    for a in arange(0, 360, a):
        np = (c + pgl.Matrix3.axisRotation(
            (0, 0, 1), a) * pgl.Vector3(1, 0, 0) * pgl.norm(p - c))

        pgl.Viewer.camera.lookAt(np / z, c)
        pi, ci = pgl.Viewer.frameGL.grabZBufferPoints()
        pts.pointList += pi
        pts.colorList += ci

    return pts
Example #4
0
 def PointCloud(self, color, points, pointSize, **kwds):
     points = str(points)
     color = str(color)
     points = [float(num) for num in points.split(",")]
     colorlist = [float(num) for num in color.split(",")]
     pointSize = int(pointSize)
     if pointSize <= 0:
         pointSize = 1
     items, chunk = points, 3
     point3Array = zip(*[iter(items)] * chunk)
     idx4 = pgl.Index4(int(colorlist[0] * 255), int(colorlist[1] * 255),
                       int(colorlist[2] * 255), int(colorlist[3] * 255))
     lidx4, v3array = [], []
     for item in point3Array:
         v3array.append(Vector3(item))
         lidx4.append(idx4)
     c4array = Color4Array(lidx4)
     return (pgl.PointSet(v3array, c4array, pointSize), None)
Example #5
0
def skeleton(scene, threshold=0.01):
    result = []
    for shape in scene:
        position = pgl.Vector3(0, 0, 0)
        heading = pgl.Vector3(0, 0, 1)
        geometry = shape.geometry
        while isinstance(geometry, pgl.Transformed):
            if isinstance(geometry, pgl.Translated):
                position = geometry.translation
            if isinstance(geometry, pgl.Oriented):
                heading = cross(geometry.primary, geometry.secondary)
            geometry = geometry.geometry
        if isinstance(geometry, pgl.Cylinder) or isinstance(
                geometry, pgl.Cone):
            line = pgl.Polyline(
                [position, position + heading * geometry.height])
            splits = max(1, line.getLength() / threshold)
            for i in linspace(0, 1, splits):
                subline = line.split(i)[0]
                result.append(subline.pointList[1])
        elif isinstance(geometry, pgl.Extrusion):
            result.append(geometry.axis)
    result = pgl.PointSet(result)
    return result
Example #6
0
def topointset(obj):
    pointset = pgl.Scene(obj)[0] if isinstance(obj, str) else pgl.PointSet(obj)
    while not isinstance(pointset, pgl.PointSet):
        pointset = pointset.geometry
    return pointset
Example #7
0
def zoom(pointset, zoom):
    position = getbbx(pointset)[0]
    return pgl.PointSet((array(pointset.pointList) - position) * zoom + position)
Example #8
0
def move(pointset, position):
    return pgl.PointSet(array(pointset.pointList) - getbbx(pointset)[0] + position)