Esempio n. 1
0
def saneSettings(k):
    """Sanitize sloppy settings for JavaScript output"""
    ok = {}
    try:
        ok['color'] = checkArray(k['color'], (3, ), 'f')
    except:
        try:
            c = checkInt(k['color'][0])
            print("COLOR INDEX %s" % c)
            colormap = pf.canvas.settings.colormap
            ok['color'] = colormap[c % len(colormap)]
        except:
            print("Unexpected color: %s" % k['color'])

    try:
        ok['alpha'] = checkFloat(k['alpha'], 0., 1.)
    except:
        pass
    try:
        ok['caption'] = str(k['caption'])
    except:
        pass
    try:
        ok['control'] = intersection(k['control'], controller_format.keys())
    except:
        pass
    return ok
Esempio n. 2
0
def saneSettings(k):
    """Sanitize sloppy settings for JavaScript output"""
    ok = {}
    try:
        ok['color'] = checkArray(k['color'],(3,),'f')
    except:
        try:
            c = checkInt(k['color'][0])
            print("COLOR INDEX %s" % c)
            colormap = pf.canvas.settings.colormap
            ok['color'] = colormap[c % len(colormap)]
        except:
            print("Unexpected color: %s" % k['color'])

    try:
        ok['alpha'] = checkFloat(k['alpha'],0.,1.)
    except:
        pass
    try:
        ok['caption'] = str(k['caption'])
    except:
        pass
    try:
        ok['control'] = intersection(k['control'],controller_format.keys())
    except:
        pass
    return ok
Esempio n. 3
0
    def toWorld(self,v):
        """Transform a vertex from camera to world coordinates.

        This multiplies
        The specified vector can have 3 or 4 (homogoneous) components.
        This uses the currently saved rotation matrix.
        """
        v = at.checkArray(v,(3,),'f') + [0.,0.,self.dist]
        return dot(v,transpose(self.rot[:3,:3])) + self.focus
Esempio n. 4
0
 def __new__(clas,coords=None,origin=None,axes=None):
     """Initialize the CoordinateSystem"""
     if coords is None:
         coords = np.eye(4,3)
         if axes is not None:
             coords[:3] = axes
         if origin is not None:
             coords += origin
     else:
         coords = at.checkArray(coords,(4,3),'f','i')
     coords = Coords.__new__(clas,coords)
     return coords
Esempio n. 5
0
    def focus(self,vector):
        """Set the camera reference point (the focus point).

        The focus is the point the camer is looking at. It is a point on
        the camera's optical axis.

        - `vector`: (3,) float array: the global coordinates of the focus.

        """
        if not self.locked:
            self._focus = at.checkArray(vector,(3,),'f')
            self.viewChanged = True
Esempio n. 6
0
def write_stl_bin(fn,x,color=None):
    """Write a binary stl.

    Parameters:

    - `x`: (ntri,4,3) float array describin ntri triangles.
      The first item of each triangle is the normal, the other
      three are the vertices.
    - `color`: (4,) int array with values in the range 0..255. These are
      the red, green, blue and alpha components of the color. This is a
      single color for all the triangles, and will be stored in the header
      of the STL file.
    """
    x = checkArray(x,shape=(-1,4,3),kind='f')
    if color is not None:
        color = checkArray(color,shape=(4,),kind='i').astype(np.uint8)

    def addTriangle(i):
        x[i].tofile(fil)
        fil.write('\x00\x00')

    pf.message("Writing binary STL %s" % fn)
    ver = pf.fullVersion()
    if len(ver) > 50:
        ver = ver[:50]
    if color is None:
        color = ''
    else:
        color = "COLOR=%4s" % color.tostring()
        pf.message("Adding %s to the header" % color)

    with open(fn,'wb') as fil:
        head = "%-50s%-30s" % (ver,color)
        fil.write(head)
        ntri = x.shape[0]
        pf.message("Number of triangles: %s" % ntri)
        np.array(ntri).astype(np.int32).tofile(fil)
        x = x.astype(np.float32)
        [ addTriangle(i) for i in range(ntri) ]
    pf.message("Finished writing binary STL, %s bytes" % utils.fileSize(fn))