1. #ifndef INITIAL_OPENGL
  2. #define INITIAL_OPENGL
  3. #include <vtkAutoInit.h>
  4. VTK_MODULE_INIT(vtkRenderingOpenGL)
  5. VTK_MODULE_INIT(vtkInteractionStyle)
  6. #endif
  7. #include <iostream>
  8. using namespace std;
  9. #include <vtkVersion.h>
  10. #include <vtkPolyData.h>
  11. #include <vtkProperty.h>
  12. #include <vtkMath.h>
  13. #include <vtkSmartPointer.h>
  14. #include <vtkPolyDataMapper.h>
  15. #include <vtkActor.h>
  16. #include <vtkRenderWindow.h>
  17. #include <vtkRenderer.h>
  18. #include <vtkRenderWindowInteractor.h>
  19. #include <vtkImageData.h>
  20. #include <vtkGreedyTerrainDecimation.h>
  21. #include <vtkInteractorStyleTrackballCamera.h>
  22. #include <vtkInteractionWidgetsModule.h>
  23. void myShow(vtkGreedyTerrainDecimation* anInput)
  24. {
  25. vtkSmartPointer<vtkPolyDataMapper> aMapper=vtkSmartPointer<vtkPolyDataMapper>::New();
  26. aMapper->SetInputConnection(anInput->GetOutputPort());
  27. aMapper->ScalarVisibilityOn();
  28. vtkSmartPointer<vtkActor> anActor=vtkSmartPointer<vtkActor>::New();
  29. anActor->SetMapper(aMapper);
  30. anActor->GetProperty()->SetInterpolationToFlat();
  31. anActor->GetProperty()->EdgeVisibilityOn();
  32. anActor->GetProperty()->SetEdgeColor(,,);
  33. vtkSmartPointer<vtkRenderer> ren1=vtkSmartPointer<vtkRenderer>::New();
  34. vtkSmartPointer<vtkRenderWindow> renWin=vtkSmartPointer<vtkRenderWindow>::New();
  35. ren1->AddActor(anActor);
  36. ren1->ResetCamera();
  37. ren1->SetBackground(,,);
  38. renWin->AddRenderer(ren1);
  39. renWin->SetSize(,);
  40. vtkSmartPointer<vtkRenderWindowInteractor> iren=vtkSmartPointer<vtkRenderWindowInteractor>::New();
  41. vtkSmartPointer<vtkInteractorStyleTrackballCamera> style=vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
  42. iren->SetRenderWindow(renWin);
  43. iren->SetInteractorStyle(style);
  44. iren->Start();
  45. }
  46. int main()
  47. {
  48. vtkSmartPointer<vtkImageData> image=vtkSmartPointer<vtkImageData>::New();
  49. image->SetDimensions(,,);
  50. image->AllocateScalars(VTK_UNSIGNED_CHAR,);
  51. int dims[];
  52. // double max=sqrt(dims[0]*dims[0]+dims[1]*dims[1]);
  53. image->GetDimensions(dims);
  54. double R=;//球面半径
  55. double r=;//任意x、y坐标点,到(0,0)点的距离
  56. double r2=r*r;
  57. double rCrown=dims[]/;
  58. double rCrown2=rCrown*rCrown;//球冠半径的平方
  59. double hmax2=R*R-rCrown2;//最大弧矢高的平方
  60. double hmax=R-sqrt(hmax2);//最大弧矢高
  61. for(double i=;i<dims[];i++)
  62. {
  63. for(double j=;j<dims[];j++)
  64. {
  65. unsigned char* pixel=static_cast<unsigned char*>(image->GetScalarPointer(i,j,));
  66. double x=(i-dims[]/),y=(j-dims[]/);
  67. r2=x*x+y*y;
  68. r=sqrt(r2);
  69. if(r<rCrown)
  70. //不知道为什么,要在后面多加一个最大弧矢高hmax,才能得到正确的球冠,大概是坐标方向问题吧
  71. pixel[]=sqrt(R*R-r2)-(R-hmax)+hmax;
  72. else
  73. pixel[]=hmax;
  74. }
  75. }
  76. vtkSmartPointer<vtkGreedyTerrainDecimation>decimation=vtkSmartPointer<vtkGreedyTerrainDecimation>::New();
  77. decimation->SetInputData(image);
  78. decimation->Update();
  79. //可视化
  80. myShow(decimation);
  81. return ;
  82. }
  1.  
  1.  

VTK初学一,a Mesh from vtkImageData—球冠的更多相关文章

  1. VTK初学一,a Mesh from vtkImageData

    #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRend ...

  2. VTK初学一,vtkDelaunay2D创建球冠曲面

    #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRend ...

  3. VTK初学一,比较常见的错误2

    我的开发环境: 系统:win8.1 QT:5.4.2MinGW版 VTK:6.3 按照教程生成一个球体显示在,Qt的QVTKWidget控件中,出现如下ERROR: ERROR: In D:\VTK6 ...

  4. VTK初学一,c_Line_CellArray线段的CellArray绘制

    VTK窗口默认坐标方向: #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE ...

  5. VTK初学一,a_Vertex图形点的绘制

    系统:Win8.1 QT版本:2.4.2,Mingw VTK版本:6.3 2. main.cpp #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #incl ...

  6. VTK初学一,动画加AVI录制终于做出来了

      #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRe ...

  7. VTK初学一,比较常见的错误1

      错误原因: 通常是在文件头部没有初始化 #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> V ...

  8. VTK初学一,Pro文件的配置

    1. pro文件的配置 TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG += qt QT += core gui greate ...

  9. VTK初学一,b_PolyVertex_CellArray多个点的绘制

    #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRend ...

随机推荐

  1. Hash Length Extension Attacks

    catalogue . Hash函数的内部原理 . 漏洞原理 1. Hash函数的内部原理 0x1: 分组.Padding 哈希函数以区块为单位操作数据.比如说,MD5, SHA1, SHA256的区 ...

  2. Linux System Account SSH Weak Password Detection Automatic By System API

    catalog . Linux弱口令攻击向量 . Linux登录验证步骤 . PAM . 弱口令风险基线检查 1. Linux弱口令攻击向量 0x1: SSH密码暴力破解 hydra -l root ...

  3. [U3D 画起重机,绑脚本和控制它运动的基本操作]

    之前在学习Unity3D,不知为何网上的教学资源真是少啊...我某段时间还卡在不知如何让物体绑个脚本自动运动.. 之所以要学习U3D是因为导师让我做的IOS项目里有个需要模拟起重机,从而控制真实起重机 ...

  4. Node.js使用Mongoose包操作MongoDB数据库

    1. 安装Mongoose npm install mongoose 2. 使用 2.1 创建连接 var mongoose = require('mongoose'); mongoose.conne ...

  5. C++ 第二次课堂作业(反转链表)

    题目链接: 传送门 GitHub链接: 传送门

  6. 更改primefaces theme

    PrimeFaces is using jQuery ThemeRoller CSS theme framework, and come with 30+ pre-designed themes th ...

  7. CentOS 6 日期 时间,时区,设置修改及时间同步

    一.时区 显示时区 date --help 获取帮助 date -R date +%z 上面两个命令都可 [root@localhost ~]# date -R; date +%z Fri, 19 O ...

  8. redis理解

    1. Redis是什么 redis是nosql的一种. 这个问题的结果影响了我们怎么用Redis.如果你认为Redis是一个key value store, 那可能会用它来代替MySQL:如果认为它是 ...

  9. css的核心内容 标准流、盒子模型、浮动、定位等分析

    1.块级元素:如:<div></div>2.行内元素:如:<span></span>从效果中看块级元素与行内元素的区别: 通过CSS的设置把行内元素转换 ...

  10. MSMQ 学习(1)

    在 Windows Server 2008 or Windows Server 2008 R2 上安装消息队列 4.0 在服务器管理器中,单击“功能”. 在“功能摘要”下的右窗格中,单击“添加功能”. ...