/usr/include/InsightToolkit/Utilities/MetaIO/metaUtils.h is in libinsighttoolkit3-dev 3.20.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | /*============================================================================
MetaIO
Copyright 2000-2010 Insight Software Consortium
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
/**
* MetaUtils (.h and .cpp)
*
* Description:
* This file provides generic ascii file parsing capabilities.
* It assumes that the files consist of a set of fields
* Each field is list of variable = value pairs
*
* Features:
* There can be dependencies between fields, required fields,
* and optional fields.
* Undefined fields are skipped.
* Values must conform to expected types. There can be default
* values for fields.
*
* Author:
* Stephen R. Aylward
*
* Date:
* February 22, 2002
*
**/
#include "metaTypes.h"
#ifndef ITKMetaIO_METAUTILS_H
#define ITKMetaIO_METAUTILS_H
#ifdef _MSC_VER
#pragma warning( disable:4251 )
#pragma warning( disable:4511 )
#pragma warning( disable:4512 )
#pragma warning( disable:4284 )
#pragma warning( disable:4702 )
#pragma warning( disable:4786 )
#pragma warning( disable:4996 )
#endif
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
//#include <iomanip>
#include <typeinfo>
#include <string.h>
#if (METAIO_USE_NAMESPACE)
namespace METAIO_NAMESPACE {
#endif
extern int META_DEBUG;
// Types used for storing the compression table
typedef struct MET_CompressionOffset
{
METAIO_STL::streamoff uncompressedOffset;
METAIO_STL::streamoff compressedOffset;
} MET_CompressionOffsetType;
typedef METAIO_STL::vector<MET_CompressionOffsetType>
MET_CompressionOffsetListType;
typedef struct MET_CompressionTable
{
MET_CompressionOffsetListType offsetList;
z_stream* compressedStream;
char* buffer;
METAIO_STL::streamoff bufferSize;
} MET_CompressionTableType;
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
METAIO_EXPORT MET_FieldRecordType *
MET_GetFieldRecord(const char * _fieldName,
METAIO_STL::vector<MET_FieldRecordType *> * _fields);
METAIO_EXPORT
int MET_GetFieldRecordNumber(const char * _fieldName,
METAIO_STL::vector<MET_FieldRecordType *> * _fields);
METAIO_EXPORT
bool MET_SizeOfType(MET_ValueEnumType _type, int *_size);
/////////////////////////////////////////////////////////
// Byte Order
/////////////////////////////////////////////////////////
METAIO_EXPORT
bool MET_SystemByteOrderMSB(void);
inline
unsigned short MET_ByteOrderSwapShort(unsigned short x)
{
return (unsigned short)((unsigned short)(x<<8) | (unsigned short)(x>>8));
}
inline
unsigned long MET_ByteOrderSwapLong(unsigned int x)
{
return (((x<<24) & 0xff000000) |
((x<<8) & 0x00ff0000) |
((x>>8) & 0x0000ff00) |
((x>>24) & 0x000000ff));
}
inline
void MET_ByteOrderSwap2(void* x)
{
char one_byte;
char *p = reinterpret_cast<char *>(x);
one_byte = p[0];
p[0] = p[1];
p[1] = one_byte;
}
inline
void MET_ByteOrderSwap4(void* x)
{
char one_byte;
char *p = reinterpret_cast<char *>(x);
one_byte = p[0];
p[0] = p[3];
p[3] = one_byte;
one_byte = p[1];
p[1] = p[2];
p[2] = one_byte;
}
inline
void MET_ByteOrderSwap8(void* x)
{
char one_byte;
char* p = reinterpret_cast<char*>(x);
one_byte = p[0];
p[0] = p[7];
p[7] = one_byte;
one_byte = p[1];
p[1] = p[6];
p[6] = one_byte;
one_byte = p[2];
p[2] = p[5];
p[5] = one_byte;
one_byte = p[3];
p[3] = p[4];
p[4] = one_byte;
}
/** Make sure that all the byte are read and written as LSB */
void MET_SwapByteIfSystemMSB(void* val, MET_ValueEnumType _type);
/////////////////////////////////////////////////////////
// STRINGS AND TYPES
/////////////////////////////////////////////////////////
METAIO_EXPORT
bool MET_StringToWordArray(const char *s, int *n, char ***val);
template <class T>
void MET_StringToVector( const METAIO_STL::string & s,
METAIO_STL::vector< T > & vec )
{
vec.clear();
METAIO_STL::string::size_type prevPos = 0;
METAIO_STL::string::size_type pos = s.find(",", prevPos);
T tVal;
while( pos != METAIO_STL::string::npos )
{
METAIO_STL::stringstream ss;
METAIO_STL::string tmpString = s.substr( prevPos, (pos-prevPos) );
ss << tmpString;
ss >> tVal;
vec.push_back( tVal );
prevPos = pos+1;
pos = s.find(",", prevPos);
}
METAIO_STL::stringstream ss;
METAIO_STL::string tmpString = s.substr( prevPos, (s.size()-prevPos) );
ss << tmpString;
ss >> tVal;
vec.push_back( tVal );
}
METAIO_EXPORT
bool MET_StringToType(const char *_str, MET_ValueEnumType *_type);
METAIO_EXPORT
bool MET_TypeToString(MET_ValueEnumType _type, char *_str);
METAIO_EXPORT
bool MET_StringToInterpolationType(const char * _str,
MET_InterpolationEnumType * _type);
METAIO_EXPORT
bool MET_InterpolationTypeToString(MET_InterpolationEnumType _type,
char * _str);
inline
MET_ValueEnumType MET_GetPixelType(const METAIO_STL::type_info & ptype)
{
if( ptype == typeid(MET_UCHAR_TYPE) )
{
return MET_UCHAR;
}
else if( ptype == typeid(MET_CHAR_TYPE) )
{
return MET_CHAR;
}
else if( ptype == typeid(MET_USHORT_TYPE))
{
return MET_USHORT;
}
else if( ptype == typeid(MET_SHORT_TYPE) )
{
return MET_SHORT;
}
else if( ptype == typeid(MET_UINT_TYPE) )
{
return MET_UINT;
}
else if( ptype == typeid(MET_INT_TYPE) )
{
return MET_INT;
}
else if( ptype == typeid(MET_ULONG_TYPE))
{
return MET_ULONG;
}
else if( ptype == typeid(MET_LONG_TYPE) )
{
return MET_LONG;
}
else if( ptype == typeid(MET_ULONG_LONG_TYPE) )
{
return MET_ULONG_LONG;
}
else if( ptype == typeid(MET_LONG_LONG_TYPE) )
{
return MET_LONG_LONG;
}
else if( ptype == typeid(MET_FLOAT_TYPE) )
{
return MET_FLOAT;
}
else if( ptype == typeid(MET_DOUBLE_TYPE) )
{
return MET_DOUBLE;
}
else
{
METAIO_STREAM::cerr << "MET_GetPixelType: Couldn't convert pixel type : "
<< ptype.name() << METAIO_STREAM::endl;
return MET_NONE;
}
}
inline
MET_ValueEnumType MET_GetValueEnumType(const METAIO_STL::type_info & ptype)
{
return MET_GetPixelType( ptype );
}
/////////////////////////////////////////////////////////
// VALUES
/////////////////////////////////////////////////////////
METAIO_EXPORT
bool MET_ValueToDouble(MET_ValueEnumType _pType,
const void *_data,
METAIO_STL::streamoff _index,
double *_value);
METAIO_EXPORT
bool MET_DoubleToValue(double _value,
MET_ValueEnumType _type,
void *_data,
METAIO_STL::streamoff _index);
METAIO_EXPORT
bool MET_ValueToValue(MET_ValueEnumType _fromType,
const void *_fromData,
METAIO_STL::streamoff _index,
MET_ValueEnumType _toType,
void *_toData,
double _fromMin=0, double _fromMax=0,
double _toMin=0, double _toMax=0);
METAIO_EXPORT
unsigned char * MET_PerformCompression(const unsigned char * source,
METAIO_STL::streamoff sourceSize,
METAIO_STL::streamoff * compressedDataSize);
METAIO_EXPORT
bool MET_PerformUncompression(const unsigned char * sourceCompressed,
METAIO_STL::streamoff sourceCompressedSize,
unsigned char * uncompressedData,
METAIO_STL::streamoff uncompressedDataSize);
// Uncompress a stream given an uncompressedSeekPosition
METAIO_EXPORT
METAIO_STL::streamoff MET_UncompressStream(METAIO_STREAM::ifstream * stream,
METAIO_STL::streamoff uncompressedSeekPosition,
unsigned char * uncompressedData,
METAIO_STL::streamoff uncompressedDataSize,
METAIO_STL::streamoff compressedDataSize,
MET_CompressionTableType * compressionTable);
/////////////////////////////////////////////////////////
// FILES NAMES
/////////////////////////////////////////////////////////
METAIO_EXPORT
bool MET_GetFilePath(const char *_fName, char *_fPath);
METAIO_EXPORT
bool MET_GetFileSuffixPtr(const char *_fName, int *i);
METAIO_EXPORT
bool MET_SetFileSuffix(char *_fName, const char *_suf);
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
METAIO_EXPORT
bool MET_InitWriteField(MET_FieldRecordType * _mf,
const char *_name,
MET_ValueEnumType _type,
double _v=0);
template <class T>
bool MET_InitWriteField(MET_FieldRecordType * _mf,
const char *_name,
MET_ValueEnumType _type,
size_t _length,
T *_v)
{
strncpy(_mf->name, _name,254);
_mf->name[254] = '\0';
_mf->type = _type;
_mf->defined = true;
_mf->length = static_cast<int>(_length);
_mf->dependsOn = -1;
_mf->required = false;
_mf->terminateRead = false;
if(_type == MET_FLOAT_MATRIX)
{
size_t i;
for(i=0; i < 255 && i < _length*_length; i++)
{
_mf->value[i] = (double)(_v[i]);
}
}
else if(_type != MET_STRING)
{
size_t i;
for(i=0; i < 255 && i < _length; i++)
{
_mf->value[i] = (double)(_v[i]);
}
}
else
{
strncpy((char *)(_mf->value), (const char *)_v,
(sizeof(_mf->value)-1));
((char *)(_mf->value))[(sizeof(_mf->value)-1)] = '\0';
}
return true;
}
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
METAIO_EXPORT
bool MET_Write(METAIO_STREAM::ostream &fp,
METAIO_STL::vector<MET_FieldRecordType *> * fields,
char _sepChar='=');
METAIO_EXPORT
bool MET_WriteFieldToFile(METAIO_STREAM::ostream &_fp, const char *_fieldName,
MET_ValueEnumType _pType, size_t _n, const void *_v);
METAIO_EXPORT
bool MET_WriteFieldToFile(METAIO_STREAM::ostream &_fp, const char *_fieldName,
MET_ValueEnumType _pType, double _v);
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
METAIO_EXPORT
bool MET_InitReadField(MET_FieldRecordType * _mf,
const char *_name,
MET_ValueEnumType _type,
bool _required=true,
int _dependsOn=-1,
size_t _length=0);
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
METAIO_EXPORT
bool MET_Read(METAIO_STREAM::istream &fp,
METAIO_STL::vector<MET_FieldRecordType *> * fields,
char _sepChar='=', bool oneLine=false,
bool display_warnings=true,
METAIO_STL::vector<MET_FieldRecordType *> * newFields=NULL);
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
METAIO_EXPORT
METAIO_STL::string MET_ReadForm(METAIO_STREAM::istream & _fp);
METAIO_EXPORT
METAIO_STL::string MET_ReadType(METAIO_STREAM::istream & _fp);
METAIO_EXPORT
char * MET_ReadSubType(METAIO_STREAM::istream & _fp);
#if (METAIO_USE_NAMESPACE)
};
#endif
#endif
|