Esempio n. 1
0
    /**
     * @brief Gather the separate decoded characters into clusters.
     */
    private static void GatherIntoClusters ()
    {
        while (allDecos.Count > 0) {

            /*
             * Find leftmost character.
             */
            Deco deco = allDecos.First.Value;
            allDecos.RemoveFirst ();

            bool debug = false; // (deco.x >= 1420) && (deco.x <= 1540) && (deco.y >= 2210) && (deco.y <= 2250);
            if (debug) Console.WriteLine ("GatherIntoClusters*: " + deco.x + "," + deco.y + " <" + deco.c + ">");

            /*
             * Sometimes there are stray marks around that look like ' and ..
             * Skip over them so they don't obscure a nearby legitimate number.
             * See BAB 39^07'N.
             */
            if ((deco.c == '\'') || (deco.c == '.')) continue;

            /*
             * Create a cluster for it.
             */
            Cluster cluster = new Cluster ();
            cluster.vertical = landscape;

            /*
             * Append first character to cluster and likewise with all
             * subsequent nearby characters to its right that overlap on
             * the Y axis.
             */
        useit:
            if (debug) Console.WriteLine ("GatherIntoClusters*:   " + deco.c);
            cluster.InsertDeco (deco);
            if ((deco.c == 'N') || (deco.c == 'S') || (deco.c == 'E') || (deco.c == 'W')) goto endclus;

            for (LinkedListNode<Deco> ptr = allDecos.First; ptr != null; ptr = ptr.Next) {
                Deco dd = ptr.Value;                      // scan by ascending X value
                if (debug) Console.WriteLine ("GatherIntoClusters*: ? " + dd.c + " " + dd.x + "," + dd.y);
                if (dd.x > cluster.hix + MAXGAP) break;   // if too far right, nothing more can match
                if (dd.x < cluster.hix - 2) continue;     // if too far left, just ignore it

                /*
                 * We have char dd just to the right of char deco
                 * but we don't know if they are vertically aligned.
                 *
                 * Sometimes we mis-decode an apostrophe as a dot.
                 * Eg, HOP 36^40'N
                 * So we have to fix it in context.
                 */
                int ydiff = dd.y - deco.y;
                if (dd.c == '.') {
                    if ((ydiff >= -YOVER) && (ydiff <= YOVER)) {
                        // the dot is near the top of the line of chars
                        dd.c = '\'';
                    } else {
                        ydiff += dd.h - deco.h;
                        if ((ydiff < -YOVER) || (ydiff > YOVER)) continue;
                        // the dot is near the bottom of the line of chars
                    }
                    dd.y = deco.y;
                    dd.h = deco.h;
                } else {
                    if ((ydiff < -YOVER) || (ydiff > YOVER)) continue;
                }

                /*
                 * Remove from allDecos and append to cluster.
                 */
                allDecos.Remove (ptr);
                deco = dd;
                goto useit;
            }

            /*
             * If valid size, append to list of all clusters and draw box around it.
             */
        endclus:
            if (verbose) Console.WriteLine ("cluster " + cluster.lox + "," + cluster.loy + " <" + cluster.Result + ">");
            if (cluster.IsLatLon) {
                clusters.AddLast (cluster);
            }
        }
    }