VR-Forces Development_Version Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
triangleIndirect.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 2000 MaK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 /*********************************************************************
6 ** $RCSfile: triInd.h,v $ $Revision: 1.25 $ $State: Exp $
7 *********************************************************************/
8 
9 #ifndef triangleIndirect_H_
10 #define triangleIndirect_H_
11 
12 #include "gdb/gdbDefines.h"
13 #include "gdb/baseTriangle.h"
14 #include "gdb/vertexManager.h"
15 #include "gdb/surfaceManager.h"
16 #include "geometry/point.h"
17 
18 #include <vlutil/vlPrint.h>
19 #include <assert.h>
20 
21 // forward declarations
22 class DtSurfaceManager;
23 class DtPolygonIndirect;
24 
25 
26 // class DtTriangleIndirect:
27 //
28 // DtTriangleIndirect allows for the specification of the
29 // vertices of a polygon as indices into a vertex Manager.
30 
32 {
33 public:
34 
35  // constructor using a polygon indirect.
36  DtTriangleIndirect(const DtPolygonIndirect* const poly);
37 
38  // constructor with vertex IDs, vertex manager, surface manager,
39  // and surface ID
40  DtTriangleIndirect(DtVertexManager* const vertManager,
41  const DtVertexID vertID0,
42  const DtVertexID vertID1,
43  const DtVertexID vertID2,
44  DtSurfaceManager* const surfMgr,
45  const DtSurfaceID surfID);
46 
47  // destructor
48  virtual ~DtTriangleIndirect();
49 
50  // copy constructor
52 
53  // assignment operator
55 
56  // computes the intersection of chord with polygon; returns
57  // intersection point.
58  virtual bool intersect(const DtChord& chord,
59  DtPoint& intersectionPoint,
60  double& t) const;
61 
62  // Since this class only overrides one of the intersection functions,
63  // specify that its using the base classes to prevent hiding.
67 
68  // returns extent of the triangle
69  inline DtExtent extent() const;
70 
71  // vertex accessors
72  inline DtPoint& vertex0();
73  inline const DtPoint& vertex0() const;
74 
75  inline DtPoint& vertex1();
76  inline const DtPoint& vertex1() const;
77 
78  inline DtPoint& vertex2();
79  inline const DtPoint& vertex2() const;
80 
81  virtual bool getVertex(DtPoint& retVal, unsigned int localIndex) const;
82  const DtPoint& getVertex(unsigned int localIndex) const;
83 
84  // Requires index be a valid localIndex into the list of vertex IDs.
85  virtual DtVertexID getVertexID(unsigned int localIndex) const;
86 
87  virtual void setVertex(unsigned int localIndex, DtVertexID vertexID);
88 
89  // get the surface associated with the triangle
90  virtual bool getSurface(DtSurface& s) const;
91  const DtSurface& getSurface() const;
92 
93  // get the surface ID associated with the triangle
94  virtual DtSurfaceID getSurfaceID() const;
95 
96  // set the surface associated with the triangle
97  // If the ID is a valid surface ID, then it sets the
98  // surface and returns true. If the ID is invalid,
99  // the it returns false and does NOT set the surface.
100  virtual bool setSurface(DtSurfaceID surfaceID);
101 
102  // Sets the surface of the associated triangle.
103  // \return A boolean indicating whether or not the surface could be set.
104  // \note \b Implementation \b detail! - Does not add the surface if it already
105  // exists in the surface manager.
106  virtual bool setSurface(const DtSurface& newSurface);
107 
108  // get the vertex Manager associated with the polygon
109  inline virtual DtVertexManager* const vertexManager() const;
110 
111  // get a pointer to the the surface Manager associated with the triangle
112  inline virtual DtSurfaceManager* const surfaceManager() const;
113 
114  // debugging aid function
115  virtual void dump(int indentLevel) const;
116 
117  // Applies the specified transform to its vertices. If the flag
118  // is true, will create new vertices instead of modifying existing
119  // ones. Returns false if the transformation fails for any reason.
120  virtual bool applyTransform(const DtHomogeneousTransformMatrix& matrix,
121  bool createNewVertices);
122 
123 // Unsafe public functions: These functions expose the internals of
124 // the object.They are unsafe in that, should the implementation change,
125 // these functions are not guaranteed to stay the same. Any use of these
126 // functions assumes the risk they will be broken by future changes to the
127 // internals of this class
128 
129  // default constructor
131 
132  // constructor with vertex indices and vertex manager to
133  // index into
135  const DtVertexID ind0,
136  const DtVertexID ind1,
137  const DtVertexID ind2);
138 
139  // returns type of gdb node
140  virtual DtGdbNode::DtGdbNodeType type() const;
141 
142  // set the vertex Manager associated with the polygon
143  // Requires that the specified vertex manager is not 0.
144  virtual void setVertexManager(DtVertexManager* const vertManager);
145 
146  // set the pointer to the surface Manager associated with the triangle
147  // Requires that the specified surface manager is not 0.
148  virtual void setSurfaceManager(DtSurfaceManager* const surfManager);
149 
150  virtual int sizeInBytes() const;
151 
152 protected:
153 
154  virtual bool testInvariant() const;
155 
159  DtVertexID myVertexIDs[3]; // an array of size 3 to hold the indices.
160 };
161 
163 // Functions below do NOT test for invariancy
164 // and may corrupt the triangle if not used properly
167 {
168  return myVertexManager->vertex(myVertexIDs[0]);
169 }
170 
172 {
173  return myVertexManager->vertex(myVertexIDs[0]);
174 }
175 
176 
178 {
179  return myVertexManager->vertex(myVertexIDs[1]);
180 }
181 
183 {
184  return myVertexManager->vertex(myVertexIDs[1]);
185 }
186 
187 
189 {
190  return myVertexManager->vertex(myVertexIDs[2]);
191 }
192 
194 {
195  return myVertexManager->vertex(myVertexIDs[2]);
196 }
197 
199 {
200  DtExtent expandedExtent(vertex0(), vertex1());
201  expandedExtent.expandToInclude(vertex2());
202  return expandedExtent;
203 }
204 
206 {
207  return myVertexManager;
208 }
209 
210 
212 {
213  return mySurfaceManager;
214 }
215 
216 
218 {
220 }
221 
222 inline DtVertexID DtTriangleIndirect::getVertexID(unsigned int index) const
223 {
224  assert(index <= 2);
225  return myVertexIDs[index];
226 }
227 
228 inline const DtPoint& DtTriangleIndirect::getVertex(unsigned int localIndex) const
229 {
230  return myVertexManager->vertex(myVertexIDs[localIndex]);
231 }
232 
234 {
235  return mySurfaceID;
236 }
237 
239 {
240  assert(surfMgr != 0);
241  mySurfaceManager = surfMgr;
242  // every polygon is created with a surface type of 0
243  // as soon as there is a surface manager, add 1 to the polygon count of this
244  // surface
246 }
247 
249 {
250  assert(vertManager != 0);
251  myVertexManager = vertManager;
252 }
253 
254 inline void DtTriangleIndirect::setVertex(unsigned int localIndex, DtVertexID vertexIndex)
255 {
256  assert(localIndex <= 2);
257  assert(myVertexManager->isValidID(vertexIndex));
258  if (localIndex <= 2)
259  {
260  myVertexIDs[localIndex] = vertexIndex;
261  }
262  else
263  {
264  DtWarn("Warning: DtTriangleIndirect::setVertex -- "
265  "bad localIndex %d\n", localIndex);
266  }
267 }
268 
270 {
272 }
273 
274 #endif

Document ID: Generated on Mon Jul 4 01:00:18 EDT 2016 from SVN revision 166489
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)