open3d绘制箭头

        在使用open3d的过程中,我需要将提取到的目标用箭头表示出来。箭头的起始点代表目标的位置,箭头的方向代表目标表面的法向量。但open3d中并没有直接可以调用的api。

        在open3d的示例中,可以找到通过mesh生成坐标轴的代码,所以,我们对这个代码稍加修改,对坐标轴的mesh进行平移、旋转、缩放,就可以得到任意位置的箭头了。这里的代码是我在网络上搜索到的,但原始代码存在一些bug,箭头的尺度有一些问题,修复了问题的代码如下:

import numpy as np
import open3d as o3d


def get_cross_prod_mat(pVec_Arr):
    # pVec_Arr shape (3)
    qCross_prod_mat = np.array([
        [0, -pVec_Arr[2], pVec_Arr[1]],
        [pVec_Arr[2], 0, -pVec_Arr[0]],
        [-pVec_Arr[1], pVec_Arr[0], 0],
    ])
    return qCross_prod_mat


def caculate_align_mat(pVec_Arr):
    scale = np.linalg.norm(pVec_Arr)
    pVec_Arr = pVec_Arr / scale
    # must ensure pVec_Arr is also a unit vec.
    z_unit_Arr = np.array([0, 0, 1])
    z_mat = get_cross_prod_mat(z_unit_Arr)

    z_c_vec = np.matmul(z_mat, pVec_Arr)
    z_c_vec_mat = get_cross_prod_mat(z_c_vec)

    if np.dot(z_unit_Arr, pVec_Arr) == -1:
        qTrans_Mat = -np.eye(3, 3)
    elif np.dot(z_unit_Arr, pVec_Arr) == 1:
        qTrans_Mat = np.eye(3, 3)
    else:
        qTrans_Mat = np.eye(3, 3) + z_c_vec_mat + np.matmul(z_c_vec_mat,
                                                            z_c_vec_mat) / (1 + np.dot(z_unit_Arr, pVec_Arr))

    qTrans_Mat *= scale
    return qTrans_Mat

def get_arrow(begin=[0,0,0],vec=[0,0,1]):
    z_unit_Arr = np.array([0, 0, 1])
    begin = begin
    end = np.add(begin,vec)
    vec_Arr = np.array(end) - np.array(begin)
    vec_len = np.linalg.norm(vec_Arr)

    mesh_frame = o3d.geometry.TriangleMesh.create_coordinate_frame(size=60, origin=[0, 0, 0])

    mesh_arrow = o3d.geometry.TriangleMesh.create_arrow(
        cone_height=0.2 * 1 ,
        cone_radius=0.06 * 1,
        cylinder_height=0.8 * 1,
        cylinder_radius=0.04 * 1
    )
    mesh_arrow.paint_uniform_color([0, 1, 0])
    mesh_arrow.compute_vertex_normals()

    mesh_sphere_begin = o3d.geometry.TriangleMesh.create_sphere(radius=10, resolution=20)
    mesh_sphere_begin.translate(begin)
    mesh_sphere_begin.paint_uniform_color([0, 1, 1])
    mesh_sphere_begin.compute_vertex_normals()

    mesh_sphere_end = o3d.geometry.TriangleMesh.create_sphere(radius=10, resolution=20)
    mesh_sphere_end.translate(end)
    mesh_sphere_end.paint_uniform_color([0, 1, 1])
    mesh_sphere_end.compute_vertex_normals()


    rot_mat = caculate_align_mat(vec_Arr)
    mesh_arrow.rotate(rot_mat, center=np.array([0, 0, 0]))
    mesh_arrow.translate(np.array(begin))  # 0.5*(np.array(end) - np.array(begin))
    return mesh_frame, mesh_arrow, mesh_sphere_begin, mesh_sphere_end



if __name__ == "__main__":
    mesh_frame, mesh_arrow, mesh_sphere_begin, mesh_sphere_end = get_arrow([0,0,0],[0,0,-100])
    o3d.visualization.draw_geometries(
        geometry_list=[mesh_frame, mesh_arrow, mesh_sphere_begin, mesh_sphere_end],
        window_name="after translate", width=800, height=600
    )

  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 您好,您可以通过设置QComboBox的属性来隐藏箭头。具体方法是:在Qt Creator中打开ui文件,选中QComboBox,然后在右侧属性栏中找到"frame"属性,将其设置为false即可。如果您是在代码中创建QComboBox,可以使用setFrame(false)函数来实现。希望能对您有所帮助。 ### 回答2: Qt中的ComboBox默认是带有下拉箭头的,如果希望去除箭头,可以通过以下几种方法实现: 1. 修改样式表:可以通过设置ComboBox的样式表来隐藏箭头。例如: ```c++ ui->comboBox->setStyleSheet("QComboBox::drop-down {image: none;}"); ``` 这样就可以去除ComboBox的箭头图标。 2. 自定义ComboBox的外观:可以通过继承QComboBox类并重写paintEvent方法来绘制自定义的ComboBox外观,不包含箭头。例如: ```c++ class CustomComboBox : public QComboBox { protected: void paintEvent(QPaintEvent *event) override { // 在这里绘制自定义的ComboBox外观 } }; ``` 然后使用CustomComboBox来替代原先的QComboBox实例。 3. 使用QLineEdit替代:如果只需要一个下拉列表,而不需要文本框,可以使用QLineEdit和QCompleter来实现。例如: ```c++ QLineEdit *lineEdit = new QLineEdit(); QCompleter *completer = new QCompleter(QStringList() << "Item 1" << "Item 2" << "Item 3"); completer->setCompletionMode(QCompleter::PopupCompletion); lineEdit->setCompleter(completer); ``` 这样就可以实现一个没有箭头的下拉自动完成列表效果。 总之,以上是几种常用的方法来去除Qt中ComboBox的箭头。具体选择哪种方法,可以根据实际需求和个人偏好来决定。 ### 回答3: 要想在Qt代码中去除ComboBox的箭头,可以使用QSS(Qt Style Sheets)来修改ComboBox的样式。下面是一个实现方法: 1. 在Qt代码中,给ComboBox控件设置一个特定的ObjectName,例如: ```cpp QComboBox *comboBox = new QComboBox(); comboBox->setObjectName("myComboBox"); ``` 2. 在QSS文件中,使用ObjectName选择器找到这个ComboBox并修改其样式,去除箭头。例如: ```css QComboBox#myComboBox QAbstractItemView { combobox-popup: 0; /* 去除箭头 */ } ``` 上述QSS代码中,`QComboBox#myComboBox`表示选择ObjectName为"myComboBox"的ComboBox,`QAbstractItemView`表示ComboBox的下拉列表视图部分。 3. 在Qt代码中,将QSS文件应用到ComboBox控件上,例如: ```cpp QFile styleSheetFile(":/stylesheets/myStylesheet.qss"); // 根据实际情况选择QSS文件路径 styleSheetFile.open(QFile::ReadOnly); QString styleSheet = QLatin1String(styleSheetFile.readAll()); comboBox->setStyleSheet(styleSheet); ``` 上述代码中,`:/stylesheets/myStylesheet.qss`为QSS文件的路径。 通过上述步骤,可以通过给ComboBox设置特定的ObjectName并使用QSS来去除ComboBox的箭头样式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值