Пример #1
0
            public Tuple <double, double, double> compute_line_eqn(map_node n1, map_node n2)
            {
                // sore the point using x and then by y
                map_node temp;

                if (n1.x > n2.x)
                {
                    // swap bcoz n1.x greater
                    temp = n2;
                    n2   = n1;
                    n1   = temp;
                }
                else if (n1.x == n2.x)
                {
                    if (n1.y > n2.y)
                    {
                        // swap bcoz n1.y greater
                        temp = n2;
                        n2   = n1;
                        n1   = temp;
                    }
                }

                double a = n2.y - n1.y;         // a = y2 - y1
                double b = n1.x - n2.x;         // b = x1 - x2
                double c = a * n1.x + b * n1.y; // c = ax1 + by1

                return(Tuple.Create(a, b, c));
            }
Пример #2
0
            public map_square(control_node i_topleft, control_node i_topright, control_node i_bottomright, control_node i_bottomleft)
            {
                topleft     = i_topleft;
                topright    = i_topright;
                bottomleft  = i_bottomleft;
                bottomright = i_bottomright;

                centretop    = topleft.right;
                centreright  = bottomright.above;
                centrebottom = bottomleft.right;
                centreleft   = bottomleft.above;

                if (topleft.active)
                {
                    configuration += 8;
                }
                if (topright.active)
                {
                    configuration += 4;
                }
                if (bottomright.active)
                {
                    configuration += 2;
                }
                if (bottomleft.active)
                {
                    configuration += 1;
                }
            }
Пример #3
0
            public bool Equals(map_node other_nd)
            {
                bool return_var = false;

                if (this.vertex_index == other_nd.vertex_index)
                {
                    return_var = true;
                }
                return(return_var);
            }
Пример #4
0
 public control_node(double x, double y, bool i_active, int square_size) : base(x, y)
 {
     active = i_active;
     above  = new map_node(x, (y + (square_size / 2.0f))); // above node
     right  = new map_node((x + (square_size / 2.0f)), y); // right node
 }
Пример #5
0
        public void detect_surfaces(ref List <pslg_datastructure.surface_store> set_surfaces)
        {
            // Find the closed loop which are not self intersecting
            // transfer to temporary nodes and temporary edges
            // List<map_node> temp_border_nodes = new List<map_node>();
            List <map_edge> temp_border_edges = new List <map_edge>();

            //temp_border_nodes = the_squaregrid.border_nodes;
            temp_border_edges.AddRange(the_squaregrid.border_edges);

            //bool is_closed = false;
            //int i, j;
            // temporary surfaces
            List <pslg_datastructure.surface_store> temp_surfaces = new List <pslg_datastructure.surface_store>();


            while (temp_border_edges.Count > 0)                              // loop until all the border edges are visited
            {
                List <map_edge> temp_border_edges_1 = new List <map_edge>(); // border edge sublist 1
                temp_border_edges_1.AddRange(temp_border_edges);             // add the main list to sublist 1
                temp_border_edges_1.RemoveAt(0);                             // remove the first edge


                List <map_edge> temp_border_edges_2 = new List <map_edge>(); // border edge sublist 2
                temp_border_edges_2.Add(temp_border_edges[0]);               // add only the first edge frpm mail list
                int current_edge_end_node = temp_border_edges_2[0].index_1;  // only one object is at the list


                while (temp_border_edges_1.Count > 0)
                {
                    map_edge connected_edge = temp_border_edges_1.Find(obj => obj.index_0 == current_edge_end_node || obj.index_1 == current_edge_end_node); // find the connected edge
                    if (connected_edge != null)
                    {
                        if (connected_edge.index_1 == current_edge_end_node) // if the edge end
                        {
                            // then the orientation is towards this point so reverse orientation
                            connected_edge.change_orientation();
                        }

                        current_edge_end_node = connected_edge.index_1;                                                         // index 0 is connected
                        temp_border_edges_2.Add(connected_edge);                                                                // add to the sub list
                        temp_border_edges_1.RemoveAt(temp_border_edges_1.FindIndex(obj => obj.Equals(connected_edge) == true)); //remove from the sub list 1
                    }
                    else
                    {
                        break; // exit because there is no edge connected to the current edge end node
                    }
                }
                //_________________________________________
                if (temp_border_edges_2[0].index_0 == current_edge_end_node) // we started with index_0 so check whether index_1 is connected to the last in the list
                {
                    // pslg_datastructure Edges and Points
                    List <pslg_datastructure.edge2d>  surf_edges  = new List <pslg_datastructure.edge2d>();
                    List <pslg_datastructure.point2d> surf_points = new List <pslg_datastructure.point2d>();

                    // closed boundary is confirmed
                    List <map_node> temp_border_nodes = new List <map_node>();
                    foreach (map_edge edg in temp_border_edges_2)
                    {
                        map_node the_node_1 = the_squaregrid.all_nodes[edg.index_0];
                        map_node the_node_2 = the_squaregrid.all_nodes[edg.index_1];

                        //pslg_datastructure.point2d pt1,pt2;

                        // Add first node
                        if (temp_border_nodes.Exists(obj => obj.Equals(the_node_1) == true) == false)
                        {
                            temp_border_nodes.Add(the_node_1);
                            //pslg_datastructure.point2d pt1 = new pslg_datastructure.point2d(surf_points.Count, the_node_1.x, the_node_1.y);
                            surf_points.Add(new pslg_datastructure.point2d(surf_points.Count, the_node_1.x, the_node_1.y));
                        }

                        // Add second node
                        if (temp_border_nodes.Exists(obj => obj.Equals(the_node_2) == true) == false)
                        {
                            temp_border_nodes.Add(the_node_2);
                            //pslg_datastructure.point2d pt2 = new pslg_datastructure.point2d(surf_points.Count, the_node_2.x, the_node_2.y);
                            surf_points.Add(new pslg_datastructure.point2d(surf_points.Count, the_node_2.x, the_node_2.y));
                        }

                        // Add the edges
                        pslg_datastructure.point2d pt1 = surf_points.Find(obj => obj.Equals(new pslg_datastructure.point2d(-1, the_node_1.x, the_node_1.y)) == true);
                        pslg_datastructure.point2d pt2 = surf_points.Find(obj => obj.Equals(new pslg_datastructure.point2d(-1, the_node_2.x, the_node_2.y)) == true);

                        surf_edges.Add(new pslg_datastructure.edge2d(surf_edges.Count, pt1, pt2));
                    }

                    // check the surface orientation
                    pslg_datastructure.surface_store t_surf = new pslg_datastructure.surface_store(temp_surfaces.Count, surf_points, surf_edges, temp_surfaces.Count);

                    if (t_surf.SignedPolygonArea() < 0)// check whether the outter surface is oriented anti clockwise (negative area = clockwise)
                    {
                        // clockwise orientation detected so reverse the orientation to be anti-clockwise
                        t_surf.reverse_surface_orinetation();
                    }

                    temp_surfaces.Add(t_surf);
                    //System.Threading.Thread.Sleep(200);
                }

                foreach (map_edge edg in temp_border_edges_2)
                {
                    //remove from the main edge
                    temp_border_edges.RemoveAt(temp_border_edges.FindIndex(obj => obj.Equals(edg) == true));
                }
            }

            // sort the surfaces with surface area
            temp_surfaces = temp_surfaces.OrderBy(obj => obj.surface_area).ToList();
            // Set the polygon inside polygon
            List <int> skip_index = new List <int>();

            for (int i = 1; i < temp_surfaces.Count; i++)
            {
                List <int> inner_surface_index = new List <int>(); // variable to store the index of surface which is inside the i_th surface

                for (int j = i - 1; j >= 0; j--)                   // cycle through all the other surface except this one
                {
                    if (skip_index.Contains(j) == true)
                    {
                        continue; // skip the nested surfaces
                    }

                    bool is_contain = true;                                                   // variable to store the point is inside true or false
                    foreach (pslg_datastructure.point2d pt in temp_surfaces[j].surface_nodes) // cycle thro all the point of j_th polygon
                    {
                        if (temp_surfaces[i].PointInPolygon(pt.x, pt.y) == false)             // check whether outter polygon contains the inner polygon
                        {
                            is_contain = false;
                            break;
                        }
                    }

                    if (is_contain == true)
                    {
                        skip_index.Add(j); // skip index is used to avoid adding nested surfaces
                        inner_surface_index.Add(j);
                    }
                }

                List <pslg_datastructure.surface_store> temp_inner_surface = new List <pslg_datastructure.surface_store>();
                foreach (int k in inner_surface_index)
                {
                    // reversed k surface

                    temp_inner_surface.Add(temp_surfaces[k]); // add the found inner surfaces to temporary inner surfaces
                }

                // innersurface count not = 0
                if (inner_surface_index.Count != 0)
                {
                    temp_surfaces[i].set_inner_surfaces(temp_inner_surface);
                }
            }

            // Surface detection complete add to the main list
            set_surfaces = new List <pslg_datastructure.surface_store>();
            set_surfaces.AddRange(temp_surfaces);
        }