00001 /*========================================================================= 00002 00003 Program: The OpenIGTLink Library 00004 Module: $HeadURL: $ 00005 Language: C 00006 Date: $Date: 2010-11-23 14:47:40 -0500 (Tue, 23 Nov 2010) $ 00007 Version: $Revision: 6958 $ 00008 00009 Copyright (c) Insight Software Consortium. All rights reserved. 00010 00011 This software is distributed WITHOUT ANY WARRANTY; without even 00012 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00013 PURPOSE. See the above copyright notices for more information. 00014 00015 =========================================================================*/ 00016 00017 #ifndef __IGTL_NDARRAY_H 00018 #define __IGTL_NDARRAY_H 00019 00020 #include "igtl_win32header.h" 00021 #include "igtl_util.h" 00022 #include "igtl_types.h" 00023 #include "igtl_win32header.h" 00024 00025 #define IGTL_NDARRAY_HEADER_SIZE 2 00026 00027 /* Scalar type */ 00028 #define IGTL_NDARRAY_STYPE_TYPE_INT8 2 00029 #define IGTL_NDARRAY_STYPE_TYPE_UINT8 3 00030 #define IGTL_NDARRAY_STYPE_TYPE_INT16 4 00031 #define IGTL_NDARRAY_STYPE_TYPE_UINT16 5 00032 #define IGTL_NDARRAY_STYPE_TYPE_INT32 6 00033 #define IGTL_NDARRAY_STYPE_TYPE_UINT32 7 00034 #define IGTL_NDARRAY_STYPE_TYPE_FLOAT32 10 00035 #define IGTL_NDARRAY_STYPE_TYPE_FLOAT64 11 00036 #define IGTL_NDARRAY_STYPE_TYPE_COMPLEX 13 00037 00038 #define IGTL_NDARRAY_HOST_TO_NETWORK 0 00039 #define IGTL_NDARRAY_NETWORK_TO_HOST 1 00040 00041 00042 #ifdef __cplusplus 00043 extern "C" { 00044 #endif 00045 00046 /* 00047 * NDARRAY is a data type, which is designed to transfer N-dimensional numerical array. 00048 * The message body consists of N-D array header, size table, and N-D array body. 00049 */ 00050 00051 typedef struct { 00052 igtl_uint8 type; /* Scalar type (2:int8 3:uint8 4:int16 5:uint16 6:int32 00053 7:uint32 10:float32 11:float64 13:complex) */ 00054 igtl_uint8 dim; /* Dimension of array */ 00055 igtl_uint16 * size; /* Array size */ 00056 void * array; 00057 } igtl_ndarray_info; 00058 00059 00060 /* 00061 * Initialize igtl_ndarray_info 00062 */ 00063 void igtl_export igtl_ndarray_init_info(igtl_ndarray_info * info); 00064 00065 00066 /* 00067 * Allocate / free ndarray 00068 * 00069 * Allocate size array and ND-array pointed from igtl_ndarray_info. 00070 * 'type' and 'dim' in igtl_ndarray_info must be specified before 00071 * calling igtl_ndarray_alloc_info(). 00072 */ 00073 00074 int igtl_export igtl_ndarray_alloc_info(igtl_ndarray_info * info, const igtl_uint16 * size); 00075 int igtl_export igtl_ndarray_free_info(igtl_ndarray_info * info); 00076 00077 00078 /* 00079 * Unpack NDARRAY message 00080 * 00081 * Extract information in a byte array of NDARRAY messages and store 00082 * it in a igtl_ndarray_info structure. 'type' argument specifies 00083 * a message type prefix (none, GET_, STT_, STP_ or RTS_) by IGTL_TYPE_PREFIX_* macro. 00084 * Returns 1 if success, otherwise 0. 00085 */ 00086 00087 int igtl_export igtl_ndarray_unpack(int type, void * byte_array, igtl_ndarray_info * info, igtl_uint64 pack_size); 00088 00089 00090 /* 00091 * Pack NDARRAY message 00092 * 00093 * Convert an igtl_ndarray_info structure to a byte array. 00094 * 'byte_array' should be allocated prior to calling igtl_ndarray_pack() with memory size 00095 * calculated by igtl_ndarray_get_size(). 'type' argument specifies a message type prefix 00096 * (none, or GET_) by IGTL_TYPE_PREFIX_* macro. Returns 1 if success, otherwise 0. 00097 */ 00098 00099 int igtl_export igtl_ndarray_pack(igtl_ndarray_info * info, void * byte_array, int type); 00100 00101 00102 /* 00103 * N-D array data size 00104 * 00105 * This function calculates size of N-D array body including 00106 * size table (defined by UINT16[dim]) and array data. 00107 */ 00108 00109 igtl_uint64 igtl_export igtl_ndarray_get_size(igtl_ndarray_info * info, int type); 00110 00111 /* 00112 * CRC calculation 00113 * 00114 * This function calculates CRC of image data body including header 00115 * and array of pixel data. 00116 * 00117 */ 00118 00119 igtl_uint64 igtl_export igtl_ndarray_get_crc(igtl_ndarray_info * info, int type, void* byte_array); 00120 00121 00122 #ifdef __cplusplus 00123 } 00124 #endif 00125 00126 #endif /* __IGTL_NDARRAY_H */ 00127