Exemple #1
0
        public MarchingCubesResults Generate(List <GridCube> cubes, double isoLevel)
        {
            var toReturn = new MarchingCubesResults();

            toReturn.Iso  = isoLevel;
            toReturn.Grid = cubes;

            foreach (var cube in cubes)
            {
                foreach (var line in cube.Edges)
                {
                    if (!line.IsAnalyzed)
                    {
                        var calcA = line.Point1.CalculatedValue;
                        if (!calcA.HasValue)
                        {
                            calcA = line.Point1.CalculatedValue = CalculateOrGetFromCache(function, line.Point1);
                        }

                        var calcB = line.Point2.CalculatedValue;
                        if (!calcB.HasValue)
                        {
                            calcB = line.Point2.CalculatedValue = CalculateOrGetFromCache(function, line.Point2);
                        }

                        line.IsAnalyzed = true;

                        // Current edge has iso line.
                        if (calcA.HasValue && calcB.HasValue && (calcA.Value < isoLevel != calcB.Value < isoLevel))
                        {
                            if (line.IsoPoint == null)
                            {
                                line.HasIsoLine = true;
                                var interpolation = Interpolation;
                                if (interpolation == null)
                                {
                                    interpolation = new SimpleInterpolation(true);
                                }

                                line.IsoPoint = interpolation.Interpolate(
                                    line.Point1,
                                    line.Point2,
                                    line.AxissIndex,
                                    isoLevel);
                            }
                        }
                    }
                }

                toReturn.Triangles.AddRange(GetTriangles(cube, isoLevel));
            }

            return(toReturn);
        }
Exemple #2
0
        private void SetFunction(object parameter)
        {
            var function = FunctionsViewModel.SelectedItem;

            var step = function.Step;

            IinterpolationAlgoritm interpolation = new SimpleInterpolation();

            if (UseGoldenSection)
            {
                interpolation = new GoldenSectionSearch(function.Function);
            }

            //interpolation = new SimpleInterpolation(false);
            var marchingCubes = new MarchingCubes.Algoritms.MarchingCubes.MarchingCubesAlgorithm(function.Function, interpolation);
            var defaultSize   = 10;
            var region        = function.Region ?? new Region3D(0, defaultSize, 0, defaultSize, 0, defaultSize);
            var results       = marchingCubes.Generate(region, step, function.CountorLine);

            viewPort.Children.Remove(gridModel);
            var converter = new ModelsConverter();

            if (ShowGrid)
            {
                var grid = converter.RenderGrid(results.Grid, DrawVertexIndexes, null);
                viewPort.Children.Add(grid);

                gridModel = grid;
            }

            var model = converter.RenderMesh(results.Triangles, UseMeshNormals, ShowNormals, ShowTwoSided);

            viewPort.Children.Remove(meshModel);
            viewPort.Children.Add(model);
            meshModel = model;

            this.ShowFunctionsPanel = false;
        }