Esempio n. 1
0
        /// <summary>
        /// 根据节点和单元信息来Mapper
        /// </summary>
        public void ConstructActor()
        {
            if (m_cells.GetNumberOfCells() < 0)
            {
                Debug.Fail("m_tetraElements没有cell");
            }
            m_gridData.SetPoints(m_points);
            m_gridData.SetCells((int)VTKCellType.VTK_TETRA, m_cells);

            //AddVertex(m_points, m_gridData);//添加vertex
            //vtkVertexGlyphFilter filter = new vtkVertexGlyphFilter();

            //filter.SetInput(m_gridData);

            ////
            vtkDataSetMapper dataSetMapper = new vtkDataSetMapper();

            dataSetMapper.SetInput(m_gridData);
            //dataSetMapper.SetInput(filter.GetOutput ());
            this.SetMapper(dataSetMapper);
            this.GetProperty().SetPointSize(5);
            m_defaultColor = ModelUtils.GetRandomColor256();//获取随机颜色
            SetDefaultColor();
            this.GetProperty().SetEdgeVisibility(1);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }