enzoruiz/3dbinpacking

Objects locate outside bin

XareniGalindo opened this issue · 0 comments

In my project, I want to pack image stacks (my packages) in a container using py3dbp. I can arrange them and know each image location inside the container I defined. After, I extract the locations of each image and try to use this information to place the "packages" in a NumPy array full of ones that is the same size as the container I defined previously. However, when I extract the image positions I notice that some of them are partially "outside" the bin, i.e if my bin is defined by:

final_image = Bin("final Image", 3300 , 3300, 17, 100000)

when I access some of the item's position and size information, I get the next

print(packer.items[514].position)
print(packer.items[514].width)
print(packer.items[514].height)
print(packer.items[514].depth)

Output: 
[Decimal('3278.000'), Decimal('264.000'), 0]
70.000
22.000
17.000

As you can see, the width of package 514 is bigger than the space left for it in the container, 70 against 22. My question is, How this can be possible? The package size corresponding to item 514 is the same as the image I want to locate. Besides, the list of unfitted objects is empty and the list of fitted objects corresponds to the total number of objects I have. The code I am using to pack the objects and locate them in the NumPy array is:

final_image2 = np.ones((17, 3300,  3300), dtype = int) 

packer = Packer()
final_image =  Bin("final Image", 3300 , 3300, 17, 100000)
packer.add_bin(final_image )

for label in unique_labels: 

    zero_padding =  np.pad(single_nuclei_dic[label], [(0, z_padding), (y_padding_2, y_padding_2), (x_padding_2, x_padding_2)],
                           mode='constant', constant_values=0)
    
    final_size_dic[label] = zero_padding.shape
    zero_padding_nuclei[label] = zero_padding.astype(int)

    my_item = Item(str(label), final_size_dic[label][2], final_size_dic[label][1], final_size_dic[label][0],  1)
    packer.add_item(my_item)
    

packer.pack(bigger_first=True, number_of_decimals=0) 

for image in packer.items: 
    
    label1= int(image.name) 

    z_incial = int(image.position[2])
    y_inicial = int(image.position[1])
    x_inicial  = int(image.position[0])
    
    items_position[label1] = [x_inicial, y_inicial, z_incial]
    
    box = zero_padding_nuclei[label1].astype(int)
    
    z_final = z_incial + box.shape[0] 
    y_final = y_inicial + box.shape[1] 
    x_final = x_inicial + box.shape[2] 
    
    final_image2[z_incial:z_final, y_inicial:y_final, x_inicial:x_final] = zero_padding_nuclei[label1]
 

Thank you for your help