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

📄 三角化.cpp

📁 VTK入门样例(种类齐全)
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	  polyVertexPoints-> InsertPoint( 1 ,1 ,0 ,0);
	  polyVertexPoints-> InsertPoint( 2 ,1 ,1 ,0);

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

	vtkPolyVertex *aPolyVertex=vtkPolyVertex::New();
	  aPolyVertex-> GetPointIds() ->SetNumberOfIds (3);
	  aPolyVertex-> GetPointIds() ->SetId( 0,0);
	  aPolyVertex-> GetPointIds() ->SetId( 1,1);
	  aPolyVertex-> GetPointIds() ->SetId( 2,2);

	vtkUnstructuredGrid *aPolyVertexGrid=vtkUnstructuredGrid::New();
	  aPolyVertexGrid-> Allocate (1, 1);
	  aPolyVertexGrid-> InsertNextCell
						(aPolyVertex->GetCellType(),aPolyVertex->GetPointIds());
	  aPolyVertexGrid-> SetPoints (polyVertexPoints);
	  aPolyVertexGrid-> GetPointData() ->SetScalars (polyVertexScalars);

	vtkContourFilter *polyVertexContours=vtkContourFilter::New();
	  polyVertexContours-> SetInput (aPolyVertexGrid);
	  polyVertexContours-> SetValue (0, 0);

	vtkDataSetMapper *aPolyVertexContourMapper=vtkDataSetMapper::New();
	  aPolyVertexContourMapper-> SetInputConnection (polyVertexContours-> GetOutputPort());
	  aPolyVertexContourMapper-> ScalarVisibilityOff();

	vtkActor *aPolyVertexContourActor=vtkActor::New();
	  aPolyVertexContourActor-> SetMapper (aPolyVertexContourMapper);
	  aPolyVertexContourActor-> GetProperty()-> SetRepresentationToWireframe();

	vtkDataSetMapper *aPolyVertexMapper=vtkDataSetMapper::New();
	  aPolyVertexMapper-> SetInput (aPolyVertexGrid);
	  aPolyVertexMapper-> ScalarVisibilityOff();

	vtkActor *aPolyVertexActor=vtkActor::New();
	  aPolyVertexActor-> SetMapper(aPolyVertexMapper);

	// Pentagonal prism

	vtkPoints *pentaPoints=vtkPoints::New();
	  pentaPoints-> SetNumberOfPoints (10);
	  pentaPoints-> InsertPoint (0, 0.25 ,0.0 ,0.0  );
	  pentaPoints-> InsertPoint (1, 0.75 ,0.0 ,0.0 );
	  pentaPoints-> InsertPoint (2, 1.0  ,0.5 ,0.0  );
	  pentaPoints-> InsertPoint (3, 0.5  ,1.0 ,0.0 );
	  pentaPoints-> InsertPoint (4, 0.0  ,0.5 ,0.0  );
	  pentaPoints-> InsertPoint (5, 0.25 ,0.0 ,1.0  );
	  pentaPoints-> InsertPoint (6, 0.75 ,0.0 ,1.0  );
	  pentaPoints-> InsertPoint (7, 1.0  ,0.5 ,1.0  );
	  pentaPoints-> InsertPoint (8, 0.5  ,1.0 ,1.0 );
	  pentaPoints-> InsertPoint (9, 0.0  ,0.5 ,1.0 );

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

	vtkPentagonalPrism *aPenta=vtkPentagonalPrism::New();
	  aPenta-> GetPointIds() ->SetId( 0 ,0);
	  aPenta-> GetPointIds() ->SetId( 1, 1);
	  aPenta-> GetPointIds() ->SetId( 2 ,2);
	  aPenta-> GetPointIds() ->SetId( 3 ,3);
	  aPenta-> GetPointIds() ->SetId( 4 ,4);
	  aPenta-> GetPointIds() ->SetId( 5 ,5);
	  aPenta-> GetPointIds() ->SetId( 6, 6);
	  aPenta-> GetPointIds() ->SetId( 7 ,7);
	  aPenta-> GetPointIds() ->SetId( 8, 8);
	  aPenta-> GetPointIds() ->SetId( 9 ,9);

  
	vtkUnstructuredGrid *aPentaGrid=vtkUnstructuredGrid::New();
	  aPentaGrid ->Allocate (1 ,1);
	  aPentaGrid ->InsertNextCell
					(aPenta-> GetCellType(), aPenta-> GetPointIds());
	  aPentaGrid ->SetPoints (pentaPoints);
	  aPentaGrid ->GetPointData() ->SetScalars (pentaScalars);

	vtkContourFilter *pentaContours=vtkContourFilter::New();
	  pentaContours-> SetInput (aPentaGrid);
	  pentaContours-> SetValue (0, 0.5);

	vtkDataSetMapper *aPentaContourMapper=vtkDataSetMapper::New();
	  aPentaContourMapper-> SetInputConnection (pentaContours-> GetOutputPort());
	  aPentaContourMapper-> ScalarVisibilityOff();

	vtkDataSetMapper *aPentaMapper=vtkDataSetMapper::New();
	  aPentaMapper-> SetInput (aPentaGrid);
	  aPentaMapper-> ScalarVisibilityOff();

	vtkActor *aPentaActor=vtkActor::New();
	  aPentaActor-> SetMapper (aPentaMapper);
	  aPentaActor-> GetProperty()-> BackfaceCullingOn();
	  aPentaActor-> GetProperty()-> SetRepresentationToWireframe();

	vtkActor *aPentaContourActor=vtkActor::New();
	  aPentaContourActor-> SetMapper (aPentaContourMapper);
	  aPentaContourActor-> GetProperty()-> BackfaceCullingOn();


	// Hexagonal prism

	vtkPoints *hexaPoints=vtkPoints::New();
	  hexaPoints-> SetNumberOfPoints( 12);
	  hexaPoints-> InsertPoint( 0, 0.0, 0.0 ,0.0 ); 
	  hexaPoints-> InsertPoint( 1, 0.5, 0.0 ,0.0 );
	  hexaPoints-> InsertPoint( 2, 1.0, 0.5 ,0.0 ); 
	  hexaPoints-> InsertPoint( 3, 1.0, 1.0 ,0.0 );
	  hexaPoints-> InsertPoint( 4, 0.5, 1.0 ,0.0 ); 
	  hexaPoints-> InsertPoint( 5, 0.0, 0.5 ,0.0 );
	  hexaPoints-> InsertPoint( 6, 0.0, 0.0 ,1.0  );
	  hexaPoints-> InsertPoint( 7, 0.5, 0.0 ,1.0 );
	  hexaPoints-> InsertPoint( 8, 1.0 ,0.5 ,1.0  );
	  hexaPoints-> InsertPoint( 9, 1.0 ,1.0,1.0 );
	  hexaPoints-> InsertPoint( 10, 0.5, 1.0, 1.0 ); 
	  hexaPoints-> InsertPoint( 11, 0.0 ,0.5 ,1.0); 
                         
	vtkFloatArray *hexaScalars=vtkFloatArray::New();
	  hexaScalars-> SetNumberOfTuples( 12); 
	  hexaScalars-> InsertValue( 0 ,0); 
	  hexaScalars-> InsertValue( 1 ,0); 
	  hexaScalars-> InsertValue( 2 ,0); 
	  hexaScalars-> InsertValue( 3 ,0); 
	  hexaScalars-> InsertValue( 4 ,0); 
	  hexaScalars-> InsertValue( 5 ,0); 
	  hexaScalars-> InsertValue( 6 ,1); 
	  hexaScalars-> InsertValue( 7 ,1); 
	  hexaScalars-> InsertValue( 8 ,1); 
	  hexaScalars-> InsertValue( 9 ,1); 
	  hexaScalars-> InsertValue( 10 ,1); 
	  hexaScalars-> InsertValue( 11 ,1); 

	vtkHexagonalPrism *aHexa=vtkHexagonalPrism::New();
	  aHexa-> GetPointIds()-> SetId( 0 ,0); 
	  aHexa-> GetPointIds()-> SetId( 1, 1); 
	  aHexa-> GetPointIds()-> SetId( 2, 2); 
	  aHexa-> GetPointIds()-> SetId( 3, 3); 
	  aHexa-> GetPointIds()-> SetId( 4, 4); 
	  aHexa-> GetPointIds()-> SetId( 5, 5); 
	  aHexa-> GetPointIds()-> SetId( 6, 6); 
	  aHexa-> GetPointIds()-> SetId( 7, 7); 
	  aHexa-> GetPointIds()-> SetId( 8, 8); 
	  aHexa-> GetPointIds()-> SetId( 9, 9); 
	  aHexa-> GetPointIds()-> SetId( 10 ,10); 
	  aHexa-> GetPointIds()-> SetId( 11, 11); 

  
	vtkUnstructuredGrid *aHexaGrid=vtkUnstructuredGrid::New();
	  aHexaGrid-> Allocate( 1, 1); 
	  aHexaGrid-> InsertNextCell(aHexa-> GetCellType(), aHexa-> GetPointIds()); 
	  aHexaGrid-> SetPoints( hexaPoints); 
	  aHexaGrid-> GetPointData() ->SetScalars (hexaScalars); 

	vtkContourFilter *hexaContours=vtkContourFilter::New();
	  hexaContours-> SetInput (aHexaGrid); 
	  hexaContours-> SetValue (0, 0.5); 

	vtkDataSetMapper *aHexaContourMapper=vtkDataSetMapper::New();
	  aHexaContourMapper-> SetInputConnection (hexaContours-> GetOutputPort()); 
	  aHexaContourMapper-> ScalarVisibilityOff(); 

	vtkDataSetMapper *aHexaMapper=vtkDataSetMapper::New();
	  aHexaMapper-> SetInput (aHexaGrid); 
	  aHexaMapper-> ScalarVisibilityOff(); 

	vtkActor *aHexaActor=vtkActor::New();
	  aHexaActor-> SetMapper (aHexaMapper); 
	  aHexaActor-> GetProperty() ->BackfaceCullingOn(); 
	  aHexaActor-> GetProperty() ->SetRepresentationToWireframe(); 

	vtkActor *aHexaContourActor=vtkActor::New();
	  aHexaContourActor-> SetMapper (aHexaContourMapper); 
	  aHexaContourActor-> GetProperty() ->BackfaceCullingOn(); 



	ren1->SetBackground( 0 ,0 ,0); 
	renWin-> SetSize( 400, 400); 

	ren1-> AddActor( aVoxelActor); 
    aVoxelActor-> GetProperty() ->SetDiffuseColor( 1 ,0 ,0); 
	ren1-> AddActor( aVoxelContourActor); 
	aVoxelContourActor ->GetProperty()-> SetDiffuseColor( 1 ,0, 0); 

	ren1-> AddActor( aHexahedronActor); 
	aHexahedronActor-> GetProperty()-> SetDiffuseColor (1, 1, 0); 
	ren1-> AddActor( aHexahedronContourActor); 
	aHexahedronContourActor-> GetProperty() ->SetDiffuseColor( 1, 1, 0); 

	ren1-> AddActor( aTetraActor); 
	aTetraActor ->GetProperty() ->SetDiffuseColor( 0 ,1, 0); 
	ren1-> AddActor (aTetraContourActor); 
	aTetraContourActor ->GetProperty() ->SetDiffuseColor (0 ,1, 0); 

	ren1-> AddActor (aWedgeActor); 
	aWedgeActor ->GetProperty() ->SetDiffuseColor (0 ,1 ,1); 
	ren1-> AddActor (aWedgeContourActor); 
	aWedgeContourActor ->GetProperty() ->SetDiffuseColor (0, 1, 1); 

	ren1-> AddActor (aPyramidActor); 
	aPyramidActor ->GetProperty()-> SetDiffuseColor (1, 0 ,1); 
	ren1-> AddActor (aPyramidContourActor); 
	aPyramidContourActor ->GetProperty() ->SetDiffuseColor (1 ,0, 1); 

	ren1-> AddActor (aPixelActor); 
	aPixelActor ->GetProperty() ->SetDiffuseColor (0, 1 ,1); 
	ren1-> AddActor (aPixelContourActor); 
	aPixelContourActor-> GetProperty() ->SetDiffuseColor (0 ,1, 1); 

	ren1-> AddActor( aQuadActor); 
	aQuadActor ->GetProperty()-> SetDiffuseColor (1 ,0, 1); 
	ren1-> AddActor( aQuadContourActor); 
	aQuadContourActor-> GetProperty() ->SetDiffuseColor (1, 0 ,1); 

	ren1-> AddActor (aTriangleActor); 
	aTriangleActor ->GetProperty() ->SetDiffuseColor( .3 ,1 ,.5); 
	ren1-> AddActor (aTriangleContourActor); 
	aTriangleContourActor ->GetProperty()-> SetDiffuseColor (.3, 1 ,.5); 

	ren1-> AddActor (aPolygonActor);
	aPolygonActor ->GetProperty() ->SetDiffuseColor (1 ,.4 ,.5); 
	ren1-> AddActor (aPolygonContourActor);
	aPolygonContourActor ->GetProperty()-> SetDiffuseColor (1 ,.4 ,.5); 

	ren1-> AddActor (aTriangleStripActor); 
	aTriangleStripActor ->GetProperty() ->SetDiffuseColor( .3, .7 ,1); 
	ren1-> AddActor (aTriangleStripContourActor); 
	aTriangleStripContourActor ->GetProperty() ->SetDiffuseColor (.3 ,.7 ,1); 

	ren1-> AddActor (aLineActor); 
	aLineActor ->GetProperty() ->SetDiffuseColor (.2 ,1 ,1); 
	ren1-> AddActor (aLineContourActor); 
	aLineContourActor ->GetProperty() ->SetDiffuseColor (.2 ,1 ,1); 

	ren1-> AddActor (aPolyLineActor); 
	aPolyLineActor ->GetProperty() ->SetDiffuseColor (1 ,1 ,1); 
	ren1-> AddActor (aPolyLineContourActor); 
	aPolyLineContourActor ->GetProperty() ->SetDiffuseColor( 1, 1, 1); 

	ren1-> AddActor (aVertexActor); 
	aVertexActor ->GetProperty() ->SetDiffuseColor( 1, 1, 1); 
	ren1-> AddActor (aVertexContourActor); 
	aVertexContourActor-> GetProperty() ->SetDiffuseColor (1 ,1, 1); 

	ren1-> AddActor (aPolyVertexActor); 
	aPolyVertexActor ->GetProperty() ->SetDiffuseColor (1 ,1, 1); 
	ren1-> AddActor (aPolyVertexContourActor); 
	aPolyVertexContourActor ->GetProperty() ->SetDiffuseColor (1,1 ,1); 

	ren1-> AddActor (aPentaActor); 
	aPentaActor ->GetProperty() ->SetDiffuseColor (.2 ,.4 ,.7); 
	ren1 ->AddActor (aPentaContourActor); 
	aPentaContourActor ->GetProperty() ->SetDiffuseColor (.2 ,.4 ,.7); 

	ren1-> AddActor (aHexaActor); 
	aHexaActor ->GetProperty() ->SetDiffuseColor (.7 ,.5 ,1); 
	ren1-> AddActor (aHexaContourActor); 
	aHexaContourActor ->GetProperty() ->SetDiffuseColor (.7, .5 ,1); 

	// places everyone!!
	aVoxelContourActor-> AddPosition(0, 0, 0); 
	aVoxelContourActor-> AddPosition( 0 ,2, 0); 
	aHexahedronContourActor-> AddPosition( 2, 0, 0); 
	aHexahedronContourActor-> AddPosition( 0,2 ,0); 
	aHexahedronActor-> AddPosition (2 ,0, 0); 
	aTetraContourActor-> AddPosition( 4, 0, 0); 
	aTetraContourActor-> AddPosition (0 ,2, 0); 
	aTetraActor-> AddPosition (4 ,0, 0); 
	aWedgeContourActor-> AddPosition (6, 0, 0); 
	aWedgeContourActor-> AddPosition (0, 2 ,0); 
	aWedgeActor-> AddPosition (6 ,0, 0); 
	aPyramidContourActor-> AddPosition (8, 0 ,0); 
	aPyramidContourActor-> AddPosition( 0, 2, 0); 
	aPyramidActor-> AddPosition (8 ,0, 0); 

	aPixelContourActor-> AddPosition( 0 ,4, 0); 
	aPixelContourActor-> AddPosition( 0 ,2, 0); 
	aPixelActor-> AddPosition (0, 4, 0); 
	aQuadContourActor-> AddPosition (2, 4, 0); 
	aQuadContourActor-> AddPosition (0 ,2, 0); 
	aQuadActor-> AddPosition( 2, 4 ,0); 
	aTriangleContourActor-> AddPosition( 4 ,4 ,0); 
	aTriangleContourActor-> AddPosition( 0, 2 ,0); 
	aTriangleActor-> AddPosition (4 ,4, 0); 
	aPolygonContourActor-> AddPosition( 6, 4 ,0); 
	aPolygonContourActor-> AddPosition( 0, 2 ,0); 
	aPolygonActor-> AddPosition (6, 4, 0); 
	aTriangleStripContourActor-> AddPosition( 8, 4, 0); 
	aTriangleStripContourActor-> AddPosition( 0 ,2, 0); 
	aTriangleStripActor-> AddPosition( 8 ,4 ,0); 

	aLineContourActor-> AddPosition( 0 ,8, 0); 
	aLineContourActor-> AddPosition( 0 ,2, 0); 
	aLineActor-> AddPosition( 0 ,8, 0); 
	aPolyLineContourActor-> AddPosition( 2, 8, 0); 
	aPolyLineContourActor-> AddPosition( 0, 2, 0); 
	aPolyLineActor-> AddPosition (2, 8 ,0); 

	aVertexContourActor-> AddPosition( 0 ,12 ,0); 
	aVertexContourActor-> AddPosition( 0, 2, 0); 
	aVertexActor-> AddPosition( 0 ,12, 0); 
	aPolyVertexContourActor-> AddPosition( 2, 12, 0); 
	aPolyVertexContourActor-> AddPosition( 0, 2, 0); 
	aPolyVertexActor-> AddPosition (2, 12 ,0); 

	aPentaContourActor-> AddPosition( 4, 8, 0); 
	aPentaContourActor-> AddPosition (0 ,2, 0); 
	aPentaActor-> AddPosition( 4, 8 ,0); 
	aHexaContourActor-> AddPosition( 6, 8, 0); 
	aHexaContourActor-> AddPosition( 0, 2 ,0); 
	aHexaActor-> AddPosition( 6, 8, 0); 

/*
	BuildBackdrop -1 11 -1 16 -1 2 .1

	ren1-> AddActor base
	base-> GetProperty() ->SetDiffuseColor (.2 .2 .2
	ren1-> AddActor left
	left-> GetProperty() ->SetDiffuseColor (.2 .2 .2
	ren1-> AddActor back
	back-> GetProperty() ->SetDiffuseColor (.2 .2 .2
*/

	ren1->ResetCamera();

	renWin->SetSize(700,700);
	renWin->Render();
	iren->Start();

	ren1->Delete();
	iren->Delete();
	renWin->Delete();
}






⌨️ 快捷键说明

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