Exemplo n.º 1
0
        /// <summary>
        /// Test intersections in 3D on a big dataset.
        /// </summary>
        public static void TestIntersectExampleData()
        {
            var parser     = new Parser();
            var generators = new List <Vertex>();

            using (var streamReader = new StreamReader("Data/exampleVoronoi.txt"))
            {
                int    i = 0;
                string line;
                while ((line = streamReader.ReadLine()) != null)
                {
                    var vertex = parser.ParseVertex(line);
                    vertex.Index = i;
                    generators.Add(vertex);
                    i++;
                }
            }

            var reader             = new TriangulationReader();
            var tetrahedralization = reader.Read("Data/exampleTetra.dat");

            for (int i = 0; i < tetrahedralization.Indices.Count; i++)
            {
                var indices = tetrahedralization.Indices[i].Indices;

                for (int j = 0; j < indices.Length; j++)
                {
                    indices[j] = indices[j] - 1;
                }
            }

            //var boundingBox = CreateBoundingBox3D(tetrahedralization.Vertices);

            //var voronoiData = new VolumeData3D();
            //voronoiData.FromVoronoi(generators);

            var tetrahedralizationData = new VolumeData3D();

            tetrahedralizationData.FromTriangulation(tetrahedralization.Vertices, tetrahedralization.Indices);

            //var bitmap = new System.Drawing.Bitmap(800, 800);
            //VolumeVisualisator.Visualise3D(bitmap, 0.4, voronoiData, boundingBox);
            //bitmap.Save("export000.png");

            //bitmap = new System.Drawing.Bitmap(800, 800);
            //VolumeVisualisator.Visualise3D(bitmap, 0.4, tetrahedralizationData, boundingBox);
            //bitmap.Save("example.png");

            var volumeIntersection = new VolumeIntersection3D(new BruteForceHalfSpaceRemoval3D());
            var volumeData         = volumeIntersection.Intersect(tetrahedralization.Vertices, tetrahedralization.Indices, generators);

            var writer = new VolumeData3DWriter(',');

            writer.Write("exampleIntersection.txt", volumeData);

            //bitmap = new System.Drawing.Bitmap(800, 800);
            //VolumeVisualisator.Visualise3D(bitmap, 0.4, volumeData, boundingBox);
            //bitmap.Save("intersectExample.png");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Test intersection in 3D on a small dataset.
        /// </summary>
        public static void TestIntersectSmallData()
        {
            var reader             = new TriangulationReader();
            var tetrahedralization = reader.Read("Data/smallTetra.dat");

            Random rd         = new Random();
            var    generators = new List <Vertex>();

            for (int i = 0; i < 5; i++)
            {
                generators.Add(new Vertex(rd.NextDouble() * 0.6 + 0.1, rd.NextDouble() * 0.9, rd.NextDouble() * 0.7 + 0.2)
                {
                    Index = i
                });
            }

            var boundingBox = CreateBoundingBox3D(tetrahedralization.Vertices);

            var voronoiData = new VolumeData3D();

            voronoiData.FromVoronoi(generators);

            var tetrahedralizationData = new VolumeData3D();

            tetrahedralizationData.FromTriangulation(tetrahedralization.Vertices, tetrahedralization.Indices);

            var bitmap = new System.Drawing.Bitmap(800, 800);

            VolumeVisualisator.Visualise3D(bitmap, 0.4, voronoiData, boundingBox);
            bitmap.Save("smallVoronoi.png");

            bitmap = new System.Drawing.Bitmap(800, 800);
            VolumeVisualisator.Visualise3D(bitmap, 0.4, tetrahedralizationData, boundingBox);
            bitmap.Save("smallTetra.png");

            var volumeData = new VolumeIntersection3D(new BruteForceHalfSpaceRemoval3D()).Intersect(tetrahedralization.Vertices, tetrahedralization.Indices, generators);

            bitmap = new System.Drawing.Bitmap(800, 800);
            VolumeVisualisator.Visualise3D(bitmap, 0.4, volumeData, boundingBox);
            bitmap.Save("intersectSmallData.png");
        }