示例#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);
        }
示例#2
0
        private void Tetrahedron()
        {
            vtkPoints points = vtkPoints.New();

            points.InsertNextPoint(0, 0, 0);
            points.InsertNextPoint(1, 0, 0);
            points.InsertNextPoint(1, 1, 0);
            points.InsertNextPoint(0, 1, 1);
            points.InsertNextPoint(5, 5, 5);
            points.InsertNextPoint(6, 5, 5);
            points.InsertNextPoint(6, 6, 5);
            points.InsertNextPoint(5, 6, 6);

            // Method 1
            vtkUnstructuredGrid unstructuredGrid1 = vtkUnstructuredGrid.New();

            unstructuredGrid1.SetPoints(points);

            int[]  ptIds        = new int[] { 0, 1, 2, 3 };
            IntPtr ptIdsPointer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * 4);

            Marshal.Copy(ptIds, 0, ptIdsPointer, 4);
            unstructuredGrid1.InsertNextCell(10, 4, ptIdsPointer);
            Marshal.FreeHGlobal(ptIdsPointer);

            // Method 2
            vtkUnstructuredGrid unstructuredGrid2 = vtkUnstructuredGrid.New();

            unstructuredGrid2.SetPoints(points);

            vtkTetra tetra = vtkTetra.New();

            tetra.GetPointIds().SetId(0, 4);
            tetra.GetPointIds().SetId(1, 5);
            tetra.GetPointIds().SetId(2, 6);
            tetra.GetPointIds().SetId(3, 7);

            vtkCellArray cellArray = vtkCellArray.New();

            cellArray.InsertNextCell(tetra);
            unstructuredGrid2.SetCells(10, cellArray);

            // Create a mapper and actor
            vtkDataSetMapper mapper1 = vtkDataSetMapper.New();

            mapper1.SetInputConnection(unstructuredGrid1.GetProducerPort());

            vtkActor actor1 = vtkActor.New();

            actor1.SetMapper(mapper1);

            // Create a mapper and actor
            vtkDataSetMapper mapper2 = vtkDataSetMapper.New();

            mapper2.SetInputConnection(unstructuredGrid2.GetProducerPort());

            vtkActor actor2 = vtkActor.New();

            actor2.SetMapper(mapper2);

            vtkRenderWindow renderWindow = myRenderWindowControl.RenderWindow;
            vtkRenderer     renderer     = renderWindow.GetRenderers().GetFirstRenderer();

            renderer.SetBackground(0.2, 0.3, 0.4);
            // Add the actor to the scene
            renderer.AddActor(actor1);
            renderer.AddActor(actor2);
            renderer.SetBackground(.3, .6, .3); // Background color green
        }
示例#3
0
        public void WritSimpleVTM()
        {
            string filePath = "..\\..\\..\\..\\..\\03Daten\\testData\\simpleTest8Points.vtm";
            vtkMultiBlockDataSet multiBlockDataSet = vtkMultiBlockDataSet.New();

            multiBlockDataSet.SetNumberOfBlocks(2);

            vtkUnstructuredGrid unstructuredGrid1 = vtkUnstructuredGrid.New();

            vtkPoints points1 = vtkPoints.New();

            points1.InsertNextPoint(0, 0, 0);
            points1.InsertNextPoint(1, 0, 0);
            points1.InsertNextPoint(1, 1, 0);
            points1.InsertNextPoint(0, 1, 1);

            vtkPoints points2 = vtkPoints.New();

            points1.InsertNextPoint(2, 0, 0);
            points1.InsertNextPoint(2, 2, 0);
            points1.InsertNextPoint(2, 2, 3);
            points1.InsertNextPoint(0, 2, 3);

            vtkTetra tetra = vtkTetra.New();

            tetra.GetPointIds().SetId(0, 0);
            tetra.GetPointIds().SetId(1, 1);
            tetra.GetPointIds().SetId(2, 2);
            tetra.GetPointIds().SetId(3, 3);

            vtkCellArray cellArray1 = vtkCellArray.New();

            cellArray1.InsertNextCell(tetra);

            unstructuredGrid1.SetPoints(points1);
            const int VTK_TETRA = 10;

            unstructuredGrid1.SetCells(VTK_TETRA, cellArray1);

            vtkCellArray cellArray2 = vtkCellArray.New();

            tetra = vtkTetra.New();
            tetra.GetPointIds().SetId(0, 4);
            tetra.GetPointIds().SetId(1, 5);
            tetra.GetPointIds().SetId(2, 6);
            tetra.GetPointIds().SetId(3, 7);
            cellArray2.InsertNextCell(tetra);
            tetra = vtkTetra.New();
            tetra.GetPointIds().SetId(0, 7);
            tetra.GetPointIds().SetId(1, 5);
            tetra.GetPointIds().SetId(2, 2);
            tetra.GetPointIds().SetId(3, 4);

            cellArray2.InsertNextCell(tetra);


            vtkUnstructuredGrid unstructuredGrid = vtkUnstructuredGrid.New();

            unstructuredGrid.SetPoints(points1);
            unstructuredGrid.SetCells(VTK_TETRA, cellArray2);

            multiBlockDataSet.SetBlock(0, unstructuredGrid1);
            multiBlockDataSet.SetBlock(1, unstructuredGrid);

            // Write file
            vtkXMLMultiBlockDataWriter writer = vtkXMLMultiBlockDataWriter.New();

            writer.SetFileName(filePath);
            writer.SetInput(multiBlockDataSet);
            writer.Write();
        }
示例#4
0
        public void WriteSimpleVTUExample()
        {
            string    filePath = "C:\\DatenE\\02Studium\\02WiSe1718\\06IndividualProjekt\\03Daten\\testData\\simpleTest4Points.vtu";
            vtkPoints points   = vtkPoints.New();

            points.InsertNextPoint(0, 0, 0);
            points.InsertNextPoint(1, 0, 0);
            points.InsertNextPoint(1, 1, 0);
            points.InsertNextPoint(0, 1, 1);

            points.InsertNextPoint(2, 0, 0);
            //points.InsertNextPoint(2, 2, 0);


            vtkTetra tetra = vtkTetra.New();

            tetra.GetPointIds().SetId(0, 0);
            tetra.GetPointIds().SetId(1, 1);
            tetra.GetPointIds().SetId(2, 2);
            tetra.GetPointIds().SetId(3, 3);

            vtkCellArray cellArray = vtkCellArray.New();

            cellArray.InsertNextCell(tetra);



            tetra.GetPointIds().SetId(0, 1);
            tetra.GetPointIds().SetId(1, 0);
            tetra.GetPointIds().SetId(2, 3);
            tetra.GetPointIds().SetId(3, 2);

            cellArray.InsertNextCell(tetra);
            tetra.GetPointIds().SetId(0, 0);
            tetra.GetPointIds().SetId(1, 2);
            tetra.GetPointIds().SetId(2, 3);
            tetra.GetPointIds().SetId(3, 1);

            cellArray.InsertNextCell(tetra);
            tetra.GetPointIds().SetId(0, 3);
            tetra.GetPointIds().SetId(1, 1);
            tetra.GetPointIds().SetId(2, 0);
            tetra.GetPointIds().SetId(3, 2);

            cellArray.InsertNextCell(tetra);

            tetra.GetPointIds().SetId(0, 3);
            tetra.GetPointIds().SetId(1, 0);
            tetra.GetPointIds().SetId(2, 2);
            tetra.GetPointIds().SetId(3, 4);

            cellArray.InsertNextCell(tetra);

            //tetra.GetPointIds().SetId(0, 4);
            //tetra.GetPointIds().SetId(1, 3);
            //tetra.GetPointIds().SetId(2, 0);
            //tetra.GetPointIds().SetId(3, 2);

            //cellArray.InsertNextCell(tetra);

            vtkUnstructuredGrid unstructuredGrid = vtkUnstructuredGrid.New();

            unstructuredGrid.SetPoints(points);
            const int VTK_TETRA = 10;

            unstructuredGrid.SetCells(VTK_TETRA, cellArray);


            // vX
            vtkDoubleArray scalarsX = new vtkDoubleArray();

            scalarsX.SetNumberOfValues(5);
            scalarsX.SetValue(0, 4);
            scalarsX.SetValue(1, 1);
            scalarsX.SetValue(2, 2);
            scalarsX.SetValue(3, 3);
            scalarsX.SetValue(4, 1);
            //scalarsX.SetValue(5, 2);
            scalarsX.SetName("Vx");
            unstructuredGrid.GetPointData().AddArray(scalarsX);
            // vY
            vtkDoubleArray scalarsY = new vtkDoubleArray();

            scalarsY.SetNumberOfValues(5);
            scalarsY.SetValue(0, 1);
            scalarsY.SetValue(1, 2);
            scalarsY.SetValue(2, 3);
            scalarsY.SetValue(3, 4);
            scalarsY.SetValue(4, 1);
            //scalarsY.SetValue(5, 2);
            scalarsY.SetName("Vy");
            unstructuredGrid.GetPointData().AddArray(scalarsY);
            // vZ
            vtkDoubleArray scalarsZ = new vtkDoubleArray();

            scalarsZ.SetNumberOfValues(5);
            scalarsZ.SetValue(0, 3);
            scalarsZ.SetValue(1, 1);
            scalarsZ.SetValue(2, 4);
            scalarsZ.SetValue(3, 2);
            scalarsZ.SetValue(4, 1);
            //scalarsZ.SetValue(5, 2);
            scalarsZ.SetName("Vz");
            unstructuredGrid.GetPointData().AddArray(scalarsZ);


            // Write file
            vtkXMLUnstructuredGridWriter writer = vtkXMLUnstructuredGridWriter.New();

            writer.SetFileName(filePath);
            writer.SetInput(unstructuredGrid);
            writer.Write();
        }
示例#5
0
        public void WriteVTUTriangle(string filePath, List <Vector3d> point_data, List <Vector3> trianglepoints, Dictionary <String, vtkDataArray> scalar_dataArray, List <String> arrayNames, int numberOfPoints, int numberOfTetraPoints)
        {
            vtkPoints points = vtkPoints.New();

            for (int i = 0; i < numberOfPoints; i++)
            {
                points.InsertNextPoint(point_data[i].X, point_data[i].Y, point_data[i].Z);
            }

            vtkUnstructuredGrid unstructuredGrid = vtkUnstructuredGrid.New();


            vtkCellArray cellArrayOne = vtkCellArray.New();

            for (int i = 0; i < numberOfTetraPoints; i++)
            {
                vtkTriangle triangle = vtkTriangle.New();

                triangle.GetPointIds().SetId(0, (long)trianglepoints[i][0]);
                triangle.GetPointIds().SetId(1, (long)trianglepoints[i][1]);
                triangle.GetPointIds().SetId(2, (long)trianglepoints[i][2]);


                cellArrayOne.InsertNextCell(triangle);
            }


            unstructuredGrid.SetPoints(points);

            const int VTK_TRIANGLE = 5;

            unstructuredGrid.SetCells(VTK_TRIANGLE, cellArrayOne);



            int numberOfScalarData = scalar_dataArray.Count();

            for (int i = 0; i < numberOfScalarData; i++)
            {
                scalar_dataArray.TryGetValue(arrayNames[i], out vtkDataArray scalars);
                unstructuredGrid.GetPointData().AddArray(scalars);
            }

            // add file ending if it is not existent
            string suffix = (".vtu");

            if (!(filePath.EndsWith(suffix)))
            {
                filePath += suffix;
            }

            // Write file
            vtkXMLUnstructuredGridWriter writer = vtkXMLUnstructuredGridWriter.New();

            writer.SetFileName(filePath);
            writer.SetInput(unstructuredGrid);
            writer.Write();

            // Read and display file for verification that it was written correctly
            vtkXMLUnstructuredGridReader reader = vtkXMLUnstructuredGridReader.New();

            if (reader.CanReadFile(filePath) == 0)
            {
                //MessageBox.Show("Cannot read file \"" + filePath + "\"", "Error", MessageBoxButtons.OK);
                return;
            }
            Console.WriteLine("VTU file was writen and is saved at {0}", filePath);
        }
示例#6
0
        public void WriteVTM(string filePath, List <Vector3d> point_data, List <Vector4> tetrapoints, Dictionary <String, vtkDataArray> scalar_dataArray, List <String> arrayNames, int numberOfPoints, int numberOfTetraPoints)
        {
            vtkPoints points = vtkPoints.New();

            for (int i = 0; i < numberOfPoints; i++)
            {
                points.InsertNextPoint(point_data[i].X, point_data[i].Y, point_data[i].Z);
            }
            vtkMultiBlockDataSet multiBlockDataSet = vtkMultiBlockDataSet.New();

            double countBlocks = Math.Ceiling((double)((1.0 * numberOfTetraPoints) / 1000000));

            multiBlockDataSet.SetNumberOfBlocks((uint)1);
            for (int j = 0; j < 1; j++)
            {
                vtkUnstructuredGrid unstructuredGrid = vtkUnstructuredGrid.New();

                vtkCellArray cellArrayOne = vtkCellArray.New();
                int          countTetras  = 0;
                int          startTetras  = j * 1000000;
                if (numberOfTetraPoints < (j * 1000000) + 1000000)
                {
                    countTetras = numberOfTetraPoints;
                }
                else
                {
                    countTetras = (j * 1000000) + 1000000;
                }
                for (int i = startTetras; i < tetrapoints.Count(); i++)
                {
                    vtkTetra tetra = vtkTetra.New();

                    tetra.GetPointIds().SetId(0, (long)tetrapoints[i][0]);
                    tetra.GetPointIds().SetId(1, (long)tetrapoints[i][1]);
                    tetra.GetPointIds().SetId(2, (long)tetrapoints[i][2]);
                    tetra.GetPointIds().SetId(3, (long)tetrapoints[i][3]);

                    cellArrayOne.InsertNextCell(tetra);
                }
                //for (int i = 0; i < tetrapoints2.Count(); i++)
                //{
                //    vtkTetra tetra = vtkTetra.New();

                //    tetra.GetPointIds().SetId(0, (long)tetrapoints2[i][0]);
                //    tetra.GetPointIds().SetId(1, (long)tetrapoints2[i][1]);
                //    tetra.GetPointIds().SetId(2, (long)tetrapoints2[i][2]);
                //    tetra.GetPointIds().SetId(3, (long)tetrapoints2[i][3]);

                //    cellArrayOne.InsertNextCell(tetra);
                //}

                unstructuredGrid.SetPoints(points);

                const int VTK_TETRA = 10;
                unstructuredGrid.SetCells(VTK_TETRA, cellArrayOne);


                int numberOfScalarData = scalar_dataArray.Count();
                for (int i = 0; i < numberOfScalarData; i++)
                {
                    scalar_dataArray.TryGetValue(arrayNames[i], out vtkDataArray scalars);
                    unstructuredGrid.GetPointData().AddArray(scalars);
                }
                multiBlockDataSet.SetBlock((uint)j, unstructuredGrid);
            }

            // add file ending if it is not existent
            string suffix = (".vtm");

            if (!(filePath.EndsWith(suffix)))
            {
                filePath += suffix;
            }

            // Write file
            vtkXMLMultiBlockDataWriter writer = vtkXMLMultiBlockDataWriter.New();

            writer.SetFileName(filePath);
            writer.SetInput(multiBlockDataSet);
            writer.Write();

            // Read and display file for verification that it was written correctly
            vtkXMLMultiBlockDataReader reader = vtkXMLMultiBlockDataReader.New();

            if (reader.CanReadFile(filePath) == 0)
            {
                //MessageBox.Show("Cannot read file \"" + filePath + "\"", "Error", MessageBoxButtons.OK);
                return;
            }
            Console.WriteLine("VTU file was writen and is saved at {0}", filePath);
        }
示例#7
0
        private void WriteVTUFile()
        {
            // 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\tetra_test.vtu");

            vtkPoints points = vtkPoints.New();

            points.InsertNextPoint(0, 0, 0);
            points.InsertNextPoint(1, 0, 0);
            points.InsertNextPoint(1, 1, 0);
            points.InsertNextPoint(0, 1, 1);

            vtkTetra tetra = vtkTetra.New();

            tetra.GetPointIds().SetId(0, 0);
            tetra.GetPointIds().SetId(1, 1);
            tetra.GetPointIds().SetId(2, 2);
            tetra.GetPointIds().SetId(3, 3);

            vtkCellArray cellArray = vtkCellArray.New();

            cellArray.InsertNextCell(tetra);

            vtkUnstructuredGrid unstructuredGrid = vtkUnstructuredGrid.New();

            unstructuredGrid.SetPoints(points);
            const int VTK_TETRA = 10;

            unstructuredGrid.SetCells(VTK_TETRA, cellArray);

            // Write file
            vtkXMLUnstructuredGridWriter writer = vtkXMLUnstructuredGridWriter.New();

            writer.SetFileName(filePath);
            writer.SetInput(unstructuredGrid);
            writer.Write();

            // Read and display file for verification that it was written correctly
            vtkXMLUnstructuredGridReader reader = vtkXMLUnstructuredGridReader.New();

            if (reader.CanReadFile(filePath) == 0)
            {
                MessageBox.Show("Cannot read file \"" + filePath + "\"", "Error", MessageBoxButtons.OK);
                return;
            }
            reader.SetFileName(filePath);
            reader.Update();

            vtkDataSetMapper mapper = vtkDataSetMapper.New();

            mapper.SetInputConnection(reader.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);
        }