jerry800416 / 3D-bin-packing

3D Bin Packing improvements based on https://github.com/enzoruiz/3dbinpacking
MIT License
158 stars 44 forks source link

Cannot write anything on cubes. #9

Closed ShockKissXtreme closed 1 year ago

ShockKissXtreme commented 2 years ago

Cannot write anything on cubes. I tried to add text like ,colors or box(Because operator cannot understand which box is which) no, on box. box cannot see them. have you got an idea? when i create box on my codes, it works, i modified your Painter Class, please help.

you can see "li" on left. image

but it should shown like this :

image

Summary is:

` xz_sizes = np.array(boyutlar)

    xz_sizes[:,1] = 0

    print(xz_sizes)
    label_pos = (np.array(pozisyon) + xz_sizes/2 ).tolist()
    labels = ["limegreen","blue","1","1","1","1","1","1","1"]

    # labels = ['12', '24']
    for pos, label in zip(label_pos, labels):
        axGlob.text( *pos, label, 'x', ha='center', va='center') 
        counter2 += 2
        if counter2 == 100:
            break ```

`

`
def init(self,bins): self.items = bins.items self.width = bins.width self.height = bins.height self.depth = bins.depth

def _plotCube(self, ax, x, y, z, dx, dy, dz, color='red',mode=2):

stoppause = 5

""" Auxiliary function to plot a cube. code taken somewhere from the web.  """
xx = [x, x, x+dx, x+dx, x]
yy = [y, y+dy, y+dy, y, y]

kwargs = {'alpha': 1, 'color': color,'linewidth':1 }
if mode == 1 :
    ax.plot3D(xx, yy, [z]*5, **kwargs)
    ax.plot3D(xx, yy, [z+dz]*5, **kwargs)
    ax.plot3D([x, x], [y, y], [z, z+dz], **kwargs)
    ax.plot3D([x, x], [y+dy, y+dy], [z, z+dz], **kwargs)
    ax.plot3D([x+dx, x+dx], [y+dy, y+dy], [z, z+dz], **kwargs)
    ax.plot3D([x+dx, x+dx], [y, y], [z, z+dz], **kwargs)
else :
    text='sadsadas'
    p = Rectangle((x,y),dx,dy,fc=color,ec='black')

    p2 = Rectangle((x,y),dx,dy,fc=color,ec='black',label = 'adad')
    p3 = Rectangle((y,z),dy,dz,fc=color,ec='black')
    p4 = Rectangle((y,z),dy,dz,fc=color,ec='black')
    p5 = Rectangle((x,z),dx,dz,fc=color,ec='black')
    p6 = Rectangle((x,z),dx,dz,fc=color,ec='black')
    ax.add_patch(p)
   # ax.annotate(text, (x+dx/2,y))
    ax.add_patch(p2)
   # ax.annotate(text, (x+dx/2,y))
    ax.add_patch(p3)
    ax.add_patch(p4)
    ax.add_patch(p5)
    ax.add_patch(p6)
   # ax.text(x+dx, y+dy/2, z, "red", color='red',rotation_mode= None,verticalalignment = 'top',animated = 'b')
    # ax.text
    ax.annotate(text, (x,y))
    art3d.pathpatch_2d_to_3d(p, z=z, zdir="z")
    # art3d.text(x+0.8,y+0.8,z+0.8, 'label', zdir="x")
    art3d.pathpatch_2d_to_3d(p2, z=z+dz, zdir="z")
    art3d.pathpatch_2d_to_3d(p3, z=x, zdir="x")
    art3d.pathpatch_2d_to_3d(p4, z=x + dx, zdir="x")
    art3d.pathpatch_2d_to_3d(p5, z=y, zdir="y")
    art3d.pathpatch_2d_to_3d(p6, z=y + dy, zdir="y")

def plotBoxAndItems(self,title=""): counter2 = 0 with open('boyutlar.csv', newline='') as f: reader = csv.reader(f) boyutlar = list(reader)

boyutlar = [e for e in boyutlar if e]

# boyutlar = [[float(value) for value in sublist] for sublist in boyutlar]      
boyutlar = [list(map(float, y)) for y in boyutlar]         

with open('pozisyon.csv', newline='') as f:
    reader2 = csv.reader(f)
    pozisyon = list(reader2)
pozisyon = [e for e in pozisyon if e]
# print(pozisyon)

# pozisyon = [[float(value) for value in sublist] for sublist in pozisyon]   
pozisyon = [[float(value) for value in sublist] for sublist in pozisyon]
print(pozisyon)

""" side effective. Plot the Bin and the items it contains. """
fig = plt.figure()
axGlob = plt.axes(projection='3d')
stoppause = 1
counter=0
# fit rotation type
for item in self.items:
    rt = item.rotation_type  
    x,y,z = item.position
    [w,h,d] = item.getDimension()
    color = item.color
    # countt=countt+1
    if item.typeof == 'cube':
         # plot item of cube
        self._plotCube(axGlob, float(x), float(y), float(z), float(w),float(h),float(d),color=color,mode=2)
    elif item.typeof == 'cylinder':
        # plot item of cylinder
        self._plotCylinder(axGlob, float(x), float(y), float(z), float(w),float(h),float(d),color=color,mode=2)

    counter = counter + 1 
    if counter == stoppause:
        break
# plot bin 
self._plotCube(axGlob,0, 0, 0, float(self.width), float(self.height), float(self.depth),color='black',mode=1)

plt.title('result')
self.setAxesEqual(axGlob)
xz_sizes = np.array(boyutlar)

xz_sizes[:,1] = 0

print(xz_sizes)
label_pos = (np.array(pozisyon) + xz_sizes/2 ).tolist()
labels = ["limegreen","blue","1","1","1","1","1","1","1"]

# labels = ['12', '24']
for pos, label in zip(label_pos, labels):
    axGlob.text( *pos, label, 'x', ha='center', va='center') 
    counter2 += 1
    if counter2 == 1:
        break

plt.show()`
jerry800416 commented 1 year ago

Hi @ShockKissXtreme , I fixed this issue in the latest version, please refer to the Readme. I wrote the numbers inside the cube, and adjusted alpha =0.2, and finally achieved the following effect.

11

jerry800416 commented 1 year ago

This issue has been resolved, please reopen if you have other questions.