1 #ifndef bstm_data_traits_h_
2 #define bstm_data_traits_h_
3 
4 #include <string>
5 #include <iostream>
6 #include <cstddef>
7 #ifdef _MSC_VER
8 #  include <vcl_msvc_warnings.h>
9 #endif
10 #include <vnl/vnl_vector_fixed.h>
11 
12 #include <boxm2/boxm2_data_traits.h>
13 
14 class boxm2_mog3_grey_processor;
15 class boxm2_gauss_grey_processor;
16 class boxm2_gauss_rgb_processor;
17 class boxm2_mog6_view_processor;
18 class boxm2_mog6_view_compact_processor;
19 
20 enum bstm_data_type
21 {
22   BSTM_ALPHA=0,
23   BSTM_CHANGE,
24   BSTM_MOG3_GREY,
25   BSTM_MOG3_GREY_16,
26   BSTM_MOG6_VIEW,
27   BSTM_NUM_OBS_VIEW,
28   BSTM_NUM_OBS_VIEW_COMPACT,
29   BSTM_MOG6_VIEW_COMPACT,
30   BSTM_GAUSS_RGB,
31   BSTM_GAUSS_RGB_VIEW,
32   BSTM_GAUSS_RGB_VIEW_COMPACT,
33   BSTM_NUM_OBS_SINGLE,
34   BSTM_NUM_OBS,
35   BSTM_LABEL,
36   BSTM_RAY_DIR,
37   BSTM_POINT,
38   BSTM_AUX0,
39   BSTM_AUX1,
40   BSTM_AUX2,
41   BSTM_AUX3,
42   BSTM_UNKNOWN
43 };
44 
45 // Pixel properties for templates.
46 template <bstm_data_type type>
47 class bstm_data_traits;
48 
49 template<>
50 class bstm_data_traits<BSTM_ALPHA>
51 {
52  public:
53   typedef float datatype;
datasize()54   static std::size_t datasize() { return sizeof(datatype); }
55   static std::string prefix(const std::string& identifier = "")
56   { if (!identifier.size()) return "alpha"; else return "alpha_"+identifier; }
57 };
58 
59 
60 template<>
61 class bstm_data_traits<BSTM_CHANGE>
62 {
63  public:
64   typedef float datatype;
datasize()65   static std::size_t datasize() { return sizeof(datatype); }
66   static std::string prefix(const std::string& identifier = "")
67   { if (!identifier.size()) return "bstm_change"; else return "bstm_change_"+identifier; }
68 };
69 
70 
71 template<>
72 class bstm_data_traits<BSTM_NUM_OBS>
73 {
74  public:
75   typedef vnl_vector_fixed<unsigned short, 4> datatype;
datasize()76   static std::size_t datasize() { return sizeof(datatype); }
77   static std::string prefix(const std::string& identifier = "")
78   { if (!identifier.size()) return "bstm_num_obs"; else return "bstm_num_obs_"+identifier; }
79 };
80 
81 template<>
82 class bstm_data_traits<BSTM_NUM_OBS_SINGLE>
83 {
84  public:
85   typedef unsigned short datatype;
datasize()86   static std::size_t datasize() { return sizeof(datatype); }
87   static std::string prefix(const std::string& identifier = "")
88   { if (!identifier.size()) return "bstm_num_obs_single"; else return "bstm_num_obs_single_"+identifier; }
89 };
90 
91 template<>
92 class bstm_data_traits<BSTM_GAUSS_RGB>
93 {
94  public:
95   typedef vnl_vector_fixed<unsigned char, 8> datatype;
datasize()96   static std::size_t datasize() { return sizeof(datatype); }
97   static std::string prefix(const std::string& identifier = "")
98   { if (!identifier.size()) return "bstm_gauss_rgb"; else return "bstm_gauss_rgb_"+identifier; }
99 };
100 
101 template<>
102 class bstm_data_traits<BSTM_GAUSS_RGB_VIEW>
103 {
104  public:
105   typedef boxm2_mog6_view_processor processor;
106   typedef vnl_vector_fixed<int, 16> datatype;
datasize()107   static std::size_t datasize() { return sizeof(datatype); }
108   static std::string prefix(const std::string& identifier = "")
109   { if (!identifier.size()) return "bstm_gauss_rgb_view"; else return "bstm_gauss_rgb_view_"+identifier; }
110 };
111 
112 template<>
113 class bstm_data_traits<BSTM_GAUSS_RGB_VIEW_COMPACT>
114 {
115  public:
116   typedef vnl_vector_fixed<int, 8> datatype;
datasize()117   static std::size_t datasize() { return sizeof(datatype); }
118   static std::string prefix(const std::string& identifier = "")
119   { if (!identifier.size()) return "bstm_gauss_rgb_view_compact"; else return "bstm_gauss_rgb_view_compact_"+identifier; }
120 };
121 
122 template<>
123 class bstm_data_traits<BSTM_MOG3_GREY>
124 {
125  public:
126   typedef boxm2_mog3_grey_processor processor;
127   typedef vnl_vector_fixed<unsigned char, 8> datatype;
datasize()128   static std::size_t datasize() { return sizeof(datatype); }
129   static std::string prefix(const std::string& identifier = "")
130   { if (!identifier.size()) return "bstm_mog3_grey"; else return "bstm_mog3_grey_"+identifier; }
131 };
132 
133 
134 template<>
135 class bstm_data_traits<BSTM_MOG6_VIEW>
136 {
137  public:
138   typedef boxm2_mog6_view_processor processor;
139   typedef vnl_vector_fixed<float, 16> datatype;
datasize()140   static std::size_t datasize() { return sizeof(datatype); }
141   static std::string prefix(const std::string& identifier = "")
142   { if (!identifier.size()) return "bstm_mog6_view"; else return "bstm_mog6_view_"+identifier; }
143 };
144 
145 
146 template<>
147 class bstm_data_traits<BSTM_MOG6_VIEW_COMPACT>
148 {
149  public:
150   typedef boxm2_mog6_view_compact_processor processor;
151   typedef vnl_vector_fixed<unsigned char, 16> datatype;
datasize()152   static std::size_t datasize() { return sizeof(datatype); }
153   static std::string prefix(const std::string& identifier = "")
154   { if (!identifier.size()) return "bstm_mog6_view_compact"; else return "bstm_mog6_view_compact_"+identifier; }
155 };
156 
157 
158 template<>
159 class bstm_data_traits<BSTM_NUM_OBS_VIEW>
160 {
161  public:
162   typedef vnl_vector_fixed<float, 8> datatype;
datasize()163   static std::size_t datasize() { return sizeof(datatype); }
164   static std::string prefix(const std::string& identifier = "")
165   { if (!identifier.size()) return "bstm_num_obs_view"; else return "bstm_num_obs_view"+identifier; }
166 };
167 
168 template<>
169 class bstm_data_traits<BSTM_NUM_OBS_VIEW_COMPACT>
170 {
171  public:
172   typedef vnl_vector_fixed<unsigned short, 8> datatype;
datasize()173   static std::size_t datasize() { return sizeof(datatype); }
174   static std::string prefix(const std::string& identifier = "")
175   { if (!identifier.size()) return "bstm_num_obs_view_compact"; else return "bstm_num_obs_view_compact"+identifier; }
176 };
177 
178 
179 template<>
180 class bstm_data_traits<BSTM_LABEL>
181 {
182  public:
183   typedef unsigned char datatype;
datasize()184   static std::size_t datasize() { return sizeof(datatype); }
185   static std::string prefix(const std::string& identifier = "")
186   { if (!identifier.size()) return "bstm_label"; else return "bstm_label_"+identifier; }
187 };
188 
189 template<>
190 class bstm_data_traits<BSTM_AUX0>
191 {
192  public:
193   typedef float datatype;
datasize()194   static std::size_t datasize() { return sizeof(datatype); }
195   static std::string prefix(const std::string& identifier = "")
196   { if (!identifier.size()) return "aux0"; else return "aux0_"+identifier; }
197 };
198 
199 template<>
200 class bstm_data_traits<BSTM_AUX1>
201 {
202  public:
203   typedef float datatype;
datasize()204   static std::size_t datasize() { return sizeof(datatype); }
205   static std::string prefix(const std::string& identifier = "")
206   { if (!identifier.size()) return "aux1"; else return "aux1_"+identifier; }
207 };
208 
209 template<>
210 class bstm_data_traits<BSTM_AUX2>
211 {
212  public:
213   typedef float datatype;
datasize()214   static std::size_t datasize() { return sizeof(datatype); }
215   static std::string prefix(const std::string& identifier = "")
216   { if (!identifier.size()) return "aux2"; else return "aux2_"+identifier; }
217 };
218 
219 template<>
220 class bstm_data_traits<BSTM_AUX3>
221 {
222  public:
223   typedef float datatype;
datasize()224   static std::size_t datasize() { return sizeof(datatype); }
225   static std::string prefix(const std::string& identifier = "")
226   { if (!identifier.size()) return "aux3"; else return "aux3_"+identifier; }
227 };
228 
229 
230 template<>
231 class bstm_data_traits<BSTM_RAY_DIR>
232 {
233  public:
234   typedef vnl_vector_fixed<float, 4> datatype;
datasize()235   static std::size_t datasize() { return sizeof(datatype); }
236   static std::string prefix(const std::string& identifier = "")
237   { if (!identifier.size()) return "bstm_ray_dir"; else return "bstm_ray_dir_"+identifier; }
238 };
239 
240 
241 template<>
242 class bstm_data_traits<BSTM_POINT>
243 {
244  public:
245   typedef vnl_vector_fixed<float, 4> datatype;
datasize()246   static std::size_t datasize() { return sizeof(datatype); }
247   static std::string prefix(const std::string& identifier = "")
248   { if (!identifier.size()) return "bstm_point"; else return "bstm_point_"+identifier; }
249 };
250 
251 
252 // HACKY WAY TO GENERICALLY GET DATASIZES -
253 class bstm_data_info
254 {
255  public:
256 
datasize(std::string prefix)257   static std::size_t datasize(std::string prefix)
258   {
259     // some of them changed to using find method to account for identifiers
260 
261     if (prefix.find(bstm_data_traits<BSTM_ALPHA>::prefix()) != std::string::npos)
262       return bstm_data_traits<BSTM_ALPHA>::datasize();
263     if (prefix.find(bstm_data_traits<BSTM_MOG3_GREY>::prefix()) != std::string::npos)
264       return bstm_data_traits<BSTM_MOG3_GREY>::datasize();
265     if (prefix.find(bstm_data_traits<BSTM_NUM_OBS_VIEW_COMPACT>::prefix()) != std::string::npos)
266       return bstm_data_traits<BSTM_NUM_OBS_VIEW_COMPACT>::datasize();
267     if (prefix.find(bstm_data_traits<BSTM_NUM_OBS_VIEW>::prefix()) != std::string::npos)
268       return bstm_data_traits<BSTM_NUM_OBS_VIEW>::datasize();
269     if (prefix.find(bstm_data_traits<BSTM_NUM_OBS_SINGLE>::prefix()) != std::string::npos)
270       return bstm_data_traits<BSTM_NUM_OBS_SINGLE>::datasize();
271     if (prefix.find(bstm_data_traits<BSTM_NUM_OBS>::prefix()) != std::string::npos)
272       return bstm_data_traits<BSTM_NUM_OBS>::datasize();
273     if (prefix.find(bstm_data_traits<BSTM_GAUSS_RGB_VIEW_COMPACT>::prefix()) != std::string::npos)
274       return bstm_data_traits<BSTM_GAUSS_RGB_VIEW_COMPACT>::datasize();
275     if (prefix.find(bstm_data_traits<BSTM_GAUSS_RGB>::prefix()) != std::string::npos)
276       return bstm_data_traits<BSTM_GAUSS_RGB>::datasize();
277     if (prefix.find(bstm_data_traits<BSTM_MOG6_VIEW_COMPACT>::prefix()) != std::string::npos)
278       return bstm_data_traits<BSTM_MOG6_VIEW_COMPACT>::datasize();
279     if (prefix.find(bstm_data_traits<BSTM_MOG6_VIEW>::prefix()) != std::string::npos)
280       return bstm_data_traits<BSTM_MOG6_VIEW>::datasize();
281     if (prefix.find(bstm_data_traits<BSTM_AUX0>::prefix()) != std::string::npos)
282       return bstm_data_traits<BSTM_AUX0>::datasize();
283     if (prefix.find(bstm_data_traits<BSTM_AUX1>::prefix()) != std::string::npos)
284       return bstm_data_traits<BSTM_AUX1>::datasize();
285     if (prefix.find(bstm_data_traits<BSTM_AUX2>::prefix()) != std::string::npos)
286       return bstm_data_traits<BSTM_AUX2>::datasize();
287     if (prefix.find(bstm_data_traits<BSTM_AUX3>::prefix()) != std::string::npos)
288       return bstm_data_traits<BSTM_AUX3>::datasize();
289     if (prefix.find(bstm_data_traits<BSTM_RAY_DIR>::prefix()) != std::string::npos)
290       return bstm_data_traits<BSTM_RAY_DIR>::datasize();
291     if (prefix.find(bstm_data_traits<BSTM_LABEL>::prefix()) != std::string::npos)
292       return bstm_data_traits<BSTM_LABEL>::datasize();
293     if (prefix.find(bstm_data_traits<BSTM_POINT>::prefix()) != std::string::npos)
294       return bstm_data_traits<BSTM_POINT>::datasize();
295     if (prefix.find(bstm_data_traits<BSTM_CHANGE>::prefix()) != std::string::npos)
296       return bstm_data_traits<BSTM_CHANGE>::datasize();
297     return 0;
298   }
299 
data_type(std::string prefix)300   static bstm_data_type data_type(std::string prefix)
301   {
302     // some of them changed to using find method to account for identifiers
303     if (prefix.find(bstm_data_traits<BSTM_ALPHA>::prefix()) != std::string::npos)
304       return BSTM_ALPHA ;
305     else if (prefix.find(bstm_data_traits<BSTM_MOG3_GREY>::prefix()) != std::string::npos)
306       return BSTM_MOG3_GREY ;
307     else if (prefix.find(bstm_data_traits<BSTM_NUM_OBS>::prefix()) != std::string::npos)
308       return  BSTM_NUM_OBS ;
309     else if (prefix.find(bstm_data_traits<BSTM_GAUSS_RGB>::prefix()) != std::string::npos)
310       return  BSTM_GAUSS_RGB ;
311     else if (prefix.find(bstm_data_traits<BSTM_LABEL>::prefix()) != std::string::npos)
312       return  BSTM_LABEL ;
313     else if (prefix.find(bstm_data_traits<BSTM_GAUSS_RGB_VIEW_COMPACT>::prefix()) != std::string::npos)
314       return  BSTM_GAUSS_RGB_VIEW_COMPACT ;
315     else if (prefix.find(bstm_data_traits<BSTM_MOG6_VIEW_COMPACT>::prefix()) != std::string::npos)
316       return  BSTM_MOG6_VIEW_COMPACT ;
317     else if (prefix.find(bstm_data_traits<BSTM_MOG6_VIEW>::prefix()) != std::string::npos)
318       return  BSTM_MOG6_VIEW ;
319     else
320       return BSTM_UNKNOWN;
321   }
322 };
323 
324 template <boxm2_data_type BOXM2_TYPE> struct boxm2_to_bstm_type;
325 
326 template <> struct boxm2_to_bstm_type<BOXM2_ALPHA> {
327   static const bstm_data_type bstm_type = BSTM_ALPHA;
328 };
329 template <> struct boxm2_to_bstm_type<BOXM2_MOG3_GREY> {
330   static const bstm_data_type bstm_type = BSTM_MOG3_GREY;
331 };
332 template <> struct boxm2_to_bstm_type<BOXM2_MOG3_GREY_16> {
333   static const bstm_data_type bstm_type = BSTM_MOG3_GREY_16;
334 };
335 template <> struct boxm2_to_bstm_type<BOXM2_MOG6_VIEW> {
336   static const bstm_data_type bstm_type = BSTM_MOG6_VIEW;
337 };
338 template <> struct boxm2_to_bstm_type<BOXM2_NUM_OBS_VIEW> {
339   static const bstm_data_type bstm_type = BSTM_NUM_OBS_VIEW;
340 };
341 template <> struct boxm2_to_bstm_type<BOXM2_NUM_OBS_VIEW_COMPACT> {
342   static const bstm_data_type bstm_type = BSTM_NUM_OBS_VIEW_COMPACT;
343 };
344 template <> struct boxm2_to_bstm_type<BOXM2_MOG6_VIEW_COMPACT> {
345   static const bstm_data_type bstm_type = BSTM_MOG6_VIEW_COMPACT;
346 };
347 template <> struct boxm2_to_bstm_type<BOXM2_GAUSS_RGB> {
348   static const bstm_data_type bstm_type = BSTM_GAUSS_RGB;
349 };
350 template <> struct boxm2_to_bstm_type<BOXM2_GAUSS_RGB_VIEW> {
351   static const bstm_data_type bstm_type = BSTM_GAUSS_RGB_VIEW;
352 };
353 template <> struct boxm2_to_bstm_type<BOXM2_GAUSS_RGB_VIEW_COMPACT> {
354   static const bstm_data_type bstm_type = BSTM_GAUSS_RGB_VIEW_COMPACT;
355 };
356 template <> struct boxm2_to_bstm_type<BOXM2_NUM_OBS_SINGLE> {
357   static const bstm_data_type bstm_type = BSTM_NUM_OBS_SINGLE;
358 };
359 template <> struct boxm2_to_bstm_type<BOXM2_NUM_OBS> {
360   static const bstm_data_type bstm_type = BSTM_NUM_OBS;
361 };
362 template <> struct boxm2_to_bstm_type<BOXM2_RAY_DIR> {
363   static const bstm_data_type bstm_type = BSTM_RAY_DIR;
364 };
365 template <> struct boxm2_to_bstm_type<BOXM2_POINT> {
366   static const bstm_data_type bstm_type = BSTM_POINT;
367 };
368 template <> struct boxm2_to_bstm_type<BOXM2_AUX0> {
369   static const bstm_data_type bstm_type = BSTM_AUX0;
370 };
371 template <> struct boxm2_to_bstm_type<BOXM2_AUX1> {
372   static const bstm_data_type bstm_type = BSTM_AUX1;
373 };
374 template <> struct boxm2_to_bstm_type<BOXM2_AUX2> {
375   static const bstm_data_type bstm_type = BSTM_AUX2;
376 };
377 template <> struct boxm2_to_bstm_type<BOXM2_AUX3> {
378   static const bstm_data_type bstm_type = BSTM_AUX3;
379 };
380 template <> struct boxm2_to_bstm_type<BOXM2_UNKNOWN> {
381   static const bstm_data_type bstm_type = BSTM_UNKNOWN;
382 };
383 
384 template <bstm_data_type BSTM_TYPE> struct bstm_to_boxm2_type;
385 
386 template <> struct bstm_to_boxm2_type<BSTM_ALPHA> {
387   static const boxm2_data_type boxm2_type = BOXM2_ALPHA;
388 };
389 template <> struct bstm_to_boxm2_type<BSTM_MOG3_GREY> {
390   static const boxm2_data_type boxm2_type = BOXM2_MOG3_GREY;
391 };
392 template <> struct bstm_to_boxm2_type<BSTM_MOG3_GREY_16> {
393   static const boxm2_data_type boxm2_type = BOXM2_MOG3_GREY_16;
394 };
395 template <> struct bstm_to_boxm2_type<BSTM_MOG6_VIEW> {
396   static const boxm2_data_type boxm2_type = BOXM2_MOG6_VIEW;
397 };
398 template <> struct bstm_to_boxm2_type<BSTM_NUM_OBS_VIEW> {
399   static const boxm2_data_type boxm2_type = BOXM2_NUM_OBS_VIEW;
400 };
401 template <> struct bstm_to_boxm2_type<BSTM_NUM_OBS_VIEW_COMPACT> {
402   static const boxm2_data_type boxm2_type = BOXM2_NUM_OBS_VIEW_COMPACT;
403 };
404 template <> struct bstm_to_boxm2_type<BSTM_MOG6_VIEW_COMPACT> {
405   static const boxm2_data_type boxm2_type = BOXM2_MOG6_VIEW_COMPACT;
406 };
407 template <> struct bstm_to_boxm2_type<BSTM_GAUSS_RGB> {
408   static const boxm2_data_type boxm2_type = BOXM2_GAUSS_RGB;
409 };
410 template <> struct bstm_to_boxm2_type<BSTM_GAUSS_RGB_VIEW> {
411   static const boxm2_data_type boxm2_type = BOXM2_GAUSS_RGB_VIEW;
412 };
413 template <> struct bstm_to_boxm2_type<BSTM_GAUSS_RGB_VIEW_COMPACT> {
414   static const boxm2_data_type boxm2_type = BOXM2_GAUSS_RGB_VIEW_COMPACT;
415 };
416 template <> struct bstm_to_boxm2_type<BSTM_NUM_OBS_SINGLE> {
417   static const boxm2_data_type boxm2_type = BOXM2_NUM_OBS_SINGLE;
418 };
419 template <> struct bstm_to_boxm2_type<BSTM_NUM_OBS> {
420   static const boxm2_data_type boxm2_type = BOXM2_NUM_OBS;
421 };
422 template <> struct bstm_to_boxm2_type<BSTM_RAY_DIR> {
423   static const boxm2_data_type boxm2_type = BOXM2_RAY_DIR;
424 };
425 template <> struct bstm_to_boxm2_type<BSTM_POINT> {
426   static const boxm2_data_type boxm2_type = BOXM2_POINT;
427 };
428 template <> struct bstm_to_boxm2_type<BSTM_AUX0> {
429   static const boxm2_data_type boxm2_type = BOXM2_AUX0;
430 };
431 template <> struct bstm_to_boxm2_type<BSTM_AUX1> {
432   static const boxm2_data_type boxm2_type = BOXM2_AUX1;
433 };
434 template <> struct bstm_to_boxm2_type<BSTM_AUX2> {
435   static const boxm2_data_type boxm2_type = BOXM2_AUX2;
436 };
437 template <> struct bstm_to_boxm2_type<BSTM_AUX3> {
438   static const boxm2_data_type boxm2_type = BOXM2_AUX3;
439 };
440 template <> struct bstm_to_boxm2_type<BSTM_UNKNOWN> {
441   static const boxm2_data_type boxm2_type = BOXM2_UNKNOWN;
442 };
443 
444 #endif
445