VR-Forces 4.10 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtIndirectAggregateIndicesHelper.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2019 VT-MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
13 
15 
16 #include <vlutil/vlPrint.h>
17 
18 #include <osg/Geometry>
19 
20 #include <string>
21 #include <vector>
22 
23 #include <tbb/atomic.h>
24 
25 namespace osg
26 {
27  class Geometry;
28 }
29 
30 namespace makVrv
31 {
35  {
36  public:
38  DtIndirectAggregateIndicesHelper(const std::string& modelName, const osg::ref_ptr<osg::Geometry>& aggregatedGeometry);
39 
42  private:
45 
48 
51  public:
52 
54  virtual bool checkSrcAndDstIndicesOk(const osg::Geometry& geometry);
55 
57  virtual void copyIndices(std::vector<int>& indices, const osg::Geometry& geometry);
58 
61  virtual void cancel();
62 
64  virtual bool isModeSupported(GLenum mode);
65 
69  virtual std::string toModeString(GLenum mode);
70 
71  public:
73  static int calculateNumIndices(const osg::PrimitiveSet* primitiveSet);
74 
75  protected:
76 
78  virtual bool checkAndCopyIndicesIfTriangleElements(std::vector<int>& indices, const osg::PrimitiveSet* primitiveSet);
79 
81  virtual bool checkAndCopyIndicesIfDrawArrays(std::vector<int>& indices, const osg::PrimitiveSet* primitiveSet);
82 
84  virtual void printDetailsPrimitiveSets(const osg::Geometry& geometry);
85 
86  protected:
87 
90  template <class T>
91  bool copyIndicesOnMatch(std::vector<int>& indices, const osg::PrimitiveSet* primitiveSet);
92 
93 
94  protected:
95  // used only for outputting debug messages
96  const std::string myModelFileName;
97 
99 
100  tbb::atomic<int> myCancelTask;
101  };
102 
103  template <class T>
104  bool DtIndirectAggregateIndicesHelper::copyIndicesOnMatch(std::vector<int>& indices, const osg::PrimitiveSet* primitiveSet)
105  {
106  const T* primitiveSetT = dynamic_cast<const T*>(primitiveSet);
107  if (primitiveSetT == 0)
108  {
109  return false;
110  }
111 
112  GLenum mode = primitiveSetT->getMode();
113  if (isModeSupported(mode) == false)
114  {
115  DtWarn << "Info: " << __FILE__ << " +" << __LINE__ << " " << __FUNCTION__ << " mode is: " << toModeString(mode) << ", skipping" << std::endl;
116  return false;
117  }
118  // avoid lots of resizing
119  indices.reserve(indices.size() + primitiveSetT->size());
120  if (mode == GL_TRIANGLES)
121  {
122  indices.insert(indices.end(), primitiveSetT->begin(), primitiveSetT->end());
123 
124  }
125  else if (mode == GL_TRIANGLE_FAN)
126  {
127  ASSERT_PREDICATE(primitiveSetT->size() >= 3);
128 
129  int numTriangles = primitiveSetT->size() - 2;
130 
131  int i0 = primitiveSetT->at(0);
132 
133  for (int i = 0; i < numTriangles; ++i)
134  {
135  int i1 = primitiveSetT->at(i + 1);
136  int i2 = primitiveSetT->at(i + 2);
137 
138  indices.push_back(i0);
139  indices.push_back(i1);
140  indices.push_back(i2);
141  }
142  }
143  else if (mode == GL_TRIANGLE_STRIP)
144  {
145  ASSERT_PREDICATE(primitiveSetT->size() >= 3);
146  int numTriangles = primitiveSetT->size() - 2;
147  for (int i = 0; i < numTriangles; ++i)
148  {
149  int i0 = primitiveSetT->at(i);
150  int i1 = primitiveSetT->at(i + 1);
151  int i2 = primitiveSetT->at(i + 2);
152 
153  if (i % 2 == 0)
154  {
155  indices.push_back(i0);
156  indices.push_back(i1);
157  indices.push_back(i2);
158  }
159  else
160  {
161  indices.push_back(i1);
162  indices.push_back(i0);
163  indices.push_back(i2);
164  }
165  }
166  }
167  else if (mode == GL_QUADS)
168  {
169  int count = primitiveSetT->size();
170  ASSERT_PREDICATE(count % 4 == 0);
171  int numQuads = count / 4;
172  for (int quad = 0; quad < numQuads; ++quad)
173  {
174  int q0 = primitiveSetT->at(quad) * 4 + 0;
175  int q1 = primitiveSetT->at(quad) * 4 + 1;
176  int q2 = primitiveSetT->at(quad) * 4 + 2;
177  int q3 = primitiveSetT->at(quad) * 4 + 3;
178 
179  indices.push_back(q0);
180  indices.push_back(q1);
181  indices.push_back(q2);
182 
183  indices.push_back(q0);
184  indices.push_back(q2);
185  indices.push_back(q3);
186  }
187  }
188  else
189  {
190  ASSERT_PREDICATE(false);
191  return false;
192  }
193  return true;
194  }
195 }
tbb::atomic< int > myCancelTask
Definition: DtIndirectAggregateIndicesHelper.h:100
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
osg::ref_ptr< osg::Geometry > myAggregatedGeometry
Definition: DtIndirectAggregateIndicesHelper.h:98
bool copyIndicesOnMatch(std::vector< int > &indices, const osg::PrimitiveSet *primitiveSet)
templated function used to copy indices that are a DrawElements vector.
Definition: DtIndirectAggregateIndicesHelper.h:104
helper class for DtIndirectAggregateHelper which checks and copies indices from a geometry ...
Definition: DtIndirectAggregateIndicesHelper.h:34
virtual std::string toModeString(GLenum mode)
helper function for converting from a GLenum to a string that contains the GLenum.
unsigned int GLenum
Definition: DtGlTextureBufferObject.h:18
const char int mode
Definition: ioapi.h:38
Contains DLL export macros.
#define ASSERT_PREDICATE(p)
Definition: DtAssert.h:28
assert macros
virtual bool isModeSupported(GLenum mode)
helper function for checking if a mode is supported by this helper/indirect
const std::string myModelFileName
Definition: DtIndirectAggregateIndicesHelper.h:96

Document ID: Generated on Tue Sep 21 17:42:52 EDT 2021 from SVN revision 234861
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)