Exemplo n.º 1
0
def write_stl_asc(fn,x):
    """Write a collection of triangles to an ascii .stl file.

    Parameters:

    - `fn`: file name, by preference ending with '.stl' or '.stla'
    - `x`: (ntriangles,3,3) shaped array with the vertices of the
      triangles
    """
    if not x.shape[1:] == (4,3):
        raise ValueError,"Expected an (ntri,4,3) array, got %s" % x.shape

    pf.message("Writing ascii STL %s" % fn)
    with open(fn,'wb') as fil:

        fil.write("solid  Created by %s\n" % pf.fullVersion())
        for e in x:
            fil.write("  facet normal %s %s %s\n" % tuple(e[0]))
            fil.write("    outer loop\n")
            for p in e[1:]:
                fil.write("      vertex %s %s %s\n" % tuple(p))
            fil.write("    endloop\n")
            fil.write("  endfacet\n")
        fil.write("endsolid\n")
    pf.message("Finished writing ascii STL, %s bytes" % utils.fileSize(fn))
Exemplo n.º 2
0
    def upload(self, bucket):

        self.lastUpload = 0
        headers = {'Cache-Control': 'max-age=%s' % self.CACHE_EXPIRATION}

        if self.shouldCompress():
            headers['Content-Encoding'] = 'gzip'

        changed = self.checksum() != self.remoteChecksum()

        if changed:

            # Show progress if the file size is big
            progressCallback = None
            progressCallbackCount = int(len(self.payload()) / (1024 * 1024))

            if len(self.payload()) > self.PROGRESS_MIN_SIZE:
                def progressCallback(current, total):
                    if current > self.lastUpload:
                        uploadPercentage = (float(current) / float(total)) * 100
                        print('+ %s upload progress %.1f%%' % (self.path, uploadPercentage))
                        self.lastUpload = current

            # Create a new key from the file path and guess the mime type
            key = bucket.new_key(self.path)
            mimeType = mime.guess(self.path)

            if mimeType:
                key.content_type = mimeType

            # Upload the data
            key.set_contents_from_string(self.payload(), headers,
                policy='public-read',
                cb=progressCallback,
                num_cb=progressCallbackCount)

        op1 = '+' if changed else '-'
        op2 = ' (%s compressed)' % (fileSize(len(self.payload()))) if self.shouldCompress() else ''

        print('%s %s - %s%s' % (op1, self.path, fileSize(len(self.data())), op2))

        return {'changed': changed, 'size': len(self.payload())}
Exemplo n.º 3
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))
Exemplo n.º 4
0
        self.config.set('aws-bucket-website', awsBucket.get_website_endpoint())
        self.config.write()

        logging.info('Uploading site to bucket %s' % awsBucketName)

        # Upload all files concurrently in a thread pool
        totalFiles = multiMap(lambda p: p.upload(awsBucket), self.files())
        changedFiles = [r for r in totalFiles if r['changed'] == True]


        # Display done message and some statistics
        logging.info('\nDone\n')

        logging.info('%s total files with a size of %s' % \
            (len(totalFiles), fileSize(sum([r['size'] for r in totalFiles]))))
        logging.info('%s changed files with a size of %s' % \
            (len(changedFiles), fileSize(sum([r['size'] for r in changedFiles]))))

        logging.info('\nhttp://%s\n' % self.config.get('aws-bucket-website'))


    def files(self):
        """
        List of build files.
        """
        return [File(self, p) for p in fileList(self.paths['build'], relative=True)]