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