File: citygmltest.cpp

package info (click to toggle)
libcitygml 0.14%2Bsvn134-2%2B3p2p1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 468 kB
  • ctags: 670
  • sloc: cpp: 3,128; ansic: 262; sh: 20; makefile: 17
file content (132 lines) | stat: -rw-r--r-- 4,951 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* -*-c++-*- citygml2vrml - Copyright (c) 2010 Joachim Pouderoux, BRGM
*
* This file is part of libcitygml library
* http://code.google.com/p/libcitygml
*
* libcitygml is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* libcitygml is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*/

#include <iostream>
#include <fstream>
#include <time.h> 
#include <algorithm>
#include "citygml.h"

void analyzeObject( const citygml::CityObject*, unsigned int );

void usage() 
{
	std::cout << "Usage: citygmltest [-options...] <filename>" << std::endl;
	std::cout << " Options:" << std::endl;
	std::cout << "  -log            Print some information during parsing" << std::endl;
	std::cout << "  -filter <mask>  CityGML objects to parse (default:All)" << std::endl
		<< "                  The mask is composed of:" << std::endl
		<< "                   GenericCityObject, Building, Room," << std::endl
		<< "                   BuildingInstallation, BuildingFurniture, Door, Window, " << std::endl
		<< "                   CityFurniture, Track, Road, Railway, Square, PlantCover," << std::endl
		<< "                   SolitaryVegetationObject, WaterBody, TINRelief, LandUse," << std::endl
		<< "                   Tunnel, Bridge, BridgeConstructionElement," << std::endl
		<< "                   BridgeInstallation, BridgePart, All" << std::endl
		<< "                  and seperators |,&,~." << std::endl
		<< "                  Examples:" << std::endl
		<< "                  \"All&~Track&~Room\" to parse everything but tracks & rooms" << std::endl
		<< "                  \"Road&Railway\" to parse only roads & railways" << std::endl;
	std::cout << "  -destSRS <srs> Destination SRS (default: no transform)" << std::endl;
	exit( EXIT_FAILURE );
}

int main( int argc, char **argv )
{
	if ( argc < 2 ) usage();

	int fargc = 1;

	bool log = false;

	citygml::ParserParams params;

	for ( int i = 1; i < argc; i++ ) 
	{
		std::string param = std::string( argv[i] );
		std::transform( param.begin(), param.end(), param.begin(), tolower );
		if ( param == "-log" ) { log = true; fargc = i+1; }
		if ( param == "-filter" ) { if ( i == argc - 1 ) usage(); params.objectsMask = argv[i+1]; i++; fargc = i+1; }
		if ( param == "-destsrs" ) { if ( i == argc - 1 ) usage(); params.destSRS = argv[i+1]; i++; fargc = i+1; }
	}

	if ( argc - fargc < 1 ) usage();

	std::cout << "Parsing CityGML file " << argv[fargc] << " using libcitygml v." << LIBCITYGML_VERSIONSTR << "..." << std::endl;

	time_t start;
	time( &start );

#if 0
	std::ifstream file;
	file.open( argv[fargc], std::ifstream::in );
	citygml::CityModel *city = citygml::load( file, params );
#else
	citygml::CityModel *city = citygml::load( argv[fargc], params );
#endif

	time_t end;
	time( &end );

	if ( !city ) return EXIT_FAILURE;

	std::cout << "Done in " << difftime( end, start ) << " seconds." << std::endl << city->size() << " city objects read." << std::endl;

	std::cout << "Analyzing the city objects..." << std::endl;


	const citygml::CityObjectsMap& cityObjectsMap = city->getCityObjectsMap();

	citygml::CityObjectsMap::const_iterator it = cityObjectsMap.begin();

	for ( ; it != cityObjectsMap.end(); ++it )
	{
		const citygml::CityObjects& v = it->second;

		std::cout << ( log ? " Analyzing " : " Found " ) << v.size() << " " << citygml::getCityObjectsClassName( it->first ) << ( ( v.size() > 1 ) ? "s" : "" ) << "..." << std::endl;

		if ( log ) 
		{
			for ( unsigned int i = 0; i < v.size(); i++ )
			{
				std::cout << "  + found object " << v[i]->getId();
				if ( v[i]->getChildCount() > 0 ) std::cout << " with " << v[i]->getChildCount() << " children";
				std::cout << " with " << v[i]->size() << " geometr" << ( ( v[i]->size() > 1 ) ? "ies" : "y" );
				std::cout << std::endl;
			}
		}
	}

	if ( log ) 
	{
		std::cout << std::endl << "Objects hierarchy:" << std::endl;
		const citygml::CityObjects& roots = city->getCityObjectsRoots();

		for ( unsigned int i = 0; i < roots.size(); i++ ) analyzeObject( roots[ i ], 2 );
	}

	std::cout << "Done." << std::endl;

	return EXIT_SUCCESS;
}

void analyzeObject( const citygml::CityObject* object, unsigned int indent )
{
	for ( unsigned int i = 0; i < indent; i++ ) std::cout << " ";
		std::cout << "Object " << citygml::getCityObjectsClassName( object->getType() ) << ": " << object->getId() << std::endl;

	for ( unsigned int i = 0; i < object->getChildCount(); i++ )
		analyzeObject( object->getChild(i), indent+1 );
}