Пример #1
0
    def get_cantorLawnVolumeImage(self,
                                  epsilon: float,
                                  imgProvider: Image = None) -> Image:
        """ Call this method to get a PIL.Image of the inner tubular neighborhood of the volume at epsilon. """
        cString_X = self._cantorSet_X.get_cantorString()
        cString_Y = self._cantorSet_Y.get_cantorString()

        cString_Eps_X = self._cantorSet_X.get_epsilonNeighborhoodLevel(epsilon)
        cString_Eps_Y = self._cantorSet_Y.get_epsilonNeighborhoodLevel(epsilon)

        img = imgProvider
        if img == None:
            img = self.get_cantorLawnImage()
        pixels = img.load()  # Create the pixel map

        #color in the heights blue
        for y in range(self.resolution[ResolutionType.Height]):
            if BinarySearch(cString_Y, y) != -1:
                for x in range(self.resolution[ResolutionType.Width]):
                    if BinarySearch(cString_Eps_X, x) != -1:
                        pixels[x, y] = (0, 0, 255)

        #color in the lengths red
        for y in range(self.resolution[ResolutionType.Height]):
            if BinarySearch(cString_Eps_Y, y) != -1:
                for x in range(self.resolution[ResolutionType.Width]):
                    if BinarySearch(cString_X, x) != -1:
                        #add red to shade the squares counted twice deaper
                        p = pixels[x, y]
                        pixels[x, y] = (255, 0, p[2])

        return img
Пример #2
0
    def get_cantorLawnVolumeImageJustVolume(self, epsilon: float) -> Image:
        cString_X = self._cantorSet_X.get_cantorString()
        cString_Y = self._cantorSet_Y.get_cantorString()

        cString_Eps_X = self._cantorSet_X.get_epsilonNeighborhoodLevel(epsilon)
        cString_Eps_Y = self._cantorSet_Y.get_epsilonNeighborhoodLevel(epsilon)

        img = Image.new('RGB', self.resolution, (255, 255, 255))
        pixels = img.load()  # Create the pixel map

        #color in the heights blue
        for y in range(self.resolution[ResolutionType.Height]):
            if BinarySearch(cString_Y, y) != -1:
                for x in range(self.resolution[ResolutionType.Width]):
                    if BinarySearch(cString_Eps_X, x) != -1:
                        pixels[x, y] = (0, 0, 255)

        #color in the lengths red
        for y in range(self.resolution[ResolutionType.Height]):
            if BinarySearch(cString_Eps_Y, y) != -1:
                for x in range(self.resolution[ResolutionType.Width]):
                    if BinarySearch(cString_X, x) != -1:
                        p = pixels[x, y]
                        if p == (0, 0, 255):
                            pixels[x, y] = (255, 0, 255)
                        else:
                            pixels[x, y] = (255, 0, 0)

        return img
Пример #3
0
    def _get_bitMap(self, string_X: list, string_Y: list):
        """ This method should not be called. """

        bitMap = []
        for y in range(self.resolution[ResolutionType.Height]):
            if BinarySearch(string_Y, y) != -1:
                bitMap.append([])
                for x in range(self.resolution[ResolutionType.Width]):
                    #draw black if in the cantor string, otherwise draw white
                    bitMap[y].append(
                        0 if BinarySearch(string_X, x) != -1 else 1)
            else:
                bitMap.append(
                    [1 for x in range(self.resolution[ResolutionType.Width])]
                )  #draw white for the entire row if y is not in the y cantor string

        return bitMap
Пример #4
0
 def _get_compliment(self) :
     """ This method should not be called. """
     num_string = range(self._interval[0], self._interval[1] + 1)
     out_string = []
     for x in num_string :
         if BinarySearch(self._set, x) == -1 :
             out_string.append(x)
     return out_string
Пример #5
0
    def _get_bitMap(self, string_Z: list, cantorLawn_XY: CantorLawn):
        """ This method should not be called. """

        bitMap = []

        for z in range(self.resolution[ResolutionType.Depth]):
            if BinarySearch(string_Z, z) != -1:
                #append a cantor lawn to the current z value
                bitMap.append(cantorLawn_XY.get_cantorLawn())
            else:
                #append a 2d map of 1s
                bitMap.append(
                    [1 for x in range(self.resolution[ResolutionType.Width])]
                    for y in range(self.resolution[ResolutionType.Height]))

        return bitMap
Пример #6
0
    def _get_cantorStringBitMap(self, resolution : tuple, rowRange : tuple) -> list :
        """ This method should not be called. """
        cString = self.get_cantorString() #cache value for the process

        pixels = []
        for y in range(resolution[ResolutionType.Height]):    # For every pixel:
            pixels.append([])
            for x in range(resolution[ResolutionType.Width]):
                if y >= rowRange[0] and y <= rowRange[1] :
                    #draw black if in the cantor string, otherwise draw white
                    pixels[y].append(0 if BinarySearch(cString, x) != -1 else 1)
                else:
                    #draw white inbetween tiers
                    pixels[y].append(1)
        
        return pixels
Пример #7
0
    def get_cantorStringVolumeImage(self, resolution : tuple, rowRange : tuple, epsilon : float,  imgProvider : Image = None) -> Image :
        """ Call this method to save the volume of the current model. Resolution and rowRange will dictate how the 1D image
            is mapped onto a 2D plane, epsilon dictates the inner tubular neighborhood used for the volume.
        """
        cString_eps = self._get_epsilonNeighborhoodLevelString(self._cantorSet.inner_set(), epsilon)

        img = imgProvider
        if img == None : 
            img = self.get_cantorStringImage(resolution, rowRange)
        pixels = img.load() # Create the pixel map

        #color in the volume red
        for y in range(resolution[ResolutionType.Height]) :
            if y >= rowRange[0] and y <= rowRange[1] :
                for x in range(resolution[ResolutionType.Width]) :
                    if BinarySearch(cString_eps, x) != -1 :
                        pixels[x,y] = (255,0,0)
        
        return img
Пример #8
0
import os, sys, time

app_path = os.path.dirname(os.path.realpath('cantorSetTestBench.py'))
sys.path.append(os.path.join(app_path, 'src'))

from Util import BinarySearch
from CantorSet import CantorSet

cSet = CantorSet((0, 2560), 6)
cString = cSet.get_cantorString()

print("Start loop")
start = time.time()

for y in range(1440):
    for x in range(2560):
        if BinarySearch(cString, x) != -1:
            z = 1

finish = time.time()
print("Time: ", finish - start)