GteRectanglePatchMesh.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.4 (2016/08/29)
7 
8 #pragma once
9 
10 #include <Mathematics/GteMesh.h>
12 #include <memory>
13 
14 namespace gte
15 {
16 
17 template <typename Real>
18 class RectanglePatchMesh : public Mesh<Real>
19 {
20 public:
21  // Create a mesh (x(u,v),y(u,v),z(u,v)) defined by the specified surface.
22  // It is required that surface->IsRectangular() return 'true'.
23  RectanglePatchMesh(MeshDescription const& description,
24  std::shared_ptr<ParametricSurface<3, Real>> const& surface);
25 
26  // Member access.
27  inline std::shared_ptr<ParametricSurface<3, Real>> const& GetSurface() const;
28 
29 protected:
30  void InitializeTCoords();
31  void InitializePositions();
32  void InitializeNormals();
33  void InitializeFrame();
34  virtual void UpdatePositions() override;
35  virtual void UpdateNormals() override;
36  virtual void UpdateFrame() override;
37 
38  std::shared_ptr<ParametricSurface<3, Real>> mSurface;
39 
40  // If the client does not request texture coordinates, they will be
41  // computed internally for use in evaluation of the surface geometry.
42  std::vector<Vector2<Real>> mDefaultTCoords;
43 };
44 
45 
46 template <typename Real>
48  std::shared_ptr<ParametricSurface<3, Real>> const& surface)
49  :
50  Mesh<Real>(description, { MeshTopology::RECTANGLE }),
51  mSurface(surface)
52 {
53  if (!this->mDescription.constructed)
54  {
55  // The logger system will report these errors in the Mesh constructor.
56  mSurface = nullptr;
57  return;
58  }
59 
60  if (!mSurface || !mSurface->IsRectangular())
61  {
62  LogError("A nonnull rectangular surface is required.");
63  mSurface = nullptr;
64  this->mDescription.constructed = false;
65  return;
66  }
67 
68  if (!this->mTCoords)
69  {
71  this->mTCoords = mDefaultTCoords.data();
72  this->mTCoordStride = sizeof(Vector2<Real>);
73 
76  {
78  {
79  this->mDescription.allowUpdateFrame = false;
80  }
81 
82  if (!this->mNormals)
83  {
84  this->mDescription.allowUpdateFrame = false;
85  }
86  }
87  }
88 
89  this->ComputeIndices();
93  {
95  }
96  else if (this->mNormals)
97  {
99  }
100 }
101 
102 template <typename Real>
103 inline std::shared_ptr<ParametricSurface<3, Real>> const&
105 {
106  return mSurface;
107 }
108 
109 template <typename Real>
111 {
112  Real uMin = mSurface->GetUMin();
113  Real uDelta = (mSurface->GetUMax() - uMin) / static_cast<Real>(this->mDescription.numCols - 1);
114  Real vMin = mSurface->GetVMin();
115  Real vDelta = (mSurface->GetVMax() - vMin) / static_cast<Real>(this->mDescription.numRows - 1);
116  Vector2<Real> tcoord;
117  for (uint32_t r = 0, i = 0; r < this->mDescription.numRows; ++r)
118  {
119  tcoord[1] = vMin + vDelta * (Real)r;
120  for (uint32_t c = 0; c < this->mDescription.numCols; ++c, ++i)
121  {
122  tcoord[0] = uMin + uDelta * (Real)c;
123  this->TCoord(i) = tcoord;
124  }
125  }
126 }
127 
128 template <typename Real>
130 {
131  for (uint32_t r = 0, i = 0; r < this->mDescription.numRows; ++r)
132  {
133  for (uint32_t c = 0; c < this->mDescription.numCols; ++c, ++i)
134  {
135  Vector2<Real> tcoord = this->TCoord(i);
136  this->Position(i) = mSurface->GetPosition(tcoord[0], tcoord[1]);
137  }
138  }
139 }
140 
141 template <typename Real>
143 {
144  for (uint32_t r = 0, i = 0; r < this->mDescription.numRows; ++r)
145  {
146  for (uint32_t c = 0; c < this->mDescription.numCols; ++c, ++i)
147  {
148  Vector2<Real> tcoord = this->TCoord(i);
150  mSurface->Evaluate(tcoord[0], tcoord[1], 1, values);
151  Normalize(values[1], true);
152  Normalize(values[2], true);
153  this->Normal(i) = UnitCross(values[1], values[2], true);
154  }
155  }
156 }
157 
158 template <typename Real>
160 {
161  Vector3<Real> normal, tangent, bitangent;
162  for (unsigned int r = 0, i = 0; r < this->mDescription.numRows; ++r)
163  {
164  for (unsigned int c = 0; c < this->mDescription.numCols; ++c, ++i)
165  {
166  Vector2<Real> tcoord = this->TCoord(i);
168  mSurface->Evaluate(tcoord[0], tcoord[1], 1, values);
169  Normalize(values[1], true);
170  Normalize(values[2], true);
171 
172  if (this->mDPDUs)
173  {
174  this->DPDU(i) = values[1];
175  }
176  if (this->mDPDVs)
177  {
178  this->DPDV(i) = values[2];
179  }
180 
181  ComputeOrthogonalComplement(2, &values[1], true);
182 
183  if (this->mNormals)
184  {
185  this->Normal(i) = values[3];
186  }
187  if (this->mTangents)
188  {
189  this->Tangent(i) = values[1];
190  }
191  if (this->mBitangents)
192  {
193  this->Bitangent(i) = values[2];
194  }
195  }
196  }
197 }
198 
199 template <typename Real>
201 {
202  if (mSurface)
203  {
205  }
206 }
207 
208 template <typename Real>
210 {
211  if (mSurface)
212  {
214  }
215 }
216 
217 template <typename Real>
219 {
220  if (mSurface)
221  {
222  InitializeFrame();
223  }
224 }
225 
226 }
MeshDescription mDescription
Definition: GteMesh.h:163
uint32_t numRows
Definition: GteMesh.h:97
Vector3< Real > * mBitangents
Definition: GteMesh.h:169
std::shared_ptr< ParametricSurface< 3, Real > > const & GetSurface() const
Vector< N, Real > UnitCross(Vector< N, Real > const &v0, Vector< N, Real > const &v1, bool robust=false)
Definition: GteVector3.h:130
Vector3< Real > & Bitangent(uint32_t i)
Definition: GteMesh.h:487
Vector3< Real > & DPDU(uint32_t i)
Definition: GteMesh.h:494
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1597
RectanglePatchMesh(MeshDescription const &description, std::shared_ptr< ParametricSurface< 3, Real >> const &surface)
Vector3< Real > * mTangents
Definition: GteMesh.h:168
virtual void UpdateFrame() override
const GLubyte * c
Definition: glext.h:11671
bool wantDynamicTangentSpaceUpdate
Definition: GteMesh.h:91
#define LogError(message)
Definition: GteLogger.h:92
Vector3< Real > * mNormals
Definition: GteMesh.h:167
Real Normalize(GVector< Real > &v, bool robust=false)
Definition: GteGVector.h:454
uint32_t numVertices
Definition: GteMesh.h:87
Vector3< Real > * mDPDVs
Definition: GteMesh.h:171
std::vector< Vector2< Real > > mDefaultTCoords
virtual void UpdatePositions() override
virtual void UpdateNormals() override
Vector2< Real > & TCoord(uint32_t i)
Definition: GteMesh.h:508
GLboolean r
Definition: glcorearb.h:1217
size_t mTCoordStride
Definition: GteMesh.h:179
Vector3< Real > & Tangent(uint32_t i)
Definition: GteMesh.h:480
Vector2< Real > * mTCoords
Definition: GteMesh.h:172
void ComputeIndices()
Definition: GteMesh.h:515
Vector3< Real > & Normal(uint32_t i)
Definition: GteMesh.h:473
uint32_t numCols
Definition: GteMesh.h:97
std::shared_ptr< ParametricSurface< 3, Real > > mSurface
Vector3< Real > & DPDV(uint32_t i)
Definition: GteMesh.h:501
bool hasTangentSpaceVectors
Definition: GteMesh.h:95
Real ComputeOrthogonalComplement(int numInputs, Vector2< Real > *v, bool robust=false)
Definition: GteVector2.h:123
Vector3< Real > & Position(uint32_t i)
Definition: GteMesh.h:466
Vector3< Real > * mDPDUs
Definition: GteMesh.h:170


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01