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:// ...
随机推荐
- APUE包含头文件"apue.h"问题
下载源码 从unix高级编程书籍官网下载书籍的上的所有源码. wget http://www.apuebook.com/src.tar.gz 解压这个文件 tar -zxvf src.tar.gz 解 ...
- VS2012 配置 OpenCV3.0
VS2012 配置 opencv3.0,相比之前的版本,3.0的配置简单了好多. 通过配置属性文件,可以做到一次配置,重复使用! 根据文章的操作在 win7 64bit VS2012 下成功配置 op ...
- poj 3468【线段树】
题意:给定Q(1<=Q<=100000)个数A1,A2…AQ,以及可能多次进行的两个操作 1)对某个区间Ai……Aj的每个数都加n(n可变) 2)对某个区间Ai……Aj的数求和 分析: 树 ...
- IM即时通讯实现原理
即时通讯(Instant Messenger,简称IM)软件多是基于TCP/IP和UDP进行通讯的,TCP/IP和UDP都是建立在更低层的IP协议上的两种通讯传输协议.前 者是以数据流的形式,将传 ...
- Struts2基本配置详解
Struts2配置文件加载顺序 struts2 配置文件由核心控制器加载 StrutsPrepareAndExecuteFilter (预处理,执行过滤) init_DefaultProperties ...
- Android 通过Java代码生成创建界面。动态生成View,动态设置View属性。addRules详解
废话不多说,本文将会层层深入给大家讲解如何动态的生成一个完整的界面. 本文内容: Java代码中动态生成View Java代码中动态设置View的位置,以及其他的属性 LayoutParams详解 一 ...
- Handler(消息机制)
Demo演示 //通过Handler事件倒计时的一个操作,并判断状态 public class MainActivity extends AppCompatActivity {private Text ...
- express-9 Handlebars模板引擎(2)
视图和布局 视图通常表现为网站上的各个页面(它也可以表现为页面中AJAX局部加载的内容,或一封电子邮件,或页面上的任何东西).默认情况下,Express会在views子目录中查找视图.布局是一种特殊的 ...
- CSS3属性
1.边框阴影(box-shadow ): 投影方式,X轴偏移,Y轴偏移,阴影模糊半径,阴影扩展半径,颜色 2.边框图像(border-image) 3.边框圆角:border-radius:5px 4 ...
- AngularJS 验证
AngularJS ng-model 指令用于绑定输入元素到模型中. 模型对象有两个属性: user 和 email. 我们使用了 ng-show指令, color:red 在邮件是 $dirty 或 ...