Slicer 5.9
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;
60 *a = *b;
61 *b = temp;
62}
63
64template <class T>
65inline T sqr(T x)
66{
67 return x * x;
68}
69
70// thresholding operators
71template <class T>
72inline void ipUpperThreshold(T* data, const int size, const T threshold)
73{
74 T* dp = data;
75
76 for (int i = 0; i < size; i++, dp++)
77 {
78 if (*dp < threshold)
79 {
80 *dp = (T)0.0;
81 }
82 }
83}
84
85template <class T>
86inline void ipLowerThreshold(T* data, const int size, const T threshold)
87{
88 T* dp = data;
89
90 for (int i = 0; i < size; i++, dp++)
91 {
92 if (*dp > threshold)
93 {
94 *dp = (T)0.0;
95 }
96 }
97}
98
99template <class T>
100inline void ipUpperBinaryThreshold(T* data, const int size, const T threshold)
101{
102 T* dp = data;
103
104 for (int i = 0; i < size; i++, dp++)
105 {
106 *dp = (*dp < threshold ? (T)0.0 : (T)1.0);
107 }
108}
109
110template <class T>
111inline void ipLowerBinaryThreshold(T* data, const int size, const T threshold)
112{
113 T* dp = data;
114
115 for (int i = 0; i < size; i++, dp++)
116 {
117 *dp = (*dp > threshold ? (T)0.0 : (T)1.0);
118 }
119}
120
121#endif
void ipLowerThreshold(T *data, const int size, const T threshold)
Definition misc.h:86
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:72
T sqr(T x)
Definition misc.h:65
void * ipAllocateData(const int size, const size_t elemsize)
void ipLowerBinaryThreshold(T *data, const int size, const T threshold)
Definition misc.h:111
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:100
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