private static void ClosedSurface() { // Create a sphere vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.Update(); vtkFeatureEdges featureEdges = vtkFeatureEdges.New(); featureEdges.FeatureEdgesOff(); featureEdges.BoundaryEdgesOn(); featureEdges.NonManifoldEdgesOn(); featureEdges.SetInputConnection(sphereSource.GetOutputPort()); featureEdges.Update(); int numberOfOpenEdges = featureEdges.GetOutput().GetNumberOfCells(); if (numberOfOpenEdges > 0) { Console.WriteLine("Surface is not closed"); } else { Console.WriteLine("Surface is closed"); } // nothing to show graphically Console.WriteLine("\nPress any key to continue..."); Console.ReadKey(); }
private void ShrinkPolyData() { vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.SetRadius(10); sphereSource.SetPhiResolution(12); sphereSource.SetThetaResolution(12); sphereSource.Update(); vtkShrinkPolyData shrinkFilter = vtkShrinkPolyData.New(); shrinkFilter.SetInputConnection(sphereSource.GetOutputPort()); shrinkFilter.Update(); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(shrinkFilter.GetOutputPort()); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(.2, .3, .4); //Add the actors to the renderer, set the background and size renderer.AddActor(actor); }
private void vtkPolyDataConnectivityFilter_LargestRegion() { // Small sphere vtkSphereSource sphereSource1 = vtkSphereSource.New(); sphereSource1.Update(); // Large sphere vtkSphereSource sphereSource2 = vtkSphereSource.New(); sphereSource2.SetRadius(10); sphereSource2.SetCenter(25, 0, 0); sphereSource2.SetThetaResolution(10); sphereSource2.SetPhiResolution(10); sphereSource2.Update(); vtkAppendPolyData appendFilter = vtkAppendPolyData.New(); appendFilter.AddInputConnection(sphereSource1.GetOutputPort()); appendFilter.AddInputConnection(sphereSource2.GetOutputPort()); appendFilter.Update(); vtkPolyDataConnectivityFilter connectivityFilter = vtkPolyDataConnectivityFilter.New(); connectivityFilter.SetInputConnection(appendFilter.GetOutputPort()); connectivityFilter.SetExtractionModeToLargestRegion(); connectivityFilter.Update(); // Create a mapper and actor for original data vtkPolyDataMapper originalMapper = vtkPolyDataMapper.New(); originalMapper.SetInputConnection(appendFilter.GetOutputPort()); originalMapper.Update(); vtkActor originalActor = vtkActor.New(); originalActor.SetMapper(originalMapper); // Create a mapper and actor for extracted data vtkPolyDataMapper extractedMapper = vtkPolyDataMapper.New(); extractedMapper.SetInputConnection(connectivityFilter.GetOutputPort()); extractedMapper.Update(); vtkActor extractedActor = vtkActor.New(); extractedActor.GetProperty().SetColor(1, 0, 0); extractedActor.SetMapper(extractedMapper); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(0.2, 0.3, 0.4); // add our actor to the renderer renderer.AddActor(originalActor); renderer.AddActor(extractedActor); }
private void ExtractEdges() { vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.Update(); Debug.WriteLine("Sphere" + Environment.NewLine + "----------"); Debug.WriteLine("There are " + sphereSource.GetOutput().GetNumberOfCells() + " cells."); Debug.WriteLine("There are " + sphereSource.GetOutput().GetNumberOfPoints() + " points."); vtkExtractEdges extractEdges = vtkExtractEdges.New(); #if VTK_MAJOR_VERSION_5 extractEdges.SetInputConnection(sphereSource.GetOutputPort()); #else extractEdges.SetInputData(sphereSource); #endif extractEdges.Update(); vtkCellArray lines = extractEdges.GetOutput().GetLines(); vtkPoints points = extractEdges.GetOutput().GetPoints(); Debug.WriteLine(Environment.NewLine + "Edges" + Environment.NewLine + "----------"); Debug.WriteLine("There are " + lines.GetNumberOfCells() + " cells."); Debug.WriteLine("There are " + points.GetNumberOfPoints() + " points."); // Traverse all of the edges for (int i = 0; i < extractEdges.GetOutput().GetNumberOfCells(); i++) { //Debug.WriteLine("Type: " + extractEdges.GetOutput().GetCell(i).GetClassName() ); vtkLine line = vtkLine.SafeDownCast(extractEdges.GetOutput().GetCell(i)); Debug.WriteLine("Line " + i + " : " + line); } // Visualize the edges // Create a mapper and actor vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 mapper.SetInputConnection(extractEdges.GetOutputPort()); #else mapper.SetInputData(extractEdges); #endif vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(1, 1, 1); // add our actor to the renderer renderer.AddActor(actor); }
private void MarchingCubes() { vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.SetPhiResolution(20); sphereSource.SetThetaResolution(20); sphereSource.Update(); double[] bounds = sphereSource.GetOutput().GetBounds(); for (int i = 0; i < 6; i += 2) { double range = bounds[i + 1] - bounds[i]; bounds[i] = bounds[i] - .1 * range; bounds[i + 1] = bounds[i + 1] + .1 * range; } vtkVoxelModeller voxelModeller = vtkVoxelModeller.New(); voxelModeller.SetSampleDimensions(50, 50, 50); voxelModeller.SetModelBounds(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]); voxelModeller.SetScalarTypeToFloat(); voxelModeller.SetMaximumDistance(.1); #if VTK_MAJOR_VERSION_5 voxelModeller.SetInputConnection(sphereSource.GetOutputPort()); #else voxelModeller.SetInputData(sphereSource); #endif vtkMarchingCubes surface = vtkMarchingCubes.New(); #if VTK_MAJOR_VERSION_5 surface.SetInputConnection(voxelModeller.GetOutputPort()); #else surface.SetInputData(voxelModeller); #endif surface.ComputeNormalsOn(); surface.SetValue(0, 0.5); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 mapper.SetInputConnection(surface.GetOutputPort()); #else mapper.SetInputData(surface); #endif vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(.2, .3, .4); // add our actor to the renderer renderer.AddActor(actor); }
private void ColorDisconnectedRegions() { // Create some spheres vtkSphereSource sphereSource1 = vtkSphereSource.New(); sphereSource1.Update(); vtkSphereSource sphereSource2 = vtkSphereSource.New(); sphereSource2.SetCenter(5, 0, 0); sphereSource2.Update(); vtkSphereSource sphereSource3 = vtkSphereSource.New(); sphereSource3.SetCenter(10, 0, 0); sphereSource3.Update(); vtkAppendPolyData appendFilter = vtkAppendPolyData.New(); appendFilter.AddInputConnection(sphereSource1.GetOutputPort()); appendFilter.AddInputConnection(sphereSource2.GetOutputPort()); appendFilter.AddInputConnection(sphereSource3.GetOutputPort()); vtkPolyDataConnectivityFilter connectivityFilter = vtkPolyDataConnectivityFilter.New(); connectivityFilter.SetInputConnection(appendFilter.GetOutputPort()); connectivityFilter.SetExtractionModeToAllRegions(); connectivityFilter.ColorRegionsOn(); connectivityFilter.Update(); // Visualize vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(connectivityFilter.GetOutputPort()); double[] range = connectivityFilter.GetOutput().GetPointData().GetArray("RegionId").GetRange(); mapper.SetScalarRange(range[0], range[1]); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(0.0, 0.0, 0.0); // add our actor to the renderer renderer.AddActor(actor); }
private void PolyDataGetPoint() { // Create a sphere vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.Update(); vtkPolyData polydata = sphereSource.GetOutput(); // Write all of the coordinates of the points in the vtkPolyData to the console. for (int i = 0; i < polydata.GetNumberOfPoints(); i++) { double[] p = polydata.GetPoint(i); // This is identical to: // double[] p = polydata.GetPoints().GetPoint(i); Console.WriteLine("Point " + i + " : (" + p[0] + " " + p[1] + " " + p[2] + ")"); } }
private void DijkstraGraphGeodesicPath() { // Create a sphere vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.Update(); vtkDijkstraGraphGeodesicPath dijkstra = vtkDijkstraGraphGeodesicPath.New(); dijkstra.SetInputConnection(sphereSource.GetOutputPort()); dijkstra.SetStartVertex(0); dijkstra.SetEndVertex(10); dijkstra.Update(); // Create a mapper and actor vtkPolyDataMapper pathMapper = vtkPolyDataMapper.New(); pathMapper.SetInputConnection(dijkstra.GetOutputPort()); vtkActor pathActor = vtkActor.New(); pathActor.SetMapper(pathMapper); pathActor.GetProperty().SetColor(1, 0, 0); // Red pathActor.GetProperty().SetLineWidth(4); // Create a mapper and actor vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(sphereSource.GetOutputPort()); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(0.3, 0.6, 0.3); // add our actor to the renderer renderer.AddActor(actor); renderer.AddActor(pathActor); }
void GenerateData(ref vtkPolyData input) { // Create a sphere vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.Update(); // Remove some cells vtkIdTypeArray ids = vtkIdTypeArray.New(); ids.SetNumberOfComponents(1); // Set values ids.InsertNextValue(2); ids.InsertNextValue(10); vtkSelectionNode selectionNode = vtkSelectionNode.New(); selectionNode.SetFieldType((int)vtkSelectionNode.SelectionField.CELL); selectionNode.SetContentType((int)vtkSelectionNode.SelectionContent.INDICES); selectionNode.SetSelectionList(ids); selectionNode.GetProperties().Set(vtkSelectionNode.INVERSE(), 1); //invert the selection vtkSelection selection = vtkSelection.New(); selection.AddNode(selectionNode); vtkExtractSelection extractSelection = vtkExtractSelection.New(); extractSelection.SetInputConnection(0, sphereSource.GetOutputPort()); #if VTK_MAJOR_VERSION_5 extractSelection.SetInput(1, selection); #else extractSelection.SetInputData(1, selection); #endif extractSelection.Update(); // In selection vtkDataSetSurfaceFilter surfaceFilter = vtkDataSetSurfaceFilter.New(); surfaceFilter.SetInputConnection(extractSelection.GetOutputPort()); surfaceFilter.Update(); input.ShallowCopy(surfaceFilter.GetOutput()); }
private void Planes() { // in this example we need the renderer first to retrieve the active camera // in order to get camera's frustum planes and renderer's aspectratio vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; vtkRenderer renderer = vtkRenderer.New(); renderer = renderWindow.GetRenderers().GetFirstRenderer(); vtkCamera camera = renderer.GetActiveCamera(); double[] aspect = renderer.GetAspect(); double aspectRatio = aspect[0] / aspect[1]; vtkPlanes planes = vtkPlanes.New(); // one way { // allocate memory for 24 unmanaged doubles int size = Marshal.SizeOf(typeof(double)) * 24; IntPtr ptr = Marshal.AllocHGlobal(size); camera.GetFrustumPlanes(aspectRatio, ptr); // in case we would need this values diectly we could copy // the unmanaged double array to a managed array like so: // double[] planesArray = new double[24]; // Marshal.Copy(ptr, planesArray, 0, 24); // but fortunately we can forward the IntPtr directly to the function // SetFrustumPlanes() planes.SetFrustumPlanes(ptr); // free unmanaged memory Marshal.FreeHGlobal(ptr); } // another way { vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.Update(); double[] bounds = new double[6]; bounds = sphereSource.GetOutput().GetBounds(); planes.SetBounds(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]); } // nothing to visualize }
private static void FindAllArrayNames(string filePath) { vtkPolyData polydata = vtkPolyData.New(); if (filePath == null) { vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.Update(); vtkXMLPolyDataWriter writer = vtkXMLPolyDataWriter.New(); writer.SetFileName(@"c:\vtk\vtkdata-5.8.0\Data\testFindAllArrayNames.vtp"); writer.SetInputConnection(sphereSource.GetOutputPort()); writer.Write(); polydata = sphereSource.GetOutput(); } else { vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New(); reader.SetFileName(filePath); reader.Update(); polydata = reader.GetOutput(); } FindAllData(ref polydata); }
private void PlanesIntersection() { vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.Update(); double[] bounds = new double[6]; bounds = sphereSource.GetOutput().GetBounds(); vtkPoints box = vtkPoints.New(); box.SetNumberOfPoints(8); double xMin, xMax, yMin, yMax, zMin, zMax; xMin = bounds[0]; xMax = bounds[1]; yMin = bounds[2]; yMax = bounds[3]; zMin = bounds[4]; zMax = bounds[5]; box.SetPoint(0, xMax, yMin, zMax); box.SetPoint(1, xMax, yMin, zMin); box.SetPoint(2, xMax, yMax, zMin); box.SetPoint(3, xMax, yMax, zMax); box.SetPoint(4, xMin, yMin, zMax); box.SetPoint(5, xMin, yMin, zMin); box.SetPoint(6, xMin, yMax, zMin); box.SetPoint(7, xMin, yMax, zMax); vtkPlanesIntersection planesIntersection = vtkPlanesIntersection.New(); planesIntersection.SetBounds(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]); int intersects = planesIntersection.IntersectsRegion(box); Debug.WriteLine("Intersects? " + ((intersects == 1) ? true : false).ToString()); // nothing to visualize }
private static void MultiBlockMergeFilter() { vtkSphereSource sphereSource1 = vtkSphereSource.New(); sphereSource1.Update(); vtkSphereSource sphereSource2 = vtkSphereSource.New(); sphereSource2.SetCenter(10, 10, 10); sphereSource2.Update(); vtkMultiBlockDataSet multiBlockDataSet1 = vtkMultiBlockDataSet.New(); multiBlockDataSet1.SetNumberOfBlocks(1); multiBlockDataSet1.SetBlock(0, sphereSource1.GetOutput()); #if VTK_MAJOR_VERSION_5 multiBlockDataSet1.Update(); #endif vtkMultiBlockDataSet multiBlockDataSet2 = vtkMultiBlockDataSet.New(); multiBlockDataSet2.SetNumberOfBlocks(1); multiBlockDataSet2.SetBlock(0, sphereSource2.GetOutput()); #if VTK_MAJOR_VERSION_5 multiBlockDataSet2.Update(); #endif vtkMultiBlockMergeFilter multiBlockMergeFilter = vtkMultiBlockMergeFilter.New(); #if VTK_MAJOR_VERSION_5 multiBlockMergeFilter.AddInput(multiBlockDataSet1); multiBlockMergeFilter.AddInput(multiBlockDataSet2); #else multiBlockMergeFilter.AddInputData(multiBlockDataSet1); multiBlockMergeFilter.AddInputData(multiBlockDataSet2); #endif multiBlockMergeFilter.Update(); }
private void HighLightBadCells() { vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.Update(); vtkTriangleFilter triangleFilter = vtkTriangleFilter.New(); triangleFilter.SetInputConnection(sphereSource.GetOutputPort()); triangleFilter.Update(); //Create a mapper and actor vtkDataSetMapper sphereMapper = vtkDataSetMapper.New(); sphereMapper.SetInputConnection(triangleFilter.GetOutputPort()); vtkActor sphereActor = vtkActor.New(); sphereActor.SetMapper(sphereMapper); vtkPolyData mesh = triangleFilter.GetOutput(); Debug.WriteLine("There are " + mesh.GetNumberOfCells() + " cells."); vtkMeshQuality qualityFilter = vtkMeshQuality.New(); #if VTK_MAJOR_VERSION_5 qualityFilter.SetInput(mesh); #else qualityFilter.SetInputData(mesh); #endif qualityFilter.SetTriangleQualityMeasureToArea(); qualityFilter.Update(); vtkDataSet qualityMesh = qualityFilter.GetOutput(); vtkDoubleArray qualityArray = vtkDoubleArray.SafeDownCast(qualityMesh.GetCellData().GetArray("Quality")); Debug.WriteLine("There are " + qualityArray.GetNumberOfTuples() + " values."); for (int i = 0; i < qualityArray.GetNumberOfTuples(); i++) { double val = qualityArray.GetValue(i); Debug.WriteLine("value " + i + ": " + val); } vtkThreshold selectCells = vtkThreshold.New(); selectCells.ThresholdByLower(.02); selectCells.SetInputArrayToProcess( 0, 0, 0, 1, // POINTS = 0, CELLS = 1, NONE = 2, POINTS_THEN_CELLS = 3, VERTICES = 4, EDGES = 5, ROWS = 6 0 // SCALARS = 0, VECTORS = 1, NORMALS = 2, TCOORDS = 3, TENSORS = 4, GLOBALIDS = 5, PEDIGREEIDS = 6, EDGEFLAG = 7 ); #if VTK_MAJOR_VERSION_5 selectCells.SetInput(qualityMesh); #else selectCells.SetInputData(qualityMesh); #endif selectCells.Update(); vtkUnstructuredGrid ug = selectCells.GetOutput(); // Create a mapper and actor vtkDataSetMapper mapper = vtkDataSetMapper.New(); #if VTK_MAJOR_VERSION_5 mapper.SetInput(ug); #else mapper.SetInputData(ug); #endif vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); actor.GetProperty().SetColor(1.0, 0.0, 0.0); actor.GetProperty().SetRepresentationToWireframe(); actor.GetProperty().SetLineWidth(5); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(1.0, 1.0, 1.0); // add our actors to the renderer renderer.AddActor(actor); renderer.AddActor(sphereActor); }
private void Subdivision(string filePath) { vtkPolyData originalMesh; if (filePath != null) { vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New(); reader.SetFileName(filePath); // Subdivision filters only work on triangles vtkTriangleFilter triangles = vtkTriangleFilter.New(); triangles.SetInputConnection(reader.GetOutputPort()); triangles.Update(); originalMesh = triangles.GetOutput(); } else { vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.Update(); originalMesh = sphereSource.GetOutput(); } Debug.WriteLine("Before subdivision"); Debug.WriteLine(" There are " + originalMesh.GetNumberOfPoints() + " points."); Debug.WriteLine(" There are " + originalMesh.GetNumberOfPolys() + " triangles."); int numberOfViewports = 3; vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; this.Size = new System.Drawing.Size(200 * numberOfViewports + 12, 252); this.Text += " - Subdivision"; Random rnd = new Random(2); int numberOfSubdivisions = 2; // Create one text property for all vtkTextProperty textProperty = vtkTextProperty.New(); textProperty.SetFontSize(14); textProperty.SetJustificationToCentered(); for (int i = 0; i < numberOfViewports; i++) { // Note: Here we create a superclass pointer (vtkPolyDataAlgorithm) so that we can easily instantiate different // types of subdivision filters. Typically you would not want to do this, but rather create the pointer to be the type // filter you will actually use, e.g. // <vtkLinearSubdivisionFilter> subdivisionFilter = <vtkLinearSubdivisionFilter>.New(); vtkPolyDataAlgorithm subdivisionFilter; switch (i) { case 0: subdivisionFilter = vtkLinearSubdivisionFilter.New(); ((vtkLinearSubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions); break; case 1: subdivisionFilter = vtkLoopSubdivisionFilter.New(); ((vtkLoopSubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions); break; case 2: subdivisionFilter = vtkButterflySubdivisionFilter.New(); ((vtkButterflySubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions); break; default: subdivisionFilter = vtkLinearSubdivisionFilter.New(); ((vtkLinearSubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions); break; } #if VTK_MAJOR_VERSION_5 subdivisionFilter.SetInputConnection(originalMesh.GetProducerPort()); #else subdivisionFilter.SetInputData(originalMesh); #endif subdivisionFilter.Update(); vtkRenderer renderer = vtkRenderer.New(); renderWindow.AddRenderer(renderer); renderer.SetViewport((float)i / numberOfViewports, 0, (float)(i + 1) / numberOfViewports, 1); renderer.SetBackground(.2 + rnd.NextDouble() / 8, .3 + rnd.NextDouble() / 8, .4 + rnd.NextDouble() / 8); vtkTextMapper textMapper = vtkTextMapper.New(); vtkActor2D textActor = vtkActor2D.New(); textMapper.SetInput(subdivisionFilter.GetClassName()); textMapper.SetTextProperty(textProperty); textActor.SetMapper(textMapper); textActor.SetPosition(100, 16); //Create a mapper and actor vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(subdivisionFilter.GetOutputPort()); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); renderer.AddActor(actor); renderer.AddActor(textActor); renderer.ResetCamera(); } renderWindow.Render(); }
private void QuadricDecimation() { vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.Update(); vtkPolyData input = vtkPolyData.New(); input.ShallowCopy(sphereSource.GetOutput()); Debug.WriteLine("Before decimation" + Environment.NewLine + "------------"); Debug.WriteLine("There are " + input.GetNumberOfPoints() + " points."); Debug.WriteLine("There are " + input.GetNumberOfPolys() + " polygons."); vtkQuadricDecimation decimate = vtkQuadricDecimation.New(); #if VTK_MAJOR_VERSION_5 decimate.SetInputConnection(input.GetProducerPort()); #else decimate.SetInputData(input); #endif decimate.Update(); vtkPolyData decimated = vtkPolyData.New(); decimated.ShallowCopy(decimate.GetOutput()); Debug.WriteLine("After decimation" + Environment.NewLine + "------------"); Debug.WriteLine("There are " + decimated.GetNumberOfPoints() + " points."); Debug.WriteLine("There are " + decimated.GetNumberOfPolys() + " polygons."); vtkPolyDataMapper inputMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 inputMapper.SetInputConnection(input.GetProducerPort()); #else inputMapper.SetInputData(input); #endif vtkActor inputActor = vtkActor.New(); inputActor.SetMapper(inputMapper); vtkPolyDataMapper decimatedMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 decimatedMapper.SetInputConnection(decimated.GetProducerPort()); #else decimatedMapper.SetInputData(decimated); #endif vtkActor decimatedActor = vtkActor.New(); decimatedActor.SetMapper(decimatedMapper); vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; this.Size = new System.Drawing.Size(612, 352); // Define viewport ranges // (xmin, ymin, xmax, ymax) double[] leftViewport = new double[] { 0.0, 0.0, 0.5, 1.0 }; double[] rightViewport = new double[] { 0.5, 0.0, 1.0, 1.0 }; // Setup both renderers vtkRenderer leftRenderer = vtkRenderer.New(); renderWindow.AddRenderer(leftRenderer); leftRenderer.SetViewport(leftViewport[0], leftViewport[1], leftViewport[2], leftViewport[3]); leftRenderer.SetBackground(.6, .5, .4); vtkRenderer rightRenderer = vtkRenderer.New(); renderWindow.AddRenderer(rightRenderer); rightRenderer.SetViewport(rightViewport[0], rightViewport[1], rightViewport[2], rightViewport[3]); rightRenderer.SetBackground(.4, .5, .6); // Add the sphere to the left and the cube to the right leftRenderer.AddActor(inputActor); rightRenderer.AddActor(decimatedActor); leftRenderer.ResetCamera(); rightRenderer.ResetCamera(); renderWindow.Render(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVclosedSplines(String [] argv) { //Prefix Content is: "" // get the interactor ui[] // Now create the RenderWindow, Renderer and Interactor[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); math = new vtkMath(); numberOfInputPoints = 30; aKSplineX = new vtkKochanekSpline(); aKSplineX.ClosedOn(); aKSplineY = new vtkKochanekSpline(); aKSplineY.ClosedOn(); aKSplineZ = new vtkKochanekSpline(); aKSplineZ.ClosedOn(); aCSplineX = new vtkCardinalSpline(); aCSplineX.ClosedOn(); aCSplineY = new vtkCardinalSpline(); aCSplineY.ClosedOn(); aCSplineZ = new vtkCardinalSpline(); aCSplineZ.ClosedOn(); // add some points[] inputPoints = new vtkPoints(); x = -1.0; y = -1.0; z = 0.0; aKSplineX.AddPoint((double)0, (double)x); aKSplineY.AddPoint((double)0, (double)y); aKSplineZ.AddPoint((double)0, (double)z); aCSplineX.AddPoint((double)0, (double)x); aCSplineY.AddPoint((double)0, (double)y); aCSplineZ.AddPoint((double)0, (double)z); inputPoints.InsertPoint((int)0, (double)x, (double)y, (double)z); x = 1.0; y = -1.0; z = 0.0; aKSplineX.AddPoint((double)1, (double)x); aKSplineY.AddPoint((double)1, (double)y); aKSplineZ.AddPoint((double)1, (double)z); aCSplineX.AddPoint((double)1, (double)x); aCSplineY.AddPoint((double)1, (double)y); aCSplineZ.AddPoint((double)1, (double)z); inputPoints.InsertPoint((int)1, (double)x, (double)y, (double)z); x = 1.0; y = 1.0; z = 0.0; aKSplineX.AddPoint((double)2, (double)x); aKSplineY.AddPoint((double)2, (double)y); aKSplineZ.AddPoint((double)2, (double)z); aCSplineX.AddPoint((double)2, (double)x); aCSplineY.AddPoint((double)2, (double)y); aCSplineZ.AddPoint((double)2, (double)z); inputPoints.InsertPoint((int)2, (double)x, (double)y, (double)z); x = -1.0; y = 1.0; z = 0.0; aKSplineX.AddPoint((double)3, (double)x); aKSplineY.AddPoint((double)3, (double)y); aKSplineZ.AddPoint((double)3, (double)z); aCSplineX.AddPoint((double)3, (double)x); aCSplineY.AddPoint((double)3, (double)y); aCSplineZ.AddPoint((double)3, (double)z); inputPoints.InsertPoint((int)3, (double)x, (double)y, (double)z); inputData = new vtkPolyData(); inputData.SetPoints((vtkPoints)inputPoints); balls = new vtkSphereSource(); balls.SetRadius((double).04); balls.SetPhiResolution((int)10); balls.SetThetaResolution((int)10); balls.Update(); glyphPoints = new vtkGlyph3D(); glyphPoints.SetInputData((vtkDataObject)inputData); glyphPoints.SetSourceData((vtkPolyData)balls.GetOutput()); glyphMapper = vtkPolyDataMapper.New(); glyphMapper.SetInputConnection((vtkAlgorithmOutput)glyphPoints.GetOutputPort()); glyph = new vtkActor(); glyph.SetMapper((vtkMapper)glyphMapper); glyph.GetProperty().SetDiffuseColor((double)1.0000, 0.3882, 0.2784); glyph.GetProperty().SetSpecular((double).3); glyph.GetProperty().SetSpecularPower((double)30); ren1.AddActor((vtkProp)glyph); Kpoints = new vtkPoints(); Cpoints = new vtkPoints(); profileKData = new vtkPolyData(); profileCData = new vtkPolyData(); numberOfInputPoints = 5; numberOfOutputPoints = 100; offset = 1.0; //method moved fit(); lines = new vtkCellArray(); lines.InsertNextCell((int)numberOfOutputPoints); i = 0; while ((i) < numberOfOutputPoints) { lines.InsertCellPoint((int)i); i = i + 1; } profileKData.SetPoints((vtkPoints)Kpoints); profileKData.SetLines((vtkCellArray)lines); profileCData.SetPoints((vtkPoints)Cpoints); profileCData.SetLines((vtkCellArray)lines); profileKTubes = new vtkTubeFilter(); profileKTubes.SetNumberOfSides((int)8); profileKTubes.SetInputData((vtkDataObject)profileKData); profileKTubes.SetRadius((double).01); profileKMapper = vtkPolyDataMapper.New(); profileKMapper.SetInputConnection((vtkAlgorithmOutput)profileKTubes.GetOutputPort()); profileK = new vtkActor(); profileK.SetMapper((vtkMapper)profileKMapper); profileK.GetProperty().SetDiffuseColor((double)0.8900, 0.8100, 0.3400); profileK.GetProperty().SetSpecular((double).3); profileK.GetProperty().SetSpecularPower((double)30); ren1.AddActor((vtkProp)profileK); profileCTubes = new vtkTubeFilter(); profileCTubes.SetNumberOfSides((int)8); profileCTubes.SetInputData((vtkDataObject)profileCData); profileCTubes.SetRadius((double).01); profileCMapper = vtkPolyDataMapper.New(); profileCMapper.SetInputConnection((vtkAlgorithmOutput)profileCTubes.GetOutputPort()); profileC = new vtkActor(); profileC.SetMapper((vtkMapper)profileCMapper); profileC.GetProperty().SetDiffuseColor((double)0.2000, 0.6300, 0.7900); profileC.GetProperty().SetSpecular((double).3); profileC.GetProperty().SetSpecularPower((double)30); ren1.AddActor((vtkProp)profileC); ren1.ResetCamera(); ren1.GetActiveCamera().Dolly((double)1.5); ren1.ResetCameraClippingRange(); renWin.SetSize((int)300, (int)300); // render the image[] //[] iren.Initialize(); // prevent the tk window from showing up then start the event loop[] //method moved //method moved //method moved //method moved //method moved //method moved //deleteAllVTKObjects(); }
private void WindowedSincPolyDataFilter() { vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.Update(); vtkWindowedSincPolyDataFilter smoother = vtkWindowedSincPolyDataFilter.New(); smoother.SetInputConnection(sphereSource.GetOutputPort()); smoother.SetNumberOfIterations(15); smoother.BoundarySmoothingOff(); smoother.FeatureEdgeSmoothingOff(); smoother.SetFeatureAngle(120.0); smoother.SetPassBand(.001); smoother.NonManifoldSmoothingOn(); smoother.NormalizeCoordinatesOn(); smoother.Update(); vtkPolyDataMapper smoothedMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 smoothedMapper.SetInputConnection(smoother.GetOutputPort()); #else smoothedMapper.SetInputData(smoother); #endif vtkActor smoothedActor = vtkActor.New(); smoothedActor.SetMapper(smoothedMapper); vtkPolyDataMapper inputMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 inputMapper.SetInputConnection(sphereSource.GetOutputPort()); #else inputMapper.SetInputData(sphereSource); #endif vtkActor inputActor = vtkActor.New(); inputActor.SetMapper(inputMapper); vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; this.Size = new System.Drawing.Size(612, 352); // Define viewport ranges // (xmin, ymin, xmax, ymax) double[] leftViewport = new double[] { 0.0, 0.0, 0.5, 1.0 }; double[] rightViewport = new double[] { 0.5, 0.0, 1.0, 1.0 }; // Setup both renderers vtkRenderer leftRenderer = vtkRenderer.New(); renderWindow.AddRenderer(leftRenderer); leftRenderer.SetViewport(leftViewport[0], leftViewport[1], leftViewport[2], leftViewport[3]); leftRenderer.SetBackground(.6, .5, .4); vtkRenderer rightRenderer = vtkRenderer.New(); renderWindow.AddRenderer(rightRenderer); rightRenderer.SetViewport(rightViewport[0], rightViewport[1], rightViewport[2], rightViewport[3]); rightRenderer.SetBackground(.4, .5, .6); // Add the sphere to the left and the cube to the right leftRenderer.AddActor(inputActor); rightRenderer.AddActor(smoothedActor); leftRenderer.ResetCamera(); rightRenderer.ResetCamera(); renderWindow.Render(); }
private void WeightedTransformFilter() { // Use a sphere as a basis of the shape vtkSphereSource sphere = vtkSphereSource.New(); sphere.SetPhiResolution(40); sphere.SetThetaResolution(40); sphere.Update(); vtkPolyData sphereData = sphere.GetOutput(); // Create a data array to hold the weighting coefficients vtkFloatArray tfarray = vtkFloatArray.New(); int npoints = sphereData.GetNumberOfPoints(); tfarray.SetNumberOfComponents(2); tfarray.SetNumberOfTuples(npoints); // Parameterize the sphere along the z axis, and fill the weights // with (1.0-a, a) to linearly interpolate across the shape IntPtr pPoint = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) * 3); double[] point = new double[3]; for (int i = 0; i < npoints; i++) { sphereData.GetPoint(i, pPoint); Marshal.Copy(pPoint, point, 0, 3); double x = point[0]; double y = point[1]; double z = point[2]; double zn = z + 0.5; double zn1 = 1.0 - zn; if (zn > 1.0) { zn = 1.0; } if (zn1 < 0.0) { zn1 = 0.0; } tfarray.SetComponent(i, 0, zn1); tfarray.SetComponent(i, 1, zn); } Marshal.FreeHGlobal(pPoint); // Create field data to hold the array, and bind it to the sphere vtkFieldData fd = vtkFieldData.New(); tfarray.SetName("weights"); sphereData.GetPointData().AddArray(tfarray); // Use an ordinary transform to stretch the shape vtkTransform stretch = vtkTransform.New(); stretch.Scale(1, 1, 3.2); vtkTransformFilter stretchFilter = vtkTransformFilter.New(); stretchFilter.SetInputConnection(sphereData.GetProducerPort()); stretchFilter.SetTransform(stretch); // Now, for the weighted transform stuff vtkWeightedTransformFilter weightedTrans = vtkWeightedTransformFilter.New(); // Create two transforms to interpolate between vtkTransform identity = vtkTransform.New(); identity.Identity(); vtkTransform rotated = vtkTransform.New(); double rotatedAngle = 45; rotated.RotateX(rotatedAngle); weightedTrans.SetNumberOfTransforms(2); weightedTrans.SetTransform(identity, 0); weightedTrans.SetTransform(rotated, 1); // which data array should the filter use ? weightedTrans.SetWeightArray("weights"); weightedTrans.SetInputConnection(stretchFilter.GetOutputPort()); vtkPolyDataMapper weightedTransMapper = vtkPolyDataMapper.New(); weightedTransMapper.SetInputConnection(weightedTrans.GetOutputPort()); vtkActor weightedTransActor = vtkActor.New(); weightedTransActor.SetMapper(weightedTransMapper); weightedTransActor.GetProperty().SetDiffuseColor(0.8, 0.8, 0.1); weightedTransActor.GetProperty().SetRepresentationToSurface(); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(0.2, 0.3, 0.4); // add our actor to the renderer renderer.AddActor(weightedTransActor); renderer.ResetCamera(); renderer.GetActiveCamera().Azimuth(90); renderer.GetActiveCamera().Dolly(1); }
private void OBBDicer(string filePath) { vtkPolyData inputPolyData; if (filePath != null) { vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New(); reader.SetFileName(filePath); reader.Update(); inputPolyData = reader.GetOutput(); } else { vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.SetThetaResolution(30); sphereSource.SetPhiResolution(15); sphereSource.Update(); inputPolyData = sphereSource.GetOutput(); } // Create pipeline vtkOBBDicer dicer = vtkOBBDicer.New(); #if VTK_MAJOR_VERSION_5 dicer.SetInput(inputPolyData); #else dicer.SetInputData(inputPolyData); #endif dicer.SetNumberOfPieces(4); dicer.SetDiceModeToSpecifiedNumberOfPieces(); dicer.Update(); vtkPolyDataMapper inputMapper = vtkPolyDataMapper.New(); inputMapper.SetInputConnection(dicer.GetOutputPort()); inputMapper.SetScalarRange(0, dicer.GetNumberOfActualPieces()); Debug.WriteLine("Asked for: " + dicer.GetNumberOfPieces() + " pieces, got: " + dicer.GetNumberOfActualPieces()); vtkActor inputActor = vtkActor.New(); inputActor.SetMapper(inputMapper); inputActor.GetProperty().SetInterpolationToFlat(); vtkOutlineCornerFilter outline = vtkOutlineCornerFilter.New(); #if VTK_MAJOR_VERSION_5 outline.SetInput(inputPolyData); #else outline.SetInputData(inputPolyData); #endif vtkPolyDataMapper outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection(outline.GetOutputPort()); vtkActor outlineActor = vtkActor.New(); outlineActor.SetMapper(outlineMapper); outlineActor.GetProperty().SetColor(0, 0, 0); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(.2, .3, .4); // add our actor to the renderer renderer.AddActor(inputActor); renderer.AddActor(outlineActor); }
private void PolygonalSurfaceContourLineInterpolator() { vtkPolyData polyData; vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.SetThetaResolution(40); sphereSource.SetPhiResolution(20); sphereSource.Update(); polyData = sphereSource.GetOutput(); // The Dijkstra interpolator will not accept cells that aren't triangles vtkTriangleFilter triangleFilter = vtkTriangleFilter.New(); #if VTK_MAJOR_VERSION_5 triangleFilter.SetInput(polyData); #else triangleFilter.SetInputData(polyData); #endif triangleFilter.Update(); vtkPolyData pd = triangleFilter.GetOutput(); //Create a mapper and actor vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(triangleFilter.GetOutputPort()); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); actor.GetProperty().SetInterpolationToFlat(); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(0.3, 0.4, 0.5); // add our actor to the renderer renderer.AddActor(actor); // Here comes the contour widget stuff..... vtkContourWidget contourWidget = vtkContourWidget.New(); contourWidget.SetInteractor(renderWindow.GetInteractor()); vtkOrientedGlyphContourRepresentation rep = vtkOrientedGlyphContourRepresentation.SafeDownCast( contourWidget.GetRepresentation()); rep.GetLinesProperty().SetColor(1, 0.2, 0); rep.GetLinesProperty().SetLineWidth(3.0f); vtkPolygonalSurfacePointPlacer pointPlacer = vtkPolygonalSurfacePointPlacer.New(); pointPlacer.AddProp(actor); pointPlacer.GetPolys().AddItem(pd); rep.SetPointPlacer(pointPlacer); vtkPolygonalSurfaceContourLineInterpolator interpolator = vtkPolygonalSurfaceContourLineInterpolator.New(); interpolator.GetPolys().AddItem(pd); rep.SetLineInterpolator(interpolator); renderWindow.Render(); contourWidget.EnabledOn(); }
private void SelectPolyData() { vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.Update(); vtkPoints selectionPoints = vtkPoints.New(); selectionPoints.InsertPoint(0, -0.16553, 0.135971, 0.451972); selectionPoints.InsertPoint(1, -0.0880123, -0.134952, 0.4747); selectionPoints.InsertPoint(2, 0.00292618, -0.134604, 0.482459); selectionPoints.InsertPoint(3, 0.0641941, 0.067112, 0.490947); selectionPoints.InsertPoint(4, 0.15577, 0.0734765, 0.469245); selectionPoints.InsertPoint(5, 0.166667, -0.129217, 0.454622); selectionPoints.InsertPoint(6, 0.241259, -0.123363, 0.420581); selectionPoints.InsertPoint(7, 0.240334, 0.0727106, 0.432555); selectionPoints.InsertPoint(8, 0.308529, 0.0844311, 0.384357); selectionPoints.InsertPoint(9, 0.32672, -0.121674, 0.359187); selectionPoints.InsertPoint(10, 0.380721, -0.117342, 0.302527); selectionPoints.InsertPoint(11, 0.387804, 0.0455074, 0.312375); selectionPoints.InsertPoint(12, 0.43943, -0.111673, 0.211707); selectionPoints.InsertPoint(13, 0.470984, -0.0801913, 0.147919); selectionPoints.InsertPoint(14, 0.436777, 0.0688872, 0.233021); selectionPoints.InsertPoint(15, 0.44874, 0.188852, 0.109882); selectionPoints.InsertPoint(16, 0.391352, 0.254285, 0.176943); selectionPoints.InsertPoint(17, 0.373274, 0.154162, 0.294296); selectionPoints.InsertPoint(18, 0.274659, 0.311654, 0.276609); selectionPoints.InsertPoint(19, 0.206068, 0.31396, 0.329702); selectionPoints.InsertPoint(20, 0.263789, 0.174982, 0.387308); selectionPoints.InsertPoint(21, 0.213034, 0.175485, 0.417142); selectionPoints.InsertPoint(22, 0.169113, 0.261974, 0.390286); selectionPoints.InsertPoint(23, 0.102552, 0.25997, 0.414814); selectionPoints.InsertPoint(24, 0.131512, 0.161254, 0.454705); selectionPoints.InsertPoint(25, 0.000192443, 0.156264, 0.475307); selectionPoints.InsertPoint(26, -0.0392091, 0.000251724, 0.499943); selectionPoints.InsertPoint(27, -0.096161, 0.159646, 0.46438); vtkSelectPolyData loop = vtkSelectPolyData.New(); loop.SetInputConnection(sphereSource.GetOutputPort()); loop.SetLoop(selectionPoints); loop.GenerateSelectionScalarsOn(); loop.SetSelectionModeToSmallestRegion(); //negative scalars inside vtkClipPolyData clip = //clips out positive region vtkClipPolyData.New(); clip.SetInputConnection(loop.GetOutputPort()); vtkPolyDataMapper clipMapper = vtkPolyDataMapper.New(); clipMapper.SetInputConnection(clip.GetOutputPort()); vtkLODActor clipActor = vtkLODActor.New(); clipActor.SetMapper(clipMapper); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(.1, .2, .4); renderWindow.SetSize(500, 250); // add our actor to the renderer renderer.AddActor(clipActor); }
void _sphereSource_ModifiedEvt(vtkObject sender, vtkObjectEventArgs e) { _sphereSource.Update(); SpherePolyData = _sphereSource.GetOutput(); }
private void ContoursFromPolyData(string filePath) { vtkPolyData inputPolyData; if (filePath != null) { vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New(); reader.SetFileName(filePath); reader.Update(); inputPolyData = reader.GetOutput(); } else { vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.SetThetaResolution(30); sphereSource.SetPhiResolution(15); sphereSource.Update(); inputPolyData = sphereSource.GetOutput(); } vtkPolyDataMapper inputMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 inputMapper.SetInput(inputPolyData); #else inputMapper.SetInputData(inputPolyData); #endif // Create a plane to cut vtkPlane plane = vtkPlane.New(); double[] center = inputPolyData.GetCenter(); double[] bounds = inputPolyData.GetBounds(); plane.SetOrigin(center[0], center[1], center[2]); plane.SetNormal(1, 1, 1); float[] centerf = new float[] { (float)center[0], (float)center[1], (float)center[2] }; float[] minBoundf = new float[] { (float)bounds[0], (float)bounds[2], (float)bounds[4] }; float[] maxBoundf = new float[] { (float)bounds[1], (float)bounds[3], (float)bounds[5] }; IntPtr pCenter = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(float)) * 3); IntPtr pMinBound = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(float)) * 3); IntPtr pMaxBound = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(float)) * 3); Marshal.Copy(centerf, 0, pCenter, 3); Marshal.Copy(minBoundf, 0, pMinBound, 3); Marshal.Copy(maxBoundf, 0, pMaxBound, 3); // vtkMath.Distance2BetweenPoints accepts floats only double distanceMin = Math.Sqrt(vtkMath.Distance2BetweenPoints(pMinBound, pCenter)); double distanceMax = Math.Sqrt(vtkMath.Distance2BetweenPoints(pMaxBound, pCenter)); Marshal.FreeHGlobal(pCenter); Marshal.FreeHGlobal(pMinBound); Marshal.FreeHGlobal(pMaxBound); // Create cutter vtkCutter cutter = vtkCutter.New(); cutter.SetCutFunction(plane); #if VTK_MAJOR_VERSION_5 cutter.SetInput(inputPolyData); #else cutter.SetInputData(inputPolyData); #endif cutter.GenerateValues(20, -distanceMin, distanceMax); vtkPolyDataMapper cutterMapper = vtkPolyDataMapper.New(); cutterMapper.SetInputConnection(cutter.GetOutputPort()); cutterMapper.ScalarVisibilityOff(); // Create plane actor vtkActor planeActor = vtkActor.New(); planeActor.GetProperty().SetColor(1.0, 0.0, 0.0); planeActor.GetProperty().SetLineWidth(3); planeActor.SetMapper(cutterMapper); // Create input actor vtkActor inputActor = vtkActor.New(); inputActor.GetProperty().SetColor(1.0, 0.8941, 0.7686); // bisque inputActor.SetMapper(inputMapper); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(.2, .3, .4); renderer.AddActor(inputActor); renderer.AddActor(planeActor); //display the contour lines }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVclosedSplines(String [] argv) { //Prefix Content is: "" // get the interactor ui[] // Now create the RenderWindow, Renderer and Interactor[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); math = new vtkMath(); numberOfInputPoints = 30; aKSplineX = new vtkKochanekSpline(); aKSplineX.ClosedOn(); aKSplineY = new vtkKochanekSpline(); aKSplineY.ClosedOn(); aKSplineZ = new vtkKochanekSpline(); aKSplineZ.ClosedOn(); aCSplineX = new vtkCardinalSpline(); aCSplineX.ClosedOn(); aCSplineY = new vtkCardinalSpline(); aCSplineY.ClosedOn(); aCSplineZ = new vtkCardinalSpline(); aCSplineZ.ClosedOn(); // add some points[] inputPoints = new vtkPoints(); x = -1.0; y = -1.0; z = 0.0; aKSplineX.AddPoint((double)0,(double)x); aKSplineY.AddPoint((double)0,(double)y); aKSplineZ.AddPoint((double)0,(double)z); aCSplineX.AddPoint((double)0,(double)x); aCSplineY.AddPoint((double)0,(double)y); aCSplineZ.AddPoint((double)0,(double)z); inputPoints.InsertPoint((int)0,(double)x,(double)y,(double)z); x = 1.0; y = -1.0; z = 0.0; aKSplineX.AddPoint((double)1,(double)x); aKSplineY.AddPoint((double)1,(double)y); aKSplineZ.AddPoint((double)1,(double)z); aCSplineX.AddPoint((double)1,(double)x); aCSplineY.AddPoint((double)1,(double)y); aCSplineZ.AddPoint((double)1,(double)z); inputPoints.InsertPoint((int)1,(double)x,(double)y,(double)z); x = 1.0; y = 1.0; z = 0.0; aKSplineX.AddPoint((double)2,(double)x); aKSplineY.AddPoint((double)2,(double)y); aKSplineZ.AddPoint((double)2,(double)z); aCSplineX.AddPoint((double)2,(double)x); aCSplineY.AddPoint((double)2,(double)y); aCSplineZ.AddPoint((double)2,(double)z); inputPoints.InsertPoint((int)2,(double)x,(double)y,(double)z); x = -1.0; y = 1.0; z = 0.0; aKSplineX.AddPoint((double)3,(double)x); aKSplineY.AddPoint((double)3,(double)y); aKSplineZ.AddPoint((double)3,(double)z); aCSplineX.AddPoint((double)3,(double)x); aCSplineY.AddPoint((double)3,(double)y); aCSplineZ.AddPoint((double)3,(double)z); inputPoints.InsertPoint((int)3,(double)x,(double)y,(double)z); inputData = new vtkPolyData(); inputData.SetPoints((vtkPoints)inputPoints); balls = new vtkSphereSource(); balls.SetRadius((double).04); balls.SetPhiResolution((int)10); balls.SetThetaResolution((int)10); balls.Update(); glyphPoints = new vtkGlyph3D(); glyphPoints.SetInputData((vtkDataObject)inputData); glyphPoints.SetSourceData((vtkPolyData)balls.GetOutput()); glyphMapper = vtkPolyDataMapper.New(); glyphMapper.SetInputConnection((vtkAlgorithmOutput)glyphPoints.GetOutputPort()); glyph = new vtkActor(); glyph.SetMapper((vtkMapper)glyphMapper); glyph.GetProperty().SetDiffuseColor((double) 1.0000, 0.3882, 0.2784 ); glyph.GetProperty().SetSpecular((double).3); glyph.GetProperty().SetSpecularPower((double)30); ren1.AddActor((vtkProp)glyph); Kpoints = new vtkPoints(); Cpoints = new vtkPoints(); profileKData = new vtkPolyData(); profileCData = new vtkPolyData(); numberOfInputPoints = 5; numberOfOutputPoints = 100; offset = 1.0; //method moved fit(); lines = new vtkCellArray(); lines.InsertNextCell((int)numberOfOutputPoints); i = 0; while((i) < numberOfOutputPoints) { lines.InsertCellPoint((int)i); i = i + 1; } profileKData.SetPoints((vtkPoints)Kpoints); profileKData.SetLines((vtkCellArray)lines); profileCData.SetPoints((vtkPoints)Cpoints); profileCData.SetLines((vtkCellArray)lines); profileKTubes = new vtkTubeFilter(); profileKTubes.SetNumberOfSides((int)8); profileKTubes.SetInputData((vtkDataObject)profileKData); profileKTubes.SetRadius((double).01); profileKMapper = vtkPolyDataMapper.New(); profileKMapper.SetInputConnection((vtkAlgorithmOutput)profileKTubes.GetOutputPort()); profileK = new vtkActor(); profileK.SetMapper((vtkMapper)profileKMapper); profileK.GetProperty().SetDiffuseColor((double) 0.8900, 0.8100, 0.3400 ); profileK.GetProperty().SetSpecular((double).3); profileK.GetProperty().SetSpecularPower((double)30); ren1.AddActor((vtkProp)profileK); profileCTubes = new vtkTubeFilter(); profileCTubes.SetNumberOfSides((int)8); profileCTubes.SetInputData((vtkDataObject)profileCData); profileCTubes.SetRadius((double).01); profileCMapper = vtkPolyDataMapper.New(); profileCMapper.SetInputConnection((vtkAlgorithmOutput)profileCTubes.GetOutputPort()); profileC = new vtkActor(); profileC.SetMapper((vtkMapper)profileCMapper); profileC.GetProperty().SetDiffuseColor((double) 0.2000, 0.6300, 0.7900 ); profileC.GetProperty().SetSpecular((double).3); profileC.GetProperty().SetSpecularPower((double)30); ren1.AddActor((vtkProp)profileC); ren1.ResetCamera(); ren1.GetActiveCamera().Dolly((double)1.5); ren1.ResetCameraClippingRange(); renWin.SetSize((int)300,(int)300); // render the image[] //[] iren.Initialize(); // prevent the tk window from showing up then start the event loop[] //method moved //method moved //method moved //method moved //method moved //method moved //deleteAllVTKObjects(); }