Библиотеки для преобразования dxf в рисунок

Есть dxf файл состоящий в основном из сплайнов, какие Python библиотеки лучше всего использовать для преобразования его в рисунок png? Я сделал для типов arc и line с помощью opencv, но не знаю есть ли возможность в нем нарисовать spline.

import dxfgrabber as dxf
import numpy as np
import cv2

LINE_SIZE = 1

def getMinXY(shapes):
    minX, minY = 99999, 99999
    for shape in shapes:
        if shape.dxftype == 'LINE':
            minX = min(minX, shape.start[0], shape.end[0])
            minY = min(minY, shape.start[1], shape.end[1])
        elif shape.dxftype == 'ARC':
            minX = min(minX, shape.center[0])
            minY = min(minY, shape.center[1])

    return minX, minY

def getMaxXY(shapes):
    maxX, maxY = -99999, -99999
    for shape in shapes:
        if shape.dxftype == 'LINE':
            maxX = max(maxX, shape.start[0], shape.end[0])
            maxY = max(maxY, shape.start[1], shape.end[1])
        elif shape.dxftype == 'ARC':
            maxX = max(maxX, shape.center[0])
            maxY = max(maxY, shape.center[1])

    return maxX, maxY

def getXY(point):
    x, y = point[0], point[1]
    return int(x-minX), int(abs(y-maxY))


dwg = dxf.readfile("zadanie.dxf")
print (dwg)

shapes = dwg.entities.get_entities()

minX, minY = getMinXY(shapes)
maxX, maxY = getMaxXY(shapes)


canvas = np.zeros((int(maxY),int(maxX)), np.uint8)
polynom = []


for shape in shapes:
    print(shape.dxftype)
    if shape.dxftype == 'LINE':
        x1, y1 = getXY(shape.start)
        x2, y2 = getXY(shape.end)
        canvas = cv2.line(canvas, (int(x1),int(y1)), (int(x2),int(y2)), 255, LINE_SIZE)

    elif shape.dxftype == 'SPLINE':
        print(shape.degree)

    elif shape.dxftype == 'ARC':
        centerX, centerY = getXY(shape.center)        
        if (shape.start_angle > 180) and (shape.end_angle < shape.start_angle):
            canvas = cv2.ellipse(canvas, (centerX, centerY), (int(shape.radius), int(shape.radius)), 180, int(shape.start_angle) - 180, 180 + int(shape.end_angle), 255, LINE_SIZE)
        else:
            canvas = cv2.ellipse(canvas, (centerX, centerY), (int(shape.radius), int(shape.radius)), 0, int(360 - shape.start_angle), int(360 - shape.end_angle), 255, LINE_SIZE)


minX, minY = getMinXY(shapes)
maxX, maxY = getMaxXY(shapes)

template_width = [maxX-minX,maxY-minY]
print(template_width)

cv2.imwrite('obr1.png', canvas)

Ответы (0 шт):