fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / Collada / OSGColladaGeometry.h
blobb8f70da0d1b7b8a0242aa5bb346592d1e1c1acc2
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2009 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGCOLLADAGEOMETRY_H_
40 #define _OSGCOLLADAGEOMETRY_H_
42 #include "OSGConfig.h"
44 #if defined(OSG_WITH_COLLADA) || defined(OSG_DO_DOC)
46 #include "OSGColladaInstantiableElement.h"
47 #include "OSGColladaElementFactoryHelper.h"
48 #include "OSGColladaInstanceMaterial.h"
49 #include "OSGColladaInstInfo.h"
50 #include "OSGColladaSource.h"
51 #include "OSGNode.h"
52 #include "OSGGeometry.h"
53 #include "OSGGeoVectorProperty.h"
54 #include "OSGGeoIntegralProperty.h"
56 #include <dae/daeDomTypes.h>
57 #include <dom/domInputLocal.h>
58 #include <dom/domInputLocalOffset.h>
59 #include <dom/domSource.h>
61 #ifdef OSG_WITH_COLLADA_NAMESPACE
62 namespace ColladaDOM141 {
63 #endif
65 // forward decls
66 class domMesh;
67 class domLines;
68 class domLinestrips;
69 class domPolygons;
70 class domPolylist;
71 class domTriangles;
72 class domTrifans;
73 class domTristrips;
75 #ifdef OSG_WITH_COLLADA_NAMESPACE
77 #endif
79 OSG_BEGIN_NAMESPACE
81 // forward decls
82 class ColladaInstanceGeometry;
83 OSG_GEN_MEMOBJPTR(ColladaInstanceGeometry);
85 class ColladaNode;
87 /*! \ingroup GrpFileIOCollada
88 \nohierarchy
91 class OSG_FILEIO_DLLMAPPING ColladaGeometry : public ColladaInstantiableElement
93 /*========================== PUBLIC =================================*/
94 public:
95 /*---------------------------------------------------------------------*/
96 /*! \name Types */
97 /*! \{ */
99 typedef ColladaInstantiableElement Inherited;
100 typedef ColladaGeometry Self;
102 OSG_GEN_INTERNAL_MEMOBJPTR(ColladaGeometry);
104 typedef ColladaInstanceMaterial::BindInfo BindInfo;
105 typedef ColladaInstanceMaterial::BindStore BindStore;
107 typedef ColladaInstanceMaterial::BindVertexInfo BindVertexInfo;
108 typedef ColladaInstanceMaterial::BindVertexStore BindVertexStore;
110 class ColladaGeometryInstInfo : public ColladaInstInfo
112 /*========================== PUBLIC =============================*/
113 public:
114 /*-----------------------------------------------------------------*/
115 /*! \name Types */
116 /*! \{ */
118 typedef ColladaInstInfo Inherited;
119 typedef ColladaGeometryInstInfo Self;
121 OSG_GEN_INTERNAL_MEMOBJPTR(ColladaGeometryInstInfo);
123 /*! \} */
124 /*-----------------------------------------------------------------*/
125 /*! \name Create */
126 /*! \{ */
128 static ColladaInstInfoTransitPtr
129 create(ColladaNode *colInstParent,
130 ColladaInstanceGeometry *colInst,
131 Node *parentN );
133 /*! \} */
134 /*-----------------------------------------------------------------*/
135 /*! \name Access */
136 /*! \{ */
138 inline Node *getParentNode(void) const;
140 /*! \} */
141 /*-----------------------------------------------------------------*/
142 /*! \name Process */
143 /*! \{ */
145 virtual void process(void);
147 /*! \} */
148 /*========================= PROTECTED ===========================*/
149 protected:
150 /*-----------------------------------------------------------------*/
151 /*! \name Constructors/Destructor */
152 /*! \{ */
154 ColladaGeometryInstInfo(
155 ColladaNode *colInstParent,
156 ColladaInstanceGeometry *colInst,
157 Node *parentN );
158 virtual ~ColladaGeometryInstInfo(void );
160 /*! \} */
161 /*-----------------------------------------------------------------*/
163 NodeUnrecPtr _parentN;
166 OSG_GEN_MEMOBJPTR(ColladaGeometryInstInfo);
168 /*! \} */
169 /*---------------------------------------------------------------------*/
170 /*! \name Create */
171 /*! \{ */
173 static ColladaElementTransitPtr
174 create(daeElement *elem, ColladaGlobal *global);
176 /*! \} */
177 /*---------------------------------------------------------------------*/
178 /*! \name Reading */
179 /*! \{ */
181 void setDoubleSided(bool value);
183 /*! \} */
184 /*---------------------------------------------------------------------*/
185 /*! \name Reading */
186 /*! \{ */
188 virtual void read (ColladaElement *colElemParent);
189 virtual Node *createInstance(ColladaInstInfo *colInstInfo );
191 /*! \} */
192 /*========================= PROTECTED ===============================*/
193 protected:
194 /*---------------------------------------------------------------------*/
195 /*! \name Constructors/Destructor */
196 /*! \{ */
198 ColladaGeometry(daeElement *elem, ColladaGlobal *global);
199 virtual ~ColladaGeometry(void );
201 /*! \} */
202 /*---------------------------------------------------------------------*/
203 /*! \name Internal Types */
204 /*! \{ */
206 // <source> map
207 typedef std::map<std::string, ColladaSourceRefPtr> SourceMap;
208 typedef SourceMap::iterator SourceMapIt;
209 typedef SourceMap::const_iterator SourceMapConstIt;
211 /*! \nohierarchy
213 struct PropInfo
215 PropInfo(void );
216 PropInfo(const PropInfo &source);
218 std::string _semantic;
219 Int32 _set;
221 GeoVectorPropertyUnrecPtr _prop;
224 typedef std::vector<PropInfo > PropStore;
225 typedef PropStore::iterator PropStoreIt;
226 typedef PropStore::const_iterator PropStoreConstIt;
228 typedef std::vector<GeoIntegralPropertyUnrecPtr> IndexStore;
229 typedef IndexStore::iterator IndexStoreIt;
230 typedef IndexStore::const_iterator IndexStoreConstIt;
232 // map <instance_material> target attribute to an index into
233 // the instance store (getInstStore())
234 typedef std::map<std::string, UInt32> InstanceMap;
235 typedef InstanceMap::iterator InstanceMapIt;
236 typedef InstanceMap::const_iterator InstanceMapConstIt;
238 /*! \nohierarchy
240 struct GeoInfo
242 std::string _matSymbol;
244 PropStore _propStore;
245 IndexStore _indexStore;
247 GeoIntegralPropertyUnrecPtr _lengths;
248 GeoIntegralPropertyUnrecPtr _types;
250 InstanceMap _instMap;
252 GeoInfo(void):
253 _matSymbol ( ),
254 _propStore ( ),
255 _indexStore( ),
256 _lengths (NULL),
257 _types (NULL),
258 _instMap ( ) {}
261 typedef std::vector<GeoInfo > GeoStore;
262 typedef GeoStore::iterator GeoStoreIt;
263 typedef GeoStore::const_iterator GeoStoreConstIt;
265 /*! \} */
266 /*---------------------------------------------------------------------*/
267 /*! \name Helper Functions */
268 /*! \{ */
270 void readMesh ( domMesh *mesh );
271 void readSources(const domSource_Array &sources);
273 void readLines (domMesh *mesh, domLines *lines );
274 void readLineStrips(domMesh *mesh, domLinestrips *lineStrips);
275 void readPolygons (domMesh *mesh, domPolygons *polygons );
276 void readPolyList (domMesh *mesh, domPolylist *polyList );
277 void readTriangles (domMesh *mesh, domTriangles *triangles );
278 void readTriFans (domMesh *mesh, domTrifans *triFans );
279 void readTriStrips (domMesh *mesh, domTristrips *triStrips );
281 UInt32 mapSemantic (const std::string &semantic,
282 UInt32 set,
283 UInt32 geoIdx );
285 void setupProperty(UInt32 geoIdx,
286 UInt32 propIdx,
287 const std::string &semantic,
288 UInt32 set,
289 const std::string &sourceId,
290 GeoIntegralProperty *idxProp );
292 UInt32 setupGeometry(const domInputLocal_Array &vertInputs,
293 const domInputLocalOffset_Array &inputs,
294 xsNCName matSymbold,
295 IndexStore &indexStore );
297 void handleBindMaterial(const GeoInfo &geoInfo,
298 Geometry *geo,
299 ColladaInstanceGeometry *colInstGeo);
301 const BindInfo *findBind (const BindStore &store,
302 const std::string &semantic,
303 UInt32 &offset );
304 const BindVertexInfo *findBindVertex(const BindVertexStore &store,
305 const std::string &inSemantic,
306 UInt32 inSet,
307 UInt32 &offset );
309 UInt16 findFreePropertyIndex(UInt32 geoIdx);
311 void validateIndices ( UInt32 geoIdx,
312 const std::vector<bool> &vIdxValid,
313 const IndexStore idxStore );
315 /*! \} */
316 /*---------------------------------------------------------------------*/
318 static ColladaElementRegistrationHelper _regHelper;
320 SourceMap _sourceMap;
321 GeoStore _geoStore;
322 bool _doubleSided;
323 ExtraHandlerStore _extraHandlers;
327 OSG_GEN_MEMOBJPTR(ColladaGeometry);
329 OSG_END_NAMESPACE
331 #include "OSGColladaGeometry.inl"
333 #endif // OSG_WITH_COLLADA
335 #endif // _OSGCOLLADAGEOMETRY_H_