VTK初学一,a Mesh from vtkImageData—球冠

#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—球冠的更多相关文章
- VTK初学一,a Mesh from vtkImageData
#ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRend ...
- VTK初学一,vtkDelaunay2D创建球冠曲面
#ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRend ...
- VTK初学一,比较常见的错误2
我的开发环境: 系统:win8.1 QT:5.4.2MinGW版 VTK:6.3 按照教程生成一个球体显示在,Qt的QVTKWidget控件中,出现如下ERROR: ERROR: In D:\VTK6 ...
- VTK初学一,c_Line_CellArray线段的CellArray绘制
VTK窗口默认坐标方向: #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE ...
- VTK初学一,a_Vertex图形点的绘制
系统:Win8.1 QT版本:2.4.2,Mingw VTK版本:6.3 2. main.cpp #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #incl ...
- VTK初学一,动画加AVI录制终于做出来了
#ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRe ...
- VTK初学一,比较常见的错误1
错误原因: 通常是在文件头部没有初始化 #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> V ...
- VTK初学一,Pro文件的配置
1. pro文件的配置 TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG += qt QT += core gui greate ...
- VTK初学一,b_PolyVertex_CellArray多个点的绘制
#ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRend ...
随机推荐
- MongoDB: 数据库复制
db.copyDatabase("from","to","127.0.0.1:16161"); 将127.0.0.1上的from库.拷贝到t ...
- 数据结构算法C语言实现(十四)--- 4.1&4.2串的类型定义、表示及实现
一.简述 [暂无] 二.头文件 //4_2_part1.h /** author:zhaoyu */ //2016-6-10 //----串的定长顺序存储表示---- #include "h ...
- 屠蛟之路_蛟灵岛战役(下)_SeventhDay
蛟灵山,蛟灵洞,beta蛟. 终极决斗的时刻,这又是一场不是你死就是我亡的战争! beta怪蛟法力虽然没有alpha恶龙强,但是它依仗着地利,对屠蛟少年们发起了一次次极具威胁性地攻击!少年们的身上添了 ...
- 【原】整理的react相关的一些学习地址,包括 react-router、redux、webpack、flux
因为平时经常去网上找react相关的一些地址,找来找去很麻烦,所以自己整理了一下,不过前面部分不是我整理的, 是出自于:http://www.cnblogs.com/aaronjs/p/4333925 ...
- C#中int,string,char[],char的转换(待续)
//char[]转string string mm = "woshicainiao"; char[] ss = mm.ToCharArray(); string AA = new ...
- Jquery 学习之基础一
1.添加一个CSS类 $("button").click(function(){ $("#div1").addClass("important bl ...
- MySQL增加列,修改列名、列属性,删除列
mysql修改表名,列名,列类型,添加表列,删除表列 alter table test rename test1; --修改表名 alter table test add column name v ...
- JAVA第三周课后作业
JAVA课后作业 一.枚举类型 代码: enum Size{SMALL,MEDIUM,LARGE}; public cl ass EnumTest { public static void main( ...
- Java 生成验证码图片
生成验证码图片并对提交的输入进行验证 // HttpServletResponse常见应用——生成验证码 // 利用BufferedImage类生产随机图片 public static final i ...
- HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四 ...