cisst-saw
Loading...
Searching...
No Matches
vctDynamicConstNArrayRef.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-03
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 _vctDynamicConstNArrayRef_h
23#define _vctDynamicConstNArrayRef_h
24
29
32
88template <class _elementType, vct::size_type _dimension>
90 public vctDynamicConstNArrayBase<vctDynamicNArrayRefOwner<_elementType, _dimension>, _elementType, _dimension>
91{
92public:
93 /* define most types from vctContainerTraits and vctNArrayTraits */
94 enum {DIMENSION = _dimension};
97
98 /* documented in base class */
106
107
109 {
110 this->SetRef(0, nsize_type(0), nstride_type(0));
111 }
112
115 BaseType()
116 {
117 SetRef(other.Pointer(), other.sizes(), other.strides());
118 }
119
123 vctDynamicConstNArrayRef(const_pointer dataPointer, const nsize_type & sizes, const nstride_type & strides)
124 {
125 this->SetRef(dataPointer, sizes, strides);
126 }
127
131 vctDynamicConstNArrayRef(pointer dataPointer, const nsize_type & sizes, const nstride_type & strides)
132 {
133 this->SetRef(dataPointer, sizes, strides);
134 }
135
139 template <class __ownerType>
141 {
142 this->SetRef(otherNArray);
143 }
144
148 template <class __ownerType>
150 {
151 this->SetRef(vector);
152 }
153
157 template <size_type __size, stride_type __stride, typename __dataPtrType>
162
166 template <class __ownerType>
168 {
169 this->SetRef(matrix);
170 }
171
175 template <size_type __rows, size_type __cols, stride_type __rowStride, stride_type __colStride, typename __dataPtrType>
177 __rowStride, __colStride,
178 value_type, __dataPtrType>
179 & matrix)
180 {
181 this->SetRef(matrix);
182 }
183
184
188 void SetRef(const_pointer dataPointer, const nsize_type & sizes, const nstride_type & strides)
189 {
190 this->NArray.SetRef( const_cast<pointer>(dataPointer), sizes, strides );
191 }
192
196 template <class __ownerType>
198 {
199 this->SetRef( otherNArray.Pointer(), otherNArray.sizes(), otherNArray.strides() );
200 }
201
209 template <class __ownerType>
211 const nsize_type & startPosition,
212 const nsize_type & lengths)
213 {
214 CMN_ASSERT((startPosition + lengths).LesserOrEqual(otherNArray.sizes()));
215 this->SetRef(otherNArray.Pointer(startPosition), lengths, otherNArray.strides());
216 }
217
225 template <class __ownerType>
227 const ndimension_type & dimensions)
228 {
229 nsize_type sizes;
230 nstride_type strides;
231
232 const typename ndimension_type::const_iterator dimensionsBegin = dimensions.begin();
233 const typename ndimension_type::const_iterator dimensionsEnd = dimensions.end();
234 typename ndimension_type::const_iterator dimensionsIter;
235 typename nsize_type::iterator sizesIter = sizes.begin();
236 typename nstride_type::iterator stridesIter = strides.begin();
237 for (dimensionsIter = dimensionsBegin;
238 dimensionsIter != dimensionsEnd;
239 ++dimensionsIter, ++sizesIter, ++stridesIter) {
240 *sizesIter = otherNArray.size(*dimensionsIter);
241 *stridesIter = otherNArray.stride(*dimensionsIter);
242 }
243
244 this->SetRef(otherNArray.Pointer(), sizes, strides);
245 }
246
255 template <class __ownerType>
257 dimension_type dimension,
258 size_type index)
259 {
260 // set up local sizes and strides
261 nsize_type sizes;
262 nstride_type strides;
263 size_type i;
264
266 typedef typename OtherArrayType::nsize_type other_nsize_type;
267 typedef typename OtherArrayType::nstride_type other_nstride_type;
268
269 // set up iterators
270 const typename other_nsize_type::const_iterator otherSizesBegin = otherNArray.sizes().begin();
271 typename other_nsize_type::const_iterator otherSizesIter;
272 const typename other_nstride_type::const_iterator otherStridesBegin = otherNArray.strides().begin();
273 typename other_nstride_type::const_iterator otherStridesIter;
274 const typename nsize_type::iterator sizesBegin = sizes.begin();
275 const typename nsize_type::iterator sizesEnd = sizes.end();
276 typename nsize_type::iterator sizesIter;
277 const typename nstride_type::iterator stridesBegin = strides.begin();
278 typename nstride_type::iterator stridesIter;
279
280 // copy sizes and strides in every dimension except the one specified
281 otherSizesIter = otherSizesBegin;
282 otherStridesIter = otherStridesBegin;
283 sizesIter = sizesBegin;
284 stridesIter = stridesBegin;
285 i = 0;
286 while (sizesIter != sizesEnd) {
287 if (i == dimension) {
288 ++otherSizesIter;
289 ++otherStridesIter;
290 ++i;
291 } else {
292 *sizesIter = *otherSizesIter;
293 *stridesIter = *otherStridesIter;
294
295 ++otherSizesIter;
296 ++otherStridesIter;
297 ++sizesIter;
298 ++stridesIter;
299 ++i;
300 }
301 }
302
303 // set start position
304 other_nsize_type startPosition(static_cast<size_type>(0));
305 startPosition[dimension] = index;
306 this->SetRef(otherNArray.Pointer(startPosition), sizes, strides);
307 }
308
312 template <class __ownerType>
314 {
315 this->SetRef( vector.Pointer(), nsize_type(vector.size()), nstride_type(vector.stride()) );
316 }
317
321 template <size_type __size, stride_type __stride, typename __dataPtrType>
323 {
324 this->SetRef( vector.Pointer(), nsize_type(__size), nstride_type(__stride) );
325 }
326
330 template <class __ownerType>
332 {
333 this->SetRef(matrix.Pointer(),
334 nsize_type(matrix.rows(), matrix.cols()),
335 nstride_type(matrix.row_stride(), matrix.col_stride()));
336 }
337
341 template <size_type __rows, size_type __cols, stride_type __rowStride, stride_type __colStride, typename __dataPtrType>
343 {
344 this->SetRef(matrix.Pointer(),
345 nsize_type(__rows, __cols),
346 nstride_type(__rowStride, __colStride));
347 }
348};
349
350
351#endif // _vctDynamicConstNArrayRef_h
352
Definition vctForwardDeclarations.h:145
Definition vctForwardDeclarations.h:171
vctDynamicConstNArrayRef(const vctDynamicConstVectorBase< __ownerType, value_type > &vector)
Definition vctDynamicConstNArrayRef.h:149
void SetRef(const vctDynamicConstVectorBase< __ownerType, value_type > &vector)
Definition vctDynamicConstNArrayRef.h:313
vctDynamicConstNArrayRef(const vctFixedSizeConstVectorBase< __size, __stride, value_type, __dataPtrType > &vector)
Definition vctDynamicConstNArrayRef.h:158
vctDynamicNArrayRefOwner< _elementType, DIMENSION > NArrayOwnerType
Definition vctDynamicConstNArrayRef.h:100
vctDynamicConstNArrayRef(const vctFixedSizeConstMatrixBase< __rows, __cols, __rowStride, __colStride, value_type, __dataPtrType > &matrix)
Definition vctDynamicConstNArrayRef.h:176
NArrayOwnerType::iterator iterator
Definition vctDynamicConstNArrayRef.h:102
void SubarrayOf(const vctDynamicConstNArrayBase< __ownerType, value_type, DIMENSION > &otherNArray, const nsize_type &startPosition, const nsize_type &lengths)
Definition vctDynamicConstNArrayRef.h:210
void SetRef(const vctDynamicConstMatrixBase< __ownerType, value_type > &matrix)
Definition vctDynamicConstNArrayRef.h:331
vctDynamicConstNArrayRef(const vctDynamicConstMatrixBase< __ownerType, value_type > &matrix)
Definition vctDynamicConstNArrayRef.h:167
void PermutationOf(const vctDynamicConstNArrayBase< __ownerType, value_type, DIMENSION > &otherNArray, const ndimension_type &dimensions)
Definition vctDynamicConstNArrayRef.h:226
NArrayOwnerType::reverse_iterator reverse_iterator
Definition vctDynamicConstNArrayRef.h:104
void SetRef(const vctDynamicConstNArrayBase< __ownerType, value_type, DIMENSION > &otherNArray)
Definition vctDynamicConstNArrayRef.h:197
@ DIMENSION
Definition vctDynamicConstNArrayRef.h:94
vctDynamicConstNArrayRef(const vctDynamicConstNArrayBase< __ownerType, value_type, DIMENSION > &otherNArray)
Definition vctDynamicConstNArrayRef.h:140
void SetRef(const vctFixedSizeConstMatrixBase< __rows, __cols, __rowStride, __colStride, value_type, __dataPtrType > &matrix)
Definition vctDynamicConstNArrayRef.h:342
vctDynamicConstNArrayRef(const_pointer dataPointer, const nsize_type &sizes, const nstride_type &strides)
Definition vctDynamicConstNArrayRef.h:123
void SetRef(const_pointer dataPointer, const nsize_type &sizes, const nstride_type &strides)
Definition vctDynamicConstNArrayRef.h:188
vctDynamicConstNArrayRef()
Definition vctDynamicConstNArrayRef.h:108
vctDynamicConstNArrayBase< vctDynamicNArrayRefOwner< _elementType, DIMENSION >, _elementType, DIMENSION > BaseType
Definition vctDynamicConstNArrayRef.h:101
NArrayOwnerType::const_iterator const_iterator
Definition vctDynamicConstNArrayRef.h:103
vctDynamicConstNArrayRef(pointer dataPointer, const nsize_type &sizes, const nstride_type &strides)
Definition vctDynamicConstNArrayRef.h:131
vctDynamicConstNArrayRef< _elementType, DIMENSION > ThisType
Definition vctDynamicConstNArrayRef.h:99
void SliceOf(const vctDynamicConstNArrayBase< __ownerType, value_type, DIMENSION+1 > &otherNArray, dimension_type dimension, size_type index)
Definition vctDynamicConstNArrayRef.h:256
NArrayOwnerType::const_reverse_iterator const_reverse_iterator
Definition vctDynamicConstNArrayRef.h:105
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
vctDynamicConstNArrayRef(const ThisType &other)
Definition vctDynamicConstNArrayRef.h:114
VCT_NARRAY_TRAITS_TYPEDEFS(DIMENSION)
void SetRef(const vctFixedSizeConstVectorBase< __size, __stride, value_type, __dataPtrType > &vector)
Definition vctDynamicConstNArrayRef.h:322
Definition vctForwardDeclarations.h:119
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
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
Declaration of vctDynamicConstNArrayBase.
dimension_type dimension(void) const
Definition vctDynamicConstNArrayBase.h:331
OwnerType NArray
Definition vctDynamicConstNArrayBase.h:226
Declaration of vctDynamicNArrayRefOwner.