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:// ...
随机推荐
- 手机端touchstart,touchmove,touchend事件,优化用户划入某个可以点击LI的效果
在我们滑动手机的时候,如果LI或者DIV标签可以点击,那么在移动端给用户一个效果 /*id为添加效果LI上的UL的ID,或者是当前DIV的ID*/ function doTouchPublic(id) ...
- [转] Spring MVC sample application for downloading files
http://www.codejava.net/frameworks/spring/spring-mvc-sample-application-for-downloading-files n this ...
- set UVA 11136 Hoax or what
题目传送门 题意:训练指南P245 分析:set维护,查询删除最大最小值 #include <bits/stdc++.h> using namespace std; typedef lon ...
- iOS 初学UITableView、UITableViewCell、Xib
注意事项: 1.一个.xib里面最多设置一个cell 2.要仔细调整自动布局,其实它不太好用 3.记得设置<UITableViewDataSource>委托 4.记得在ViewContro ...
- 卸载Photoshop
安装Photoshop后出现卸载不干净的问题,从而导致安装另一个photoshop版本时出现错误,一般情况下我们都是在控制面板的卸载程序里进行卸载的,但往往这样的卸载并不能清除注册表残留以及系统盘里的 ...
- android项目 在签名打包遇到的问题
我在签名打包前,build success ,可以把程序安装在手机上 然后签名打包的时候,build fail ,原因采用了release 版本,因此这个时候在gradule build 添加下面 ...
- data.table包
data.table 1.生成一个data.table对象 生成一个data.table对象,记为DT. library(data.table) :],V3=round(rnorm(),),V4=:) ...
- hadoop datanode 挂机恢复后,多复制的块删除的问题
发现: 如果到namenode,用start-all.sh启动datanode,则会删除该datanode上所有的数据 到datanode上用hadoop-daemon.sh start datano ...
- angularjs 实现 文件拖拽,缩略图显示
成果图: main-hugeScreen.html <div class="hbox hbox-auto-xs hbox-auto-sm" ng-controller=&qu ...
- 福建红色文化VR/AR实体体验馆正式启用
(12月13日),福建红色文化网上展示馆上线暨福建红色文化VR/AR实体体验馆启动仪式在福建省革命历史纪念馆举行.省委常委.宣传部长高翔出席仪式并宣布启动上线. 福建红色文化网上展示馆和VR/AR实体 ...