莫比乌斯环-vtkTriangleStrip-LMLPHP

 #ifndef INITIAL_OPENGL
#define INITIAL_OPENGL
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL)
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingFreeType)
#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 "vtkPointData.h"
#include "vtkPolyVertex.h"
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkCellArray.h>
#include "vtkDelaunay2D.h"
#include "vtkMath.h"
#include <vtkTransformFilter.h>
#include <vtkCamera.h>
#include <vtkTriangleStrip.h> void myShow(vtkPolyData* anInput)
{
vtkSmartPointer<vtkPolyDataMapper> aMapper=vtkSmartPointer<vtkPolyDataMapper>::New();
aMapper->SetInputData(anInput);
aMapper->ScalarVisibilityOn(); vtkSmartPointer<vtkActor> anActor=vtkSmartPointer<vtkActor>::New();
anActor->SetMapper(aMapper);
anActor->GetProperty()->SetRepresentationToSurface();
anActor->GetProperty()->SetPointSize();
anActor->GetProperty()->SetColor(,,);
anActor->GetProperty()->SetOpacity(0.4); vtkSmartPointer<vtkRenderer> ren1=vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renWin=vtkSmartPointer<vtkRenderWindow>::New(); ren1->AddActor(anActor); ren1->SetBackground(0.5,0.5,0.5);
ren1->SetBackground2(,,);
renWin->AddRenderer(ren1);
renWin->SetSize(,); vtkSmartPointer<vtkRenderWindowInteractor> iren=vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style=vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
iren->SetRenderWindow(renWin);
iren->SetInteractorStyle(style); ren1->ResetCamera();
renWin->Render();
iren->Start();
} int main()
{
//创建几何点数据
double vArr[]={-0.5,0.5};
double theta=vtkMath::Pi()*;
int thetaResolution=;
double dTheta=theta/thetaResolution;
double *uArr=new double[thetaResolution];
vtkSmartPointer<vtkPoints> points=vtkSmartPointer<vtkPoints>::New();
for(int i=;i<thetaResolution+;i++)
{
uArr[i]=i*dTheta;
double u=uArr[i];
for(int j=;j<;j++)
{
double v=vArr[j];
double pt[]={(+v/*cos(u/))*cos(u),(+v/*cos(u/))*sin(u),v/*sin(u/)};
points->InsertNextPoint(pt); }
}
//创建拓扑结构
vtkSmartPointer<vtkTriangleStrip> mobiusStrip=vtkSmartPointer<vtkTriangleStrip>::New();
mobiusStrip->GetPointIds()->SetNumberOfIds((thetaResolution+)*);
for(int i=;i<(thetaResolution+)*;i++)
mobiusStrip->GetPointIds()->SetId(i,i);
//将拓扑结构组合进Cell
vtkSmartPointer<vtkCellArray> mobiusCell=vtkSmartPointer<vtkCellArray>::New();
mobiusCell->InsertNextCell(mobiusStrip);
//将几何点与Cell结构组合成一个PolyData。
vtkSmartPointer<vtkPolyData> mobiusPolydata=vtkSmartPointer<vtkPolyData>::New();
mobiusPolydata->SetPoints(points);
mobiusPolydata->SetStrips(mobiusCell); myShow(mobiusPolydata);
return ;
}
05-04 08:33