Community Core Vision 1.4
Cross platform, user friendly computer vision.
C:/CCV/1.4/addons/ofxFiducialFinder/src/libfidtrack/segment.h
Go to the documentation of this file.
00001 /*
00002   Fiducial tracking library.
00003   Copyright (C) 2004 Ross Bencina <rossb@audiomulch.com>
00004   Maintainer (C) 2005-2008 Martin Kaltenbrunner <mkalten@iua.upf.edu>
00005 
00006   This library is free software; you can redistribute it and/or
00007   modify it under the terms of the GNU Lesser General Public
00008   License as published by the Free Software Foundation; either
00009   version 2.1 of the License, or (at your option) any later version.
00010 
00011   This library is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   Lesser General Public License for more details.
00015 
00016   You should have received a copy of the GNU Lesser General Public
00017   License along with this library; if not, write to the Free Software
00018   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 */
00020 
00021 #ifndef INCLUDED_SEGMENT_H
00022 #define INCLUDED_SEGMENT_H
00023 
00024 #ifdef __cplusplus
00025 extern "C"
00026 {
00027 #endif /* __cplusplus */
00028 
00029 
00030 /*
00031     usage:
00032 
00033     Segmenter s;
00034 
00035     ...
00036     
00037     initialize_segmenter( &s, WIDTH, HEIGHT, 8 );
00038 
00039     ...
00040 
00041     step_segmenter( &s, thresholded_image, WIDTH, HEIGHT );
00042 
00043     ...
00044 
00045     terminate_segmenter( &s );
00046 */
00047 
00048 #define NO_REGION_FLAG                  (0)
00049 
00050 #define FREE_REGION_FLAG                (1)
00051 
00052 #define ADJACENT_TO_ROOT_REGION_FLAG    (2)
00053 
00054 /*
00055     saturated regions are those whose adjacency list became full and other nodes
00056     couldn't be made adjacent, either during a make_adjacent operation or
00057     during a merge operation.
00058 */
00059 #define SATURATED_REGION_FLAG           (4)
00060 
00061 /*
00062     fragmented regions are those which couldn't be made adjacent to another
00063     region (or had to be detached from another region) because the other region
00064     was saturated.
00065 */
00066 #define FRAGMENTED_REGION_FLAG          (8)
00067 
00068 #define LOST_SYMBOL_FLAG                                (16)
00069 
00070 #define VALID_REGION_FLAG                               (64)
00071 
00072 #define UNKNOWN_REGION_LEVEL            (-1)
00073 
00074 #define REGION_GATE_AREA                                1
00075 
00076 typedef struct Span{
00077         int start, end;
00078         struct Span *next;
00079 } Span;
00080 
00081 typedef struct fidRegion{
00082     struct fidRegion *previous, *next;
00083     unsigned char colour;
00084     short left, top, right, bottom;
00085     short center_x, center_y;
00086 
00087         struct Span *first_span;
00088         struct Span *last_span;
00089         int area;
00090         
00091     int flags;
00092 
00093     short level;                            /* initialized to UNKNOWN_REGION_LEVEL */
00094     short depth;                            /* initialized to 0 */
00095     short children_visited_count;           /* initialized to 0 */
00096     short descendent_count;                 /* initialized to 0x7FFF */
00097     char *depth_string;                     /* not initialized by segmenter */
00098     
00099     short adjacent_region_count;
00100     struct fidRegion *adjacent_regions[ 1 ];   /* variable length array of length max_adjacent_regions */
00101 } fidRegion;
00102 
00103 
00104 typedef struct RegionReference{
00105     fidRegion *region;
00106     struct RegionReference *redirect;
00107 } RegionReference;
00108 
00109 
00110 
00111 //#define REGIONREF_IS_REDIRECTED(r) ((r)->redirect != (r))
00112 
00113 
00114 #define RESOLVE_REGIONREF_REDIRECTS( x, r )                                    \
00115 {                                                                              \
00116     if( r->redirect != r ){                                                    \
00117         RegionReference *result = r;                                                                               \
00118                 while( result->redirect != result )                                                                    \
00119             result = result->redirect;                                         \
00120         r->redirect = result;                                                  \
00121         x = result;                                                            \
00122     }else{                                                                     \
00123         x = r;                                                                 \
00124     }                                                                          \
00125 }
00126 
00127 
00128 void initialize_head_region( fidRegion *r );
00129 void link_region( fidRegion *head, fidRegion* r );
00130 void unlink_region( fidRegion* r );
00131 
00132 
00133 typedef struct Segmenter{
00134     RegionReference *region_refs;
00135     int region_ref_count;
00136     unsigned char *regions;     /* buffer containing raw region ptrs */
00137     unsigned char *spans;               /* buffer containing raw span ptrs */
00138     int region_count;
00139     fidRegion *freed_regions_head;
00140 
00141     int sizeof_region;
00142     int max_adjacent_regions;
00143         
00144         short width, height;
00145 
00146     RegionReference **regions_under_construction;
00147 }Segmenter;
00148 
00149 #define LOOKUP_SEGMENTER_REGION( s, index )\
00150     (fidRegion*)(s->regions + (s->sizeof_region * (index)))
00151 
00152 #define LOOKUP_SEGMENTER_SPAN( s, index )\
00153     (Span*)(s->spans + (sizeof(Span) * (index)))
00154 
00155 void initialize_segmenter( Segmenter *segments, int width, int height, int max_adjacent_regions );
00156 void terminate_segmenter( Segmenter *segments );
00157 
00158 void step_segmenter( Segmenter *segments, const unsigned char *source );
00159 
00160 
00161 #ifdef __cplusplus
00162 }
00163 #endif /* __cplusplus */
00164 #endif /* INCLUDED_SEGMENT_H */
00165 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines