You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
4.2 KiB

13 years ago
13 years ago
  1. //----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2004-2018 by EMGU Corporation. All rights reserved.
  4. //
  5. //----------------------------------------------------------------------------
  6. #pragma once
  7. #ifndef EMGU_POINT_UTIL_H
  8. #define EMGU_POINT_UTIL_H
  9. #include "opencv2/core/core.hpp"
  10. #include "sse.h"
  11. /**
  12. * @fn inline float cvPoint3D32fDotProduct(const CvPoint3D32f* p1, const CvPoint3D32f* p2)
  13. *
  14. * @brief Compute the dot product of two 3D vector
  15. *
  16. * @author Canming Huang
  17. * @date 8/31/2010
  18. *
  19. * @param p1 The first const CvPoint3D32f*.
  20. * @param p2 The second const CvPoint3D32f*.
  21. *
  22. * @return The dot product of two 3D vector
  23. **/
  24. inline float cvPoint3D32fDotProduct(const CvPoint3D32f* p1, const CvPoint3D32f* p2)
  25. {
  26. /*
  27. #if EMGU_SSE
  28. __m128 ps1 = _mm_set_ps(p1->x, p1->y, p1->z, 0);
  29. __m128 ps2 = _mm_set_ps(p2->x, p2->y, p2->z, 0);
  30. __m128 product = _mm_mul_ps(ps1, ps2);
  31. return product.m128_f32[3] + product.m128_f32[2] + product.m128_f32[1];
  32. #else*/
  33. return p1->x * p2->x + p1->y * p2->y + p1->z * p2->z;
  34. //#endif
  35. };
  36. /**
  37. * @fn inline double cvPoint3D64fDotProduct(const CvPoint3D64f* p1, const CvPoint3D64f* p2)
  38. *
  39. * @brief Compute the dot product of two 3D vector
  40. *
  41. * @author Canming Huang
  42. * @date 8/31/2010
  43. *
  44. * @param p1 The first const CvPoint3D64f*.
  45. * @param p2 The second const CvPoint3D64f*.
  46. *
  47. * @return The dot product of two 3D vector
  48. **/
  49. inline double cvPoint3D64fDotProduct(const CvPoint3D64f* p1, const CvPoint3D64f* p2)
  50. {
  51. #if EMGU_SSE2
  52. double tmp;
  53. _mm_store_sd(&tmp, _dot_product(_mm_loadu_pd(&p1->x), _mm_loadu_pd(&p2->x)));
  54. return tmp + p1->z * p2->z;
  55. #else
  56. return p1->x * p2->x + p1->y * p2->y + p1->z * p2->z;
  57. #endif
  58. };
  59. /**
  60. * @fn inline void cvPoint3D64fCrossProduct(const CvPoint3D64f* p1, const CvPoint3D64f* p2,
  61. * CvPoint3D64f* crossProduct)
  62. *
  63. * @brief Compute the cross product of two 3D vector
  64. *
  65. * @author Canming Huang
  66. * @date 8/31/2010
  67. *
  68. * @param p1 The first const CvPoint3D64f*.
  69. * @param p2 The second const CvPoint3D64f*.
  70. * @param [in, out] crossProduct If non-null, the cross product.
  71. **/
  72. inline void cvPoint3D64fCrossProduct(const CvPoint3D64f* p1, const CvPoint3D64f* p2, CvPoint3D64f* crossProduct)
  73. {
  74. #if EMGU_SSE2
  75. _mm_store_sd(&crossProduct->x, _cross_product(_mm_loadu_pd(&p1->y), _mm_loadu_pd(&p2->y)));
  76. _mm_store_sd(&crossProduct->y, _cross_product(_mm_set_pd(p1->x, p1->z), _mm_set_pd(p2->x, p2->z)));
  77. _mm_store_sd(&crossProduct->z, _cross_product(_mm_loadu_pd(&p1->x), _mm_loadu_pd(&p2->x)));
  78. #else
  79. crossProduct->x = p1->y * p2->z - p1->z * p2->y;
  80. crossProduct->y = p1->z * p2->x - p1->x * p2->z;
  81. crossProduct->z = p1->x * p2->y - p1->y * p2->x;
  82. #endif
  83. };
  84. inline void cvPoint3D64fSub(const CvPoint3D64f* p1, const CvPoint3D64f* p2, CvPoint3D64f* result)
  85. {
  86. #if EMGU_SSE2
  87. _mm_storeu_pd((double*)result, _mm_sub_pd(_mm_loadu_pd((const double*) p1), _mm_loadu_pd((const double*) p2)));
  88. #else
  89. result->x = p1->x - p2->x;
  90. result->y = p1->y - p2->y;
  91. #endif
  92. result->z = p1->z - p2->z;
  93. }
  94. inline void cvPoint3D64fAdd(const CvPoint3D64f* p1, const CvPoint3D64f* p2, CvPoint3D64f* result)
  95. {
  96. #if EMGU_SSE2
  97. _mm_storeu_pd((double*)result, _mm_add_pd(_mm_loadu_pd((const double*) p1), _mm_loadu_pd((const double*) p2)));
  98. #else
  99. result->x = p1->x + p2->x;
  100. result->y = p1->y + p2->y;
  101. #endif
  102. result->z = p1->z + p2->z;
  103. }
  104. inline void cvPoint3D64fMul(const CvPoint3D64f* p1, double scale, CvPoint3D64f* result)
  105. {
  106. #if EMGU_SSE2
  107. _mm_storeu_pd((double*)result, _mm_mul_pd(_mm_loadu_pd((const double*) p1), _mm_set1_pd(scale)));
  108. #else
  109. result->x = p1->x * scale;
  110. result->y = p1->y * scale;
  111. #endif
  112. result->z = p1->z * scale;
  113. }
  114. /**
  115. * @fn inline bool cvPoint3D64Equals(const CvPoint3D64f* p1, const CvPoint3D64f* p2)
  116. *
  117. * @brief Check if the two point equals.
  118. *
  119. * @author Canming Huang
  120. * @date 9/01/2010
  121. *
  122. * @param p1 The first CvPoint3D64f.
  123. * @param p2 The second CvPoint3D64f.
  124. *
  125. * @return true if the two point equals, false otherwise.
  126. **/
  127. inline bool cvPoint3D64Equals(const CvPoint3D64f* p1, const CvPoint3D64f* p2)
  128. {
  129. return memcmp(p1, p2, sizeof(CvPoint3D64f)) == 0;
  130. }
  131. #endif