예제 #1
0
 public StlClassifier(string _stl_location, int _bin_count)
 {
     //build bounds...
     bin_count       = _bin_count;
     stl_location    = _stl_location;
     temp_facet_data = new STL(_stl_location);
     bounds          = get_bounds();
     classifier      = new GridClassifier(bin_count, bounds);
     lookup_table    = new StlClassificationTable(bin_count);
 }
예제 #2
0
        public RectangularCover(Triangle T, GridClassifier map)
        {
            tri  = T;
            grid = map;

            //O(n^2) unfortunately.
            List <int> i_indices_list = new List <int>();
            List <int> j_indices_list = new List <int>();

            //Optimization here: Precompute containment of each point in the GridClassifier object, then load in O(1). Implement if performance is horrible.
            bool[,] grid_point_interior_status = new bool[map.Count + 1, map.Count + 1];
            int[] ll   = map.GetIndices(new Pair(T.Xmin, T.Ymin));
            int[] ur   = map.GetIndices(new Pair(T.Xmax, T.Ymax));
            int   imin = ll[0];
            int   jmin = ll[1];
            int   imax = ur[0];
            int   jmax = ur[1];

            //Loop 1: precompute interiors
            for (int i = imin; i < imax + 1; i++)
            {
                for (int j = jmin; j < jmax + 1; j++)
                {
                    grid_point_interior_status[i, j] = T.Contains(map.ComputeXY(i, j));
                }
            }

            //Loop 2: iterate.
            for (int i = 0; i < 3; i++)
            {
                int[] vertexcoords = map.GetIndices(T[i]);
                i_indices_list.Add(vertexcoords[0]);
                j_indices_list.Add(vertexcoords[1]);
            }
            for (int i = imin; i < imax + 1; i++)
            {
                for (int j = jmin; j < jmax + 1; j++)
                {
                    //Check corners of rectangle
                    bool[] corners =
                    {
                        grid_point_interior_status[i, j],               //Lower left
                        grid_point_interior_status[i + 1, j],           //Lower right
                        grid_point_interior_status[i, j + 1],           //Upper left
                        grid_point_interior_status[i + 1, j + 1]        //Upper right
                    };
                    bool rectangle_has_interior_point = MathTools.CheckAny(corners);
                    if (rectangle_has_interior_point)
                    {
                        //No more computations should occur after here.
                        i_indices_list.Add(i);
                        j_indices_list.Add(j);
                    }
                    else
                    {
                        //Only check three - see reference above.
                        Pair[] ccw_orientation_cornerpoints = new Pair[]
                        {
                            new Pair(map.ComputeXY(i, j)),                            //Lower left
                            new Pair(map.ComputeXY(i + 1, j)),                        //Lower right
                            new Pair(map.ComputeXY(i + 1, j + 1)),                    //Upper right
                            new Pair(map.ComputeXY(i, j + 1))                         //Uppper left
                        };
                        if (check_three_side(ccw_orientation_cornerpoints, T))
                        {
                            i_indices_list.Add(i);
                            j_indices_list.Add(j);
                        }
                    }
                }
            }
            i_indices = i_indices_list.ToArray();
            j_indices = j_indices_list.ToArray();
        }