QTrk
labview.h
Go to the documentation of this file.
1 #pragma once
2 
3 #define _STDINT_H
4 // WOW, including this causes a labview crash on DLL unloading!! (Only if vision is not actually ran)
5 // #include "nivision.h"
6 #include "extcode.h"
7 #include "niimaq.h"
8 #include <complex>
9 
22 /* lv_prolog.h and lv_epilog.h set up the correct alignment for LabVIEW data. */
23 #include "lv_prolog.h"
24 
25 typedef struct {
26  LVBoolean status;
27  int32 code;
28  LStrHandle message;
29 } ErrorCluster;
30 
32 template<typename T>
33 struct LVArray {
34  int32_t dimSize;
35  T elem[1];
36 };
37 //typedef LVArray<float> **ppFloatArray;
38 
40 template<typename T>
41 struct LVArray2D {
42  int32_t dimSizes[2];
43  T elem[1];
44 
45  T & xy(int col, int row) {
46  return elem[row*dimSizes[1]+col];
47  }
48  T& get(int row, int col) {
49  return elem[row*dimSizes[1]+col];
50  }
51  int numElem() { return dimSizes[0]*dimSizes[1]; }
52 };
53 //typedef LVArray2D<float> **ppFloatArray2;
54 
56 template<typename T>
57 struct LVArray3D {
58  int32_t dimSizes[3];
59  T elem[1];
60 
61  int numElem() { return dimSizes[0]*dimSizes[1]*dimSizes[2]; }
62 };
63 
65 template<typename T, int N>
66 struct LVArrayND {
67  int32_t dimSizes[N];
68  T elem[1];
69 
70  int numElem() {
71  int n = dimSizes[0];
72  for (int i=1;i<N;i++) n*=dimSizes[i];
73  return n;
74  }
75 };
76 
77 #ifndef DOXYGEN // Hide these structs from documentation (why not a single enum?)
78 
79 // Compile-time map of C++ types to Labview DataType codes
80 // https://zone.ni.com/reference/en-XX/help/371361J-01/lvexcode/numericarrayresize/
81 template<typename T> struct LVDataType {};
82 template<> struct LVDataType<float> { enum { code=9 }; };
83 template<> struct LVDataType<double> { enum { code=10 }; };
84 template<> struct LVDataType<int8_t> { enum { code=1 }; };
85 template<> struct LVDataType<int16_t> { enum { code=2 }; };
86 template<> struct LVDataType<int32_t> { enum { code=3 }; };
87 template<> struct LVDataType<int64_t> { enum { code=4 }; };
88 template<> struct LVDataType<uint8_t> { enum { code=5 }; };
89 template<> struct LVDataType<uint16_t> { enum { code=6 }; };
90 template<> struct LVDataType<uint32_t> { enum { code=7 }; };
91 template<> struct LVDataType<uint64_t> { enum { code=8 }; };
92 template<> struct LVDataType<std::complex<float> > { enum { code=0xc }; };
93 template<> struct LVDataType<std::complex<double> > { enum { code=0xd }; };
94 
95 #endif
96 
97 template<typename T>
98 void ResizeLVArray2D(LVArray2D<T>**& d, int rows, int cols)
99 {
100  if (NumericArrayResize(LVDataType<T>::code, 2, (UHandle*)&d, sizeof(T)*rows*cols) != mgNoErr)
101  throw std::runtime_error( SPrintf("NumericArrayResize(2D array, %d, %d) returned error.", rows,cols));
102  (*d)->dimSizes[0] = rows;
103  (*d)->dimSizes[1] = cols;
104 }
105 
106 template<typename T>
107 void ResizeLVArray3D(LVArray3D<T>**& d, int depth, int rows, int cols)
108 {
109  if (NumericArrayResize(LVDataType<T>::code, 3, (UHandle*)&d, sizeof(T)*rows*cols*depth) != mgNoErr)
110  throw std::runtime_error( SPrintf("NumericArrayResize(3D array, %d, %d, %d) returned error.", depth,rows,cols));
111 
112  (*d)->dimSizes[0] = depth;
113  (*d)->dimSizes[1] = rows;
114  (*d)->dimSizes[2] = cols;
115 }
116 
117 template<typename T, int N>
118 void ResizeLVArray(LVArrayND<T, N>**& d, int* dims)
119 {
120  for (int i=0;i<N;i++)
121  (*d)->dimSizes[i]=dims[i];
122  NumericArrayResize(LVDataType<T>::code, N, (UHandle*)&d, sizeof(T)*(*d)->numElem());
123 }
124 
125 template<typename T>
126 void ResizeLVArray(LVArray<T>**& d, int elems)
127 {
128  if (NumericArrayResize(LVDataType<T>::code, 1, (UHandle*)&d, sizeof(T)*elems) != mgNoErr)
129  throw std::runtime_error( SPrintf("NumericArrayResize(1D array, %d) returned error.", elems));
130  (*d)->dimSize = elems;
131 }
132 
133 #include "lv_epilog.h"
134 
135 void ArgumentErrorMsg(ErrorCluster* e, const std::string& msg);
136 
137 void SetLVString (LStrHandle str, const char *text);
138 MgErr FillErrorCluster(MgErr err, const char *message, ErrorCluster *error);
139 std::vector<std::string> LVGetStringArray(int count, LStrHandle *str);
140 
141 class QueuedTracker;
150 bool ValidateTracker(QueuedTracker* tracker, ErrorCluster* e, const char *funcname);
int32 code
Definition: labview.h:27
int32_t dimSize
Definition: labview.h:34
int numElem()
Definition: labview.h:51
bool ValidateTracker(QueuedTracker *tracker, ErrorCluster *e, const char *funcname)
Verify the referenced tracker is a valid QueuedTracker instance.
void SetLVString(LStrHandle str, const char *text)
void ResizeLVArray(LVArrayND< T, N > **&d, int *dims)
Definition: labview.h:118
T elem[1]
Definition: labview.h:35
int numElem()
Definition: labview.h:61
LabVIEW Array template.
Definition: labview.h:33
LVBoolean status
Definition: labview.h:26
void ResizeLVArray3D(LVArray3D< T > **&d, int depth, int rows, int cols)
Definition: labview.h:107
void ArgumentErrorMsg(ErrorCluster *e, const std::string &msg)
T & xy(int col, int row)
Definition: labview.h:45
void ResizeLVArray2D(LVArray2D< T > **&d, int rows, int cols)
Definition: labview.h:98
int numElem()
Definition: labview.h:70
LabVIEW N dimensions array template.
Definition: labview.h:66
LabVIEW 3D Array template.
Definition: labview.h:57
LabVIEW 2D Array template.
Definition: labview.h:41
LStrHandle message
Definition: labview.h:28
std::vector< std::string > LVGetStringArray(int count, LStrHandle *str)
Abstract tracker interface, implemented by QueuedCUDATracker and QueuedCPUTracker.
Definition: QueuedTracker.h:86
std::string SPrintf(const char *fmt,...)
Definition: utils.cpp:132
MgErr FillErrorCluster(MgErr err, const char *message, ErrorCluster *error)