Example #1
0
    def contour(self, bit_diameter, count=1, overlap=0.5):
        """ @brief Finds a set of isolines on a distance field image.
            @param bit_diameter Tool diameter (in mm)
            @param count Number of offsets
            @param overlap Overlap between offsets
            @returns A list of Paths
        """
        if self.depth != 'f' or self.channels != 1:
            raise ValueError('Invalid image type for contour cut '+
                '(requires floating-point, 1-channel image)')

        max_distance = max(self.array.flatten())
        levels = [bit_diameter/2]
        step = bit_diameter * overlap
        if count == -1:
            while levels[-1] < max_distance:
                levels.append(levels[-1] + step)
            levels[-1] = max_distance
        else:
            for i in range(count-1):
                levels.append(levels[-1] + step)
        levels = (ctypes.c_float*len(levels))(*levels)

        ptr = ctypes.POINTER(ctypes.POINTER(Path_))()
        path_count = libfab.find_paths(
            self.width, self.height, self.pixels,
            1./self.pixels_per_mm, len(levels),
            levels, ptr)

        paths = [Path.from_ptr(ptr[i]) for i in range(path_count)]
        libfab.free_paths(ptr, path_count)

        return Path.sort(paths)
Example #2
0
    def finish_cut(self, bit_diameter, overlap, bit_type):
        ''' Calculates xy and yz finish cuts on a 16-bit heightmap
        '''

        if self.depth != 16 or self.channels != 1:
            raise ValueError('Invalid image type for finish cut ' +
                             '(requires 16-bit, 1-channel image)')

        ptr = ctypes.POINTER(ctypes.POINTER(Path_))()
        path_count = libfab.finish_cut(self.width, self.height, self.pixels,
                                       self.mm_per_pixel, self.mm_per_bit,
                                       bit_diameter, overlap, bit_type, ptr)

        paths = [Path.from_ptr(ptr[i]) for i in range(path_count)]
        libfab.free_paths(ptr, path_count)

        return paths
Example #3
0
    def finish_cut(self, bit_diameter, overlap, bit_type):
        ''' Calculates xy and yz finish cuts on a 16-bit heightmap
        '''

        if self.depth != 16 or self.channels != 1:
            raise ValueError('Invalid image type for finish cut '+
                '(requires 16-bit, 1-channel image)')

        ptr = ctypes.POINTER(ctypes.POINTER(Path_))()
        path_count = libfab.finish_cut(
            self.width, self.height, self.pixels,
            self.mm_per_pixel, self.mm_per_bit,
            bit_diameter, overlap, bit_type, ptr)

        paths = [Path.from_ptr(ptr[i]) for i in range(path_count)]
        libfab.free_paths(ptr, path_count)

        return paths