|
Slicer 4.2
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
|
00001 /*========================================================================= 00002 00003 Program: Extract Skeleton 00004 Module: $HeadURL: http://svn.slicer.org/Slicer4/trunk/Modules/CLI/ExtractSkeleton/misc.h $ 00005 Language: C++ 00006 Date: $Date: 2011-12-20 17:20:05 -0500 (Tue, 20 Dec 2011) $ 00007 Version: $Revision: 18967 $ 00008 00009 Copyright (c) Brigham and Women's Hospital (BWH) All Rights Reserved. 00010 00011 See License.txt or http://www.slicer.org/copyright/copyright.txt for details. 00012 00013 ==========================================================================*/ 00014 /* 00015 * misc.h 00016 * 00017 * author: msturm 00018 * created: 27 Mar 1997 00019 * changes: mastyner 00020 */ 00021 00022 #ifndef __IP_MISC_H__ 00023 #define __IP_MISC_H__ 00024 00025 #include <cstdlib> 00026 #include <cstdio> 00027 #include <cerrno> 00028 #include <sys/types.h> 00029 00030 typedef enum 00031 { 00032 IP_BYTE = 0, /* AVS_TYPE_BYTE = 0 */ 00033 IP_INT, /* AVS_TYPE_INTEGER = 1 */ 00034 IP_FLOAT, /* AVS_TYPE_REAL = 2 */ 00035 IP_DOUBLE, /* AVS_TYPE_DOUBLE = 3 */ 00036 IP_SHORT /* AVS_TYPE_SHORT = 4 */ 00037 } ipDataType; 00038 00039 typedef union 00040 { 00041 void *_void; 00042 unsigned char *_byte; 00043 short *_short; 00044 int *_int; 00045 float *_float; 00046 double *_double; 00047 } ipDataUnion; 00048 00049 // memory allocation & handling 00050 size_t ipGetDataSize(const ipDataType type); 00051 00052 void * ipAllocateData(const int size, const size_t elemsize); 00053 00054 // misc functions 00055 00056 template <class T> 00057 inline void ipSwap(T *a, T *b) 00058 { 00059 T temp = *a; *a = *b; *b = temp; 00060 00061 } 00062 00063 template <class T> 00064 inline T sqr(T x) 00065 { 00066 return x * x; 00067 } 00068 00069 // thresholding operators 00070 template <class T> 00071 inline void ipUpperThreshold(T *data, const int size, const T threshold) 00072 { 00073 T *dp = data; 00074 00075 for( int i = 0; i < size; i++, dp++ ) 00076 { 00077 if( *dp < threshold ) 00078 { 00079 *dp = (T) 0.0; 00080 } 00081 } 00082 } 00083 00084 template <class T> 00085 inline void ipLowerThreshold(T *data, const int size, const T threshold) 00086 { 00087 T *dp = data; 00088 00089 for( int i = 0; i < size; i++, dp++ ) 00090 { 00091 if( *dp > threshold ) 00092 { 00093 *dp = (T) 0.0; 00094 } 00095 } 00096 } 00097 00098 template <class T> 00099 inline void ipUpperBinaryThreshold(T *data, const int size, const T threshold) 00100 { 00101 T *dp = data; 00102 00103 for( int i = 0; i < size; i++, dp++ ) 00104 { 00105 *dp = (*dp < threshold ? (T) 0.0 : (T) 1.0); 00106 } 00107 } 00108 00109 template <class T> 00110 inline void ipLowerBinaryThreshold(T *data, const int size, const T threshold) 00111 { 00112 T *dp = data; 00113 00114 for( int i = 0; i < size; i++, dp++ ) 00115 { 00116 *dp = (*dp > threshold ? (T) 0.0 : (T) 1.0); 00117 } 00118 } 00119 00120 #endif
1.7.4