HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GU_NURBPyramid.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 library (C++)
7  *
8  * COMMENTS: NURB Pyramid classes.
9  *
10  */
11 
12 #ifndef __GU_NURBPyramid_h__
13 #define __GU_NURBPyramid_h__
14 
15 #include "GU_API.h"
16 #include <UT/UT_IntArray.h>
17 #include <UT/UT_RefMatrix.h>
18 #include <UT/UT_VectorTypes.h>
19 #include <UT/UT_Interval.h>
20 #include <GA/GA_Basis.h>
21 #include <GA/GA_PwHandle.h>
22 #include <GEO/GEO_Hull.h>
23 #include <GEO/GEO_Face.h>
24 
25 template <int Dir> // u = 0, v = 1
27 {
28 public:
30  : myCV(0)
31  , myHull(0)
32  , myFace(0) {}
34  : myCV(cv)
35  , myHull(0)
36  , myFace(0) {}
37  GU_CVMesh(const GEO_Hull *cv, const GA_PwHandleRO &h)
38  : myHull(cv)
39  , myCV(0)
40  , myFace(0)
41  , myHandle(h) {}
42  GU_CVMesh(const GEO_Face *cv, const GA_PwHandleRO &h)
43  : myFace(cv)
44  , myCV(0)
45  , myHull(0)
46  , myHandle(h) {}
47 
48  unsigned int rows() const
49  {
50  return Dir ? getCols() : getRows();
51  }
52  unsigned int cols() const
53  {
54  return Dir ? getRows() : getCols();
55  }
56  const UT_Vector4 getPos(int i, int j) const
57  {
58  return Dir ? get(j, i) : get(i, j);
59  }
60  void setPos(int i, int j, const UT_Vector4 &pos)
61  {
62  if (Dir)
63  set(j, i, pos);
64  else
65  set(i, j, pos);
66  }
67  void homogenize(int i, int j)
68  {
69  UT_Vector4 pos = getPos(i, j);
70  pos.homogenize();
71  setPos(i, j, pos);
72  }
73 
74 private:
75  const UT_Vector4 get(int i, int j) const
76  {
77  if (myCV)
78  return (*myCV)(i, j);
79  if (myHull)
80  return myHandle.get(myHull->getPointOffset(i, j));
81  return myHandle.get(myFace->getPointOffset(j));
82  }
83  void set(int i, int j, const UT_Vector4 &pos)
84  {
85  if (myCV)
86  (*myCV)(i, j) = pos;
87  else
88  UT_ASSERT(0 && "Read-only mesh");
89  }
90  int getRows() const
91  {
92  return myCV ? myCV->rows() :
93  (myHull ? myHull->getNumRows() : 1);
94  }
95  int getCols() const
96  {
97  return myCV ? myCV->cols() :
98  (myHull ? myHull->getNumCols() :
99  myFace->getVertexCount());
100  }
101 
102 private:
104  const GEO_Hull *myHull;
105  const GEO_Face *myFace;
106  GA_PwHandleRO myHandle;
107 };
108 
109 template <int Dir> // u = 0, v = 1
111 {
112 public:
114  {
115  }
116  GU_NURBPyramid(const GA_Basis *basis,
118  fpreal umin = 0, fpreal umax = -1)
119  {
120  // cv is not modified
121  myCV = GU_CVMesh<Dir>(cv);
122  myUMin = umin;
123  myUMax = umax;
124  if (myUMin > myUMax)
125  basis->getValidRange(myUMin, myUMax);
126  }
127 
128  template <typename T> // GEO_Hull or GEO_Face
129  GU_NURBPyramid(const GA_Basis *basis,
130  const T *cv, const GA_PwHandleRO &h,
131  fpreal umin = 0, fpreal umax = -1)
132  {
133  // cv is not modified
134  myCV = GU_CVMesh<Dir>(cv, h);
135  myUMin = umin;
136  myUMax = umax;
137  if (myUMin > myUMax)
138  basis->getValidRange(myUMin, myUMax);
139  }
140 
141  template <typename T> // GEO_Hull or GEO_Face
142  void init(const GA_Basis *basis,
143  const T *cv, const GA_PwHandleRO &h,
144  fpreal umin = 0, fpreal umax = -1)
145  {
146  // cv is not modified
147  myCV = GU_CVMesh<Dir>(cv, h);
148  myUMin = umin;
149  myUMax = umax;
150  if (myUMin > myUMax)
151  basis->getValidRange(myUMin, myUMax);
152  }
153 
154  void rewind(const GA_Basis *basis);
155  bool atEnd() { return SYSisEqual(myInterval.min, myUMax); }
156  void advance();
157 
158  // Return bezier hull data. Vectors are homogenized, so to get
159  // bounding information you will need to dehomogenize these positions.
160  UT_RefMatrix<UT_Vector4> &getResult() { return myResultData; }
161 
162  // Return the current parametric interval
163  const UT_Interval &getInterval() { return myInterval; }
164 
165 private:
166  void refine(fpreal u, int R, int newIdx);
167 
168  int myOrd, myDeg;
169  int myCVSize;
170  GA_KnotVector myKnots;
171  GU_CVMesh<Dir> myCV;
172  fpreal myUMin, myUMax;
173 
174  GU_CVMesh<Dir> myPyramid;
175  UT_RefMatrix<UT_Vector4> myPyramidData;
176  GU_CVMesh<Dir> myResult;
177  UT_RefMatrix<UT_Vector4> myResultData;
178 
179  // Iteration indices
180  UT_Interval myInterval; // Parametric interval
181  int myK; // Knot index
182  int myCVIdx; // CV index
183 };
184 
185 #endif
UT_RefMatrix< UT_Vector4 > & getResult()
void init(const GA_Basis *basis, const T *cv, const GA_PwHandleRO &h, fpreal umin=0, fpreal umax=-1)
GU_CVMesh(const GEO_Face *cv, const GA_PwHandleRO &h)
unsigned int rows() const
GU_CVMesh(const GEO_Hull *cv, const GA_PwHandleRO &h)
const UT_Vector4 getPos(int i, int j) const
png_uint_32 i
Definition: png.h:2877
GU_NURBPyramid(const GA_Basis *basis, UT_RefMatrix< UT_Vector4 > *cv, fpreal umin=0, fpreal umax=-1)
unsigned int cols() const
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:102
Bezier or NURBS basis classes which maintain knot vectors.
Definition: GA_Basis.h:49
void setPos(int i, int j, const UT_Vector4 &pos)
#define GU_API
Definition: GU_API.h:11
void homogenize(int i, int j)
const UT_Interval & getInterval()
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
double fpreal
Definition: SYS_Types.h:269
void homogenize(void)
Express the point in homogeneous coordinates or vice-versa.
Definition: UT_Vector4.h:411
GU_NURBPyramid(const GA_Basis *basis, const T *cv, const GA_PwHandleRO &h, fpreal umin=0, fpreal umax=-1)
GU_CVMesh(UT_RefMatrix< UT_Vector4 > *cv)
bool getValidRange(fpreal &a, fpreal &b) const
Get the boundaries of the valid range of evaluation.