cisst-saw
Loading...
Searching...
No Matches
vctDynamicNArrayRef.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-13
8
9 (C) Copyright 2006-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 _vctDynamicNArrayRef_h
23#define _vctDynamicNArrayRef_h
24
29
33
86template <class _elementType, vct::size_type _dimension>
88 public vctDynamicNArrayBase<vctDynamicNArrayRefOwner<_elementType, _dimension>, _elementType, _dimension>
89{
90public:
91 /* define most types from vctContainerTraits and vctNArrayTraits */
92 enum {DIMENSION = _dimension};
95
96 /* documented in base class */
104
105
107 {
108 this->SetRef(0, nsize_type(0), nstride_type(0));
109 }
110
118 BaseType()
119 {
120 this->SetRef(const_cast<pointer>(other.Pointer()), other.sizes(), other.strides());
121 }
122
126 vctDynamicNArrayRef(pointer dataPointer, const nsize_type & sizes, const nstride_type & strides)
127 {
128 this->SetRef(dataPointer, sizes, strides);
129 }
130
134 template <class __ownerType>
136 {
137 this->SetRef(otherNArray);
138 }
139
143 template <class __ownerType>
148
152 template <size_type __size, stride_type __stride, typename __dataPtrType>
157
161 template <class __ownerType>
166
170 template <size_type __rows, size_type __cols, stride_type __rowStride, stride_type __colStride, typename __dataPtrType>
175
176
180 void SetRef(pointer dataPointer, const nsize_type & sizes, const nstride_type & strides)
181 {
182 this->NArray.SetRef(dataPointer, sizes, strides);
183 }
184
188 template <class __ownerType>
190 {
191 this->SetRef(otherNArray.Pointer(), otherNArray.sizes(), otherNArray.strides());
192 }
193
201 template <class __ownerType>
203 const nsize_type & startPosition,
204 const nsize_type & lengths)
205 {
206 CMN_ASSERT((startPosition + lengths).LesserOrEqual(otherNArray.sizes()));
207 this->SetRef(otherNArray.Pointer(startPosition), lengths, otherNArray.strides());
208 }
209
217 template <class __ownerType>
219 const ndimension_type & dimensions)
220 {
221 nsize_type sizes;
222 nstride_type strides;
223
224 const typename ndimension_type::const_iterator dimensionsBegin = dimensions.begin();
225 const typename ndimension_type::const_iterator dimensionsEnd = dimensions.end();
226 typename ndimension_type::const_iterator dimensionsIter;
227 typename nsize_type::iterator sizesIter = sizes.begin();
228 typename nstride_type::iterator stridesIter = strides.begin();
229 for (dimensionsIter = dimensionsBegin;
230 dimensionsIter != dimensionsEnd;
231 ++dimensionsIter, ++sizesIter, ++stridesIter) {
232 *sizesIter = otherNArray.size(*dimensionsIter);
233 *stridesIter = otherNArray.stride(*dimensionsIter);
234 }
235
236 this->SetRef(otherNArray.Pointer(), sizes, strides);
237 }
238
247 template <class __ownerType>
249 dimension_type dimension,
250 size_type index)
251 {
252 // set up local sizes and strides
253 nsize_type sizes;
254 nstride_type strides;
255 size_type i;
256
258 typedef typename OtherArrayType::nsize_type other_nsize_type;
259 typedef typename OtherArrayType::nstride_type other_nstride_type;
260
261 // set up iterators
262 const typename other_nsize_type::const_iterator otherSizesBegin = otherNArray.sizes().begin();
263 typename other_nsize_type::const_iterator otherSizesIter;
264 const typename other_nstride_type::const_iterator otherStridesBegin = otherNArray.strides().begin();
265 typename other_nstride_type::const_iterator otherStridesIter;
266 const typename nsize_type::iterator sizesBegin = sizes.begin();
267 const typename nsize_type::iterator sizesEnd = sizes.end();
268 typename nsize_type::iterator sizesIter;
269 const typename nstride_type::iterator stridesBegin = strides.begin();
270 typename nstride_type::iterator stridesIter;
271
272 // copy sizes and strides in every dimension except the one specified
273 otherSizesIter = otherSizesBegin;
274 otherStridesIter = otherStridesBegin;
275 sizesIter = sizesBegin;
276 stridesIter = stridesBegin;
277 i = 0;
278 while (sizesIter != sizesEnd) {
279 if (i == dimension) {
280 ++otherSizesIter;
281 ++otherStridesIter;
282 ++i;
283 } else {
284 *sizesIter = *otherSizesIter;
285 *stridesIter = *otherStridesIter;
286
287 ++otherSizesIter;
288 ++otherStridesIter;
289 ++sizesIter;
290 ++stridesIter;
291 ++i;
292 }
293 }
294
295 // set start position
296 other_nsize_type startPosition(static_cast<size_type>(0));
297 startPosition[dimension] = index;
298 this->SetRef(otherNArray.Pointer(startPosition), sizes, strides);
299 }
300
304 template <class __ownerType>
306 {
307 this->SetRef( vector.Pointer(), nsize_type(vector.size()), nstride_type(vector.stride()) );
308 }
309
313 template <size_type __size, stride_type __stride, typename __dataPtrType>
315 {
316 this->SetRef( vector.Pointer(), nsize_type(__size), nstride_type(__stride) );
317 }
318
322 template <class __ownerType>
324 {
325 this->SetRef(matrix.Pointer(),
326 nsize_type(matrix.rows(), matrix.cols()),
327 nstride_type(matrix.row_stride(), matrix.col_stride()));
328 }
329
333 template <size_type __rows, size_type __cols, stride_type __rowStride, stride_type __colStride, typename __dataPtrType>
335 {
336 this->SetRef(matrix.Pointer(),
337 nsize_type(__rows, __cols),
338 nstride_type(__rowStride, __colStride));
339 }
340
341
347 inline ThisType & operator = (const ThisType & other)
348 {
349 return reinterpret_cast<ThisType &>(this->Assign(other));
350 }
351
353 {
354 return reinterpret_cast<ThisType &>(this->Assign(other));
355 }
356
357 template <class __nArrayOwnerType, typename __elementType>
359 {
360 return reinterpret_cast<ThisType &>(this->Assign(other));
361 }
362
363
365 inline ThisType & operator = (const value_type & value)
366 {
367 this->SetAll(value);
368 return *this;
369 }
370
371};
372
373
374#endif // _vctDynamicNArrayRef_h
375
Definition vctForwardDeclarations.h:145
Dynamic nArray referencing existing memory (const).
Definition vctDynamicConstNArrayRef.h:91
Definition vctForwardDeclarations.h:119
Definition vctDynamicNArrayBase.h:41
value_type SetAll(const value_type value)
Definition vctDynamicNArrayBase.h:337
iterator begin(void)
Definition vctDynamicNArrayBase.h:91
pointer Pointer(const nsize_type &indices)
Definition vctDynamicNArrayBase.h:154
ThisType & Assign(const vctDynamicConstNArrayBase< __nArrayOwnerType, value_type, DIMENSION > &other)
Definition vctDynamicNArrayBase.h:370
vctDynamicNArrayRef(vctDynamicConstVectorBase< __ownerType, _elementType > &vector)
Definition vctDynamicNArrayRef.h:144
vctDynamicNArrayRef(pointer dataPointer, const nsize_type &sizes, const nstride_type &strides)
Definition vctDynamicNArrayRef.h:126
vctDynamicNArrayBase< vctDynamicNArrayRefOwner< _elementType, DIMENSION >, _elementType, DIMENSION > BaseType
Definition vctDynamicNArrayRef.h:99
vctDynamicNArrayRef(vctFixedSizeConstVectorBase< __size, __stride, _elementType, __dataPtrType > &vector)
Definition vctDynamicNArrayRef.h:153
vctDynamicNArrayRef(vctFixedSizeConstMatrixBase< __rows, __cols, __rowStride, __colStride, _elementType, __dataPtrType > &matrix)
Definition vctDynamicNArrayRef.h:171
@ DIMENSION
Definition vctDynamicNArrayRef.h:92
vctDynamicNArrayRef< _elementType, DIMENSION > ThisType
Definition vctDynamicNArrayRef.h:97
void SubarrayOf(vctDynamicNArrayBase< __ownerType, _elementType, DIMENSION > &otherNArray, const nsize_type &startPosition, const nsize_type &lengths)
Definition vctDynamicNArrayRef.h:202
vctDynamicNArrayRef()
Definition vctDynamicNArrayRef.h:106
void SetRef(pointer dataPointer, const nsize_type &sizes, const nstride_type &strides)
Definition vctDynamicNArrayRef.h:180
void SetRef(vctDynamicConstMatrixBase< __ownerType, _elementType > &matrix)
Definition vctDynamicNArrayRef.h:323
void PermutationOf(vctDynamicNArrayBase< __ownerType, _elementType, DIMENSION > &otherNArray, const ndimension_type &dimensions)
Definition vctDynamicNArrayRef.h:218
void SetRef(vctFixedSizeConstVectorBase< __size, __stride, _elementType, __dataPtrType > &vector)
Definition vctDynamicNArrayRef.h:314
void SetRef(vctFixedSizeConstMatrixBase< __rows, __cols, __rowStride, __colStride, _elementType, __dataPtrType > &matrix)
Definition vctDynamicNArrayRef.h:334
vctDynamicNArrayRefOwner< _elementType, DIMENSION > NArrayOwnerType
Definition vctDynamicNArrayRef.h:98
NArrayOwnerType::iterator iterator
Definition vctDynamicNArrayRef.h:100
void SliceOf(vctDynamicNArrayBase< __ownerType, _elementType, DIMENSION+1 > &otherNArray, dimension_type dimension, size_type index)
Definition vctDynamicNArrayRef.h:248
vctDynamicNArrayRef(vctDynamicNArrayBase< __ownerType, _elementType, DIMENSION > &otherNArray)
Definition vctDynamicNArrayRef.h:135
void SetRef(vctDynamicNArrayBase< __ownerType, _elementType, DIMENSION > &otherNArray)
Definition vctDynamicNArrayRef.h:189
NArrayOwnerType::reverse_iterator reverse_iterator
Definition vctDynamicNArrayRef.h:102
VCT_NARRAY_TRAITS_TYPEDEFS(DIMENSION)
vctDynamicNArrayRef(const ThisType &other)
Definition vctDynamicNArrayRef.h:117
ThisType & operator=(const ThisType &other)
Definition vctDynamicNArrayRef.h:347
NArrayOwnerType::const_reverse_iterator const_reverse_iterator
Definition vctDynamicNArrayRef.h:103
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
NArrayOwnerType::const_iterator const_iterator
Definition vctDynamicNArrayRef.h:101
void SetRef(vctDynamicConstVectorBase< __ownerType, _elementType > &vector)
Definition vctDynamicNArrayRef.h:305
vctDynamicNArrayRef(vctDynamicConstMatrixBase< __ownerType, _elementType > &matrix)
Definition vctDynamicNArrayRef.h:162
Definition vctDynamicNArrayRefOwner.h:37
vctVarStrideNArrayIterator< ThisType, true > iterator
Definition vctDynamicNArrayRefOwner.h:48
vctVarStrideNArrayIterator< ThisType, false > reverse_iterator
Definition vctDynamicNArrayRefOwner.h:50
vctVarStrideNArrayConstIterator< ThisType, true > const_iterator
Definition vctDynamicNArrayRefOwner.h:49
vctVarStrideNArrayConstIterator< ThisType, false > const_reverse_iterator
Definition vctDynamicNArrayRefOwner.h:51
void SetRef(pointer data, const nsize_type &sizes, const nstride_type &strides)
Definition vctDynamicNArrayRefOwner.h:67
A template for a fixed size matrix with fixed spacing in memory.
Definition vctFixedSizeConstMatrixBase.h:104
const_pointer Pointer(size_type rowIndex, size_type colIndex) const
Definition vctFixedSizeConstMatrixBase.h:329
A template for a fixed length vector with fixed spacing in memory.
Definition vctFixedSizeConstVectorBase.h:108
const_pointer Pointer(size_type index=0) const
Definition vctFixedSizeConstVectorBase.h:268
#define CMN_ASSERT(expr)
Definition cmnAssert.h:97
const nsize_type & sizes(void) const
Definition vctDynamicConstMatrixBase.h:233
bool LesserOrEqual(const vctDynamicConstMatrixBase< __matrixOwnerType, _elementType > &otherMatrix) const
Definition vctDynamicConstMatrixBase.h:758
const nstride_type & strides(void) const
Definition vctDynamicConstMatrixBase.h:258
dimension_type dimension(void) const
Definition vctDynamicConstNArrayBase.h:331
OwnerType NArray
Definition vctDynamicConstNArrayBase.h:226
Declaration of vctDynamicConstNArrayRef.
Declaration of vctDynamicNArrayBase.
Declaration of vctDynamicNArrayRefOwner.