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_POLYDATA_H 00018 #define __IGTL_POLYDATA_H 00019 00020 #include "igtl_win32header.h" 00021 #include "igtl_header.h" 00022 #include "igtl_util.h" 00023 #include "igtl_types.h" 00024 #include "igtl_win32header.h" 00025 00026 00027 #ifdef __cplusplus 00028 extern "C" { 00029 #endif 00030 00031 /* Scalar type for point data */ 00032 #define IGTL_POLYDATA_TYPE_INT8 2 00033 #define IGTL_POLYDATA_TYPE_UINT8 3 00034 #define IGTL_POLYDATA_TYPE_INT16 4 00035 #define IGTL_POLYDATA_TYPE_UINT16 5 00036 #define IGTL_POLYDATA_TYPE_INT32 6 00037 #define IGTL_POLYDATA_TYPE_UINT32 7 00038 #define IGTL_POLYDATA_TYPE_FLOAT32 10 00039 #define IGTL_POLYDATA_TYPE_FLOAT64 11 00040 00041 00042 #pragma pack(1) /* For 1-byte boundary in memroy */ 00043 00044 /* 00045 * POLYDATA Header 00046 */ 00047 typedef struct { 00048 igtl_uint32 npoints; /* Number of points */ 00049 igtl_uint8 type_point; /* Type of points */ 00050 igtl_uint8 reserved; /* Points */ 00051 00052 igtl_uint32 nvertices; /* Number of vertices */ 00053 igtl_uint32 size_vertices; /* Size of vertices */ 00054 00055 igtl_uint32 nlines; /* Number of lines */ 00056 igtl_uint32 size_lines; /* Size of lines */ 00057 00058 igtl_uint32 npolygons; /* Number of polygons */ 00059 igtl_uint32 size_polygons; /* Size of polygons */ 00060 00061 igtl_uint32 ntriangle_strips; /* Number of triangle strips */ 00062 igtl_uint32 size_triangle_strips; /* Size of triangle strips */ 00063 00064 00065 00066 } igtl_polydata_header; 00067 00068 #pragma pack(0) 00069 00070 /* 00071 * POLYDATA info 00072 */ 00073 typedef struct { 00074 igtl_polydata_header header; /* Header */ 00075 void * points; /* Points */ 00076 igtl_uint32 * vertices; /* Vertices -- array of (N, i1, i2, i3 ...iN) */ 00077 igtl_uint32 * lines; /* Lines -- array of (N, i1, i2, i3 ...iN) */ 00078 igtl_uint32 * polygons; /* Polygons -- array of (N, i1, i2, i3 ...iN) */ 00079 igtl_uint32 * triangle_strips; /* Triangle strips -- array of (N, i1, i2, i3 ...iN) */ 00080 } igtl_polydata_info; 00081 00082 00083 /* 00084 * Initialize igtl_polydata_info 00085 */ 00086 void igtl_export igtl_polydata_init_info(igtl_polydata_info * info); 00087 00088 /* 00089 * Allocate / free an array of igtl_polydata_info structure 00090 * 00091 * Allocate / free an array of igtl_polydata_child_info in polydata_info with length of 'ncmessages.' 00092 * Return 1 if the array is successfully allocated/freed 00093 */ 00094 00095 int igtl_export igtl_polydata_alloc_info(igtl_polydata_info * info); 00096 int igtl_export igtl_polydata_free_info(igtl_polydata_info * info); 00097 00098 /* 00099 * Unpack POLYDATA message 00100 * 00101 * Extract information about child messages in a byte array of POLYDATA messages and store 00102 * it in a igtl_polydata_info structure. 'type' argument specifies a message type prefix 00103 * (none, GET_, STT_, STP_ or RTS_) by IGTL_TYPE_PREFIX_* macro. 00104 * Returns 1 if success, otherwise 0. 00105 */ 00106 00107 int igtl_export igtl_polydata_unpack(int type, void * byte_array, igtl_polydata_info * info, igtl_uint64 size); 00108 00109 /* 00110 * Pack POLYDATA message 00111 * 00112 * Convert an igtl_polydata_info structure to a byte array. 00113 * 'byte_array' should be allocated prior to calling igtl_polydata_pack() with memory size 00114 * calculated by igtl_polydata_get_size(). 'type' argument specifies a message type prefix 00115 * (none, GET_, STT_, STP_ or RTS_) by IGTL_TYPE_PREFIX_* macro. 00116 * Returns 1 if success, otherwise 0. 00117 */ 00118 00119 int igtl_export igtl_polydata_pack(igtl_polydata_info * info, void * byte_array, int type); 00120 00121 /* 00122 * Polydata data size 00123 * 00124 * igtl_polydata_get_size() calculates the size of polydata header, consisting of 00125 * POLYDATA hearder section (including number of child messages) and 00126 * name table section based on a igtl_polydata_header. 00127 * The size returned from this function does not include size of child message data. 00128 * 'type' argument specifies a message type prefix 00129 * (none, GET_, STT_, STP_ or RTS_) by IGTL_TYPE_PREFIX_* macro. 00130 */ 00131 00132 igtl_uint64 igtl_export igtl_polydata_get_size(igtl_polydata_info * info, int type); 00133 00134 00135 /* 00136 * CRC calculation 00137 * 00138 * This function calculates CRC of POLYDATA message. Note that 'info' is used only for 00139 * getting size of the message. 00140 * 00141 */ 00142 00143 igtl_uint64 igtl_export igtl_polydata_get_crc(igtl_polydata_info * info, int type, void* polydata_message); 00144 00145 #ifdef __cplusplus 00146 } 00147 #endif 00148 00149 #endif /* __IGTL_POLYDATA_H */ 00150 00151 00152