cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vctBarycentricVector.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 
6  Author(s): Ofri Sadowsky
7  Created on: 2003-12-02
8 
9  (C) Copyright 2003-2007 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 */
20 
21 #pragma once
22 #ifndef _vctBarycentricVector_h
23 #define _vctBarycentricVector_h
24 
32 
68 template <class _elementType, vct::size_type _size>
69 class vctBarycentricVector : public vctFixedSizeVector<_elementType, _size>
70 {
71 public:
74 
75  VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType);
76  typedef class cmnTypeTraits<value_type> TypeTraits;
77 
80  : BaseType()
81  {}
82 
85  : BaseType( static_cast<const BaseType &>(other) )
86  {}
87 
90  : BaseType(other)
91  {}
92 
94  template <stride_type __stride, class __dataPtrType>
96  : BaseType(other)
97  {}
98 
99  vctBarycentricVector(_elementType value)
100  : BaseType(value)
101  {}
102 
103  vctBarycentricVector(_elementType element0, _elementType element1)
104  : BaseType(element0, element1)
105  {}
106 
107  vctBarycentricVector(_elementType element0, _elementType element1, _elementType element2)
108  : BaseType(element0, element1, element2)
109  {}
110 
111  vctBarycentricVector(_elementType element0, _elementType element1, _elementType element2,
112  _elementType element3)
113  : BaseType(element0, element1, element2, element3)
114  {}
115 
116  /* This one cannot call BaseType constructor as we cannot identify the
117  unknown arguments */
118  vctBarycentricVector(_elementType element0, _elementType element1, _elementType element2,
119  _elementType element3, _elementType element4, ...)
120  {
121  (*this)[0] = element0;
122  (*this)[1] = element1;
123  (*this)[2] = element2;
124  (*this)[3] = element3;
125  (*this)[4] = element4;
126  va_list nextArg;
127  va_start(nextArg, element4);
128  for (index_type i = 5; i < _size; ++i) {
129  (*this)[i] = va_arg(nextArg, value_type);
130  }
131  va_end(nextArg);
132  }
133 
136  bool IsBarycentric(const _elementType tolerance = TypeTraits::Tolerance() ) const
137  {
138  const _elementType diff = this->SumOfElements() - 1;
139  return ( (-tolerance <= diff) && (diff <= tolerance) );
140  }
141 
144  bool IsInterior(const _elementType tolerance = TypeTraits::Tolerance()) const
145  {
146  if (!IsBarycentric())
147  return false;
148  const bool result = ((*this).GreaterOrEqual(tolerance));
149  return result;
150  }
151 
154  bool IsMember(const _elementType tolerance = TypeTraits::Tolerance()) const
155  {
156  if (!IsBarycentric())
157  return false;
158  const bool result = ((*this).GreaterOrEqual(-tolerance));
159  return result;
160  }
161 
164  bool HasZero(const _elementType tolerance = TypeTraits::Tolerance()) const
165  {
166  return
168  SoViSi< typename vctBinaryOperations<bool>::Or,
170  Unfold( (*this), tolerance );
171  }
172 
174  bool IsBoundary(const _elementType tolerance = TypeTraits::Tolerance()) const
175  {
176  return (IsMember(tolerance) && HasZero(tolerance));
177  }
178 
181  bool IsVertex(const _elementType tolerance = TypeTraits::Tolerance()) const
182  {
183  if (!IsMember(tolerance))
184  return false;
185  const ThisType diff((*this) - _elementType(1));
186  return (diff.HasZero(tolerance));
187  }
188 
194  ThisType ScaleToBarycentric(const _elementType tolerance = TypeTraits::Tolerance()) const
195  {
196  _elementType scale = this->SumOfElements();
197  if ( (-tolerance <= scale) && (scale <= tolerance) )
198  return ThisType(0);
199  ThisType result(*this);
200  result /= scale;
201  return result;
202  }
203 
204 };
205 
206 
207 #endif // _vctBarycentricVector_h
208 
size_t index_type
Definition: vctContainerTraits.h:36
bool IsBoundary(const _elementType tolerance=TypeTraits::Tolerance()) const
Definition: vctBarycentricVector.h:174
vctBarycentricVector(_elementType element0, _elementType element1, _elementType element2)
Definition: vctBarycentricVector.h:107
Definition: vctBarycentricVector.h:69
vctFixedSizeVector< _elementType, _size > BaseType
Definition: vctBarycentricVector.h:72
vctBarycentricVector< _elementType, _size > ThisType
Definition: vctBarycentricVector.h:73
vctBarycentricVector(_elementType element0, _elementType element1)
Definition: vctBarycentricVector.h:103
class cmnTypeTraits< value_type > TypeTraits
Definition: vctBarycentricVector.h:76
vctBarycentricVector(_elementType value)
Definition: vctBarycentricVector.h:99
vctBarycentricVector(const vctFixedSizeVectorBase< _size, __stride, _elementType, __dataPtrType > &other)
Definition: vctBarycentricVector.h:95
Implementation of a fixed-size vector using template metaprogramming.
Definition: vctFixedSizeVector.h:52
bool HasZero(const _elementType tolerance=TypeTraits::Tolerance()) const
Definition: vctBarycentricVector.h:164
vctBarycentricVector()
Definition: vctBarycentricVector.h:79
Declaration of vctFixedSizeVector.
Declaration of the class cmnTypeTraits.
vctBarycentricVector(_elementType element0, _elementType element1, _elementType element2, _elementType element3, _elementType element4,...)
Definition: vctBarycentricVector.h:118
value_type SumOfElements(void) const
Definition: vctFixedSizeConstVectorBase.h:424
bool IsMember(const _elementType tolerance=TypeTraits::Tolerance()) const
Definition: vctBarycentricVector.h:154
A template for a fixed length vector with fixed spacing in memory.
Definition: vctFixedSizeVectorBase.h:76
vctBarycentricVector(const BaseType &other)
Definition: vctBarycentricVector.h:89
Test if the first argument is bound by the second argument.
Definition: vctBinaryOperations.h:454
bool IsBarycentric(const _elementType tolerance=TypeTraits::Tolerance()) const
Definition: vctBarycentricVector.h:136
bool IsVertex(const _elementType tolerance=TypeTraits::Tolerance()) const
Definition: vctBarycentricVector.h:181
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
vctBarycentricVector(_elementType element0, _elementType element1, _elementType element2, _elementType element3)
Definition: vctBarycentricVector.h:111
bool IsInterior(const _elementType tolerance=TypeTraits::Tolerance()) const
Definition: vctBarycentricVector.h:144
A collection of useful information about the C++ basic types, represented in a generic programming wa...
Definition: cmnTypeTraits.h:155
Container class for the recursive engines.
Definition: vctFixedSizeVectorRecursiveEngines.h:76
ThisType ScaleToBarycentric(const _elementType tolerance=TypeTraits::Tolerance()) const
Definition: vctBarycentricVector.h:194
vctBarycentricVector(const ThisType &other)
Definition: vctBarycentricVector.h:84