catmullclark_coefficients.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "../common/geometry.h"
  5. namespace embree
  6. {
  7. static const size_t MAX_PATCH_VALENCE = 16; //!< maximum number of vertices of a patch
  8. static const size_t MAX_RING_FACE_VALENCE = 64; //!< maximum number of faces per ring
  9. static const size_t MAX_RING_EDGE_VALENCE = 2*64; //!< maximum number of edges per ring
  10. class CatmullClarkPrecomputedCoefficients
  11. {
  12. private:
  13. float table_cos_2PI_div_n[MAX_RING_FACE_VALENCE+1];
  14. float* table_limittangent_a[MAX_RING_FACE_VALENCE+1];
  15. float* table_limittangent_b[MAX_RING_FACE_VALENCE+1];
  16. float table_limittangent_c[MAX_RING_FACE_VALENCE+1];
  17. __forceinline float set_cos_2PI_div_n(const size_t n) {
  18. if (unlikely(n == 0)) return 1.0f;
  19. return cosf(2.0f*float(pi)/(float)n);
  20. }
  21. __forceinline float set_limittangent_a(const size_t i, const size_t n)
  22. {
  23. if (unlikely(n == 0)) return 1.0f;
  24. const float c0 = 1.0f/(float)n * 1.0f / sqrtf(4.0f + cosf(float(pi)/(float)n)*cosf(float(pi)/(float)n));
  25. const float c1 = (1.0f/(float)n + cosf(float(pi)/(float)n) * c0);
  26. return cosf(2.0f*float(pi)*(float)i/(float)n) * c1;
  27. }
  28. __forceinline float set_limittangent_b(const size_t i, const size_t n)
  29. {
  30. if (unlikely(n == 0)) return 1.0f;
  31. const float c0 = 1.0f/(float)n * 1.0f / sqrtf(4.0f + cosf(float(pi)/(float)n)*cosf(float(pi)/(float)n));
  32. return cosf((2.0f*float(pi)*i+float(pi))/(float)n) * c0;
  33. }
  34. __forceinline float set_limittangent_c(const size_t n)
  35. {
  36. if (unlikely(n == 0)) return 1.0f;
  37. return 2.0f/16.0f * (5.0f + cosf(2.0f*float(pi)/(float)n) + cosf(float(pi)/(float)n) * sqrtf(18.0f+2.0f*cosf(2.0f*float(pi)/(float)n)));
  38. }
  39. public:
  40. __forceinline float cos_2PI_div_n(const size_t n)
  41. {
  42. if (likely(n <= MAX_RING_FACE_VALENCE))
  43. return table_cos_2PI_div_n[n];
  44. else
  45. return set_cos_2PI_div_n(n);
  46. }
  47. __forceinline float limittangent_a(const size_t i, const size_t n)
  48. {
  49. assert(n <= MAX_RING_FACE_VALENCE);
  50. assert(i < n);
  51. return table_limittangent_a[n][i];
  52. }
  53. __forceinline float limittangent_b(const size_t i, const size_t n)
  54. {
  55. assert(n <= MAX_RING_FACE_VALENCE);
  56. assert(i < n);
  57. return table_limittangent_b[n][i];
  58. }
  59. __forceinline float limittangent_c(const size_t n)
  60. {
  61. assert(n <= MAX_RING_FACE_VALENCE);
  62. return table_limittangent_c[n];
  63. }
  64. static CatmullClarkPrecomputedCoefficients table;
  65. CatmullClarkPrecomputedCoefficients();
  66. ~CatmullClarkPrecomputedCoefficients();
  67. };
  68. }