cisst-saw
Loading...
Searching...
No Matches
vctDynamicNArray.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): Daniel Li, Ofri Sadowsky, Anton Deguet
7 Created on: 2006-07-10
8
9 (C) Copyright 2006-2009 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 _vctDynamicNArray_h
23#define _vctDynamicNArray_h
24
29
33
121template<class _elementType, vct::size_type _dimension>
122class vctDynamicNArray :
123 public vctDynamicNArrayBase<vctDynamicNArrayOwner<_elementType, _dimension>, _elementType, _dimension>
124{
125
126 friend class vctReturnDynamicNArray<_elementType, _dimension>;
127
128public:
129 /* define most types from vctContainerTraits and vctNArrayTraits */
132
135
138 // The default initialization of vctDynamicNArrayOwner is empty.
139 {}
140
143 vctDynamicNArray(const nsize_type & sizes)
144 {
145 this->NArray.SetSize(sizes);
146 }
147
150 vctDynamicNArray(const nsize_type & sizes, value_type value)
151 {
152 this->NArray.SetSize(sizes);
153 SetAll(value);
154 }
155
161
162
166 vctDynamicNArray(const ThisType & otherNArray):
167 BaseType()
168 {
169 SetSize(otherNArray.sizes());
170 this->Assign(otherNArray);
171 }
172 template <class _otherNArrayOwnerType>
174 {
175 SetSize(otherNArray.sizes());
176 this->Assign(otherNArray);
177 }
178
179
184 template <class _otherNArrayOwnerType, typename _otherNArrayElementType>
186 {
187 SetSize(otherNArray.sizes());
188 this->Assign(otherNArray);
189 }
190
191
197 template <class __nArrayOwnerType, typename __elementType>
199 {
200 SetSize(otherNArray.sizes());
201 this->Assign(otherNArray);
202 return *this;
203 }
204
211 ThisType & operator = (const ThisType & otherNArray)
212 {
213 SetSize(otherNArray.sizes());
214 this->Assign(otherNArray);
215 return *this;
216 }
217
218
229
231 inline ThisType & operator = (const value_type & value)
232 {
233 this->SetAll(value);
234 return *this;
235 }
236
237 // documented in base class
238 template <class __nArrayOwnerType, typename __elementType>
240 this->SetSize(other.size());
241 return this->Assign(other);
242 }
243
247 void SetSize(const nsize_type & sizes)
248 {
249 this->NArray.SetSize(sizes);
250 }
251
252};
253
254
270template <class _elementType, vct::size_type _dimension>
271class vctReturnDynamicNArray : public vctDynamicNArray<_elementType, _dimension>
272{
273public:
276
279
280 explicit vctReturnDynamicNArray(const BaseType & other)
281 {
282 BaseType & nonConstOther = const_cast<BaseType &>(other);
283 // if we don't save it in a variable, it will be destroyed in the Release operation
284
285 const nsize_type sizes = other.sizes();
286 this->NArray.Own(sizes, nonConstOther.NArray.Release());
287 }
288};
289
290
291// implementation of the special copy constructor of vctDynamicNArray
292template <class _elementType, vct::size_type _dimension>
294{
297 // if we don't save it in a variable, it will be destroyed in the Release operation
298
299 const nsize_type sizes = other.sizes();
300 this->NArray.Own(sizes, nonConstOther.NArray.Release());
301}
302
303
304// implementation of the special assignment operator from vctReturnDynamicNArray to vctDynamicNArray
305template <class _elementType, vct::size_type _dimension>
308{
311 // if we don't save it in a variable, it will be destroyed in the Release operation
312
313 const nsize_type sizes = other.sizes();
314 this->NArray.clear();
315 this->NArray.Own(sizes, nonConstOther.NArray.Release());
316 return *this;
317}
318
319
322
327template <class _nArrayOwnerType1, class _nArrayOwnerType2, class _elementType, vct::size_type _dimension>
331{
332 typedef _elementType value_type;
333 vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray1);
334 resultStorage.Add(inputNArray2);
336}
337
338/* documented above */
339template <class _nArrayOwnerType1, class _nArrayOwnerType2, class _elementType, vct::size_type _dimension>
343{
344 typedef _elementType value_type;
345 vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray1);
346 resultStorage.Subtract(inputNArray2);
348}
349
350
351
352
356
361template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
364 const _elementType & inputScalar)
365{
366 typedef _elementType value_type;
367 vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray);
368 resultStorage.Add(inputScalar);
370}
371
372/* documented above */
373template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
376 const _elementType & inputScalar)
377{
378 typedef _elementType value_type;
379 vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray);
380 resultStorage.Subtract(inputScalar);
382}
383
384/* documented above */
385template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
388 const _elementType & inputScalar)
389{
390 typedef _elementType value_type;
391 vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray);
392 resultStorage.Multiply(inputScalar);
394}
395
396/* documented above */
397template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
400 const _elementType & inputScalar)
401{
402 typedef _elementType value_type;
403 vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray);
404 resultStorage.Divide(inputScalar);
406}
407
408
409
410
413
418template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
420operator + (const _elementType & inputScalar,
422{
423 typedef _elementType value_type;
424 vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray.sizes());
425 resultStorage.SumOf(inputScalar, inputNArray);
427}
428
429/* documented above */
430template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
432operator - (const _elementType & inputScalar,
434{
435 typedef _elementType value_type;
436 vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray.sizes());
437 resultStorage.DifferenceOf(inputScalar, inputNArray);
439}
440
441/* documented above */
442template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
444operator * (const _elementType & inputScalar,
446{
447 typedef _elementType value_type;
448 vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray.sizes());
449 resultStorage.ProductOf(inputScalar, inputNArray);
451}
452
453/* documented above */
454template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
456operator / (const _elementType & inputScalar,
458{
459 typedef _elementType value_type;
460 vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray.sizes());
461 resultStorage.RatioOf(inputScalar, inputNArray);
463}
464
465
466
469
473template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
476{
477 typedef _elementType value_type;
478 vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray.sizes());
479 resultStorage.NegationOf(inputNArray);
481}
482
483
484
485
486#ifndef DOXYGEN
487template <class _nArrayOwnerType1, class _nArrayOwnerType2, class _elementType, vct::size_type _dimension>
491{
492 typedef _elementType value_type;
493 vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray1.sizes());
494 resultStorage.ProductOf(inputNArray1, inputNArray2);
496}
497
498
499/*
500 Methods declared previously and implemented here because they require vctReturnDynamicNArray
501*/
502
503
504/* documented in class vctDynamicConstNArrayBase */
505template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
508{
509 typedef _elementType value_type;
510 vctDynamicNArray<value_type, _dimension> resultStorage(this->sizes());
512 NoNi<typename vctUnaryOperations<value_type>::AbsValue>::
513 Run(resultStorage, *this);
515}
516
517/* documented in class vctDynamicConstNArrayBase */
518template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
521{
522 typedef _elementType value_type;
523 vctDynamicNArray<value_type, _dimension> resultStorage(this->sizes());
525 NoNi<typename vctUnaryOperations<value_type>::Negation>::
526 Run(resultStorage, *this);
528}
529
530/* documented in class vctDynamicConstNArrayBase */
531template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
534{
535 typedef _elementType value_type;
536 vctDynamicNArray<value_type, _dimension> resultStorage(this->sizes());
538 NoNi<typename vctUnaryOperations<value_type>::Floor>::
539 Run(resultStorage, *this);
541}
542
543/* documented in class vctDynamicConstNArrayBase */
544template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
547{
548 typedef _elementType value_type;
549 vctDynamicNArray<value_type, _dimension> resultStorage(this->sizes());
551 NoNi<typename vctUnaryOperations<value_type>::Ceil>::
552 Run(resultStorage, *this);
554}
555
556/* Documented in class vctDynamicConstNArrayBase */
557template <class _nArrayOwnerType, class __nArrayOwnerType, class _elementType,
558 class _elementOperationType, vct::size_type _dimension>
568
569/* documented in class vctDynamicConstNArrayBase */
570template <class _nArrayOwnerType, class _elementType, class _elementOperationType, vct::size_type _dimension>
573 const _elementType & scalar)
574{
575 vctDynamicNArray<bool, _dimension> result(nArray.sizes());
577 NoNiSi<_elementOperationType>::Run(result, nArray, scalar);
579}
580
581
582/* documented in class vctDynamicConstNArrayBase */
583template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
584inline vctDynamicNArrayRef<_elementType, _dimension - 1>
587 vct::index_type index)
588{
589 vctDynamicNArrayRef<_elementType, _dimension - 1> slice;
590 slice.SliceOf(input, dimension, index);
591 return slice;
592}
593
594/* documented in class vctDynamicConstNArrayBase */
595template <class _nArrayOwnerType, class _elementType>
596inline _elementType &
602
603/* documented in class vctDynamicConstNArrayBase */
604template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
605inline vctDynamicConstNArrayRef<_elementType, _dimension - 1>
608 vct::index_type index)
609{
610 vctDynamicConstNArrayRef<_elementType, _dimension - 1> slice;
611 slice.SliceOf(input, dimension, index);
612 return slice;
613}
614
615/* documented in class vctDynamicConstNArrayBase */
616template <class _nArrayOwnerType, class _elementType>
617inline const _elementType &
623
624#endif // DOXYGEN
625
626
627#endif // _vctDynamicNArray_h
628
Definition vctForwardDeclarations.h:171
Dynamic nArray referencing existing memory (const).
Definition vctDynamicConstNArrayRef.h:91
void SliceOf(const vctDynamicConstNArrayBase< __ownerType, value_type, DIMENSION+1 > &otherNArray, dimension_type dimension, size_type index)
Definition vctDynamicConstNArrayRef.h:256
Definition vctDynamicNArrayBase.h:41
reference Element(const nsize_type &coordinates)
Definition vctDynamicNArrayBase.h:239
Definition vctForwardDeclarations.h:183
Container class for the dynamic nArray engines.
Definition vctDynamicNArrayLoopEngines.h:42
Dynamic nArray referencing existing memory.
Definition vctDynamicNArrayRef.h:89
void SliceOf(vctDynamicNArrayBase< __ownerType, _elementType, DIMENSION+1 > &otherNArray, dimension_type dimension, size_type index)
Definition vctDynamicNArrayRef.h:248
Implementation of a fixed-size vector using template metaprogramming.
Definition vctFixedSizeVector.h:54
Definition vctDynamicNArray.h:272
vctDynamicNArray< value_type, _dimension > BaseType
Definition vctDynamicNArray.h:278
VCT_NARRAY_TRAITS_TYPEDEFS(_dimension)
vctReturnDynamicNArray(const BaseType &other)
Definition vctDynamicNArray.h:280
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
size_t size_type
Definition vctContainerTraits.h:35
size_t index_type
Definition vctContainerTraits.h:36
#define VCT_CONTAINER_TRAITS_TYPEDEFS(type)
Definition vctContainerTraits.h:50
#define VCT_NARRAY_TRAITS_TYPEDEFS(dimension)
Definition vctContainerTraits.h:68
const nsize_type & sizes(void) const
Definition vctDynamicConstMatrixBase.h:233
vctDynamicConstMatrixBase< _matrixOwnerType, _elementType > ThisType
Definition vctDynamicConstMatrixBase.h:86
_elementType & vctDynamicNArrayElementSlice(vctDynamicNArrayBase< _nArrayOwnerType, _elementType, 1 > &input, vct::index_type index)
Definition vctDynamicNArray.h:597
const _elementType & vctDynamicNArrayConstElementSlice(const vctDynamicConstNArrayBase< _nArrayOwnerType, _elementType, 1 > &input, vct::index_type index)
Definition vctDynamicNArray.h:618
vctDynamicConstNArrayRef< _elementType, _dimension - 1 > vctDynamicNArrayConstNArraySlice(const vctDynamicConstNArrayBase< _nArrayOwnerType, _elementType, _dimension > &input, vct::size_type dimension, vct::index_type index)
Definition vctDynamicNArray.h:606
vctReturnDynamicNArray< bool, _dimension > vctDynamicNArrayElementwiseCompareNArray(const vctDynamicConstNArrayBase< _nArrayOwnerType, _elementType, _dimension > &nArray1, const vctDynamicConstNArrayBase< _nArrayOwnerType, _elementType, _dimension > &nArray2)
Definition vctDynamicNArray.h:560
vctDynamicNArrayRef< _elementType, _dimension - 1 > vctDynamicNArrayNArraySlice(vctDynamicNArrayBase< _nArrayOwnerType, _elementType, _dimension > &input, vct::size_type dimension, vct::index_type index)
Definition vctDynamicNArray.h:585
dimension_type dimension(void) const
Definition vctDynamicConstNArrayBase.h:331
vctReturnDynamicNArray< bool, _dimension > vctDynamicNArrayElementwiseCompareScalar(const vctDynamicConstNArrayBase< _nArrayOwnerType, _elementType, _dimension > &nArray, const _elementType &scalar)
Definition vctDynamicNArray.h:572
OwnerType NArray
Definition vctDynamicConstNArrayBase.h:226
ThisType & ForceAssign(const vctDynamicConstMatrixBase< __matrixOwnerType, __elementType > &other)
Definition vctDynamicMatrix.h:306
void SetSize(size_type rows, size_type cols, bool storageOrder)
Definition vctDynamicMatrix.h:364
ThisType & operator=(const vctDynamicConstMatrixBase< __matrixOwnerType, __elementType > &otherMatrix)
Definition vctDynamicMatrix.h:255
vctReturnDynamicNArray< _elementType, _dimension > operator*(const vctDynamicConstNArrayBase< _nArrayOwnerType, _elementType, _dimension > &inputNArray, const _elementType &inputScalar)
Definition vctDynamicNArray.h:387
vctDynamicNArray()
Definition vctDynamicNArray.h:137
vctDynamicNArrayBase< vctDynamicNArrayOwner< _elementType, _dimension >, _elementType, _dimension > BaseType
Definition vctDynamicNArray.h:133
vctReturnDynamicNArray< _elementType, _dimension > operator/(const vctDynamicConstNArrayBase< _nArrayOwnerType, _elementType, _dimension > &inputNArray, const _elementType &inputScalar)
Definition vctDynamicNArray.h:399
vctReturnDynamicNArray< _elementType, _dimension > operator+(const vctDynamicConstNArrayBase< _nArrayOwnerType1, _elementType, _dimension > &inputNArray1, const vctDynamicConstNArrayBase< _nArrayOwnerType2, _elementType, _dimension > &inputNArray2)
Definition vctDynamicNArray.h:329
vctReturnDynamicNArray< _elementType, _dimension > operator-(const vctDynamicConstNArrayBase< _nArrayOwnerType1, _elementType, _dimension > &inputNArray1, const vctDynamicConstNArrayBase< _nArrayOwnerType2, _elementType, _dimension > &inputNArray2)
Definition vctDynamicNArray.h:341
Declaration of vctDynamicNArrayBase.
Declaration of vctDynamicNArrayOwner.
Declaration of vctDynamicNArrayRef.