VR-Forces 4.8 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:
37  DtIndirectAggregateIndicesHelper(const std::string& modelName, const osg::ref_ptr<osg::Geometry>& aggregatedGeometry);
38 
40 
42  virtual bool checkSrcAndDstIndicesOk(const osg::Geometry& geometry);
43 
45  virtual void copyIndices(std::vector<int>& indices, const osg::Geometry& geometry);
46 
48  static int calculateNumIndices(const osg::PrimitiveSet* primitiveSet);
49 
52  virtual void cancel();
53 
55  virtual bool isModeSupported(GLenum mode);
56 
60  virtual std::string toModeString(GLenum mode);
61 
62  protected:
63 
65  virtual bool checkAndCopyIndicesIfTriangleElements(std::vector<int>& indices, const osg::PrimitiveSet* primitiveSet);
66 
68  virtual bool checkAndCopyIndicesIfDrawArrays(std::vector<int>& indices, const osg::PrimitiveSet* primitiveSet);
69 
70 
71 
73  virtual void printDetailsPrimitiveSets(const osg::Geometry& geometry);
74 
75  protected:
76 
79  template <class T>
80  bool copyIndicesOnMatch(std::vector<int>& indices, const osg::PrimitiveSet* primitiveSet);
81 
82 
83  protected:
84  // used only for outputting debug messages
85  const std::string myModelFileName;
86 
88 
89  tbb::atomic<int> myCancelTask;
90  };
91 
92  template <class T>
93  bool DtIndirectAggregateIndicesHelper::copyIndicesOnMatch(std::vector<int>& indices, const osg::PrimitiveSet* primitiveSet)
94  {
95  const T* primitiveSetT = dynamic_cast<const T*>(primitiveSet);
96  if (primitiveSetT == 0)
97  {
98  return false;
99  }
100 
101  GLenum mode = primitiveSetT->getMode();
102  if (isModeSupported(mode) == false)
103  {
104  DtWarn << "Info: " << __FILE__ << " +" << __LINE__ << " " << __FUNCTION__ << " mode is: " << toModeString(mode) << ", skipping" << std::endl;
105  return false;
106  }
107  // avoid lots of resizing
108  indices.reserve(indices.size() + primitiveSetT->size());
109  if (mode == GL_TRIANGLES)
110  {
111  indices.insert(indices.end(), primitiveSetT->begin(), primitiveSetT->end());
112 
113  }
114  else if (mode == GL_TRIANGLE_FAN)
115  {
116  ASSERT_PREDICATE(primitiveSetT->size() >= 3);
117 
118  int numTriangles = primitiveSetT->size() - 2;
119 
120  int i0 = primitiveSetT->at(0);
121 
122  for (int i = 0; i < numTriangles; ++i)
123  {
124  int i1 = primitiveSetT->at(i + 1);
125  int i2 = primitiveSetT->at(i + 2);
126 
127  indices.push_back(i0);
128  indices.push_back(i1);
129  indices.push_back(i2);
130  }
131  }
132  else if (mode == GL_TRIANGLE_STRIP)
133  {
134  ASSERT_PREDICATE(primitiveSetT->size() >= 3);
135  int numTriangles = primitiveSetT->size() - 2;
136  for (int i = 0; i < numTriangles; ++i)
137  {
138  int i0 = primitiveSetT->at(i);
139  int i1 = primitiveSetT->at(i + 1);
140  int i2 = primitiveSetT->at(i + 2);
141 
142  if (i % 2 == 0)
143  {
144  indices.push_back(i0);
145  indices.push_back(i1);
146  indices.push_back(i2);
147  }
148  else
149  {
150  indices.push_back(i1);
151  indices.push_back(i0);
152  indices.push_back(i2);
153  }
154  }
155  }
156  else if (mode == GL_QUADS)
157  {
158  int count = primitiveSetT->size();
159  ASSERT_PREDICATE(count % 4 == 0);
160  int numQuads = count / 4;
161  for (int quad = 0; quad < numQuads; ++quad)
162  {
163  int q0 = primitiveSetT->at(quad) * 4 + 0;
164  int q1 = primitiveSetT->at(quad) * 4 + 1;
165  int q2 = primitiveSetT->at(quad) * 4 + 2;
166  int q3 = primitiveSetT->at(quad) * 4 + 3;
167 
168  indices.push_back(q0);
169  indices.push_back(q1);
170  indices.push_back(q2);
171 
172  indices.push_back(q0);
173  indices.push_back(q2);
174  indices.push_back(q3);
175  }
176  }
177  else
178  {
179  ASSERT_PREDICATE(false);
180  return false;
181  }
182  return true;
183  }
184 }
tbb::atomic< int > myCancelTask
Definition: DtIndirectAggregateIndicesHelper.h:89
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
osg::ref_ptr< osg::Geometry > myAggregatedGeometry
Definition: DtIndirectAggregateIndicesHelper.h:87
bool copyIndicesOnMatch(std::vector< int > &indices, const osg::PrimitiveSet *primitiveSet)
templated function used to copy indicies that are a DrawElements vector.
Definition: DtIndirectAggregateIndicesHelper.h:93
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
virtual ~DtIndirectAggregateIndicesHelper()
Definition: DtIndirectAggregateIndicesHelper.h:39
const std::string myModelFileName
Definition: DtIndirectAggregateIndicesHelper.h:85

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)