Model.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (c) 1996-2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED, AS TO THE CORRECTNESS
00008 //  OF THIS CODE OR ANY DERIVATIVE WORKS WHICH INCORPORATE IT. AUTODESK
00009 //  PROVIDES THE CODE ON AN "AS-IS" BASIS AND EXPLICITLY DISCLAIMS ANY
00010 //  LIABILITY, INCLUDING CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00011 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00012 //
00013 //  Use, duplication, or disclosure by the U.S. Government is subject to
00014 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00015 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00016 //  Data and Computer Software), as applicable.
00017 //
00018 
00019 #ifndef _DWFTK_MODEL_H
00020 #define _DWFTK_MODEL_H
00021 
00022 
00027 
00028 #ifndef DWFTK_READ_ONLY
00029 
00030 
00031 #include "dwfcore/STL.h"
00032 #include "dwfcore/TempFile.h"
00033 #include "dwfcore/OutputStream.h"
00034 using namespace DWFCore;
00035 
00036 #include "dwf/Toolkit.h"
00037 #include "dwf/w3dtk/W3DCamera.h"
00038 #include "dwf/w3dtk/W3DStreamWriter.h"
00039 #include "dwf/package/Units.h"
00040 #include "dwf/package/Content.h"
00041 #include "dwf/publisher/Publisher.h"
00042 #include "dwf/publisher/model/Segment.h"
00043 #include "dwf/publisher/model/StyleSegment.h"
00044 #include "dwf/publisher/model/IncludeSegment.h"
00045 
00046 
00047 
00048 namespace DWFToolkit
00049 {
00050 
00051 //
00052 // fwd declarations
00053 //
00054 class DWFPublishedContentElement;
00055 
00072 class DWFModel : public DWFPublishableSection
00073                , private DWFSegmentHandlerBuilder
00074                , private DWFGeometryHandlerBuilder
00075                , private DWFFeatureHandlerBuilder
00076                , private DWFAttributeHandlerBuilder
00077                _DWFTK_EXPORT_API_MEMORY_CONTROL_BASE_MEMBER
00078 {
00079 
00080 public:
00081 
00085     static char const keNormal_FullResolution = -1;
00089     static char const keNormal_DefaultResolution = 24;
00093     static char const keNormal_MaximumResolution = 72;
00097     static char const keVertex_FullResolution = -1;
00101     static char const keVertex_DefaultResolution = 54;
00105     static char const keVertex_MaximumResolution = 72;
00109     static char const keTextureParameter_FullResolution = -1;
00113     static char const keTextureParameter_DefaultResolution = 54;
00117     static char const keTextureParameter_MaximumResolution = 72;
00118 
00123     typedef enum
00124     {
00125         eHandednessLeft,
00126         eHandednessRight,
00127 
00128         eHandednessNone
00129 
00130     } tePolygonHandedness;
00131 
00139     typedef enum
00140     {
00144         eShaded = 0x01,
00147         eEdges =  0x02
00148 
00149     } teDisplayMode;
00150 
00157     typedef enum
00158     {
00159         eViewCubeCompassOff,
00160         eViewCubeCompassOn,
00161 
00162         eViewCubeCompassNone
00163 
00164     } teViewCubeCompassState;
00165 
00170     typedef enum
00171     {
00175         eInitialView,
00176 
00180         eViewCubeHome,
00181 
00182                 //
00183                 // The customized Front view
00184                 //
00185                 eFrontView
00186 
00187     } teViewType;
00195     typedef enum
00196     {
00197         eBinary,
00198         eASCII
00199 
00200     } teOutputMode;
00201 
00202     typedef _DWFTK_STD_VECTOR(double) tDoubleList;
00203 
00204 public:
00205 
00219     _DWFTK_API
00220     DWFModel( DWFOutputStream& rModelStream,
00221               const DWFString& zModelTitle = "",
00222               const DWFString& zModelSource = "",
00223               const DWFString& zModelSourceID = "",
00224               const DWFString& zModelSourceHRef = "",
00225               const DWFString& zModelLabel = "")
00226         throw();
00227 
00240     _DWFTK_API
00241     DWFModel( const DWFString& zModelTitle = "",
00242               const DWFString& zModelSource = "",
00243               const DWFString& zModelSourceID = "",
00244               const DWFString& zModelSourceHRef = "",
00245               const DWFString& zModelLabel = "" )
00246         throw();
00247 
00253     _DWFTK_API
00254     ~DWFModel()
00255         throw();
00256 
00306     _DWFTK_API
00307     void open( DWFContent*                     pContent,
00308                tePolygonHandedness             ePolygonHandedness,
00309                DWFUnits::teType                eModelUnits,
00310                double*                         pTransform          = NULL,
00311                bool                            bUseDefaultLighting = true,
00312                bool                            bUsePublishedEdges  = false,
00313                bool                            bUseSilhouetteEdges = false,
00314                unsigned int                    nTargetW3DVersion   = 0,
00315                DWFPublisher::teMetadataVersion eMetadataVersion    = DWFPublisher::ePublishContentDefinition )
00316         throw( DWFException );
00317 
00330     _DWFTK_API
00331     unsigned int close()
00332         throw( DWFException );
00333 
00339     _DWFTK_API
00340         void setW3DOutputMode( teOutputMode eMode ) throw();
00341 
00347         _DWFTK_API
00348                 teOutputMode getW3DOutputMode() throw()
00349         {
00350                 return _eOutputMode;
00351         }
00352 
00360     _DWFTK_API
00361     bool streamCompressionEnabled() const
00362         throw()
00363     {
00364         return _bCompressStream;
00365     }
00366 
00374     _DWFTK_API
00375     bool vertexCompressionEnabled() const
00376         throw()
00377     {
00378         return _bCompressVertices;
00379     }
00380 
00392     _DWFTK_API
00393     void enableW3DCompression( bool bEnableStreamCompression = true,
00394                                bool bEnableConnectivityCompression = true,
00395                                bool bEnableGlobalQuantizationCompression = false )
00396         throw( DWFException );
00397 
00413     _DWFTK_API
00414     void enableNormalsCompression( char nTotalNormalBits = keNormal_DefaultResolution )
00415         throw();
00416 
00448     _DWFTK_API
00449     void enableVertexCompression( char nTotalVertexBits = keVertex_DefaultResolution,
00450                                   char nTotalParameterBits = keTextureParameter_FullResolution )
00451         throw();
00452 
00464     _DWFTK_API
00465     void disableAllCompression()
00466         throw( DWFException );
00467 
00474     _DWFTK_API
00475     void publish( DWFPublisher& rPublisher )
00476         throw( DWFException );
00477 
00478         //
00479         //
00480         // Scene Graphics
00481         //
00482         //
00483 
00490     _DWFTK_API
00491     DWFSegment openSegment()
00492         throw( DWFException );
00493 
00500     _DWFTK_API
00501     DWFIncludeSegment openIncludeSegment()
00502         throw( DWFException );
00503 
00510     _DWFTK_API
00511     DWFStyleSegment openStyleSegment()
00512         throw( DWFException );
00513 
00525     _DWFTK_API
00526     void createView( const char*    zName,
00527                      W3DCamera&     rViewCamera )
00528         throw( DWFException );
00529 
00536         //                                                              if eFrontView, this is a Front view defined by custormer
00541     _DWFTK_API
00542     void createView( teViewType         eCameraType,
00543                      const DWFString&   zName,
00544                      W3DCamera&         rViewCamera )
00545         throw( DWFException );
00546 
00562     _DWFTK_API
00563     void setBoundingCube( float nMinX,   float nMinY,    float nMinZ,
00564                           float nMaxX,   float nMaxY,    float nMaxZ )
00565          throw( DWFException );
00566 
00580     _DWFTK_API
00581     void setBoundingSphere( float nCenterX, float nCenterY, float nCenterZ,
00582                             float nRadius )
00583         throw( DWFException );
00584 
00592     _DWFTK_API
00593     void setEdgeColor( float anRGB[3] )
00594         throw();
00595 
00604     _DWFTK_API
00605     void setViewCubeCompassState( teViewCubeCompassState eCompassState )
00606         throw();
00607 
00614     _DWFTK_API
00615     void setViewCubeNorthAngle( float fAngle )
00616         throw();
00617 
00618         //
00619         //
00620         // Publishable features
00621         //
00622         //
00623 
00630     _DWFTK_API
00631     const W3DCamera* getDefaultView() const
00632         throw();
00633 
00644     _DWFTK_API
00645     bool getDefinedView( teViewType teViewType, DWFString& zName, W3DCamera& rView ) const
00646         throw( DWFException );
00647 
00660     _DWFTK_API
00661     void getBoundingVolume( tDoubleList& rBounds ) const
00662         throw();
00663 
00675     _DWFTK_API
00676     bool useModelLighting() const
00677         throw();
00678 
00689     _DWFTK_API
00690     bool useSilhouetteEdges() const
00691         throw();
00692 
00699     _DWFTK_API
00700     const float* const getEdgeColor() const
00701         throw();
00702 
00709     _DWFTK_API
00710     const float* const getViewCubeAngleOfNorth() const
00711         throw();
00712 
00720     _DWFTK_API
00721     DWFUnits::teType getUnits() const
00722         throw();
00723 
00738     _DWFTK_API
00739     void getTransform( double* pTransform ) const
00740         throw();
00741 
00748     _DWFTK_API
00749     tePolygonHandedness getPolygonHandedness() const
00750         throw();
00751 
00758     _DWFTK_API
00759     teViewCubeCompassState getViewCubeCompassState() const
00760         throw();
00761 
00769     _DWFTK_API
00770     virtual void setDisplayMode( unsigned int nDisplayMode )
00771         throw();
00772     
00780     _DWFTK_API
00781     virtual unsigned int getDisplayMode() const
00782         throw();
00783 
00784         //
00785         //
00786         // Publishable Interface
00787         //
00788         //
00789 
00793     _DWFTK_API
00794     virtual double getVersion() const
00795         throw()
00796     {
00797         return _DWF_FORMAT_EMODEL_VERSION_CURRENT_FLOAT;
00798     }
00799 
00803     _DWFTK_API
00804     const DWFString& getMIMEType()
00805         throw( DWFException );
00806 
00810     _DWFTK_API
00811     DWFInputStream* getInputStream()
00812         throw( DWFException );
00813 
00817     _DWFTK_API
00818     void embedFont( DWFEmbeddedFont* pFont )
00819         throw( DWFException );
00820 
00824     _DWFTK_API
00825     void addResource( DWFPublishableResource* pResource )
00826         throw( DWFException );
00827 
00831     _DWFTK_API
00832     DWFIterator<DWFPublishableResource*>* getResources()
00833         throw( DWFException );
00834 
00841     _DWFTK_API
00842     DWFContent* getContent()
00843         throw()
00844     {
00845         return _pContent;
00846     }
00847 
00855     _DWFTK_API
00856     const DWFString& id()
00857         throw()
00858     {
00859         return _zTempID;
00860     }
00861 
00869     _DWFTK_API
00870     void setId( const DWFString& zID )
00871         throw()
00872     {
00873         _zTempID = zID;
00874     }
00875 
00884     _DWFTK_API
00885     int keyToIndex(const DWFSegment::tKey &rKey)
00886         throw( DWFException );
00887 
00888 private:
00889 
00893     DWFPublishedObject* makePublishedObject( DWFPublishedObject::tKey nKey,
00894                                              const DWFString&      zName )
00895         throw( DWFException );
00896 
00900     DWFPublishedObject& findPublishedObject( DWFPublishedObject::tKey nKey )
00901         throw( DWFException );
00902 
00903 private:
00904 
00905         //
00906         //
00907         // SegmentHandlerBuilder Interface
00908         //
00909         //
00910 
00911     TK_Close_Segment& getCloseSegmentHandler()
00912         throw( DWFException );
00913 
00914     TK_Open_Segment& getOpenSegmentHandler()
00915         throw( DWFException );
00916 
00917     TK_Referenced_Segment& getIncludeSegmentHandler()
00918         throw( DWFException );
00919 
00920     TK_Referenced_Segment& getStyleSegmentHandler()
00921         throw( DWFException );
00922 
00923         //
00924         //
00925         // GeometryHandlerBuilder Interface
00926         //
00927         //
00928 
00929     TK_Area_Light& getAreaLightHandler()
00930         throw( DWFException );
00931 
00932     TK_Circle& getCircleHandler()
00933         throw( DWFException );
00934 
00935     TK_Circle& getCircularArcHandler()
00936         throw( DWFException );
00937 
00938     TK_Circle& getCircularChordHandler()
00939         throw( DWFException );
00940 
00941     TK_Circle& getCircularWedgeHandler()
00942         throw( DWFException );
00943 
00944     TK_Cutting_Plane& getCuttingPlaneHandler()
00945         throw( DWFException );
00946 
00947     TK_Cylinder& getCylinderHandler()
00948         throw( DWFException );
00949 
00950     TK_Point& getDistantLightHandler()
00951         throw( DWFException );
00952 
00953     TK_Ellipse& getEllipseHandler()
00954         throw( DWFException );
00955 
00956     TK_Ellipse& getEllipticalArcHandler()
00957         throw( DWFException );
00958 
00959     TK_Glyph_Definition& getGlyphDefinitionHandler()
00960         throw( DWFException );
00961 
00962     TK_Grid& getGridHandler()
00963         throw( DWFException );
00964 
00965     TK_Image& getImageHandler()
00966         throw( DWFException );
00967 
00968     TK_Line& getLineHandler()
00969         throw( DWFException );
00970 
00971     TK_Point& getLocalLightHandler()
00972         throw( DWFException );
00973 
00974     TK_Point& getMarkerHandler()
00975         throw( DWFException );
00976 
00977     TK_Mesh& getMeshHandler()
00978         throw( DWFException );
00979 
00980     TK_NURBS_Curve& getNURBSCurveHandler()
00981         throw( DWFException );
00982 
00983     TK_NURBS_Surface& getNURBSSurfaceHandler()
00984         throw( DWFException );
00985 
00986     TK_PolyCylinder& getPolyCylinderHandler()
00987         throw( DWFException );
00988 
00989     TK_Polypoint& getPolygonHandler()
00990         throw( DWFException );
00991 
00992     TK_Polypoint& getPolylineHandler()
00993         throw( DWFException );
00994 
00995     //
00996     // IMPORTANT:   Setting this flag to true when you data is not in tristrips may produce garbage.
00997     //
00998     // bTriStripsOnly - the shell is assumed to contain triangles only and may not contain holes,
00999     //                  and the "faces" are actually the way that vertices are connected into triangle strips.
01000     //                  Start with the length of the strip, followed by the vertex indices to be connected.
01001     //                  The first 3 vertices form a triangle, and every additional vertex is
01002     //                  combined with the two previous ones to  define one additional triangle.
01003     //                  Exactly as with OpenGL's GL_TRIANGLE_STRIP primitive,
01004     //                  the orientation of every even triangle is reversed, beginning with the second.
01005     //
01006     // bDisableOptimization - Disable vertex and face optimization algorithm just before stream serialization
01007     //                          This optimization is on by default, it's tolerance parameters may be tuned
01008     //                          by calling optimize() (this method can also be used to disable the process)
01009     //
01010     TK_Shell& getShellHandler( bool bTriStripsOnly = false,
01011                                bool bDisableOptimization = false )
01012         throw( DWFException );
01013 
01014     TK_Sphere& getSphereHandler()
01015         throw( DWFException );
01016 
01017     TK_Spot_Light& getSpotLightHandler()
01018         throw( DWFException );
01019 
01020     TK_Text& getTextHandler()
01021         throw( DWFException );
01022 
01023     TK_Text& getTextWithEncodingHandler()
01024         throw( DWFException );
01025 
01026         //
01027         //
01028         // FeatureHandlerBuilder Interface
01029         //
01030         //
01031 
01032     TK_Texture& getTextureHandler()
01033         throw( DWFException );
01034 
01035     TK_Matrix& getTextureMatrixHandler()
01036         throw( DWFException );
01037 
01038         //
01039         //
01040         // AttributeHandlerBuilder Interface
01041         //
01042         //
01043 
01044     TK_Camera& getCameraHandler()
01045         throw( DWFException );
01046 
01047     TK_Color& getColorHandler()
01048         throw( DWFException );
01049 
01050     TK_Color_Map& getColorMapHandler()
01051         throw( DWFException );
01052 
01053     TK_Color_RGB& getColorRGBHandler()
01054         throw( DWFException );
01055 
01056     TK_Named& getEdgePatternHandler()
01057         throw( DWFException );
01058 
01059     TK_Size& getEdgeWeightHandler()
01060         throw( DWFException );
01061 
01062     TK_Enumerated& getFacePatternHandler()
01063         throw( DWFException );
01064 
01065     TK_Enumerated& getHandednessHandler()
01066         throw( DWFException );
01067 
01068     TK_Heuristics& getHeuristicsHandler()
01069         throw( DWFException );
01070 
01071     TK_Named& getLinePatternHandler()
01072         throw( DWFException );
01073 
01074     TK_Line_Style& getLineStyleHandler()
01075         throw( DWFException );
01076 
01077     TK_Size& getLineWeightHandler()
01078         throw( DWFException );
01079 
01080     TK_Size& getMarkerSizeHandler()
01081         throw( DWFException );
01082 
01083     TK_Enumerated& getMarkerSymbolHandler()
01084         throw( DWFException );
01085 
01086     TK_Matrix& getModellingMatrixHandler()
01087         throw( DWFException );
01088 
01089     TK_Rendering_Options& getRenderingOptionsHandler()
01090         throw( DWFException );
01091 
01092     TK_Selectability& getSelectabilityHandler()
01093         throw( DWFException );
01094 
01095     TK_Enumerated& getTextAlignmentHandler()
01096         throw( DWFException );
01097 
01098     TK_Text_Font& getTextFontHandler()
01099         throw( DWFException );
01100 
01101     TK_Point& getTextPathHandler()
01102         throw( DWFException );
01103 
01104     TK_Size& getTextSpacingHandler()
01105         throw( DWFException );
01106 
01107     TK_User_Options& getUserOptionsHandler()
01108         throw( DWFException );
01109 
01110     TK_Unicode_Options& getUnicodeOptionsHandler()
01111         throw( DWFException );
01112 
01113     TK_Visibility& getVisibilityHandler()
01114         throw( DWFException );
01115 
01116     TK_Camera& getViewHandler()
01117         throw( DWFException );
01118 
01119     TK_Window& getWindowHandler()
01120         throw( DWFException );
01121 
01122     TK_Enumerated& getWindowFrameHandler()
01123         throw( DWFException );
01124 
01125     TK_Enumerated& getWindowPatternHandler()
01126         throw( DWFException );
01127 
01128     void openLocalLightAttributes()
01129         throw( DWFException );
01130 
01131     void closeLocalLightAttributes()
01132         throw( DWFException );
01133 
01134 private:
01135 
01136     _DWFTK_API
01137     void _visitPublishedContentElements( DWFPublisher& rPublisher )
01138         throw( DWFException );
01139 
01140     _DWFTK_API
01141     void _ensurePublishedContentElementIndex( DWFPublishedContentElement* pElement )
01142         throw();
01143 
01144     _DWFTK_API
01145     void _visitPublishedObjects( DWFPublisher& rPublisher )
01146         throw( DWFException );
01147 
01148 private:
01149 
01150     teOutputMode            _eOutputMode;
01151     bool                    _bOpen;
01152     bool                    _bCompressStream;
01153     bool                    _bCompressVertices;
01154     bool                    _bStreamDefaults;
01155     bool                    _bBoundingVolumeSet;
01156     bool                    _bUseDefaultLighting;
01157     bool                    _bModelLightsUsed;
01158     bool                    _bUseSilhouetteEdges;
01159     bool                    _bSetEdgeColor;
01160     bool                    _bOpenLocalLightAttributes;
01161     bool                    _bSetNorthAngle;
01162     float                   _anEdgeColor[3];
01163     float                   _fNorthAngle;
01164 
01165     DWFUnits::teType        _eUnits;
01166     double                  _anUnitsTransform[16];
01167     tePolygonHandedness     _eHandedness;
01168     teViewCubeCompassState  _eCompassState;     
01169 
01170     unsigned int            _nStyleSegments;
01171 
01172     DWFString               _zMIME;
01173 
01174     DWFTempFile*            _pW3DFile;
01175     DWFInputStream*         _pW3DFileStream;
01176     char*                   _pVersionBuffer;
01177 
01178     BStreamFileToolkit      _oToolkit;
01179     W3DStreamWriter*        _pW3DStreamWriter;
01180     W3DCamera*              _pDefaultViewCamera;
01181     W3DCamera*              _pInitialViewCamera;
01182     DWFString               _zDefaultViewName;
01183 
01184     tDoubleList             _oBoundingVolume;
01185     DWFEmbeddedFont::tList          _oEmbeddedFonts;
01186     DWFPublishableResource::tList   _oResources;
01187 
01188     //
01189     //  Since 7.2.0
01190     //
01191 
01192     DWFPublishedObject::Factory*    _pPublishedObjectFactory;
01193     //
01194     //  The content library is the storage area for the metadata associated with the model
01195     //
01196     DWFContent*                     _pContent;
01197     //
01198     //  The content stores a mapping from an ID of the DWFInstance generators to the actual
01199     //  instances. Until a section is generated for the model, this is the ID used.
01200     //
01201     DWFString                       _zTempID;
01202 
01203     DWFPublisher::teMetadataVersion _eMetadataVersion;
01204 
01205     unsigned int                    _nDisplayMode;
01206 
01207     W3DCamera*                      _pViewCubeHome;
01208     DWFString                       _zViewCubeHomeName;
01209 
01210         //
01211         // For Front View
01212         //
01213     W3DCamera*                      _pFrontView;
01214     DWFString                       _zFrontViewName;
01215 
01216 private:
01217 
01218     //
01219     //
01220     //
01221     class _SpecialBufferedInputStream : public DWFInputStream
01222                                         _DWFTK_EXPORT_API_MEMORY_CONTROL_BASE_MEMBER
01223     {
01224     public:
01225 
01226         _SpecialBufferedInputStream( char*              pBuffer,
01227                                      unsigned int       nBufferBytes,
01228                                      DWFInputStream*    pStream )
01229             throw();
01230 
01231         virtual ~_SpecialBufferedInputStream()
01232             throw();
01233 
01234         size_t available() const
01235             throw( DWFException );
01236 
01237         size_t read( void*  pBuffer,
01238                      size_t nBytesToRead )
01239             throw( DWFException );
01240 
01241         off_t seek( int    eOrigin,
01242                     off_t  nOffset )
01243             throw( DWFException );
01244 
01245     private:
01246 
01247         unsigned int    _nBufferBytes;
01248         unsigned int    _nBufferBytesRead;
01249         char*           _pBuffer;
01250         DWFInputStream* _pStream;
01251     };
01252 
01253 private:
01254 
01255     //
01256     // Not Implemented
01257     //
01258 
01259     DWFModel( const DWFModel& );
01260     DWFModel& operator=( const DWFModel& );
01261 };
01262 
01263 
01264 }
01265 
01266 
01267 #endif
01268 #endif

Generated on Tue Jan 6 22:40:04 2009 for Autodesk DWF Toolkit by  doxygen 1.4.5