📄 三角化.cpp
字号:
vtkContourFilter *pixelContours=vtkContourFilter::New();
pixelContours ->SetInput (aPixelGrid);
pixelContours ->SetValue (0,0.5);
vtkDataSetMapper *aPixelContourMapper=vtkDataSetMapper::New();
aPixelContourMapper-> SetInputConnection (pixelContours->GetOutputPort());
aPixelContourMapper-> ScalarVisibilityOff();
vtkDataSetMapper *aPixelMapper=vtkDataSetMapper::New();
aPixelMapper-> SetInput (aPixelGrid);
aPixelMapper-> ScalarVisibilityOff();
vtkActor *aPixelContourActor=vtkActor::New();
aPixelContourActor-> SetMapper (aPixelContourMapper);
vtkActor *aPixelActor=vtkActor::New();
aPixelActor-> SetMapper (aPixelMapper);
aPixelActor-> GetProperty() ->BackfaceCullingOn();
aPixelActor-> GetProperty() ->SetRepresentationToWireframe();
// Quad
vtkPoints *quadPoints=vtkPoints::New();
quadPoints-> SetNumberOfPoints (4);
quadPoints-> InsertPoint( 0, 0, 0, 0);
quadPoints-> InsertPoint( 1, 1, 0, 0);
quadPoints-> InsertPoint( 2, 1, 1, 0);
quadPoints-> InsertPoint( 3, 0, 1, 0);
vtkFloatArray *quadScalars=vtkFloatArray::New();
quadScalars-> SetNumberOfTuples( 4);
quadScalars-> InsertValue( 0 ,1);
quadScalars-> InsertValue( 1 ,0);
quadScalars-> InsertValue( 2 ,0);
quadScalars-> InsertValue( 3 ,0);
vtkQuad *aQuad=vtkQuad::New();
aQuad-> GetPointIds() ->SetId( 0 ,0);
aQuad-> GetPointIds() ->SetId( 1 ,1);
aQuad-> GetPointIds() ->SetId( 2 ,2);
aQuad-> GetPointIds() ->SetId( 3 ,3);
vtkUnstructuredGrid *aQuadGrid=vtkUnstructuredGrid::New();
aQuadGrid-> Allocate( 1 ,1);
aQuadGrid-> InsertNextCell( aQuad-> GetCellType(), aQuad-> GetPointIds());
aQuadGrid-> SetPoints (quadPoints);
aQuadGrid-> GetPointData()-> SetScalars (quadScalars);
vtkContourFilter *quadContours=vtkContourFilter::New();
quadContours-> SetInput (aQuadGrid);
quadContours-> SetValue( 0 ,0.5);
vtkDataSetMapper *aQuadContourMapper=vtkDataSetMapper::New();
aQuadContourMapper-> SetInputConnection (quadContours-> GetOutputPort());
aQuadContourMapper-> ScalarVisibilityOff();
vtkDataSetMapper *aQuadMapper=vtkDataSetMapper::New();
aQuadMapper-> SetInput (aQuadGrid);
aQuadMapper-> ScalarVisibilityOff();
vtkActor *aQuadContourActor=vtkActor::New();
aQuadContourActor-> SetMapper (aQuadContourMapper);
vtkActor *aQuadActor=vtkActor::New();
aQuadActor-> SetMapper (aQuadMapper);
aQuadActor-> GetProperty()-> BackfaceCullingOn();
aQuadActor-> GetProperty() ->SetRepresentationToWireframe();
// Triangle
vtkPoints *trianglePoints=vtkPoints::New();
trianglePoints-> SetNumberOfPoints( 3);
trianglePoints-> InsertPoint( 0, 0 ,0 ,0);
trianglePoints-> InsertPoint( 1, 1 ,0 ,0);
trianglePoints-> InsertPoint( 2, .5 ,.5 ,0);
vtkFloatArray *triangleScalars=vtkFloatArray::New();
triangleScalars-> SetNumberOfTuples( 3);
triangleScalars-> InsertValue( 0, 1);
triangleScalars-> InsertValue( 1, 0);
triangleScalars-> InsertValue( 2, 0);
vtkTriangle *aTriangle=vtkTriangle::New();
aTriangle-> GetPointIds()-> SetId( 0, 0);
aTriangle-> GetPointIds()-> SetId( 1, 1);
aTriangle-> GetPointIds()-> SetId( 2, 2);
vtkUnstructuredGrid *aTriangleGrid=vtkUnstructuredGrid::New();
aTriangleGrid-> Allocate( 1, 1);
aTriangleGrid-> InsertNextCell
( aTriangle-> GetCellType(), aTriangle-> GetPointIds());
aTriangleGrid-> SetPoints (trianglePoints);
aTriangleGrid-> GetPointData()-> SetScalars (triangleScalars);
vtkContourFilter *triangleContours=vtkContourFilter::New();
triangleContours-> SetInput (aTriangleGrid);
triangleContours-> SetValue (0 ,0.5);
vtkDataSetMapper *aTriangleContourMapper=vtkDataSetMapper::New();
aTriangleContourMapper-> SetInputConnection (triangleContours-> GetOutputPort());
aTriangleContourMapper-> ScalarVisibilityOff();
vtkActor *aTriangleContourActor=vtkActor::New();
aTriangleContourActor-> SetMapper (aTriangleContourMapper);
vtkDataSetMapper *aTriangleMapper=vtkDataSetMapper::New();
aTriangleMapper-> SetInput (aTriangleGrid);
aTriangleMapper-> ScalarVisibilityOff();
vtkActor *aTriangleActor=vtkActor::New();
aTriangleActor-> SetMapper (aTriangleMapper);
aTriangleActor-> GetProperty()-> BackfaceCullingOn();
aTriangleActor-> GetProperty()-> SetRepresentationToWireframe();
// Polygon
vtkPoints *polygonPoints=vtkPoints::New();
polygonPoints-> SetNumberOfPoints (4);
polygonPoints-> InsertPoint (0 ,0 ,0 ,0);
polygonPoints-> InsertPoint (1,1 ,0 ,0);
polygonPoints-> InsertPoint (2, 1, 1, 0);
polygonPoints-> InsertPoint (3 ,0, 1 ,0);
vtkFloatArray *polygonScalars=vtkFloatArray::New();
polygonScalars-> SetNumberOfTuples( 4);
polygonScalars-> InsertValue (0 ,1);
polygonScalars-> InsertValue (1 ,0);
polygonScalars-> InsertValue (2 ,0);
polygonScalars-> InsertValue (3 ,0);
vtkPolygon *aPolygon=vtkPolygon::New();
aPolygon-> GetPointIds() ->SetNumberOfIds( 4);
aPolygon-> GetPointIds() ->SetId( 0 ,0);
aPolygon-> GetPointIds() ->SetId( 1 ,1);
aPolygon-> GetPointIds() ->SetId( 2, 2);
aPolygon-> GetPointIds() ->SetId( 3, 3);
vtkUnstructuredGrid *aPolygonGrid=vtkUnstructuredGrid::New();
aPolygonGrid-> Allocate (1, 1);
aPolygonGrid-> InsertNextCell (aPolygon-> GetCellType() ,aPolygon-> GetPointIds());
aPolygonGrid-> SetPoints (polygonPoints);
aPolygonGrid-> GetPointData() ->SetScalars (polygonScalars);
vtkContourFilter *polygonContours=vtkContourFilter::New();
polygonContours-> SetInput (aPolygonGrid);
polygonContours-> SetValue (0 ,0.5);
vtkDataSetMapper *aPolygonContourMapper=vtkDataSetMapper::New();
aPolygonContourMapper-> SetInputConnection (polygonContours-> GetOutputPort());
aPolygonContourMapper-> ScalarVisibilityOff();
vtkDataSetMapper *aPolygonMapper=vtkDataSetMapper::New();
aPolygonMapper-> SetInput (aPolygonGrid);
aPolygonMapper-> ScalarVisibilityOff();
vtkActor *aPolygonContourActor=vtkActor::New();
aPolygonContourActor-> SetMapper (aPolygonContourMapper);
vtkActor *aPolygonActor=vtkActor::New();
aPolygonActor-> SetMapper (aPolygonMapper);
aPolygonActor-> GetProperty()-> BackfaceCullingOn();
aPolygonActor-> GetProperty()-> SetRepresentationToWireframe();
// Triangle strip
vtkPoints *triangleStripPoints=vtkPoints::New();
triangleStripPoints-> SetNumberOfPoints (5);
triangleStripPoints-> InsertPoint (0 ,0 ,1 ,0);
triangleStripPoints-> InsertPoint (1 ,0 ,0 ,0);
triangleStripPoints-> InsertPoint (2 ,1 ,1 ,0);
triangleStripPoints-> InsertPoint( 3 ,1 ,0 ,0);
triangleStripPoints-> InsertPoint( 4 ,2 ,1 ,0);
vtkFloatArray *triangleStripScalars=vtkFloatArray::New();
triangleStripScalars-> SetNumberOfTuples( 5);
triangleStripScalars-> InsertValue( 0 ,1);
triangleStripScalars-> InsertValue( 1 ,0);
triangleStripScalars-> InsertValue( 2 ,0);
triangleStripScalars-> InsertValue( 3 ,0);
triangleStripScalars-> InsertValue( 4 ,0);
vtkTriangleStrip *aTriangleStrip=vtkTriangleStrip::New();
aTriangleStrip-> GetPointIds()-> SetNumberOfIds( 5);
aTriangleStrip-> GetPointIds()-> SetId( 0 ,0);
aTriangleStrip-> GetPointIds()-> SetId( 1, 1);
aTriangleStrip-> GetPointIds()-> SetId( 2, 2);
aTriangleStrip-> GetPointIds()-> SetId( 3, 3);
aTriangleStrip-> GetPointIds()-> SetId( 4, 4);
vtkUnstructuredGrid *aTriangleStripGrid=vtkUnstructuredGrid::New();
aTriangleStripGrid-> Allocate( 1, 1);
aTriangleStripGrid-> InsertNextCell
( aTriangleStrip-> GetCellType(), aTriangleStrip-> GetPointIds());
aTriangleStripGrid ->SetPoints (triangleStripPoints);
aTriangleStripGrid-> GetPointData()-> SetScalars (triangleStripScalars);
vtkDataSetMapper *aTriangleStripMapper=vtkDataSetMapper::New();
aTriangleStripMapper-> SetInput (aTriangleStripGrid);
aTriangleStripMapper-> ScalarVisibilityOff();
vtkContourFilter *triangleStripContours=vtkContourFilter::New();
triangleStripContours-> SetInput (aTriangleStripGrid);
triangleStripContours-> SetValue (0 ,0.5);
vtkDataSetMapper *aTriangleStripContourMapper=vtkDataSetMapper::New();
aTriangleStripContourMapper-> SetInputConnection
(triangleStripContours-> GetOutputPort());
aTriangleStripContourMapper-> ScalarVisibilityOff();
vtkActor *aTriangleStripContourActor=vtkActor::New();
aTriangleStripContourActor-> SetMapper (aTriangleStripContourMapper);
vtkActor *aTriangleStripActor=vtkActor::New();
aTriangleStripActor-> SetMapper (aTriangleStripMapper);
aTriangleStripActor-> GetProperty()-> BackfaceCullingOn();
aTriangleStripActor-> GetProperty()-> SetRepresentationToWireframe();
// Line
vtkPoints *linePoints=vtkPoints::New();
linePoints-> SetNumberOfPoints( 2);
linePoints-> InsertPoint( 0 ,0 ,0 ,0);
linePoints-> InsertPoint( 1 ,1 ,1 ,0);
vtkFloatArray *lineScalars=vtkFloatArray::New();
lineScalars-> SetNumberOfTuples( 2);
lineScalars-> InsertValue( 0 ,1);
lineScalars-> InsertValue( 1 ,0);
vtkLine *aLine=vtkLine::New();
aLine-> GetPointIds()-> SetId( 0, 0);
aLine-> GetPointIds()-> SetId( 1, 1);
vtkUnstructuredGrid *aLineGrid=vtkUnstructuredGrid::New();
aLineGrid-> Allocate (1, 1);
aLineGrid-> InsertNextCell( aLine-> GetCellType() ,aLine-> GetPointIds());
aLineGrid-> SetPoints (linePoints);
aLineGrid-> GetPointData() ->SetScalars (lineScalars);
vtkContourFilter *lineContours=vtkContourFilter::New();
lineContours-> SetInput (aLineGrid);
lineContours-> SetValue (0, 0.5);
vtkDataSetMapper *aLineContourMapper=vtkDataSetMapper::New();
aLineContourMapper-> SetInputConnection (lineContours-> GetOutputPort());
aLineContourMapper-> ScalarVisibilityOff();
vtkActor *aLineContourActor=vtkActor::New();
aLineContourActor-> SetMapper (aLineContourMapper);
vtkDataSetMapper *aLineMapper=vtkDataSetMapper::New();
aLineMapper-> SetInput (aLineGrid);
aLineMapper-> ScalarVisibilityOff();
vtkActor *aLineActor=vtkActor::New();
aLineActor-> SetMapper (aLineMapper);
aLineActor-> GetProperty() ->BackfaceCullingOn();
aLineActor-> GetProperty() ->SetRepresentationToWireframe();
// Polyline
vtkPoints *polyLinePoints=vtkPoints::New();
polyLinePoints-> SetNumberOfPoints (3);
polyLinePoints-> InsertPoint (0, 0, 0, 0);
polyLinePoints-> InsertPoint (1, 1, 1, 0);
polyLinePoints-> InsertPoint (2, 1, 0, 0);
vtkFloatArray *polyLineScalars=vtkFloatArray::New();
polyLineScalars-> SetNumberOfTuples( 3);
polyLineScalars-> InsertValue (0 ,1);
polyLineScalars-> InsertValue (1, 0);
polyLineScalars-> InsertValue (2 ,0);
vtkPolyLine *aPolyLine=vtkPolyLine::New();
aPolyLine-> GetPointIds()-> SetNumberOfIds( 3);
aPolyLine-> GetPointIds()-> SetId (0, 0);
aPolyLine-> GetPointIds()-> SetId (1 ,1);
aPolyLine-> GetPointIds()-> SetId (2, 2);
vtkUnstructuredGrid *aPolyLineGrid=vtkUnstructuredGrid::New();
aPolyLineGrid-> Allocate (1, 1);
aPolyLineGrid-> InsertNextCell
( aPolyLine-> GetCellType(), aPolyLine-> GetPointIds());
aPolyLineGrid-> SetPoints ( polyLinePoints);
aPolyLineGrid-> GetPointData() ->SetScalars ( polyLineScalars);
vtkContourFilter *polyLineContours=vtkContourFilter::New();
polyLineContours-> SetInput (aPolyLineGrid);
polyLineContours-> SetValue (0, 0.5);
vtkDataSetMapper *aPolyLineContourMapper=vtkDataSetMapper::New();
aPolyLineContourMapper-> SetInputConnection (polyLineContours-> GetOutputPort());
aPolyLineContourMapper-> ScalarVisibilityOff();
vtkActor *aPolyLineContourActor=vtkActor::New();
aPolyLineContourActor-> SetMapper (aPolyLineContourMapper);
vtkDataSetMapper *aPolyLineMapper=vtkDataSetMapper::New();
aPolyLineMapper-> SetInput (aPolyLineGrid);
aPolyLineMapper-> ScalarVisibilityOff();
vtkActor *aPolyLineActor=vtkActor::New();
aPolyLineActor ->SetMapper (aPolyLineMapper);
aPolyLineActor ->GetProperty() ->BackfaceCullingOn();
aPolyLineActor ->GetProperty() ->SetRepresentationToWireframe();
// Vertex
vtkPoints *vertexPoints=vtkPoints::New();
vertexPoints-> SetNumberOfPoints (1);
vertexPoints-> InsertPoint( 0, 0, 0, 0);
vtkFloatArray *vertexScalars=vtkFloatArray::New();
vertexScalars-> SetNumberOfTuples (1);
vertexScalars-> InsertValue (0, 1);
vtkVertex *aVertex=vtkVertex::New();
aVertex-> GetPointIds()-> SetId (0, 0);
vtkUnstructuredGrid *aVertexGrid=vtkUnstructuredGrid::New();
aVertexGrid-> Allocate (1, 1);
aVertexGrid-> InsertNextCell (aVertex-> GetCellType(), aVertex ->GetPointIds());
aVertexGrid ->SetPoints (vertexPoints);
aVertexGrid-> GetPointData() ->SetScalars (vertexScalars);
vtkContourFilter *vertexContours=vtkContourFilter::New();
vertexContours-> SetInput (aVertexGrid);
vertexContours-> SetValue (0 ,1);
vtkDataSetMapper *aVertexContourMapper=vtkDataSetMapper::New();
aVertexContourMapper-> SetInputConnection (vertexContours-> GetOutputPort());
aVertexContourMapper-> ScalarVisibilityOff();
vtkActor *aVertexContourActor=vtkActor::New();
aVertexContourActor-> SetMapper (aVertexContourMapper);
aVertexContourActor-> GetProperty()-> SetRepresentationToWireframe();
vtkDataSetMapper *aVertexMapper=vtkDataSetMapper::New();
aVertexMapper-> SetInput (aVertexGrid);
aVertexMapper-> ScalarVisibilityOff();
vtkActor *aVertexActor=vtkActor::New();
aVertexActor ->SetMapper (aVertexMapper);
aVertexActor ->GetProperty()-> BackfaceCullingOn();
// Poly Vertex
vtkPoints *polyVertexPoints=vtkPoints::New();
polyVertexPoints-> SetNumberOfPoints( 3);
polyVertexPoints-> InsertPoint (0 ,0 ,0 ,0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -