cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vctUnaryOperations.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5  Author(s): Ofri Sadowsky
6  Created on: 2003-08-18
7 
8  (C) Copyright 2003-2014 Johns Hopkins University (JHU), All Rights Reserved.
9 
10 --- begin cisst license - do not edit ---
11 
12 This software is provided "as is" under an open source license, with
13 no warranty. The complete license can be found in license.txt and
14 http://www.cisst.org/cisst/license.txt.
15 
16 --- end cisst license ---
17 */
18 
19 #pragma once
20 #ifndef _vctUnaryOperations_h
21 #define _vctUnaryOperations_h
22 
54 template<class _outputElementType, class _inputElementType = _outputElementType>
56 {
57  public:
58  typedef _outputElementType OutputElementType;
59  typedef _inputElementType InputElementType;
60 
65  class Identity {
66  public:
71  static inline OutputElementType Operate(const InputElementType & input) {
72  return OutputElementType(input);
73  }
74  };
75 
80  class AbsValue {
81  public:
86  static inline OutputElementType Operate(const InputElementType & input) {
87  return (input > InputElementType(0)) ? OutputElementType(input) : OutputElementType(-input);
88  }
89  };
90 
95  class Floor {
96  public:
97  static inline OutputElementType Operate(const InputElementType & input) {
98  return OutputElementType( floor((double)input) );
99  }
100  };
101 
106  class Ceil {
107  public:
108  static inline OutputElementType Operate(const InputElementType & input) {
109  return OutputElementType( ceil((double)input) );
110  }
111  };
112 
113 
114 
119  class Square {
120  public:
125  static inline OutputElementType Operate(const InputElementType & input) {
126  return OutputElementType(input * input);
127  }
128  };
129 
134  class Negation {
135  public:
140  static inline OutputElementType Operate(const InputElementType & input) {
141  return OutputElementType(-input);
142  }
143  };
144 
146  class IsPositive {
147  public:
148  static inline OutputElementType Operate(const InputElementType & input) {
149  return OutputElementType(input > InputElementType(0));
150  }
151  };
152 
155  public:
156  static inline OutputElementType Operate(const InputElementType & input) {
157  return OutputElementType(input >= InputElementType(0));
158  }
159  };
160 
163  public:
164  static inline OutputElementType Operate(const InputElementType & input) {
165  return OutputElementType(input <= InputElementType(0));
166  }
167  };
168 
170  class IsNegative {
171  public:
172  static inline OutputElementType Operate(const InputElementType & input) {
173  return OutputElementType(input < InputElementType(0));
174  }
175  };
176 
178  class IsNonzero {
179  public:
180  static inline OutputElementType Operate(const InputElementType & input) {
181  return OutputElementType(input != InputElementType(0));
182  }
183  };
184 
186  class IsFinite {
187  public:
188  static inline OutputElementType Operate(const InputElementType & input) {
190  }
191  };
192 
194  class IsNaN {
195  public:
196  static inline OutputElementType Operate(const InputElementType & input) {
198  }
199  };
200 
201  /* template<unsigned int EXPONENT>
202  class Power {
203  public:
204  static inline OutputElementType Operate(const InputElementType & input) {
205  OutputElementType rootOfPower = Power<EXPONENT / 2>::OperationType(input);
206  return ((EXPONENT % 2 == 0)
207  ? (rootOfPower * rootOfPower)
208  : (rootOfPower * rootOfPower * input));
209  }
210  };
211 
212  class Power<0> {
213  public:
214  static inline OutputElementType Operate(const InputElementType & input) {
215  return OutputElementType(1);
216  }
217  };
218  */
219 };
220 
221 
222 #endif // _vctUnaryOperations_h
223 
static OutputElementType Operate(const InputElementType &input)
Definition: vctUnaryOperations.h:148
Returns the negative of the input as an OutputType object.
Definition: vctUnaryOperations.h:134
static OutputElementType Operate(const InputElementType &input)
Definition: vctUnaryOperations.h:164
Returns the absolute value of the input as an OutputType object.
Definition: vctUnaryOperations.h:80
static OutputElementType Operate(const InputElementType &input)
Definition: vctUnaryOperations.h:180
static OutputElementType Operate(const InputElementType &input)
Definition: vctUnaryOperations.h:86
Returns the ceiling of the input, that is, the smallest integer greater-than or equal to the input...
Definition: vctUnaryOperations.h:106
static OutputElementType Operate(const InputElementType &input)
Definition: vctUnaryOperations.h:156
Definition: vctUnaryOperations.h:178
Returns the square of the input as an OutputType object.
Definition: vctUnaryOperations.h:119
Returns the input as an OutputType object.
Definition: vctUnaryOperations.h:65
Define unary operations on an object as classes.
Definition: vctUnaryOperations.h:55
Definition: vctUnaryOperations.h:186
static OutputElementType Operate(const InputElementType &input)
Definition: vctUnaryOperations.h:188
static OutputElementType Operate(const InputElementType &input)
Definition: vctUnaryOperations.h:172
Definition: vctUnaryOperations.h:154
_inputElementType InputElementType
Definition: vctUnaryOperations.h:59
static OutputElementType Operate(const InputElementType &input)
Definition: vctUnaryOperations.h:97
Definition: vctUnaryOperations.h:170
static OutputElementType Operate(const InputElementType &input)
Definition: vctUnaryOperations.h:125
Returns the floor of the input, that is, the largest integer less-than or equal to the input...
Definition: vctUnaryOperations.h:95
Definition: vctUnaryOperations.h:146
_outputElementType OutputElementType
Definition: vctUnaryOperations.h:58
static OutputElementType Operate(const InputElementType &input)
Definition: vctUnaryOperations.h:196
static OutputElementType Operate(const InputElementType &input)
Definition: vctUnaryOperations.h:140
A collection of useful information about the C++ basic types, represented in a generic programming wa...
Definition: cmnTypeTraits.h:155
Definition: vctUnaryOperations.h:194
static OutputElementType Operate(const InputElementType &input)
Definition: vctUnaryOperations.h:71
static OutputElementType Operate(const InputElementType &input)
Definition: vctUnaryOperations.h:108
Definition: vctUnaryOperations.h:162