VTK 三角剖分 Delaunay3D

标签: 计算机图形学  GIS  VTK  Delaunay3D  四面体网格

在这里插入图片描述

描述

空间不规则点集,生成四面体网格。

vtkSmartPointer<vtkNamedColors> color =vtkSmartPointer<vtkNamedColors>::New();

  vtkSmartPointer<vtkPoints> ps = vtkSmartPointer<vtkPoints>::New();
  unsigned int GridSize = 10;
  for (unsigned int x = 0; x < GridSize; x++)
  {
	  for (unsigned int y = 0; y < GridSize; y++)
	  {
		  ps->InsertNextPoint(x, y, vtkMath::Random(-.25, .25));
		 /* ps->InsertNextPoint(
			  x + vtkMath::Random(-1.25, 1.25),
			  y + vtkMath::Random(-1.25, 1.25), 
			  vtkMath::Random(2.5, 2.75)
		  );*/
	  }
  }
  GridSize = 6;
  for (unsigned int x = 1; x < GridSize; x++)
  {
	  for (unsigned int y = 1; y < GridSize; y++)
	  {
		 // ps->InsertNextPoint(x, y, vtkMath::Random(-.25, .25));
		  ps->InsertNextPoint(
			  x + vtkMath::Random(-1.25, 1.25),
			  y + vtkMath::Random(-1.25, 1.25),
			  vtkMath::Random(2.5, 2.75)
		  );
	  }
  }
  vtkSmartPointer<vtkPolyData>polydata =vtkSmartPointer<vtkPolyData>::New();
  polydata->SetPoints(ps);

  vtkSmartPointer<vtkDelaunay3D> delaunay3D =vtkSmartPointer<vtkDelaunay3D>::New();
  delaunay3D->SetInputData(polydata);
  delaunay3D->Update();

  vtkSmartPointer<vtkDataSetMapper> delaunayMapper =vtkSmartPointer<vtkDataSetMapper>::New();
  delaunayMapper->SetInputConnection(delaunay3D->GetOutputPort());
  
  vtkSmartPointer<vtkActor> delaunayActor =vtkSmartPointer<vtkActor>::New();
  delaunayActor->SetMapper(delaunayMapper);
  delaunayActor->GetProperty()->SetColor(color->GetColor3d("banana").GetData());
  delaunayActor->GetProperty()->EdgeVisibilityOn();
  
  
  vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New();
  glyphFilter->SetInputData(delaunay3D->GetOutput());

  vtkSmartPointer<vtkPolyDataMapper> pointMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
  pointMapper->SetInputConnection(glyphFilter->GetOutputPort());

  vtkSmartPointer<vtkActor> pointActor = vtkSmartPointer<vtkActor>::New();
  pointActor->GetProperty()->SetColor(color->GetColor3d("Tomato").GetData());
  pointActor->GetProperty()->SetPointSize(5);
  pointActor->SetMapper(pointMapper);


  vtkSmartPointer<vtkRenderer> delaunayRenderer =vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow =vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->SetSize(900,900);

 
  renderWindow->AddRenderer(delaunayRenderer);
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

 
  delaunayRenderer->AddActor(delaunayActor);
  delaunayRenderer->AddActor(pointActor);
  delaunayRenderer->SetBackground(color->GetColor3d("Mint").GetData());

  // Render and interact
  renderWindowInteractor->Start();
  return EXIT_SUCCESS;
版权声明:本文为mrbaolong原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/mrbaolong/article/details/104838411