def buildVertexAttrs(parent, array, attrspecs): # Measure the input array rows = len(array) columns = len(array[0]) basetype = basetype_numpy_codes_reverse[array.dtype.type] basetype_width = basetype_widths[basetype] row_width = columns * basetype_width #print(columns, rows, basetype, basetype_width, row_width) # Convert input to a qt buffer rawstring = array.tobytes() byte_array = QByteArray(rawstring) qbuffer = Qt3DRender.QBuffer(parent) qbuffer.setData(byte_array) attrs = list() for asp in attrspecs: attr = Qt3DRender.QAttribute(parent) attr.setName(asp.name) attr.setVertexBaseType(basetype) attr.setVertexSize(asp.numcols) attr.setAttributeType(Qt3DRender.QAttribute.VertexAttribute) attr.setBuffer(qbuffer) attr.setByteStride(row_width) attr.setByteOffset(asp.column * basetype_width) attr.setCount(rows) attrs.append(attr) return attrs
def __init__(self, vertex_data: QtCore.QByteArray, parent=None): """ Geometry for depicting a line. Used for axes placed in the origin of the instrument view. :param vertex_data: A byte array containing the coordinates for the start and end points of the line. :param parent: The object parent. """ Qt3DRender.QGeometry.__init__(self, parent) # Create a position buffer and give it the vertex data self.position_buffer = Qt3DRender.QBuffer(self) self.position_buffer.setUsage(Qt3DRender.QBuffer.StaticDraw) self.position_buffer.setData(vertex_data) # Configure a position attribute and configure it to represent a set of coordinates self.position_attribute = Qt3DRender.QAttribute(self) self.position_attribute.setAttributeType( Qt3DRender.QAttribute.VertexAttribute) self.position_attribute.setVertexBaseType(Qt3DRender.QAttribute.Float) self.position_attribute.setVertexSize(3) self.position_attribute.setName( Qt3DRender.QAttribute.defaultPositionAttributeName()) self.position_attribute.setBuffer(self.position_buffer) # Set the number of points contained in the attribute # This must be two for the start and end of the line self.position_attribute.setCount(2) self.addAttribute(self.position_attribute)
def buildIndexAttr(parent, array): basetype = basetype_numpy_codes_reverse[array.dtype.type] basetype_width = basetype_widths[basetype] basetype_width = array.itemsize rawstring = array.tobytes() byte_array = QByteArray(rawstring) qbuffer = Qt3DRender.QBuffer(parent) qbuffer.setData(byte_array) attr = Qt3DRender.QAttribute(parent) attr.setVertexBaseType(basetype) attr.setAttributeType(Qt3DRender.QAttribute.IndexAttribute) attr.setBuffer(qbuffer) attr.setCount(array.size) return attr