Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

231 wiersze
5.1 KiB

  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2012, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file DXFHelper.h
  34. * @brief Internal utilities for the DXF loader.
  35. */
  36. #ifndef INCLUDED_DXFHELPER_H
  37. #define INCLUDED_DXFHELPER_H
  38. #include "LineSplitter.h"
  39. #include "TinyFormatter.h"
  40. #include "StreamReader.h"
  41. namespace Assimp {
  42. namespace DXF {
  43. // read pairs of lines, parse group code and value and provide utilities
  44. // to convert the data to the target data type.
  45. class LineReader
  46. {
  47. public:
  48. LineReader(StreamReaderLE& reader)
  49. // do NOT skip empty lines. In DXF files, they count as valid data.
  50. : splitter(reader,false,true)
  51. , end()
  52. {
  53. }
  54. public:
  55. // -----------------------------------------
  56. bool Is(int gc, const char* what) const {
  57. return groupcode == gc && !strcmp(what,value.c_str());
  58. }
  59. // -----------------------------------------
  60. bool Is(int gc) const {
  61. return groupcode == gc;
  62. }
  63. // -----------------------------------------
  64. int GroupCode() const {
  65. return groupcode;
  66. }
  67. // -----------------------------------------
  68. const std::string& Value() const {
  69. return value;
  70. }
  71. // -----------------------------------------
  72. bool End() const {
  73. return !((bool)*this);
  74. }
  75. public:
  76. // -----------------------------------------
  77. unsigned int ValueAsUnsignedInt() const {
  78. return strtoul10(value.c_str());
  79. }
  80. // -----------------------------------------
  81. int ValueAsSignedInt() const {
  82. return strtol10(value.c_str());
  83. }
  84. // -----------------------------------------
  85. float ValueAsFloat() const {
  86. return fast_atof(value.c_str());
  87. }
  88. public:
  89. // -----------------------------------------
  90. /** pseudo-iterator increment to advance to the next (groupcode/value) pair */
  91. LineReader& operator++() {
  92. if (end) {
  93. if (end == 1) {
  94. ++end;
  95. }
  96. return *this;
  97. }
  98. try {
  99. groupcode = strtol10(splitter->c_str());
  100. splitter++;
  101. value = *splitter;
  102. splitter++;
  103. // automatically skip over {} meta blocks (these are for application use
  104. // and currently not relevant for Assimp).
  105. if (value.length() && value[0] == '{') {
  106. size_t cnt = 0;
  107. for(;splitter->length() && splitter->at(0) != '}'; splitter++, cnt++);
  108. splitter++;
  109. DefaultLogger::get()->debug((Formatter::format("DXF: skipped over control group ("),cnt," lines)"));
  110. }
  111. } catch(std::logic_error&) {
  112. ai_assert(!splitter);
  113. }
  114. if (!splitter) {
  115. end = 1;
  116. }
  117. return *this;
  118. }
  119. // -----------------------------------------
  120. LineReader& operator++(int) {
  121. return ++(*this);
  122. }
  123. // -----------------------------------------
  124. operator bool() const {
  125. return end <= 1;
  126. }
  127. private:
  128. LineSplitter splitter;
  129. int groupcode;
  130. std::string value;
  131. int end;
  132. };
  133. // represents a POLYLINE or a LWPOLYLINE. or even a 3DFACE The data is converted as needed.
  134. struct PolyLine
  135. {
  136. PolyLine()
  137. : flags()
  138. {}
  139. std::vector<aiVector3D> positions;
  140. std::vector<aiColor4D> colors;
  141. std::vector<unsigned int> indices;
  142. std::vector<unsigned int> counts;
  143. unsigned int flags;
  144. std::string layer;
  145. std::string desc;
  146. };
  147. // reference to a BLOCK. Specifies its own coordinate system.
  148. struct InsertBlock
  149. {
  150. InsertBlock()
  151. : scale(1.f,1.f,1.f)
  152. , angle()
  153. {}
  154. aiVector3D pos;
  155. aiVector3D scale;
  156. float angle;
  157. std::string name;
  158. };
  159. // keeps track of all geometry in a single BLOCK.
  160. struct Block
  161. {
  162. std::vector< boost::shared_ptr<PolyLine> > lines;
  163. std::vector<InsertBlock> insertions;
  164. std::string name;
  165. aiVector3D base;
  166. };
  167. struct FileData
  168. {
  169. // note: the LAST block always contains the stuff from ENTITIES.
  170. std::vector<Block> blocks;
  171. };
  172. }}
  173. #endif