从 polydata 中获取数组 及 vtkDoubleArray、vtkIntArray互转

2024-02-07 01:20

本文主要是介绍从 polydata 中获取数组 及 vtkDoubleArray、vtkIntArray互转,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!


开发环境:

  1. Windows 11 家庭中文版
  2. Microsoft Visual Studio Community 2019
  3. VTK-9.3.0.rc0
  4. vtk-example

demo解决问题:示范冲polydata中获取命名数组,并转换数组数据类型

关键点:

  1. 从 polydata 中获取数组,我们必须使用 SafeDownCast 转换为我们想要的类型。
  // Get the distances from the polydata.vtkDoubleArray* array = dynamic_cast<vtkDoubleArray*>(polydata->GetPointData()->GetArray("Distances"));
  1. vtkDoubleArray->vtkIntArray
 // Cast the double distances to ints.vtkDoubleArray* doubleDistances = dynamic_cast<vtkDoubleArray*>(polydata->GetPointData()->GetArray("Distances"));vtkIntArray* intDistances = dynamic_cast<vtkIntArray*>

prj name: Casting

#include <vtkDoubleArray.h>
#include <vtkIntArray.h>
#include <vtkNew.h>
#include <vtkPointData.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>int main(int, char*[])
{// Create points.vtkNew<vtkPoints> points;unsigned int numberOfPoints = 3;points->InsertNextPoint(0.0, 0.0, 0.0);points->InsertNextPoint(1.0, 0.0, 0.0);points->InsertNextPoint(0.0, 1.0, 0.0);// Add the points to a polydatavtkNew<vtkPolyData> polydata;polydata->SetPoints(points);// Add distances to each pointvtkNew<vtkDoubleArray> distances;distances->SetNumberOfComponents(1);distances->SetName("Distances");distances->InsertNextValue(1.1);distances->InsertNextValue(2.2);distances->InsertNextValue(3.3);polydata->GetPointData()->AddArray(distances);// Get the distances from the polydata.vtkDoubleArray* array = dynamic_cast<vtkDoubleArray*>(polydata->GetPointData()->GetArray("Distances"));if (array){for (unsigned int i = 0; i < numberOfPoints; i++){double dist;dist = array->GetValue(i);std::cout << "Distance: " << dist << std::endl;}}// Cast the double distances to ints.vtkDoubleArray* doubleDistances = dynamic_cast<vtkDoubleArray*>(polydata->GetPointData()->GetArray("Distances"));vtkIntArray* intDistances = dynamic_cast<vtkIntArray*>(doubleDistances);if (intDistances){for (unsigned int i = 0; i < numberOfPoints; i++){int dist;dist = intDistances->GetValue(i);std::cout << "Distance: " << dist << std::endl;}}else{std::cout << "invalid cast." << std::endl;}return EXIT_SUCCESS;
}

这篇关于从 polydata 中获取数组 及 vtkDoubleArray、vtkIntArray互转的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/686123

相关文章

Java数组动态扩容的实现示例

《Java数组动态扩容的实现示例》本文主要介绍了Java数组动态扩容的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录1 问题2 方法3 结语1 问题实现动态的给数组添加元素效果,实现对数组扩容,原始数组使用静态分配

springboot的controller中如何获取applicatim.yml的配置值

《springboot的controller中如何获取applicatim.yml的配置值》本文介绍了在SpringBoot的Controller中获取application.yml配置值的四种方式,... 目录1. 使用@Value注解(最常用)application.yml 配置Controller 中

golang实现nacos获取配置和服务注册-支持集群详解

《golang实现nacos获取配置和服务注册-支持集群详解》文章介绍了如何在Go语言中使用Nacos获取配置和服务注册,支持集群初始化,客户端结构体中的IpAddresses可以配置多个地址,新客户... 目录golang nacos获取配置和服务注册-支持集群初始化客户端可选参数配置new一个客户端 支

Python版本信息获取方法详解与实战

《Python版本信息获取方法详解与实战》在Python开发中,获取Python版本号是调试、兼容性检查和版本控制的重要基础操作,本文详细介绍了如何使用sys和platform模块获取Python的主... 目录1. python版本号获取基础2. 使用sys模块获取版本信息2.1 sys模块概述2.1.1

JavaScript对象转数组的三种方法实现

《JavaScript对象转数组的三种方法实现》本文介绍了在JavaScript中将对象转换为数组的三种实用方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友... 目录方法1:使用Object.keys()和Array.map()方法2:使用Object.entr

Java发送SNMP至交换机获取交换机状态实现方式

《Java发送SNMP至交换机获取交换机状态实现方式》文章介绍使用SNMP4J库(2.7.0)通过RCF1213-MIB协议获取交换机单/多路状态,需开启SNMP支持,重点对比SNMPv1、v2c、v... 目录交换机协议SNMP库获取交换机单路状态获取交换机多路状态总结交换机协议这里使用的交换机协议为常

MyBatis/MyBatis-Plus同事务循环调用存储过程获取主键重复问题分析及解决

《MyBatis/MyBatis-Plus同事务循环调用存储过程获取主键重复问题分析及解决》MyBatis默认开启一级缓存,同一事务中循环调用查询方法时会重复使用缓存数据,导致获取的序列主键值均为1,... 目录问题原因解决办法如果是存储过程总结问题myBATis有如下代码获取序列作为主键IdMappe

C#使用iText获取PDF的trailer数据的代码示例

《C#使用iText获取PDF的trailer数据的代码示例》开发程序debug的时候,看到了PDF有个trailer数据,挺有意思,于是考虑用代码把它读出来,那么就用到我们常用的iText框架了,所... 目录引言iText 核心概念C# 代码示例步骤 1: 确保已安装 iText步骤 2: C# 代码程

Spring Boot中获取IOC容器的多种方式

《SpringBoot中获取IOC容器的多种方式》本文主要介绍了SpringBoot中获取IOC容器的多种方式,包括直接注入、实现ApplicationContextAware接口、通过Spring... 目录1. 直接注入ApplicationContext2. 实现ApplicationContextA

python获取指定名字的程序的文件路径的两种方法

《python获取指定名字的程序的文件路径的两种方法》本文主要介绍了python获取指定名字的程序的文件路径的两种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 最近在做项目,需要用到给定一个程序名字就可以自动获取到这个程序在Windows系统下的绝对路径,以下