Slicer 5.6
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
misc.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Extract Skeleton
4 Module: $HeadURL$
5 Language: C++
6 Date: $Date$
7 Version: $Revision$
8
9 Copyright (c) Brigham and Women's Hospital (BWH) All Rights Reserved.
10
11 See License.txt or http://www.slicer.org/copyright/copyright.txt for details.
12
13==========================================================================*/
14/*
15 * misc.h
16 *
17 * author: msturm
18 * created: 27 Mar 1997
19 * changes: mastyner
20 */
21
22#ifndef __IP_MISC_H__
23#define __IP_MISC_H__
24
25#include <cstdlib>
26#include <cstdio>
27#include <cerrno>
28#include <sys/types.h>
29
30typedef enum
31 {
32 IP_BYTE = 0, /* AVS_TYPE_BYTE = 0 */
33 IP_INT, /* AVS_TYPE_INTEGER = 1 */
34 IP_FLOAT, /* AVS_TYPE_REAL = 2 */
35 IP_DOUBLE, /* AVS_TYPE_DOUBLE = 3 */
36 IP_SHORT /* AVS_TYPE_SHORT = 4 */
38
39typedef union
40 {
41 void *_void;
42 unsigned char *_byte;
43 short *_short;
44 int *_int;
45 float *_float;
46 double *_double;
48
49// memory allocation & handling
50size_t ipGetDataSize(const ipDataType type);
51
52void * ipAllocateData(const int size, const size_t elemsize);
53
54// misc functions
55
56template <class T>
57inline void ipSwap(T *a, T *b)
58{
59 T temp = *a; *a = *b; *b = temp;
60
61}
62
63template <class T>
64inline T sqr(T x)
65{
66 return x * x;
67}
68
69// thresholding operators
70template <class T>
71inline void ipUpperThreshold(T *data, const int size, const T threshold)
72{
73 T *dp = data;
74
75 for( int i = 0; i < size; i++, dp++ )
76 {
77 if( *dp < threshold )
78 {
79 *dp = (T) 0.0;
80 }
81 }
82}
83
84template <class T>
85inline void ipLowerThreshold(T *data, const int size, const T threshold)
86{
87 T *dp = data;
88
89 for( int i = 0; i < size; i++, dp++ )
90 {
91 if( *dp > threshold )
92 {
93 *dp = (T) 0.0;
94 }
95 }
96}
97
98template <class T>
99inline void ipUpperBinaryThreshold(T *data, const int size, const T threshold)
100{
101 T *dp = data;
102
103 for( int i = 0; i < size; i++, dp++ )
104 {
105 *dp = (*dp < threshold ? (T) 0.0 : (T) 1.0);
106 }
107}
108
109template <class T>
110inline void ipLowerBinaryThreshold(T *data, const int size, const T threshold)
111{
112 T *dp = data;
113
114 for( int i = 0; i < size; i++, dp++ )
115 {
116 *dp = (*dp > threshold ? (T) 0.0 : (T) 1.0);
117 }
118}
119
120#endif
void ipLowerThreshold(T *data, const int size, const T threshold)
Definition misc.h:85
size_t ipGetDataSize(const ipDataType type)
void ipSwap(T *a, T *b)
Definition misc.h:57
void ipUpperThreshold(T *data, const int size, const T threshold)
Definition misc.h:71
T sqr(T x)
Definition misc.h:64
void * ipAllocateData(const int size, const size_t elemsize)
void ipLowerBinaryThreshold(T *data, const int size, const T threshold)
Definition misc.h:110
ipDataType
Definition misc.h:31
@ IP_BYTE
Definition misc.h:32
@ IP_INT
Definition misc.h:33
@ IP_SHORT
Definition misc.h:36
@ IP_DOUBLE
Definition misc.h:35
@ IP_FLOAT
Definition misc.h:34
void ipUpperBinaryThreshold(T *data, const int size, const T threshold)
Definition misc.h:99
short * _short
Definition misc.h:43
int * _int
Definition misc.h:44
double * _double
Definition misc.h:46
unsigned char * _byte
Definition misc.h:42
void * _void
Definition misc.h:41
float * _float
Definition misc.h:45