cisst-saw
Loading...
Searching...
No Matches
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
14This software is provided "as is" under an open source license, with
15no warranty. The complete license can be found in license.txt and
16http://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
29
32
68template <class _elementType, vct::size_type _size>
69class vctBarycentricVector : public vctFixedSizeVector<_elementType, _size>
70{
71public:
74
77
82
85 : BaseType( static_cast<const BaseType &>(other) )
86 {}
87
90 : BaseType(other)
91 {}
92
94 template <stride_type __stride, class __dataPtrType>
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
167 vctFixedSizeVectorRecursiveEngines<_size>::template
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
Implement operation of the form for fixed size vectors.
Definition vctFixedSizeVectorRecursiveEngines.h:785
A collection of useful information about the C++ basic types, represented in a generic programming wa...
Definition cmnTypeTraits.h:155
static Type Tolerance(void)
Definition cmnTypeTraits.h:170
vctBarycentricVector()
Definition vctBarycentricVector.h:79
bool HasZero(const _elementType tolerance=TypeTraits::Tolerance()) const
Definition vctBarycentricVector.h:164
bool IsInterior(const _elementType tolerance=TypeTraits::Tolerance()) const
Definition vctBarycentricVector.h:144
vctBarycentricVector(_elementType element0, _elementType element1, _elementType element2)
Definition vctBarycentricVector.h:107
vctBarycentricVector(const vctFixedSizeVectorBase< _size, __stride, _elementType, __dataPtrType > &other)
Definition vctBarycentricVector.h:95
vctBarycentricVector(_elementType value)
Definition vctBarycentricVector.h:99
bool IsVertex(const _elementType tolerance=TypeTraits::Tolerance()) const
Definition vctBarycentricVector.h:181
vctBarycentricVector(const BaseType &other)
Definition vctBarycentricVector.h:89
vctBarycentricVector(_elementType element0, _elementType element1, _elementType element2, _elementType element3, _elementType element4,...)
Definition vctBarycentricVector.h:118
vctBarycentricVector(const ThisType &other)
Definition vctBarycentricVector.h:84
vctBarycentricVector(_elementType element0, _elementType element1)
Definition vctBarycentricVector.h:103
bool IsMember(const _elementType tolerance=TypeTraits::Tolerance()) const
Definition vctBarycentricVector.h:154
class cmnTypeTraits< value_type > TypeTraits
Definition vctBarycentricVector.h:76
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
vctBarycentricVector(_elementType element0, _elementType element1, _elementType element2, _elementType element3)
Definition vctBarycentricVector.h:111
vctFixedSizeVector< _elementType, _size > BaseType
Definition vctBarycentricVector.h:72
bool IsBoundary(const _elementType tolerance=TypeTraits::Tolerance()) const
Definition vctBarycentricVector.h:174
bool IsBarycentric(const _elementType tolerance=TypeTraits::Tolerance()) const
Definition vctBarycentricVector.h:136
ThisType ScaleToBarycentric(const _elementType tolerance=TypeTraits::Tolerance()) const
Definition vctBarycentricVector.h:194
vctBarycentricVector< _elementType, _size > ThisType
Definition vctBarycentricVector.h:73
Test if the first argument is bound by the second argument.
Definition vctBinaryOperations.h:454
A template for a fixed length vector with fixed spacing in memory.
Definition vctFixedSizeVectorBase.h:77
vctFixedSizeVector()
Definition vctFixedSizeVector.h:76
Declaration of the class cmnTypeTraits.
value_type SumOfElements(void) const
Definition vctDynamicConstMatrixBase.h:432
Declaration of vctFixedSizeVector.