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


    #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();
        double R=80;//球面曲率半径
        double r=0;//任意x、y面上坐标点,到(0,0)点的距离
        double r2=r*r;
    //球冠切割面距圆心的距离(Z方向,所以名为zh)
        float zh=R*0.5;
        unsigned int gridXSize=2*R,gridYSize=gridXSize;
        double rCrown=sqrt(R*R-zh*zh);
        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)
                {
                    z=sqrt(R*R-r2);
                }
                else
                    z=zh;
                    points->InsertNextPoint(i,j,z);
            }
        }
        vtkSmartPointer<vtkPolyData> polydata=vtkSmartPointer<vtkPolyData>::New();
        polydata->SetPoints(points);
    
        vtkSmartPointer<vtkDelaunay2D> delaunay=vtkSmartPointer<vtkDelaunay2D>::New();
        delaunay->SetInputData(polydata);
        delaunay->Update();
        //在窗口中显示
        myShow(delaunay);
        return 0;
    }

    
    
    
    
  • 相关阅读:
    夏季适合IT程序员的养生小妙招
    夏季适合IT程序员的养生小妙招
    JS实现分钟数和时间小时 格式的转换
    Linux入门基础(1)
    Linux入门基础(1)
    Linux入门基础(1)
    常见通信协议HTTP、TCP、UDP的简单介绍
    BMP彩色转成黑色二值图
    《暗时间》笔记
    L53-Maximum-Subarray
  • 原文地址:https://www.cnblogs.com/phoenixdsg/p/6127934.html
Copyright © 2020-2023  润新知