CadQuery / cadquery

A python parametric CAD scripting framework based on OCCT
https://cadquery.readthedocs.io
Other
2.96k stars 280 forks source link

Turning DLP-SLA printer pixels into 3D step file. #1093

Open RyanABahr opened 2 years ago

RyanABahr commented 2 years ago
full3D = cq.Assembly(name='stackup')
  for layer_idx, layer in enumerate(data['Layers']):
    pts =[] # initialize the points. 
    for row_idx, row in enumerate(bmpArray): # iterate through rows
        for col_idx, column in enumerate(bmpArray[0]): # iterate through columns
            if bmpArray[row_idx][col_idx] > 0: # Checks if there is a 'white' pixel.
                pts.append((row_idx*pixel_x,col_idx*pixel_y)) # append these points

    result = cq.Workplane(cq.Plane((0,0,height))).pushPoints(pts).box(pixel_x, pixel_y, thickness) # convert these points to rectangles centered at those points.
    full3D.add(result,name=("layer"+str(layer_idx)),color=cq.Color("orange"))
full3D.save('test.step')

I'm trying to convert bitmaps (arrays of 0,1 denoting presence of 35um x 35um x 20um voxel) into 3D step file to have a representation of what a model looks like after slicing. Is there are recommended method for improving the speed? This can take an hour by the time it gets to the second layer on an 800x800 landscape that has 100 cylinders of 6 pixel radius. I believe if I use a separate algorithm to convert the boundaries of pixel bodies into a polyline, it may speed things up rather than pixel by pixel, but I fear this may not solve the problem. I believe I am doing something inherently wrong with cadquery.

jmwright commented 2 years ago

Doing that many voxels will probably always be slow with CadQuery, but there may be ways to improve the performance. Here is a similar discussion that might provide some ideas. Specific comments that might help are this one and this one. There is also another similar issue referenced.

One option (discussed in the linked issue) might be to draw the voxels as 2D rects and then extrude them at the end. In that scenario you would not use an assembly, but you can still export solids to STEP.

adam-urbanczyk commented 2 years ago

Not a use case of CQ. You could try using combine=False in the box call.