Path Tracer
Exporter.hpp
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
5 
6 Copyright (c) 2006-2020, assimp team
7 
8 All rights reserved.
9 
10 Redistribution and use of this software in source and binary forms,
11 with or without modification, are permitted provided that the following
12 conditions are met:
13 
14 * Redistributions of source code must retain the above
15 copyright notice, this list of conditions and the
16 following disclaimer.
17 
18 * Redistributions in binary form must reproduce the above
19 copyright notice, this list of conditions and the
20 following disclaimer in the documentation and/or other
21 materials provided with the distribution.
22 
23 * Neither the name of the assimp team, nor the names of its
24 contributors may be used to endorse or promote products
25 derived from this software without specific prior
26 written permission of the assimp team.
27 
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 ---------------------------------------------------------------------------
40 */
41 
45 #pragma once
46 #ifndef AI_EXPORT_HPP_INC
47 #define AI_EXPORT_HPP_INC
48 
49 #ifdef __GNUC__
50 #pragma GCC system_header
51 #endif
52 
53 #ifndef ASSIMP_BUILD_NO_EXPORT
54 
55 #include "cexport.h"
56 #include <map>
57 #include <functional>
58 
59 namespace Assimp {
60 
61 class ExporterPimpl;
62 class IOSystem;
63 class ProgressHandler;
64 
65 // ----------------------------------------------------------------------------------
83 class ASSIMP_API ExportProperties;
84 
85 class ASSIMP_API Exporter {
86 public:
88  typedef void (*fpExportFunc)(const char *, IOSystem *, const aiScene *, const ExportProperties *);
89 
94 
95  // Worker function to do the actual exporting
96  fpExportFunc mExportFunction;
97 
98  // Post-processing steps to be executed PRIOR to invoking mExportFunction
99  unsigned int mEnforcePP;
100 
101  // Constructor to fill all entries
102  ExportFormatEntry(const char *pId, const char *pDesc, const char *pExtension, fpExportFunc pFunction, unsigned int pEnforcePP = 0u) {
103  mDescription.id = pId;
104  mDescription.description = pDesc;
105  mDescription.fileExtension = pExtension;
106  mExportFunction = pFunction;
107  mEnforcePP = pEnforcePP;
108  }
109 
111  mExportFunction(),
112  mEnforcePP() {
113  mDescription.id = nullptr;
114  mDescription.description = nullptr;
115  mDescription.fileExtension = nullptr;
116  }
117  };
118 
123 
128 
129  // -------------------------------------------------------------------
144  void SetIOHandler(IOSystem *pIOHandler);
145 
146  // -------------------------------------------------------------------
154 
155  // -------------------------------------------------------------------
160  bool IsDefaultIOHandler() const;
161 
162  // -------------------------------------------------------------------
174 
175  // -------------------------------------------------------------------
193  const aiExportDataBlob *ExportToBlob(const aiScene *pScene, const char *pFormatId,
194  unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr);
195  const aiExportDataBlob *ExportToBlob(const aiScene *pScene, const std::string &pFormatId,
196  unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr);
197 
198  // -------------------------------------------------------------------
231  aiReturn Export(const aiScene *pScene, const char *pFormatId, const char *pPath,
232  unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr);
233  aiReturn Export(const aiScene *pScene, const std::string &pFormatId, const std::string &pPath,
234  unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr);
235 
236  // -------------------------------------------------------------------
246  const char *GetErrorString() const;
247 
248  // -------------------------------------------------------------------
250  const aiExportDataBlob *GetBlob() const;
251 
252  // -------------------------------------------------------------------
257 
258  // -------------------------------------------------------------------
266  void FreeBlob();
267 
268  // -------------------------------------------------------------------
276  size_t GetExportFormatCount() const;
277 
278  // -------------------------------------------------------------------
292  const aiExportFormatDesc *GetExportFormatDescription(size_t pIndex) const;
293 
294  // -------------------------------------------------------------------
306 
307  // -------------------------------------------------------------------
316  void UnregisterExporter(const char *id);
317 
318 protected:
319  // Just because we don't want you to know how we're hacking around.
320  ExporterPimpl *pimpl;
321 };
322 
323 class ASSIMP_API ExportProperties {
324 public:
325  // Data type to store the key hash
326  typedef unsigned int KeyType;
327 
328  // typedefs for our four configuration maps.
329  // We don't need more, so there is no need for a generic solution
330  typedef std::map<KeyType, int> IntPropertyMap;
331  typedef std::map<KeyType, ai_real> FloatPropertyMap;
332  typedef std::map<KeyType, std::string> StringPropertyMap;
333  typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap;
334  typedef std::map<KeyType, std::function<void *(void *)>> CallbackPropertyMap;
335 
336 public:
341 
342  // -------------------------------------------------------------------
349 
350  // -------------------------------------------------------------------
363  bool SetPropertyInteger(const char *szName, int iValue);
364 
365  // -------------------------------------------------------------------
372  bool SetPropertyBool(const char *szName, bool value) {
373  return SetPropertyInteger(szName, value);
374  }
375 
376  // -------------------------------------------------------------------
380  bool SetPropertyFloat(const char *szName, ai_real fValue);
381 
382  // -------------------------------------------------------------------
386  bool SetPropertyString(const char *szName, const std::string &sValue);
387 
388  // -------------------------------------------------------------------
392  bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue);
393 
394  bool SetPropertyCallback(const char *szName, const std::function<void *(void *)> &f);
395 
396  // -------------------------------------------------------------------
409  int GetPropertyInteger(const char *szName,
410  int iErrorReturn = 0xffffffff) const;
411 
412  // -------------------------------------------------------------------
419  bool GetPropertyBool(const char *szName, bool bErrorReturn = false) const {
420  return GetPropertyInteger(szName, bErrorReturn) != 0;
421  }
422 
423  // -------------------------------------------------------------------
427  ai_real GetPropertyFloat(const char *szName,
428  ai_real fErrorReturn = 10e10f) const;
429 
430  // -------------------------------------------------------------------
436  const std::string GetPropertyString(const char *szName,
437  const std::string &sErrorReturn = "") const;
438 
439  // -------------------------------------------------------------------
445  const aiMatrix4x4 GetPropertyMatrix(const char *szName,
446  const aiMatrix4x4 &sErrorReturn = aiMatrix4x4()) const;
447 
448  std::function<void *(void *)> GetPropertyCallback(const char* szName) const;
449 
450  // -------------------------------------------------------------------
454  bool HasPropertyInteger(const char *szName) const;
455 
459  bool HasPropertyBool(const char *szName) const;
460 
464  bool HasPropertyFloat(const char *szName) const;
465 
469  bool HasPropertyString(const char *szName) const;
470 
474  bool HasPropertyMatrix(const char *szName) const;
475 
476  bool HasPropertyCallback(const char *szName) const;
477 
479  IntPropertyMap mIntProperties;
480 
482  FloatPropertyMap mFloatProperties;
483 
485  StringPropertyMap mStringProperties;
486 
488  MatrixPropertyMap mMatrixProperties;
489 
490  CallbackPropertyMap mCallbackProperties;
491 };
492 
493 // ----------------------------------------------------------------------------------
494 inline const aiExportDataBlob *Exporter::ExportToBlob(const aiScene *pScene, const std::string &pFormatId,
495  unsigned int pPreprocessing, const ExportProperties *pProperties) {
496  return ExportToBlob(pScene, pFormatId.c_str(), pPreprocessing, pProperties);
497 }
498 
499 // ----------------------------------------------------------------------------------
500 inline aiReturn Exporter ::Export(const aiScene *pScene, const std::string &pFormatId,
501  const std::string &pPath, unsigned int pPreprocessing,
502  const ExportProperties *pProperties) {
503  return Export(pScene, pFormatId.c_str(), pPath.c_str(), pPreprocessing, pProperties);
504 }
505 
506 } // namespace Assimp
507 
508 #endif // ASSIMP_BUILD_NO_EXPORT
509 #endif // AI_EXPORT_HPP_INC
Assimp::ExportProperties::GetPropertyBool
bool GetPropertyBool(const char *szName, bool bErrorReturn=false) const
Definition: Exporter.hpp:419
Assimp::Exporter::GetErrorString
const char * GetErrorString() const
Assimp::ExportProperties::HasPropertyInteger
bool HasPropertyInteger(const char *szName) const
aiExportDataBlob
Definition: cexport.h:200
Assimp::Exporter::SetProgressHandler
void SetProgressHandler(ProgressHandler *pHandler)
Assimp::Exporter::UnregisterExporter
void UnregisterExporter(const char *id)
Assimp::ExportProperties::HasPropertyFloat
bool HasPropertyFloat(const char *szName) const
Assimp::ExportProperties::mFloatProperties
FloatPropertyMap mFloatProperties
Definition: Exporter.hpp:482
Assimp::ExportProperties::mMatrixProperties
MatrixPropertyMap mMatrixProperties
Definition: Exporter.hpp:488
Assimp::ExportProperties::SetPropertyString
bool SetPropertyString(const char *szName, const std::string &sValue)
Assimp::ExportProperties::mStringProperties
StringPropertyMap mStringProperties
Definition: Exporter.hpp:485
aiExportFormatDesc::description
const char * description
Definition: cexport.h:80
Assimp::Exporter::~Exporter
~Exporter()
The class destructor.
Assimp::ExportProperties::SetPropertyFloat
bool SetPropertyFloat(const char *szName, ai_real fValue)
Assimp::Exporter::GetExportFormatDescription
const aiExportFormatDesc * GetExportFormatDescription(size_t pIndex) const
aiReturn
aiReturn
Definition: types.h:397
Assimp::ExportProperties::ExportProperties
ExportProperties()
Assimp::ExportProperties
class ASSIMP_API ExportProperties
Definition: Exporter.hpp:83
Assimp::ExportProperties::GetPropertyMatrix
const aiMatrix4x4 GetPropertyMatrix(const char *szName, const aiMatrix4x4 &sErrorReturn=aiMatrix4x4()) const
Assimp::Exporter::GetIOHandler
IOSystem * GetIOHandler() const
Assimp::Exporter::GetBlob
const aiExportDataBlob * GetBlob() const
aiExportFormatDesc::fileExtension
const char * fileExtension
Recommended file extension for the exported file in lower case.
Definition: cexport.h:83
Assimp::ExportProperties::mIntProperties
IntPropertyMap mIntProperties
Definition: Exporter.hpp:479
Assimp::Exporter::GetOrphanedBlob
const aiExportDataBlob * GetOrphanedBlob() const
Assimp::ExportProperties::SetPropertyInteger
bool SetPropertyInteger(const char *szName, int iValue)
Assimp::ExportProperties::SetPropertyBool
bool SetPropertyBool(const char *szName, bool value)
Definition: Exporter.hpp:372
Assimp::Exporter::RegisterExporter
aiReturn RegisterExporter(const ExportFormatEntry &desc)
Assimp::Exporter::FreeBlob
void FreeBlob()
Assimp::Exporter::IsDefaultIOHandler
bool IsDefaultIOHandler() const
Assimp::Exporter::ExportToBlob
const aiExportDataBlob * ExportToBlob(const aiScene *pScene, const char *pFormatId, unsigned int pPreprocessing=0u, const ExportProperties *pProperties=nullptr)
aiExportFormatDesc
Describes an file format which Assimp can export to.
Definition: cexport.h:72
Assimp::Exporter
Definition: Exporter.hpp:85
Assimp::ExportProperties::HasPropertyString
bool HasPropertyString(const char *szName) const
Assimp::ExportProperties::HasPropertyMatrix
bool HasPropertyMatrix(const char *szName) const
cexport.h
Defines the C-API for the Assimp export interface.
Assimp::ExportProperties::ExportProperties
ExportProperties(const ExportProperties &other)
Assimp::ExportProperties::HasPropertyBool
bool HasPropertyBool(const char *szName) const
Assimp::Exporter::Export
aiReturn Export(const aiScene *pScene, const char *pFormatId, const char *pPath, unsigned int pPreprocessing=0u, const ExportProperties *pProperties=nullptr)
Assimp::Exporter::Exporter
Exporter()
The class constructor.
Assimp::ExportProperties::GetPropertyFloat
ai_real GetPropertyFloat(const char *szName, ai_real fErrorReturn=10e10f) const
Assimp::ExportProperties
Definition: Exporter.hpp:323
Assimp::Exporter::ExportFormatEntry::mDescription
aiExportFormatDesc mDescription
Public description structure to be returned by aiGetExportFormatDescription()
Definition: Exporter.hpp:93
Assimp::IOSystem
CPP-API: Interface to the file system.
Definition: IOSystem.hpp:93
aiMatrix4x4
Definition: matrix4x4.h:266
Assimp::ExportProperties::GetPropertyString
const std::string GetPropertyString(const char *szName, const std::string &sErrorReturn="") const
Assimp::ExportProperties::SetPropertyMatrix
bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue)
Assimp::Exporter::SetIOHandler
void SetIOHandler(IOSystem *pIOHandler)
Assimp::Exporter::GetExportFormatCount
size_t GetExportFormatCount() const
Assimp::Exporter::ExportFormatEntry
Definition: Exporter.hpp:91
Assimp
Definition: ai_assert.h:50
Assimp::ExportProperties::GetPropertyInteger
int GetPropertyInteger(const char *szName, int iErrorReturn=0xffffffff) const
aiScene
Definition: scene.h:247
aiExportFormatDesc::id
const char * id
Definition: cexport.h:76
Assimp::ProgressHandler
CPP-API: Abstract interface for custom progress report receivers.
Definition: ProgressHandler.hpp:67