1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000,2001,2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #include "OSGConfig.h"
45 #include "OSGNFIOOptions.h"
46 #include "OSGNFIOQuantizer.h"
52 /***************************************************************************\
54 \***************************************************************************/
56 /*-------------------------------------------------------------------------*\
58 \*-------------------------------------------------------------------------*/
61 /***************************************************************************\
63 \***************************************************************************/
65 /*----------------------------- constructors -----------------------------*/
67 NFIOOptions::NFIOOptions(void)
68 : _inlineTextures(true),
69 _compressTextures(false),
70 _texturesCompressionQuality(75),
71 _texturesImageType("jpeg"),
72 _quantizePositions(Quantizer::QRES_OFF
),
73 _quantizeNormals(Quantizer::QRES_OFF
),
74 _quantizeTexCoords(Quantizer::QRES_OFF
),
76 _unpack16BitIndices(true),
77 _forceVolumeExport(false)
81 /*------------------------------ destructor -------------------------------*/
83 NFIOOptions::~NFIOOptions(void)
87 /*------------------------------ init------ -------------------------------*/
89 void NFIOOptions::init(const std::string
&options
)
91 // init default parameters
92 _inlineTextures
= true;
93 _compressTextures
= false;
94 _texturesCompressionQuality
= 75;
95 _texturesImageType
= "jpeg",
96 _quantizePositions
= Quantizer::QRES_OFF
;
97 _quantizeNormals
= Quantizer::QRES_OFF
;
98 _quantizeTexCoords
= Quantizer::QRES_OFF
;
100 _unpack16BitIndices
= false;
101 _forceVolumeExport
= false;
104 std::string::size_type i
= 0;
107 if(options
.find("inlineTextures=true") != std::string::npos
)
108 _inlineTextures
= true;
109 if(options
.find("inlineTextures=false") != std::string::npos
)
110 _inlineTextures
= false;
112 if(options
.find("compressTextures=true") != std::string::npos
)
113 _compressTextures
= true;
114 if(options
.find("compressTextures=false") != std::string::npos
)
115 _compressTextures
= false;
117 option
= "texturesCompressionQuality=";
118 if((i
=options
.find(option
)) != std::string::npos
)
119 _texturesCompressionQuality
= getInteger(options
.substr(i
+option
.size()));
121 option
= "texturesImageType=";
122 if((i
= options
.find(option
)) != std::string::npos
)
123 _texturesImageType
= getString(options
.substr(i
+ option
.size()));
125 if(options
.find("quantizePositions=0") != std::string::npos
)
126 _quantizePositions
= Quantizer::QRES_OFF
;
127 if(options
.find("quantizePositions=8") != std::string::npos
)
128 _quantizePositions
= Quantizer::QRES_8BIT
;
129 if(options
.find("quantizePositions=16") != std::string::npos
)
130 _quantizePositions
= Quantizer::QRES_16BIT
;
131 if(options
.find("quantizePositions=24") != std::string::npos
)
132 _quantizePositions
= Quantizer::QRES_24BIT
;
134 if(options
.find("quantizeNormals=0") != std::string::npos
)
135 _quantizeNormals
= Quantizer::QRES_OFF
;
136 if(options
.find("quantizeNormals=8") != std::string::npos
)
137 _quantizeNormals
= Quantizer::QRES_8BIT
;
138 if(options
.find("quantizeNormals=16") != std::string::npos
)
139 _quantizeNormals
= Quantizer::QRES_16BIT
;
140 if(options
.find("quantizeNormals=24") != std::string::npos
)
141 _quantizeNormals
= Quantizer::QRES_24BIT
;
143 if(options
.find("quantizeTexCoords=0") != std::string::npos
)
144 _quantizeTexCoords
= Quantizer::QRES_OFF
;
145 if(options
.find("quantizeTexCoords=8") != std::string::npos
)
146 _quantizeTexCoords
= Quantizer::QRES_8BIT
;
147 if(options
.find("quantizeTexCoords=16") != std::string::npos
)
148 _quantizeTexCoords
= Quantizer::QRES_16BIT
;
149 if(options
.find("quantizeTexCoords=24") != std::string::npos
)
150 _quantizeTexCoords
= Quantizer::QRES_24BIT
;
152 if(options
.find("packIndices=true") != std::string::npos
)
154 if(options
.find("packIndices=false") != std::string::npos
)
155 _packIndices
= false;
157 if(options
.find("unpack16BitIndices=true") != std::string::npos
)
158 _unpack16BitIndices
= true;
159 if(options
.find("unpack16BitIndices=false") != std::string::npos
)
160 _unpack16BitIndices
= false;
162 if(options
.find("forceVolumeExport=true") != std::string::npos
)
163 _forceVolumeExport
= true;
166 void NFIOOptions::init(const OptionSet
&options
)
168 // init default parameters
169 _inlineTextures
= true;
170 _compressTextures
= false;
171 _texturesCompressionQuality
= 75;
172 _texturesImageType
= "jpeg",
173 _quantizePositions
= Quantizer::QRES_OFF
;
174 _quantizeNormals
= Quantizer::QRES_OFF
;
175 _quantizeTexCoords
= Quantizer::QRES_OFF
;
176 _packIndices
= false;
177 _unpack16BitIndices
= false;
178 _forceVolumeExport
= false;
180 OptionSet::const_iterator oIt
= options
.begin();
181 OptionSet::const_iterator oEnd
= options
.end ();
183 for(; oIt
!= oEnd
; ++oIt
)
185 if(oIt
->first
== "inlineTextures")
186 _inlineTextures
= getBoolOption(oIt
->second
);
188 if(oIt
->first
== "compressTextures")
189 _compressTextures
= getBoolOption(oIt
->second
);
191 if(oIt
->first
== "texturesCompressionQuality")
192 _texturesCompressionQuality
= getValue
<UInt32
>(oIt
->second
, 75);
194 if(oIt
->first
== "texturesImageType")
195 _texturesImageType
= getValue
<std::string
>(oIt
->second
, "jpeg");
197 if(oIt
->first
== "quantizePositions")
198 _quantizePositions
= getQuantizeOption(oIt
->second
);
200 if(oIt
->first
== "quantizeNormals")
201 _quantizeNormals
= getQuantizeOption(oIt
->second
);
203 if(oIt
->first
== "quantizeTexCoords")
204 _quantizeTexCoords
= getQuantizeOption(oIt
->second
);
206 if(oIt
->first
== "packIndices")
207 _packIndices
= getBoolOption(oIt
->second
);
209 if(oIt
->first
== "unpack16BitIndices")
210 _unpack16BitIndices
= getBoolOption(oIt
->second
);
212 if(oIt
->first
== "forceVolumeExport")
213 _forceVolumeExport
= getBoolOption(oIt
->second
);
217 /*------------------------------ options--- -------------------------------*/
219 bool NFIOOptions::inlineTextures(void) const
221 return _inlineTextures
;
224 bool NFIOOptions::compressTextures(void) const
226 return _compressTextures
;
229 UInt32
NFIOOptions::texturesCompressionQuality(void) const
231 return _texturesCompressionQuality
;
234 std::string
NFIOOptions::texturesImageType(void) const
236 return _texturesImageType
;
239 UInt8
NFIOOptions::quantizePositions(void) const
241 return _quantizePositions
;
244 UInt8
NFIOOptions::quantizeNormals(void) const
246 return _quantizeNormals
;
249 UInt8
NFIOOptions::quantizeTexCoords(void) const
251 return _quantizeTexCoords
;
254 bool NFIOOptions::packIndices(void) const
259 bool NFIOOptions::unpack16BitIndices(void) const
261 return _unpack16BitIndices
;
264 bool NFIOOptions::forceVolumeExport(void) const
266 return _forceVolumeExport
;
269 /*------------------------ helper functions ------------------------------*/
271 Int32
NFIOOptions::getInteger(const std::string
&str
)
273 std::stringstream ss
;
275 while(i
< str
.length() && str
[i
] != ',' &&
276 (isdigit(str
[i
]) || str
[i
] == '-'))
285 std::string
NFIOOptions::getString(const std::string
&str
)
289 while(i
< str
.length() && str
[i
] != ',')
296 bool NFIOOptions::getBoolOption(const IOOption
&option
)
300 if(!option
.optValue
.empty())
304 retVal
= boost::lexical_cast
<bool>(option
.optValue
);
306 catch(boost::bad_lexical_cast
&)
315 UInt8
NFIOOptions::getQuantizeOption(const IOOption
&option
)
317 UInt8 retVal
= Quantizer::QRES_OFF
;
319 if(!option
.optValue
.empty())
325 quanRes
= boost::lexical_cast
<UInt8
>(option
.optValue
);
327 catch(boost::bad_lexical_cast
&)
329 quanRes
= Quantizer::QRES_OFF
;
334 case 0: retVal
= Quantizer::QRES_OFF
;
337 case 8: retVal
= Quantizer::QRES_8BIT
;
340 case 16: retVal
= Quantizer::QRES_16BIT
;
343 case 24: retVal
= Quantizer::QRES_24BIT
;
346 default: retVal
= Quantizer::QRES_OFF
;