예제 #1
0
        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();
            }
        }
예제 #2
0
        public static DimensionDescription FromPoints(vtkPoints points)
        {
            if (points == null)
            {
                return(null);
            }

            var bounds    = points.GetBounds();
            var numPoints = points.GetNumberOfPoints();
            var result    = new DimensionDescription
            {
                MinX        = bounds[0],
                MaxX        = bounds[1],
                MinY        = bounds[2],
                MaxY        = bounds[3],
                Coordinates = new double[numPoints, 4]
            };

            var xIndices = new List <double>();
            var yIndices = new List <double>();

            for (var i = 0; i < numPoints; i++)
            {
                var current = points.GetPoint(i);
                if (!xIndices.Contains(current[0]))
                {
                    xIndices.Add(current[0]);
                }
                if (!yIndices.Contains(current[1]))
                {
                    yIndices.Add(current[1]);
                }
            }

            xIndices.Sort();
            yIndices.Sort();

            if (xIndices.Count > 0)
            {
                result.DistanceX = xIndices[1] - xIndices[0];
            }
            if (yIndices.Count > 0)
            {
                result.DistanceY = yIndices[1] - yIndices[0];
            }

            for (var i = 0; i < numPoints; i++)
            {
                var current = points.GetPoint(i);

                result.Coordinates[i, 0] = current[0];
                result.Coordinates[i, 1] = current[1];
                result.Coordinates[i, 2] = xIndices.IndexOf(current[0]);
                result.Coordinates[i, 3] = yIndices.IndexOf(current[1]);
            }

            return(result);
        }
예제 #3
0
        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);
        }
예제 #4
0
        /// <summary>
        /// 处理弹体信息,根据基本几何建模信息构造polygon(先找出边界点,再放入vtkPolygon中)
        /// </summary>
        /// <param name="info"></param>
        /// <param name="points"></param>
        /// <param name="polygon"></param>
        /// <param name="reflcet"></param>
        private static void ProcessBulletInfo(ModelingBaseInfo info, ref vtkPoints points, ref vtkPolygon polygon, SECTIONTYPE reflcet)
        {
            points = GetHalfEdgePoint(info);
            int numpoints;

            if (reflcet == SECTIONTYPE.SECTION_HALF)
            {// 如果不做镜像
                numpoints = points.GetNumberOfPoints();
            }
            else
            {//如果做镜像,将点的个数增加一倍
                points    = ReflectPointsByXOZ(points);
                numpoints = points.GetNumberOfPoints();
            }
            polygon.GetPointIds().SetNumberOfIds(numpoints);
            for (int i = 0; i < numpoints; i++)
            {
                polygon.GetPointIds().SetId(i, i);
            }
        }
예제 #5
0
        /// <summary>
        /// 将点做映射,按照xoz面来影射点,为2维的弹体做准备
        /// </summary>
        /// <param name="points"></param>
        /// <returns></returns>
        private static vtkPoints ReflectPointsByXOZ(vtkPoints points)
        {
            vtkPoints tempPoints = vtkPoints.New();
            int       numPoints  = points.GetNumberOfPoints();

            //点数扩大两倍
            tempPoints.SetNumberOfPoints(numPoints * 2);
            //构造相应的点
            for (int i = 0; i < numPoints; i++)
            {
                double[] temp = points.GetPoint(i);
                tempPoints.SetPoint(numPoints * 2 - 1 - i, temp[0] * (-1), temp[1], temp[2]);//x坐标变为相反数
                tempPoints.SetPoint(i, temp[0], temp[1], temp[2]);
            }
            return(tempPoints);
        }
예제 #6
0
        private void geometryPoints()
        {
            int pointId = 0;

            //Só colocamos nos pontos da janela VTK caso o pixel não seja preto.
            for (int i = 0; i < toShow.Height; i++)
            {
                for (int j = 0; j < toShow.Width; j++)
                {
                    if (toShow.GetPixel(j, i).ToArgb() != Color.Black.ToArgb())
                    {
                        pontosVTK.InsertPoint(pointId, j, i, 0);
                        pointId++;
                        //pontosVTK.InsertNextPoint(i, j, 0);
                    }
                }
            }

            Console.WriteLine("" + pontosVTK.GetNumberOfPoints());
            return;
        }
예제 #7
0
        public void Read_Unstructured_Grid_File(string filename)
        {
            // Initalize VTK Reader
            vtkXMLUnstructuredGridReader reader = new vtkXMLUnstructuredGridReader();

            reader.SetFileName(filename);

            reader.Update();

            vtkUnstructuredGrid grid = reader.GetOutput();

            vtkCellArray data     = grid.GetCells();
            vtkIdList    idList   = vtkIdList.New();
            int          numCells = (int)data.GetNumberOfCells();

            if (numCells != 0)
            {
                if (grid.GetCellType(0) == 10)
                {
                    isTetra = true;
                    Console.WriteLine("Celltype is tetra");
                }
                else if (grid.GetCellType(0) == 5)
                {
                    isTetra = false;
                    Console.WriteLine("Celltype is triangle");
                }
                else
                {
                    Console.WriteLine("No valid celltype");
                }

                for (int i = 0; i < numCells; i++)
                {
                    long cellTypeID = grid.GetCellType(i);
                    // alle punkte durchlaufen und in eine Variable für jeden Punkt die anderen drei Punkte speichern
                    if (isTetra)
                    {
                        Vector4 tetraPoint = new Vector4();

                        grid.GetCellPoints(i, idList);
                        // ueber alle vier punkte iterieren und diese in extra liste für jeden Punkt speichern
                        for (int j = 0; j < 4; j++)
                        {
                            tetraPoint[j] = idList.GetId(j);
                        }

                        tetraPoints.Add(tetraPoint);
                    }
                    else if (!isTetra)
                    {
                        Vector3 triangle = new Vector3();

                        grid.GetCellPoints(i, idList);
                        // ueber alle drei punkte iterieren und diese in extra liste für jeden Punkt speichern
                        for (int j = 0; j < 3; j++)
                        {
                            triangle[j] = idList.GetId(j);
                        }
                        trianglePoints.Add(triangle);
                    }
                }
            }

            // Read Point Coordinates
            vtkPoints points = grid.GetPoints();

            int numPoints = (int)points.GetNumberOfPoints();

            List <Vector3d> point_dat = new List <Vector3d>();

            if (numPoints != 0)
            {
                // Read Point Data
                double[] pt;
                for (int i = 0; i < numPoints; i++)
                {
                    pt = points.GetPoint(i);
                    point_dat.Add(new Vector3d((float)pt[0], (float)pt[1], (float)pt[2]));
                }

                if (this.vertex_data.ContainsKey("vertices"))
                {
                    this.vertex_data["vertices"] = point_dat;
                }
                else
                {
                    this.vertex_data.Add("vertices", point_dat);
                }
                Console.WriteLine("All points read in correctly!");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("---------------No Points existent");
            }

            vtkPointData pointData = grid.GetPointData();

            // Load point attributes
            this.Load_Point_Attributes(pointData);
        }