- Main Page
- Classes
- Files

- File List
- File Members

# openctmpp.h

Go to the documentation of this file.

    00001 //-----------------------------------------------------------------------------
    00002 // Product:     OpenCTM
    00003 // File:        openctmpp.h
    00004 // Description: C++ wrapper for the OpenCTM API.
    00005 //-----------------------------------------------------------------------------
    00006 // Copyright (c) 2009-2010 Marcus Geelnard
    00007 //
    00008 // This software is provided 'as-is', without any express or implied
    00009 // warranty. In no event will the authors be held liable for any damages
    00010 // arising from the use of this software.
    00011 //
    00012 // Permission is granted to anyone to use this software for any purpose,
    00013 // including commercial applications, and to alter it and redistribute it
    00014 // freely, subject to the following restrictions:
    00015 //
    00016 //     1. The origin of this software must not be misrepresented; you must not
    00017 //     claim that you wrote the original software. If you use this software
    00018 //     in a product, an acknowledgment in the product documentation would be
    00019 //     appreciated but is not required.
    00020 //
    00021 //     2. Altered source versions must be plainly marked as such, and must not
    00022 //     be misrepresented as being the original software.
    00023 //
    00024 //     3. This notice may not be removed or altered from any source
    00025 //     distribution.
    00026 //-----------------------------------------------------------------------------
    00027
    00028 // To disable C++ extensions, define OPENCTM_NO_CPP
    00029 #ifndef OPENCTM_NO_CPP
    00030
    00031 #ifndef __OPENCTMPP_H_
    00032 #define __OPENCTMPP_H_
    00033
    00034 // Just in case (if this file was included from outside openctm.h)...
    00035 #ifndef __OPENCTM_H_
    00036 #include "openctm.h"
    00037 #endif
    00038
    00039 #include <exception>
    00040
    00044 class ctm_error: public std::exception
    00045 {
    00046   private:
    00047     CTMenum mErrorCode;
    00048
    00049   public:
    00050     explicit ctm_error(CTMenum aError)
    00051     {
    00052       mErrorCode = aError;
    00053     }
    00054
    00055     virtual const char* what() const throw()
    00056     {
    00057       return ctmErrorString(mErrorCode);
    00058     }
    00059
    00060     CTMenum error_code() const throw()
    00061     {
    00062       return mErrorCode;
    00063     }
    00064 };
    00065
    00066
    00086
    00087 class CTMimporter {
    00088   private:
    00090     CTMcontext mContext;
    00091
    00094     void CheckError()
    00095     {
    00096       CTMenum err = ctmGetError(mContext);
    00097       if(err != CTM_NONE)
    00098         throw ctm_error(err);
    00099     }
    00100
    00101   public:
    00103     CTMimporter()
    00104     {
    00105       mContext = ctmNewContext(CTM_IMPORT);
    00106     }
    00107
    00109     ~CTMimporter()
    00110     {
    00111       ctmFreeContext(mContext);
    00112     }
    00113
    00115     CTMuint GetInteger(CTMenum aProperty)
    00116     {
    00117       CTMuint res = ctmGetInteger(mContext, aProperty);
    00118       CheckError();
    00119       return res;
    00120     }
    00121
    00123     CTMfloat GetFloat(CTMenum aProperty)
    00124     {
    00125       CTMfloat res = ctmGetFloat(mContext, aProperty);
    00126       CheckError();
    00127       return res;
    00128     }
    00129
    00131     const CTMuint * GetIntegerArray(CTMenum aProperty)
    00132     {
    00133       const CTMuint * res = ctmGetIntegerArray(mContext, aProperty);
    00134       CheckError();
    00135       return res;
    00136     }
    00137
    00139     const CTMfloat * GetFloatArray(CTMenum aProperty)
    00140     {
    00141       const CTMfloat * res = ctmGetFloatArray(mContext, aProperty);
    00142       CheckError();
    00143       return res;
    00144     }
    00145
    00147     CTMenum GetNamedUVMap(const char * aName)
    00148     {
    00149       CTMenum res = ctmGetNamedUVMap(mContext, aName);
    00150       CheckError();
    00151       return res;
    00152     }
    00153
    00155     const char * GetUVMapString(CTMenum aUVMap, CTMenum aProperty)
    00156     {
    00157       const char * res = ctmGetUVMapString(mContext, aUVMap, aProperty);
    00158       CheckError();
    00159       return res;
    00160     }
    00161
    00163     CTMfloat GetUVMapFloat(CTMenum aUVMap, CTMenum aProperty)
    00164     {
    00165       CTMfloat res = ctmGetUVMapFloat(mContext, aUVMap, aProperty);
    00166       CheckError();
    00167       return res;
    00168     }
    00169
    00171     CTMenum GetNamedAttribMap(const char * aName)
    00172     {
    00173       CTMenum res = ctmGetNamedAttribMap(mContext, aName);
    00174       CheckError();
    00175       return res;
    00176     }
    00177
    00179     const char * GetAttribMapString(CTMenum aAttribMap, CTMenum aProperty)
    00180     {
    00181       const char * res = ctmGetAttribMapString(mContext, aAttribMap, aProperty);
    00182       CheckError();
    00183       return res;
    00184     }
    00185
    00187     CTMfloat GetAttribMapFloat(CTMenum aAttribMap, CTMenum aProperty)
    00188     {
    00189       CTMfloat res = ctmGetAttribMapFloat(mContext, aAttribMap, aProperty);
    00190       CheckError();
    00191       return res;
    00192     }
    00193
    00195     const char * GetString(CTMenum aProperty)
    00196     {
    00197       const char * res = ctmGetString(mContext, aProperty);
    00198       CheckError();
    00199       return res;
    00200     }
    00201
    00203     void Load(const char * aFileName)
    00204     {
    00205       ctmLoad(mContext, aFileName);
    00206       CheckError();
    00207     }
    00208
    00210     void LoadCustom(CTMreadfn aReadFn, void * aUserData)
    00211     {
    00212       ctmLoadCustom(mContext, aReadFn, aUserData);
    00213       CheckError();
    00214     }
    00215
    00216     // You can not copy nor assign from one CTMimporter object to another, since
    00217     // the object contains hidden state. By declaring these dummy prototypes
    00218     // without an implementation, you will at least get linker errors if you try
    00219     // to copy or assign a CTMimporter object.
    00220     CTMimporter(const CTMimporter& v);
    00221     CTMimporter& operator=(const CTMimporter& v);
    00222 };
    00223
    00224
    00242
    00243 class CTMexporter {
    00244   private:
    00246     CTMcontext mContext;
    00247
    00250     void CheckError()
    00251     {
    00252       CTMenum err = ctmGetError(mContext);
    00253       if(err != CTM_NONE)
    00254         throw ctm_error(err);
    00255     }
    00256
    00257   public:
    00259     CTMexporter()
    00260     {
    00261       mContext = ctmNewContext(CTM_EXPORT);
    00262     }
    00263
    00265     ~CTMexporter()
    00266     {
    00267       ctmFreeContext(mContext);
    00268     }
    00269
    00271     void CompressionMethod(CTMenum aMethod)
    00272     {
    00273       ctmCompressionMethod(mContext, aMethod);
    00274       CheckError();
    00275     }
    00276
    00278     void CompressionLevel(CTMuint aLevel)
    00279     {
    00280       ctmCompressionLevel(mContext, aLevel);
    00281       CheckError();
    00282     }
    00283
    00285     void VertexPrecision(CTMfloat aPrecision)
    00286     {
    00287       ctmVertexPrecision(mContext, aPrecision);
    00288       CheckError();
    00289     }
    00290
    00292     void VertexPrecisionRel(CTMfloat aRelPrecision)
    00293     {
    00294       ctmVertexPrecisionRel(mContext, aRelPrecision);
    00295       CheckError();
    00296     }
    00297
    00299     void NormalPrecision(CTMfloat aPrecision)
    00300     {
    00301       ctmNormalPrecision(mContext, aPrecision);
    00302       CheckError();
    00303     }
    00304
    00306     void UVCoordPrecision(CTMenum aUVMap, CTMfloat aPrecision)
    00307     {
    00308       ctmUVCoordPrecision(mContext, aUVMap, aPrecision);
    00309       CheckError();
    00310     }
    00311
    00313     void AttribPrecision(CTMenum aAttribMap, CTMfloat aPrecision)
    00314     {
    00315       ctmAttribPrecision(mContext, aAttribMap, aPrecision);
    00316       CheckError();
    00317     }
    00318
    00320     void FileComment(const char * aFileComment)
    00321     {
    00322       ctmFileComment(mContext, aFileComment);
    00323       CheckError();
    00324     }
    00325
    00327     void DefineMesh(const CTMfloat * aVertices, CTMuint aVertexCount,
    00328       const CTMuint * aIndices, CTMuint aTriangleCount,
    00329       const CTMfloat * aNormals)
    00330     {
    00331       ctmDefineMesh(mContext, aVertices, aVertexCount, aIndices, aTriangleCount,
    00332                     aNormals);
    00333       CheckError();
    00334     }
    00335
    00337     CTMenum AddUVMap(const CTMfloat * aUVCoords, const char * aName,
    00338       const char * aFileName)
    00339     {
    00340       CTMenum res = ctmAddUVMap(mContext, aUVCoords, aName, aFileName);
    00341       CheckError();
    00342       return res;
    00343     }
    00344
    00346     CTMenum AddAttribMap(const CTMfloat * aAttribValues, const char * aName)
    00347     {
    00348       CTMenum res = ctmAddAttribMap(mContext, aAttribValues, aName);
    00349       CheckError();
    00350       return res;
    00351     }
    00352
    00354     void Save(const char * aFileName)
    00355     {
    00356       ctmSave(mContext, aFileName);
    00357       CheckError();
    00358     }
    00359
    00361     void SaveCustom(CTMwritefn aWriteFn, void * aUserData)
    00362     {
    00363       ctmSaveCustom(mContext, aWriteFn, aUserData);
    00364       CheckError();
    00365     }
    00366
    00367     // You can not copy nor assign from one CTMexporter object to another, since
    00368     // the object contains hidden state. By declaring these dummy prototypes
    00369     // without an implementation, you will at least get linker errors if you try
    00370     // to copy or assign a CTMexporter object.
    00371     CTMexporter(const CTMexporter& v);
    00372     CTMexporter& operator=(const CTMexporter& v);
    00373 };
    00374
    00375 #endif // __OPENCTMPP_H_
    00376
    00377 #endif // OPENCTM_NO_CPP

Copyright © 2009-2010 Marcus Geelnard — openctm.sourceforge.net