博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
VTK GetScalarPointer() and GetScalarComponentAsFloat() not work
阅读量:6280 次
发布时间:2019-06-22

本文共 2040 字,大约阅读时间需要 6 分钟。

 

I am using VTK 5.10.1 with VS 2010, and the following example does not work on my machine:

The erros said:

vtkImageData [009B92A8]: Bad component index 1302176011

I am not sure why this happened, and it should work since it is from the official document. However, the reality is that it does not work on my machine, neither GetScalarComponentAsFloat() or GetScalarComponentAsDouble() will work.

So if we want to get the pixel data from vtkImageData, we need to find another way to do it. And we can get the data by accessing vtkDataArray, please see the following example code:

#include 
#include
#include
#include
#include "vtkBMPReader.h"int main(int, char *[]){ char * filename = "img.bmp"; if( !filename || strlen(filename) == 0 ) { return -1; } vtkBMPReader * reader = vtkBMPReader::New(); reader->SetFileName(filename); reader->Update(); vtkSmartPointer
image_data = reader->GetOutput(); int* dims = image_data->GetDimensions(); std::cout << "Dims: " << " x: " << dims[0] << " y: " << dims[1] << " z: " << dims[2] << std::endl; std::cout << "Number of points: " << image_data->GetNumberOfPoints() << std::endl; std::cout << "Number of cells: " << image_data->GetNumberOfCells() << std::endl; std::cout << "Number of scalar components: " << image_data->GetNumberOfScalarComponents() << std::endl; vtkDataArray *arr = image_data->GetPointData()->GetArray(0); // Retrieve the entries from the image data and print them to the screen for (int z = 0; z < dims[2]; z++) { for (int y = 0; y < dims[1]; y++) { for (int x = 0; x < dims[0]; x++) { /* Change this double* pixel = static_cast
(imageData->GetScalarPointer(x,y,z)); // do something with v std::cout << pixel[0] << " "; */ double d[3]; arr->GetTuple(y * dims[0] + x, d); std::cout << d[0] << " "; } std::cout << std::endl; } std::cout << std::endl; } return EXIT_SUCCESS;}

 

转载地址:http://hrnva.baihongyu.com/

你可能感兴趣的文章
台湾移动市场电信服务价格竞争预计将放缓
查看>>
《领域特定语言》一2.6 设计优良的DSL从何而来
查看>>
IDC圈探营:山西联通太原云数据中心
查看>>
呼叫中心还是客户中心?
查看>>
如何选择适当的低照度红外摄像机
查看>>
惠普企业总裁表示边缘计算将推动本地部署数据中心的需求
查看>>
数据说话|新华三近百个项目通过泰尔实验室测试
查看>>
CloudCC CRM探讨CRM如何提高客户的盈利性
查看>>
印度迎来可再生能源产业大发展
查看>>
光伏制造业“融资难、融资贵”问题亟待破解
查看>>
Java Mail最基本的发送邮件例子
查看>>
《HTML 5与CSS 3 权威指南(第3版·上册)》——2.3 新增的属性和废除的属性
查看>>
《Total Commander:万能文件管理器》——第3.5节.选择文件
查看>>
《日志管理与分析权威指南》一导读
查看>>
去 TMD 互联网思维,性价比而已
查看>>
如何手动删除Oracle 11g数据库
查看>>
懒人促进社会进步 - 5种索引的原理和优化Case (btree,hash,gin,gist,brin)
查看>>
《深入实践Spring Boot》一3.4 视图设计
查看>>
《设计模式解析(第2版•修订版)》目录—导读
查看>>
《Web前端开发精品课 HTML与CSS进阶教程》——2.2 标题语义化
查看>>