#ifndef INITIAL_OPENGL
#define INITIAL_OPENGL
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL)
VTK_MODULE_INIT(vtkInteractionStyle)
#endif
#include <iostream>
using namespace std;
#include <vtkVersion.h>
#include <vtkPolyData.h>
#include <vtkProperty.h>
#include <vtkMath.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkImageData.h>
#include <vtkGreedyTerrainDecimation.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkInteractionWidgetsModule.h>
void myShow(vtkGreedyTerrainDecimation* anInput)
{
vtkSmartPointer<vtkPolyDataMapper> aMapper=vtkSmartPointer<vtkPolyDataMapper>::New();
aMapper->SetInputConnection(anInput->GetOutputPort());
aMapper->ScalarVisibilityOn();
vtkSmartPointer<vtkActor> anActor=vtkSmartPointer<vtkActor>::New();
anActor->SetMapper(aMapper);
anActor->GetProperty()->SetInterpolationToFlat();
anActor->GetProperty()->EdgeVisibilityOn();
anActor->GetProperty()->SetEdgeColor(,,);
vtkSmartPointer<vtkRenderer> ren1=vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renWin=vtkSmartPointer<vtkRenderWindow>::New();
ren1->AddActor(anActor);
ren1->ResetCamera();
ren1->SetBackground(,,);
renWin->AddRenderer(ren1);
renWin->SetSize(,);
vtkSmartPointer<vtkRenderWindowInteractor> iren=vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style=vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
iren->SetRenderWindow(renWin);
iren->SetInteractorStyle(style);
iren->Start();
}
int main()
{
vtkSmartPointer<vtkImageData> image=vtkSmartPointer<vtkImageData>::New();
image->SetDimensions(,,);
image->AllocateScalars(VTK_UNSIGNED_CHAR,);
int dims[];
// double max=sqrt(dims[0]*dims[0]+dims[1]*dims[1]);
image->GetDimensions(dims);
double R=;//球面半径
double r=;//任意x、y坐标点,到(0,0)点的距离
double r2=r*r;
double rCrown=dims[]/;
double rCrown2=rCrown*rCrown;//球冠半径的平方
double hmax2=R*R-rCrown2;//最大弧矢高的平方
double hmax=R-sqrt(hmax2);//最大弧矢高
for(double i=;i<dims[];i++)
{
for(double j=;j<dims[];j++)
{
unsigned char* pixel=static_cast<unsigned char*>(image->GetScalarPointer(i,j,));
double x=(i-dims[]/),y=(j-dims[]/);
r2=x*x+y*y;
r=sqrt(r2);
if(r<rCrown)
//不知道为什么,要在后面多加一个最大弧矢高hmax,才能得到正确的球冠,大概是坐标方向问题吧
pixel[]=sqrt(R*R-r2)-(R-hmax)+hmax;
else
pixel[]=hmax;
}
}
vtkSmartPointer<vtkGreedyTerrainDecimation>decimation=vtkSmartPointer<vtkGreedyTerrainDecimation>::New();
decimation->SetInputData(image);
decimation->Update();
//可视化
myShow(decimation);
return ;
}

												

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. Android成长日记-Noification实现状态栏通知

    Notification可以作为状态栏的通知,实现这个效果需要使用NotificationManager实现控制类,才能实现对这个效果的显示 下面是实现状态栏显示效果的通知: 1. 首先在Layout ...

  2. Bzoj2763 [JLOI2011]飞行路线

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2651  Solved: 1004 Description Alice和Bob现在要乘飞机旅行,他们选 ...

  3. python grammar、C/C++ Python Parsing Engine

    catalog . Python语言简介 . Python模块 . 嵌入式Python解析引擎: C++调用Python . Python 调用 C (base) . 扩展Python语法解析器功能: ...

  4. Linux Overflow Vulnerability General Hardened Defense Technology、Grsecurity/PaX

    Catalog . Linux attack vector . Grsecurity/PaX . Hardened toolchain . Default addition of the Stack ...

  5. linux: shell常用指令归纳

    1.软件安装方式: 1)源码安装: ~ wget xxxxxx ~ ./configure ~ make ~ make install 2) yum: ~ yum search : 查找软件包 ~ y ...

  6. Python翻转字符串或者列表的方式

    1. reversed class reversed(object) | reversed(sequence) -> reverse iterator over values of the se ...

  7. linux系统命令

    TOP命令 top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.top是一个动态显示过程, 即可以通过用户按键来不断刷新当前状态.如 ...

  8. win8启动文件夹

    进入C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp.鼠标右键选中粘贴,将软件快捷方式粘贴到启动目录 进入文件夹时路径可能是C: ...

  9. 9月20日上午JavaScript函数

    函数 一.  函数定义 函数又叫方法,在程序里面函数是用来执行某些特定功能的代码.为了减少重复使用代码,可以把特定功能的代码做成函数,需要使用时拿出来调用.alert();就是一个很常见的.简单的函数 ...

  10. Java数据库——事务处理

    在数据库中执行5条SQL语句,这些SQL语句本身需要保持一致,即要么同时成功,要么同时失败 事务基本操作 //============================================= ...