728x90
PolyData의 위치 및 회전을 제어하기 위해서 Transformfilter 를 사용한다.
우선 적용할 vtkTransform을 이용해 transformation matrix 를 생성한다.
변환할 객체 정보를 vtkTransformPolyDataFilter 에 입력하고 polydata 값을 연결한다.
filter를 mapper에 연결하고 최종적으로 actor에 연결하면된다.
vtkFloatArray Scalars = vtkFloatArray.New();
Scalars.InsertNextTuple1(1.0);
Scalars.InsertNextTuple1(0.0);
Scalars.InsertNextTuple1(0.0);
Scalars.InsertNextTuple1(1.0);
Scalars.InsertNextTuple1(0.0);
Scalars.InsertNextTuple1(0.0);
Scalars.InsertNextTuple1(0.0);
Scalars.InsertNextTuple1(0.0);
vtkPoints Points = vtkPoints.New();
Points.InsertNextPoint(0, 0, 0);
Points.InsertNextPoint(1, 1, 0);
Points.InsertNextPoint(0, 1, 0);
Points.InsertNextPoint(1, 0, 0);
Points.InsertNextPoint(0, 0, 1);
Points.InsertNextPoint(1, 0, 1);
Points.InsertNextPoint(1, 1, 1);
Points.InsertNextPoint(0, 1, 1);
vtkIdList Ids = vtkIdList.New();
Ids.InsertNextId(0);
Ids.InsertNextId(1);
Ids.InsertNextId(2);
Ids.InsertNextId(3);
Ids.InsertNextId(4);
Ids.InsertNextId(5);
Ids.InsertNextId(6);
Ids.InsertNextId(7);
vtkUnstructuredGrid Grid = vtkUnstructuredGrid.New();
Grid.Allocate(10, 10);
var celltypename = vtkCellTypes.GetClassNameFromTypeId(12);
Grid.InsertNextCell(12, Ids);
Grid.SetPoints(Points);
Grid.GetPointData().SetScalars(Scalars);
//# Find the triangles that lie along the 0.5 contour in this cube.
vtkContourFilter Marching = vtkContourFilter.New();
Marching.SetInputData(Grid);
Marching.SetValue(0, 0.5);
Marching.Update();
//# Extract the edges of the triangles just found.
vtkExtractEdges triangleEdges = vtkExtractEdges.New();
triangleEdges.SetInputConnection(Marching.GetOutputPort());
//# Draw the edges as tubes instead of lines. Also create the associated
//# mapper and actor to display the tubes.
vtkTubeFilter triangleEdgeTubes = vtkTubeFilter.New();
triangleEdgeTubes.SetInputConnection(triangleEdges.GetOutputPort());
triangleEdgeTubes.SetRadius(.005);
triangleEdgeTubes.SetNumberOfSides(6);
triangleEdgeTubes.UseDefaultNormalOn();
triangleEdgeTubes.SetDefaultNormal(.577, .577, .577);
vtkPolyDataMapper triangleEdgeMapper = vtkPolyDataMapper.New();
triangleEdgeMapper.SetInputConnection(triangleEdgeTubes.GetOutputPort());
triangleEdgeMapper.ScalarVisibilityOff();
vtkActor triangleEdgeActor = vtkActor.New();
triangleEdgeActor.SetMapper(triangleEdgeMapper);
//eval[triangleEdgeActor GetProperty] SetDiffuseColor $lamp_black
triangleEdgeActor.GetProperty().SetSpecular(.4);
triangleEdgeActor.GetProperty().SetSpecularPower(10);
// # Shrink the triangles we found earlier. Create the associated mapper
// # and actor. Set the opacity of the shrunken triangles.
vtkShrinkPolyData aShrinker = vtkShrinkPolyData.New();
aShrinker.SetShrinkFactor(1);
aShrinker.SetInputConnection(Marching.GetOutputPort());
vtkPolyDataMapper aMapper = vtkPolyDataMapper.New();
aMapper.ScalarVisibilityOff();
aMapper.SetInputConnection(aShrinker.GetOutputPort());
vtkActor Triangles = vtkActor.New();
Triangles.SetMapper(aMapper);
//eval[Triangles GetProperty] SetDiffuseColor $banana
Triangles.GetProperty().SetOpacity(.6);
// # Draw a cube the same size and at the same position as the one created
// # previously. Extract the edges because we only want to see the outline
// # of the cube. Pass the edges through a vtkTubeFilter so they are displayed
// # as tubes rather than lines.
vtkCubeSource CubeModel = vtkCubeSource.New();
CubeModel.SetCenter(.5, .5, .5);
vtkExtractEdges Edges = vtkExtractEdges.New();
Edges.SetInputConnection(CubeModel.GetOutputPort());
vtkTubeFilter Tubes = vtkTubeFilter.New();
Tubes.SetInputConnection(Edges.GetOutputPort());
Tubes.SetRadius(.01);
Tubes.SetNumberOfSides(6);
Tubes.UseDefaultNormalOn();
Tubes.SetDefaultNormal(.577, .577, .577);
//# Create the mapper and actor to display the cube edges.
vtkPolyDataMapper TubeMapper = vtkPolyDataMapper.New();
TubeMapper.SetInputConnection(Tubes.GetOutputPort());
vtkActor CubeEdges = vtkActor.New();
CubeEdges.SetMapper(TubeMapper);
//eval[CubeEdges GetProperty] SetDiffuseColor $khaki
CubeEdges.GetProperty().SetSpecular(.4);
CubeEdges.GetProperty().SetSpecularPower(10);
//# Create a sphere to use as a glyph source for vtkGlyph3D.
vtkSphereSource Sphere = vtkSphereSource.New();
Sphere.SetRadius(0.04);
Sphere.SetPhiResolution(20);
Sphere.SetThetaResolution(20);
//# Remove the part of the cube with data values below 0.5.
vtkThresholdPoints ThresholdIn = vtkThresholdPoints.New();
ThresholdIn.SetInputData(Grid);
ThresholdIn.ThresholdByUpper(.5);
// # Display spheres at the vertices remaining in the cube data set after
// # it was passed through vtkThresholdPoints.
vtkGlyph3D Vertices = vtkGlyph3D.New();
Vertices.SetInputConnection(ThresholdIn.GetOutputPort());
Vertices.SetSourceConnection(Sphere.GetOutputPort());
//# Create a mapper and actor to display the glyphs.
vtkPolyDataMapper SphereMapper = vtkPolyDataMapper.New();
SphereMapper.SetInputConnection(Vertices.GetOutputPort());
SphereMapper.ScalarVisibilityOff();
vtkActor CubeVertices = vtkActor.New();
CubeVertices.SetMapper(SphereMapper);
// eval[CubeVertices GetProperty] SetDiffuseColor $tomato
// eval[CubeVertices GetProperty] SetDiffuseColor $tomato
//# Define the text for the label
vtkVectorText caseLabel = vtkVectorText.New();
caseLabel.SetText("Case 1");
//# Set up a transform to move the label to a new position.
vtkTransform aLabelTransform = vtkTransform.New();
aLabelTransform.Identity();
aLabelTransform.Translate(-.2, 0, 1.25);
aLabelTransform.Scale(.05, .05, .05);
//# Move the label to a new position.
vtkTransformPolyDataFilter labelTransform = vtkTransformPolyDataFilter.New();
labelTransform.SetTransform(aLabelTransform);
labelTransform.SetInputConnection(caseLabel.GetOutputPort());
//# Create a mapper and actor to display the text.
vtkPolyDataMapper labelMapper = vtkPolyDataMapper.New();
labelMapper.SetInputConnection(labelTransform.GetOutputPort());
vtkActor labelActor = vtkActor.New();
labelActor.SetMapper(labelMapper);
// # Define the base that the cube sits on. Create its associated mapper
// # and actor. Set the position of the actor.
vtkCubeSource baseModel = vtkCubeSource.New();
baseModel.SetXLength(1.5);
baseModel.SetYLength(.01);
baseModel.SetZLength(1.5);
vtkPolyDataMapper baseMapper = vtkPolyDataMapper.New();
baseMapper.SetInputConnection(baseModel.GetOutputPort());
vtkActor baseActor = vtkActor.New();
baseActor.SetMapper(baseMapper);
baseActor.SetPosition(.5, -.09, .5);
//# Add the actors to the renderer
ren1.AddActor(triangleEdgeActor);
ren1.AddActor(baseActor);
ren1.AddActor(labelActor);
ren1.AddActor(CubeEdges);
ren1.AddActor(CubeVertices);
ren1.AddActor(Triangles);
vtkAxes axes = vtkAxes.New();
axes.SetOrigin( 0, 0, 0);
axes.SetScaleFactor(5);
vtkPolyDataMapper axesMapper = vtkPolyDataMapper.New();
axesMapper.SetInputConnection(axes.GetOutputPort());
vtkActor axesActor = vtkActor.New();
axesActor.SetMapper(axesMapper);
728x90
728x90