Canny-EVT
A library for ***
Loading...
Searching...
No Matches
utility.h
1#ifndef CannyEVT_UTILITY_H
2#define CannyEVT_UTILITY_H
3
4#include <eigen3/Eigen/Dense>
5#include <cmath>
6#include <opencv2/opencv.hpp>
7#include <cassert>
8#include <cstring>
9#include "TimeSurface.h"
10#include "type.h"
11#include "EventCamera.h"
12// #include "CamBasedProblemLM.h"
13// #include "Optimizer.h"
14
15namespace CannyEVT
16{
17
18
19namespace Utility
20{
21
22 void DrawTs(TimeSurface::Ptr TsPtr, pCloud cloud, Eigen::Matrix4d Twc, EventCamera::Ptr eventCam,
23 std::string name);
24
25 Eigen::Matrix3d cayley2rot(const Eigen::Vector3d &cayley);
26
27 Eigen::Vector3d rot2cayley(const Eigen::Matrix3d &R);
28
29 template <typename Derived>
30 static Eigen::Quaternion<typename Derived::Scalar> positify(const Eigen::QuaternionBase<Derived> &q)
31 {
32 //printf("a: %f %f %f %f", q.w(), q.x(), q.y(), q.z());
33 //Eigen::Quaternion<typename Derived::Scalar> p(-q.w(), -q.x(), -q.y(), -q.z());
34 //printf("b: %f %f %f %f", p.w(), p.x(), p.y(), p.z());
35 //return q.template w() >= (typename Derived::Scalar)(0.0) ? q : Eigen::Quaternion<typename Derived::Scalar>(-q.w(), -q.x(), -q.y(), -q.z());
36 return q;
37 }
38
39 template <typename Derived>
40 static Eigen::Matrix<typename Derived::Scalar, 3, 3> skewSymmetric(const Eigen::MatrixBase<Derived> &q)
41 {
42 Eigen::Matrix<typename Derived::Scalar, 3, 3> ans;
43 ans << typename Derived::Scalar(0), -q(2), q(1),
44 q(2), typename Derived::Scalar(0), -q(0),
45 -q(1), q(0), typename Derived::Scalar(0);
46 return ans;
47 }
48
49 template <typename Derived>
50 static Eigen::Quaternion<typename Derived::Scalar> deltaQ(const Eigen::MatrixBase<Derived> &theta)
51 {
52 typedef typename Derived::Scalar Scalar_t;
53
54 Eigen::Quaternion<Scalar_t> dq;
55 Eigen::Matrix<Scalar_t, 3, 1> half_theta = theta;
56 half_theta /= static_cast<Scalar_t>(2.0);
57 dq.w() = static_cast<Scalar_t>(1.0);
58 dq.x() = half_theta.x();
59 dq.y() = half_theta.y();
60 dq.z() = half_theta.z();
61 return dq;
62 }
63
64 template <typename Derived>
65 static Eigen::Matrix<typename Derived::Scalar, 4, 4> Qleft(const Eigen::QuaternionBase<Derived> &q)
66 {
67 Eigen::Quaternion<typename Derived::Scalar> qq = positify(q);
68 Eigen::Matrix<typename Derived::Scalar, 4, 4> ans;
69 ans(0, 0) = qq.w(), ans.template block<1, 3>(0, 1) = -qq.vec().transpose();
70 ans.template block<3, 1>(1, 0) = qq.vec(), ans.template block<3, 3>(1, 1) = qq.w() * Eigen::Matrix<typename Derived::Scalar, 3, 3>::Identity() + skewSymmetric(qq.vec());
71 return ans;
72 }
73
74 template <typename Derived>
75 static Eigen::Matrix<typename Derived::Scalar, 4, 4> Qright(const Eigen::QuaternionBase<Derived> &p)
76 {
77 Eigen::Quaternion<typename Derived::Scalar> pp = positify(p);
78 Eigen::Matrix<typename Derived::Scalar, 4, 4> ans;
79 ans(0, 0) = pp.w(), ans.template block<1, 3>(0, 1) = -pp.vec().transpose();
80 ans.template block<3, 1>(1, 0) = pp.vec(), ans.template block<3, 3>(1, 1) = pp.w() * Eigen::Matrix<typename Derived::Scalar, 3, 3>::Identity() - skewSymmetric(pp.vec());
81 return ans;
82 }
83
84// //回头直接复制到optimizer
85// void visulization(TimeSurface::Ptr TsPtr, CamBasedProblemLM::Ptr CamBasedProblemLMPtr, EventCamera::Ptr eventCam);
86
87 void DrawPoint(double val, double maxRange, double minRange, const Eigen::Vector2d &location, cv::Mat &img);
88
89 // the rgb values for a jet colormap with 256 values
90// static const float r[];
91// static const float g[];
92// static const float b[];
93
94 // the rgb values for a jet colormap with 256 values
95static const float r[] = {0,
96 0,
97 0,
98 0,
99 0,
100 0,
101 0,
102 0,
103 0,
104 0,
105 0,
106 0,
107 0,
108 0,
109 0,
110 0,
111 0,
112 0,
113 0,
114 0,
115 0,
116 0,
117 0,
118 0,
119 0,
120 0,
121 0,
122 0,
123 0,
124 0,
125 0,
126 0,
127 0,
128 0,
129 0,
130 0,
131 0,
132 0,
133 0,
134 0,
135 0,
136 0,
137 0,
138 0,
139 0,
140 0,
141 0,
142 0,
143 0,
144 0,
145 0,
146 0,
147 0,
148 0,
149 0,
150 0,
151 0,
152 0,
153 0,
154 0,
155 0,
156 0,
157 0,
158 0,
159 0,
160 0,
161 0,
162 0,
163 0,
164 0,
165 0,
166 0,
167 0,
168 0,
169 0,
170 0,
171 0,
172 0,
173 0,
174 0,
175 0,
176 0,
177 0,
178 0,
179 0,
180 0,
181 0,
182 0,
183 0,
184 0,
185 0,
186 0,
187 0,
188 0,
189 0,
190 0,
191 0.00588235294117645,
192 0.02156862745098032,
193 0.03725490196078418,
194 0.05294117647058827,
195 0.06862745098039214,
196 0.084313725490196,
197 0.1000000000000001,
198 0.115686274509804,
199 0.1313725490196078,
200 0.1470588235294117,
201 0.1627450980392156,
202 0.1784313725490196,
203 0.1941176470588235,
204 0.2098039215686274,
205 0.2254901960784315,
206 0.2411764705882353,
207 0.2568627450980392,
208 0.2725490196078431,
209 0.2882352941176469,
210 0.303921568627451,
211 0.3196078431372549,
212 0.3352941176470587,
213 0.3509803921568628,
214 0.3666666666666667,
215 0.3823529411764706,
216 0.3980392156862744,
217 0.4137254901960783,
218 0.4294117647058824,
219 0.4450980392156862,
220 0.4607843137254901,
221 0.4764705882352942,
222 0.4921568627450981,
223 0.5078431372549019,
224 0.5235294117647058,
225 0.5392156862745097,
226 0.5549019607843135,
227 0.5705882352941174,
228 0.5862745098039217,
229 0.6019607843137256,
230 0.6176470588235294,
231 0.6333333333333333,
232 0.6490196078431372,
233 0.664705882352941,
234 0.6803921568627449,
235 0.6960784313725492,
236 0.7117647058823531,
237 0.7274509803921569,
238 0.7431372549019608,
239 0.7588235294117647,
240 0.7745098039215685,
241 0.7901960784313724,
242 0.8058823529411763,
243 0.8215686274509801,
244 0.8372549019607844,
245 0.8529411764705883,
246 0.8686274509803922,
247 0.884313725490196,
248 0.8999999999999999,
249 0.9156862745098038,
250 0.9313725490196076,
251 0.947058823529412,
252 0.9627450980392158,
253 0.9784313725490197,
254 0.9941176470588236,
255 1,
256 1,
257 1,
258 1,
259 1,
260 1,
261 1,
262 1,
263 1,
264 1,
265 1,
266 1,
267 1,
268 1,
269 1,
270 1,
271 1,
272 1,
273 1,
274 1,
275 1,
276 1,
277 1,
278 1,
279 1,
280 1,
281 1,
282 1,
283 1,
284 1,
285 1,
286 1,
287 1,
288 1,
289 1,
290 1,
291 1,
292 1,
293 1,
294 1,
295 1,
296 1,
297 1,
298 1,
299 1,
300 1,
301 1,
302 1,
303 1,
304 1,
305 1,
306 1,
307 1,
308 1,
309 1,
310 1,
311 1,
312 1,
313 1,
314 1,
315 1,
316 1,
317 1,
318 1,
319 0.9862745098039216,
320 0.9705882352941178,
321 0.9549019607843139,
322 0.93921568627451,
323 0.9235294117647062,
324 0.9078431372549018,
325 0.892156862745098,
326 0.8764705882352941,
327 0.8607843137254902,
328 0.8450980392156864,
329 0.8294117647058825,
330 0.8137254901960786,
331 0.7980392156862743,
332 0.7823529411764705,
333 0.7666666666666666,
334 0.7509803921568627,
335 0.7352941176470589,
336 0.719607843137255,
337 0.7039215686274511,
338 0.6882352941176473,
339 0.6725490196078434,
340 0.6568627450980391,
341 0.6411764705882352,
342 0.6254901960784314,
343 0.6098039215686275,
344 0.5941176470588236,
345 0.5784313725490198,
346 0.5627450980392159,
347 0.5470588235294116,
348 0.5313725490196077,
349 0.5156862745098039,
350 0.5};
351static const float g[] = {0,
352 0,
353 0,
354 0,
355 0,
356 0,
357 0,
358 0,
359 0,
360 0,
361 0,
362 0,
363 0,
364 0,
365 0,
366 0,
367 0,
368 0,
369 0,
370 0,
371 0,
372 0,
373 0,
374 0,
375 0,
376 0,
377 0,
378 0,
379 0,
380 0,
381 0,
382 0,
383 0.001960784313725483,
384 0.01764705882352935,
385 0.03333333333333333,
386 0.0490196078431373,
387 0.06470588235294117,
388 0.08039215686274503,
389 0.09607843137254901,
390 0.111764705882353,
391 0.1274509803921569,
392 0.1431372549019607,
393 0.1588235294117647,
394 0.1745098039215687,
395 0.1901960784313725,
396 0.2058823529411764,
397 0.2215686274509804,
398 0.2372549019607844,
399 0.2529411764705882,
400 0.2686274509803921,
401 0.2843137254901961,
402 0.3,
403 0.3156862745098039,
404 0.3313725490196078,
405 0.3470588235294118,
406 0.3627450980392157,
407 0.3784313725490196,
408 0.3941176470588235,
409 0.4098039215686274,
410 0.4254901960784314,
411 0.4411764705882353,
412 0.4568627450980391,
413 0.4725490196078431,
414 0.4882352941176471,
415 0.503921568627451,
416 0.5196078431372548,
417 0.5352941176470587,
418 0.5509803921568628,
419 0.5666666666666667,
420 0.5823529411764705,
421 0.5980392156862746,
422 0.6137254901960785,
423 0.6294117647058823,
424 0.6450980392156862,
425 0.6607843137254901,
426 0.6764705882352942,
427 0.692156862745098,
428 0.7078431372549019,
429 0.723529411764706,
430 0.7392156862745098,
431 0.7549019607843137,
432 0.7705882352941176,
433 0.7862745098039214,
434 0.8019607843137255,
435 0.8176470588235294,
436 0.8333333333333333,
437 0.8490196078431373,
438 0.8647058823529412,
439 0.8803921568627451,
440 0.8960784313725489,
441 0.9117647058823528,
442 0.9274509803921569,
443 0.9431372549019608,
444 0.9588235294117646,
445 0.9745098039215687,
446 0.9901960784313726,
447 1,
448 1,
449 1,
450 1,
451 1,
452 1,
453 1,
454 1,
455 1,
456 1,
457 1,
458 1,
459 1,
460 1,
461 1,
462 1,
463 1,
464 1,
465 1,
466 1,
467 1,
468 1,
469 1,
470 1,
471 1,
472 1,
473 1,
474 1,
475 1,
476 1,
477 1,
478 1,
479 1,
480 1,
481 1,
482 1,
483 1,
484 1,
485 1,
486 1,
487 1,
488 1,
489 1,
490 1,
491 1,
492 1,
493 1,
494 1,
495 1,
496 1,
497 1,
498 1,
499 1,
500 1,
501 1,
502 1,
503 1,
504 1,
505 1,
506 1,
507 1,
508 1,
509 1,
510 1,
511 0.9901960784313726,
512 0.9745098039215687,
513 0.9588235294117649,
514 0.943137254901961,
515 0.9274509803921571,
516 0.9117647058823528,
517 0.8960784313725489,
518 0.8803921568627451,
519 0.8647058823529412,
520 0.8490196078431373,
521 0.8333333333333335,
522 0.8176470588235296,
523 0.8019607843137253,
524 0.7862745098039214,
525 0.7705882352941176,
526 0.7549019607843137,
527 0.7392156862745098,
528 0.723529411764706,
529 0.7078431372549021,
530 0.6921568627450982,
531 0.6764705882352944,
532 0.6607843137254901,
533 0.6450980392156862,
534 0.6294117647058823,
535 0.6137254901960785,
536 0.5980392156862746,
537 0.5823529411764707,
538 0.5666666666666669,
539 0.5509803921568626,
540 0.5352941176470587,
541 0.5196078431372548,
542 0.503921568627451,
543 0.4882352941176471,
544 0.4725490196078432,
545 0.4568627450980394,
546 0.4411764705882355,
547 0.4254901960784316,
548 0.4098039215686273,
549 0.3941176470588235,
550 0.3784313725490196,
551 0.3627450980392157,
552 0.3470588235294119,
553 0.331372549019608,
554 0.3156862745098041,
555 0.2999999999999998,
556 0.284313725490196,
557 0.2686274509803921,
558 0.2529411764705882,
559 0.2372549019607844,
560 0.2215686274509805,
561 0.2058823529411766,
562 0.1901960784313728,
563 0.1745098039215689,
564 0.1588235294117646,
565 0.1431372549019607,
566 0.1274509803921569,
567 0.111764705882353,
568 0.09607843137254912,
569 0.08039215686274526,
570 0.06470588235294139,
571 0.04901960784313708,
572 0.03333333333333321,
573 0.01764705882352935,
574 0.001960784313725483,
575 0,
576 0,
577 0,
578 0,
579 0,
580 0,
581 0,
582 0,
583 0,
584 0,
585 0,
586 0,
587 0,
588 0,
589 0,
590 0,
591 0,
592 0,
593 0,
594 0,
595 0,
596 0,
597 0,
598 0,
599 0,
600 0,
601 0,
602 0,
603 0,
604 0,
605 0,
606 0};
607const float b[] = {0.5,
608 0.5156862745098039,
609 0.5313725490196078,
610 0.5470588235294118,
611 0.5627450980392157,
612 0.5784313725490196,
613 0.5941176470588235,
614 0.6098039215686275,
615 0.6254901960784314,
616 0.6411764705882352,
617 0.6568627450980392,
618 0.6725490196078432,
619 0.6882352941176471,
620 0.7039215686274509,
621 0.7196078431372549,
622 0.7352941176470589,
623 0.7509803921568627,
624 0.7666666666666666,
625 0.7823529411764706,
626 0.7980392156862746,
627 0.8137254901960784,
628 0.8294117647058823,
629 0.8450980392156863,
630 0.8607843137254902,
631 0.8764705882352941,
632 0.892156862745098,
633 0.907843137254902,
634 0.9235294117647059,
635 0.9392156862745098,
636 0.9549019607843137,
637 0.9705882352941176,
638 0.9862745098039216,
639 1,
640 1,
641 1,
642 1,
643 1,
644 1,
645 1,
646 1,
647 1,
648 1,
649 1,
650 1,
651 1,
652 1,
653 1,
654 1,
655 1,
656 1,
657 1,
658 1,
659 1,
660 1,
661 1,
662 1,
663 1,
664 1,
665 1,
666 1,
667 1,
668 1,
669 1,
670 1,
671 1,
672 1,
673 1,
674 1,
675 1,
676 1,
677 1,
678 1,
679 1,
680 1,
681 1,
682 1,
683 1,
684 1,
685 1,
686 1,
687 1,
688 1,
689 1,
690 1,
691 1,
692 1,
693 1,
694 1,
695 1,
696 1,
697 1,
698 1,
699 1,
700 1,
701 1,
702 1,
703 0.9941176470588236,
704 0.9784313725490197,
705 0.9627450980392158,
706 0.9470588235294117,
707 0.9313725490196079,
708 0.915686274509804,
709 0.8999999999999999,
710 0.884313725490196,
711 0.8686274509803922,
712 0.8529411764705883,
713 0.8372549019607844,
714 0.8215686274509804,
715 0.8058823529411765,
716 0.7901960784313726,
717 0.7745098039215685,
718 0.7588235294117647,
719 0.7431372549019608,
720 0.7274509803921569,
721 0.7117647058823531,
722 0.696078431372549,
723 0.6803921568627451,
724 0.6647058823529413,
725 0.6490196078431372,
726 0.6333333333333333,
727 0.6176470588235294,
728 0.6019607843137256,
729 0.5862745098039217,
730 0.5705882352941176,
731 0.5549019607843138,
732 0.5392156862745099,
733 0.5235294117647058,
734 0.5078431372549019,
735 0.4921568627450981,
736 0.4764705882352942,
737 0.4607843137254903,
738 0.4450980392156865,
739 0.4294117647058826,
740 0.4137254901960783,
741 0.3980392156862744,
742 0.3823529411764706,
743 0.3666666666666667,
744 0.3509803921568628,
745 0.335294117647059,
746 0.3196078431372551,
747 0.3039215686274508,
748 0.2882352941176469,
749 0.2725490196078431,
750 0.2568627450980392,
751 0.2411764705882353,
752 0.2254901960784315,
753 0.2098039215686276,
754 0.1941176470588237,
755 0.1784313725490199,
756 0.1627450980392156,
757 0.1470588235294117,
758 0.1313725490196078,
759 0.115686274509804,
760 0.1000000000000001,
761 0.08431372549019622,
762 0.06862745098039236,
763 0.05294117647058805,
764 0.03725490196078418,
765 0.02156862745098032,
766 0.00588235294117645,
767 0,
768 0,
769 0,
770 0,
771 0,
772 0,
773 0,
774 0,
775 0,
776 0,
777 0,
778 0,
779 0,
780 0,
781 0,
782 0,
783 0,
784 0,
785 0,
786 0,
787 0,
788 0,
789 0,
790 0,
791 0,
792 0,
793 0,
794 0,
795 0,
796 0,
797 0,
798 0,
799 0,
800 0,
801 0,
802 0,
803 0,
804 0,
805 0,
806 0,
807 0,
808 0,
809 0,
810 0,
811 0,
812 0,
813 0,
814 0,
815 0,
816 0,
817 0,
818 0,
819 0,
820 0,
821 0,
822 0,
823 0,
824 0,
825 0,
826 0,
827 0,
828 0,
829 0,
830 0,
831 0,
832 0,
833 0,
834 0,
835 0,
836 0,
837 0,
838 0,
839 0,
840 0,
841 0,
842 0,
843 0,
844 0,
845 0,
846 0,
847 0,
848 0,
849 0,
850 0,
851 0,
852 0,
853 0,
854 0,
855 0,
856 0,
857 0,
858 0,
859 0,
860 0,
861 0,
862 0};
863
864
865};
866
867}
868
869#endif