从 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

相关文章

hdu2241(二分+合并数组)

题意:判断是否存在a+b+c = x,a,b,c分别属于集合A,B,C 如果用暴力会超时,所以这里用到了数组合并,将b,c数组合并成d,d数组存的是b,c数组元素的和,然后对d数组进行二分就可以了 代码如下(附注释): #include<iostream>#include<algorithm>#include<cstring>#include<stack>#include<que

hdu 1166 敌兵布阵(树状数组 or 线段树)

题意是求一个线段的和,在线段上可以进行加减的修改。 树状数组的模板题。 代码: #include <stdio.h>#include <string.h>const int maxn = 50000 + 1;int c[maxn];int n;int lowbit(int x){return x & -x;}void add(int x, int num){while

C语言:柔性数组

数组定义 柔性数组 err int arr[0] = {0}; // ERROR 柔性数组 // 常见struct Test{int len;char arr[1024];} // 柔性数组struct Test{int len;char arr[0];}struct Test *t;t = malloc(sizeof(Test) + 11);strcpy(t->arr,

C 语言基础之数组

文章目录 什么是数组数组变量的声明多维数组 什么是数组 数组,顾名思义,就是一组数。 假如班上有 30 个同学,让你编程统计每个人的分数,求最高分、最低分、平均分等。如果不知道数组,你只能这样写代码: int ZhangSan_score = 95;int LiSi_score = 90;......int LiuDong_score = 100;int Zhou

Android Environment 获取的路径问题

1. 以获取 /System 路径为例 /*** Return root of the "system" partition holding the core Android OS.* Always present and mounted read-only.*/public static @NonNull File getRootDirectory() {return DIR_ANDR

计算数组的斜率,偏移,R2

模拟Excel中的R2的计算。         public bool fnCheckRear_R2(List<double[]> lRear, int iMinRear, int iMaxRear, ref double dR2)         {             bool bResult = true;             int n = 0;             dou

C# double[] 和Matlab数组MWArray[]转换

C# double[] 转换成MWArray[], 直接赋值就行             MWNumericArray[] ma = new MWNumericArray[4];             double[] dT = new double[] { 0 };             double[] dT1 = new double[] { 0,2 };

JS和jQuery获取节点的兄弟,父级,子级元素

原文转自http://blog.csdn.net/duanshuyong/article/details/7562423 先说一下JS的获取方法,其要比JQUERY的方法麻烦很多,后面以JQUERY的方法作对比。 JS的方法会比JQUERY麻烦很多,主要则是因为FF浏览器,FF浏览器会把你的换行也当最DOM元素。 <div id="test"><div></div><div></div

PHP7扩展开发之数组处理

前言 这次,我们将演示如何在PHP扩展中如何对数组进行处理。要实现的PHP代码如下: <?phpfunction array_concat ($arr, $prefix) {foreach($arr as $key => $val) {if (isset($prefix[$key]) && is_string($val) && is_string($prefix[$key])) {$arr[

vcpkg子包路径批量获取

获取vcpkg 子包的路径,并拼接为set(CMAKE_PREFIX_PATH “拼接路径” ) import osdef find_directories_with_subdirs(root_dir):# 构建根目录下的 "packages" 文件夹路径root_packages_dir = os.path.join(root_dir, "packages")# 如果 "packages"