zarray.hpp
Go to the documentation of this file.
1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
4 //
5 // Copyright (C) 2013-2016, The Regents of The University of Michigan.
6 //
7 // This software was developed in the APRIL Robotics Lab under the
8 // direction of Edwin Olson, ebolson@umich.edu. This software may be
9 // available under alternative licensing terms; contact the address above.
10 //
11 // The views and conclusions contained in the software and documentation are those
12 // of the authors and should not be interpreted as representing official policies,
13 // either expressed or implied, of the Regents of The University of Michigan.
14 #ifndef _OPENCV_ZARRAY_HPP_
15 #define _OPENCV_ZARRAY_HPP_
16 
17 #include <stdlib.h>
18 #include <string.h>
19 
20 namespace cv {
21 namespace aruco {
22 
23 
24 struct sQuad{
25  float p[4][2]; // corners
26 };
27 
31 typedef struct zarray zarray_t;
32 struct zarray{
33  size_t el_sz; // size of each element
34 
35  int size; // how many elements?
36  int alloc; // we've allocated storage for how many elements?
37  char *data;
38 };
39 
45 inline static zarray_t *_zarray_create(size_t el_sz){
46  zarray_t *za = (zarray_t*) calloc(1, sizeof(zarray_t));
47  za->el_sz = el_sz;
48  return za;
49 }
50 
55 inline static void _zarray_destroy(zarray_t *za){
56  if (za == NULL)
57  return;
58 
59  if (za->data != NULL)
60  free(za->data);
61  memset(za, 0, sizeof(zarray_t));
62  free(za);
63 }
64 
70 inline static int _zarray_size(const zarray_t *za){
71  return za->size;
72 }
73 
78 inline static void _zarray_ensure_capacity(zarray_t *za, int capacity){
79  if (capacity <= za->alloc)
80  return;
81 
82  while (za->alloc < capacity) {
83  za->alloc *= 2;
84  if (za->alloc < 8)
85  za->alloc = 8;
86  }
87 
88  za->data = (char*) realloc(za->data, za->alloc * za->el_sz);
89 }
90 
96 inline static void _zarray_add(zarray_t *za, const void *p){
97  _zarray_ensure_capacity(za, za->size + 1);
98 
99  memcpy(&za->data[za->size*za->el_sz], p, za->el_sz);
100  za->size++;
101 }
102 
108 inline static void _zarray_get(const zarray_t *za, int idx, void *p){
109  CV_DbgAssert(idx >= 0);
110  CV_DbgAssert(idx < za->size);
111 
112  memcpy(p, &za->data[idx*za->el_sz], za->el_sz);
113 }
114 
122 inline static void _zarray_get_volatile(const zarray_t *za, int idx, void *p){
123  CV_DbgAssert(idx >= 0);
124  CV_DbgAssert(idx < za->size);
125 
126  *((void**) p) = &za->data[idx*za->el_sz];
127 }
128 
129 inline static void _zarray_truncate(zarray_t *za, int sz){
130  za->size = sz;
131 }
132 
138 static inline void _zarray_set(zarray_t *za, int idx, const void *p, void *outp){
139  CV_DbgAssert(idx >= 0);
140  CV_DbgAssert(idx < za->size);
141 
142  if (outp != NULL)
143  memcpy(outp, &za->data[idx*za->el_sz], za->el_sz);
144 
145  memcpy(&za->data[idx*za->el_sz], p, za->el_sz);
146 }
147 
148 }
149 }
150 #endif
static void _zarray_truncate(zarray_t *za, int sz)
Definition: zarray.hpp:129
static void _zarray_ensure_capacity(zarray_t *za, int capacity)
Definition: zarray.hpp:78
static void _zarray_destroy(zarray_t *za)
Definition: zarray.hpp:55
Definition: charuco.hpp:47
float p[4][2]
Definition: zarray.hpp:25
static void _zarray_get(const zarray_t *za, int idx, void *p)
Definition: zarray.hpp:108
static zarray_t * _zarray_create(size_t el_sz)
Definition: zarray.hpp:45
static void _zarray_get_volatile(const zarray_t *za, int idx, void *p)
Definition: zarray.hpp:122
static void _zarray_set(zarray_t *za, int idx, const void *p, void *outp)
Definition: zarray.hpp:138
static int _zarray_size(const zarray_t *za)
Definition: zarray.hpp:70
static void _zarray_add(zarray_t *za, const void *p)
Definition: zarray.hpp:96


aruco_pose
Author(s): Oleg Kalachev
autogenerated on Mon Feb 28 2022 22:08:24