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 OSGPixelTextures = 0x0004
00101 };
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 static const char *getClassname(void) { return "VRMLWriteAction"; };
00112
00113
00114 static VRMLWriteAction * create( void );
00115
00116
00117
00118 static void setPrototype(VRMLWriteAction * proto);
00119 static VRMLWriteAction *getPrototype(void);
00120
00121
00122
00123
00124
00125 virtual ~VRMLWriteAction(void);
00126
00127
00128
00129
00130
00131 static void registerEnterDefault( const FieldContainerType &type,
00132 const Functor &func);
00133
00134 static void registerLeaveDefault( const FieldContainerType &type,
00135 const Functor &func);
00136
00137
00138
00139
00140 MaterialPtr getMaterial(void) const;
00141 void setMaterial(MaterialPtr material);
00142
00143 FILE *getFilePtr(void) const;
00144 TraversalMode getMode (void) const;
00145
00146
00147
00148 bool open (const Char8 *szFilename);
00149 void close(void);
00150
00151
00152
00153 void addOptions(UInt32 uiOptions);
00154 void subOptions(UInt32 uiOptions);
00155
00156 UInt32 getOptions(void );
00157
00158 virtual Action::ResultE write(NodePtr node);
00159
00160
00161
00162 bool operator < (const VRMLWriteAction &other) const;
00163
00164 bool operator == (const VRMLWriteAction &other) const;
00165 bool operator != (const VRMLWriteAction &other) const;
00166
00167 protected:
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
00195 virtual std::vector<Functor> *getDefaultEnterFunctors( void );
00196 virtual std::vector<Functor> *getDefaultLeaveFunctors( void );
00197
00198 virtual Action::ResultE apply(std::vector<NodePtr>::iterator begin,
00199 std::vector<NodePtr>::iterator end);
00200
00201 virtual Action::ResultE apply(NodePtr node);
00202
00203 private:
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 typedef Action Inherited;
00214
00215 struct ActionInitializer
00216 {
00217 ActionInitializer(void);
00218 ~ActionInitializer(void);
00219 };
00220
00221 struct FCInfo
00222 {
00223 private:
00224
00225 Int32 _iTimesUsed;
00226 bool _bOwnName;
00227 Char8 *_szName;
00228 bool _bWritten;
00229
00230 public:
00231
00232 FCInfo(void);
00233 FCInfo(const FCInfo &source);
00234 ~FCInfo(void);
00235
00236 Char8 mapChar ( Char8 c);
00237 void convertName( Char8 *&szName);
00238
00239 void setName (const Char8 *szName);
00240 void buildName (const Char8 *szTypename,
00241 UInt32 uiContainerId);
00242 void incUse (void);
00243
00244 UInt32 getUse (void) const;
00245 const Char8 *getName(void) const;
00246
00247 bool getWritten(void) const;
00248 void setWritten (void);
00249
00250
00251 Int32 clear (void);
00252 };
00253
00254
00255
00256
00257
00258 friend struct ActionInitializer;
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 static char cvsid[];
00269
00270
00271 static VRMLWriteAction * _prototype;
00272
00273
00274 static std::vector<Functor> *_defaultEnterFunctors;
00275 static std::vector<Functor> *_defaultLeaveFunctors;
00276
00277 static ActionInitializer _actionInitializer;
00278
00279
00280
00281
00282
00283
00284 static Action::ResultE writeGroupEnter(CNodePtr &pGroup,
00285 Action *pAction);
00286 static Action::ResultE writeGroupLeave(CNodePtr &pGroup,
00287 Action *pAction);
00288
00289 static Action::ResultE writeMatGroupEnter(CNodePtr &pGroup,
00290 Action *pAction);
00291 static Action::ResultE writeMatGroupLeave(CNodePtr &pGroup,
00292 Action *pAction);
00293
00294 static Action::ResultE writeComponentTransformEnter(CNodePtr &pGroup,
00295 Action *pAction);
00296 static Action::ResultE writeComponentTransformLeave(CNodePtr &pGroup,
00297 Action *pAction);
00298
00299 static Action::ResultE writeTransformEnter(CNodePtr &pGroup,
00300 Action *pAction);
00301 static Action::ResultE writeTransformLeave(CNodePtr &pGroup,
00302 Action *pAction);
00303
00304 static void writePoints ( GeometryPtr pGeo,
00305 FILE *pFile,
00306 VRMLWriteAction *pWriter);
00307 static void writeNormals ( GeometryPtr pGeo,
00308 FILE *pFile,
00309 VRMLWriteAction *pWriter);
00310 static void writeColors ( GeometryPtr pGeo,
00311 FILE *pFile,
00312 VRMLWriteAction *pWriter);
00313 static void writeTexCoords( GeometryPtr pGeo,
00314 FILE *pFile,
00315 VRMLWriteAction *pWriter);
00316
00317 static void writeIndex ( GeometryPtr pGeo,
00318 FILE *pFile,
00319 VRMLWriteAction *pWriter);
00320
00321 static void writeLineIndex( GeometryPtr pGeo,
00322 FILE *pFile,
00323 VRMLWriteAction *pWriter);
00324
00325 static void writeMaterial ( GeometryPtr pGeo,
00326 FILE *pFile,
00327 VRMLWriteAction *pWriter);
00328
00329 static bool writeGeoCommon( NodePtr pNode,
00330 GeometryPtr pGeo,
00331 FILE *pFile,
00332 VRMLWriteAction *pWriter,
00333 const Char8 *setTypename);
00334
00335 static void writePointSet ( NodePtr pNode,
00336 GeometryPtr pGeo,
00337 FILE *pFile,
00338 VRMLWriteAction *pWriter);
00339
00340 static void writeLineSet ( NodePtr pNode,
00341 GeometryPtr pGeo,
00342 FILE *pFile,
00343 VRMLWriteAction *pWriter,
00344 bool bSinglePrimitiveGeo);
00345
00346 static void writeFaceSet ( NodePtr pNode,
00347 GeometryPtr pGeo,
00348 FILE *pFile,
00349 VRMLWriteAction *pWriter,
00350 bool bSinglePrimitiveGeo);
00351
00352 static Action::ResultE writeGeoEnter(CNodePtr &pGroup,
00353 Action *pAction);
00354 static Action::ResultE writeGeoLeave(CNodePtr &pGroup,
00355 Action *pAction);
00356
00357 static bool initializeAction(void);
00358 static bool terminateAction (void);
00359
00360
00361
00362
00363
00364 MaterialPtr _material;
00365
00366 UInt32 _uiIndent;
00367 FILE *_pFile;
00368
00369 TraversalMode _eTraversalMode;
00370 bool _currentUse;
00371 UInt32 _uiOptions;
00372
00373 std::vector<FCInfo> _vFCInfos;
00374
00375
00376
00377
00378 std::vector<FieldContainerPtr> _writtenFCs;
00379
00380 UInt32 _nodeCount;
00381 UInt32 _currentNodeCount;
00382
00383
00384
00385
00386
00387
00388
00389 VRMLWriteAction(void);
00390 VRMLWriteAction(const VRMLWriteAction &source);
00391 VRMLWriteAction& operator =(const VRMLWriteAction &source);
00392
00393 void incIndent (UInt32 uiDelta);
00394 void decIndent (UInt32 uiDelta);
00395 void printIndent(void);
00396
00397 void setCurrentUse (bool bVal );
00398 bool isCurrentUse (void );
00399
00400 void addNodeUse (CNodePtr &pNode );
00401 void addContainerUse(FieldContainerPtr &pContainer);
00402
00403 FCInfo *getInfo (FieldContainerPtr &pContainer);
00404
00405 void updateProgress (void );
00406
00407 inline bool isWritten(FieldContainerPtr &fc);
00408 inline UInt32 getIndex(FieldContainerPtr &fc);
00409 inline UInt32 setWritten(FieldContainerPtr &fc);
00410 };
00411
00412
00413
00414
00415
00416
00417
00418 typedef VRMLWriteAction *VRMLWriteActionP;
00419
00420 OSG_END_NAMESPACE
00421
00422 #include "OSGVRMLWriteAction.inl"
00423
00424 #endif