00001 /* Copyright (C) 2002 Dominic Letourneau (dominic.letourneau@usherbrooke.ca) 00002 00003 This library is free software; you can redistribute it and/or 00004 modify it under the terms of the GNU Lesser General Public 00005 License as published by the Free Software Foundation; either 00006 version 2.1 of the License, or (at your option) any later version. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Lesser General Public License for more details. 00012 00013 You should have received a copy of the GNU Lesser General Public 00014 License along with this library; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00016 */ 00017 // Components.h: interface for the CComponents class. 00018 // 00019 ////////////////////////////////////////////////////////////////////// 00020 00021 #ifndef _COMPONENTS_H_ 00022 #define _COMPONENTS_H_ 00023 00024 #include <vector> 00025 #include <list> 00026 #include "CRect.h" 00027 #include "BufferedNode.h" 00028 #include "Image.h" 00029 00030 namespace RobotFlow { 00031 00032 #define MAX_COLOR 32 //THIS ALGORITHM CANNOT ALLOW MORE THAN 32 COLORS (CAUSE 32bits for unsigned int) 00033 #define MAX_CELLS 76800 //IMAGE_WIDTH * IMAGE_HEIGHT 00034 #define MAX_RECT 4800 //MAX_CELLS / MIN_RECT_AREA + 1 00035 #define MAX_X_GAP 3 //USER DEFINED X GAP BETWEEN TWO PIXELS OF THE SAME COLOR 00036 #define MAX_Y_GAP 3 //USER DEFINED Y GAP BETWEEN TWO PIXELS OF THE SAME COLOR 00037 00038 //local prototype (for sort) 00039 int CRect_compare(const void *a, const void *b); 00040 00041 class Components : public FD::BufferedNode { 00042 00043 00044 public: 00045 00046 Components(); 00047 00048 Components(std::string nodeName, FD::ParameterSet params); 00049 00050 ~Components(); 00051 00052 00053 00054 void get_components (Image &image); 00055 00056 void initialize (int width, int height, int num_colors); 00057 00058 int get_component_count(){return m_rect_count;} 00059 00060 std::list<CRect*> & get_color_components(int color); 00061 00062 void draw_rectangles(int color, unsigned short *image_16bits, unsigned short value); 00063 00064 void calculate(int output_id, int count, FD::Buffer &out); 00065 00066 void reset(); 00067 00068 private: 00069 00070 void get_components (unsigned short *image_16bits); 00071 void get_components (unsigned char *image_8bits); 00072 void find_runs (unsigned short *image); 00073 void find_runs (unsigned char *image); 00074 00075 void recursive_compute(int line_number); 00076 00077 void sort(int color); 00078 00079 std::vector<std::list<ImageCell *> > m_cell_list[MAX_COLOR]; 00080 00081 //list<CRect*> m_rect_list[MAX_COLOR]; 00082 00083 int m_width; 00084 int m_height; 00085 int m_color_number; 00086 int m_cell_count; 00087 int m_rect_count; 00088 int m_x_gap; 00089 int m_y_gap; 00090 int m_minArea; 00091 int m_imageID; 00092 int m_lookupID; 00093 int m_blobsID; 00094 00095 ImageCell *m_cell_array; //reusable cells 00096 CRect *m_rect_array; //reusable rectangles 00097 00098 CRect *m_current_rect; 00099 00100 //the color table 00101 unsigned int *m_color_table; 00102 00103 int m_num_colors; 00104 00105 FD::ObjectRef m_components_data; 00106 00107 }; 00108 00109 }//namespace RobotFlow 00110 00111 #endif