private void Segment()
        {
            m_segmentation.ClearInput();

            foreach (var block in m_grid.CubeBlocks)
            {
                Vector3I begin = block.Min;
                Vector3I end   = block.Max;
                Vector3I pos   = begin;
                for (var it = new Vector3I.RangeIterator(ref begin, ref end); it.IsValid(); it.GetNext(out pos))
                {
                    m_segmentation.AddInput(pos);
                }
            }

            var segmentList = m_segmentation.FindSegments(MyVoxelSegmentationType.Simple2);

            m_segments = new List <BoundingBox>(segmentList.Count);
            for (int i = 0; i < segmentList.Count; ++i)
            {
                BoundingBox bb = new BoundingBox();
                bb.Min = (new Vector3(segmentList[i].Min) - Vector3.Half) * m_grid.GridSize - Vector3.Half; // The another half is here to just add some head space
                bb.Max = (new Vector3(segmentList[i].Max) + Vector3.Half) * m_grid.GridSize + Vector3.Half;
                m_segments.Add(bb);
            }

            m_segmentation.ClearInput();
        }
Ejemplo n.º 2
0
        private void Segment()
        {
            m_segmentation.ClearInput();
            foreach (MySlimBlock local1 in this.m_grid.CubeBlocks)
            {
                Vector3I min   = local1.Min;
                Vector3I max   = local1.Max;
                Vector3I input = min;
                Vector3I_RangeIterator iterator = new Vector3I_RangeIterator(ref min, ref max);
                while (iterator.IsValid())
                {
                    m_segmentation.AddInput(input);
                    iterator.GetNext(out input);
                }
            }
            List <Sandbox.Engine.Utils.MyVoxelSegmentation.Segment> list = m_segmentation.FindSegments(MyVoxelSegmentationType.Simple2, 1);

            this.m_segments = new List <BoundingBox>(list.Count);
            for (int i = 0; i < list.Count; i++)
            {
                BoundingBox item = new BoundingBox {
                    Min = ((new Vector3(list[i].Min) - Vector3.Half) * this.m_grid.GridSize) - Vector3.Half,
                    Max = ((new Vector3(list[i].Max) + Vector3.Half) * this.m_grid.GridSize) + Vector3.Half
                };
                this.m_segments.Add(item);
            }
            m_segmentation.ClearInput();
        }
Ejemplo n.º 3
0
        private unsafe void AddSegmentedParts(float gridSize, MyVoxelSegmentation segmenter, MyVoxelSegmentationType segmentationType)
        {
            int     num    = (int)Math.Floor((double)(40f / gridSize));
            Vector3 vector = new Vector3(gridSize * 0.5f);

            if (segmenter != null)
            {
                int mergeIterations = (segmentationType == MyVoxelSegmentationType.Optimized) ? 1 : 0;
                segmenter.ClearInput();
                foreach (Vector3I vectori3 in this.m_tmpCubes)
                {
                    segmenter.AddInput(vectori3);
                }
                foreach (MyVoxelSegmentation.Segment segment in segmenter.FindSegments(segmentationType, mergeIterations))
                {
                    Vector3I vectori;
                    vectori.X = segment.Min.X;
                    while (vectori.X <= segment.Max.X)
                    {
                        vectori.Y = segment.Min.Y;
                        while (true)
                        {
                            if (vectori.Y > segment.Max.Y)
                            {
                                int *numPtr3 = (int *)ref vectori.X;
                                numPtr3[0] += num;
                                break;
                            }
                            vectori.Z = segment.Min.Z;
                            while (true)
                            {
                                if (vectori.Z > segment.Max.Z)
                                {
                                    int *numPtr2 = (int *)ref vectori.Y;
                                    numPtr2[0] += num;
                                    break;
                                }
                                Vector3I maxPos = Vector3I.Min((Vector3I)((vectori + num) - 1), segment.Max);
                                Vector3  min    = ((Vector3)(vectori * gridSize)) - vector;
                                Vector3  max    = (maxPos * gridSize) + vector;
                                this.AddBox(vectori, maxPos, ref min, ref max);
                                int *numPtr1 = (int *)ref vectori.Z;
                                numPtr1[0] += num;
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (Vector3I vectori4 in this.m_tmpCubes)
                {
                    Vector3 min = ((Vector3)(vectori4 * gridSize)) - vector;
                    Vector3 max = (vectori4 * gridSize) + vector;
                    this.AddBox(vectori4, vectori4, ref min, ref max);
                }
            }
        }
 List <MyVoxelSegmentation.Segment> GetSegments(List <Vector3I> positions)
 {
     m_seg.ClearInput();
     foreach (var p in positions)
     {
         m_seg.AddInput(p);
     }
     return(m_seg.FindSegments(MyVoxelSegmentationType.Simple));
 }
 List <MyVoxelSegmentation.Segment> GetSegments(List <Vector3I> positions, int index, int count)
 {
     m_seg.ClearInput();
     count = Math.Min(count, positions.Count);
     for (int i = index; i < index + count; i++)
     {
         m_seg.AddInput(positions[i]);
     }
     return(m_seg.FindSegments(MyVoxelSegmentationType.Simple));
 }
        void AddSegmentedParts(float gridSize, MyVoxelSegmentation segmenter, MyVoxelSegmentationType segmentationType)
        {
            if (segmenter != null)
            {
                int mergeIterations = segmentationType == MyVoxelSegmentationType.Optimized ? 1 : 0;
                //SegmenterBenchmark(collector, segmenter, mergeIterations);

                ProfilerShort.Begin("Prepare segmentation");
                segmenter.ClearInput();
                foreach (var cube in m_tmpCubes)
                {
                    segmenter.AddInput(cube);
                }
                ProfilerShort.End();

                ProfilerShort.Begin("Make segments");
                var segments = segmenter.FindSegments(segmentationType, mergeIterations);
                ProfilerShort.End();

                ProfilerShort.Begin("Add segments");
                foreach (var s in segments)
                {
                    Vector3 min = s.Min * gridSize - new Vector3(gridSize / 2.0f);
                    Vector3 max = s.Max * gridSize + new Vector3(gridSize / 2.0f);
                    AddBox(s.Min, s.Max, ref min, ref max);
                }
                ProfilerShort.End();
            }
            else
            {
                ProfilerShort.Begin("Add full cubes");
                foreach (var c in m_tmpCubes)
                {
                    Vector3 min = c * gridSize - new Vector3(gridSize / 2.0f);
                    Vector3 max = c * gridSize + new Vector3(gridSize / 2.0f);
                    AddBox(c, c, ref min, ref max);
                }
                ProfilerShort.End();
            }
        }
Ejemplo n.º 7
0
        void AddSegmentedParts(float gridSize, MyVoxelSegmentation segmenter, MyVoxelSegmentationType segmentationType)
        {
            if (segmenter != null)
            {
                int mergeIterations = segmentationType == MyVoxelSegmentationType.Optimized ? 1 : 0;
                //SegmenterBenchmark(collector, segmenter, mergeIterations);

                ProfilerShort.Begin("Prepare segmentation");
                segmenter.ClearInput();
                foreach (var cube in m_tmpCubes)
                {
                    segmenter.AddInput(cube);
                }
                ProfilerShort.End();

                ProfilerShort.Begin("Make segments");
                var segments = segmenter.FindSegments(segmentationType, mergeIterations);
                ProfilerShort.End();

                ProfilerShort.Begin("Add segments");
                foreach (var s in segments)
                {
                    Vector3 min = s.Min * gridSize - new Vector3(gridSize / 2.0f);
                    Vector3 max = s.Max * gridSize + new Vector3(gridSize / 2.0f);
                    AddBox(s.Min, s.Max, ref min, ref max);
                }
                ProfilerShort.End();
            }
            else
            {
                ProfilerShort.Begin("Add full cubes");
                foreach (var c in m_tmpCubes)
                {
                    Vector3 min = c * gridSize - new Vector3(gridSize / 2.0f);
                    Vector3 max = c * gridSize + new Vector3(gridSize / 2.0f);
                    AddBox(c, c, ref min, ref max);
                }
                ProfilerShort.End();
            }
        }
Ejemplo n.º 8
0
        void AddSegmentedParts(float gridSize, MyVoxelSegmentation segmenter, MyVoxelSegmentationType segmentationType)
        {
            int maxExCubes = (int)Math.Floor(MAX_BOX_EXTENT/gridSize);
            Vector3 gridSizeHalf = new Vector3(gridSize*0.5f);
            if (segmenter != null)
            {
                int mergeIterations = segmentationType == MyVoxelSegmentationType.Optimized ? 1 : 0;
                //SegmenterBenchmark(collector, segmenter, mergeIterations);

                ProfilerShort.Begin("Prepare segmentation");
                segmenter.ClearInput();
                foreach (var cube in m_tmpCubes)
                {
                    segmenter.AddInput(cube);
                }
                ProfilerShort.End();

                ProfilerShort.Begin("Make segments");
                var segments = segmenter.FindSegments(segmentationType, mergeIterations);
                ProfilerShort.End();

                ProfilerShort.Begin("Add segments");
                Vector3I it;
                Vector3I maxI;
                foreach (var s in segments)
                {
                    for (it.X = s.Min.X; it.X <= s.Max.X; it.X += maxExCubes)
                    {
                        for (it.Y = s.Min.Y; it.Y <= s.Max.Y; it.Y += maxExCubes)
                            for (it.Z = s.Min.Z; it.Z <= s.Max.Z; it.Z += maxExCubes)
                            {
                                maxI = Vector3I.Min(it + maxExCubes - 1, s.Max);
                                Vector3 min = it * gridSize - gridSizeHalf;
                                Vector3 max = maxI * gridSize + gridSizeHalf;
                                AddBox(it, maxI, ref min, ref max);
                }
                    }
                }

                //foreach (var s in segments)
                //{
                //    Vector3 min = s.Min * gridSize - gridSizeHalf;
                //    Vector3 max = s.Max * gridSize + gridSizeHalf;
                //    AddBox(s.Min, s.Max, ref min, ref max);
                //}
                ProfilerShort.End();
            }
            else
            {
                ProfilerShort.Begin("Add full cubes");
                foreach (var c in m_tmpCubes)
                {
                    Vector3 min = c * gridSize - gridSizeHalf;
                    Vector3 max = c * gridSize + gridSizeHalf;
                    AddBox(c, c, ref min, ref max);
                }
                ProfilerShort.End();
            }
        }
Ejemplo n.º 9
0
        void AddSegmentedParts(float gridSize, MyVoxelSegmentation segmenter, MyVoxelSegmentationType segmentationType)
        {
            int     maxExCubes   = (int)Math.Floor(MAX_BOX_EXTENT / gridSize);
            Vector3 gridSizeHalf = new Vector3(gridSize * 0.5f);

            if (segmenter != null)
            {
                int mergeIterations = segmentationType == MyVoxelSegmentationType.Optimized ? 1 : 0;
                //SegmenterBenchmark(collector, segmenter, mergeIterations);

                ProfilerShort.Begin("Prepare segmentation");
                segmenter.ClearInput();
                foreach (var cube in m_tmpCubes)
                {
                    segmenter.AddInput(cube);
                }
                ProfilerShort.End();

                ProfilerShort.Begin("Make segments");
                var segments = segmenter.FindSegments(segmentationType, mergeIterations);
                ProfilerShort.End();

                ProfilerShort.Begin("Add segments");
                Vector3I it;
                Vector3I maxI;
                foreach (var s in segments)
                {
                    for (it.X = s.Min.X; it.X <= s.Max.X; it.X += maxExCubes)
                    {
                        for (it.Y = s.Min.Y; it.Y <= s.Max.Y; it.Y += maxExCubes)
                        {
                            for (it.Z = s.Min.Z; it.Z <= s.Max.Z; it.Z += maxExCubes)
                            {
                                maxI = Vector3I.Min(it + maxExCubes - 1, s.Max);
                                Vector3 min = it * gridSize - gridSizeHalf;
                                Vector3 max = maxI * gridSize + gridSizeHalf;
                                AddBox(it, maxI, ref min, ref max);
                            }
                        }
                    }
                }

                //foreach (var s in segments)
                //{
                //    Vector3 min = s.Min * gridSize - gridSizeHalf;
                //    Vector3 max = s.Max * gridSize + gridSizeHalf;
                //    AddBox(s.Min, s.Max, ref min, ref max);
                //}
                ProfilerShort.End();
            }
            else
            {
                ProfilerShort.Begin("Add full cubes");
                foreach (var c in m_tmpCubes)
                {
                    Vector3 min = c * gridSize - gridSizeHalf;
                    Vector3 max = c * gridSize + gridSizeHalf;
                    AddBox(c, c, ref min, ref max);
                }
                ProfilerShort.End();
            }
        }