GteRectangleMesh.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 <Mathematics/GteVector3.h>
13 #include <memory>
14 
15 namespace gte
16 {
17 
18 template <typename Real>
19 class RectangleMesh : public Mesh<Real>
20 {
21 public:
22  // Create a mesh that tessellates a rectangle.
23  RectangleMesh(MeshDescription const& description, Rectangle<3, Real> const& rectangle);
24 
25  // Member access.
26  inline Rectangle<3, Real> const& GetRectangle() const;
27 
28 protected:
29  void InitializeTCoords();
30  void InitializePositions();
31  void InitializeNormals();
32  void InitializeFrame();
33 
35 
36  // If the client does not request texture coordinates, they will be
37  // computed internally for use in evaluation of the surface geometry.
38  std::vector<Vector2<Real>> mDefaultTCoords;
39 };
40 
41 
42 template <typename Real>
44  Rectangle<3, Real> const& rectangle)
45  :
46  Mesh<Real>(description, { MeshTopology::RECTANGLE }),
47  mRectangle(rectangle)
48 {
49  if (!this->mDescription.constructed)
50  {
51  // The logger system will report these errors in the Mesh constructor.
52  return;
53  }
54 
55  if (!this->mTCoords)
56  {
58  this->mTCoords = mDefaultTCoords.data();
59  this->mTCoordStride = sizeof(Vector2<Real>);
60 
63  {
65  {
66  this->mDescription.allowUpdateFrame = false;
67  }
68 
69  if (!this->mNormals)
70  {
71  this->mDescription.allowUpdateFrame = false;
72  }
73  }
74  }
75 
76  this->ComputeIndices();
80  {
82  }
83  else if (this->mNormals)
84  {
86  }
87 }
88 
89 template <typename Real>
91 {
92  return mRectangle;
93 }
94 
95 template <typename Real>
97 {
98  Vector2<Real> tcoord;
99  for (uint32_t r = 0, i = 0; r < this->mDescription.numRows; ++r)
100  {
101  tcoord[1] = (Real)r / (Real)(this->mDescription.numRows - 1);
102  for (uint32_t c = 0; c < this->mDescription.numCols; ++c, ++i)
103  {
104  tcoord[0] = (Real)c / (Real)(this->mDescription.numCols - 1);
105  this->TCoord(i) = tcoord;
106  }
107  }
108 }
109 
110 template <typename Real>
112 {
113  for (uint32_t r = 0, i = 0; r < this->mDescription.numRows; ++r)
114  {
115  for (uint32_t c = 0; c < this->mDescription.numCols; ++c, ++i)
116  {
117  Vector2<Real> tcoord = this->TCoord(i);
118  Real w0 = ((Real)2 * tcoord[0] - (Real)1) * mRectangle.extent[0];
119  Real w1 = ((Real)2 * tcoord[1] - (Real)1) * mRectangle.extent[1];
120  this->Position(i) = mRectangle.center + w0 * mRectangle.axis[0] + w1 * mRectangle.axis[1];
121  }
122  }
123 }
124 
125 template <typename Real>
127 {
129  for (uint32_t i = 0; i < this->mDescription.numVertices; ++i)
130  {
131  this->Normal(i) = normal;
132  }
133 }
134 
135 template <typename Real>
137 {
139  Vector3<Real> tangent{ (Real)1, (Real)0, (Real)0 };
140  Vector3<Real> bitangent{ (Real)0, (Real)1, (Real)0 }; // = Cross(normal,tangent)
141  for (uint32_t i = 0; i < this->mDescription.numVertices; ++i)
142  {
143  if (this->mNormals)
144  {
145  this->Normal(i) = normal;
146  }
147 
148  if (this->mTangents)
149  {
150  this->Tangent(i) = tangent;
151  }
152 
153  if (this->mBitangents)
154  {
155  this->Bitangent(i) = bitangent;
156  }
157 
158  if (this->mDPDUs)
159  {
160  this->DPDU(i) = tangent;
161  }
162 
163  if (this->mDPDVs)
164  {
165  this->DPDV(i) = bitangent;
166  }
167  }
168 }
169 
170 }
Vector< 2, Real > extent
Definition: GteRectangle.h:40
Vector< N, Real > center
Definition: GteRectangle.h:38
MeshDescription mDescription
Definition: GteMesh.h:163
std::vector< Vector2< Real > > mDefaultTCoords
uint32_t numRows
Definition: GteMesh.h:97
Vector3< Real > * mBitangents
Definition: GteMesh.h:169
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
std::array< Vector< N, Real >, 2 > axis
Definition: GteRectangle.h:39
Vector3< Real > * mTangents
Definition: GteMesh.h:168
const GLubyte * c
Definition: glext.h:11671
bool wantDynamicTangentSpaceUpdate
Definition: GteMesh.h:91
Vector3< Real > * mNormals
Definition: GteMesh.h:167
uint32_t numVertices
Definition: GteMesh.h:87
Vector3< Real > * mDPDVs
Definition: GteMesh.h:171
RectangleMesh(MeshDescription const &description, Rectangle< 3, Real > const &rectangle)
Rectangle< 3, Real > mRectangle
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
Vector3< Real > & DPDV(uint32_t i)
Definition: GteMesh.h:501
bool hasTangentSpaceVectors
Definition: GteMesh.h:95
Vector3< Real > & Position(uint32_t i)
Definition: GteMesh.h:466
Vector3< Real > * mDPDUs
Definition: GteMesh.h:170
Rectangle< 3, Real > const & GetRectangle() const
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble w1
Definition: glext.h:11365


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