Point.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * TI Voxel Lib component.
  3. *
  4. * Copyright (c) 2014 Texas Instruments Inc.
  5. */
  6. #ifndef VOXEL_POINT_H
  7. #define VOXEL_POINT_H
  8. #define _USE_MATH_DEFINES
  9. #include <math.h>
  10. #include <type_traits>
  11. #include "Common.h"
  12. namespace Voxel
  13. {
  14. /**
  15. * \addtogroup Frm
  16. * @{
  17. */
  18. class Point
  19. {
  20. public:
  21. float x, y, z; // in meters
  22. Point(): x(0), y(0), z(0) {}
  23. Point(float x, float y): x(x), y(y), z(0) {}
  24. Point(float x, float y, float z): x(x), y(y), z(z) {}
  25. inline float angle(const Point &other) const;
  26. inline float norm() const;
  27. inline float dot(const Point &other) const;
  28. inline Point cross(const Point &other) const;
  29. inline Point &operator -();
  30. inline Point operator +(const Point &other) const;
  31. inline Point operator *(const Point &other) const;
  32. inline Point operator *(const float &other) const;
  33. };
  34. float Point::dot(const Point &other) const
  35. {
  36. return (x*other.x + y*other.y + z*other.z);
  37. }
  38. Point Point::cross(const Point &other) const
  39. {
  40. Point p;
  41. p.x = y*other.z - z*other.y;
  42. p.y = z*other.x - x*other.z;
  43. p.z = x*other.y - y*other.x;
  44. return p;
  45. }
  46. float Point::angle(const Point &other) const
  47. {
  48. float n1 = norm(), n2 = other.norm();
  49. if(floatEquals(n1, 0) || floatEquals(n2, 0))
  50. return 0;
  51. return acos(dot(other)/n1/n2);
  52. }
  53. float Point::norm() const
  54. {
  55. return sqrt(x*x + y*y + z*z);
  56. }
  57. inline Point &Point::operator -()
  58. {
  59. x = -x;
  60. y = -y;
  61. z = -z;
  62. return *this;
  63. }
  64. Point Point::operator*(const Point &other) const
  65. {
  66. return Point(x*other.x, y*other.y, z*other.z);
  67. }
  68. Point Point::operator*(const float &other) const
  69. {
  70. return Point(x*other, y*other, z*other);
  71. }
  72. Point Point::operator +(const Point &other) const
  73. {
  74. return Point(x + other.x, y + other.y, z + other.z);
  75. }
  76. class IntensityPoint: public Point
  77. {
  78. public:
  79. float i; // normalized 0-1
  80. static IntensityPoint *typeCast(Point *ptr)
  81. {
  82. return (IntensityPoint *)(ptr);
  83. }
  84. };
  85. class RGBPoint: public Point
  86. {
  87. public:
  88. float r, g, b; // normalized 0-1
  89. static RGBPoint *typeCast(Point *ptr)
  90. {
  91. return (RGBPoint *)(ptr);
  92. }
  93. };
  94. class Orientation // in radial co-ordinates
  95. {
  96. public:
  97. float theta, phi; // in radians
  98. };
  99. /**
  100. * @}
  101. */
  102. }
  103. #endif // VOXEL_POINT_H