00001 /*!@file NeovisionII/nv2_common.h */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00005 // by the University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Rob Peters <rjpeters at usc dot edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/NeovisionII/nv2_common.h $ 00035 // $Id: nv2_common.h 9742 2008-05-11 00:41:01Z lior $ 00036 // 00037 00038 #ifndef NEOVISIONII_NV2_COMMON_H_DEFINED 00039 #define NEOVISIONII_NV2_COMMON_H_DEFINED 00040 00041 #include <stdint.h> 00042 #include <stdlib.h> 00043 00044 #ifdef __cplusplus 00045 # define NV2_EXTERN_C extern "C" 00046 #else 00047 # define NV2_EXTERN_C 00048 #endif 00049 00050 /// Different pixel types that can be stored in an nv2_image_patch 00051 enum nv2_pixel_type 00052 { 00053 NV2_PIXEL_TYPE_NONE = 5000, 00054 NV2_PIXEL_TYPE_GRAY8 = 5001, 00055 NV2_PIXEL_TYPE_RGB24 = 5002 00056 }; 00057 00058 /// Get the number of bytes used per pixel of a given type 00059 uint32_t nv2_pixel_type_bytes_per_pixel(enum nv2_pixel_type typ); 00060 00061 /// Represents the current version of struct nv2_image_patch 00062 /** Make sure that any struct nv2_image_patch objects to be sent 00063 across the network have this value assigned to their 00064 protocol_version field, and make sure that any struct 00065 nv2_image_patch objects received from the network have the proper 00066 protocol_version before using the other data fields. 00067 */ 00068 #define NV2_PATCH_PROTOCOL_VERSION ((uint32_t) 1004) 00069 00070 /// Represents an image patch, with image data stored in row-major fashion 00071 struct nv2_image_patch 00072 { 00073 uint32_t protocol_version; 00074 uint32_t width; 00075 uint32_t height; 00076 uint32_t id; 00077 uint32_t is_training_image; 00078 uint32_t type; 00079 uint32_t fix_x; 00080 uint32_t fix_y; 00081 char training_label[128]; 00082 char remote_command[128]; 00083 unsigned char* data; // this field must remain last 00084 }; 00085 00086 #define NV2_IMAGE_PATCH_HEADER_SIZE \ 00087 (sizeof(struct nv2_image_patch) - sizeof(unsigned char*)) 00088 00089 /// Initialize with the current protocol version, and zeros elsewhere 00090 /** This function does NOT free any data associated with p->data; it 00091 is up to the caller to do that (if necessary) before calling this 00092 function. */ 00093 NV2_EXTERN_C 00094 void nv2_image_patch_init_empty(struct nv2_image_patch* p); 00095 00096 /// Free the data array associated with p, and reinitialize to an empty state 00097 NV2_EXTERN_C 00098 void nv2_image_patch_destroy(struct nv2_image_patch* p); 00099 00100 /// Copy a training label into the image patch 00101 NV2_EXTERN_C 00102 void nv2_image_patch_set_training_label( 00103 struct nv2_image_patch* p, 00104 const char* label); 00105 00106 /// Copy a remote command into the image patch 00107 NV2_EXTERN_C 00108 void nv2_image_patch_set_remote_command( 00109 struct nv2_image_patch* p, 00110 const char* command); 00111 00112 /// Represents the current version of struct nv2_patch_label 00113 /** Be sure to assign the proper protocol_version before sending any 00114 nv2_patch_label objects across the network, and be sure to check 00115 the protocol_version field of any nv2_patch_label objects received 00116 from the network before using any of the other data fields. 00117 */ 00118 #define NV2_LABEL_PROTOCOL_VERSION ((uint32_t) 2004) 00119 00120 /// Represents a label for an image patch 00121 /** The patch_id indicates which nv2_image_patch this label 00122 corresponds to, and the name field contains a human-readable label 00123 for the patch. 00124 */ 00125 struct nv2_patch_label 00126 { 00127 uint32_t protocol_version; 00128 uint32_t patch_id; 00129 uint32_t confidence; ///< min = 0; max = NV2_MAX_LABEL_CONFIDENCE 00130 char source[16]; 00131 char name[64]; 00132 char extra_info[64]; 00133 }; 00134 00135 /// The scaling factor used to represent confidence levels in nv2_patch_label 00136 /** A raw confidence value in [0,1] should be encoded as 00137 uint32_t(0.5 + raw*NV2_MAX_LABEL_CONFIDENCE) */ 00138 #define NV2_MAX_LABEL_CONFIDENCE 10000u 00139 00140 /// Initialize with the current protocol version, and zeros elsewhere 00141 NV2_EXTERN_C 00142 void nv2_patch_label_init_empty(struct nv2_patch_label* l); 00143 00144 /// Helper for nv2_fatal 00145 NV2_EXTERN_C 00146 void nv2_fatal_impl(const char* file, int line, const char* function, 00147 const char* what); 00148 00149 /// Print an error message to stderr and exit 00150 #define nv2_fatal(what) nv2_fatal_impl(__FILE__, __LINE__, __FUNCTION__, what) 00151 00152 /// Helper for nv2_warn 00153 NV2_EXTERN_C 00154 void nv2_warn_impl(const char* file, int line, const char* function, 00155 const char* what); 00156 00157 /// Print a warning message to stderr 00158 #define nv2_warn(what) nv2_warn_impl(__FILE__, __LINE__, __FUNCTION__, what) 00159 00160 /// Keep doing write() calls until either all the bytes are written or an error occurs 00161 /** Returns the number of bytes written; if this number is less than 00162 the number of requested bytes (nbytes), then it means that some 00163 error occurred */ 00164 size_t nv2_robust_write(int fd, const void* data, size_t nbytes); 00165 00166 /// Keep doing read() calls until either all the bytes are read or an error occurs 00167 /** Returns the number of bytes read; if this number is less than the 00168 number of requested bytes (nbytes), then it means that some error 00169 occurred 00170 00171 @param nchunks if not null, then the total number of read() system 00172 calls performed will be returned through this pointer 00173 */ 00174 size_t nv2_robust_read(int fd, void* buf, size_t nbytes, 00175 int* nchunks); 00176 00177 /// Default tcp port number for the patch reader 00178 #define NV2_PATCH_READER_PORT 9930 00179 00180 /// Default tcp port number for the label reader 00181 #define NV2_LABEL_READER_PORT 9931 00182 00183 #undef NV2_EXTERN_C 00184 00185 // ###################################################################### 00186 /* So things look consistent in everyone's emacs... */ 00187 /* Local Variables: */ 00188 /* indent-tabs-mode: nil */ 00189 /* c-file-style: "linux" */ 00190 /* End: */ 00191 00192 #endif // NEOVISIONII_NV2_COMMON_H_DEFINED