Frame.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. /*
  2. * TI Voxel Lib component.
  3. *
  4. * Copyright (c) 2014 Texas Instruments Inc.
  5. */
  6. #ifndef VOXEL_FRAME_H
  7. #define VOXEL_FRAME_H
  8. #include <Common.h>
  9. #include <Point.h>
  10. #include "VideoMode.h"
  11. #include "SerializedObject.h"
  12. #include <sstream>
  13. namespace Voxel
  14. {
  15. /**
  16. * \defgroup Frm Frame related classes
  17. * @{
  18. */
  19. class VOXEL_EXPORT Frame
  20. {
  21. public:
  22. TimeStampType timestamp = 0; // Unix timestamp in micro-seconds
  23. int id = -1;
  24. inline operator String()
  25. {
  26. std::ostringstream s;
  27. s << id << "@" << timestamp;
  28. return s.str();
  29. }
  30. virtual Ptr<Frame> copy() const = 0;
  31. virtual Ptr<Frame> copyTo(Ptr<Frame> &other) const = 0;
  32. virtual Ptr<Frame> newFrame() const = 0;
  33. virtual bool isSameType(const Frame &other) const = 0;
  34. virtual bool isSameSize(const Frame &other) const = 0;
  35. virtual bool serialize(SerializedObject &object) const = 0;
  36. virtual bool deserialize(SerializedObject &object) = 0;
  37. virtual ~Frame() {}
  38. };
  39. typedef Ptr<Frame> FramePtr;
  40. class VOXEL_EXPORT DepthFrame: public Frame
  41. {
  42. public:
  43. Vector<float> depth; // depth frame row-wise. Unit: meters
  44. Vector<float> amplitude; // amplitude of each depth pixel normalized to value between 0 and 1
  45. FrameSize size;
  46. virtual Ptr<Frame> copy() const
  47. {
  48. Ptr<Frame> f(new DepthFrame());
  49. return copyTo(f);
  50. }
  51. virtual Ptr<Frame> copyTo(Ptr<Frame> &other) const
  52. {
  53. if(!other || !isSameType(*other))
  54. other = Ptr<Frame>(new DepthFrame());
  55. DepthFrame *d = dynamic_cast<DepthFrame *>(other.get());
  56. d->id = id;
  57. d->timestamp = timestamp;
  58. d->depth = depth;
  59. d->amplitude = amplitude;
  60. d->size = size;
  61. return other;
  62. }
  63. virtual bool serialize(SerializedObject &object) const
  64. {
  65. size_t s = sizeof(id) + sizeof(timestamp) + depth.size()*sizeof(float)*2 + sizeof(size_t)*2;
  66. object.resize(s);
  67. object.put((const char *)&id, sizeof(id));
  68. object.put((const char *)&timestamp, sizeof(timestamp));
  69. object.put((const char *)&size.width, sizeof(size.width));
  70. object.put((const char *)&size.height, sizeof(size.height));
  71. object.put((const char *)depth.data(), sizeof(float)*depth.size());
  72. object.put((const char *)amplitude.data(), sizeof(float)*amplitude.size());
  73. return true;
  74. }
  75. virtual bool deserialize(SerializedObject &object)
  76. {
  77. if(!object.get((char *)&id, sizeof(id)) ||
  78. !object.get((char *)&timestamp, sizeof(timestamp)) ||
  79. !object.get((char *)&size.width, sizeof(size.width)) ||
  80. !object.get((char *)&size.height, sizeof(size.height)))
  81. return false;
  82. depth.resize(size.width*size.height);
  83. amplitude.resize(size.width*size.height);
  84. if(!object.get((char *)depth.data(), sizeof(float)*depth.size()) ||
  85. !object.get((char *)amplitude.data(), sizeof(float)*amplitude.size()))
  86. return false;
  87. return true;
  88. }
  89. virtual bool isSameType(const Frame &other) const
  90. {
  91. const DepthFrame *f = dynamic_cast<const DepthFrame *>(&other);
  92. return f;
  93. }
  94. virtual bool isSameSize(const Frame &other) const
  95. {
  96. const DepthFrame *f = dynamic_cast<const DepthFrame *>(&other);
  97. return (f && size == f->size);
  98. }
  99. virtual Ptr<Frame> newFrame() const
  100. {
  101. DepthFrame *d = new DepthFrame();
  102. d->depth.resize(depth.size());
  103. d->amplitude.resize(amplitude.size());
  104. d->size = size;
  105. return FramePtr(d);
  106. }
  107. static Ptr<DepthFrame> typeCast(FramePtr ptr)
  108. {
  109. return std::dynamic_pointer_cast<DepthFrame>(ptr);
  110. }
  111. virtual ~DepthFrame() {}
  112. };
  113. typedef Ptr<DepthFrame> DepthFramePtr;
  114. class VOXEL_EXPORT RawFrame: public Frame
  115. {
  116. public:
  117. static Ptr<RawFrame> typeCast(FramePtr ptr)
  118. {
  119. return std::dynamic_pointer_cast<RawFrame>(ptr);
  120. }
  121. virtual ~RawFrame() {}
  122. };
  123. typedef Ptr<RawFrame> RawFramePtr;
  124. enum ToFFrameType {
  125. ToF_PHASE_AMPLITUDE,
  126. ToF_I_Q,
  127. ToF_QUAD
  128. };
  129. class VOXEL_EXPORT ToFRawFrame : public RawFrame
  130. {
  131. public:
  132. virtual const uint8_t *phase() const = 0;
  133. virtual uint8_t *phase() = 0;
  134. virtual SizeType phaseWordWidth() const = 0; // in bytes
  135. virtual const uint8_t *amplitude() const = 0;
  136. virtual uint8_t *amplitude() = 0;
  137. virtual SizeType amplitudeWordWidth() const = 0; // in bytes
  138. virtual const uint8_t *flags() const = 0;
  139. virtual uint8_t *flags() = 0;
  140. virtual SizeType flagsWordWidth() const = 0; // in bytes
  141. virtual const uint8_t *ambient() const = 0;
  142. virtual uint8_t *ambient() = 0;
  143. virtual SizeType ambientWordWidth() const = 0; // in bytes
  144. virtual const uint16_t *histogram() const = 0;
  145. virtual uint16_t *histogram() = 0;
  146. virtual SizeType histogramSize() const = 0; // number of elements in the histogram
  147. FrameSize size;
  148. static Ptr<ToFRawFrame> typeCast(FramePtr ptr)
  149. {
  150. return std::dynamic_pointer_cast<ToFRawFrame>(ptr);
  151. }
  152. virtual ~ToFRawFrame() {}
  153. };
  154. typedef Ptr<ToFRawFrame> ToFRawFramePtr;
  155. template <typename PhaseByteType, typename AmbientByteType>
  156. class ToFRawFrameTemplate : public ToFRawFrame
  157. {
  158. public:
  159. typedef PhaseByteType AmplitudeByteType;
  160. typedef AmbientByteType FlagsByteType;
  161. Vector<PhaseByteType> _phase;
  162. Vector<AmplitudeByteType> _amplitude;
  163. Vector<AmbientByteType> _ambient;
  164. Vector<FlagsByteType> _flags;
  165. Vector<uint16_t> _histogram;
  166. virtual const uint8_t *ambient() const
  167. {
  168. return (const uint8_t *)_ambient.data();
  169. }
  170. virtual uint8_t *ambient()
  171. {
  172. return (uint8_t *)_ambient.data();
  173. }
  174. virtual SizeType ambientWordWidth() const
  175. {
  176. return sizeof(AmbientByteType);
  177. }
  178. virtual const uint8_t *amplitude() const
  179. {
  180. return (const uint8_t *)_amplitude.data();
  181. }
  182. virtual uint8_t *amplitude()
  183. {
  184. return (uint8_t *)_amplitude.data();
  185. }
  186. virtual SizeType amplitudeWordWidth() const
  187. {
  188. return sizeof(AmplitudeByteType);
  189. }
  190. virtual const uint8_t *phase() const
  191. {
  192. return (const uint8_t *)_phase.data();
  193. }
  194. virtual uint8_t *phase()
  195. {
  196. return (uint8_t *)_phase.data();
  197. }
  198. virtual SizeType phaseWordWidth() const
  199. {
  200. return sizeof(PhaseByteType);
  201. }
  202. virtual const uint8_t *flags() const
  203. {
  204. return (const uint8_t *)_flags.data();
  205. }
  206. virtual uint8_t *flags()
  207. {
  208. return (uint8_t *)_flags.data();
  209. }
  210. virtual SizeType flagsWordWidth() const
  211. {
  212. return sizeof(FlagsByteType);
  213. }
  214. virtual const uint16_t *histogram() const
  215. {
  216. return _histogram.data();
  217. }
  218. virtual uint16_t *histogram()
  219. {
  220. return _histogram.data();
  221. }
  222. virtual SizeType histogramSize() const
  223. {
  224. return _histogram.size();
  225. }
  226. virtual Ptr<Frame> copy() const
  227. {
  228. Ptr<Frame> f(new ToFRawFrameTemplate<PhaseByteType, AmbientByteType>());
  229. return copyTo(f);
  230. }
  231. virtual Ptr<Frame> copyTo(Ptr<Frame> &other) const
  232. {
  233. if(!other || !isSameType(*other))
  234. other = Ptr<Frame>(new ToFRawFrameTemplate<PhaseByteType, AmbientByteType>());
  235. auto *t = dynamic_cast<ToFRawFrameTemplate<PhaseByteType, AmbientByteType> *>(other.get());
  236. t->id = id;
  237. t->timestamp = timestamp;
  238. t->_phase = _phase;
  239. t->_amplitude = _amplitude;
  240. t->_ambient = _ambient;
  241. t->_flags = _flags;
  242. t->_histogram = _histogram;
  243. t->size = size;
  244. return other;
  245. }
  246. virtual Ptr<Frame> newFrame() const
  247. {
  248. ToFRawFrameTemplate<PhaseByteType, AmbientByteType> *t = new ToFRawFrameTemplate<PhaseByteType, AmbientByteType>();
  249. t->_phase.resize(_phase.size());
  250. t->_amplitude.resize(_amplitude.size());
  251. t->_ambient.resize(_ambient.size());
  252. t->_flags.resize(_flags.size());
  253. t->_histogram.resize(_histogram.size());
  254. t->size = size;
  255. return FramePtr(t);
  256. }
  257. virtual bool isSameType(const Frame &other) const
  258. {
  259. const ToFRawFrameTemplate<PhaseByteType, AmbientByteType> *f = dynamic_cast<const ToFRawFrameTemplate<PhaseByteType, AmbientByteType> *>(&other);
  260. return f;
  261. }
  262. static Ptr<ToFRawFrameTemplate<PhaseByteType, AmbientByteType>> typeCast(FramePtr ptr)
  263. {
  264. return std::dynamic_pointer_cast<ToFRawFrameTemplate<PhaseByteType, AmbientByteType>>(ptr);
  265. }
  266. virtual bool isSameSize(const Frame &other) const
  267. {
  268. const ToFRawFrameTemplate<PhaseByteType, AmbientByteType> *f = dynamic_cast<const ToFRawFrameTemplate<PhaseByteType, AmbientByteType> *>(&other);
  269. return (f && size == f->size);
  270. }
  271. virtual bool serialize(SerializedObject &object) const
  272. {
  273. size_t s = sizeof(id) + sizeof(timestamp) +
  274. _phase.size()*sizeof(PhaseByteType) +
  275. _amplitude.size()*sizeof(AmplitudeByteType) +
  276. _ambient.size()*sizeof(AmbientByteType) +
  277. _flags.size()*sizeof(FlagsByteType) +
  278. _histogram.size()*sizeof(uint16_t) +
  279. sizeof(size_t)*2;
  280. object.resize(s);
  281. object.put((const char *)&id, sizeof(id));
  282. object.put((const char *)&timestamp, sizeof(timestamp));
  283. size_t histogramSize = _histogram.size();
  284. object.put((const char *)&size.width, sizeof(size.width));
  285. object.put((const char *)&size.height, sizeof(size.height));
  286. object.put((const char *)&histogramSize, sizeof(histogramSize));
  287. object.put((const char *)_phase.data(), sizeof(PhaseByteType)*_phase.size());
  288. object.put((const char *)_amplitude.data(), sizeof(AmplitudeByteType)*_amplitude.size());
  289. object.put((const char *)_ambient.data(), sizeof(AmbientByteType)*_ambient.size());
  290. object.put((const char *)_flags.data(), sizeof(FlagsByteType)*_flags.size());
  291. if(histogramSize)
  292. object.put((const char *)_histogram.data(), sizeof(uint16_t)*_histogram.size());
  293. return true;
  294. }
  295. virtual bool deserialize(SerializedObject &object)
  296. {
  297. object.get((char *)&id, sizeof(id));
  298. object.get((char *)&timestamp, sizeof(timestamp));
  299. size_t histogramSize;
  300. object.get((char *)&size.width, sizeof(size.width));
  301. object.get((char *)&size.height, sizeof(size.height));
  302. object.get((char *)&histogramSize, sizeof(histogramSize));
  303. unsigned int frameSize = size.width*size.height;
  304. _phase.resize(frameSize);
  305. _amplitude.resize(frameSize);
  306. _ambient.resize(frameSize);
  307. _flags.resize(frameSize);
  308. object.get((char *)_phase.data(), sizeof(PhaseByteType)*_phase.size());
  309. object.get((char *)_amplitude.data(), sizeof(AmplitudeByteType)*_amplitude.size());
  310. object.get((char *)_ambient.data(), sizeof(AmbientByteType)*_ambient.size());
  311. object.get((char *)_flags.data(), sizeof(FlagsByteType)*_flags.size());
  312. if(histogramSize)
  313. {
  314. _histogram.resize(histogramSize);
  315. object.get((char *)_histogram.data(), sizeof(uint16_t)*_histogram.size());
  316. }
  317. else
  318. _histogram.clear();
  319. return true;
  320. }
  321. virtual ~ToFRawFrameTemplate() {}
  322. };
  323. class VOXEL_EXPORT ToFRawIQFrame: public RawFrame
  324. {
  325. public:
  326. virtual const uint8_t *i() const = 0;
  327. virtual uint8_t *i() = 0;
  328. virtual const uint8_t *q() const = 0;
  329. virtual uint8_t *q() = 0;
  330. virtual SizeType wordWidth() const = 0; // in bytes
  331. FrameSize size;
  332. static Ptr<ToFRawIQFrame> typeCast(FramePtr ptr)
  333. {
  334. return std::dynamic_pointer_cast<ToFRawIQFrame>(ptr);
  335. }
  336. virtual ~ToFRawIQFrame() {}
  337. };
  338. typedef Ptr<ToFRawIQFrame> ToFRawIQFramePtr;
  339. template <typename ByteType>
  340. class ToFRawIQFrameTemplate : public ToFRawIQFrame
  341. {
  342. public:
  343. Vector<ByteType> _i;
  344. Vector<ByteType> _q;
  345. virtual const uint8_t *i() const
  346. {
  347. return (const uint8_t *)_i.data();
  348. }
  349. virtual uint8_t *i()
  350. {
  351. return (uint8_t *)_i.data();
  352. }
  353. virtual const uint8_t *q() const
  354. {
  355. return (const uint8_t *)_q.data();
  356. }
  357. virtual uint8_t *q()
  358. {
  359. return (uint8_t *)_q.data();
  360. }
  361. virtual SizeType wordWidth() const
  362. {
  363. return sizeof(ByteType);
  364. }
  365. virtual Ptr<Frame> copy() const
  366. {
  367. Ptr<Frame> f(new ToFRawIQFrameTemplate<ByteType>());
  368. return copyTo(f);
  369. }
  370. virtual Ptr<Frame> copyTo(Ptr<Frame> &other) const
  371. {
  372. if(!other || !isSameType(*other))
  373. other = Ptr<Frame>(new ToFRawIQFrameTemplate<ByteType>());
  374. auto *t = dynamic_cast<ToFRawIQFrameTemplate<ByteType> *>(other.get());
  375. t->id = id;
  376. t->timestamp = timestamp;
  377. t->_i = _i;
  378. t->_q = _q;
  379. t->size = size;
  380. return other;
  381. }
  382. virtual Ptr<Frame> newFrame() const
  383. {
  384. ToFRawIQFrameTemplate<ByteType> *t = new ToFRawIQFrameTemplate<ByteType>();
  385. t->_i.resize(_i.size());
  386. t->_q.resize(_q.size());
  387. t->size = size;
  388. return FramePtr(t);
  389. }
  390. virtual bool isSameType(const Frame &other) const
  391. {
  392. const ToFRawIQFrameTemplate<ByteType> *f = dynamic_cast<const ToFRawIQFrameTemplate<ByteType> *>(&other);
  393. return f;
  394. }
  395. static Ptr<ToFRawIQFrameTemplate<ByteType>> typeCast(FramePtr ptr)
  396. {
  397. return std::dynamic_pointer_cast<ToFRawIQFrameTemplate<ByteType>>(ptr);
  398. }
  399. virtual bool isSameSize(const Frame &other) const
  400. {
  401. const ToFRawIQFrameTemplate<ByteType> *f = dynamic_cast<const ToFRawIQFrameTemplate<ByteType> *>(&other);
  402. return (f && size == f->size);
  403. }
  404. virtual bool serialize(SerializedObject &object) const
  405. {
  406. size_t s = sizeof(id) + sizeof(timestamp) +
  407. _i.size()*sizeof(ByteType) +
  408. _q.size()*sizeof(ByteType) +
  409. sizeof(uint32_t)*2;
  410. object.resize(s);
  411. object.put((const char *)&id, sizeof(id));
  412. object.put((const char *)&timestamp, sizeof(timestamp));
  413. uint32_t x;
  414. x = sizeof(ByteType);
  415. object.put((const char *)&x, sizeof(x));
  416. x = size.width;
  417. object.put((const char *)&x, sizeof(x));
  418. x = size.height;
  419. object.put((const char *)&x, sizeof(x));
  420. object.put((const char *)_i.data(), sizeof(ByteType)*_i.size());
  421. object.put((const char *)_q.data(), sizeof(ByteType)*_q.size());
  422. return true;
  423. }
  424. virtual bool deserialize(SerializedObject &object)
  425. {
  426. object.get((char *)&id, sizeof(id));
  427. object.get((char *)&timestamp, sizeof(timestamp));
  428. uint32_t x;
  429. object.get((char *)&x, sizeof(x));
  430. if(x != sizeof(ByteType))
  431. return false;
  432. object.get((char *)&x, sizeof(x));
  433. size.width = x;
  434. object.get((char *)&x, sizeof(x));
  435. size.height = x;
  436. _i.resize(size.width*size.height);
  437. _q.resize(size.width*size.height);
  438. object.get((char *)_i.data(), sizeof(ByteType)*_i.size());
  439. object.get((char *)_q.data(), sizeof(ByteType)*_q.size());
  440. return true;
  441. }
  442. virtual ~ToFRawIQFrameTemplate() {}
  443. };
  444. class VOXEL_EXPORT RawDataFrame : public RawFrame
  445. {
  446. public:
  447. Vector<ByteType> data;
  448. virtual Ptr<Frame> copy() const
  449. {
  450. Ptr<Frame> f(new RawDataFrame());
  451. return copyTo(f);
  452. }
  453. virtual Ptr<Frame> copyTo(Ptr<Frame> &other) const
  454. {
  455. if(!other || !isSameType(*other))
  456. other = Ptr<Frame>(new RawDataFrame());
  457. auto *r = dynamic_cast<RawDataFrame *>(other.get());
  458. r->id = id;
  459. r->timestamp = timestamp;
  460. r->data = data;
  461. return other;
  462. }
  463. virtual Ptr<Frame> newFrame() const
  464. {
  465. RawDataFrame *r = new RawDataFrame();
  466. r->data.resize(data.size());
  467. return FramePtr(r);
  468. }
  469. virtual bool isSameType(const Frame &other) const
  470. {
  471. const RawDataFrame *f = dynamic_cast<const RawDataFrame *>(&other);
  472. return f;
  473. }
  474. virtual bool isSameSize(const Frame &other) const
  475. {
  476. const RawDataFrame *f = dynamic_cast<const RawDataFrame *>(&other);
  477. return f && data.size() == f->data.size();
  478. }
  479. static Ptr<RawDataFrame> typeCast(FramePtr ptr)
  480. {
  481. return std::dynamic_pointer_cast<RawDataFrame>(ptr);
  482. }
  483. virtual bool serialize(SerializedObject &object) const
  484. {
  485. size_t s = sizeof(id) + sizeof(timestamp) + data.size()*sizeof(ByteType) + sizeof(size_t);
  486. object.resize(s);
  487. object.put((const char *)&id, sizeof(id));
  488. object.put((const char *)&timestamp, sizeof(timestamp));
  489. s = data.size();
  490. object.put((const char *)&s, sizeof(s));
  491. object.put((const char *)data.data(), sizeof(ByteType)*data.size());
  492. return true;
  493. }
  494. virtual bool deserialize(SerializedObject &object)
  495. {
  496. /** size_t is 4 in arm and 8 in x86. So used uint64_t**/
  497. uint64_t s;
  498. if(!object.get((char *)&id, sizeof(id)) ||
  499. !object.get((char *)&timestamp, sizeof(timestamp)) ||
  500. !object.get((char *)&s, sizeof(s)))
  501. return false;
  502. data.resize(s);
  503. return object.get((char *)data.data(), sizeof(ByteType)*data.size());
  504. }
  505. virtual ~RawDataFrame() {}
  506. };
  507. typedef Ptr<RawDataFrame> RawDataFramePtr;
  508. class VOXEL_EXPORT PointCloudFrame : public Frame
  509. {
  510. public:
  511. virtual SizeType size() const = 0;
  512. virtual Point *operator [](IndexType index) = 0;
  513. static Ptr<PointCloudFrame> typeCast(FramePtr ptr)
  514. {
  515. return std::dynamic_pointer_cast<PointCloudFrame>(ptr);
  516. }
  517. virtual ~PointCloudFrame() {}
  518. };
  519. typedef Ptr<PointCloudFrame> PointCloudFramePtr;
  520. template <typename PointType>
  521. class PointCloudFrameTemplate : public PointCloudFrame
  522. {
  523. public:
  524. Vector<PointType> points;
  525. virtual SizeType size() const
  526. {
  527. return points.size();
  528. }
  529. virtual Point *operator[] (IndexType index)
  530. {
  531. if(index < points.size() && index >= 0)
  532. return &points[index];
  533. else
  534. return 0;
  535. }
  536. virtual Ptr<Frame> copy() const
  537. {
  538. Ptr<Frame> f(new PointCloudFrameTemplate<PointType>());
  539. return copyTo(f);
  540. }
  541. virtual Ptr<Frame> copyTo(Ptr<Frame> &other) const
  542. {
  543. if(!other || !isSameType(*other))
  544. other = Ptr<Frame>(new PointCloudFrameTemplate<PointType>());
  545. auto *p = dynamic_cast<PointCloudFrameTemplate<PointType> *>(other.get());
  546. p->id = id;
  547. p->timestamp = timestamp;
  548. p->points = points;
  549. return other;
  550. }
  551. virtual Ptr<Frame> newFrame() const
  552. {
  553. PointCloudFrameTemplate<PointType> *p = new PointCloudFrameTemplate<PointType>();
  554. p->points.resize(points.size());
  555. return FramePtr(p);
  556. }
  557. virtual bool isSameType(const Frame &other) const
  558. {
  559. const PointCloudFrameTemplate<PointType> *f = dynamic_cast<const PointCloudFrameTemplate<PointType> *>(&other);
  560. return f;
  561. }
  562. virtual bool isSameSize(const Frame &other) const
  563. {
  564. const PointCloudFrameTemplate<PointType> *f = dynamic_cast<const PointCloudFrameTemplate<PointType> *>(&other);
  565. return f && f->size() == size();
  566. }
  567. virtual bool serialize(SerializedObject &object) const
  568. {
  569. size_t s = sizeof(id) + sizeof(timestamp) + points.size()*sizeof(PointType) + sizeof(size_t);
  570. object.resize(s);
  571. object.put((const char *)&id, sizeof(id));
  572. object.put((const char *)&timestamp, sizeof(timestamp));
  573. s = points.size();
  574. object.put((const char *)&s, sizeof(s));
  575. object.put((const char *)points.data(), sizeof(PointType)*points.size());
  576. return true;
  577. }
  578. virtual bool deserialize(SerializedObject &object)
  579. {
  580. object.get((char *)&id, sizeof(id));
  581. object.get((char *)&timestamp, sizeof(timestamp));
  582. size_t s;
  583. object.get((char *)&s, sizeof(s));
  584. points.resize(s);
  585. object.get((char *)points.data(), sizeof(ByteType)*points.size());
  586. return true;
  587. }
  588. static Ptr<PointCloudFrameTemplate<PointType>> typeCast(FramePtr ptr)
  589. {
  590. return std::dynamic_pointer_cast<PointCloudFrameTemplate<PointType>>(ptr);
  591. }
  592. virtual ~PointCloudFrameTemplate() {}
  593. };
  594. typedef PointCloudFrameTemplate<Point> XYZPointCloudFrame;
  595. typedef PointCloudFrameTemplate<IntensityPoint> XYZIPointCloudFrame;
  596. typedef Ptr<XYZPointCloudFrame> XYZPointCloudFramePtr;
  597. /**
  598. * @}
  599. */
  600. }
  601. #endif // VOXEL_POINT_H