Beispiel #1
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();
        }
Beispiel #2
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);
        }