Skip to content

Commit e2e83b5

Browse files
committed
REN-132 Implemented new parser base
1 parent 6119113 commit e2e83b5

File tree

76 files changed

+5843
-589
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+5843
-589
lines changed

TODO.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
* Rename Appearance in SurfaceData (an Appearance is actually the objects that defines a Theme)
44
* Allow two textures and materials per AppearanceTarget (one backfacing and one front facing)
5-
* ensure that there are no memory leaks in the parser (e.g _currentGeometry)
5+
* Allow polygon sharing (search for gml:CompositeSurface in Berlin_komplett.citygml)
66

77
# Optimization
88
* In the finish step check if the geometry hierachy can be folded. It should be possible to merge all geometries of the same lod level together... however thats not so simple with shared geometries (ImplicitGeomentry)

citygml2vrml/citygml2vrml.cpp

+44-44
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@
1919
#include <time.h>
2020
#include <algorithm>
2121
#include <citygml/citygml.h>
22+
#include <citygml/cityobject.h>
23+
#include <citygml/citymodel.h>
24+
#include <citygml/geometry.h>
2225
#include <citygml/material.h>
2326
#include <citygml/texture.h>
27+
#include <citygml/geometry.h>
28+
#include <citygml/polygon.h>
2429

2530
// VRML97 Helper class to produce a hierarchy of VRML nodes with attributes
2631
class VRML97Printer
@@ -31,38 +36,38 @@ class VRML97Printer
3136
bool save( const std::string& outFilename );
3237

3338
private:
34-
void dumpCityObject( const citygml::CityObject* );
39+
void dumpCityObject(const citygml::CityObject& );
3540

36-
void dumpGeometry( const citygml::CityObject*, const citygml::Geometry* );
41+
void dumpGeometry(const citygml::CityObject&, const citygml::Geometry& );
3742

38-
void dumpPolygon( const citygml::CityObject*, const citygml::Geometry*, const citygml::Polygon* );
43+
void dumpPolygon(const citygml::CityObject&, const citygml::Geometry&, const citygml::Polygon& );
3944

4045
protected:
41-
inline addHeader() { _out << "#VRML V2.0 utf8" << std::endl; }
46+
void addHeader() { _out << "#VRML V2.0 utf8" << std::endl; }
4247

43-
inline printIndent() { for ( int i = 0; i < _indentCount; i++ ) _out << "\t"; }
48+
void printIndent() { for ( int i = 0; i < _indentCount; i++ ) _out << "\t"; }
4449

45-
inline addComment(const std::string& cmt) { printIndent(); _out << "# " << cmt << std::endl; }
50+
void addComment(const std::string& cmt) { printIndent(); _out << "# " << cmt << std::endl; }
4651

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++; }
4853

49-
inline endNode() { _indentCount--; printIndent(); _out << "}" << std::endl; }
54+
void endNode() { _indentCount--; printIndent(); _out << "}" << std::endl; }
5055

51-
inline addAttribute( const std::string &attr ) { printIndent(); _out << attr << " "; }
56+
void addAttribute( const std::string &attr ) { printIndent(); _out << attr << " "; }
5257

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; }
5459

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; }
5661

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++; }
5863

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++; }
6065

61-
inline endAttributeArray() { _indentCount--; printIndent(); _out << "]" << std::endl; }
66+
void endAttributeArray() { _indentCount--; printIndent(); _out << "]" << std::endl; }
6267

63-
inline beginGroup() { beginNode("Group"); beginAttributeArray( "children" ); }
68+
void beginGroup() { beginNode("Group"); beginAttributeArray( "children" ); }
6469

65-
inline endGroup() { endAttributeArray(); endNode(); }
70+
void endGroup() { endAttributeArray(); endNode(); }
6671

6772
private:
6873
citygml::CityModel* _cityModel;
@@ -118,7 +123,6 @@ int main( int argc, char **argv )
118123
if ( param == "-optimize" ) { params.optimize = true; fargc = i+1; }
119124
if ( param == "-comments" ) { g_comments = true; fargc = i+1; }
120125
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; }
122126
if ( param == "-minlod" ) { if ( i == argc - 1 ) usage(); params.minLOD = atoi( argv[i+1] ); i++; fargc = i+1; }
123127
if ( param == "-maxlod" ) { if ( i == argc - 1 ) usage(); params.maxLOD = atoi( argv[i+1] ); i++; fargc = i+1; }
124128
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 )
138142

139143
if ( !city ) return EXIT_FAILURE;
140144

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;
142146

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;
145148

146149
std::string outfile;
147150
if ( argc - fargc == 1 )
@@ -197,54 +200,52 @@ bool VRML97Printer::save( const std::string& outFilename )
197200
endGroup();
198201
}
199202
#else
200-
const citygml::CityObjects& roots = _cityModel->getCityObjectsRoots();
203+
citygml::ConstCityObjects roots = _cityModel->getRootCityObjects();
201204

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] );
203206
#endif
204207

205208
_out.close();
206209

207210
return true;
208211
}
209212

210-
void VRML97Printer::dumpCityObject( const citygml::CityObject* object )
213+
void VRML97Printer::dumpCityObject( const citygml::CityObject& object )
211214
{
212-
if ( !object ) return;
213215

214-
if ( g_comments ) addComment( object->getTypeAsString() + ": " + object->getId() );
216+
if ( g_comments ) addComment( object.getType() + ": " + object.getId() );
215217

216218
beginGroup();
217219

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 ) );
219221

220222
#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) );
222224
#endif
223225

224226
endGroup();
225227
}
226228

227-
void VRML97Printer::dumpGeometry( const citygml::CityObject* object, const citygml::Geometry* g )
229+
void VRML97Printer::dumpGeometry( const citygml::CityObject& object, const citygml::Geometry& g )
228230
{
229-
if ( !g ) return;
230231

231-
if ( g_comments ) addComment( "Geometry: " + g->getId() );
232+
if ( g_comments ) addComment( "Geometry: " + g.getId() );
232233

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) );
234235
}
235236

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 )
237238
{
238239
static bool s_isFirstVert = true;
239240
static TVec3d s_firstVert;
240241

241-
if ( !p || p->getIndices().size() == 0 ) return;
242+
if ( p.getIndices().size() == 0 ) return;
242243

243244
if ( g_comments )
244245
{
245246
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() );
248249
}
249250

250251
beginNode( "Shape" );
@@ -253,7 +254,7 @@ void VRML97Printer::dumpPolygon( const citygml::CityObject* object, const citygm
253254
beginAttributeNode( "geometry", "IndexedFaceSet" );
254255

255256
{
256-
const std::vector<TVec3d>& vertices = p->getVertices();
257+
const std::vector<TVec3d>& vertices = p.getVertices();
257258
beginAttributeNode( "coord", "Coordinate" );
258259
beginAttributeArray( "point" );
259260
printIndent();
@@ -273,7 +274,7 @@ void VRML97Printer::dumpPolygon( const citygml::CityObject* object, const citygm
273274
}
274275

275276
{
276-
const std::vector<unsigned int>& indices = p->getIndices();
277+
const std::vector<unsigned int>& indices = p.getIndices();
277278
beginAttributeArray( "coordIndex" );
278279
printIndent();
279280
for ( unsigned int k = 0 ; k < indices.size() / 3; k++ )
@@ -283,9 +284,9 @@ void VRML97Printer::dumpPolygon( const citygml::CityObject* object, const citygm
283284
}
284285

285286
// Normal management
286-
if ( p->getNormals().size() > 0 )
287+
if ( p.getNormals().size() > 0 )
287288
{
288-
const std::vector<TVec3f>& normals = p->getNormals();
289+
const std::vector<TVec3f>& normals = p.getNormals();
289290
beginAttributeNode( "normal", "Normal" );
290291
beginAttributeArray( "vector" );
291292
printIndent();
@@ -299,9 +300,9 @@ void VRML97Printer::dumpPolygon( const citygml::CityObject* object, const citygm
299300
addAttributeValue( "solid", "FALSE" ); //draw both sides of faces
300301

301302
// 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 )
303304
{
304-
const citygml::TexCoords& texCoords = p->getTexCoords();
305+
const citygml::TexCoords& texCoords = p.getTexCoords();
305306
beginAttributeNode( "texCoord", "TextureCoordinate" );
306307

307308
beginAttributeArray( "point" );
@@ -321,7 +322,7 @@ void VRML97Printer::dumpPolygon( const citygml::CityObject* object, const citygm
321322

322323
bool colorset = false;
323324

324-
std::shared_ptr<const citygml::Appearance> mat = p->getAppearance();
325+
std::shared_ptr<const citygml::Appearance> mat = p.getAppearance();
325326

326327
if ( auto m = std::dynamic_pointer_cast<const citygml::Material>( mat ) )
327328
{
@@ -350,8 +351,7 @@ void VRML97Printer::dumpPolygon( const citygml::CityObject* object, const citygm
350351
{
351352
beginAttributeNode( "material", "Material" );
352353

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 );
355355
TVec3f crgb( color.r, color.g, color.b );
356356
addAttributeValue( "diffuseColor", crgb );
357357
if ( color.a != 1.f ) addAttributeValue( "transparency", 1.f - color.a );

0 commit comments

Comments
 (0)