ccstruct/stepblob.cpp

Go to the documentation of this file.
00001 
00020 #include "mfcpch.h"
00021 #include          "stepblob.h"
00022 
00023 ELISTIZE_S (C_BLOB)
00024 
00025 
00031 static void position_outline(                          //put in place
00032                              C_OUTLINE *outline,       //thing to place
00033                              C_OUTLINE_LIST *destlist  //desstination list
00034                             ) {
00035   C_OUTLINE *dest_outline;       //outline from dest list
00036   C_OUTLINE_IT it = destlist;    //iterator
00037                                  //iterator on children
00038   C_OUTLINE_IT child_it = outline->child ();
00039 
00040   if (!it.empty ()) {
00041     do {
00042       dest_outline = it.data (); //get destination
00043                                  //encloses dest
00044       if (*dest_outline < *outline) {
00045                                  //take off list
00046         dest_outline = it.extract ();
00047                                  //put this in place
00048         it.add_after_then_move (outline);
00049                                  //make it a child
00050         child_it.add_to_end (dest_outline);
00051         while (!it.at_last ()) {
00052           it.forward ();         //do rest of list
00053                                  //check for other children
00054           dest_outline = it.data ();
00055           if (*dest_outline < *outline) {
00056                                  //take off list
00057             dest_outline = it.extract ();
00058             child_it.add_to_end (dest_outline);
00059             //make it a child
00060             if (it.empty ())
00061               break;
00062           }
00063         }
00064         return;                  //finished
00065       }
00066                                  //enclosed by dest
00067       else if (*outline < *dest_outline) {
00068         position_outline (outline, dest_outline->child ());
00069         //place in child list
00070         return;                  //finished
00071       }
00072       it.forward ();
00073     }
00074     while (!it.at_first ());
00075   }
00076   it.add_to_end (outline);       //at outer level
00077 }
00078 
00079 
00086 #ifndef GRAPHICS_DISABLED
00087 static void plot_outline_list(                       //draw outlines
00088                               C_OUTLINE_LIST *list,  //outline to draw
00089                               WINDOW window,         //window to draw in
00090                               COLOUR colour,         //colour to use
00091                               COLOUR child_colour    //colour of children
00092                              ) {
00093   C_OUTLINE *outline;            //current outline
00094   C_OUTLINE_IT it = list;        //iterator
00095 
00096   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00097     outline = it.data ();
00098                                  //draw it
00099     outline->plot (window, colour);
00100     if (!outline->child ()->empty ())
00101       plot_outline_list (outline->child (), window,
00102         child_colour, child_colour);
00103   }
00104 }
00105 #endif
00106 
00107 
00113 static void reverse_outline_list(                      //reverse outlines
00114                                  C_OUTLINE_LIST *list  //outline to reverse
00115                                 ) {
00116   C_OUTLINE *outline;            //current outline
00117   C_OUTLINE_IT it = list;        //iterator
00118 
00119   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00120     outline = it.data ();
00121     outline->reverse ();         //reverse it
00122     if (!outline->child ()->empty ())
00123       reverse_outline_list (outline->child ());
00124   }
00125 }
00126 
00127 
00134 C_BLOB::C_BLOB(                              //constructor
00135                C_OUTLINE_LIST *outline_list  //in random order
00136               ) {
00137   C_OUTLINE *outline;            //current outline
00138   C_OUTLINE_IT it = outline_list;//iterator
00139 
00140   while (!it.empty ()) {         //grab the list
00141     outline = it.extract ();     //get off the list
00142                                  //put it in place
00143     position_outline(outline, &outlines); 
00144     if (!it.empty ())
00145       it.forward ();
00146   }
00147   it.set_to_list (&outlines);
00148   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00149     outline = it.data ();
00150     if (outline->turn_direction () < 0) {
00151       outline->reverse ();
00152       reverse_outline_list (outline->child ());
00153       outline->set_flag (COUT_INVERSE, TRUE);
00154     }
00155     else {
00156       outline->set_flag (COUT_INVERSE, FALSE);
00157     }
00158   }
00159 }
00160 
00161 
00167 BOX C_BLOB::bounding_box() {  //bounding box
00168   C_OUTLINE *outline;            //current outline
00169   C_OUTLINE_IT it = &outlines;   //outlines of blob
00170   BOX box;                       //bounding box
00171 
00172   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00173     outline = it.data ();
00174     box += outline->bounding_box ();
00175   }
00176   return box;
00177 }
00178 
00179 
00183 INT32 C_BLOB::area() {  //area
00184   C_OUTLINE *outline;            //current outline
00185   C_OUTLINE_IT it = &outlines;   //outlines of blob
00186   INT32 total;                   //total area
00187 
00188   total = 0;
00189   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00190     outline = it.data ();
00191     total += outline->area ();
00192   }
00193   return total;
00194 }
00195 
00196 
00200 INT32 C_BLOB::outer_area() {  //area
00201   C_OUTLINE *outline;            //current outline
00202   C_OUTLINE_IT it = &outlines;   //outlines of blob
00203   INT32 total;                   //total area
00204 
00205   total = 0;
00206   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00207     outline = it.data ();
00208     total += outline->outer_area ();
00209   }
00210   return total;
00211 }
00212 
00213 
00219 INT32 C_BLOB::count_transitions(                 //area
00220                                 INT32 threshold  //on size
00221                                ) {
00222   C_OUTLINE *outline;            //current outline
00223   C_OUTLINE_IT it = &outlines;   //outlines of blob
00224   INT32 total;                   //total area
00225 
00226   total = 0;
00227   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00228     outline = it.data ();
00229     total += outline->count_transitions (threshold);
00230   }
00231   return total;
00232 }
00233 
00234 
00240 void C_BLOB::move(                  // reposition blob
00241                   const ICOORD vec  // by vector
00242                  ) {
00243   C_OUTLINE_IT it(&outlines);  // iterator
00244 
00245   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
00246     it.data ()->move (vec);      // move each outline
00247 }
00248 
00249 
00253 #ifndef GRAPHICS_DISABLED
00254 void C_BLOB::plot(                     //draw it
00255                   WINDOW window,       //window to draw in
00256                   COLOUR blob_colour,  //main colour
00257                   COLOUR child_colour  //for holes
00258                  ) {
00259   plot_outline_list(&outlines, window, blob_colour, child_colour); 
00260 }
00261 #endif

Generated on Wed Feb 28 19:49:08 2007 for Tesseract by  doxygen 1.5.1