HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_NSidedSubdivPatch.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GU_NSidedSubdivPatch.h (GU Library, C++)
7  *
8  * COMMENTS: This class is based off the subdivision scheme detailed in the
9  * following paper:
10  * Filling an N-sided hole using subdivision schemes, Adi Levin
11  *
12  * Note that this is different from GU_SubDivPatch, this takes some extra work
13  * to ensure that the sides of the hole are smooth with the surface surrounding
14  * the hole. An example of it's use can be seen in GU_PolyBevel.C in
15  * BlendPositioner::positionPointsCubicSubdiv().
16  */
17 
18 
19 #ifndef __GU_NSidedSubdivPatch_h__
20 #define __GU_NSidedSubdivPatch_h__
21 
22 #include "GU_API.h"
23 
24 #include <UT/UT_Vector.h>
25 #include <array>
26 
27 template <typename T>
29 {
30 public:
31  using Real = T;
33 
34  GU_NSidedSubdivPatchT() = default;
35 
36  explicit GU_NSidedSubdivPatchT(int sides, int divs = 1) :
37  mySides(sides), myDivs(divs) { setupMesh(); }
38 
39 
41  int divs() const { return myDivs; }
42 
44  int sides() const { return mySides; }
45 
47  const
48  UT_Vector3T<T> &pos(int m, int i, int j) const
49  { return myPoints(pointIndex(m, i, j)); }
50 
52  UT_Vector3T<T> &pos(int m, int i, int j)
53  { return myPoints(pointIndex(m, i, j)); }
54 
55  void subdivide(const Patch &src);
56  UT_Vector3T<T> interpolate(int m, T u, T v);
57 
58 private:
59  using PosArray = UT_Array< UT_Vector3T<T> >;
60 
61  void setupMesh();
62 
64  int pointIndex(int m, int i, int j) const;
65 
66 
67  int myDivs = 1;
68  int mySides = 0;
69  int myMeshSize = 0;
70  fpreal myMeshUnit = 1.0;
71  PosArray myPoints;
72 };
73 
74 
75 template<typename T>
76 int
77 GU_NSidedSubdivPatchT<T>::pointIndex(int m, int i, int j) const
78 {
79  // The point with coordinates (myDivs, myDivs) is shared between all
80  // corner meshes.
81  if (i == myDivs && j == myDivs)
82  return int(myPoints.size()) - 1;
83 
84  // Either of i or j (both *not* both) can have values greater than
85  // myDivs (but less than 2 * myDivs).
86  UT_ASSERT_P(i < myDivs || j < myDivs);
87 
88  if (i > myDivs)
89  {
90  m = (m + mySides - 1) % mySides;
91  auto tmp = i;
92  i = j;
93  j = 2 * myDivs - tmp;
94  }
95 
96  if (j >= myDivs)
97  {
98  m = (m + 1) % mySides;
99  auto tmp = i;
100  i = 2 * myDivs - j;
101  j = tmp;
102  }
103 
104  return myMeshSize * m + myDivs * i + j;
105 }
106 
107 
108 template <typename S>
110 interpolatePatch(const S &s, int m, typename S::Real u, typename S::Real v);
111 
112 
117 
118 #endif
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
const GLdouble * v
Definition: glcorearb.h:837
GLdouble s
Definition: glad.h:3009
SYS_FORCE_INLINE int sides() const
3D Vector class.
GU_NSidedSubdivPatchT(int sides, int divs=1)
SYS_FORCE_INLINE const UT_Vector3T< T > & pos(int m, int i, int j) const
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
SYS_FORCE_INLINE UT_Vector3T< T > & pos(int m, int i, int j)
#define GU_API
Definition: GU_API.h:14
IMATH_HOSTDEVICE constexpr int divs(int x, int y) IMATH_NOEXCEPT
Definition: ImathFun.h:140
GLint j
Definition: glad.h:2733
fpreal64 fpreal
Definition: SYS_Types.h:277
UT_Vector3T< UT_Vector3T< typename S::Real > > interpolatePatch(const S &s, int m, typename S::Real u, typename S::Real v)
SYS_FORCE_INLINE int divs() const
GU_NSidedSubdivPatchT< fpreal32 > GU_NSidedSubdivPatchF
GLenum src
Definition: glcorearb.h:1793