internal void ApplyTransform(ref vtkTransform transform, string filename) { vtkPolyData polydata = vtkPolyData.New(); CreatePolydata(ref polydata); vtkTransformFilter transformFilter = vtkTransformFilter.New(); #if VTK_MAJOR_VERSION_5 transformFilter.SetInputConnection(polydata.GetProducerPort()); #else transformFilter.SetInputData(polydata); #endif transformFilter.SetTransform(transform); transformFilter.Update(); vtkXMLPolyDataWriter writer = vtkXMLPolyDataWriter.New(); writer.SetFileName(filename); #if VTK_MAJOR_VERSION_5 writer.SetInputConnection(transformFilter.GetOutputPort()); #else writer.SetInputData(transformFilter); #endif writer.Write(); }
private void MatrixMathFilter() { // Path to vtk data must be set as an environment variable // VTK_DATA_ROOT = "C:\VTK\vtkdata-5.8.0" vtkTesting test = vtkTesting.New(); string root = test.GetDataRoot(); string filePath = System.IO.Path.Combine(root, @"Data\tensors.vtk"); vtkUnstructuredGridReader reader = vtkUnstructuredGridReader.New(); reader.SetFileName(filePath); reader.Update(); vtkDataSetSurfaceFilter surfaceFilter = vtkDataSetSurfaceFilter.New(); surfaceFilter.SetInputConnection(reader.GetOutputPort()); surfaceFilter.Update(); vtkMatrixMathFilter matrixMathFilter = vtkMatrixMathFilter.New(); //matrixMathFilter.SetOperationToDeterminant(); matrixMathFilter.SetOperationToEigenvalue(); matrixMathFilter.SetInputConnection(surfaceFilter.GetOutputPort()); matrixMathFilter.Update(); matrixMathFilter.GetOutput().GetPointData().SetActiveScalars("Eigenvalue"); vtkXMLPolyDataWriter writer = vtkXMLPolyDataWriter.New(); writer.SetInputConnection(matrixMathFilter.GetOutputPort()); writer.SetFileName(System.IO.Path.Combine(root, @"Data\output.vtp")); writer.Write(); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(matrixMathFilter.GetOutputPort()); // actor 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.2, 0.3, 0.4); // add our actor to the renderer renderer.AddActor(actor); }
internal void Write(string filename) { vtkPolyData polydata = vtkPolyData.New(); CreatePolydata(ref polydata); vtkXMLPolyDataWriter writer = vtkXMLPolyDataWriter.New(); writer.SetFileName(filename); #if VTK_MAJOR_VERSION_5 writer.SetInputConnection(polydata.GetProducerPort()); #else writer.SetInputData(polydata); #endif writer.Write(); }
private void Curvature() { // Path to vtk data must be set as an environment variable // VTK_DATA_ROOT = "C:\VTK\vtkdata-5.8.0" vtkTesting test = vtkTesting.New(); string root = test.GetDataRoot(); // note: one should use a coarse surface mesh to achieve a good visual effect string filePath = System.IO.Path.Combine(root, @"Data\bunny.vtp"); // Create a polydata vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New(); reader.SetFileName(filePath); vtkCurvatures curvaturesFilter = vtkCurvatures.New(); curvaturesFilter.SetInputConnection(reader.GetOutputPort()); //curvaturesFilter.SetCurvatureTypeToGaussian(); //curvaturesFilter.SetCurvatureTypeToMean(); //curvaturesFilter.SetCurvatureTypeToMaximum(); curvaturesFilter.SetCurvatureTypeToMinimum(); // To inspect more closely, if required vtkXMLPolyDataWriter writer = vtkXMLPolyDataWriter.New(); writer.SetInputConnection(curvaturesFilter.GetOutputPort()); writer.SetFileName(System.IO.Path.Combine(root, @"Data\gauss.vtp")); writer.Write(); // Create a mapper and actor vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(curvaturesFilter.GetOutputPort()); double[] range = curvaturesFilter.GetOutput().GetScalarRange(); 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 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); }