zoukankan      html  css  js  c++  java
  • 莫比乌斯环-vtkTriangleStrip

      1 #ifndef INITIAL_OPENGL
      2 #define INITIAL_OPENGL
      3 #include <vtkAutoInit.h>
      4 VTK_MODULE_INIT(vtkRenderingOpenGL)
      5 VTK_MODULE_INIT(vtkInteractionStyle)
      6 VTK_MODULE_INIT(vtkRenderingFreeType)
      7 #endif
      8 #include <iostream>
      9 using namespace std;
     10 
     11 #include "vtkPolyDataMapper.h"
     12 #include "vtkWin32OpenGLRenderWindow.h"
     13 #include "vtkRenderWindow.h"
     14 #include "vtkRenderWindowInteractor.h"
     15 #include "vtkRenderer.h"
     16 #include "vtkPoints.h"
     17 #include "vtkWin32RenderWindowInteractor.h"
     18 #include "vtkProperty.h"
     19 #include "vtkFloatArray.h"
     20 #include "vtkPolyData.h"
     21 #include "vtkDataSetMapper.h"
     22 #include "vtkActor2D.h"
     23 #include "vtkPointData.h"
     24 #include "vtkPolyVertex.h"
     25 #include <vtkInteractorStyleTrackballCamera.h>
     26 #include <vtkCellArray.h>
     27 #include "vtkDelaunay2D.h"
     28 #include "vtkMath.h"
     29 #include <vtkTransformFilter.h>
     30 #include <vtkCamera.h>
     31 #include <vtkTriangleStrip.h>
     32 
     33 void myShow(vtkPolyData* anInput)
     34 {
     35     vtkSmartPointer<vtkPolyDataMapper> aMapper=vtkSmartPointer<vtkPolyDataMapper>::New();
     36     aMapper->SetInputData(anInput);
     37     aMapper->ScalarVisibilityOn();
     38 
     39     vtkSmartPointer<vtkActor> anActor=vtkSmartPointer<vtkActor>::New();
     40     anActor->SetMapper(aMapper);
     41     anActor->GetProperty()->SetRepresentationToSurface();
     42     anActor->GetProperty()->SetPointSize(1);
     43     anActor->GetProperty()->SetColor(1,0,1);
     44     anActor->GetProperty()->SetOpacity(0.4);
     45 
     46     vtkSmartPointer<vtkRenderer> ren1=vtkSmartPointer<vtkRenderer>::New();
     47     vtkSmartPointer<vtkRenderWindow> renWin=vtkSmartPointer<vtkRenderWindow>::New();
     48 
     49     ren1->AddActor(anActor);
     50 
     51     ren1->SetBackground(0.5,0.5,0.5);
     52     ren1->SetBackground2(1,0,0);
     53     renWin->AddRenderer(ren1);
     54     renWin->SetSize(512,512);
     55 
     56     vtkSmartPointer<vtkRenderWindowInteractor> iren=vtkSmartPointer<vtkRenderWindowInteractor>::New();
     57     vtkSmartPointer<vtkInteractorStyleTrackballCamera> style=vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
     58     iren->SetRenderWindow(renWin);
     59     iren->SetInteractorStyle(style);
     60 
     61     ren1->ResetCamera();
     62     renWin->Render();
     63     iren->Start();
     64 }
     65 
     66 int main()
     67 {
     68     //创建几何点数据
     69     double vArr[2]={-0.5,0.5};
     70     double theta=vtkMath::Pi()*2;
     71     int thetaResolution=60;
     72     double dTheta=theta/thetaResolution;
     73     double *uArr=new double[thetaResolution];
     74     vtkSmartPointer<vtkPoints> points=vtkSmartPointer<vtkPoints>::New();
     75     for(int i=0;i<thetaResolution+1;i++)
     76     {
     77         uArr[i]=i*dTheta;
     78         double u=uArr[i];
     79         for(int j=0;j<2;j++)
     80         {
     81             double v=vArr[j];
     82             double pt[3]={(2+v/2*cos(u/2))*cos(u),(1+v/2*cos(u/2))*sin(u),v/2*sin(u/2)};
     83             points->InsertNextPoint(pt);
     84 
     85         }
     86     }
     87     //创建拓扑结构
     88     vtkSmartPointer<vtkTriangleStrip> mobiusStrip=vtkSmartPointer<vtkTriangleStrip>::New();
     89     mobiusStrip->GetPointIds()->SetNumberOfIds((thetaResolution+1)*2);
     90     for(int i=0;i<(thetaResolution+1)*2;i++)
     91         mobiusStrip->GetPointIds()->SetId(i,i);
     92     //将拓扑结构组合进Cell
     93     vtkSmartPointer<vtkCellArray> mobiusCell=vtkSmartPointer<vtkCellArray>::New();
     94     mobiusCell->InsertNextCell(mobiusStrip);
     95     //将几何点与Cell结构组合成一个PolyData。
     96     vtkSmartPointer<vtkPolyData> mobiusPolydata=vtkSmartPointer<vtkPolyData>::New();
     97     mobiusPolydata->SetPoints(points);
     98     mobiusPolydata->SetStrips(mobiusCell);
     99 
    100     myShow(mobiusPolydata);
    101     return 0;
    102 }
  • 相关阅读:
    星空雅梦
    星空雅梦
    星空雅梦
    星空雅梦
    星空雅梦
    星空雅梦
    code=exited,status=1/failure;failed to start LSB:Bring up/down networking
    Eclipse安装AmaterasUML插件问题
    Navicat如何导出Excel格式表结构
    powerdesigner生成mysql带注释的ER图
  • 原文地址:https://www.cnblogs.com/phoenixdsg/p/6166000.html
Copyright © 2011-2022 走看看