19
19
#include < time.h>
20
20
#include < algorithm>
21
21
#include < citygml/citygml.h>
22
+ #include < citygml/cityobject.h>
23
+ #include < citygml/citymodel.h>
24
+ #include < citygml/geometry.h>
22
25
#include < citygml/material.h>
23
26
#include < citygml/texture.h>
27
+ #include < citygml/geometry.h>
28
+ #include < citygml/polygon.h>
24
29
25
30
// VRML97 Helper class to produce a hierarchy of VRML nodes with attributes
26
31
class VRML97Printer
@@ -31,38 +36,38 @@ class VRML97Printer
31
36
bool save ( const std::string& outFilename );
32
37
33
38
private:
34
- void dumpCityObject ( const citygml::CityObject* );
39
+ void dumpCityObject (const citygml::CityObject& );
35
40
36
- void dumpGeometry ( const citygml::CityObject* , const citygml::Geometry* );
41
+ void dumpGeometry (const citygml::CityObject& , const citygml::Geometry& );
37
42
38
- void dumpPolygon ( const citygml::CityObject* , const citygml::Geometry* , const citygml::Polygon* );
43
+ void dumpPolygon (const citygml::CityObject& , const citygml::Geometry& , const citygml::Polygon& );
39
44
40
45
protected:
41
- inline addHeader () { _out << " #VRML V2.0 utf8" << std::endl; }
46
+ void addHeader () { _out << " #VRML V2.0 utf8" << std::endl; }
42
47
43
- inline printIndent () { for ( int i = 0 ; i < _indentCount; i++ ) _out << " \t " ; }
48
+ void printIndent () { for ( int i = 0 ; i < _indentCount; i++ ) _out << " \t " ; }
44
49
45
- inline addComment (const std::string& cmt) { printIndent (); _out << " # " << cmt << std::endl; }
50
+ void addComment (const std::string& cmt) { printIndent (); _out << " # " << cmt << std::endl; }
46
51
47
- inline beginNode ( const std::string &node ) { printIndent (); _out << node << " {" << std::endl; _indentCount++; }
52
+ void beginNode ( const std::string &node ) { printIndent (); _out << node << " {" << std::endl; _indentCount++; }
48
53
49
- inline endNode () { _indentCount--; printIndent (); _out << " }" << std::endl; }
54
+ void endNode () { _indentCount--; printIndent (); _out << " }" << std::endl; }
50
55
51
- inline addAttribute ( const std::string &attr ) { printIndent (); _out << attr << " " ; }
56
+ void addAttribute ( const std::string &attr ) { printIndent (); _out << attr << " " ; }
52
57
53
- template <class T > inline addAttributeValue ( const std::string &attr, T val ) { printIndent (); _out << attr << " " << val << std::endl; }
58
+ template <class T > void addAttributeValue ( const std::string &attr, T val ) { printIndent (); _out << attr << " " << val << std::endl; }
54
59
55
- inline addAttributeValue ( const std::string &attr, const char * val ) { printIndent (); _out << attr << " " << val << std::endl; }
60
+ void addAttributeValue ( const std::string &attr, const char * val ) { printIndent (); _out << attr << " " << val << std::endl; }
56
61
57
- inline beginAttributeNode ( const std::string &attr, const std::string &node ) { printIndent (); _out << attr << " " << node << " {" << std::endl; _indentCount++; }
62
+ void beginAttributeNode ( const std::string &attr, const std::string &node ) { printIndent (); _out << attr << " " << node << " {" << std::endl; _indentCount++; }
58
63
59
- inline beginAttributeArray ( const std::string &attr ) { addAttribute ( attr ); _out << " [" << std::endl; _indentCount++; }
64
+ void beginAttributeArray ( const std::string &attr ) { addAttribute ( attr ); _out << " [" << std::endl; _indentCount++; }
60
65
61
- inline endAttributeArray () { _indentCount--; printIndent (); _out << " ]" << std::endl; }
66
+ void endAttributeArray () { _indentCount--; printIndent (); _out << " ]" << std::endl; }
62
67
63
- inline beginGroup () { beginNode (" Group" ); beginAttributeArray ( " children" ); }
68
+ void beginGroup () { beginNode (" Group" ); beginAttributeArray ( " children" ); }
64
69
65
- inline endGroup () { endAttributeArray (); endNode (); }
70
+ void endGroup () { endAttributeArray (); endNode (); }
66
71
67
72
private:
68
73
citygml::CityModel* _cityModel;
@@ -118,7 +123,6 @@ int main( int argc, char **argv )
118
123
if ( param == " -optimize" ) { params.optimize = true ; fargc = i+1 ; }
119
124
if ( param == " -comments" ) { g_comments = true ; fargc = i+1 ; }
120
125
if ( param == " -center" ) { g_center = true ; fargc = i+1 ; }
121
- if ( param == " -filter" ) { if ( i == argc - 1 ) usage (); params.objectsMask = argv[i+1 ]; i++; fargc = i+1 ; }
122
126
if ( param == " -minlod" ) { if ( i == argc - 1 ) usage (); params.minLOD = atoi ( argv[i+1 ] ); i++; fargc = i+1 ; }
123
127
if ( param == " -maxlod" ) { if ( i == argc - 1 ) usage (); params.maxLOD = atoi ( argv[i+1 ] ); i++; fargc = i+1 ; }
124
128
if ( param == " -destsrs" ) { if ( i == argc - 1 ) usage (); params.destSRS = argv[i+1 ]; i++; fargc = i+1 ; }
@@ -138,10 +142,9 @@ int main( int argc, char **argv )
138
142
139
143
if ( !city ) return EXIT_FAILURE;
140
144
141
- std::cout << " Done in " << difftime ( end, start ) << " seconds." << std::endl << city-> size () << " city objects read. " << std::endl ;
145
+ std::cout << " Done in " << difftime ( end, start ) << " seconds." << std::endl;
142
146
143
- std::cout << city->getCityObjectsRoots ().size () << " root nodes" << std::endl;
144
- if ( city->getSRSName () != " " ) std::cout << " The actual model SRS is " << city->getSRSName () << std::endl;
147
+ std::cout << city->getRootCityObjects ().size () << " root nodes" << std::endl;
145
148
146
149
std::string outfile;
147
150
if ( argc - fargc == 1 )
@@ -197,54 +200,52 @@ bool VRML97Printer::save( const std::string& outFilename )
197
200
endGroup ();
198
201
}
199
202
#else
200
- const citygml::CityObjects& roots = _cityModel->getCityObjectsRoots ();
203
+ citygml::ConstCityObjects roots = _cityModel->getRootCityObjects ();
201
204
202
- for ( unsigned int i = 0 ; i < roots.size (); i++ ) dumpCityObject ( roots[i] );
205
+ for ( unsigned int i = 0 ; i < roots.size (); i++ ) dumpCityObject ( * roots[i] );
203
206
#endif
204
207
205
208
_out.close ();
206
209
207
210
return true ;
208
211
}
209
212
210
- void VRML97Printer::dumpCityObject ( const citygml::CityObject* object )
213
+ void VRML97Printer::dumpCityObject ( const citygml::CityObject& object )
211
214
{
212
- if ( !object ) return ;
213
215
214
- if ( g_comments ) addComment ( object-> getTypeAsString () + " : " + object-> getId () );
216
+ if ( g_comments ) addComment ( object. getType () + " : " + object. getId () );
215
217
216
218
beginGroup ();
217
219
218
- for ( unsigned int i = 0 ; i < object-> size (); i++ ) dumpGeometry ( object, object-> getGeometry ( i ) );
220
+ for ( unsigned int i = 0 ; i < object. getGeometriesCount (); i++ ) dumpGeometry ( object, object. getGeometry ( i ) );
219
221
220
222
#ifdef RECURSIVE_DUMP
221
- for ( unsigned int i = 0 ; i < object-> getChildCount (); i++ ) dumpCityObject ( object-> getChild ( i ) );
223
+ for ( unsigned int i = 0 ; i < object. getChildCityObjecsCount (); i++ ) dumpCityObject ( object. getChildCityObject (i ) );
222
224
#endif
223
225
224
226
endGroup ();
225
227
}
226
228
227
- void VRML97Printer::dumpGeometry ( const citygml::CityObject* object, const citygml::Geometry* g )
229
+ void VRML97Printer::dumpGeometry ( const citygml::CityObject& object, const citygml::Geometry& g )
228
230
{
229
- if ( !g ) return ;
230
231
231
- if ( g_comments ) addComment ( " Geometry: " + g-> getId () );
232
+ if ( g_comments ) addComment ( " Geometry: " + g. getId () );
232
233
233
- for ( unsigned int i = 0 ; i < g-> size (); i++ ) dumpPolygon ( object, g, (*g)[i] );
234
+ for ( unsigned int i = 0 ; i < g. getPolygonsCount (); i++ ) dumpPolygon ( object, g, g. getPolygon (i) );
234
235
}
235
236
236
- void VRML97Printer::dumpPolygon ( const citygml::CityObject* object, const citygml::Geometry* g, const citygml::Polygon* p )
237
+ void VRML97Printer::dumpPolygon ( const citygml::CityObject& object, const citygml::Geometry& g, const citygml::Polygon& p )
237
238
{
238
239
static bool s_isFirstVert = true ;
239
240
static TVec3d s_firstVert;
240
241
241
- if ( !p || p-> getIndices ().size () == 0 ) return ;
242
+ if ( p. getIndices ().size () == 0 ) return ;
242
243
243
244
if ( g_comments )
244
245
{
245
246
std::stringstream ss;
246
- ss << " " << p-> getVertices ().size () << " points, " << p-> getIndices ().size ()/3 << " triangles, " << p-> getNormals ().size () << " normals, " << p-> getTexCoords ().size () << " texCoords" ;
247
- addComment ( " Polygon: " + p-> getId () + ss.str () );
247
+ ss << " " << p. getVertices ().size () << " points, " << p. getIndices ().size ()/3 << " triangles, " << p. getNormals ().size () << " normals, " << p. getTexCoords ().size () << " texCoords" ;
248
+ addComment ( " Polygon: " + p. getId () + ss.str () );
248
249
}
249
250
250
251
beginNode ( " Shape" );
@@ -253,7 +254,7 @@ void VRML97Printer::dumpPolygon( const citygml::CityObject* object, const citygm
253
254
beginAttributeNode ( " geometry" , " IndexedFaceSet" );
254
255
255
256
{
256
- const std::vector<TVec3d>& vertices = p-> getVertices ();
257
+ const std::vector<TVec3d>& vertices = p. getVertices ();
257
258
beginAttributeNode ( " coord" , " Coordinate" );
258
259
beginAttributeArray ( " point" );
259
260
printIndent ();
@@ -273,7 +274,7 @@ void VRML97Printer::dumpPolygon( const citygml::CityObject* object, const citygm
273
274
}
274
275
275
276
{
276
- const std::vector<unsigned int >& indices = p-> getIndices ();
277
+ const std::vector<unsigned int >& indices = p. getIndices ();
277
278
beginAttributeArray ( " coordIndex" );
278
279
printIndent ();
279
280
for ( unsigned int k = 0 ; k < indices.size () / 3 ; k++ )
@@ -283,9 +284,9 @@ void VRML97Printer::dumpPolygon( const citygml::CityObject* object, const citygm
283
284
}
284
285
285
286
// Normal management
286
- if ( p-> getNormals ().size () > 0 )
287
+ if ( p. getNormals ().size () > 0 )
287
288
{
288
- const std::vector<TVec3f>& normals = p-> getNormals ();
289
+ const std::vector<TVec3f>& normals = p. getNormals ();
289
290
beginAttributeNode ( " normal" , " Normal" );
290
291
beginAttributeArray ( " vector" );
291
292
printIndent ();
@@ -299,9 +300,9 @@ void VRML97Printer::dumpPolygon( const citygml::CityObject* object, const citygm
299
300
addAttributeValue ( " solid" , " FALSE" ); // draw both sides of faces
300
301
301
302
// Texture coordinates
302
- if ( std::dynamic_pointer_cast<const citygml::Texture>( p-> getAppearance () ) && p-> getTexCoords ().size () > 0 )
303
+ if ( std::dynamic_pointer_cast<const citygml::Texture>( p. getAppearance () ) && p. getTexCoords ().size () > 0 )
303
304
{
304
- const citygml::TexCoords& texCoords = p-> getTexCoords ();
305
+ const citygml::TexCoords& texCoords = p. getTexCoords ();
305
306
beginAttributeNode ( " texCoord" , " TextureCoordinate" );
306
307
307
308
beginAttributeArray ( " point" );
@@ -321,7 +322,7 @@ void VRML97Printer::dumpPolygon( const citygml::CityObject* object, const citygm
321
322
322
323
bool colorset = false ;
323
324
324
- std::shared_ptr<const citygml::Appearance> mat = p-> getAppearance ();
325
+ std::shared_ptr<const citygml::Appearance> mat = p. getAppearance ();
325
326
326
327
if ( auto m = std::dynamic_pointer_cast<const citygml::Material>( mat ) )
327
328
{
@@ -350,8 +351,7 @@ void VRML97Printer::dumpPolygon( const citygml::CityObject* object, const citygm
350
351
{
351
352
beginAttributeNode ( " material" , " Material" );
352
353
353
- TVec4f color ( object->getDefaultColor ().rgba );
354
- if ( g->getType () == citygml::GT_Roof ) color = TVec4f ( 0 .9f , 0 .1f , 0 .1f , 1 .f );
354
+ TVec4f color = TVec4f ( 0 .9f , 0 .1f , 0 .1f , 1 .f );
355
355
TVec3f crgb ( color.r , color.g , color.b );
356
356
addAttributeValue ( " diffuseColor" , crgb );
357
357
if ( color.a != 1 .f ) addAttributeValue ( " transparency" , 1 .f - color.a );
0 commit comments