private void SelectPointClick(vtkObject sender, vtkObjectEventArgs e) { if (ModelLoaded == true && SelectionMode == true) { int[] clickPos = Inter.GetEventPosition(); vtkPointPicker PointPicker = vtkPointPicker.New(); PointPicker.SetTolerance(0.05); PointPicker.Pick(clickPos[0], clickPos[1], 0, Viewport); vtkPoints points = Faces.GetPoints(); double[] PickPosition = PointPicker.GetPickPosition(); for (int j = 0; j < points.GetNumberOfPoints(); j++) { if (Math.Abs(points.GetPoint(j)[0] - PickPosition[0]) < 1e-6 && Math.Abs(points.GetPoint(j)[1] - PickPosition[1]) < 1e-6 && Math.Abs(points.GetPoint(j)[2] - PickPosition[2]) < 1e-6) { SelectionPoints.InsertNextPoint(PickPosition[0], PickPosition[1], PickPosition[2]); break; } } SelectionGlyph = vtkGlyph3D.New(); SelectionGlyph.SetInput(SelectionPolyData); SelectionGlyph.SetSourceConnection(SelectionSphere.GetOutputPort()); SelectionMapper.SetInputConnection(SelectionGlyph.GetOutputPort()); SelectionActor.SetMapper(SelectionMapper); // Refresh Viewport Refresh(); } }
public static void SetMedianFilter(ref vtkPolyData polyData, Rectangle rect) { var image = vtkImageData.New(); image.SetExtent(0, rect.Width - 1, 0, rect.Height - 1, 0, 0); image.SetNumberOfScalarComponents(1); image.SetScalarTypeToDouble(); for (int i = 0; i < rect.Width * rect.Height; i++) { double[] d = polyData.GetPoint(i); image.SetScalarComponentFromDouble(i % rect.Width, i / rect.Width, 0, 0, d[2]); } image.Update(); var cast = vtkImageCast.New(); cast.SetInput(image); cast.SetOutputScalarTypeToUnsignedChar(); cast.Update(); var w = vtkBMPWriter.New(); w.SetInput(cast.GetOutput()); w.SetFileName("imgcastbyheight_beforefilter.bmp"); w.Update(); var medianFilter = vtkImageGaussianSmooth.New(); medianFilter.SetInput(image); medianFilter.SetDimensionality(2); medianFilter.SetRadiusFactor(10); medianFilter.SetStandardDeviation(3); medianFilter.Update(); //var medianFilter = vtkImageHybridMedian2D.New(); //medianFilter.SetInput(image); //medianFilter.Update(); var cast2 = vtkImageCast.New(); cast2.SetInput(medianFilter.GetOutput()); cast2.SetOutputScalarTypeToUnsignedChar(); cast2.Update(); var w2 = vtkBMPWriter.New(); w2.SetInput(cast2.GetOutput()); w2.SetFileName("imgcastbyheight_afterfilter.bmp"); w2.Update(); for (int i = 0; i < rect.Height; i++) { for (int j = 0; j < rect.Width; j++) { double d = medianFilter.GetOutput().GetScalarComponentAsFloat(j, i, 0, 0); polyData.GetPoints().SetPoint(i * rect.Width + j, j, i, (int)d); } } polyData.Update(); }