vrshoot
diff libs/assimp/DXFHelper.h @ 0:b2f14e535253
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 01 Feb 2014 19:58:19 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/DXFHelper.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,230 @@ 1.4 +/* 1.5 +Open Asset Import Library (assimp) 1.6 +---------------------------------------------------------------------- 1.7 + 1.8 +Copyright (c) 2006-2012, assimp team 1.9 +All rights reserved. 1.10 + 1.11 +Redistribution and use of this software in source and binary forms, 1.12 +with or without modification, are permitted provided that the 1.13 +following conditions are met: 1.14 + 1.15 +* Redistributions of source code must retain the above 1.16 + copyright notice, this list of conditions and the 1.17 + following disclaimer. 1.18 + 1.19 +* Redistributions in binary form must reproduce the above 1.20 + copyright notice, this list of conditions and the 1.21 + following disclaimer in the documentation and/or other 1.22 + materials provided with the distribution. 1.23 + 1.24 +* Neither the name of the assimp team, nor the names of its 1.25 + contributors may be used to endorse or promote products 1.26 + derived from this software without specific prior 1.27 + written permission of the assimp team. 1.28 + 1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.40 + 1.41 +---------------------------------------------------------------------- 1.42 +*/ 1.43 + 1.44 +/** @file DXFHelper.h 1.45 + * @brief Internal utilities for the DXF loader. 1.46 + */ 1.47 + 1.48 +#ifndef INCLUDED_DXFHELPER_H 1.49 +#define INCLUDED_DXFHELPER_H 1.50 + 1.51 +#include "LineSplitter.h" 1.52 +#include "TinyFormatter.h" 1.53 +#include "StreamReader.h" 1.54 + 1.55 +namespace Assimp { 1.56 + namespace DXF { 1.57 + 1.58 + 1.59 +// read pairs of lines, parse group code and value and provide utilities 1.60 +// to convert the data to the target data type. 1.61 +class LineReader 1.62 +{ 1.63 + 1.64 +public: 1.65 + 1.66 + LineReader(StreamReaderLE& reader) 1.67 + // do NOT skip empty lines. In DXF files, they count as valid data. 1.68 + : splitter(reader,false,true) 1.69 + , end() 1.70 + { 1.71 + } 1.72 + 1.73 +public: 1.74 + 1.75 + 1.76 + // ----------------------------------------- 1.77 + bool Is(int gc, const char* what) const { 1.78 + return groupcode == gc && !strcmp(what,value.c_str()); 1.79 + } 1.80 + 1.81 + // ----------------------------------------- 1.82 + bool Is(int gc) const { 1.83 + return groupcode == gc; 1.84 + } 1.85 + 1.86 + // ----------------------------------------- 1.87 + int GroupCode() const { 1.88 + return groupcode; 1.89 + } 1.90 + 1.91 + // ----------------------------------------- 1.92 + const std::string& Value() const { 1.93 + return value; 1.94 + } 1.95 + 1.96 + // ----------------------------------------- 1.97 + bool End() const { 1.98 + return !((bool)*this); 1.99 + } 1.100 + 1.101 +public: 1.102 + 1.103 + // ----------------------------------------- 1.104 + unsigned int ValueAsUnsignedInt() const { 1.105 + return strtoul10(value.c_str()); 1.106 + } 1.107 + 1.108 + // ----------------------------------------- 1.109 + int ValueAsSignedInt() const { 1.110 + return strtol10(value.c_str()); 1.111 + } 1.112 + 1.113 + // ----------------------------------------- 1.114 + float ValueAsFloat() const { 1.115 + return fast_atof(value.c_str()); 1.116 + } 1.117 + 1.118 +public: 1.119 + 1.120 + // ----------------------------------------- 1.121 + /** pseudo-iterator increment to advance to the next (groupcode/value) pair */ 1.122 + LineReader& operator++() { 1.123 + if (end) { 1.124 + if (end == 1) { 1.125 + ++end; 1.126 + } 1.127 + return *this; 1.128 + } 1.129 + 1.130 + try { 1.131 + groupcode = strtol10(splitter->c_str()); 1.132 + splitter++; 1.133 + 1.134 + value = *splitter; 1.135 + splitter++; 1.136 + 1.137 + // automatically skip over {} meta blocks (these are for application use 1.138 + // and currently not relevant for Assimp). 1.139 + if (value.length() && value[0] == '{') { 1.140 + 1.141 + size_t cnt = 0; 1.142 + for(;splitter->length() && splitter->at(0) != '}'; splitter++, cnt++); 1.143 + 1.144 + splitter++; 1.145 + DefaultLogger::get()->debug((Formatter::format("DXF: skipped over control group ("),cnt," lines)")); 1.146 + } 1.147 + } catch(std::logic_error&) { 1.148 + ai_assert(!splitter); 1.149 + } 1.150 + if (!splitter) { 1.151 + end = 1; 1.152 + } 1.153 + return *this; 1.154 + } 1.155 + 1.156 + // ----------------------------------------- 1.157 + LineReader& operator++(int) { 1.158 + return ++(*this); 1.159 + } 1.160 + 1.161 + 1.162 + // ----------------------------------------- 1.163 + operator bool() const { 1.164 + return end <= 1; 1.165 + } 1.166 + 1.167 +private: 1.168 + 1.169 + LineSplitter splitter; 1.170 + int groupcode; 1.171 + std::string value; 1.172 + int end; 1.173 +}; 1.174 + 1.175 + 1.176 + 1.177 +// represents a POLYLINE or a LWPOLYLINE. or even a 3DFACE The data is converted as needed. 1.178 +struct PolyLine 1.179 +{ 1.180 + PolyLine() 1.181 + : flags() 1.182 + {} 1.183 + 1.184 + std::vector<aiVector3D> positions; 1.185 + std::vector<aiColor4D> colors; 1.186 + std::vector<unsigned int> indices; 1.187 + std::vector<unsigned int> counts; 1.188 + unsigned int flags; 1.189 + 1.190 + std::string layer; 1.191 + std::string desc; 1.192 +}; 1.193 + 1.194 + 1.195 +// reference to a BLOCK. Specifies its own coordinate system. 1.196 +struct InsertBlock 1.197 +{ 1.198 + InsertBlock() 1.199 + : scale(1.f,1.f,1.f) 1.200 + , angle() 1.201 + {} 1.202 + 1.203 + aiVector3D pos; 1.204 + aiVector3D scale; 1.205 + float angle; 1.206 + 1.207 + std::string name; 1.208 +}; 1.209 + 1.210 + 1.211 +// keeps track of all geometry in a single BLOCK. 1.212 +struct Block 1.213 +{ 1.214 + std::vector< boost::shared_ptr<PolyLine> > lines; 1.215 + std::vector<InsertBlock> insertions; 1.216 + 1.217 + std::string name; 1.218 + aiVector3D base; 1.219 +}; 1.220 + 1.221 + 1.222 +struct FileData 1.223 +{ 1.224 + // note: the LAST block always contains the stuff from ENTITIES. 1.225 + std::vector<Block> blocks; 1.226 +}; 1.227 + 1.228 + 1.229 + 1.230 + 1.231 + 1.232 +}} 1.233 +#endif