open3d 源码阅读octree_*.py

news2024/10/7 20:36:58

目录

1. 从点云中创建octree

2. 从体素网格中创建octree

3. 遍历octree


1. 从点云中创建octree

octree_find_leaf.py

convert_from_point_cloud

建立octree,查询点云中某个点在octree中哪个叶子节点。

# ----------------------------------------------------------------------------
# -                        Open3D: www.open3d.org                            -
# ----------------------------------------------------------------------------
# Copyright (c) 2018-2023 www.open3d.org
# SPDX-License-Identifier: MIT
# ----------------------------------------------------------------------------

import open3d as o3d
import numpy as np

if __name__ == "__main__":
    # 1. read mesh data
    N = 2000
    armadillo_data = o3d.data.ArmadilloMesh()
    pcd = o3d.io.read_triangle_mesh(
        armadillo_data.path).sample_points_poisson_disk(N)

    # 2. preprocess
    # 2.1 Fit to unit cube.
    pcd.scale(scale=1 / np.max(pcd.get_max_bound() - pcd.get_min_bound()),
              center=pcd.get_center())
    # 2.2 paint random color
    pcd.colors = o3d.utility.Vector3dVector(np.random.uniform(0, 1, size=(N, 3)))

    # 3. 建立Octree. 细分深度是4
    octree = o3d.geometry.Octree(max_depth=4)
    octree.convert_from_point_cloud(pcd, size_expand=0.01)

    # 4. view octree
    print('Displaying input octree ...')
    o3d.visualization.draw([octree])
    print('Finding leaf node containing the first point of pointcloud ...')
    print(octree.locate_leaf_node(pcd.points[0]))  # 点在哪个叶子节点
    # open3d.geometry.OctreeLeafNode, open3d.geometry.OctreeNodeInfo
    # (OctreePointColorLeafNode with color [0.315858, 0.264051, 0.780834] containing 1 points.,
    # OctreeNodeInfo with origin [-2.64148, 31.714, 2.07972], size 0.063125, depth 4, child_index 4)

view octree

2. 从体素网格中创建octree

octree_from_voxel_grid.py

create_from_voxel_grid

import open3d as o3d
import numpy as np

if __name__ == "__main__":
    # 1. read pcd
    N = 2000
    armadillo_data = o3d.data.ArmadilloMesh()
    pcd = o3d.io.read_triangle_mesh(
        armadillo_data.path).sample_points_poisson_disk(N)
    # Fit to unit cube.
    pcd.scale(1 / np.max(pcd.get_max_bound() - pcd.get_min_bound()),
              center=pcd.get_center())
    pcd.colors = o3d.utility.Vector3dVector(np.random.uniform(0, 1,
                                                              size=(N, 3)))
    # 2. create voxel grid
    print('Displaying input voxel grid ...')
    voxel_grid = o3d.geometry.VoxelGrid.create_from_point_cloud(pcd,
                                                                voxel_size=0.05)
    o3d.visualization.draw([voxel_grid])

    # 3. create octree from voxel grid
    octree = o3d.geometry.Octree(max_depth=4)
    octree.create_from_voxel_grid(voxel_grid)
    print('Displaying octree ..')
    o3d.visualization.draw([octree])

                 voxel_grid                                                                        octree                 

3. 遍历octree

octree.traverse(f=f_traverse) 
import open3d as o3d
import numpy as np


def f_traverse(node, node_info):
    early_stop = False

    # 1. 当前节点为内部节点
    if isinstance(node, o3d.geometry.OctreeInternalNode):
        # OctreeInternalNode class, containing OctreeNode children.
        if isinstance(node, o3d.geometry.OctreeInternalPointNode):
            # OctreeInternalPointNode class is an OctreeInternalNode
            # with a list of point indices (from point cloud) belonging to children of this node.
            # 1.1 计算当前内部节点的子节点个数
            n = 0
            for child in node.children:
                if child is not None:
                    n += 1
            # 1.2 打印当前内部节点node_info
            print(
                "{}{}: Internal node at depth {} has {} children and {} points ({})"
                .format('    ' * node_info.depth,
                        node_info.child_index, node_info.depth, n,
                        len(node.indices), node_info.origin))

            # We only want to process nodes / spatial regions with enough points.
            early_stop = len(node.indices) < 250  # 子节点数量小于250的,停止遍历该分支。
    # 2. 当前节点为叶子节点
    elif isinstance(node, o3d.geometry.OctreeLeafNode):
        if isinstance(node, o3d.geometry.OctreePointColorLeafNode):  # ColorLeafNode
            print("{}{}: Leaf node at depth {} has {} points with origin {}".
                  format('    ' * node_info.depth, node_info.child_index,
                         node_info.depth, len(node.indices), node_info.origin))
    else:
        raise NotImplementedError('Node type not recognized!')

    # Early stopping: if True, traversal of children of the current node will be skipped.
    return early_stop


if __name__ == "__main__":
    # 1.read pcd
    N = 2000
    armadillo_data = o3d.data.ArmadilloMesh()
    pcd = o3d.io.read_triangle_mesh(
        armadillo_data.path).sample_points_poisson_disk(N)
    # Fit to unit cube.
    pcd.scale(1 / np.max(pcd.get_max_bound() - pcd.get_min_bound()),
              center=pcd.get_center())
    pcd.colors = o3d.utility.Vector3dVector(np.random.uniform(0, 1,
                                                              size=(N, 3)))
    # 2. create octree
    octree = o3d.geometry.Octree(max_depth=4)
    octree.convert_from_point_cloud(pcd, size_expand=0.01)
    print('Displaying input octree ...')
    o3d.visualization.draw([octree])

    # 3. traversing octree
    print('Traversing octree ...')
    octree.traverse(f=f_traverse)  # f_traverse是自定义的遍历函数。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/502452.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Redis(连接池)

SpringBoor环境下使用redis连接池 依赖&#xff1a; <dependencies><dependency><groupId>com.yugabyte</groupId><artifactId>jedis</artifactId><version>2.9.0-yb-11</version></dependency><dependency><…

乘势而上,在社科大能源管理硕士项目的引领下,更上一层楼

很多人都说&#xff0c;生活的起点不重要&#xff0c;重要的是你最后抵达到哪里。进入职场的门槛后&#xff0c;我们一路过关打怪才拥有了如今的职位。在享受喜悦的同时&#xff0c;有为未来做规划吗&#xff0c;乘势而上才是明智的抉择&#xff0c;让我们在社科大能源管理硕士…

Seata 1.6.1整合SpringCloud实现分布式事务(含代码)

一、环境: seata 1.6.1spring cloud :2021.0.6spring cloud alibaba: 2021.0.4.0nacos: 2.2.1mysql: 8二、部署seata-server 2.1 启动nacos 这里不再赘述 2.2 下载seata-server 下载地址:https://seata.io/zh-cn/blog/download.html 下载后解压,即为seata-server端,提…

摄影测量-笔记(理解篇)

1、基本原理 基于测量中的前方交会原理。 在两个已知点上分别拍摄一张影像&#xff0c;通过人眼观测&#xff08;一只眼睛观察一张影像上的同名点a1和a2&#xff09;&#xff0c;就能得出空间对应点A的坐标。空间景物通过传感器构像&#xff0c;再用人眼观察构像的像片产生生…

GPT 学术优化版使用指南 -- GPT Academic

目录 1. 项目介绍 1.1 简介 1.2 功能说明 2. 环境配置 2.1 本地安装

STL-String容器

string本质上是一个类&#xff0c;string 类内部封装了很多成员方法 例如&#xff1a;查找find&#xff0c;拷贝copy&#xff0c;删除delete 替换replace&#xff0c;插入insert string管理char*所分配的内存&#xff0c;不用担心复制越界和取值越界等&#xff0c;由类内部进…

C++容器适配器stack和queue(含deque,priority_queue)

目录 1.容器适配器 1.1 什么是适配器 1.2 STL标准库中stack和queue底层结构 1.3 deque 1.3.1 deque原理介绍&#xff08;了解&#xff09; 1.3.2 deque优点和缺点 1.3.3 为什么选择deque作为stack和queue的底层默认容器 2. stack介绍和使用 2.1 stack介绍 2.2 stack使用 2.3 …

HTML处理控件Aspose.Html 功能演示:在 C# 中将 HTML 转换为 JPG

Aspose.Html for .NET 是一种高级的HTML操作API&#xff0c;可让您直接在.NET应用程序中执行广泛的HTML操作任务&#xff0c;Aspose.Html for .NET允许创建&#xff0c;加载&#xff0c;编辑或转换&#xff08;X&#xff09;HTML文档&#xff0c;而无需额外的软件或工具。API还…

swing基本组件用法_JTooBar

Swing提供了JTooBar类来创建工具条&#xff0c;并且可以往JTooBar中添加多个工具按钮 JToolBar API: 方法名称方法功能JToolBar(String name,int orientation)创建一个名为name&#xff0c;方向为orientation的工具条对象&#xff0c;其orientation的是取值可以是SwingConsta…

MySQL基础(九)子查询

子查询指一个查询语句嵌套在另一个查询语句内部的查询&#xff0c;这个特性从MySQL 4.1开始引入。 SQL 中子查询的使用大大增强了 SELECT 查询的能力&#xff0c;因为很多时候查询需要从结果集中获取数据&#xff0c;或者需要从同一个表中先计算得出一个数据结果&#xff0c;然…

单调队列解决滑动窗口问题

文章目录 单调队列结构解决滑动窗口问题什么是单调队列&#xff1f;[239. 滑动窗口最大值](https://leetcode.cn/problems/sliding-window-maximum/)单调队列框架滑动窗口解题框架完整的解题代码如下&#xff1a;我的实现&#xff1a; 单调队列结构解决滑动窗口问题 什么是单调…

CVE-2023-27524 Apache Superset Auth Bypass|附检测工具

漏洞描述 Apache Superset是一个开源数据可视化和探索工具。Apache Superset 版本&#xff08;包括 2.0.1&#xff09;中的会话验证攻击。没有根据安装说明更改默认配置的SECRET_KEY的安装允许攻击者验证和访问未经授权的资源。这不会影响更改了SECRET_KEY配置默认值的Superse…

JAVA快速开发框架 一键生成表单模板代码

从计算机诞生开始&#xff0c;虽然编程的形式随着硬件及软件的不断进步而不停迭代&#xff0c;但是从事计算机技术行业的人员始终与编写代码的任务紧密联系在一起。因此如何提高软件开发的效率和质量&#xff0c;一直是软件工程领域的重要问题之一。 这一方面是由于在不同软件…

MQ(面试问题简析)学习笔记

文章目录 1. 为什么使用消息队列2. 消息队列有什么优缺点3. Kafka、ActiveMQ、RabbitMQ、RocketMQ 有什么优缺点&#xff1f;4. 如何保证消息队列的高可用4.1 RabbitMQ 的高可用性4.2 Kafka 的高可用性 5. 如何保证消息不被重复消费&#xff08;如何保证消息消费的幂等性&#…

1、Cloudsim和Workflowsim仿真环境下载

1、WorkflowSim的下载和安装 workflowsim下载地址 2、Cloudsim的下载和安装 cloudsim官网 cloudsim4.0安装包地址 2、Cloudsim如何工作 Cloudsim如何工作&#xff1f;原版内容 cloudsim配置 下面这是CloudsimExamples1的代码&#xff1a; package org.cloudbus.…

论文导读 | 大语言模型上的精调策略

随着预训练语言模型规模的快速增长&#xff0c;在下游任务上精调模型的成本也随之快速增加。这种成本主要体现在两方面上&#xff1a;一&#xff0c;计算开销。以大语言模型作为基座&#xff0c;精调的显存占用和时间成本都成倍增加。随着模型规模扩大到10B以上&#xff0c;几乎…

SpringBoot启用web模拟测试(一)

添加依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>2.5.10</version> </dependency> 模拟端口 虚拟请求测试 Slf4j RestController RequestMappin…

java后端面试大全,java后端面试宝典

JAVA_LEARNING_CONTENT JAVA后端面试大全&#xff0c;java后端面试宝典 一个分布式锁的解决方案&#xff0c;另一个是分布式事务的解决方案 -2 flink 链接&#xff1a;flink参考文章 -1 linux of view 参考链接&#xff1a; linux常见面试题 linux查看占用cup最高的10个进…

机电设备故障ar远程维修软件缩短生产线中断时间

电机属于工业生产中的关键设备之一&#xff0c;处于长期运转阶段&#xff0c;因此电机容易出现故障&#xff0c;极易增加企业生产成本&#xff0c;影响生产计划。引进AR远程维修技术效果显著。 AR远程维修技术是一种将虚拟信息与实际场景相结合的技术。当电机出现故障时&#x…