Path Tracer
BaseImporter.h
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4 
5 Copyright (c) 2006-2020, assimp team
6 
7 All rights reserved.
8 
9 Redistribution and use of this software in source and binary forms,
10 with or without modification, are permitted provided that the
11 following conditions are met:
12 
13 * Redistributions of source code must retain the above
14  copyright notice, this list of conditions and the
15  following disclaimer.
16 
17 * Redistributions in binary form must reproduce the above
18  copyright notice, this list of conditions and the
19  following disclaimer in the documentation and/or other
20  materials provided with the distribution.
21 
22 * Neither the name of the assimp team, nor the names of its
23  contributors may be used to endorse or promote products
24  derived from this software without specific prior
25  written permission of the assimp team.
26 
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 
39 ----------------------------------------------------------------------
40 */
41 
43 
44 #pragma once
45 #ifndef INCLUDED_AI_BASEIMPORTER_H
46 #define INCLUDED_AI_BASEIMPORTER_H
47 
48 #ifdef __GNUC__
49 #pragma GCC system_header
50 #endif
51 
52 #include "Exceptional.h"
53 
54 #include <assimp/ai_assert.h>
55 #include <assimp/types.h>
57 #include <map>
58 #include <set>
59 #include <vector>
60 #include <memory>
61 
62 struct aiScene;
63 struct aiImporterDesc;
64 
65 namespace Assimp {
66 
67 class Importer;
68 class IOSystem;
69 class BaseProcess;
70 class SharedPostProcessInfo;
71 class IOStream;
72 
73 // utility to do char4 to uint32 in a portable manner
74 #define AI_MAKE_MAGIC(string) ((uint32_t)((string[0] << 24) + \
75  (string[1] << 16) + (string[2] << 8) + string[3]))
76 
77 // ---------------------------------------------------------------------------
87 class ASSIMP_API BaseImporter {
88  friend class Importer;
89 
90 public:
92  BaseImporter() AI_NO_EXCEPT;
93 
95  virtual ~BaseImporter();
96 
97  // -------------------------------------------------------------------
115  virtual bool CanRead(
116  const std::string &pFile,
117  IOSystem *pIOHandler,
118  bool checkSig) const = 0;
119 
120  // -------------------------------------------------------------------
139  aiScene *ReadFile(
140  Importer *pImp,
141  const std::string &pFile,
142  IOSystem *pIOHandler);
143 
144  // -------------------------------------------------------------------
151  const std::string &GetErrorText() const {
152  return m_ErrorText;
153  }
154 
155  // -------------------------------------------------------------------
161  const std::exception_ptr& GetException() const {
162  return m_Exception;
163  }
164 
165  // -------------------------------------------------------------------
171  virtual void SetupProperties(
172  const Importer *pImp);
173 
174  // -------------------------------------------------------------------
177  virtual const aiImporterDesc *GetInfo() const = 0;
178 
182  virtual void SetFileScale(double scale) {
183  fileScale = scale;
184  }
185 
186  virtual double GetFileScale() const {
187  return fileScale;
188  }
189 
190  enum ImporterUnits {
191  M,
192  MM,
193  CM,
194  INCHES,
195  FEET
196  };
197 
207  std::map<ImporterUnits, double> importerUnits;
208 
209  virtual void SetApplicationUnits(const ImporterUnits &unit) {
210  importerScale = importerUnits[unit];
211  applicationUnits = unit;
212  }
213 
214  virtual const ImporterUnits &GetApplicationUnits() {
215  return applicationUnits;
216  }
217 
218  // -------------------------------------------------------------------
223  void GetExtensionList(std::set<std::string> &extensions);
224 
225 protected:
226  ImporterUnits applicationUnits = ImporterUnits::M;
227  double importerScale = 1.0;
228  double fileScale = 1.0;
229 
230  // -------------------------------------------------------------------
274  virtual void InternReadFile(
275  const std::string &pFile,
276  aiScene *pScene,
277  IOSystem *pIOHandler) = 0;
278 
279 public: // static utilities
280  // -------------------------------------------------------------------
295  IOSystem *pIOSystem,
296  const std::string &file,
297  const char **tokens,
298  unsigned int numTokens,
299  unsigned int searchBytes = 200,
300  bool tokensSol = false,
301  bool noAlphaBeforeTokens = false);
302 
303  // -------------------------------------------------------------------
311  static bool SimpleExtensionCheck(
312  const std::string &pFile,
313  const char *ext0,
314  const char *ext1 = nullptr,
315  const char *ext2 = nullptr);
316 
317  // -------------------------------------------------------------------
322  static std::string GetExtension(
323  const std::string &pFile);
324 
325  // -------------------------------------------------------------------
339  static bool CheckMagicToken(
340  IOSystem *pIOHandler,
341  const std::string &pFile,
342  const void *magic,
343  unsigned int num,
344  unsigned int offset = 0,
345  unsigned int size = 4);
346 
347  // -------------------------------------------------------------------
353  static void ConvertToUTF8(
354  std::vector<char> &data);
355 
356  // -------------------------------------------------------------------
363  std::string &data);
364 
365  // -------------------------------------------------------------------
368  ALLOW_EMPTY,
369  FORBID_EMPTY
370  };
371 
372  // -------------------------------------------------------------------
381  static void TextFileToBuffer(
382  IOStream *stream,
383  std::vector<char> &data,
384  TextFileMode mode = FORBID_EMPTY);
385 
386  // -------------------------------------------------------------------
391  template <typename T>
392  AI_FORCE_INLINE static void CopyVector(
393  std::vector<T> &vec,
394  T *&out,
395  unsigned int &outLength) {
396  outLength = unsigned(vec.size());
397  if (outLength) {
398  out = new T[outLength];
399  std::swap_ranges(vec.begin(), vec.end(), out);
400  }
401  }
402 
403  // -------------------------------------------------------------------
408  template <typename T>
409  AI_FORCE_INLINE static void CopyVector(
410  std::vector<std::unique_ptr<T> > &vec,
411  T **&out,
412  unsigned int &outLength) {
413  outLength = unsigned(vec.size());
414  if (outLength) {
415  out = new T*[outLength];
416  T** outPtr = out;
417  std::for_each(vec.begin(), vec.end(), [&outPtr](std::unique_ptr<T>& uPtr){*outPtr = uPtr.release(); ++outPtr; });
418  }
419  }
420 
421 private:
422  /* Pushes state into importer for the importer scale */
423  virtual void UpdateImporterScale(Importer *pImp);
424 
425 protected:
427  std::string m_ErrorText;
429  std::exception_ptr m_Exception;
432 };
433 
434 } // end of namespace Assimp
435 
436 #endif // AI_BASEIMPORTER_H_INC
Assimp::BaseImporter::SetFileScale
virtual void SetFileScale(double scale)
Definition: BaseImporter.h:182
Assimp::BaseImporter::SimpleExtensionCheck
static bool SimpleExtensionCheck(const std::string &pFile, const char *ext0, const char *ext1=nullptr, const char *ext2=nullptr)
Check whether a file has a specific file extension.
Assimp::BaseImporter::BaseImporter
BaseImporter() AI_NO_EXCEPT
types.h
Assimp::Importer
Definition: Importer.hpp:120
Assimp::BaseImporter::CheckMagicToken
static bool CheckMagicToken(IOSystem *pIOHandler, const std::string &pFile, const void *magic, unsigned int num, unsigned int offset=0, unsigned int size=4)
Check whether a file starts with one or more magic tokens.
Assimp::BaseImporter::GetException
const std::exception_ptr & GetException() const
Definition: BaseImporter.h:161
ProgressHandler.hpp
Abstract base class 'ProgressHandler'.
Assimp::BaseImporter::ConvertUTF8toISO8859_1
static void ConvertUTF8toISO8859_1(std::string &data)
Assimp::BaseImporter::m_ErrorText
std::string m_ErrorText
Error description in case there was one.
Definition: BaseImporter.h:427
Assimp::BaseImporter::ConvertToUTF8
static void ConvertToUTF8(std::vector< char > &data)
Assimp::BaseImporter::TextFileMode
TextFileMode
Enum to define, if empty files are ok or not.
Definition: BaseImporter.h:367
Assimp::BaseImporter::GetExtension
static std::string GetExtension(const std::string &pFile)
Extract file extension from a string.
Assimp::BaseImporter::GetInfo
virtual const aiImporterDesc * GetInfo() const =0
Assimp::BaseImporter::GetExtensionList
void GetExtensionList(std::set< std::string > &extensions)
aiImporterDesc
Definition: importerdesc.h:91
Assimp::BaseImporter::TextFileToBuffer
static void TextFileToBuffer(IOStream *stream, std::vector< char > &data, TextFileMode mode=FORBID_EMPTY)
Assimp::BaseImporter::InternReadFile
virtual void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler)=0
Assimp::BaseImporter::SetupProperties
virtual void SetupProperties(const Importer *pImp)
Assimp::BaseImporter::m_progress
ProgressHandler * m_progress
Currently set progress handler.
Definition: BaseImporter.h:431
Assimp::BaseImporter::SearchFileHeaderForToken
static bool SearchFileHeaderForToken(IOSystem *pIOSystem, const std::string &file, const char **tokens, unsigned int numTokens, unsigned int searchBytes=200, bool tokensSol=false, bool noAlphaBeforeTokens=false)
Assimp::IOSystem
CPP-API: Interface to the file system.
Definition: IOSystem.hpp:93
Assimp::BaseImporter
Definition: BaseImporter.h:87
Assimp
Definition: ai_assert.h:50
Assimp::BaseImporter::importerUnits
std::map< ImporterUnits, double > importerUnits
Definition: BaseImporter.h:207
aiScene
Definition: scene.h:247
Assimp::IOStream
CPP-API: Class to handle file I/O for C++.
Definition: IOStream.hpp:75
Assimp::BaseImporter::m_Exception
std::exception_ptr m_Exception
The exception, in case there was one.
Definition: BaseImporter.h:429
Assimp::ProgressHandler
CPP-API: Abstract interface for custom progress report receivers.
Definition: ProgressHandler.hpp:67