00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef _OSGVRMLWRITEACTION_H_
00040 #define _OSGVRMLWRITEACTION_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044
00045
00046
00047
00048
00049 #include <vector>
00050
00051 #include <OSGSystemDef.h>
00052 #include <OSGBaseTypes.h>
00053 #include <OSGAction.h>
00054 #include <OSGGeometry.h>
00055 #include <OSGGroup.h>
00056
00057 #include <map>
00058
00059
00060 OSG_BEGIN_NAMESPACE
00061
00062
00063
00064
00065
00066 class Node;
00067 class Action;
00068 class Material;
00069
00070
00071
00072
00073
00074
00075
00076
00077
00081 class OSG_SYSTEMLIB_DLLMAPPING VRMLWriteAction : public Action
00082 {
00083 public:
00084
00085
00086
00087
00088
00089 enum TraversalMode
00090 {
00091 OSGCollectFC = 0x0001,
00092 OSGWrite = 0x0002
00093 };
00094
00095 enum WriterOption
00096 {
00097 OSGNoOptions = 0x0000,
00098 OSGNoIndent = 0x0001,
00099 OSGNoNormals = 0x0002
00100 };
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 static const char *getClassname(void) { return "VRMLWriteAction"; };
00111
00112
00113 static VRMLWriteAction * create( void );
00114
00115
00116
00117 static void setPrototype(VRMLWriteAction * proto);
00118 static VRMLWriteAction *getPrototype(void);
00119
00120
00121
00122
00123
00124 virtual ~VRMLWriteAction(void);
00125
00126
00127
00128
00129
00130 static void registerEnterDefault( const FieldContainerType &type,
00131 const Functor &func);
00132
00133 static void registerLeaveDefault( const FieldContainerType &type,
00134 const Functor &func);
00135
00136
00137
00138
00139 MaterialPtr getMaterial(void) const;
00140 void setMaterial(MaterialPtr material);
00141
00142 FILE *getFilePtr(void) const;
00143 TraversalMode getMode (void) const;
00144
00145
00146
00147 bool open (const Char8 *szFilename);
00148 void close(void);
00149
00150
00151
00152 void addOptions(UInt32 uiOptions);
00153 void subOptions(UInt32 uiOptions);
00154
00155 UInt32 getOptions(void );
00156
00157 virtual Action::ResultE write(NodePtr node);
00158
00159
00160
00161 bool operator < (const VRMLWriteAction &other) const;
00162
00163 bool operator == (const VRMLWriteAction &other) const;
00164 bool operator != (const VRMLWriteAction &other) const;
00165
00166 protected:
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 virtual std::vector<Functor> *getDefaultEnterFunctors( void );
00195 virtual std::vector<Functor> *getDefaultLeaveFunctors( void );
00196
00197 virtual Action::ResultE apply(std::vector<NodePtr>::iterator begin,
00198 std::vector<NodePtr>::iterator end);
00199
00200 virtual Action::ResultE apply(NodePtr node);
00201
00202 private:
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 typedef Action Inherited;
00213
00214 struct ActionInitializer
00215 {
00216 ActionInitializer(void);
00217 ~ActionInitializer(void);
00218 };
00219
00220 struct FCInfo
00221 {
00222 private:
00223
00224 Int32 _iTimesUsed;
00225 bool _bOwnName;
00226 Char8 *_szName;
00227 bool _bWritten;
00228
00229 public:
00230
00231 FCInfo(void);
00232 FCInfo(const FCInfo &source);
00233 ~FCInfo(void);
00234
00235 Char8 mapChar ( Char8 c);
00236 void convertName( Char8 *&szName);
00237
00238 void setName (const Char8 *szName);
00239 void buildName (const Char8 *szTypename,
00240 UInt32 uiContainerId);
00241 void incUse (void);
00242
00243 UInt32 getUse (void) const;
00244 const Char8 *getName(void) const;
00245
00246 bool getWritten(void) const;
00247 void setWritten (void);
00248
00249
00250 Int32 clear (void);
00251 };
00252
00253
00254
00255
00256
00257 friend struct ActionInitializer;
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267 static char cvsid[];
00268
00269
00270 static VRMLWriteAction * _prototype;
00271
00272
00273 static std::vector<Functor> *_defaultEnterFunctors;
00274 static std::vector<Functor> *_defaultLeaveFunctors;
00275
00276 static ActionInitializer _actionInitializer;
00277
00278
00279
00280
00281
00282
00283 static Action::ResultE writeGroupEnter(CNodePtr &pGroup,
00284 Action *pAction);
00285 static Action::ResultE writeGroupLeave(CNodePtr &pGroup,
00286 Action *pAction);
00287
00288 static Action::ResultE writeMatGroupEnter(CNodePtr &pGroup,
00289 Action *pAction);
00290 static Action::ResultE writeMatGroupLeave(CNodePtr &pGroup,
00291 Action *pAction);
00292
00293 static Action::ResultE writeComponentTransformEnter(CNodePtr &pGroup,
00294 Action *pAction);
00295 static Action::ResultE writeComponentTransformLeave(CNodePtr &pGroup,
00296 Action *pAction);
00297
00298 static Action::ResultE writeTransformEnter(CNodePtr &pGroup,
00299 Action *pAction);
00300 static Action::ResultE writeTransformLeave(CNodePtr &pGroup,
00301 Action *pAction);
00302
00303 static void writePoints ( GeometryPtr pGeo,
00304 FILE *pFile,
00305 VRMLWriteAction *pWriter);
00306 static void writeNormals ( GeometryPtr pGeo,
00307 FILE *pFile,
00308 VRMLWriteAction *pWriter);
00309 static void writeColors ( GeometryPtr pGeo,
00310 FILE *pFile,
00311 VRMLWriteAction *pWriter);
00312 static void writeTexCoords( GeometryPtr pGeo,
00313 FILE *pFile,
00314 VRMLWriteAction *pWriter);
00315
00316 static void writeIndex ( GeometryPtr pGeo,
00317 FILE *pFile,
00318 VRMLWriteAction *pWriter);
00319
00320 static void writeLineIndex( GeometryPtr pGeo,
00321 FILE *pFile,
00322 VRMLWriteAction *pWriter);
00323
00324 static void writeMaterial ( GeometryPtr pGeo,
00325 FILE *pFile,
00326 VRMLWriteAction *pWriter);
00327
00328 static bool writeGeoCommon( NodePtr pNode,
00329 GeometryPtr pGeo,
00330 FILE *pFile,
00331 VRMLWriteAction *pWriter,
00332 const Char8 *setTypename);
00333
00334 static void writePointSet ( NodePtr pNode,
00335 GeometryPtr pGeo,
00336 FILE *pFile,
00337 VRMLWriteAction *pWriter);
00338
00339 static void writeLineSet ( NodePtr pNode,
00340 GeometryPtr pGeo,
00341 FILE *pFile,
00342 VRMLWriteAction *pWriter,
00343 bool bSinglePrimitiveGeo);
00344
00345 static void writeFaceSet ( NodePtr pNode,
00346 GeometryPtr pGeo,
00347 FILE *pFile,
00348 VRMLWriteAction *pWriter,
00349 bool bSinglePrimitiveGeo);
00350
00351 static Action::ResultE writeGeoEnter(CNodePtr &pGroup,
00352 Action *pAction);
00353 static Action::ResultE writeGeoLeave(CNodePtr &pGroup,
00354 Action *pAction);
00355
00356 static bool initializeAction(void);
00357 static bool terminateAction (void);
00358
00359
00360
00361
00362
00363 MaterialPtr _material;
00364
00365 UInt32 _uiIndent;
00366 FILE *_pFile;
00367
00368 TraversalMode _eTraversalMode;
00369 bool _currentUse;
00370 UInt32 _uiOptions;
00371
00372 std::vector<FCInfo> _vFCInfos;
00373
00374
00375
00376
00377 std::vector<FieldContainerPtr> _writtenFCs;
00378
00379
00380
00381
00382
00383
00384
00385 VRMLWriteAction(void);
00386 VRMLWriteAction(const VRMLWriteAction &source);
00387 VRMLWriteAction& operator =(const VRMLWriteAction &source);
00388
00389 void incIndent (UInt32 uiDelta);
00390 void decIndent (UInt32 uiDelta);
00391 void printIndent(void);
00392
00393 void setCurrentUse (bool bVal );
00394 bool isCurrentUse (void );
00395
00396 void addNodeUse (CNodePtr &pNode );
00397 void addContainerUse(FieldContainerPtr &pContainer);
00398
00399 FCInfo *getInfo (FieldContainerPtr &pContainer);
00400
00401 inline bool isWritten(FieldContainerPtr &fc);
00402 inline UInt32 getIndex(FieldContainerPtr &fc);
00403 inline UInt32 setWritten(FieldContainerPtr &fc);
00404 };
00405
00406
00407
00408
00409
00410
00411
00412 typedef VRMLWriteAction *VRMLWriteActionP;
00413
00414 OSG_END_NAMESPACE
00415
00416 #include "OSGVRMLWriteAction.inl"
00417
00418 #endif