⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 三角化.cpp

📁 VTK入门样例(种类齐全)
💻 CPP
📖 第 1 页 / 共 3 页
字号:
#include "vtkPolyDataMapper.h"
#include "vtkWin32OpenGLRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkPoints.h"
#include "vtkWin32RenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkTexture.h"
#include "vtkFloatArray.h"
#include "vtkParametricSuperEllipsoid.h"
#include "vtkParametricSuperToroid.h"
#include "vtkParametricMobius.h"
#include "vtkPolyData.h"
#include "vtkDataSetMapper.h"
#include "vtkHexahedron.h"
#include "vtkActor2D.h"
#include "vtkParametricKlein.h"
#include "vtkPolyVertex.h"
#include "vtkVertex.h"
#include "vtkPolyLine.h"
#include "vtkContourFilter.h"
#include "vtkPentagonalPrism.h"
#include "vtkUnstructuredGrid.h"
#include "vtkLine.h"
#include "vtkTriangleStrip.h"
#include "vtkPolygon.h"
#include "vtkTriangle.h"
#include "vtkQuad.h"
#include "vtkPixel.h"
#include "vtkPointData.h"
#include "vtkWedge.h"
#include "vtkPyramid.h"
#include "vtkTetra.h"
#include "vtkTextProperty.h"
#include "vtkVoxel.h"
#include "vtkHexagonalPrism.h"



void main()
{
	vtkRenderer *ren1=vtkRenderer::New();
	vtkWin32OpenGLRenderWindow *renWin=vtkWin32OpenGLRenderWindow::New();
  	  renWin->AddRenderer(ren1);
	vtkWin32RenderWindowInteractor *iren=vtkWin32RenderWindowInteractor::New();
	  iren->SetRenderWindow(renWin);	

// create a scene with one of each cell type
// Voxel

	vtkPoints *voxelPoints=vtkPoints::New();
	  voxelPoints-> SetNumberOfPoints( 8);
	  voxelPoints-> InsertPoint(0, 0, 0, 0);
	  voxelPoints-> InsertPoint(1, 1, 0, 0);
	  voxelPoints-> InsertPoint(2, 0, 1, 0);
	  voxelPoints-> InsertPoint(3, 1, 1, 0);
	  voxelPoints-> InsertPoint(4 ,0, 0, 1);
	  voxelPoints-> InsertPoint(5, 1, 0, 1);
	  voxelPoints-> InsertPoint(6, 0, 1, 1);
	  voxelPoints-> InsertPoint(7 ,1, 1, 1);

	vtkFloatArray *voxelScalars=vtkFloatArray::New();
	  voxelScalars-> SetNumberOfTuples( 8);
	  voxelScalars-> InsertValue( 0, 0);
	  voxelScalars-> InsertValue( 1, 1);
	  voxelScalars-> InsertValue( 2, 0);
	  voxelScalars-> InsertValue( 3, 0);
	  voxelScalars-> InsertValue( 4, 0);
	  voxelScalars-> InsertValue( 5, 0);
	  voxelScalars-> InsertValue( 6, 0);
	  voxelScalars-> InsertValue( 7, 0);

	vtkVoxel *aVoxel=vtkVoxel::New();
	  aVoxel-> GetPointIds()-> SetId(0, 0);
	  aVoxel-> GetPointIds()-> SetId(1, 1);
	  aVoxel-> GetPointIds()-> SetId(2, 2);
	  aVoxel-> GetPointIds()-> SetId(3, 3);
	  aVoxel-> GetPointIds()-> SetId(4, 4);
	  aVoxel-> GetPointIds()-> SetId(5, 5);
	  aVoxel-> GetPointIds()-> SetId(6, 6);
	  aVoxel-> GetPointIds()-> SetId(7, 7);


	vtkUnstructuredGrid *aVoxelGrid=vtkUnstructuredGrid::New();
	  aVoxelGrid-> Allocate (1, 1);
	  aVoxelGrid-> InsertNextCell (aVoxel-> GetCellType(), aVoxel-> GetPointIds());
	  aVoxelGrid ->SetPoints (voxelPoints);
	  aVoxelGrid-> GetPointData() ->SetScalars (voxelScalars);

	vtkContourFilter *voxelContours=vtkContourFilter::New();
	  voxelContours-> SetInput (aVoxelGrid);
	  voxelContours-> SetValue (0,0.5);

	vtkDataSetMapper *aVoxelContourMapper=vtkDataSetMapper::New();
	  aVoxelContourMapper-> SetInputConnection (voxelContours-> GetOutputPort());
	  aVoxelContourMapper-> ScalarVisibilityOff();

	vtkDataSetMapper *aVoxelMapper=vtkDataSetMapper::New();
	  aVoxelMapper-> SetInput (aVoxelGrid);
	  aVoxelMapper-> ScalarVisibilityOff();

	vtkActor *aVoxelActor=vtkActor::New();
	  aVoxelActor-> SetMapper (aVoxelMapper);
	  aVoxelActor-> GetProperty() ->SetRepresentationToWireframe();

	vtkActor *aVoxelContourActor=vtkActor::New();
	  aVoxelContourActor-> SetMapper( aVoxelContourMapper);
	  aVoxelContourActor-> GetProperty() ->BackfaceCullingOn();

	// Hexahedron

	vtkPoints *hexahedronPoints=vtkPoints::New();
	  hexahedronPoints-> SetNumberOfPoints (8);
	  hexahedronPoints-> InsertPoint (0, 0, 0 ,0);
	  hexahedronPoints-> InsertPoint (1, 1, 0 ,0);
	  hexahedronPoints-> InsertPoint (2, 1, 1 ,0);
	  hexahedronPoints-> InsertPoint (3, 0, 1 ,0);
	  hexahedronPoints-> InsertPoint (4, 0, 0 ,1);
	  hexahedronPoints-> InsertPoint (5, 1, 0, 1);
	  hexahedronPoints-> InsertPoint (6, 1, 1 ,1);
	  hexahedronPoints-> InsertPoint (7, 0, 1 ,1);
  
	vtkFloatArray *hexahedronScalars=vtkFloatArray::New();
	  hexahedronScalars-> SetNumberOfTuples (8);
	  hexahedronScalars-> InsertValue (0, 0);
	  hexahedronScalars-> InsertValue (1, 1);
	  hexahedronScalars-> InsertValue (2, 0);
	  hexahedronScalars-> InsertValue (3, 0);
	  hexahedronScalars-> InsertValue (4, 0);
	  hexahedronScalars-> InsertValue (5, 0);
	  hexahedronScalars-> InsertValue (6, 0);
	  hexahedronScalars-> InsertValue (7, 0);

	vtkHexahedron *aHexahedron=vtkHexahedron::New();
	  aHexahedron-> GetPointIds() ->SetId (0 ,0);
	  aHexahedron-> GetPointIds() ->SetId (1 ,1);
	  aHexahedron-> GetPointIds() ->SetId (2 ,2);
	  aHexahedron-> GetPointIds() ->SetId (3 ,3);
	  aHexahedron-> GetPointIds() ->SetId (4 ,4);
	  aHexahedron-> GetPointIds() ->SetId (5 ,5);
	  aHexahedron-> GetPointIds() ->SetId (6 ,6);
	  aHexahedron-> GetPointIds() ->SetId (7 ,7);
  
  
	vtkUnstructuredGrid *aHexahedronGrid=vtkUnstructuredGrid::New();
	  aHexahedronGrid-> Allocate (1 ,1);
	  aHexahedronGrid-> InsertNextCell 
		  (aHexahedron-> GetCellType(), aHexahedron-> GetPointIds());
	  aHexahedronGrid-> SetPoints (hexahedronPoints);
	  aHexahedronGrid-> GetPointData() ->SetScalars (hexahedronScalars);

	vtkContourFilter *hexahedronContours=vtkContourFilter::New();
	  hexahedronContours-> SetInput (aHexahedronGrid);
	  hexahedronContours-> SetValue (0, 0.5);

	vtkDataSetMapper *aHexahedronContourMapper=vtkDataSetMapper::New();
	  aHexahedronContourMapper-> SetInputConnection 
		                         (hexahedronContours-> GetOutputPort());
	  aHexahedronContourMapper-> ScalarVisibilityOff();

	vtkDataSetMapper *aHexahedronMapper=vtkDataSetMapper::New();
	  aHexahedronMapper-> SetInput (aHexahedronGrid);
	  aHexahedronMapper-> ScalarVisibilityOff();

	vtkActor *aHexahedronActor=vtkActor::New();
	  aHexahedronActor-> SetMapper (aHexahedronMapper);
	  aHexahedronActor-> GetProperty()-> BackfaceCullingOn();
	  aHexahedronActor-> GetProperty() ->SetRepresentationToWireframe();

	vtkActor *aHexahedronContourActor=vtkActor::New();
	  aHexahedronContourActor-> SetMapper (aHexahedronContourMapper);
	  aHexahedronContourActor-> GetProperty() ->BackfaceCullingOn();

	// Tetra

	vtkPoints *tetraPoints=vtkPoints::New();
	  tetraPoints-> SetNumberOfPoints (4);
	  tetraPoints-> InsertPoint (0, 0 ,0 ,0);
	  tetraPoints-> InsertPoint (1, 1 ,0,0);
	  tetraPoints-> InsertPoint (2 ,.5, 1 ,0);
	  tetraPoints-> InsertPoint (3 ,.5 ,.5, 1);

	vtkFloatArray *tetraScalars=vtkFloatArray::New();
	  tetraScalars-> SetNumberOfTuples( 4);
	  tetraScalars-> InsertValue (0 ,1);
	  tetraScalars-> InsertValue (1 ,0);
	  tetraScalars-> InsertValue (2 ,0);
	  tetraScalars-> InsertValue (3 ,0);

	vtkTetra *aTetra=vtkTetra::New();
	  aTetra-> GetPointIds()-> SetId( 0 ,0);
	  aTetra-> GetPointIds()-> SetId( 1 ,1);
	  aTetra-> GetPointIds()-> SetId( 2 ,2);
	  aTetra-> GetPointIds()-> SetId( 3, 3);

	vtkUnstructuredGrid *aTetraGrid=vtkUnstructuredGrid::New();
	  aTetraGrid-> Allocate( 1 ,1);
	  aTetraGrid-> InsertNextCell( aTetra-> GetCellType(), aTetra-> GetPointIds());
	  aTetraGrid-> SetPoints (tetraPoints);
	  aTetraGrid-> GetPointData() ->SetScalars (tetraScalars);

	vtkContourFilter *tetraContours=vtkContourFilter::New();
	  tetraContours-> SetInput (aTetraGrid);
	  tetraContours-> SetValue (0, 0.5);

	vtkDataSetMapper *aTetraContourMapper=vtkDataSetMapper::New();
	  aTetraContourMapper-> SetInputConnection (tetraContours-> GetOutputPort());
	  aTetraContourMapper-> ScalarVisibilityOff();

	vtkDataSetMapper *aTetraMapper=vtkDataSetMapper::New();
	  aTetraMapper ->SetInput (aTetraGrid);
	  aTetraMapper ->ScalarVisibilityOff();

	vtkActor *aTetraContourActor=vtkActor::New();
	  aTetraContourActor-> SetMapper (aTetraContourMapper);

	vtkActor *aTetraActor=vtkActor::New();
	  aTetraActor-> SetMapper (aTetraMapper);
	  aTetraActor-> GetProperty() ->SetRepresentationToWireframe();

	// Wedge

	vtkPoints *wedgePoints=vtkPoints::New();
	  wedgePoints-> SetNumberOfPoints( 6);
	  wedgePoints-> InsertPoint( 0 ,0, 1 ,0);
	  wedgePoints-> InsertPoint( 1 ,0, 0 ,0);
	  wedgePoints-> InsertPoint( 2, 0, .5, .5);
	  wedgePoints-> InsertPoint( 3, 1, 1 ,0);
	  wedgePoints-> InsertPoint( 4 ,1, 0, 0);
	  wedgePoints-> InsertPoint( 5, 1, .5, .5);

	vtkFloatArray *wedgeScalars=vtkFloatArray::New();
	  wedgeScalars-> SetNumberOfTuples( 6);
	  wedgeScalars-> InsertValue (0 ,1);
	  wedgeScalars-> InsertValue (1 ,1);
	  wedgeScalars-> InsertValue (2 ,0);
	  wedgeScalars-> InsertValue (3 ,1);
	  wedgeScalars-> InsertValue( 4 ,1);
	  wedgeScalars-> InsertValue( 5 ,0);

	vtkWedge *aWedge=vtkWedge::New();
	  aWedge-> GetPointIds()-> SetId( 0 ,0);
	  aWedge-> GetPointIds()-> SetId( 1 ,1);
	  aWedge-> GetPointIds()-> SetId( 2 ,2);
	  aWedge-> GetPointIds()-> SetId( 3 ,3);
	  aWedge-> GetPointIds()-> SetId( 4 ,4);
	  aWedge-> GetPointIds()-> SetId( 5 ,5);


	vtkUnstructuredGrid *aWedgeGrid=vtkUnstructuredGrid::New();
	  aWedgeGrid-> Allocate (1 ,1);
	  aWedgeGrid-> InsertNextCell (aWedge-> GetCellType(), aWedge-> GetPointIds());
	  aWedgeGrid-> SetPoints (wedgePoints);
	  aWedgeGrid ->GetPointData() ->SetScalars (wedgeScalars);

	vtkContourFilter *wedgeContours=vtkContourFilter::New();
	  wedgeContours-> SetInput (aWedgeGrid);
	  wedgeContours-> SetValue (0 ,0.5);

	vtkDataSetMapper *aWedgeContourMapper=vtkDataSetMapper::New();
	  aWedgeContourMapper-> SetInputConnection (wedgeContours-> GetOutputPort());
	  aWedgeContourMapper-> ScalarVisibilityOff();

	vtkDataSetMapper *aWedgeMapper=vtkDataSetMapper::New();
	  aWedgeMapper-> SetInput (aWedgeGrid);
	  aWedgeMapper-> ScalarVisibilityOff();

	vtkActor *aWedgeContourActor=vtkActor::New();
	  aWedgeContourActor-> SetMapper (aWedgeContourMapper);

	vtkActor *aWedgeActor=vtkActor::New();
	  aWedgeActor-> SetMapper (aWedgeMapper);
	  aWedgeActor-> GetProperty() ->SetRepresentationToWireframe();

	// Pyramid

	vtkPoints *pyramidPoints=vtkPoints::New();
	  pyramidPoints-> SetNumberOfPoints (5);
	  pyramidPoints-> InsertPoint (0, 0 ,0 ,0);
	  pyramidPoints-> InsertPoint (1, 1 ,0 ,0);
	  pyramidPoints-> InsertPoint( 2, 1 ,1 ,0);
	  pyramidPoints-> InsertPoint( 3, 0 ,1 ,0);
	  pyramidPoints-> InsertPoint( 4, .5 ,.5 ,1);

	vtkFloatArray *pyramidScalars=vtkFloatArray::New();
	  pyramidScalars-> SetNumberOfTuples( 5);
	  pyramidScalars-> InsertValue (0, 1);
	  pyramidScalars-> InsertValue (1, 1);
	  pyramidScalars-> InsertValue (2, 1);
	  pyramidScalars-> InsertValue (3, 1);
	  pyramidScalars-> InsertValue (4, 0);

	vtkPyramid *aPyramid=vtkPyramid::New();
	  aPyramid-> GetPointIds()-> SetId (0 ,0);
	  aPyramid-> GetPointIds()-> SetId (1, 1);
	  aPyramid-> GetPointIds()-> SetId( 2, 2);
	  aPyramid-> GetPointIds()-> SetId( 3 ,3);
	  aPyramid-> GetPointIds()-> SetId( 4 ,4);


	vtkUnstructuredGrid *aPyramidGrid=vtkUnstructuredGrid::New();
	  aPyramidGrid-> Allocate( 1 ,1);
	  aPyramidGrid-> InsertNextCell (aPyramid-> GetCellType(), aPyramid-> GetPointIds());
	  aPyramidGrid-> SetPoints (pyramidPoints);
	  aPyramidGrid-> GetPointData() ->SetScalars (pyramidScalars);

	vtkContourFilter *pyramidContours=vtkContourFilter::New();
	  pyramidContours-> SetInput (aPyramidGrid);
	  pyramidContours-> SetValue (0 ,0.5);

	vtkDataSetMapper *aPyramidContourMapper=vtkDataSetMapper::New();
	  aPyramidContourMapper-> SetInputConnection (pyramidContours-> GetOutputPort());
	  aPyramidContourMapper-> ScalarVisibilityOff();

	vtkDataSetMapper *aPyramidMapper=vtkDataSetMapper::New();
	  aPyramidMapper-> SetInput (aPyramidGrid);
	  aPyramidMapper-> ScalarVisibilityOff();

	vtkActor *aPyramidContourActor=vtkActor::New();
	  aPyramidContourActor-> SetMapper (aPyramidContourMapper);

	vtkActor *aPyramidActor=vtkActor::New();
	  aPyramidActor-> SetMapper (aPyramidMapper);
	  aPyramidActor-> GetProperty()-> SetRepresentationToWireframe();

	// Pixel

	vtkPoints *pixelPoints=vtkPoints::New();
	  pixelPoints-> SetNumberOfPoints (4);
	  pixelPoints-> InsertPoint( 0,0 ,0, 0);
	  pixelPoints-> InsertPoint( 1 ,1 ,0, 0);
	  pixelPoints-> InsertPoint( 2, 0 ,1,0);
	  pixelPoints-> InsertPoint( 3 ,1 ,1, 0);

	vtkFloatArray *pixelScalars=vtkFloatArray::New();
	  pixelScalars-> SetNumberOfTuples( 4);
	  pixelScalars-> InsertValue (0 ,1);
	  pixelScalars-> InsertValue (1 ,0);
	  pixelScalars-> InsertValue (2 ,0);
	  pixelScalars-> InsertValue (3 ,0);

	vtkPixel *aPixel=vtkPixel::New();
	  aPixel-> GetPointIds()-> SetId (0 ,0);
	  aPixel-> GetPointIds()-> SetId (1 ,1);
	  aPixel-> GetPointIds()-> SetId (2 ,2);
	  aPixel-> GetPointIds()-> SetId (3 ,3);

	vtkUnstructuredGrid *aPixelGrid=vtkUnstructuredGrid::New();
	  aPixelGrid-> Allocate (1, 1);
	  aPixelGrid-> InsertNextCell (aPixel->GetCellType(),aPixel->GetPointIds());
	  aPixelGrid-> SetPoints (pixelPoints);
	  aPixelGrid-> GetPointData() ->SetScalars (pixelScalars);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -