VTK GetScalarPointer() and GetScalarComponentAsFloat() not work
I am using VTK 5.10.1 with VS 2010, and the following example does not work on my machine:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/ImageData/IterateImageData
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 <vtkVersion.h>
#include <vtkSmartPointer.h>
#include <vtkImageData.h>
#include <vtkPointData.h>
#include "vtkBMPReader.h" int main(int, char *[])
{
char * filename = "img.bmp";
if( !filename || strlen(filename) == )
{
return -;
} vtkBMPReader * reader = vtkBMPReader::New();
reader->SetFileName(filename);
reader->Update(); vtkSmartPointer<vtkImageData> image_data = reader->GetOutput(); int* dims = image_data->GetDimensions();
std::cout << "Dims: " << " x: " << dims[] << " y: " << dims[] << " z: " << dims[] << 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(); // Retrieve the entries from the image data and print them to the screen
for (int z = ; z < dims[]; z++)
{
for (int y = ; y < dims[]; y++)
{
for (int x = ; x < dims[]; x++)
{
/* Change this
double* pixel = static_cast<double*>(imageData->GetScalarPointer(x,y,z));
// do something with v
std::cout << pixel[0] << " ";
*/
double d[];
arr->GetTuple(y * dims[] + x, d);
std::cout << d[] << " ";
}
std::cout << std::endl;
}
std::cout << std::endl;
} return EXIT_SUCCESS;
}
VTK GetScalarPointer() and GetScalarComponentAsFloat() not work的更多相关文章
- mfc+vtk
MFC中view类主要处理显示视图,doc类处理文档,mainframe主要为整个窗口的和工程的设置管理.由此,VTK与MFC联合编程时,需要主要的是数据操作,以及显示要很好的与MFC中的结构结合,做 ...
- vtk多线程简单测试
vtkMultithreader is a class that provides support for multithreaded execution using sproc() on an SG ...
- Convert PLY to VTK Using PCL 1.6.0 使用PCL库将PLY格式转为VTK格式
PLY格式是比较流行的保存点云Point Cloud的格式,可以用MeshLab等软件打开,而VTK是医学图像处理中比较常用的格式,可以使用VTK库和ITK库进行更加复杂的运算处理.我们可以使用Par ...
- vtk工作流
要理解VTK的工作原理,首先应明确几个类型: 1.vtkSource(数据源) 这个就好比一个剧本里面的角色,让演员知道要演的是什么人物. 数据源有:vtkConeSource,vtkSphere ...
- 认识VTK工作原理
VTk通过数据流实现变信息为图形数据的. 数据流一般为:source-filter--mapper--actor--render--renderwindow--interactor. 要理解工作原理, ...
- Qt、VTK配置常见问题
QVTKWidget undefined reference to 问题,一定要在pro文件中添加库 libvtkGUISupportQt-6.3. 2. CMAKE_MAKE_PROGRAM ...
- VTK初学一,比较常见的错误2
我的开发环境: 系统:win8.1 QT:5.4.2MinGW版 VTK:6.3 按照教程生成一个球体显示在,Qt的QVTKWidget控件中,出现如下ERROR: ERROR: In D:\VTK6 ...
- 一个很全的VTK实例网址
https://cmake.org/Wiki/VTK/Examples/Cxx#Visualization
- VTK的学习资源
本文介绍从哪儿开始学习VTK(Visualization Toolkit的简称),如何在网上找寻VTK的学习资源. 首先,可以到维基百科或者百度百科上查看VTK条目,了解VTK是什么. http:// ...
随机推荐
- NuGet学习笔记(1) 初识NuGet及快速安装使用
关于NuGet园子里已经有不少介绍及使用经验,本文仅作为自己研究学习NuGet一个记录. 初次认识NuGet是在去年把项目升级为MVC3的时候,当时看到工具菜单多一项Library Package M ...
- linux查看和修改系统时间
设置日期:date -s 20091112 设置时间:date -s 18:30:50 日期和时间一起设置: date 111218302009 (月日时分年) date -s "20091 ...
- hdu1963 完全背包(数据压缩)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1963 注意:题中有一句话说债券的价钱都是1000的倍数,我之前没看到这句话,写的完全背包, ...
- css整理-02 颜色和字体
颜色 命名颜色 RGB指定颜色 数值: 0-255 百分比 三元组:红绿蓝 16进制RGB web安全颜色 在256色计算机系统上总能避免抖动的颜色 表示为rgb值20%和51的倍数 web安全色的简 ...
- HTTP基础07--认证
何为认证 BASIC 认证 是从 HTTP/1.0 就定义的认证方式.即便是现在仍有一部分的网站会使用这种认证方式.是 Web 服务器与通信客户端之间进行的认证方式. 步骤 1: 当请求的资源需要 B ...
- 04 DOM一窥
BOM 浏览器对象模型 * window alert(); 弹出框 confirm() 询问框 setInterval("run()",1000); 每隔1秒执行run ...
- jquery笔记(效果)
显示/隐藏: $(selector).hide(speed, function()):隐藏 $(selector).show(speed, function()):隐藏 $(selector).tog ...
- API
20145217 <Java程序设计>第八周学习总结 教材学习内容总结 本章主要讲输入与输出. 15.1日志API 1.java.util.logging包提供了日志功能相关类与接口,使用 ...
- NSDICTIONARY获取内容的CRASH
NSString *path = [self.dataPath stringByAppendingPathComponent:@"dummy.plist"]; NSMutableD ...
- EF框架step by step(1)—Database-First
ADO.NET Entity Framework 是微软以 ADO.NET 为基础所发展出来的对象关系对应 (O/R Mapping) 解决方案,现已经包含在 Visual Studio 2008 S ...