Exemplo n.º 1
0
        // iterate through each x-row of grid and set unsigned distances to be negative
        // inside the mesh, based on the intersection_counts
        void compute_signs(int ni, int nj, int nk, DenseGrid3f distances, DenseGrid3i intersection_counts)
        {
            Func <int, bool> isInsideF = (count) => { return(count % 2 == 1); };

            if (InsideMode == InsideModes.ParityCount)
            {
                isInsideF = (count) => { return(count > 0); }
            }
            ;

            if (UseParallel)
            {
                // can process each x-row in parallel
                AxisAlignedBox2i box = new AxisAlignedBox2i(0, 0, nj, nk);
                gParallel.ForEach(box.IndicesExclusive(), (vi) => {
                    if (CancelF())
                    {
                        return;
                    }

                    int j           = vi.x, k = vi.y;
                    int total_count = 0;
                    for (int i = 0; i < ni; ++i)
                    {
                        total_count += intersection_counts[i, j, k];
                        if (isInsideF(total_count))                   // if parity of intersections so far is odd,
                        {
                            distances[i, j, k] = -distances[i, j, k]; // we are inside the mesh
                        }
                    }
                });
            }
            else
            {
                for (int k = 0; k < nk; ++k)
                {
                    if (CancelF())
                    {
                        return;
                    }

                    for (int j = 0; j < nj; ++j)
                    {
                        int total_count = 0;
                        for (int i = 0; i < ni; ++i)
                        {
                            total_count += intersection_counts[i, j, k];
                            if (isInsideF(total_count))                   // if parity of intersections so far is odd,
                            {
                                distances[i, j, k] = -distances[i, j, k]; // we are inside the mesh
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// "invalid" value will be returned by queries if no valid result is found (eg bounded-distance query)
        /// </summary>
        public TriangleBinsGrid2d(AxisAlignedBox2d bounds, int numCells)
        {
            this.bounds = bounds;
            double   cellsize = bounds.MaxDim / (double)numCells;
            Vector2d origin   = bounds.Min - cellsize * 0.5 * Vector2d.One;

            indexer = new ShiftGridIndexer2(origin, cellsize);

            bins_x      = (int)(bounds.Width / cellsize) + 2;
            bins_y      = (int)(bounds.Height / cellsize) + 2;
            grid_bounds = new AxisAlignedBox2i(0, 0, bins_x - 1, bins_y - 1);
            bins_list   = new SmallListSet();
            bins_list.Resize(bins_x * bins_y);
        }