cisst-saw
Loading...
Searching...
No Matches
nmrIsOrthonormal.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): Anton Deguet
6 Created on: 2005-07-27
7
8 (C) Copyright 2005-2018 Johns Hopkins University (JHU), All Rights Reserved.
9
10--- begin cisst license - do not edit ---
11
12This software is provided "as is" under an open source license, with
13no warranty. The complete license can be found in license.txt and
14http://www.cisst.org/cisst/license.txt.
15
16--- end cisst license ---
17*/
18
19
24
25
26#ifndef _nmrIsOrthonormal_h
27#define _nmrIsOrthonormal_h
28
29
32
33
34
61template <class _elementType>
63
64public:
67
68protected:
71
75 inline void SetDimension(size_type m)
76 {
77 Size = m * m;
78 }
79
100 inline void AllocateWorkspace(bool allocateWorkspace)
101 {
102 if (allocateWorkspace) {
103 this->WorkspaceMemory.SetSize(Size);
104 this->WorkspaceReference.SetRef(this->WorkspaceMemory);
105 } else {
106 this->WorkspaceMemory.SetSize(0);
107 }
108 }
109
117 template <typename __vectorOwnerTypeWorkspace>
118 inline void
120 CISST_THROW(std::runtime_error)
121 {
122 if (Size > inWorkspace.size()) {
123 cmnThrow(std::runtime_error("nmrIsOrthonormalDynamicData: Workspace is too small."));
124 }
125 if (!inWorkspace.IsCompact()) {
126 cmnThrow(std::runtime_error("nmrIsOrthonormalDynamicData: Workspace must be compact."));
127 }
128 }
129
134
137
138public:
139
147 {
148 return m * m;
149 }
150
156 template <class __matrixOwnerTypeA>
161
162
163#ifndef SWIG
164#ifndef DOXYGEN
171 class Friend {
172 private:
174 public:
176 }
178 return Data.WorkspaceReference;
179 }
180 inline size_type Size(void) {
181 return Data.Size;
182 }
183 };
184 friend class Friend;
185#endif // DOXYGEN
186#endif // SWIG
187
196 Size(static_cast<size_type>(0))
197 {
198 AllocateWorkspace(false);
199 }
200
212 {
213 this->Allocate(m);
214 }
215
225 template <class __matrixOwnerTypeA>
230
244 template <class __matrixOwnerTypeA, class __vectorOwnerTypeWorkspace>
250
251
260 template <class __matrixOwnerTypeA>
262 {
263 this->Allocate(A.rows());
264 }
265
275 template <class __matrixOwnerTypeA, class __vectorOwnerTypeWorkspace>
278 {
279 this->SetDimension(A.rows());
280
281 // allocate output and set references
282 this->AllocateWorkspace(false);
283
284 // set reference on user provided workspace
285 this->ThrowUnlessWorkspaceSizeIsCorrect(inWorkspace);
286 this->WorkspaceReference.SetRef(inWorkspace);
287 }
288
296 {
297 this->SetDimension(m);
298 this->AllocateWorkspace(true);
299 }
300};
301
302
303
330#ifndef SWIG
331template <class _elementType, vct::size_type _rows>
333{
334public:
335#ifndef DOXYGEN
336 enum {SIZE = _rows * _rows};
337#endif // DOXYGEN
341
342protected:
344
345public:
346#ifndef DOXYGEN
353 class Friend {
354 private:
356 public:
360 return Data.WorkspaceMember;
361 }
362 };
363 friend class Friend;
364#endif // DOXYGEN
365
369};
370#endif // SWIG
371
372
373
434
443template <vct::size_type _size, vct::stride_type _rowStride, vct::stride_type _colStride, typename _elementType, class _dataPtrType>
446 _elementType tolerance = cmnTypeTraits<_elementType>::Tolerance()) {
449 product.ProductOf(A, A.TransposeRef());
450 product.Diagonal().Subtract(_elementType(1));
451 return (product.LinfNorm() <= tolerance);
452}
453
461template <vct::size_type _size, vct::stride_type _rowStride, vct::stride_type _colStride, typename _elementType, class _dataPtrType>
463 _elementType tolerance = cmnTypeTraits<_elementType>::Tolerance()) {
465 typedef typename InputType::MatrixValueType MatrixValueType;
466 MatrixValueType product;
467 product.ProductOf(A, A.TransposeRef());
468 product.Diagonal().Subtract(_elementType(1));
469 return (product.LinfNorm() <= tolerance);
470}
471
480template <class _matrixOwnerTypeA, class _elementType>
483 _elementType tolerance = cmnTypeTraits<_elementType>::Tolerance())
484 CISST_THROW(std::runtime_error)
485{
487
488 /* check that this is a square matrix */
489 if (A.cols() != A.rows()) {
490 cmnThrow(std::runtime_error("nmrIsOrthonormal: Requires a square matrix."));
491 }
492 /* check that the workspace is large enough */
493 if ((A.cols() * A.rows()) > dataFriend.Size()) {
494 cmnThrow(std::runtime_error("nmrIsOrthonormal: The data provided is not large enough."));
495 }
497 product.SetRef(A.rows(), A.cols(), A.cols(), 1, dataFriend.Workspace().Pointer());
498 product.ProductOf(A, A.TransposeRef());
499 product.Diagonal().Subtract(_elementType(1));
500 return (product.LinfNorm() <= tolerance);
501}
502
510template <class _matrixOwnerTypeA, typename _elementType>
512 _elementType tolerance = cmnTypeTraits<_elementType>::Tolerance())
513 CISST_THROW(std::runtime_error)
514{
516 data.Allocate(A);
517 return nmrIsOrthonormal(A, data, tolerance);
518}
519
528template <class _matrixOwnerTypeA, class _vectorOwnerTypeWorkspace, typename _elementType>
531 _elementType tolerance = cmnTypeTraits<_elementType>::Tolerance())
532 CISST_THROW(std::runtime_error)
533{
535 data.SetRef(A, workspace);
536 return nmrIsOrthonormal(A, data, tolerance);
537}
538
539
540#endif // _nmrIsOrthonormal_h
static Type Tolerance(void)
Definition cmnTypeTraits.h:170
Definition nmrIsOrthonormal.h:171
size_type Size(void)
Definition nmrIsOrthonormal.h:180
Friend(nmrIsOrthonormalDynamicData &data)
Definition nmrIsOrthonormal.h:175
vctDynamicVectorRef< _elementType > & Workspace(void)
Definition nmrIsOrthonormal.h:177
Data (workspace) for nmrIsOrthonormal (Dynamic).
Definition nmrIsOrthonormal.h:62
size_type Size
Definition nmrIsOrthonormal.h:136
void AllocateWorkspace(bool allocateWorkspace)
Definition nmrIsOrthonormal.h:100
nmrIsOrthonormalDynamicData(const vctDynamicConstMatrixBase< __matrixOwnerTypeA, _elementType > &A, vctDynamicVectorBase< __vectorOwnerTypeWorkspace, _elementType > &inWorkspace)
Definition nmrIsOrthonormal.h:245
void SetRef(const vctDynamicConstMatrixBase< __matrixOwnerTypeA, _elementType > &A, vctDynamicVectorBase< __vectorOwnerTypeWorkspace, _elementType > &inWorkspace)
Definition nmrIsOrthonormal.h:276
vctDynamicVectorRef< _elementType > WorkspaceReference
Definition nmrIsOrthonormal.h:133
void Allocate(size_type m)
Definition nmrIsOrthonormal.h:295
nmrIsOrthonormalDynamicData(const vctDynamicConstMatrixBase< __matrixOwnerTypeA, _elementType > &A)
Definition nmrIsOrthonormal.h:226
vctDynamicVector< _elementType > WorkspaceMemory
Definition nmrIsOrthonormal.h:70
static size_type WorkspaceSize(const vctDynamicConstMatrixBase< __matrixOwnerTypeA, _elementType > &A)
Definition nmrIsOrthonormal.h:157
nmrIsOrthonormalDynamicData()
Definition nmrIsOrthonormal.h:195
nmrIsOrthonormalDynamicData(size_type m)
Definition nmrIsOrthonormal.h:211
static size_type WorkspaceSize(size_type m)
Definition nmrIsOrthonormal.h:146
void ThrowUnlessWorkspaceSizeIsCorrect(vctDynamicVectorBase< __vectorOwnerTypeWorkspace, _elementType > &inWorkspace) const CISST_THROW(std
Definition nmrIsOrthonormal.h:119
void Allocate(const vctDynamicConstMatrixBase< __matrixOwnerTypeA, _elementType > &A)
Definition nmrIsOrthonormal.h:261
vct::size_type size_type
Definition nmrIsOrthonormal.h:66
void SetDimension(size_type m)
Definition nmrIsOrthonormal.h:75
Definition nmrIsOrthonormal.h:353
Friend(nmrIsOrthonormalFixedSizeData< _elementType, _rows > &data)
Definition nmrIsOrthonormal.h:357
VectorTypeWorkspace & Workspace(void)
Definition nmrIsOrthonormal.h:359
Data for nmrIsOrthonormal (Fixed size).
Definition nmrIsOrthonormal.h:333
VectorTypeWorkspace WorkspaceMember
Definition nmrIsOrthonormal.h:343
vctFixedSizeVector< _elementType, SIZE > VectorTypeWorkspace
Definition nmrIsOrthonormal.h:340
nmrIsOrthonormalFixedSizeData()
Definition nmrIsOrthonormal.h:368
@ SIZE
Definition nmrIsOrthonormal.h:336
Definition vctForwardDeclarations.h:145
DiagonalRefType Diagonal(void)
Definition vctDynamicMatrixBase.h:239
ThisType & ProductOf(const vctDynamicConstMatrixBase< __matrixOwnerType, _elementType > &matrix, const value_type scalar)
Definition vctDynamicMatrixBase.h:971
Dynamic matrix referencing existing memory.
Definition vctDynamicMatrixRef.h:75
void SetRef(size_type rows, size_type cols, stride_type rowStride, stride_type colStride, pointer dataPointer)
Definition vctDynamicMatrixRef.h:217
Definition vctDynamicVectorBase.h:62
Definition vctForwardDeclarations.h:131
Dynamic vector referencing existing memory.
Definition vctDynamicVectorRef.h:78
void SetRef(size_type size, pointer data, stride_type stride=1)
Definition vctDynamicVectorRef.h:156
A template for a fixed size matrix with fixed spacing in memory.
Definition vctFixedSizeConstMatrixBase.h:104
ConstRefTransposeType TransposeRef(void) const
Definition vctFixedSizeConstMatrixRef.h:172
Definition vctForwardDeclarations.h:110
pointer Pointer(size_type index=0)
Definition vctFixedSizeVectorBase.h:226
Implementation of a fixed-size vector using template metaprogramming.
Definition vctFixedSizeVector.h:54
#define CISST_THROW(exceptionParameter)
Somewhat portable compilation warning message. This works with very recent versions of gcc (4....
Definition cmnPortability.h:559
void cmnThrow(const _exceptionType &except, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_ERROR)
Definition cmnThrow.h:76
STL namespace.
size_t size_type
Definition vctContainerTraits.h:35
bool nmrIsOrthonormal(const vctFixedSizeConstMatrixBase< _size, _size, _rowStride, _colStride, _elementType, _dataPtrType > &A, nmrIsOrthonormalFixedSizeData< _elementType, _size > &data, _elementType tolerance=cmnTypeTraits< _elementType >::Tolerance())
Definition nmrIsOrthonormal.h:444
vctDynamicMatrix< _elementType > MatrixValueType
Definition vctDynamicConstMatrixBase.h:141
Declaration of vctDynamicMatrix.
Declaration of vctFixedSizeMatrix.