码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-12-03 09:50:42      阅读:315      评论:0      收藏:0      [点我收藏+]

标签:窗口   set   point   track   color   poi   structure   ima   创建   

技术分享

#ifndef INITIAL_OPENGL
#define INITIAL_OPENGL
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL)
VTK_MODULE_INIT(vtkInteractionStyle)
#endif
#include <iostream>
using namespace std;
#include "vtkPolyDataMapper.h"
#include "vtkWin32OpenGLRenderWindow.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkPoints.h"
#include "vtkWin32RenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkFloatArray.h"
#include "vtkPolyData.h"
#include "vtkDataSetMapper.h"
#include "vtkActor2D.h"
#include "vtkContourFilter.h"
#include "vtkContourValues.h"
#include "vtkUnstructuredGrid.h"
#include "vtkPointData.h"
#include "vtkPolyVertex.h"
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkCellArray.h>
#include "vtkDelaunay2D.h"
#include "vtkMath.h"
void myShow(vtkDelaunay2D* 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()->SetPointSize(1);
    anActor->GetProperty()->SetColor(1,0,1);

    vtkSmartPointer<vtkRenderer> ren1=vtkSmartPointer<vtkRenderer>::New();
    vtkSmartPointer<vtkRenderWindow> renWin=vtkSmartPointer<vtkRenderWindow>::New();
    ren1->AddActor(anActor);
    ren1->ResetCamera();
    ren1->SetBackground(1,1,1);
    renWin->AddRenderer(ren1);
    renWin->SetSize(512,512);

    vtkSmartPointer<vtkRenderWindowInteractor> iren=vtkSmartPointer<vtkRenderWindowInteractor>::New();
    vtkSmartPointer<vtkInteractorStyleTrackballCamera> style=vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
    iren->SetRenderWindow(renWin);
    iren->SetInteractorStyle(style);
    iren->Start();
}
int main()
{
    vtkSmartPointer<vtkPoints> points=vtkSmartPointer<vtkPoints>::New();

    unsigned int gridXSize=60,gridYSize=60;
    double R=60;//球面曲率半径
    double r=0;//任意x、y坐标点,到(0,0)点的距离
    double r2=r*r;

    double rCrown=gridXSize/2;
    double rCrown2=rCrown*rCrown;//球冠半径的平方
    double hmax2=R*R-rCrown2;//最大弧矢高的平方
    double hmax=R-sqrt(hmax2);//最大弧矢高
    for(double i=0;i<gridXSize;i++)
    {
        for(double j=0;j<gridYSize;j++)
        {
            double x=(i-gridXSize/2),y=(j-gridYSize/2);
            r2=x*x+y*y;//r2表示r的平方
            r=sqrt(r2);
            double z=0;
            if(r<rCrown)
                //不知道为什么,要在后面多加一个最大弧矢高hmax,才能得到正确的球冠,大概是坐标方向问题吧
            {
                z=sqrt(R*R-r2)-(R-hmax)+hmax;
                points->InsertNextPoint(i,j,z);
            }
            else
                z=hmax;
        }
    }
    vtkSmartPointer<vtkPolyData> polydata=vtkSmartPointer<vtkPolyData>::New();
    polydata->SetPoints(points);

    vtkSmartPointer<vtkDelaunay2D> delaunay=vtkSmartPointer<vtkDelaunay2D>::New();
    delaunay->SetInputData(polydata);
    delaunay->Update();
    //在窗口中显示
    myShow(delaunay);
    return 0;
}

 

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

标签:窗口   set   point   track   color   poi   structure   ima   创建   

原文地址:http://www.cnblogs.com/phoenixdsg/p/6127934.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!