├── .github └── workflows │ └── cmake-multi-platform.yml ├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── CMakeModules ├── FindCityGML.cmake ├── FindXerces.cmake ├── citygml_api.h.in └── cmake_uninstall.cmake.in ├── LICENSE ├── README.md ├── SpecsToCheck.md ├── TODO.md ├── citygml_to_libcitygml_mapping.graphml ├── data ├── FZK-Haus-LoD0-KIT-IAI-KHH-B36-V1.gml ├── b1_lod2_cs_w_sem.gml ├── b1_lod2_s.gml └── berlin_open_data_sample_data.citygml ├── debian_scripts └── postinst ├── libcitygml_classdiagram.graphml ├── osgplugin ├── CMakeLists.txt ├── CitygmlOsgViewer.cpp └── ReaderWriterCityGML.cpp ├── sources ├── .gitignore ├── CMakeLists.txt ├── citygml.pc.cmake ├── citygmlConfig.cmake.in ├── include │ ├── citygml │ │ ├── address.h │ │ ├── appearance.h │ │ ├── appearancemanager.h │ │ ├── appearancetarget.h │ │ ├── appearancetargetdefinition.h │ │ ├── attributesmap.h │ │ ├── citygml.h │ │ ├── citygmlfactory.h │ │ ├── citygmllogger.h │ │ ├── citymodel.h │ │ ├── cityobject.h │ │ ├── enum_type_bitmask.h │ │ ├── envelope.h │ │ ├── externalreference.h │ │ ├── featureobject.h │ │ ├── geometry.h │ │ ├── geometrymanager.h │ │ ├── georeferencedtexture.h │ │ ├── implictgeometry.h │ │ ├── linearring.h │ │ ├── linestring.h │ │ ├── material.h │ │ ├── materialtargetdefinition.h │ │ ├── object.h │ │ ├── polygon.h │ │ ├── polygonmanager.h │ │ ├── rectifiedgridcoverage.h │ │ ├── tesselator.h │ │ ├── tesselatorbase.h │ │ ├── texture.h │ │ ├── texturecoordinates.h │ │ ├── texturetargetdefinition.h │ │ ├── transformmatrix.h │ │ ├── utils.h │ │ ├── vecs.hpp │ │ └── warnings.h │ └── parser │ │ ├── addressparser.h │ │ ├── appearanceelementparser.h │ │ ├── attributes.h │ │ ├── citygmldocumentparser.h │ │ ├── citygmlelementparser.h │ │ ├── citymodelelementparser.h │ │ ├── cityobjectelementparser.h │ │ ├── delayedchoiceelementparser.h │ │ ├── documentlocation.h │ │ ├── elementparser.h │ │ ├── externalreferenceparser.h │ │ ├── geocoordinatetransformer.h │ │ ├── geometryelementparser.h │ │ ├── georeferencedtextureelementparser.h │ │ ├── gmlfeaturecollectionparser.h │ │ ├── gmlobjectparser.h │ │ ├── implicitgeometryelementparser.h │ │ ├── linearringelementparser.h │ │ ├── linestringelementparser.h │ │ ├── materialelementparser.h │ │ ├── nodetypes.h │ │ ├── parserutils.hpp │ │ ├── polygonelementparser.h │ │ ├── rectifiedgridcoverageparser.h │ │ ├── sequenceparser.h │ │ ├── skipelementparser.h │ │ ├── textureassociationelementparser.h │ │ └── textureelementparser.h └── src │ ├── citygml │ ├── address.cpp │ ├── appearance.cpp │ ├── appearancemanager.cpp │ ├── appearancetarget.cpp │ ├── attributesmap.cpp │ ├── citygmlfactory.cpp │ ├── citymodel.cpp │ ├── cityobject.cpp │ ├── envelope.cpp │ ├── externalreference.cpp │ ├── featureobject.cpp │ ├── geometry.cpp │ ├── geometrymanager.cpp │ ├── georeferencedtexture.cpp │ ├── implictgeometry.cpp │ ├── linearring.cpp │ ├── linestring.cpp │ ├── material.cpp │ ├── materialtargetdefinition.cpp │ ├── object.cpp │ ├── polygon.cpp │ ├── polygonmanager.cpp │ ├── rectifiedgridcoverage.cpp │ ├── tesselator.cpp │ ├── tesselatorbase.cpp │ ├── texture.cpp │ ├── texturecoordinates.cpp │ ├── texturetargetdefinition.cpp │ └── transformmatrix.cpp │ └── parser │ ├── addressparser.cpp │ ├── appearanceelementparser.cpp │ ├── attributes.cpp │ ├── citygmldocumentparser.cpp │ ├── citygmlelementparser.cpp │ ├── citymodelelementparser.cpp │ ├── cityobjectelementparser.cpp │ ├── delayedchoiceelementparser.cpp │ ├── elementparser.cpp │ ├── externalreferenceparser.cpp │ ├── geocoordinatetransformer.cpp │ ├── geometryelementparser.cpp │ ├── georeferencedtextureelementparser.cpp │ ├── gmlfeaturecollectionparser.cpp │ ├── gmlobjectparser.cpp │ ├── implicitgeometryelementparser.cpp │ ├── linearringelementparser.cpp │ ├── linestringelementparser.cpp │ ├── materialelementparser.cpp │ ├── nodetypes.cpp │ ├── parserxercesc.cpp │ ├── polygonelementparser.cpp │ ├── rectifiedgridcoverageparser.cpp │ ├── sequenceparser.cpp │ ├── skipelementparser.cpp │ ├── textureassociationelementparser.cpp │ └── textureelementparser.cpp ├── systemTests ├── CMakeLists.txt ├── FileReadTests.cpp └── systemTestsMain.cpp └── test ├── CMakeLists.txt └── citygmltest.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | *.dylib 9 | 10 | # Compiled Static libraries 11 | *.lai 12 | *.la 13 | *.a 14 | 15 | build 16 | build_debug 17 | CMakeLists.txt.user* 18 | install 19 | build/ 20 | buildRelease/ 21 | *.autosave 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | 2 | os: linux 3 | arch: 4 | - amd64 5 | - ppc64le 6 | language: cpp 7 | sudo: false 8 | compiler: 9 | - gcc 10 | - clang 11 | before_install: 12 | - echo $LANG 13 | - echo $LC_ALL 14 | - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi 15 | script: mkdir build && cd build && cmake ../ && make && ./bin/citygmltest ../data/berlin_open_data_sample_data.citygml && ./bin/citygmltest ../data/b1_lod2_s.gml && ./bin/citygmltest ../data/FZK-Haus-LoD0-KIT-IAI-KHH-B36-V1.gml 16 | addons: 17 | apt: 18 | sources: 19 | - ubuntu-toolchain-r-test 20 | - george-edison55-precise-backports 21 | packages: 22 | - libxerces-c-dev 23 | - libxerces-c3.1 24 | - libgdal1i 25 | - libgdal-dev 26 | - cmake-data 27 | - cmake 28 | - g++-4.8 29 | - gcc-4.8 30 | - libopenscenegraph-dev 31 | -------------------------------------------------------------------------------- /CMakeModules/FindCityGML.cmake: -------------------------------------------------------------------------------- 1 | # Locate libcitygml 2 | # This module defines 3 | # CITYGML_LIBRARY 4 | # CITYGML_LIBRARY_DEBUG 5 | # CITYGML_LIBRARIES, choses the correct debug or optimized library for linking, add this as Target Link library in your project 6 | # CITYGML_FOUND, if false, do not try to link to CITYGML 7 | # CITYGML_INCLUDE_DIR, where to find the headers 8 | # 9 | # $CITYGML_DIR is an environment variable that would 10 | # correspond to the ./configure --prefix=$CITYGML_DIR 11 | 12 | OPTION(CITYGML_DYNAMIC "Set to ON if libcitygml was built using dynamic linking. Use OFF for static." OFF) 13 | 14 | OPTION(CITYGML_USE_XERCESC "Set to ON to build libcitygml with Xerces-c library." ON) 15 | OPTION(CITYGML_USE_LIBXML2 "Set to ON to build libcitygml with LibXml2 library." OFF) 16 | 17 | IF( CITYGML_DYNAMIC ) 18 | ADD_DEFINITIONS( -DLIBCITYGML_DYNAMIC ) 19 | ENDIF( CITYGML_DYNAMIC ) 20 | 21 | IF ( CITYGML_USE_XERCESC AND CITYGML_USE_LIBXML2 ) 22 | MESSAGE("Error: You cannot build the library with Xerces-c AND LibXml2! Xerces library will be used by default.") 23 | SET( CITYGML_USE_LIBXML2 OFF CACHE BOOL "Set to ON to build libcitygml with LibXml2 library." FORCE) 24 | ENDIF( CITYGML_USE_XERCESC AND CITYGML_USE_LIBXML2 ) 25 | 26 | IF( CITYGML_USE_XERCESC ) 27 | FIND_PACKAGE( Xerces REQUIRED ) 28 | ADD_DEFINITIONS( -DUSE_XERCESC ) 29 | SET( LIBXML2_INCLUDE_DIR "" ) 30 | # SET( LIBXML2_LIBRARIES "" ) 31 | SET( LIBXML2_LIBRARY "" ) 32 | SET( LIBXML2_LIBRARY_DEBUG "" ) 33 | ENDIF( CITYGML_USE_XERCESC ) 34 | 35 | IF( CITYGML_USE_LIBXML2 ) 36 | FIND_PACKAGE( LibXml2 REQUIRED ) 37 | ADD_DEFINITIONS( -DUSE_LIBXML2 ) 38 | ADD_DEFINITIONS( ${LIBXML2_DEFINITIONS} ) 39 | SET( XERCESC_INCLUDE "" ) 40 | SET( XERCESC_LIBRARY "" ) 41 | SET( XERCESC_LIBRARY_DEBUG "" ) 42 | ENDIF( CITYGML_USE_LIBXML2 ) 43 | 44 | FIND_PATH( CITYGML_INCLUDE_DIR citygml/citygml.h 45 | ./include 46 | ../include 47 | $ENV{CITYGML_DIR}/include 48 | ~/Library/Frameworks 49 | /Library/Frameworks 50 | /usr/local/include 51 | /usr/include 52 | /sw/include # Fink 53 | /opt/local/include # DarwinPorts 54 | /opt/csw/include # Blastwave 55 | /opt/include 56 | /usr/freeware/include 57 | ) 58 | 59 | FIND_LIBRARY( CITYGML_LIBRARY 60 | NAMES citygml 61 | PATHS 62 | ./lib 63 | ../lib 64 | $ENV{CITYGML_DIR}/lib 65 | $ENV{CITYGML_DIR} 66 | ~/Library/Frameworks 67 | /Library/Frameworks 68 | /usr/local/lib 69 | /usr/lib 70 | /sw/lib 71 | /opt/local/lib 72 | /opt/csw/lib 73 | /opt/lib 74 | /usr/freeware/lib64 75 | ) 76 | 77 | FIND_LIBRARY( CITYGML_LIBRARY_DEBUG 78 | NAMES citygmld 79 | PATHS 80 | ./lib 81 | ../lib 82 | $ENV{CITYGML_DIR}/lib 83 | $ENV{CITYGML_DIR} 84 | ~/Library/Frameworks 85 | /Library/Frameworks 86 | /usr/local/lib 87 | /usr/lib 88 | /sw/lib 89 | /opt/local/lib 90 | /opt/csw/lib 91 | /opt/lib 92 | /usr/freeware/lib64 93 | ) 94 | 95 | SET( CITYGML_FOUND FALSE ) 96 | 97 | IF(CITYGML_LIBRARY AND CITYGML_INCLUDE_DIR) 98 | SET(CITYGML_FOUND TRUE) 99 | IF(NOT CITYGML_LIBRARY_DEBUG) 100 | MESSAGE("-- Warning Debug LibCityGML not found, using: ${CITYGML_LIBRARY}") 101 | SET(CITYGML_LIBRARY_DEBUG "${CITYGML_LIBRARY}" CACHE FILEPATH "Path to a library." FORCE) 102 | ENDIF(NOT CITYGML_LIBRARY_DEBUG) 103 | ENDIF(CITYGML_LIBRARY AND CITYGML_INCLUDE_DIR) 104 | 105 | SET(CITYGML_LIBRARIES optimized ${CITYGML_LIBRARY} debug ${CITYGML_LIBRARY_DEBUG}) 106 | 107 | -------------------------------------------------------------------------------- /CMakeModules/FindXerces.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Xerces-C 2 | # Once done this will define 3 | # 4 | # XERCESC_FOUND - system has Xerces-C 5 | # XERCESC_INCLUDE - the Xerces-C include directory 6 | # XERCESC_LIBRARY - Link these to use Xerces-C 7 | # XERCESC_VERSION - Xerces-C found version 8 | 9 | IF (XERCESC_INCLUDE AND XERCESC_LIBRARY) 10 | # in cache already 11 | SET(XERCESC_FIND_QUIETLY TRUE) 12 | ENDIF (XERCESC_INCLUDE AND XERCESC_LIBRARY) 13 | 14 | OPTION(XERCESC_STATIC "Set to ON to link your project with static library (instead of DLL)." ON) 15 | 16 | IF (NOT ${XERCESC_WAS_STATIC} STREQUAL ${XERCESC_STATIC}) 17 | UNSET(XERCESC_LIBRARY CACHE) 18 | UNSET(XERCESC_LIBRARY_DEBUG CACHE) 19 | ENDIF (NOT ${XERCESC_WAS_STATIC} STREQUAL ${XERCESC_STATIC}) 20 | 21 | SET(XERCESC_WAS_STATIC ${XERCESC_STATIC} CACHE INTERNAL "" ) 22 | 23 | FIND_PATH(XERCESC_INCLUDE NAMES xercesc/util/XercesVersion.hpp 24 | PATHS 25 | $ENV{XERCESC_INCLUDE_DIR} 26 | ${XERCESC_INCLUDE_DIR} 27 | /usr/local/include 28 | /usr/include 29 | ) 30 | 31 | IF (XERCESC_STATIC) 32 | FIND_LIBRARY(XERCESC_LIBRARY NAMES xerces-c_static_3 xerces-c-3.2 xerces-c-3.1 xerces-c xerces-c_3 33 | PATHS 34 | $ENV{XERCESC_LIBRARY_DIR} 35 | ${XERCESC_LIBRARY_DIR} 36 | /usr/lib 37 | /usr/local/lib 38 | ) 39 | FIND_LIBRARY(XERCESC_LIBRARY_DEBUG NAMES xerces-c_static_3D xerces-c-3.2D xerces-c-3.1D xerces-c_3D 40 | PATHS 41 | $ENV{XERCESC_LIBRARY_DIR} 42 | ${XERCESC_LIBRARY_DIR} 43 | /usr/lib 44 | /usr/local/lib 45 | ) 46 | ADD_DEFINITIONS( -DXERCES_STATIC_LIBRARY ) 47 | ELSE (XERCESC_STATIC) 48 | FIND_LIBRARY(XERCESC_LIBRARY NAMES xerces-c_3 49 | PATHS 50 | $ENV{XERCESC_LIBRARY_DIR} 51 | ${XERCESC_LIBRARY_DIR} 52 | ) 53 | FIND_LIBRARY(XERCESC_LIBRARY_DEBUG NAMES xerces-c_3D 54 | PATHS 55 | $ENV{XERCESC_LIBRARY_DIR} 56 | ${XERCESC_LIBRARY_DIR} 57 | ) 58 | ENDIF (XERCESC_STATIC) 59 | 60 | SET(XERCESC_FOUND FALSE) 61 | 62 | IF (XERCESC_INCLUDE AND XERCESC_LIBRARY) 63 | SET(XERCESC_FOUND TRUE) 64 | ENDIF (XERCESC_INCLUDE AND XERCESC_LIBRARY) 65 | 66 | IF(XERCESC_FOUND) 67 | 68 | IF(XERCESC_LIBRARY_DEBUG) 69 | SET(XERCESC_LIBRARIES 70 | optimized ${XERCESC_LIBRARY} 71 | debug ${XERCESC_LIBRARY_DEBUG}) 72 | ELSE(XERCESC_LIBRARY_DEBUG) 73 | SET(XERCESC_LIBRARIES ${XERCESC_LIBRARY}) 74 | ENDIF(XERCESC_LIBRARY_DEBUG) 75 | 76 | FIND_PATH(XERCESC_XVERHPPPATH NAMES XercesVersion.hpp PATHS 77 | ${XERCESC_INCLUDE} 78 | PATH_SUFFIXES xercesc/util) 79 | 80 | IF ( ${XERCESC_XVERHPPPATH} STREQUAL XERCESC_XVERHPPPATH-NOTFOUND ) 81 | SET(XERCES_VERSION "0") 82 | ELSE( ${XERCESC_XVERHPPPATH} STREQUAL XERCESC_XVERHPPPATH-NOTFOUND ) 83 | FILE(READ ${XERCESC_XVERHPPPATH}/XercesVersion.hpp XVERHPP) 84 | 85 | STRING(REGEX MATCHALL "\n *#define XERCES_VERSION_MAJOR +[0-9]+" XVERMAJ 86 | ${XVERHPP}) 87 | STRING(REGEX MATCH "\n *#define XERCES_VERSION_MINOR +[0-9]+" XVERMIN 88 | ${XVERHPP}) 89 | STRING(REGEX MATCH "\n *#define XERCES_VERSION_REVISION +[0-9]+" XVERREV 90 | ${XVERHPP}) 91 | 92 | STRING(REGEX REPLACE "\n *#define XERCES_VERSION_MAJOR +" "" 93 | XVERMAJ ${XVERMAJ}) 94 | STRING(REGEX REPLACE "\n *#define XERCES_VERSION_MINOR +" "" 95 | XVERMIN ${XVERMIN}) 96 | STRING(REGEX REPLACE "\n *#define XERCES_VERSION_REVISION +" "" 97 | XVERREV ${XVERREV}) 98 | 99 | SET(XERCESC_VERSION ${XVERMAJ}.${XVERMIN}.${XVERREV}) 100 | 101 | ENDIF ( ${XERCESC_XVERHPPPATH} STREQUAL XERCESC_XVERHPPPATH-NOTFOUND ) 102 | 103 | IF(NOT XERCESC_FIND_QUIETLY) 104 | MESSAGE(STATUS "Found Xerces-C: ${XERCESC_LIBRARY}") 105 | MESSAGE(STATUS " : ${XERCESC_INCLUDE}") 106 | MESSAGE(STATUS " Version: ${XERCESC_VERSION}") 107 | ENDIF(NOT XERCESC_FIND_QUIETLY) 108 | ELSE(XERCESC_FOUND) 109 | MESSAGE(FATAL_ERROR "Could not find Xerces-C !") 110 | ENDIF(XERCESC_FOUND) 111 | 112 | MARK_AS_ADVANCED(XERCESC_INCLUDE XERCESC_LIBRARY) 113 | -------------------------------------------------------------------------------- /CMakeModules/citygml_api.h.in: -------------------------------------------------------------------------------- 1 | #define LIBCITYGML_VERSION_MAJOR @META_VERSION_MAJOR@ 2 | #define LIBCITYGML_VERSION_MINOR @META_VERSION_MINOR@ 3 | #define LIBCITYGML_VERSION_REVISION @META_VERSION_PATCH@ 4 | 5 | #define LIBCITYGML_CREATE_VERSION_STRING_(x, y, z) #x"."#y"."#z 6 | #define LIBCITYGML_CREATE_VERSION_STRING(major,minor,revision) LIBCITYGML_CREATE_VERSION_STRING_(major, minor, revision) 7 | #define LIBCITYGML_VERSIONSTR LIBCITYGML_CREATE_VERSION_STRING(LIBCITYGML_VERSION_MAJOR, LIBCITYGML_VERSION_MINOR, LIBCITYGML_VERSION_REVISION) 8 | 9 | #define LIBCITYGML_VERSION_LESS(major, minor, revision) major > LIBCITYGML_VERSION_MAJOR || \ 10 | (major == LIBCITYGML_VERSION_MAJOR && (minor > LIBCITYGML_VERSION_MINOR || \ 11 | (minor == LIBCITYGML_VERSION_MINOR && revision > LIBCITYGML_VERSION_REVISION))) 12 | 13 | #include 14 | -------------------------------------------------------------------------------- /CMakeModules/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 2 | MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") 3 | ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 4 | 5 | FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 6 | STRING(REGEX REPLACE "\n" ";" files "${files}") 7 | FOREACH(file ${files}) 8 | MESSAGE(STATUS "Uninstalling \"${file}\"") 9 | IF(EXISTS "${file}") 10 | EXEC_PROGRAM( 11 | "@CMAKE_COMMAND@" ARGS "-E remove \"${file}\"" 12 | OUTPUT_VARIABLE rm_out 13 | RETURN_VALUE rm_retval 14 | ) 15 | IF("${rm_retval}" STREQUAL 0) 16 | ELSE("${rm_retval}" STREQUAL 0) 17 | MESSAGE(FATAL_ERROR "Problem when removing \"${file}\"") 18 | ENDIF("${rm_retval}" STREQUAL 0) 19 | ELSE(EXISTS "${file}") 20 | MESSAGE(STATUS "File \"${file}\" does not exist.") 21 | ENDIF(EXISTS "${file}") 22 | ENDFOREACH(file) 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | libcitygml 2 | ========== 3 | [![Build Status](https://travis-ci.org/jklimke/libcitygml.svg?branch=master)](https://travis-ci.org/jklimke/libcitygml) 4 | 5 | [CityGML](http://www.citygml.org/) (City Geography Markup Language) is an XML-based schema for the modelling and exchange of georeferenced 3D city and landscape models that is quickly being adopted on an international level. 6 | 7 | libcitygml is a small and easy to use open source C++ library for parsing CityGML files in such a way that data can be easily exploited by 3D rendering applications (geometry data are tesselated and optimized for rendering during parsing). For instance, it can be used to develop readers of CityGML files in many 3D based applications (OpenGL, OpenSceneGraph, ...) Most metadata are not lost, they are available through a per-node hashmap. 8 | 9 | The project also contains a loader plugin for [OpenSceneGraph](http://www.openscenegraph.org/). It enables OpenSceneGraph (if installed) to read citygml documents for easy rendering and further graphical optimization. 10 | 11 | libcitygml was initally developed by the 3D team of BRGM (the French leading public institution involved in the Earth Science field for the sustainable management of natural resources and surface and subsurface risks) for the research project DeepCity3D. It is now conducted as a Github open source project. 12 | 13 | It was moved to github due to inactivity of the project on google code (https://code.google.com/p/libcitygml/). 14 | 15 | 16 | How to Setup 17 | ============ 18 | 19 | The project is based on the CMAKE build system and should be pretty straight forward to setup. 20 | 21 | Dependencies: 22 | 23 | The XercesC xml parsing library is the only requirement compiling and using libcitygml. Please use a version > 3.1 compiled with an SDK that is compatible with C++11. If the library is not found by CMake use `-DCMAKE_SYSTEM_PREFIX_PATH=`. 24 | 25 | OpenGL is required if you want to use the tesselator provided in the project. Otherwise, you can provide another implementation by inheriting TesselatorBase, or not use tesselation. Set the cmake option "LIBCITYGML_USE_OPENGL" to OFF to disable the use of OpenGL. 26 | 27 | GDAL is required if coordinate transformations should be applied during paring. 28 | Set the cmake option "LIBCITYGML_USE_GDAL" to OFF to disable the use of GDAL. 29 | 30 | OpenSceneGraph is required to build the plugin. 31 | Set the cmake option "LIBCITYGML_OSGPLUGIN" to ON to enable the build of the plugin. 32 | 33 | Test Data Attribution 34 | ===================== 35 | 36 | 37 | Overview over the testing data within the "data" directory: 38 | 39 | | Dataset | Attribution | Source | 40 | | ------------------------- |:---------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------:| 41 | | data/b1_lod2_cs_w_sem.gml | https://www.citygml.org/samplefiles/building/ | [https://www.citygml.org](https://www.citygml.org/samplefiles/) | 42 | | data/b1_lod2_s.gml | https://www.citygml.org/samplefiles/building/ | [https://www.citygml.org](https://www.citygml.org/samplefiles/) | 43 | | data/berlin_open_data_sample_data.gml | Berlin Partner für Wirtschaft und Technologie GmbH | [Berlin Partner Download Portal](http://www.businesslocationcenter.de/berlin3d-downloadportal/?lang=en) | 44 | | data/FZK-Haus-LoD0-KIT-IAI-KHH-B36-V1.gml | Institute for Automation and Applied Computer Science (IAI) / Karlsruhe Institute of Technology (KIT) | https://www.citygmlwiki.org/index.php?title=FZK_Haus | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /SpecsToCheck.md: -------------------------------------------------------------------------------- 1 | # Specification of Modules to check 2 | 3 | ## CityGML 4 | 5 | CityGML Module | Namespace identifier | schemaLocation | Recommended namespace prefix | Checked 6 | --- | --- | --- | ---- | --- 7 | Core | http://www.opengis.net/citygml/1.0 | http://schemas.opengis.net/citygml/1.0/cityGMLBase.xsd | core | ☑ 8 | Appearance | http://www.opengis.net/citygml/appearance/1.0 | http://schemas.opengis.net/citygml/appearance/1.0/appearance.xsd | app | ☑ 9 | Building | http://www.opengis.net/citygml/building/1.0 | http://schemas.opengis.net/citygml/building/1.0/building.xsd | bldg | ☑ 10 | CityFurniture | http://www.opengis.net/citygml/cityfurniture/1.0 | http://schemas.opengis.net/citygml/cityfurniture/1.0/cityFurniture.xsd | frn | ☑ 11 | CityObjectGroup | http://www.opengis.net/citygml/cityobjectgroup/1.0 | http://schemas.opengis.net/citygml/cityobjectgroup/1.0/cityObjectGroup.xsd | grp | ☑ 12 | Generics | http://www.opengis.net/citygml/generics/1.0 | http://schemas.opengis.net/citygml/generics/1.0/generics.xsd | gen | ☑ 13 | LandUse | http://www.opengis.net/citygml/landuse/1.0 | http://schemas.opengis.net/citygml/landuse/1.0/landUse.xsd | luse | ☑ 14 | Relief | http://www.opengis.net/citygml/relief/1.0 | http://schemas.opengis.net/citygml/relief/1.0/relief.xsd | dem | ☑ 15 | Transportation | http://www.opengis.net/citygml/transportation/1.0 | http://schemas.opengis.net/citygml/transportation/1.0/transportation.xsd | tran | ☑ 16 | Vegetation | http://www.opengis.net/citygml/vegetation/1.0 | http://schemas.opengis.net/citygml/vegetation/1.0/vegetation.xsd | veg | ☑ 17 | WaterBody | http://www.opengis.net/citygml/waterbody/1.0 | http://schemas.opengis.net/citygml/waterbody/1.0/waterBody.xsd | wtr | ☑ 18 | 19 | ## GML 20 | 21 | GML Module | schemaLocation | Checked 22 | --- | --- | --- 23 | Basic Types | http://schemas.opengis.net/gml/3.1.1/base/basicTypes.xsd | ☐ 24 | Geometry | http://schemas.opengis.net/gml/3.1.1/base/geometryBasic0d1d.xsd | ☐ -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | # libcitygml TODO List 2 | 3 | # Correctness 4 | * Check if the normals calculated for tesselation is always correct even if the vertices are in a spherical coordinate system 5 | ... if not one should think about removing the tesselation from libcitygml 6 | * Check if OrientableSurfaces are supported properly... may be the vertices must be reverted if the orientation is '-' 7 | * Check if Appearance assignment is correct for shared polygons 8 | * Ensure that polygons that are children of shared geometries are not also children of non shared geometries (otherwise a coordinate transformation might be applied on the vertices which is not allowed for shared geometries) 9 | * The namespace of the different modules may differ from the recommended one... make a namespace mapping based on the uri 10 | * Currently different city object types are grouped under the same enum type (CityObjectType) e.g. WaterSurface, WaterGroundSurface, WaterClosureSurface and WaterBody are of type COT_WaterBody. The reason for this is that every enum type is identified by an individual bit... however there are only 32 bits. Check if the bitmask is actually used... if not remove that constraint and define an individual enum type for every CityObject type 11 | * Some polygon types (PolygonSurface, Polygon, Triangle etc.) have an implicit ("planar") or explicit gml:SurfaceInterpolationType attribute... currently its ignored 12 | 13 | # Completness 14 | * Implement parsing of CityObject `` member (contains a cityobject or references one that is the generalization of the current one) =>` requires cityobject sharing 15 | * Implement parsing of CityObject `` member 16 | * Implement complete address parsing: Currently the address attributes (street, postalcode, etc.) are stored as indivdual address attributes. However a address can be assigned zero or more 2D or 3D point geometries (one gml:MultiPoint geometry) locating the entrance. This requires parsing of the `
` as an individual element 17 | * Implement parsing of ImplicitGeometry `` member 18 | * Implement GeoreferencedTexture parsing 19 | * Implement appearence `` support 20 | * Implement `` support (Darunter kann eine beliebige GML Geometrie hängen) 21 | * Implement full support for `` and `` (requires city object sharing, currently only inline definitions are supported) 22 | * Implement sharing for all geometries (currently onl ImplicitGeometries) 23 | * Implement lod0 parsing 24 | * Implement Relief/Terrain Model (Namespace DEM) parsing. More precisely implement ReliefComponentPropertyType parsing. 25 | * Requires gml:MultiPointPropertyType parsing 26 | * Requires gml:MultiCurvePropertyType parsing (also required for wtr module) 27 | * Requires gml:RectifiedGridCoverage parsing 28 | * Implement gml:Tin parsing (possible child of `` element that uses delauny triangulation) 29 | 30 | # Refactoring 31 | * Change the NodeTypes so that typeID is a constant expression -> Use switch-case structures instead of if-then-else in the element parsers 32 | * Rename Appearance in SurfaceData (an Appearance is actually the objects that defines a Theme) 33 | 34 | # Features 35 | * Enable CityObject filering by type mask (ParserParams) 36 | 37 | 38 | # Optimization 39 | * Remove empty objects 40 | * 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) 41 | -------------------------------------------------------------------------------- /debian_scripts/postinst: -------------------------------------------------------------------------------- 1 | ldconfig 2 | -------------------------------------------------------------------------------- /osgplugin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(target osgdb_citygml) 2 | 3 | set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON) 4 | find_package( OpenSceneGraph REQUIRED osgDB osgViewer osgGA osgUtil osgText) 5 | 6 | include_directories( 7 | ${OPENSCENEGRAPH_INCLUDE_DIRS} 8 | ${CMAKE_CURRENT_SOURCE_DIR}/../sources/include 9 | ) 10 | 11 | set( sources ReaderWriterCityGML.cpp ) 12 | 13 | add_library(${target} SHARED ${sources}) 14 | set_target_properties(${target} PROPERTIES PREFIX "") 15 | if(APPLE) 16 | SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so") 17 | endif(APPLE) 18 | target_link_libraries(${target} ${OPENSCENEGRAPH_LIBRARIES} citygml) 19 | 20 | set(OSG_PLUGINS "osgPlugins-${OPENSCENEGRAPH_VERSION}") 21 | set(LIBCITYGML_OSG_PLUGIN_INSTALL_DIR "" CACHE PATH "The directory in which the plugin will be installed. (osgPlugins- is appended to this path)") 22 | 23 | set(PLUGIN_INSTALL_PATH lib/${OSG_PLUGINS}) 24 | if (LIBCITYGML_OSG_PLUGIN_INSTALL_DIR) 25 | set(PLUGIN_INSTALL_PATH ${LIBCITYGML_OSG_PLUGIN_INSTALL_DIR}/${OSG_PLUGINS}) 26 | endif() 27 | 28 | add_definitions(-DPLUGIN_BIN_DIR=\"${CMAKE_BINARY_DIR}/lib\") 29 | add_executable(citygmlOsgViewer CitygmlOsgViewer.cpp) 30 | target_link_libraries(citygmlOsgViewer ${OPENSCENEGRAPH_LIBRARIES} citygml) 31 | 32 | INSTALL( 33 | TARGETS ${target} 34 | RUNTIME DESTINATION ${PLUGIN_INSTALL_PATH} 35 | LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH} 36 | ARCHIVE DESTINATION ${PLUGIN_INSTALL_PATH} 37 | ) 38 | 39 | INSTALL( 40 | TARGETS citygmlOsgViewer 41 | RUNTIME DESTINATION bin 42 | LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH} 43 | ARCHIVE DESTINATION ${PLUGIN_INSTALL_PATH} 44 | ) 45 | -------------------------------------------------------------------------------- /sources/.gitignore: -------------------------------------------------------------------------------- 1 | include/citygml/citygml_api.h 2 | include/citygml/citygml_export.h 3 | -------------------------------------------------------------------------------- /sources/citygml.pc.cmake: -------------------------------------------------------------------------------- 1 | prefix=${CMAKE_INSTALL_PREFIX} 2 | exec_prefix=${CMAKE_INSTALL_BINDIR} 3 | libdir=${CMAKE_INSTALL_LIBDIR} 4 | includedir=${INCLUDE_INSTALL_DIR} 5 | 6 | Name: citygml 7 | Description: Read and Write CityGML files 8 | Requires: ${PKG_CONFIG_REQUIRES} 9 | Version: ${META_VERSION} 10 | Libs: -L${CMAKE_INSTALL_LIBDIR} -lcitygml${LIBCITYGML_POSTFIX} 11 | Cflags: -I${INCLUDE_INSTALL_DIR} 12 | -------------------------------------------------------------------------------- /sources/citygmlConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/citygmlConfigInternal.cmake") 4 | 5 | set(CITYGML_ROOT_DIR ${PACKAGE_PREFIX_DIR}) 6 | set(CITYGML_LIBRARIES citygml::citygml) 7 | set(CITYGML_DYNAMIC @LIBCITYGML_DYNAMIC@) 8 | get_property(CITYGML_INCLUDE_DIRS TARGET citygml::citygml PROPERTY INTERFACE_INCLUDE_DIRECTORIES) 9 | set(CITYGML_LIBRARY_DIRS "") 10 | -------------------------------------------------------------------------------- /sources/include/citygml/address.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace citygml { 8 | 9 | class LIBCITYGML_EXPORT Address: public Object 10 | { 11 | public: 12 | Address(const std::string& id); 13 | 14 | const std::string& country() const; 15 | void setCountry(const std::string& country); 16 | 17 | const std::string& locality() const; 18 | void setLocality(const std::string& locality); 19 | 20 | const std::string& postalCode() const; 21 | void setPostalCode(const std::string& postalCode); 22 | 23 | const std::string& thoroughfareName() const; 24 | void setThoroughfareName(const std::string& thoroughfareName); 25 | 26 | const std::string& thoroughfareNumber() const; 27 | void setThoroughfareNumber(const std::string& thoroughfareNumber); 28 | 29 | protected: 30 | PRAGMA_WARN_DLL_BEGIN 31 | std::string m_country; 32 | std::string m_locality; 33 | std::string m_thoroughfareName; 34 | std::string m_thoroughfareNumber; 35 | std::string m_postalCode; 36 | PRAGMA_WARN_DLL_END 37 | }; 38 | 39 | } /* namespace citygml */ 40 | -------------------------------------------------------------------------------- /sources/include/citygml/appearance.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace citygml { 13 | 14 | class Material; 15 | class Texture; 16 | class GeoreferencedTexture; 17 | 18 | 19 | PRAGMA_WARN_DLL_BEGIN 20 | class LIBCITYGML_EXPORT Appearance : public Object, public std::enable_shared_from_this 21 | { 22 | PRAGMA_WARN_DLL_END 23 | public: 24 | std::string getType() const; 25 | 26 | bool getIsFront() const; 27 | void setIsFront(bool front); 28 | 29 | virtual std::string toString() const; 30 | 31 | virtual std::shared_ptr asMaterial(); 32 | virtual std::shared_ptr asMaterial() const; 33 | 34 | virtual std::shared_ptr asTexture(); 35 | virtual std::shared_ptr asTexture() const; 36 | 37 | virtual std::shared_ptr asGeoreferencedTexture(); 38 | virtual std::shared_ptr asGeoreferencedTexture() const; 39 | 40 | bool inTheme(const std::string& themeName) const; 41 | void addToTheme(std::string themeName); 42 | const std::vector& getThemes() const; 43 | 44 | virtual ~Appearance() {} 45 | 46 | protected: 47 | Appearance( const std::string& id, const std::string& typeString ); 48 | PRAGMA_WARN_DLL_BEGIN 49 | std::string m_typeString; 50 | std::vector m_themes; 51 | PRAGMA_WARN_DLL_END 52 | 53 | bool m_isFront; 54 | }; 55 | 56 | } 57 | -------------------------------------------------------------------------------- /sources/include/citygml/appearancemanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace citygml { 13 | 14 | class CityGMLLogger; 15 | class Appearance; 16 | class AppearanceTarget; 17 | class Material; 18 | class Texture; 19 | class MaterialTargetDefinition; 20 | class TextureTargetDefinition; 21 | 22 | 23 | class LIBCITYGML_EXPORT AppearanceManager 24 | { 25 | public: 26 | AppearanceManager(std::shared_ptr logger ); 27 | 28 | ~AppearanceManager(); 29 | 30 | /** 31 | * @brief returns the appearance with the given id 32 | * @return the Appearance object or nullptr if not found 33 | */ 34 | std::shared_ptr getAppearanceByID( const std::string& id ) const; 35 | 36 | /** 37 | * @brief all themes found in the parsed citygml file 38 | * @return a list of theme identifiers 39 | * @note should be called after assignAppearancesToTargets (otherwise the list will be empty) 40 | */ 41 | std::vector getAllThemes(); 42 | 43 | void addAppearanceTarget(AppearanceTarget* target); 44 | 45 | void addAppearance(std::shared_ptr appearance); 46 | void addTextureTargetDefinition(std::shared_ptr targetDef); 47 | void addMaterialTargetDefinition(std::shared_ptr targetDef); 48 | 49 | /** 50 | * @brief assigns each appearance to all targets for which a coresponding AppearanceTargetDefinition exits. 51 | * @note should be called once after parsing has finished 52 | */ 53 | void assignAppearancesToTargets(); 54 | 55 | 56 | protected: 57 | PRAGMA_WARN_DLL_BEGIN 58 | std::unordered_map > m_appearancesMap; 59 | std::vector > m_materialTargetDefinitions; 60 | std::vector > m_texTargetDefinitions; 61 | std::unordered_set m_themes; 62 | std::unordered_map m_appearanceTargetsMap; 63 | std::shared_ptr m_logger; 64 | PRAGMA_WARN_DLL_END 65 | 66 | void addThemesFrom(std::shared_ptr surfaceData); 67 | }; 68 | 69 | } 70 | -------------------------------------------------------------------------------- /sources/include/citygml/appearancetarget.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | namespace citygml { 13 | 14 | class MaterialTargetDefinition; 15 | class TextureTargetDefinition; 16 | class Appearance; 17 | 18 | /** 19 | * @brief The AppearanceTarget class is the base class for all citygml objects that can be targets of appearances 20 | * 21 | * Ensures that there is only one texture and material per theme 22 | */ 23 | class LIBCITYGML_EXPORT AppearanceTarget : public citygml::Object { 24 | public: 25 | 26 | void addTargetDefinition(std::shared_ptr > targetDef); 27 | void addTargetDefinition(std::shared_ptr targetDef); 28 | void addTargetDefinition(std::shared_ptr targetDef); 29 | 30 | void addTargetDefinitionsOf(const AppearanceTarget& other); 31 | 32 | std::shared_ptr getMaterialTargetDefinitionForTheme(const std::string& theme, bool front); 33 | std::shared_ptr getMaterialTargetDefinitionForTheme(const std::string& theme, bool front) const; 34 | 35 | std::shared_ptr getTextureTargetDefinitionForTheme(const std::string& theme, bool front); 36 | std::shared_ptr getTextureTargetDefinitionForTheme(const std::string& theme, bool front) const; 37 | 38 | std::vector getTextureTargetDefinitions(); 39 | 40 | std::vector getAllMaterialThemes(bool front) const; 41 | std::vector getAllTextureThemes(bool front) const; 42 | 43 | protected: 44 | AppearanceTarget(const std::string& id); 45 | 46 | 47 | 48 | private: 49 | PRAGMA_WARN_DLL_BEGIN 50 | std::unordered_map > m_themeMatMapFront; 51 | std::unordered_map > m_themeMatMapBack; 52 | 53 | std::unordered_map > m_themeTexMapFront; 54 | std::unordered_map > m_themeTexMapBack; 55 | PRAGMA_WARN_DLL_END 56 | 57 | }; 58 | } 59 | -------------------------------------------------------------------------------- /sources/include/citygml/appearancetargetdefinition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace citygml { 10 | 11 | /* 12 | * TODO: 13 | * - store the target id here 14 | * - store the appearance object here as a shared pointer 15 | * - create a subclass for material appearance type and texture appearance type (TextureTargetDefinition, MaterialTargetDefinition) 16 | * - modify AppearanceTarget so that is contains distinct lists for TextureTargetDefinition and MaterialTargetDefinition definitions... store the AppearanceTargetDefinitions as shared_ptr 17 | * - remove all knowledge of thier targets from the appearance objects (Texture, Material) 18 | * - let the appearance manager store the AppearanceTargetDefinition objects and the Appearance objects until they are assigned... then remove them from the appearance manager 19 | * - when finishing the AppearanceTarget objcts pass down the AppearanceTargetDefinition 20 | * - when finishing the polygon object remove all AppearanceTargetDefinition that are unused 21 | */ 22 | 23 | /** 24 | * @brief defines the association between an Appearance object and an AppearanceTarget object 25 | */ 26 | template 27 | class LIBCITYGML_EXPORT AppearanceTargetDefinition : public Object { 28 | public: 29 | AppearanceTargetDefinition(const std::string& targetID, std::shared_ptr appearance, const std::string& id) : Object(id), m_targetID(targetID), m_appearance(appearance) {} 30 | 31 | /** 32 | * @brief the id of the target surface 33 | * @note The targetID must not be the id of the object on which the texture is applied at the end (may be passed down to the children of the target object) 34 | */ 35 | std::string getTargetID() const { return m_targetID; } 36 | 37 | std::shared_ptr getAppearance() const { return m_appearance; } 38 | std::shared_ptr getAppearance() { return m_appearance; } 39 | 40 | virtual ~AppearanceTargetDefinition() {} 41 | 42 | protected: 43 | PRAGMA_WARN_DLL_BEGIN 44 | std::string m_targetID; 45 | std::shared_ptr m_appearance; 46 | PRAGMA_WARN_DLL_END 47 | 48 | }; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /sources/include/citygml/attributesmap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace citygml 10 | { 11 | 12 | /** 13 | * @brief The AttributeType enum represents the data type of an object attribute 14 | */ 15 | enum class AttributeType 16 | { 17 | String, 18 | Double, 19 | Integer, 20 | Date, 21 | Uri 22 | }; 23 | 24 | /** 25 | * @brief The AttributeValue class stores an attribute value and its data type 26 | */ 27 | class LIBCITYGML_EXPORT AttributeValue 28 | { 29 | public: 30 | AttributeValue(); 31 | AttributeValue(const char* value); 32 | AttributeValue(const std::string& value, AttributeType type=AttributeType::String); 33 | AttributeValue(double value); 34 | AttributeValue(int value); 35 | 36 | 37 | void setType(AttributeType type); 38 | AttributeType getType() const; 39 | 40 | void setValue(const std::string& value, AttributeType type=AttributeType::String); 41 | void setValue(double value); 42 | void setValue(int value); 43 | 44 | std::string asString() const; 45 | double asDouble(double defaultValue=0.0) const; 46 | int asInteger(int defaultValue=0) const; 47 | private: 48 | AttributeType m_type; 49 | PRAGMA_WARN_DLL_BEGIN 50 | std::string m_value; 51 | PRAGMA_WARN_DLL_END 52 | }; 53 | 54 | LIBCITYGML_EXPORT std::ostream& operator<<(std::ostream& os, const AttributeValue& o); 55 | 56 | typedef std::map AttributesMap; 57 | 58 | } // namespace citygml 59 | -------------------------------------------------------------------------------- /sources/include/citygml/citygml.h: -------------------------------------------------------------------------------- 1 | /* -*-c++-*- libcitygml - Copyright (c) 2010 Joachim Pouderoux, BRGM 2 | * 3 | * This file is part of libcitygml library 4 | * http://code.google.com/p/libcitygml 5 | * 6 | * libcitygml is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 2.1 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * libcitygml is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace citygml 38 | { 39 | class CityModel; 40 | class CityGMLLogger; 41 | class Appearance; 42 | class Texture; 43 | class Material; 44 | class AppearanceManager; 45 | 46 | typedef EnumClassBitmask CityObjectsTypeMask; 47 | 48 | 49 | /////////////////////////////////////////////////////////////////////////////// 50 | // Parsing routines 51 | 52 | // Parameters: 53 | // objectsMask: a bit mask that defines which CityObjectsTypes are parsed 54 | // examples: CityObject::CityObjectsType::COT_Building | CityObject::CityObjectsType::COT_Room <- parses only Building and Room objects" 55 | // minLOD: the minimal LOD that will be parsed 56 | // maxLOD: the maximal LOD that will be parsed 57 | // optimize: merge geometries & polygons that share the same appearance in the same object in order to reduce the global hierarchy 58 | // pruneEmptyObjects: remove the objects which do not contains any geometrical entity 59 | // tesselate: convert the interior & exteriors polygons to triangles 60 | // destSRS: the SRS (WKT, EPSG, OGC URN, etc.) where the coordinates must be transformed, default ("") is no transformation 61 | // srsSRS: the SRS (WKT, EPSG, OGC URN, etc.) to overrride the SRS in the CityGML data (if any), default ("") means no override or use included SRS 62 | 63 | class LIBCITYGML_EXPORT ParserParams 64 | { 65 | public: 66 | ParserParams() 67 | : objectsMask(CityObject::CityObjectsType::COT_All) 68 | , minLOD( 0 ) 69 | , maxLOD( 4 ) 70 | , optimize( false ) 71 | , pruneEmptyObjects( false ) 72 | , tesselate( true ) 73 | , keepVertices ( false ) 74 | , destSRS( "" ) 75 | , srcSRS( "" ) 76 | { } 77 | 78 | public: 79 | CityObjectsTypeMask objectsMask; 80 | unsigned int minLOD; 81 | unsigned int maxLOD; 82 | bool optimize; 83 | bool pruneEmptyObjects; 84 | bool tesselate; 85 | bool keepVertices; 86 | PRAGMA_WARN_DLL_BEGIN 87 | std::string destSRS; 88 | std::string srcSRS; 89 | PRAGMA_WARN_DLL_END 90 | }; 91 | 92 | LIBCITYGML_EXPORT std::shared_ptr load( std::istream& stream, const ParserParams& params, std::unique_ptr tesselator, std::shared_ptr logger = nullptr); 93 | 94 | LIBCITYGML_EXPORT std::shared_ptr load( const std::string& fileName, const ParserParams& params, std::unique_ptr tesselator, std::shared_ptr logger = nullptr); 95 | 96 | } 97 | -------------------------------------------------------------------------------- /sources/include/citygml/citygmlfactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace citygml { 11 | 12 | class AppearanceManager; 13 | class PolygonManager; 14 | class GeometryManager; 15 | class CityGMLLogger; 16 | 17 | class CityModel; 18 | class AppearanceTarget; 19 | class CityObject; 20 | class Geometry; 21 | class ImplicitGeometry; 22 | class Polygon; 23 | class LineString; 24 | class RectifiedGridCoverage; 25 | 26 | class Appearance; 27 | class Texture; 28 | class GeoreferencedTexture; 29 | class Material; 30 | 31 | class MaterialTargetDefinition; 32 | class TextureTargetDefinition; 33 | 34 | class LIBCITYGML_EXPORT CityGMLFactory { 35 | public: 36 | CityGMLFactory(std::shared_ptr logger); 37 | 38 | CityModel* createCityModel(const std::string& id); 39 | CityObject* createCityObject(const std::string& id, CityObject::CityObjectsType type); 40 | Geometry* createGeometry(const std::string& id, const CityObject::CityObjectsType& cityObjType = CityObject::CityObjectsType::COT_All, unsigned int lod = 0, std::string srsName = ""); 41 | RectifiedGridCoverage* createRectifiedGridCoverage(std::string const& id); 42 | 43 | std::shared_ptr createPolygon(const std::string& id); 44 | std::shared_ptr createLineString(const std::string& id); 45 | ExternalReference* createExternalReference(const std::string& id); 46 | 47 | /** 48 | * @brief requests a polygon for a Geometry object that will be added later 49 | * @param geom the Geometry object to which the polygon will be added 50 | * @param polygonId the id of the polygon 51 | */ 52 | void requestSharedPolygonForGeometry(Geometry* geom, const std::string& polygonId); 53 | 54 | ImplicitGeometry* createImplictGeometry(const std::string& id); 55 | std::shared_ptr shareGeometry(Geometry* geom); 56 | void requestSharedGeometryWithID(ImplicitGeometry* implicitGeom, const std::string& id); 57 | 58 | std::shared_ptr createTexture(const std::string& id); 59 | std::shared_ptr createMaterial(const std::string& id); 60 | std::shared_ptr createGeoReferencedTexture(const std::string& id); 61 | 62 | std::shared_ptr createMaterialTargetDefinition(const std::string& targetID, std::shared_ptr appearance, const std::string& id); 63 | std::shared_ptr createTextureTargetDefinition(const std::string& targetID, std::shared_ptr appearance, const std::string& id); 64 | 65 | std::shared_ptr getAppearanceWithID(const std::string& id); 66 | std::vector getAllThemes(); 67 | 68 | void closeFactory(); 69 | 70 | ~CityGMLFactory(); 71 | protected: 72 | void appearanceTargetCreated(AppearanceTarget* obj); 73 | 74 | PRAGMA_WARN_DLL_BEGIN 75 | std::shared_ptr m_logger; 76 | std::unique_ptr m_appearanceManager; 77 | std::unique_ptr m_polygonManager; 78 | std::unique_ptr m_geometryManager; 79 | PRAGMA_WARN_DLL_END 80 | }; 81 | 82 | } 83 | -------------------------------------------------------------------------------- /sources/include/citygml/citygmllogger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace citygml { 8 | 9 | class LIBCITYGML_EXPORT CityGMLLogger { 10 | public: 11 | enum class LOGLEVEL { 12 | LL_ERROR = 4, 13 | LL_WARNING = 3, 14 | LL_INFO = 2, 15 | LL_DEBUG = 1, 16 | LL_TRACE = 0 17 | }; 18 | 19 | CityGMLLogger(LOGLEVEL level = LOGLEVEL::LL_ERROR):m_logLevel(level){} 20 | 21 | /** 22 | * @brief logs a message. Might be called from different threads. 23 | */ 24 | virtual void log(LOGLEVEL level, const std::string& message, const char* file=nullptr, int line=-1) const = 0; 25 | 26 | virtual bool isEnabledFor(LOGLEVEL level) const { 27 | return level >= getLogLevel(); 28 | }; 29 | 30 | virtual LOGLEVEL getLogLevel() const{ 31 | return m_logLevel; 32 | }; 33 | 34 | virtual LOGLEVEL setLogLevel(LOGLEVEL level) { 35 | return m_logLevel = level; 36 | }; 37 | private: 38 | 39 | LOGLEVEL m_logLevel; 40 | }; 41 | 42 | /** 43 | * @brief logs a message for a certain log level 44 | * @param logger a pointer to a CityGMLLogger 45 | * @param level the CityGMLLogger::LOGLEVEL 46 | * @param message a string or a stream expression 47 | */ 48 | #define CITYGML_LOG(logger, level, message) \ 49 | do { \ 50 | if (logger->isEnabledFor(level)) { \ 51 | std::stringstream ss; \ 52 | ss << message; \ 53 | logger->log(level, ss.str(), __FILE__, __LINE__); \ 54 | } \ 55 | } while (0); 56 | 57 | 58 | #define CITYGML_LOG_ERROR(logger, message) CITYGML_LOG(logger, citygml::CityGMLLogger::LOGLEVEL::LL_ERROR, message) 59 | #define CITYGML_LOG_WARN(logger, message) CITYGML_LOG(logger, citygml::CityGMLLogger::LOGLEVEL::LL_WARNING, message) 60 | #define CITYGML_LOG_INFO(logger, message) CITYGML_LOG(logger, citygml::CityGMLLogger::LOGLEVEL::LL_INFO, message) 61 | #define CITYGML_LOG_DEBUG(logger, message) CITYGML_LOG(logger, citygml::CityGMLLogger::LOGLEVEL::LL_DEBUG, message) 62 | #define CITYGML_LOG_TRACE(logger, message) CITYGML_LOG(logger, citygml::CityGMLLogger::LOGLEVEL::LL_TRACE, message) 63 | } 64 | -------------------------------------------------------------------------------- /sources/include/citygml/citymodel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | class TesselatorBase; 13 | 14 | namespace citygml { 15 | 16 | class AppearanceManager; 17 | class AppearanceTarget; 18 | class CityGMLLogger; 19 | class CityObject; 20 | class CityGMLFactory; 21 | 22 | typedef std::vector > CityObjects; 23 | typedef std::vector ConstCityObjects; 24 | typedef std::map< CityObject::CityObjectsType, std::vector > CityObjectsMap; 25 | 26 | class LIBCITYGML_EXPORT CityModel : public FeatureObject 27 | { 28 | friend class CityGMLFactory; 29 | public: 30 | 31 | /** 32 | * @brief Return the roots elements of the model. 33 | */ 34 | const ConstCityObjects getRootCityObjects() const; 35 | void addRootObject(CityObject* obj); 36 | 37 | unsigned int getNumRootCityObjects() const; 38 | CityObject& getRootCityObject(int i); 39 | const CityObject& getRootCityObject(int i) const; 40 | 41 | const ConstCityObjects getAllCityObjectsOfType( CityObject::CityObjectsType type ) const; 42 | 43 | const std::string& getSRSName() const; 44 | 45 | void finish(TesselatorBase* tesselator, bool optimize, bool tesselate, std::shared_ptr logger); 46 | 47 | std::vector themes() const; 48 | void setThemes(std::vector themes); 49 | 50 | ~CityModel(); 51 | 52 | protected: 53 | 54 | CityModel( const std::string& id = "CityModel"); 55 | 56 | void addToCityObjectsMapRecursive(const CityObject* cityObj); 57 | 58 | PRAGMA_WARN_DLL_BEGIN 59 | CityObjects m_roots; 60 | 61 | CityObjectsMap m_cityObjectsMap; 62 | 63 | std::string m_srsName; 64 | 65 | std::vector m_themes; 66 | PRAGMA_WARN_DLL_END 67 | }; 68 | 69 | LIBCITYGML_EXPORT std::ostream& operator<<( std::ostream&, const citygml::CityModel & ); 70 | } 71 | -------------------------------------------------------------------------------- /sources/include/citygml/enum_type_bitmask.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | template 10 | class LIBCITYGML_EXPORT EnumClassBitmask 11 | { 12 | private: 13 | T t; 14 | 15 | public: 16 | typedef typename std::underlying_type::type underlying_type; 17 | 18 | /*constexpr*/ EnumClassBitmask() : t(T(0)) {} 19 | /*constexpr*/ EnumClassBitmask(T t) : t(t) {} 20 | /*constexpr*/ explicit EnumClassBitmask(underlying_type t) : t(T(t)) {} 21 | 22 | /*constexpr*/ /*explicit*/ operator bool() const { return bool(t); } 23 | /*constexpr*/ operator T() { return t; } 24 | 25 | /*constexpr*/ EnumClassBitmask operator|(T r) const { return EnumClassBitmask(t | r); } 26 | /*constexpr*/ EnumClassBitmask operator&(T r) const { return EnumClassBitmask(t & r); } 27 | /*constexpr*/ EnumClassBitmask operator^(T r) const { return EnumClassBitmask(t ^ r); } 28 | /*constexpr*/ EnumClassBitmask operator~() const { return EnumClassBitmask(~t); } 29 | 30 | const EnumClassBitmask& operator|=(T r) { t = t | r; return *this; } 31 | const EnumClassBitmask& operator&=(T r) { t = t & r; return *this; } 32 | const EnumClassBitmask& operator^=(T r) { t = t ^ r; return *this; } 33 | 34 | bool operator==(const EnumClassBitmask& r) { return underlying_type(t) == underlying_type(r.t); } 35 | bool operator==(const T& r) { return underlying_type(t) == underlying_type(r); } 36 | 37 | const EnumClassBitmask& setFromUnderlyingType(underlying_type value) { t = T(value); return *this; } 38 | 39 | friend std::istream& operator>> (std::istream &is, EnumClassBitmask& r) { underlying_type tmp; is >> tmp; r.t = static_cast(tmp); return is; } 40 | friend std::ostream& operator<< (std::ostream &os, const EnumClassBitmask& r) { os << static_cast(r.t); return os; } 41 | }; 42 | 43 | #define ENUM_CLASS_BITWISE_OPERATORS(type_name) \ 44 | /*constexpr*/ LIBCITYGML_EXPORT type_name operator|(type_name l, type_name r) { return type_name(std::underlying_type::type(l) | std::underlying_type::type(r)); } \ 45 | /*constexpr*/ LIBCITYGML_EXPORT type_name operator&(type_name l, type_name r) { return type_name(std::underlying_type::type(l) & std::underlying_type::type(r)); } \ 46 | /*constexpr*/ LIBCITYGML_EXPORT type_name operator^(type_name l, type_name r) { return type_name(std::underlying_type::type(l) ^ std::underlying_type::type(r)); } \ 47 | /*constexpr*/ LIBCITYGML_EXPORT type_name operator~(type_name l) { return type_name(~std::underlying_type::type(l)); } 48 | 49 | #define ENUM_CLASS_BITWISE_OPERATORS_DEFS(type_name) \ 50 | /*constexpr*/ LIBCITYGML_EXPORT type_name operator|(type_name l, type_name r); \ 51 | /*constexpr*/ LIBCITYGML_EXPORT type_name operator&(type_name l, type_name r); \ 52 | /*constexpr*/ LIBCITYGML_EXPORT type_name operator^(type_name l, type_name r);\ 53 | /*constexpr*/ LIBCITYGML_EXPORT type_name operator~(type_name l); 54 | 55 | 56 | -------------------------------------------------------------------------------- /sources/include/citygml/envelope.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace citygml { 10 | 11 | /** 12 | * @brief The Envelope class defines a bounding box in an spatial reference system (gml:Envelope) 13 | */ 14 | class LIBCITYGML_EXPORT Envelope 15 | { 16 | public: 17 | Envelope(); 18 | Envelope(const std::string& srsName); 19 | 20 | /** 21 | * @brief lower left front corner of the bounding box in srs coordinates 22 | */ 23 | const TVec3d& getLowerBound() const; 24 | void setLowerBound(const TVec3d& coordinate); 25 | 26 | /** 27 | * @brief upper right back corner of the bounding box in srs coordinates 28 | */ 29 | const TVec3d& getUpperBound() const; 30 | void setUpperBound(const TVec3d& coordinate); 31 | 32 | /** 33 | * @brief the name of the spatial reference system 34 | */ 35 | const std::string& srsName() const; 36 | 37 | const bool validBounds() const; 38 | 39 | protected: 40 | PRAGMA_WARN_DLL_BEGIN 41 | TVec3d m_lowerBound; 42 | TVec3d m_upperBound; 43 | std::string m_srsName; 44 | PRAGMA_WARN_DLL_END 45 | }; 46 | 47 | LIBCITYGML_EXPORT std::ostream& operator<<( std::ostream&, const citygml::Envelope& ); 48 | } 49 | -------------------------------------------------------------------------------- /sources/include/citygml/externalreference.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | 7 | namespace citygml { 8 | class LIBCITYGML_EXPORT ExternalObjectReference { 9 | public: 10 | ExternalObjectReference() = default; 11 | ~ExternalObjectReference() = default; 12 | 13 | const std::string& getName() const; 14 | const std::string& getUri() const; 15 | void setName(const std::string& name); 16 | void setUri(const std::string& uri); 17 | 18 | private: 19 | PRAGMA_WARN_DLL_BEGIN 20 | std::string value; 21 | PRAGMA_WARN_DLL_END 22 | 23 | enum class ObjectRefType { NAME, URI }; 24 | ObjectRefType type; 25 | }; 26 | 27 | class LIBCITYGML_EXPORT ExternalReference: public Object { 28 | friend class CityGMLFactory; 29 | 30 | protected: 31 | ExternalReference(std::string const& id); 32 | // ~ExternalReference() noexcept override; // Destructor 33 | public: 34 | PRAGMA_WARN_DLL_BEGIN 35 | std::string informationSystem; 36 | PRAGMA_WARN_DLL_END 37 | ExternalObjectReference externalObject; 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /sources/include/citygml/featureobject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace citygml { 10 | 11 | class Envelope; 12 | 13 | class LIBCITYGML_EXPORT FeatureObject : public Object { 14 | public: 15 | FeatureObject(const std::string& gmlID); 16 | 17 | const Envelope& getEnvelope() const; 18 | void setEnvelope(Envelope* e); 19 | 20 | virtual ~FeatureObject(); 21 | 22 | protected: 23 | PRAGMA_WARN_DLL_BEGIN 24 | std::unique_ptr m_envelope; 25 | PRAGMA_WARN_DLL_END 26 | }; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /sources/include/citygml/geometry.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | class TesselatorBase; 12 | 13 | namespace citygml { 14 | 15 | class LineString; 16 | class Polygon; 17 | class AppearanceManager; 18 | class Appearance; 19 | class ParserParams; 20 | class CityGMLFactory; 21 | class CityGMLLogger; 22 | 23 | class LIBCITYGML_EXPORT Geometry : public AppearanceTarget 24 | { 25 | friend class CityGMLFactory; 26 | public: 27 | enum class GeometryType 28 | { 29 | GT_Unknown = 1 << 0, 30 | GT_Roof = 1 << 1, 31 | GT_Wall = 1 << 2, 32 | GT_Ground = 1 << 3, 33 | GT_Closure = 1 << 4, 34 | GT_Floor = 1 << 5, 35 | GT_InteriorWall = 1 << 6, 36 | GT_Ceiling = 1 << 7, 37 | GT_OuterCeiling = 1 << 8, 38 | GT_OuterFloor = 1 << 9, 39 | GT_Tin = 1 << 10, 40 | }; 41 | 42 | unsigned int getLOD() const; 43 | 44 | unsigned int getPolygonsCount() const; 45 | std::shared_ptr getPolygon( unsigned int i ); 46 | std::shared_ptr getPolygon( unsigned int i ) const; 47 | 48 | unsigned int getLineStringCount() const; 49 | std::shared_ptr getLineString( unsigned int i ); 50 | std::shared_ptr getLineString( unsigned int i ) const; 51 | 52 | unsigned int getGeometriesCount() const; 53 | const Geometry& getGeometry( unsigned int i ) const; 54 | Geometry& getGeometry( unsigned int i ); 55 | void addGeometry(Geometry* geom); 56 | 57 | GeometryType getType() const; 58 | 59 | std::string getTypeAsString() const; 60 | 61 | unsigned int lod() const; 62 | void setLod(unsigned int lod); 63 | 64 | // Access the srs of the implicit geometry 65 | std::string getSRSName() const; 66 | void setSRSName(const std::string& srsName); 67 | 68 | void addPolygon(std::shared_ptr ); 69 | void addLineString(std::shared_ptr); 70 | 71 | /** 72 | * @brief finishes the geometry by finishing its child polygons after broadcasting its appearances to all child polygons 73 | * @param tesselate determines wether the polygons are tesselated 74 | * @param tesselator the tesselator to be used for tesselation 75 | * @param mergePolygons determines wether all polygons are merged into one 76 | */ 77 | void finish(TesselatorBase* tesselator, bool optimize, std::shared_ptr logger); 78 | 79 | ~Geometry(); 80 | 81 | 82 | protected: 83 | Geometry( const std::string& id, GeometryType type = GeometryType::GT_Unknown, unsigned int lod = 0, std::string srsName = "" ); 84 | 85 | bool m_finished; 86 | 87 | GeometryType m_type; 88 | 89 | unsigned int m_lod; 90 | 91 | PRAGMA_WARN_DLL_BEGIN 92 | std::string m_srsName; 93 | 94 | std::vector > m_childGeometries; 95 | 96 | std::vector > m_polygons; 97 | std::vector > m_lineStrings; 98 | PRAGMA_WARN_DLL_END 99 | }; 100 | 101 | LIBCITYGML_EXPORT std::ostream& operator<<( std::ostream& os, const citygml::Geometry& s ); 102 | 103 | } 104 | -------------------------------------------------------------------------------- /sources/include/citygml/geometrymanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace citygml { 12 | 13 | class ImplicitGeometry; 14 | class Geometry; 15 | class CityGMLLogger; 16 | 17 | class LIBCITYGML_EXPORT GeometryManager { 18 | public: 19 | GeometryManager(std::shared_ptr logger); 20 | 21 | void addSharedGeometry(std::shared_ptr geom); 22 | 23 | /** 24 | * @brief the Geometry with id geometryID will be added to geom when finished is called 25 | * @param geom the ImplicitGeometry object to which the Geometry object will be added 26 | * @param geometryID the id of the Geometry 27 | */ 28 | void requestSharedGeometryForImplicitGeometry(ImplicitGeometry* geom, const std::string& geometryID); 29 | 30 | void finish(); 31 | 32 | ~GeometryManager(); 33 | private: 34 | struct GeometryRequest { 35 | GeometryRequest(ImplicitGeometry* target, std::string geometryID) : target(target), geometryID(geometryID) {} 36 | ImplicitGeometry* target; 37 | std::string geometryID; 38 | }; 39 | 40 | PRAGMA_WARN_DLL_BEGIN 41 | std::shared_ptr m_logger; 42 | std::vector m_geometryRequests; 43 | std::unordered_map > m_sharedGeometries; 44 | PRAGMA_WARN_DLL_END 45 | }; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /sources/include/citygml/georeferencedtexture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace citygml { 7 | 8 | class CityGMLFactory; 9 | 10 | class LIBCITYGML_EXPORT GeoreferencedTexture : public Texture 11 | { 12 | friend class CityGMLFactory; 13 | public: 14 | 15 | bool getPreferWorldFile() const; 16 | void setPreferWorldFile(bool value); 17 | 18 | virtual std::shared_ptr asTexture(); 19 | virtual std::shared_ptr asTexture() const; 20 | 21 | virtual std::shared_ptr asGeoreferencedTexture(); 22 | virtual std::shared_ptr asGeoreferencedTexture() const; 23 | 24 | // TODO support referencePoint and orientation 25 | 26 | protected: 27 | GeoreferencedTexture( const std::string& id ); 28 | bool m_preferWorldFile; 29 | }; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /sources/include/citygml/implictgeometry.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace citygml { 12 | 13 | class Geometry; 14 | class CityGMLFactory; 15 | 16 | class LIBCITYGML_EXPORT ImplicitGeometry : public Object 17 | { 18 | friend class CityGMLFactory; 19 | public: 20 | void setTransformMatrix(const TransformationMatrix matrix); 21 | const TransformationMatrix& getTransformMatrix() const; 22 | 23 | void setReferencePoint(const TVec3d& referencePoint); 24 | TVec3d getReferencePoint() const; 25 | 26 | void addGeometry(std::shared_ptr geom); 27 | 28 | // Get the number of geometries contains in the object 29 | unsigned int getGeometriesCount() const; 30 | 31 | // Access the geometries 32 | Geometry& getGeometry( unsigned int i ) const; 33 | 34 | // Access the srs of the implicit geometry 35 | std::string getSRSName() const; 36 | void setSRSName(const std::string& srsName); 37 | 38 | protected: 39 | ImplicitGeometry(const std::string& id); 40 | 41 | TransformationMatrix m_matrix; 42 | PRAGMA_WARN_DLL_BEGIN 43 | TVec3d m_referencePoint; 44 | std::vector > m_geometries; 45 | std::string m_srsName; 46 | PRAGMA_WARN_DLL_END 47 | }; 48 | } 49 | -------------------------------------------------------------------------------- /sources/include/citygml/linearring.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace citygml { 12 | 13 | class TextureTargetDefinition; 14 | class CityGMLLogger; 15 | 16 | class LIBCITYGML_EXPORT LinearRing : public Object 17 | { 18 | public: 19 | LinearRing( const std::string& id, bool isExterior ); 20 | 21 | bool isExterior() const; 22 | 23 | unsigned int size() const; 24 | 25 | const std::vector& getVertices() const; 26 | std::vector& getVertices(); 27 | void setVertices(std::vector vertices); 28 | 29 | void addVertex( const TVec3d& v ); 30 | 31 | TVec3d computeNormal() const; 32 | 33 | void removeDuplicateVertices(const std::vector& targets , std::shared_ptr logger); 34 | 35 | void forgetVertices(); 36 | 37 | protected: 38 | bool m_exterior; 39 | 40 | PRAGMA_WARN_DLL_BEGIN 41 | std::vector m_vertices; 42 | PRAGMA_WARN_DLL_END 43 | }; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /sources/include/citygml/linestring.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | namespace citygml { 12 | 13 | class CityGMLFactory; 14 | 15 | /** 16 | * @brief The LineString class implements the gml:LineString object may also be used as a container of a single gml::Point 17 | */ 18 | class LIBCITYGML_EXPORT LineString : public Object { 19 | friend class CityGMLFactory; 20 | public: 21 | int getDimensions() const; 22 | 23 | const std::vector& getVertices2D() const; 24 | const std::vector& getVertices3D() const; 25 | 26 | std::vector& getVertices2D(); 27 | std::vector& getVertices3D(); 28 | 29 | void setVertices2D(const std::vector& vertices); 30 | void setVertices3D(const std::vector& vertices); 31 | 32 | void setDimensions(int dim); 33 | 34 | protected: 35 | LineString(const std::string& id); 36 | PRAGMA_WARN_DLL_BEGIN 37 | std::vector m_vertices_2d; 38 | std::vector m_vertices_3d; 39 | PRAGMA_WARN_DLL_END 40 | int m_dimensions; 41 | }; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /sources/include/citygml/material.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace citygml { 10 | 11 | class CityGMLFactory; 12 | 13 | class LIBCITYGML_EXPORT Material : public Appearance 14 | { 15 | friend class CityGMLFactory; 16 | public: 17 | 18 | TVec3f getDiffuse() const; 19 | void setDiffuse(TVec3f diffuse); 20 | 21 | TVec3f getEmissive() const; 22 | void setEmissive(TVec3f emissive); 23 | 24 | TVec3f getSpecular() const; 25 | void setSpecular(TVec3f specular); 26 | 27 | float getAmbientIntensity() const; 28 | void setAmbientIntensity(float intensity); 29 | 30 | /** 31 | * @brief the shininess of the material 32 | * @return a value between 0 and 1, where 1 is the brightest intensity 33 | * @note openGL defines the shininess as a value beteen 0 and 128 with 128 beeing the brightest intensity 34 | */ 35 | float getShininess() const; 36 | void setShininess(float shininess); 37 | 38 | float getTransparency() const; 39 | void setTransparency(float transparancy); 40 | 41 | bool isSmooth() const; 42 | void setIsSmooth(bool isSmooth); 43 | 44 | virtual std::shared_ptr asMaterial() override; 45 | virtual std::shared_ptr asMaterial() const override; 46 | 47 | protected: 48 | Material( const std::string& id ); 49 | PRAGMA_WARN_DLL_BEGIN 50 | TVec3f m_diffuse; 51 | TVec3f m_emissive; 52 | TVec3f m_specular; 53 | PRAGMA_WARN_DLL_END 54 | float m_ambientIntensity; 55 | float m_shininess; 56 | float m_transparency; 57 | bool m_isSmooth; 58 | }; 59 | 60 | } 61 | -------------------------------------------------------------------------------- /sources/include/citygml/materialtargetdefinition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace citygml { 8 | 9 | class CityGMLFactory; 10 | 11 | /** 12 | * @brief The MaterialTargetDefinition associates a material with a target surface. 13 | */ 14 | class LIBCITYGML_EXPORT MaterialTargetDefinition : public AppearanceTargetDefinition { 15 | friend class CityGMLFactory; 16 | protected: 17 | MaterialTargetDefinition(const std::string& targetID, std::shared_ptr appearance, const std::string& id); 18 | 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /sources/include/citygml/object.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace citygml { 10 | /** 11 | * @brief The base object associated with an unique id and a set of attributes (key-value pairs) 12 | */ 13 | class LIBCITYGML_EXPORT Object 14 | { 15 | public: 16 | Object( const std::string& id ); 17 | 18 | const std::string& getId() const; 19 | 20 | std::string getAttribute( const std::string& name ) const; 21 | 22 | const AttributesMap& getAttributes() const; 23 | 24 | AttributesMap& getAttributes(); 25 | 26 | virtual ~Object() {} 27 | 28 | void setAttribute(const std::string& name, const std::string& value, AttributeType type = AttributeType::String, bool overwrite = true ); 29 | 30 | protected: 31 | 32 | PRAGMA_WARN_DLL_BEGIN 33 | std::string m_id; 34 | 35 | AttributesMap m_attributes; 36 | PRAGMA_WARN_DLL_END 37 | }; 38 | 39 | LIBCITYGML_EXPORT std::ostream& operator<<( std::ostream&, const citygml::Object& ); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /sources/include/citygml/polygonmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace citygml { 12 | 13 | class Polygon; 14 | class Geometry; 15 | class CityGMLLogger; 16 | 17 | class LIBCITYGML_EXPORT PolygonManager { 18 | public: 19 | PolygonManager(std::shared_ptr logger); 20 | 21 | void addPolygon(std::shared_ptr poly); 22 | 23 | /** 24 | * @brief the polygon with id polygonID will be added to geom when finished is called 25 | * @param geom the geometry object to which the polygon will be added 26 | * @param polygonID the id of the polygon 27 | */ 28 | void requestSharedPolygonForGeometry(Geometry* geom, const std::string& polygonID); 29 | 30 | void finish(); 31 | 32 | ~PolygonManager(); 33 | private: 34 | struct PolygonRequest { 35 | PolygonRequest(Geometry* target, std::string polygonID) : target(target), polygonID(polygonID) {} 36 | Geometry* target; 37 | std::string polygonID; 38 | }; 39 | 40 | PRAGMA_WARN_DLL_BEGIN 41 | std::shared_ptr m_logger; 42 | std::vector m_polygonRequests; 43 | std::unordered_map > m_sharedPolygons; 44 | PRAGMA_WARN_DLL_END 45 | }; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /sources/include/citygml/rectifiedgridcoverage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace citygml { 6 | 7 | class LIBCITYGML_EXPORT RectifiedGridCoverage : public FeatureObject 8 | { 9 | friend class CityGMLFactory; 10 | 11 | protected: 12 | RectifiedGridCoverage(std::string const& id = "RectifiedGridCoverage"); 13 | }; 14 | 15 | LIBCITYGML_EXPORT std::ostream& operator<<( std::ostream& os, const RectifiedGridCoverage& o ); 16 | 17 | } 18 | 19 | -------------------------------------------------------------------------------- /sources/include/citygml/tesselator.h: -------------------------------------------------------------------------------- 1 | /* -*-c++-*- libcitygml - Copyright (c) 2010 Joachim Pouderoux, BRGM 2 | * 3 | * This file is part of libcitygml library 4 | * http://code.google.com/p/libcitygml 5 | * 6 | * libcitygml is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 2.1 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * libcitygml is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | */ 16 | 17 | #ifndef __TESSELATOR_H__ 18 | #define __TESSELATOR_H__ 19 | 20 | #ifdef WIN32 21 | # include 22 | #else 23 | # define CALLBACK 24 | # define APIENTRY 25 | #endif 26 | 27 | #ifdef __APPLE__ 28 | #include 29 | #else 30 | #include 31 | #endif 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | namespace citygml { 39 | class CityGMLLogger; 40 | } 41 | 42 | // GLU based polygon tesselator 43 | class LIBCITYGML_EXPORT Tesselator: public TesselatorBase 44 | { 45 | public: 46 | Tesselator( std::shared_ptr logger, GLenum winding_rule = GLU_TESS_WINDING_ODD); 47 | ~Tesselator(); 48 | 49 | void init(const TVec3d& normal) override; 50 | 51 | /** 52 | * @brief Add a new contour - add the exterior ring first, then interiors 53 | * @param textureCoordinatesLists a list of texture coordinates lists for the countour. Each list contains one texture coordinate for each vertex. 54 | */ 55 | void addContour(const std::vector&, std::vector > textureCoordinatesLists) override; 56 | 57 | // Let's tesselate! 58 | void compute() override; 59 | 60 | private: 61 | void processContours(); 62 | 63 | typedef void (APIENTRY *GLU_TESS_CALLBACK)(); 64 | static void CALLBACK beginCallback( GLenum, void* ); 65 | static void CALLBACK vertexDataCallback( GLvoid*, void* ); 66 | static void CALLBACK combineCallback( GLdouble[3], void* [4], GLfloat [4], void** , void* ); 67 | static void CALLBACK endCallback( void* ); 68 | static void CALLBACK errorCallback(GLenum, void*); 69 | 70 | private: 71 | // 72 | struct ContourRef { 73 | ContourRef(unsigned int index, unsigned int length) : index(index), length(length) {} 74 | unsigned int index; 75 | unsigned int length; 76 | }; 77 | 78 | GLUtesselator *_tobj; 79 | GLenum _curMode; 80 | GLenum _windingRule; 81 | PRAGMA_WARN_DLL_BEGIN 82 | std::vector _originalVertices; 83 | std::vector _contourQueue; 84 | PRAGMA_WARN_DLL_END 85 | 86 | }; 87 | 88 | #endif // __TESSELATOR_H__ 89 | -------------------------------------------------------------------------------- /sources/include/citygml/tesselatorbase.h: -------------------------------------------------------------------------------- 1 | /* -*-c++-*- libcitygml - Copyright (c) 2010 Joachim Pouderoux, BRGM 2 | * 3 | * This file is part of libcitygml library 4 | * http://code.google.com/p/libcitygml 5 | * 6 | * libcitygml is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 2.1 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * libcitygml is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | */ 16 | 17 | #ifndef __TESSELATORBASE_H__ 18 | #define __TESSELATORBASE_H__ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace citygml { 27 | class CityGMLLogger; 28 | } 29 | 30 | // base class for polygon tesselator 31 | class LIBCITYGML_EXPORT TesselatorBase 32 | { 33 | public: 34 | TesselatorBase( std::shared_ptr logger ); 35 | virtual ~TesselatorBase(); 36 | 37 | void setLogger(std::shared_ptr logger); 38 | 39 | virtual void init(const TVec3d& normal) = 0; 40 | 41 | /** 42 | * @brief Add a new contour - add the exterior ring first, then interiors 43 | * @param textureCoordinatesLists a list of texture coordinates lists for the countour. Each list contains one texture coordinate for each vertex. 44 | */ 45 | virtual void addContour(const std::vector&, std::vector > textureCoordinatesLists); 46 | 47 | // Let's tesselate! 48 | virtual void compute() = 0; 49 | 50 | // Tesselation result access 51 | const std::vector& getVertices() const; 52 | const std::vector >& getTexCoords() const { return _texCoordsLists; } 53 | const std::vector& getIndices() const; 54 | 55 | void setKeepVertices(bool val); 56 | bool keepVertices() const; 57 | 58 | protected: 59 | PRAGMA_WARN_DLL_BEGIN 60 | std::vector _vertices; 61 | std::vector > _texCoordsLists; 62 | std::vector _indices; 63 | std::vector _outIndices; 64 | 65 | std::vector _curIndices; 66 | std::shared_ptr _logger; 67 | PRAGMA_WARN_DLL_END 68 | 69 | bool _keepVertices; 70 | }; 71 | 72 | #endif // __TESSELATORBASE_H__ 73 | -------------------------------------------------------------------------------- /sources/include/citygml/texture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace citygml { 11 | 12 | class CityGMLFactory; 13 | 14 | class LIBCITYGML_EXPORT Texture : public Appearance 15 | { 16 | friend class CityGMLFactory; 17 | public: 18 | enum class WrapMode 19 | { 20 | WM_NONE, // the resulting color is fully transparent 21 | WM_WRAP, // the texture is repeated 22 | WM_MIRROR, // the texture is repeated and mirrored 23 | WM_CLAMP, // the texture is clamped to its edges 24 | WM_BORDER // the resulting color is specified by the borderColor element (RGBA) 25 | }; 26 | 27 | std::string getUrl() const; 28 | 29 | void setUrl(const std::string& url); 30 | 31 | bool getRepeat() const; 32 | 33 | WrapMode getWrapMode() const; 34 | void setWrapMode(WrapMode mode); 35 | 36 | /** 37 | * @brief tries to interpret the string as a WrapMode. Does nothing on failure. 38 | * @param wrapMode the string e.g. ("WM_NONE") 39 | * @return true if the string could be interpreted as a WrapMode, false otherwise 40 | */ 41 | bool setWrapModeFromString(std::string wrapMode); 42 | 43 | TVec4f getBorderColor() const; 44 | void setBorderColor(TVec4f color); 45 | 46 | std::string toString() const override; 47 | 48 | virtual std::shared_ptr asTexture() override; 49 | virtual std::shared_ptr asTexture() const override; 50 | 51 | virtual ~Texture(); 52 | 53 | protected: 54 | Texture( const std::string& id ); 55 | Texture( const std::string& id, const std::string& type ); 56 | PRAGMA_WARN_DLL_BEGIN 57 | std::string m_url; 58 | PRAGMA_WARN_DLL_END 59 | bool m_repeat; 60 | WrapMode m_wrapMode; 61 | PRAGMA_WARN_DLL_BEGIN 62 | TVec4f m_borderColor; 63 | PRAGMA_WARN_DLL_END 64 | }; 65 | 66 | } 67 | -------------------------------------------------------------------------------- /sources/include/citygml/texturecoordinates.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace citygml { 13 | 14 | class LinearRing; 15 | 16 | /** 17 | * @brief The TextureCoordinates class describes a mapping of texture coordinates to the vertices of a linear ring 18 | */ 19 | class LIBCITYGML_EXPORT TextureCoordinates : public Object { 20 | public: 21 | TextureCoordinates(std::string id, std::string targetID); 22 | 23 | bool targets(const LinearRing& ring) const; 24 | std::string getTargetLinearRingID() const; 25 | 26 | const std::vector& getCoords() const; 27 | void setCoords(std::vector texCoords); 28 | 29 | bool eraseCoordinate(unsigned int i); 30 | 31 | protected: 32 | PRAGMA_WARN_DLL_BEGIN 33 | std::string m_targetID; 34 | std::vector m_coordlist; 35 | PRAGMA_WARN_DLL_END 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /sources/include/citygml/texturetargetdefinition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace citygml { 12 | 13 | class TextureCoordinates; 14 | class CityGMLFactory; 15 | 16 | /** 17 | * @brief The TextureTargetDefinition associates a texture with a target surface and defines the mapping of the texture. 18 | * @note may be shared between different texture objects using the 'xlink:href' attribute. 19 | * TextureTargets are applicable only to polygonal surfaces, whose boundaries are described by gml:LinearRing 20 | * (e.g. gml:Triangle, gml:Polygon, or a gml:MultiSurface consisting of gml:Polygons). 21 | */ 22 | class LIBCITYGML_EXPORT TextureTargetDefinition : public AppearanceTargetDefinition { 23 | friend class CityGMLFactory; 24 | public: 25 | /** 26 | * @brief the number of TextureCoordinates objects for this texture target 27 | */ 28 | unsigned int getTextureCoordinatesCount() const; 29 | 30 | /** 31 | * @brief the i-th texture coordinates in texture coordinates list (gml::TexCoordList) 32 | */ 33 | std::shared_ptr getTextureCoordinates(unsigned int i); 34 | std::shared_ptr getTextureCoordinates(unsigned int i) const; 35 | 36 | /** 37 | * @brief the texture coordinates for linear ring with the given id 38 | * @return the TextureCoordinates object or nullptr if no such object exists for ringID 39 | */ 40 | std::shared_ptr getTextureCoordinatesForID(const std::string& ringID); 41 | std::shared_ptr getTextureCoordinatesForID(const std::string& ringID) const; 42 | 43 | void addTexCoordinates(std::shared_ptr texCoords); 44 | 45 | 46 | ~TextureTargetDefinition(); 47 | 48 | protected: 49 | TextureTargetDefinition(const std::string& targetID, std::shared_ptr appearance, const std::string& id); 50 | PRAGMA_WARN_DLL_BEGIN 51 | std::vector > m_coordinatesList; 52 | std::unordered_map > m_idTexCoordMap; 53 | PRAGMA_WARN_DLL_END 54 | }; 55 | } 56 | -------------------------------------------------------------------------------- /sources/include/citygml/transformmatrix.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace citygml { 7 | class LIBCITYGML_EXPORT TransformationMatrix : public Object 8 | { 9 | public: 10 | TransformationMatrix(); 11 | 12 | 13 | TransformationMatrix(double* matrix); 14 | 15 | 16 | const double* getMatrix() const; 17 | const double* getTransposedMatrix() const; 18 | 19 | ~TransformationMatrix(); 20 | 21 | 22 | protected: 23 | double m_matrix[16]; 24 | double m_transposedMatrix[16]; 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /sources/include/citygml/utils.h: -------------------------------------------------------------------------------- 1 | /* -*-c++-*- libcitygml - Copyright (c) 2010 Joachim Pouderoux, BRGM 2 | * 3 | * This file is part of libcitygml library 4 | * http://code.google.com/p/libcitygml 5 | * 6 | * libcitygml is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 2.1 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * libcitygml is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | 24 | // Helpers 25 | 26 | // std::string tokenizer 27 | inline std::vector tokenize( const std::string& str, const std::string& delimiters = ",|& " ) 28 | { 29 | std::vector tokens; 30 | std::string::size_type lastPos = str.find_first_not_of( delimiters, 0 ); 31 | std::string::size_type pos = str.find_first_of( delimiters, lastPos ); 32 | 33 | while ( pos != std::string::npos || lastPos != std::string::npos ) 34 | { 35 | tokens.push_back( str.substr( lastPos, pos - lastPos ) ); 36 | lastPos = str.find_first_not_of( delimiters, pos ); 37 | pos = str.find_first_of( delimiters, lastPos ); 38 | } 39 | return tokens; 40 | } 41 | 42 | inline bool ci_string_compare( const std::string& str1, const std::string& str2 ) 43 | { 44 | std::string s1( str1 ); 45 | std::transform( s1.begin(), s1.end(), s1.begin(), ::tolower ); 46 | std::string s2( str2 ); 47 | std::transform( s2.begin(), s2.end(), s2.begin(), ::tolower ); 48 | return s1 == s2; 49 | } 50 | 51 | inline std::string toLower(const std::string& s) { 52 | std::string lower = s; 53 | std::transform( lower.begin(), lower.end(), lower.begin(), ::tolower ); 54 | return lower; 55 | } 56 | 57 | inline std::string trim_left( const std::string& s, const std::string& t = " \t\r\n" ) 58 | { 59 | std::string d( s ); 60 | return d.erase( 0, s.find_first_not_of( t ) ); 61 | } 62 | 63 | inline std::string trim_right( const std::string& s, const std::string& t = " \t\r\n" ) 64 | { 65 | std::string d( s ); 66 | size_t endpos = d.find_last_not_of( t ); 67 | return ( endpos != std::string::npos ) ? d.erase( endpos + 1 ) : d; 68 | } 69 | 70 | inline std::string trim( const std::string& s, const std::string& t = " \t\r\n" ) 71 | { 72 | return trim_left( trim_right( s, t ), t ); 73 | } 74 | 75 | -------------------------------------------------------------------------------- /sources/include/citygml/warnings.h: -------------------------------------------------------------------------------- 1 | /* -*-c++-*- libcitygml - Copyright (c) 2010 Joachim Pouderoux, BRGM 2 | * 3 | * This file is part of libcitygml library 4 | * http://code.google.com/p/libcitygml 5 | * 6 | * libcitygml is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 2.1 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * libcitygml is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | */ 16 | 17 | #pragma once 18 | 19 | #ifdef _MSC_VER 20 | #define PRAGMA_WARN_DLL_BEGIN _Pragma("warning(push)") \ 21 | _Pragma("warning(disable : 4251 4275)") 22 | #define PRAGMA_WARN_DLL_END _Pragma("warning(pop)") 23 | #else 24 | #define PRAGMA_WARN_DLL_BEGIN 25 | #define PRAGMA_WARN_DLL_END 26 | #endif 27 | -------------------------------------------------------------------------------- /sources/include/parser/addressparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | 8 | namespace citygml { 9 | 10 | class Address; 11 | 12 | class AddressParser: public CityGMLElementParser { 13 | public: 14 | using Callback = std::function&&)>; 15 | 16 | public: 17 | AddressParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, const Callback& callback); 18 | 19 | virtual std::string elementParserName() const override; 20 | virtual bool handlesElement(const NodeType::XMLNode& node) const override; 21 | 22 | protected: 23 | virtual bool parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes ) override; 24 | virtual bool parseElementEndTag(const NodeType::XMLNode& node, const std::string& characters ) override; 25 | virtual bool parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes ) override; 26 | virtual bool parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters ) override; 27 | 28 | 29 | protected: 30 | std::unique_ptr
m_address; 31 | Callback m_callback; 32 | }; 33 | 34 | } /* namespace citygml */ 35 | -------------------------------------------------------------------------------- /sources/include/parser/appearanceelementparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace citygml { 10 | 11 | class CityObject; 12 | class Appearance; 13 | 14 | class AppearanceElementParser : public GMLObjectElementParser { 15 | public: 16 | AppearanceElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger); 17 | 18 | // ElementParser interface 19 | virtual std::string elementParserName() const override; 20 | virtual bool handlesElement(const NodeType::XMLNode &node) const override; 21 | 22 | protected: 23 | // CityGMLElementParser interface 24 | virtual bool parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 25 | virtual bool parseElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 26 | virtual bool parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 27 | virtual bool parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 28 | 29 | // GMLObjectElementParser interface 30 | virtual Object* getObject() override; 31 | 32 | private: 33 | std::vector > m_surfaceDataList; 34 | std::shared_ptr m_appearanceObj; 35 | std::string m_theme; 36 | }; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /sources/include/parser/attributes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace citygml { 7 | 8 | class CityGMLLogger; 9 | class DocumentLocation; 10 | 11 | /** 12 | * @brief The Attributes class provides methods to access the attributes of an xml element 13 | */ 14 | class Attributes { 15 | public: 16 | 17 | /** 18 | * @brief get the value of an attribute 19 | * @param attname the name of the attribute 20 | * @param defvalue the default value 21 | * @return the value of the attribute or defvalue if no such attribute exists 22 | */ 23 | virtual std::string getAttribute( const std::string& attname, const std::string& defvalue = "" ) const = 0; 24 | virtual const DocumentLocation& getDocumentLocation() const = 0; 25 | 26 | /** 27 | * @brief gets the citygml id attribute value or if not present generates a value based on the document location 28 | * @return the value of the gml::id attribute or "genID___" if there is no id attribute 29 | */ 30 | std::string getCityGMLIDAttribute() const; 31 | 32 | bool hasXLinkAttribute() const; 33 | std::string getXLinkValue(); 34 | 35 | protected: 36 | Attributes(std::shared_ptr logger); 37 | std::shared_ptr m_logger; 38 | }; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /sources/include/parser/citygmldocumentparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace citygml { 9 | 10 | class Attributes; 11 | class CityGMLLogger; 12 | class DocumentLocation; 13 | class CityGMLFactory; 14 | class ElementParser; 15 | 16 | class CityGMLDocumentParser { 17 | public: 18 | CityGMLDocumentParser(const ParserParams& params, std::shared_ptr logger, std::unique_ptr tesselator); 19 | 20 | std::shared_ptr getModel(); 21 | 22 | const ParserParams getParserParams() const; 23 | 24 | // Methods used by CityGMLElementParser 25 | 26 | void setCurrentElementParser(ElementParser* parser); 27 | void removeCurrentElementParser(const ElementParser* caller); 28 | 29 | /** 30 | * @brief the current location in the document 31 | */ 32 | virtual const DocumentLocation& getDocumentLocation() const = 0; 33 | 34 | virtual ~CityGMLDocumentParser(); 35 | 36 | protected: 37 | 38 | /** 39 | * @brief must be called for each xml element start tag 40 | * @param name the name of the xml element 41 | * @param attributes the attribut data of the xml element 42 | */ 43 | void startElement( const std::string& name, Attributes& attributes); 44 | 45 | /** 46 | * @brief must be called for each xml element end tag 47 | * @param name the name of the xml element 48 | * @param characters the character data of the element or empty string if it contains no charcter data 49 | */ 50 | void endElement( const std::string& name, const std::string& characters ); 51 | 52 | /** 53 | * @brief must be called at the start of the document 54 | */ 55 | void startDocument(); 56 | 57 | /** 58 | * @brief must be called at the end of the document 59 | */ 60 | void endDocument(); 61 | 62 | 63 | std::shared_ptr m_logger; 64 | private: 65 | void skipUnknownOrUnexpectedElement(const std::string& name); 66 | bool checkCurrentElementUnownOrUnexpected_start(const std::string& name); 67 | bool checkCurrentElementUnownOrUnexpected_end(const std::string& name); 68 | 69 | std::stack > m_parserStack; 70 | 71 | /** 72 | * @brief The currently active parser (the one on which startElement or endElement was called last) 73 | * 74 | * The active parser can remove itself from the stack at any time. Hence we need another shared_ptr reference 75 | * to it so that it does not delete itself when removed from the stack. 76 | */ 77 | std::shared_ptr m_activeParser; 78 | 79 | std::unique_ptr m_factory; 80 | std::shared_ptr m_rootModel; 81 | ParserParams m_parserParams; 82 | 83 | std::unique_ptr m_tesselator; 84 | 85 | bool m_currentElementUnknownOrUnexpected; 86 | int m_unknownElementOrUnexpectedElementDepth; 87 | std::string m_unknownElementOrUnexpectedElementName; 88 | }; 89 | 90 | } 91 | -------------------------------------------------------------------------------- /sources/include/parser/citygmlelementparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "parser/elementparser.h" 7 | #include "parser/nodetypes.h" 8 | 9 | namespace citygml { 10 | 11 | class Attributes; 12 | class CityGMLDocumentParser; 13 | class CityGMLLogger; 14 | class CityGMLFactory; 15 | class DocumentLocation; 16 | 17 | /** 18 | * @brief The CityGMLElementParser class is a xml sax parser that is responsible for parsing a specific subset of elements 19 | * 20 | * The CityGMLDocumentParser uses CityGMLElementParser objects to parse the elements that are found in the document. 21 | * Only the CityGMLElementParser objects for the root elements of a citygml document are known by the CityGMLDocumentParser. 22 | * Whenever it encounters such an element it delegates the startElement and endElement class to the corresponding CityGMLElementParser object. 23 | * A CityGMLElementParser object can itself invoke other CityGMLElementParser objects to parse its child elements. 24 | * 25 | * After a CityGMLElementParser object has been set as the active element parser by the CityGMLDocumentParser or another CityGMLElementParser (the caller) 26 | * it will be bound to the xml element whose start tag is found next by the sax parser. 27 | * As soon as the end tag of the bound element is detected the control flow is returned to the caller. 28 | * How the result values are shared between caller and callee is up to the concrete implementation. 29 | * Usally a callback mechanism is used. 30 | */ 31 | class CityGMLElementParser : public ElementParser { 32 | public: 33 | 34 | CityGMLElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger); 35 | 36 | 37 | /** 38 | * @brief must be called for xml tag that starts a child of the elements handeld by this parser or starts one of the elements itself 39 | * @return true if the node was expected otherwise false 40 | * @note the CityGMLDocumentParser calls this method 41 | */ 42 | virtual bool startElement(const NodeType::XMLNode& node, Attributes& attributes) override; 43 | 44 | /** 45 | * @brief must be called for each xml tag that ends a child of the elements handeld by this parser or ends one of the elements itself 46 | * @return true if the node was expected otherwise false 47 | * @note the CityGMLDocumentParser calls this method 48 | */ 49 | virtual bool endElement(const NodeType::XMLNode& node, const std::string& characters ) override; 50 | 51 | virtual ~CityGMLElementParser(); 52 | 53 | protected: 54 | 55 | // Template methods to be implemented by subclasses 56 | 57 | /** 58 | * @brief called for the start tag of the element to which the parser is bound 59 | * @return true if the node was expected otherwise false 60 | */ 61 | virtual bool parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes ) = 0; 62 | 63 | /** 64 | * @brief called for the end tag of the element to which the parser is bound 65 | * @return true if the node was expected otherwise false 66 | */ 67 | virtual bool parseElementEndTag(const NodeType::XMLNode& node, const std::string& characters ) = 0; 68 | 69 | /** 70 | * @brief called for the start tag of each child inside the element to which the parser is bound 71 | * @return true if the node was expected otherwise false 72 | */ 73 | virtual bool parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes ) = 0; 74 | 75 | /** 76 | * @brief called for the end tag of each child inside the element to which the parser is bound 77 | * @return true if the node was expected otherwise false 78 | * @note if a callback mechanism is used to share the result of this parser this method would be the right place to invoke the callback 79 | */ 80 | virtual bool parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters ) = 0; 81 | 82 | CityGMLFactory& m_factory; 83 | private: 84 | NodeType::XMLNode m_boundElement; 85 | }; 86 | 87 | } 88 | -------------------------------------------------------------------------------- /sources/include/parser/citymodelelementparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace citygml { 8 | 9 | class CityModel; 10 | 11 | class CityModelElementParser : public GMLFeatureCollectionElementParser { 12 | public: 13 | CityModelElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, std::function callback); 14 | 15 | // ElementParser interface 16 | virtual std::string elementParserName() const override; 17 | virtual bool handlesElement(const NodeType::XMLNode &node) const override; 18 | 19 | protected: 20 | 21 | // CityGMLElementParser interface 22 | virtual bool parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 23 | virtual bool parseElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 24 | virtual bool parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 25 | virtual bool parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 26 | 27 | // GMLFeatureCollectionElementParser interface 28 | virtual FeatureObject* getFeatureObject() override; 29 | 30 | private: 31 | std::function m_callback; 32 | CityModel* m_model; 33 | }; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /sources/include/parser/cityobjectelementparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | namespace citygml { 13 | 14 | class CityObjectElementParser : public GMLFeatureCollectionElementParser { 15 | public: 16 | CityObjectElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, std::function callback); 17 | 18 | // ElementParser interface 19 | virtual std::string elementParserName() const override; 20 | virtual bool handlesElement(const NodeType::XMLNode &node) const override; 21 | protected: 22 | 23 | // CityGMLElementParser interface 24 | virtual bool parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 25 | virtual bool parseElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 26 | virtual bool parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 27 | virtual bool parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 28 | 29 | // GMLFeatureCollectionElementParser interface 30 | virtual FeatureObject* getFeatureObject() override; 31 | 32 | private: 33 | static void initializeTypeIDTypeMap(); 34 | static void initializeAttributesSet(); 35 | static AttributeType getAttributeType(const NodeType::XMLNode& node); 36 | 37 | CityObject* m_model; 38 | std::function m_callback; 39 | std::string m_lastAttributeName; 40 | AttributeType m_lastAttributeType; 41 | 42 | // The nodes that are valid CityObjects 43 | static std::mutex initializedTypeIDMutex; 44 | static std::unordered_map typeIDTypeMap; 45 | static bool typeIDTypeMapInitialized; 46 | 47 | static std::mutex initializedAttributeSetMutex; 48 | static std::unordered_set attributesSet; 49 | static std::unordered_map attributeTypeMap; 50 | static bool attributesSetInitialized; 51 | 52 | void parseGeometryForLODLevel(int lod); 53 | void parseGeometryForLODLevel(int lod, CityObject::CityObjectsType parentType); 54 | void parseImplicitGeometryForLODLevel(int lod); 55 | void parseGeometryPropertyElementForLODLevel(int lod, const std::string& id); 56 | }; 57 | 58 | } 59 | -------------------------------------------------------------------------------- /sources/include/parser/delayedchoiceelementparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "parser/elementparser.h" 7 | 8 | namespace citygml { 9 | 10 | /** 11 | * @brief The DelayedChoiceElementParser allows to parse xml elements of which the concrete type is not known in advance 12 | * 13 | * The DelayedChoiceElementParser is initialized with a list of possible parses. When the start element of the next node is parsed it chooses the 14 | * first parser that can handle the element. 15 | */ 16 | class DelayedChoiceElementParser : public ElementParser { 17 | public: 18 | 19 | /** 20 | * @brief creates a DelayedChoiceElementParser 21 | * @param documentParser 22 | * @param logger 23 | * @param choices the parsers to choose from. The DelayedChoiceElementParser takes ownership of the parsers. 24 | */ 25 | DelayedChoiceElementParser(CityGMLDocumentParser& documentParser, std::shared_ptr logger, std::vector choices); 26 | 27 | // ElementParser interface 28 | virtual bool startElement(const NodeType::XMLNode& node, Attributes& attributes); 29 | virtual bool endElement(const NodeType::XMLNode& node, const std::string& characters); 30 | virtual bool handlesElement(const NodeType::XMLNode& node) const; 31 | virtual std::string elementParserName() const; 32 | 33 | private: 34 | std::vector m_choices; 35 | }; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /sources/include/parser/documentlocation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace citygml { 8 | 9 | class DocumentLocation { 10 | public: 11 | virtual const std::string& getDocumentFileName() const = 0; 12 | virtual uint64_t getCurrentLine() const = 0; 13 | virtual uint64_t getCurrentColumn() const = 0; 14 | }; 15 | 16 | inline std::ostream& operator<<( std::ostream& os, const DocumentLocation& o ) { 17 | 18 | if (o.getCurrentLine() == 0) { 19 | os << " unknown location"; 20 | } else { 21 | os << " line " << o.getCurrentLine(); 22 | 23 | if (o.getCurrentColumn() > 0) { 24 | os << ", column " << o.getCurrentColumn(); 25 | } 26 | } 27 | 28 | if (!o.getDocumentFileName().empty()) { 29 | os << " in file " << o.getDocumentFileName(); 30 | } 31 | 32 | return os; 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /sources/include/parser/elementparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "parser/nodetypes.h" 7 | 8 | namespace citygml { 9 | 10 | class Attributes; 11 | class CityGMLDocumentParser; 12 | class CityGMLLogger; 13 | class CityGMLFactory; 14 | class DocumentLocation; 15 | 16 | /** 17 | * @brief The ElementParser is the base class for parsers that only handle a specific subset of elements 18 | * 19 | * For a basic explanation of the parsing process @see CityGMLElementParser 20 | */ 21 | class ElementParser { 22 | public: 23 | 24 | ElementParser(CityGMLDocumentParser& documentParser, std::shared_ptr logger) : m_logger(logger), m_documentParser(documentParser) {} 25 | 26 | /** 27 | * @brief must be called for xml tag that starts a child of the elements handeld by this parser or starts one of the elements itself 28 | * @return true if the node was expected otherwise false 29 | * @note the CityGMLDocumentParser calls this method 30 | */ 31 | virtual bool startElement(const NodeType::XMLNode& node, Attributes& attributes) = 0; 32 | 33 | /** 34 | * @brief must be called for each xml tag that ends a child of the elements handeld by this parser or ends one of the elements itself 35 | * @return true if the node was expected otherwise false 36 | * @note the CityGMLDocumentParser calls this method 37 | */ 38 | virtual bool endElement(const NodeType::XMLNode& node, const std::string& characters ) = 0; 39 | 40 | /** 41 | * @brief returns wether the parser handels elements of type node 42 | * @note this is required for the delayed choice mechanism @see DelayedChoiceElementParser 43 | * @return true if node is a valid !!root!! element for this parser 44 | * (e.g. is valid root element for the appearance parser but is not since its a child element of an appearance) 45 | */ 46 | virtual bool handlesElement(const NodeType::XMLNode& node) const = 0; 47 | 48 | /** 49 | * @brief the name of the parser (for logging purposes) 50 | */ 51 | virtual std::string elementParserName() const = 0; 52 | 53 | virtual ~ElementParser(); 54 | 55 | protected: 56 | /** 57 | * @brief sets a parser that will be called for the next element. 58 | * @note The parser will be deleted after parsing the elment. 59 | */ 60 | void setParserForNextElement(ElementParser* parser); 61 | virtual const DocumentLocation& getDocumentLocation() const; 62 | 63 | std::shared_ptr m_logger; 64 | CityGMLDocumentParser& m_documentParser; 65 | }; 66 | 67 | } 68 | -------------------------------------------------------------------------------- /sources/include/parser/externalreferenceparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "parser/gmlobjectparser.h" 5 | #include 6 | 7 | 8 | namespace citygml { 9 | class ExternalReferenceParser: public GMLObjectElementParser { 10 | public: 11 | ExternalReferenceParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, std::function callback); 12 | 13 | // ElementParser interface 14 | virtual std::string elementParserName() const override; 15 | virtual bool handlesElement(NodeType::XMLNode const& node) const override; 16 | 17 | protected: 18 | // CityGMLElementParser interaface 19 | virtual bool parseElementStartTag(NodeType::XMLNode const& node, Attributes & attribute) override; 20 | virtual bool parseElementEndTag(NodeType::XMLNode const& node, std::string const& characters) override; 21 | virtual bool parseChildElementStartTag(NodeType::XMLNode const& node, Attributes & attributes) override; 22 | virtual bool parseChildElementEndTag(NodeType::XMLNode const& node, std::string const& characters) override; 23 | 24 | // GMLObjectElementParser interface 25 | virtual Object* getObject() override; 26 | 27 | private: 28 | std::unique_ptr model; 29 | std::function callback; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /sources/include/parser/geocoordinatetransformer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class GeoTransform; 8 | 9 | namespace citygml { 10 | 11 | class CityGMLLogger; 12 | class CityModel; 13 | class CityObject; 14 | class ImplicitGeometry; 15 | class Geometry; 16 | class Polygon; 17 | class LineString; 18 | 19 | class GeoCoordinateTransformer { 20 | public: 21 | GeoCoordinateTransformer(const std::string& destSRS, std::shared_ptr logger); 22 | 23 | void transformToDestinationSRS(CityModel* model); 24 | private: 25 | std::string m_destinationSRS; 26 | std::shared_ptr m_logger; 27 | std::unordered_map m_transformedPolygonsSourceURNMap; 28 | std::unordered_map m_transformedLineStringsSourceURNMap; 29 | 30 | void transformRecursive(CityObject& obj, GeoTransform& transformation); 31 | void transformRecursive_helper(CityObject& obj, GeoTransform& transformation); 32 | void transformRecursive(ImplicitGeometry& obj, GeoTransform& transformation); 33 | void transformRecursive_helper(ImplicitGeometry& obj, GeoTransform& transformation); 34 | void transform(Geometry& obj, GeoTransform& transformation); 35 | }; 36 | 37 | } 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /sources/include/parser/geometryelementparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace citygml { 10 | 11 | class Geometry; 12 | 13 | class GeometryElementParser : public GMLObjectElementParser { 14 | public: 15 | GeometryElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, 16 | int lodLevel, CityObject::CityObjectsType parentType, std::function callback); 17 | 18 | // ElementParser interface 19 | virtual std::string elementParserName() const override; 20 | virtual bool handlesElement(const NodeType::XMLNode &node) const override; 21 | protected: 22 | // CityGMLElementParser interface 23 | virtual bool parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 24 | virtual bool parseElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 25 | virtual bool parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 26 | virtual bool parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 27 | 28 | // GMLObjectElementParser interface 29 | virtual Object* getObject() override; 30 | 31 | private: 32 | Geometry* m_model; 33 | std::function m_callback; 34 | int m_lodLevel; 35 | CityObject::CityObjectsType m_parentType; 36 | std::string m_orientation; 37 | }; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /sources/include/parser/georeferencedtextureelementparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace citygml { 9 | 10 | class GeoreferencedTexture; 11 | 12 | class GeoReferencedTextureElementParser : public CityGMLElementParser { 13 | public: 14 | GeoReferencedTextureElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, std::function)> callback); 15 | 16 | // ElementParser interface 17 | virtual std::string elementParserName() const override; 18 | virtual bool handlesElement(const NodeType::XMLNode &node) const override; 19 | 20 | protected: 21 | // CityGMLElementParser interface 22 | virtual bool parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 23 | virtual bool parseElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 24 | virtual bool parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 25 | virtual bool parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 26 | 27 | private: 28 | std::function)> m_callback; 29 | }; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /sources/include/parser/gmlfeaturecollectionparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace citygml { 6 | 7 | class Envelope; 8 | class FeatureObject; 9 | 10 | /** 11 | * @brief abstract base class for all CityGMLElementParser's that parse citygml elements which inherit from gml:AbstractFeatureCollectionType 12 | */ 13 | class GMLFeatureCollectionElementParser : public GMLObjectElementParser { 14 | public: 15 | GMLFeatureCollectionElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger); 16 | 17 | protected: 18 | // CityGMLElementParser interface 19 | virtual bool parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 20 | virtual bool parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 21 | 22 | virtual FeatureObject* getFeatureObject() = 0; 23 | 24 | // GMLObjectElementParser interface 25 | virtual Object* getObject() override; 26 | 27 | const Envelope& getEnvelope() const; 28 | bool getSourceSRSOverride() const; 29 | 30 | private: 31 | Envelope* m_bounds; 32 | bool m_sourceSRSOverride; 33 | 34 | 35 | }; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /sources/include/parser/gmlobjectparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace citygml { 6 | 7 | class Object; 8 | 9 | /** 10 | * @brief abstract base class for all CityGMLElementParser's that parse citygml elements which inherit from gml:AbstractGMLType 11 | */ 12 | class GMLObjectElementParser : public CityGMLElementParser { 13 | public: 14 | GMLObjectElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger); 15 | 16 | protected: 17 | // CityGMLElementParser interface 18 | virtual bool parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 19 | virtual bool parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 20 | 21 | /** 22 | * @brief returns the object in which the parsed information will be stored 23 | */ 24 | virtual Object* getObject() = 0; 25 | 26 | }; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /sources/include/parser/implicitgeometryelementparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace citygml { 10 | 11 | class ImplicitGeometry; 12 | 13 | class ImplicitGeometryElementParser : public GMLObjectElementParser { 14 | public: 15 | ImplicitGeometryElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, 16 | int lodLevel, CityObject::CityObjectsType parentType, std::function callback); 17 | 18 | // ElementParser interface 19 | virtual std::string elementParserName() const override; 20 | virtual bool handlesElement(const NodeType::XMLNode &node) const override; 21 | protected: 22 | // CityGMLElementParser interface 23 | virtual bool parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 24 | virtual bool parseElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 25 | virtual bool parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 26 | virtual bool parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 27 | 28 | // GMLObjectElementParser interface 29 | virtual Object* getObject() override; 30 | 31 | private: 32 | ImplicitGeometry* m_model; 33 | std::function m_callback; 34 | int m_lodLevel; 35 | CityObject::CityObjectsType m_parentType; 36 | std::string m_orientation; 37 | }; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /sources/include/parser/linearringelementparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace citygml { 8 | 9 | class LinearRing; 10 | 11 | class LinearRingElementParser : public GMLObjectElementParser { 12 | public: 13 | LinearRingElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, bool interior, std::function callback); 14 | 15 | // ElementParser interface 16 | virtual std::string elementParserName() const override; 17 | virtual bool handlesElement(const NodeType::XMLNode &node) const override; 18 | protected: 19 | // CityGMLElementParser interface 20 | virtual bool parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 21 | virtual bool parseElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 22 | virtual bool parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 23 | virtual bool parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 24 | 25 | // GMLObjectElementParser interface 26 | virtual Object* getObject() override; 27 | 28 | private: 29 | LinearRing* m_model; 30 | std::function m_callback; 31 | bool m_interior; 32 | }; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /sources/include/parser/linestringelementparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace citygml { 9 | 10 | class LineString; 11 | 12 | class LineStringElementParser : public GMLObjectElementParser { 13 | public: 14 | LineStringElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, std::function)> callback); 15 | 16 | // ElementParser interface 17 | virtual std::string elementParserName() const override; 18 | virtual bool handlesElement(const NodeType::XMLNode &node) const override; 19 | protected: 20 | // CityGMLElementParser interface 21 | virtual bool parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 22 | virtual bool parseElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 23 | virtual bool parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 24 | virtual bool parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 25 | 26 | // GMLObjectElementParser interface 27 | virtual Object* getObject() override; 28 | 29 | private: 30 | std::shared_ptr m_model; 31 | std::function)> m_callback; 32 | 33 | void parseDimension(Attributes& attributes); 34 | }; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /sources/include/parser/materialelementparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace citygml { 10 | 11 | class Material; 12 | 13 | class MaterialElementParser : public GMLObjectElementParser { 14 | public: 15 | MaterialElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, std::function)> callback); 16 | 17 | // ElementParser interface 18 | virtual std::string elementParserName() const override; 19 | bool handlesElement(const NodeType::XMLNode &node) const override; 20 | 21 | protected: 22 | // CityGMLElementParser interface 23 | virtual bool parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 24 | virtual bool parseElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 25 | virtual bool parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 26 | virtual bool parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 27 | 28 | // GMLObjectElementParser interface 29 | virtual Object* getObject() override; 30 | private: 31 | std::shared_ptr m_model; 32 | std::function)> m_callback; 33 | std::string m_lastTargetDefinitionID; 34 | }; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /sources/include/parser/parserutils.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace citygml { 15 | 16 | template inline T parseValue( const std::string &s, std::shared_ptr&, const DocumentLocation&) 17 | { 18 | std::stringstream ss; 19 | ss << s; 20 | T v; 21 | ss >> v; 22 | return v; 23 | } 24 | 25 | inline TransformationMatrix parseMatrix( const std::string &s, std::shared_ptr& logger, const DocumentLocation& location) 26 | { 27 | std::stringstream ss; 28 | ss << s; 29 | 30 | 31 | double matrix[16] = { 1.0, 0.0, 0.0, 0.0, 32 | 0.0, 1.0, 0.0, 0.0, 33 | 0.0, 0.0, 1.0, 0.0, 34 | 0.0, 0.0, 0.0, 1.0 }; 35 | 36 | for (size_t i = 0; i < 16; ++i) 37 | { 38 | if(ss.eof()) { 39 | CITYGML_LOG_WARN(logger, "Matrix with 16 elements expected, got '" << i + 1 << "' at " << location << ". Matrix may be invalid."); 40 | break; 41 | } 42 | 43 | ss >> matrix[i]; 44 | } 45 | 46 | return TransformationMatrix(matrix); 47 | } 48 | 49 | template<> inline bool parseValue( const std::string &s, std::shared_ptr& logger, const DocumentLocation& location ) 50 | { 51 | // parsing a bool is special because "true" and "1" are true while "false" and "0" are false 52 | if (s == "1" || s == "true") { 53 | return true; 54 | } else if (s == "0" || s == "false") { 55 | return false; 56 | } else { 57 | CITYGML_LOG_WARN(logger, "Boolean expected, got '" << s << "' at " << location << " set value to false."); 58 | } 59 | return false; 60 | } 61 | 62 | template inline std::vector parseVecList( const std::string &s, std::shared_ptr& logger, const DocumentLocation& location ) 63 | { 64 | std::stringstream ss; 65 | ss << s; 66 | 67 | T v; 68 | std::vector vec; 69 | while ( ss >> v ) 70 | vec.push_back( v ); 71 | 72 | if ( !ss.eof() ) 73 | { 74 | CITYGML_LOG_WARN(logger, "Mismatch type, list of " << typeid(T).name() << " expected at " << location << " Ring/Polygon may be incomplete!"); 75 | } 76 | 77 | return vec; 78 | } 79 | 80 | inline std::string parseReference(const std::string& reference, std::shared_ptr& logger, const DocumentLocation& location) { 81 | if (reference.empty()) { 82 | CITYGML_LOG_WARN(logger, "Invalid reference value at " << location); 83 | } 84 | 85 | if (reference[0] == '#') { 86 | return reference.substr(1); 87 | } else { 88 | return reference; 89 | } 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /sources/include/parser/polygonelementparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace citygml { 9 | 10 | class Polygon; 11 | 12 | class PolygonElementParser : public GMLObjectElementParser { 13 | public: 14 | PolygonElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, std::function)> callback); 15 | 16 | // ElementParser interface 17 | virtual std::string elementParserName() const override; 18 | virtual bool handlesElement(const NodeType::XMLNode &node) const override; 19 | protected: 20 | // CityGMLElementParser interface 21 | virtual bool parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 22 | virtual bool parseElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 23 | virtual bool parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 24 | virtual bool parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 25 | 26 | // GMLObjectElementParser interface 27 | virtual Object* getObject() override; 28 | 29 | private: 30 | std::shared_ptr m_model; 31 | std::function)> m_callback; 32 | 33 | void parseRingElement(bool interior); 34 | }; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /sources/include/parser/rectifiedgridcoverageparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "parser/gmlfeaturecollectionparser.h" 5 | #include 6 | 7 | 8 | namespace citygml { 9 | 10 | class RectifiedGridCoverageParser : public GMLFeatureCollectionElementParser { 11 | public: 12 | RectifiedGridCoverageParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, std::function callback); 13 | 14 | // ElementParser interface 15 | virtual std::string elementParserName() const override; 16 | virtual bool handlesElement(const NodeType::XMLNode &node) const override; 17 | protected: 18 | 19 | // CityGMLElementParser interface 20 | virtual bool parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 21 | virtual bool parseElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 22 | virtual bool parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 23 | virtual bool parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 24 | 25 | // GMLFeatureCollectionElementParser interface 26 | virtual FeatureObject* getFeatureObject() override; 27 | 28 | private: 29 | std::function m_callback; 30 | RectifiedGridCoverage * m_model; 31 | }; 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /sources/include/parser/sequenceparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "parser/citygmlelementparser.h" 8 | 9 | namespace citygml { 10 | 11 | /** 12 | * @brief The SequenceParser parses a sequence of elements 13 | * 14 | * The sequence parser can be used if an xml element can contain more than one child elements. If a 15 | * parser finds the start tag of such an element (e.g. ) it can invoke the sequence parser, which 16 | * in turn calls a predefined parser for each child until the end tag of the element is found. 17 | */ 18 | class SequenceParser : public ElementParser { 19 | public: 20 | /** 21 | * @brief initializes the parser for an element that can contain multiple children 22 | * @param documentParser the CityGMLDocumentParser instance 23 | * @param logger a CityGMLLogger logger instance 24 | * @param childParserFactory a factory for the parser for the child elements 25 | * @param parentElement the element that contains the child objects 26 | */ 27 | SequenceParser(CityGMLDocumentParser& documentParser, std::shared_ptr logger, std::function childParserFactory, const NodeType::XMLNode& parentElement); 28 | 29 | // ElementParser interface 30 | virtual bool startElement(const NodeType::XMLNode& node, Attributes& attributes); 31 | virtual bool endElement(const NodeType::XMLNode& node, const std::string& characters); 32 | virtual bool handlesElement(const NodeType::XMLNode& node) const; 33 | virtual std::string elementParserName() const; 34 | 35 | private: 36 | std::function m_childParserFactory; 37 | mutable std::unique_ptr m_childParserInstance; 38 | NodeType::XMLNode m_containerType; 39 | 40 | ElementParser& getChildParserDummyInstance() const; 41 | }; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /sources/include/parser/skipelementparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace citygml { 6 | 7 | /** 8 | * @brief A parser that just skips over the element (and all its child elements) for which it was called 9 | * @note The SkipElementParser can be called for the content of an element that might be empty. In 10 | * that case the SkipElementParser will return control to the calling parser after the end element of that element was parsed. 11 | * Hence the the calling parser should not expect to parse the end element. 12 | */ 13 | class SkipElementParser : public ElementParser { 14 | public: 15 | /** 16 | * @brief initializes the SkipElementParser 17 | * @param skipNode if a valid node is passed the skip parser is bound to that node and skips all its children. 18 | * In that case the start tag of the node must already been parsed. 19 | * If the node is not valid (Default) the skip parser will be bound to the first element it encounters. 20 | */ 21 | SkipElementParser(CityGMLDocumentParser& documentParser, std::shared_ptr logger, const NodeType::XMLNode& skipNode = NodeType::XMLNode()); 22 | 23 | // ElementParser interface 24 | virtual std::string elementParserName() const override; 25 | virtual bool handlesElement(const NodeType::XMLNode &node) const override; 26 | virtual bool startElement(const NodeType::XMLNode& node, Attributes& attributes) override; 27 | virtual bool endElement(const NodeType::XMLNode& node, const std::string& characters) override; 28 | 29 | private: 30 | NodeType::XMLNode m_skipNode; 31 | int m_depth; 32 | 33 | }; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /sources/include/parser/textureassociationelementparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace citygml { 12 | 13 | class Texture; 14 | class TextureTargetDefinition; 15 | class TextureCoordinates; 16 | 17 | // Parser for CityGML 3.0 TextureAssociation elements 18 | class TextureAssociationElementParser : public GMLObjectElementParser { 19 | public: 20 | TextureAssociationElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, std::shared_ptr texture); 21 | 22 | // ElementParser interface 23 | virtual std::string elementParserName() const override; 24 | virtual bool handlesElement(const NodeType::XMLNode &node) const override; 25 | 26 | protected: 27 | // CityGMLElementParser interface 28 | virtual bool parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 29 | virtual bool parseElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 30 | virtual bool parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 31 | virtual bool parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 32 | 33 | // GMLObjectElementParser interface 34 | virtual Object* getObject() override; 35 | 36 | private: 37 | std::shared_ptr m_model; 38 | std::shared_ptr m_currentTexTargetDef; 39 | std::string m_lastTargetDefinitionID; 40 | std::string m_ringId; 41 | std::string m_texCoordGmlId; 42 | std::vector m_texCoordData; 43 | }; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /sources/include/parser/textureelementparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace citygml { 10 | 11 | class Texture; 12 | class TextureTargetDefinition; 13 | class TextureCoordinates; 14 | 15 | class TextureElementParser : public GMLObjectElementParser { 16 | public: 17 | TextureElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, std::function)> callback); 18 | 19 | // ElementParser interface 20 | virtual std::string elementParserName() const override; 21 | virtual bool handlesElement(const NodeType::XMLNode &node) const override; 22 | 23 | protected: 24 | // CityGMLElementParser interface 25 | virtual bool parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 26 | virtual bool parseElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 27 | virtual bool parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) override; 28 | virtual bool parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) override; 29 | 30 | // GMLObjectElementParser interface 31 | virtual Object* getObject() override; 32 | 33 | private: 34 | std::shared_ptr m_model; 35 | std::function)> m_callback; 36 | std::shared_ptr m_currentTexTargetDef; 37 | std::shared_ptr m_currentTexCoords; 38 | }; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /sources/src/citygml/address.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace citygml { 4 | 5 | Address::Address(const std::string& id) 6 | : Object(id) 7 | { 8 | } 9 | 10 | const std::string& Address::country() const { 11 | return m_country; 12 | } 13 | 14 | void Address::setCountry(const std::string& country) { 15 | m_country = country; 16 | } 17 | 18 | const std::string& Address::locality() const { 19 | return m_locality; 20 | } 21 | 22 | void Address::setLocality(const std::string& locality) { 23 | m_locality = locality; 24 | } 25 | 26 | const std::string& Address::postalCode() const { 27 | return m_postalCode; 28 | } 29 | 30 | void Address::setPostalCode(const std::string& postalCode) { 31 | m_postalCode = postalCode; 32 | } 33 | 34 | const std::string& Address::thoroughfareName() const { 35 | return m_thoroughfareName; 36 | } 37 | 38 | void Address::setThoroughfareName(const std::string& thoroughfareName) { 39 | m_thoroughfareName = thoroughfareName; 40 | } 41 | 42 | const std::string& Address::thoroughfareNumber() const { 43 | return m_thoroughfareNumber; 44 | } 45 | 46 | void Address::setThoroughfareNumber(const std::string& thoroughfareNumber) { 47 | m_thoroughfareNumber = thoroughfareNumber; 48 | } 49 | 50 | } /* namespace citygml */ 51 | -------------------------------------------------------------------------------- /sources/src/citygml/appearance.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace citygml { 6 | 7 | Appearance::Appearance(const std::string& id, const std::string& typeString) : Object( id ), m_typeString( typeString ), m_isFront(true) 8 | { 9 | 10 | } 11 | 12 | std::string Appearance::getType() const 13 | { 14 | return m_typeString; 15 | } 16 | 17 | bool Appearance::getIsFront() const 18 | { 19 | return m_isFront; 20 | } 21 | 22 | void Appearance::setIsFront(bool front) 23 | { 24 | m_isFront = front; 25 | } 26 | 27 | std::string Appearance::toString() const 28 | { 29 | return m_typeString + " " + m_id; 30 | } 31 | 32 | std::shared_ptr Appearance::asMaterial() 33 | { 34 | return nullptr; 35 | } 36 | 37 | std::shared_ptr Appearance::asMaterial() const 38 | { 39 | return nullptr; 40 | } 41 | 42 | std::shared_ptr Appearance::asTexture() 43 | { 44 | return nullptr; 45 | } 46 | 47 | std::shared_ptr Appearance::asTexture() const 48 | { 49 | return nullptr; 50 | } 51 | 52 | std::shared_ptr Appearance::asGeoreferencedTexture() 53 | { 54 | return nullptr; 55 | } 56 | 57 | std::shared_ptr Appearance::asGeoreferencedTexture() const 58 | { 59 | return nullptr; 60 | } 61 | 62 | bool Appearance::inTheme(const std::string& themeName) const 63 | { 64 | return std::find(m_themes.begin(), m_themes.end(), themeName) != m_themes.end(); 65 | } 66 | 67 | void Appearance::addToTheme(std::string themeName) 68 | { 69 | m_themes.push_back(themeName); 70 | } 71 | 72 | const std::vector& Appearance::getThemes() const 73 | { 74 | return m_themes; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /sources/src/citygml/appearancemanager.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace citygml { 9 | 10 | AppearanceManager::AppearanceManager(std::shared_ptr logger) 11 | { 12 | m_logger = logger; 13 | } 14 | 15 | AppearanceManager::~AppearanceManager() 16 | { 17 | 18 | } 19 | 20 | std::shared_ptr AppearanceManager::getAppearanceByID(const std::string& id) const 21 | { 22 | auto it = m_appearancesMap.find(id); 23 | 24 | if (it == m_appearancesMap.end()) { 25 | return nullptr; 26 | } 27 | 28 | return it->second; 29 | } 30 | 31 | std::vector AppearanceManager::getAllThemes() 32 | { 33 | std::vector themes(m_themes.begin(), m_themes.end()); 34 | return themes; 35 | } 36 | 37 | void AppearanceManager::addAppearanceTarget(AppearanceTarget* target) 38 | { 39 | m_appearanceTargetsMap[target->getId()] = target; 40 | } 41 | 42 | void AppearanceManager::addAppearance(std::shared_ptr appearance) 43 | { 44 | m_appearancesMap[appearance->getId()] = appearance; 45 | } 46 | 47 | void AppearanceManager::addTextureTargetDefinition(std::shared_ptr targetDef) 48 | { 49 | m_texTargetDefinitions.push_back(targetDef); 50 | } 51 | 52 | void AppearanceManager::addMaterialTargetDefinition(std::shared_ptr targetDef) 53 | { 54 | m_materialTargetDefinitions.push_back(targetDef); 55 | } 56 | 57 | template void assignTargetDefinition(std::shared_ptr& targetDef, const std::unordered_map& targetMap, std::shared_ptr& logger) { 58 | std::string targetID = targetDef->getTargetID(); 59 | auto it = targetMap.find(targetID); 60 | 61 | if (it == targetMap.end()) { 62 | CITYGML_LOG_WARN(logger, "Appearance with id '" << targetDef->getAppearance()->getId() << "' targets object with id " << targetID << " but no such object exists."); 63 | } else { 64 | it->second->addTargetDefinition(targetDef); 65 | } 66 | } 67 | 68 | void AppearanceManager::assignAppearancesToTargets() 69 | { 70 | CITYGML_LOG_INFO(m_logger, "Start assignment of appearances to targets (" 71 | << m_materialTargetDefinitions.size() << " material target definition(s), " 72 | << m_texTargetDefinitions.size() << " texture target definition(s))."); 73 | 74 | for (std::shared_ptr& targetDef : m_materialTargetDefinitions ) { 75 | assignTargetDefinition(targetDef, m_appearanceTargetsMap, m_logger); 76 | addThemesFrom(targetDef->getAppearance()); 77 | } 78 | 79 | for (std::shared_ptr& targetDef : m_texTargetDefinitions ) { 80 | assignTargetDefinition(targetDef, m_appearanceTargetsMap, m_logger); 81 | addThemesFrom(targetDef->getAppearance()); 82 | } 83 | 84 | m_materialTargetDefinitions.clear(); 85 | m_texTargetDefinitions.clear(); 86 | m_appearanceTargetsMap.clear(); 87 | m_appearancesMap.clear(); 88 | 89 | CITYGML_LOG_INFO(m_logger, "Finished assignment of appearances to targets (" 90 | << m_materialTargetDefinitions.size() << " material target definition(s), " 91 | << m_texTargetDefinitions.size() << " texture target definition(s))."); 92 | 93 | } 94 | 95 | void AppearanceManager::addThemesFrom(std::shared_ptr surfaceData) 96 | { 97 | m_themes.insert(surfaceData->getThemes().begin(), surfaceData->getThemes().end()); 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /sources/src/citygml/attributesmap.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace citygml { 6 | 7 | AttributeValue::AttributeValue() 8 | : m_type(AttributeType::String) 9 | { 10 | } 11 | 12 | AttributeValue::AttributeValue(const char* value) 13 | : m_type(AttributeType::String) 14 | , m_value(value) 15 | { 16 | 17 | } 18 | 19 | AttributeValue::AttributeValue(const std::string& value, AttributeType type) 20 | : m_type(type) 21 | , m_value(value) 22 | { 23 | 24 | } 25 | 26 | AttributeValue::AttributeValue(double value) 27 | { 28 | setValue(value); 29 | } 30 | 31 | AttributeValue::AttributeValue(int value) 32 | { 33 | setValue(value); 34 | } 35 | 36 | void AttributeValue::setType(AttributeType type) 37 | { 38 | m_type = type; 39 | } 40 | 41 | AttributeType AttributeValue::getType() const 42 | { 43 | return m_type; 44 | } 45 | 46 | void AttributeValue::setValue(const std::string& value, AttributeType type) 47 | { 48 | m_type = type; 49 | m_value = value; 50 | } 51 | 52 | void AttributeValue::setValue(double value) 53 | { 54 | m_type = AttributeType::Double; 55 | 56 | std::stringstream sstream; 57 | sstream << value; 58 | m_value = sstream.str(); 59 | } 60 | 61 | void AttributeValue::setValue(int value) 62 | { 63 | m_type = AttributeType::Integer; 64 | 65 | std::stringstream sstream; 66 | sstream << value; 67 | m_value = sstream.str(); 68 | } 69 | 70 | std::string AttributeValue::asString() const 71 | { 72 | return m_value; 73 | } 74 | 75 | double AttributeValue::asDouble(double defaultValue) const 76 | { 77 | double value = defaultValue; 78 | 79 | if (m_type == AttributeType::Double) 80 | { 81 | std::stringstream sstream; 82 | sstream << m_value; 83 | sstream >> value; 84 | } 85 | 86 | return value; 87 | } 88 | 89 | int AttributeValue::asInteger(int defaultValue) const 90 | { 91 | int value = defaultValue; 92 | 93 | if (m_type == AttributeType::Integer) 94 | { 95 | std::stringstream sstream; 96 | sstream << m_value; 97 | sstream >> value; 98 | } 99 | 100 | return value; 101 | } 102 | 103 | std::ostream& operator<<(std::ostream& os, const AttributeValue& o) 104 | { 105 | os << o.asString(); 106 | return os; 107 | } 108 | 109 | } // namespace citygml 110 | -------------------------------------------------------------------------------- /sources/src/citygml/citymodel.cpp: -------------------------------------------------------------------------------- 1 | /* -*-c++-*- libcitygml - Copyright (c) 2010 Joachim Pouderoux, BRGM 2 | * 3 | * Contributors: 4 | * - Manuel Garnier, BRGM - better normal computation 5 | * 6 | * This file is part of libcitygml library 7 | * http://code.google.com/p/libcitygml 8 | * 9 | * libcitygml is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 2.1 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * libcitygml is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #ifndef min 33 | # define min( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) ) 34 | #endif 35 | 36 | /////////////////////////////////////////////////////////////////////////////// 37 | 38 | namespace citygml 39 | { 40 | CityModel::CityModel(const std::string& id) : FeatureObject( id ) 41 | { 42 | 43 | } 44 | 45 | void CityModel::addToCityObjectsMapRecursive(const CityObject* cityObj) 46 | { 47 | 48 | CityObjectsMap::iterator it = m_cityObjectsMap.find(cityObj->getType()); 49 | 50 | if (it == m_cityObjectsMap.end()) { 51 | std::vector tmp; 52 | tmp.push_back(cityObj); 53 | m_cityObjectsMap[cityObj->getType()] = std::vector(tmp); 54 | } else { 55 | it->second.push_back(cityObj); 56 | } 57 | 58 | for (unsigned int i = 0; i < cityObj->getChildCityObjectsCount(); i++) { 59 | addToCityObjectsMapRecursive(&cityObj->getChildCityObject(i)); 60 | } 61 | } 62 | std::vector CityModel::themes() const 63 | { 64 | return m_themes; 65 | } 66 | 67 | void CityModel::setThemes(std::vector themes) 68 | { 69 | m_themes = themes; 70 | } 71 | 72 | 73 | CityModel::~CityModel() 74 | { 75 | } 76 | 77 | const ConstCityObjects CityModel::getAllCityObjectsOfType( CityObject::CityObjectsType type ) const 78 | { 79 | CityObjectsMap::const_iterator it = m_cityObjectsMap.find( type ); 80 | return it->second; 81 | } 82 | 83 | const ConstCityObjects CityModel::getRootCityObjects() const 84 | { 85 | ConstCityObjects list; 86 | for (const std::unique_ptr& cityObj : m_roots) { 87 | list.push_back(cityObj.get()); 88 | } 89 | return list; 90 | } 91 | 92 | void CityModel::addRootObject(CityObject* obj) 93 | { 94 | m_roots.push_back(std::unique_ptr(obj)); 95 | } 96 | 97 | unsigned int CityModel::getNumRootCityObjects() const 98 | { 99 | return static_cast(m_roots.size()); 100 | } 101 | 102 | CityObject& CityModel::getRootCityObject(int i) 103 | { 104 | return *m_roots.at(i); 105 | } 106 | 107 | const CityObject& CityModel::getRootCityObject(int i) const 108 | { 109 | return *m_roots.at(i); 110 | } 111 | 112 | const std::string& CityModel::getSRSName() const 113 | { 114 | return m_srsName; 115 | } 116 | 117 | 118 | void CityModel::finish(TesselatorBase* tesselator, bool optimize, bool tesselate, std::shared_ptr logger) 119 | { 120 | // Finish all cityobjcts 121 | for (auto& cityObj : m_roots) { 122 | cityObj->finish(tesselator, optimize, logger); 123 | } 124 | 125 | // Build city objects map 126 | for (std::unique_ptr& obj : m_roots) { 127 | addToCityObjectsMapRecursive(obj.get()); 128 | } 129 | } 130 | 131 | std::ostream& operator<<( std::ostream& out, const CityModel& model ) 132 | { 133 | out << "Root CityObjects: " << std::endl; 134 | ConstCityObjects rootObjcts = model.getRootCityObjects(); 135 | for (const CityObject* cityObj : rootObjcts) { 136 | out << cityObj << std::endl; 137 | } 138 | return out; 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /sources/src/citygml/envelope.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #ifndef NAN 7 | #define NAN std::numeric_limits::quiet_NaN() 8 | #endif 9 | 10 | #ifdef WIN32 11 | #define ISNAN _isnan 12 | #else 13 | #define ISNAN std::isnan 14 | #endif 15 | 16 | namespace citygml { 17 | 18 | 19 | Envelope::Envelope() 20 | { 21 | m_lowerBound = TVec3d(NAN,NAN,NAN); 22 | m_upperBound = TVec3d(NAN,NAN,NAN); 23 | } 24 | 25 | Envelope::Envelope(const std::string& srsName) 26 | { 27 | m_srsName = srsName; 28 | } 29 | 30 | const TVec3d& Envelope::getLowerBound() const 31 | { 32 | return m_lowerBound; 33 | } 34 | 35 | void Envelope::setLowerBound(const TVec3d& coordinate) 36 | { 37 | m_lowerBound = coordinate; 38 | } 39 | 40 | const TVec3d& Envelope::getUpperBound() const 41 | { 42 | return m_upperBound; 43 | } 44 | 45 | void Envelope::setUpperBound(const TVec3d& coordinate) 46 | { 47 | m_upperBound = coordinate; 48 | } 49 | 50 | const std::string& Envelope::srsName() const 51 | { 52 | return m_srsName; 53 | } 54 | 55 | const bool Envelope::validBounds() const 56 | { 57 | return !(ISNAN(m_lowerBound.x) || ISNAN(m_lowerBound.y) || ISNAN(m_lowerBound.z) 58 | || ISNAN(m_upperBound.x) || ISNAN(m_upperBound.y) || ISNAN(m_upperBound.z)); 59 | } 60 | 61 | std::ostream& operator<<( std::ostream& os, const Envelope& e ) 62 | { 63 | return os << e.getLowerBound() << " " << e.getUpperBound(); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /sources/src/citygml/externalreference.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace citygml { 4 | namespace { 5 | const std::string EMPTY_STRING(""); 6 | } // anonymous namespace 7 | 8 | const std::string& ExternalObjectReference::getName() const { 9 | if (type == ObjectRefType::NAME) { 10 | return value; 11 | } else { 12 | return EMPTY_STRING; 13 | } 14 | } 15 | 16 | const std::string& ExternalObjectReference::getUri() const { 17 | if (type == ObjectRefType::URI) { 18 | return value; 19 | } else { 20 | return EMPTY_STRING; 21 | } 22 | } 23 | 24 | void ExternalObjectReference::setName(const std::string& name) { 25 | type = ObjectRefType::NAME; 26 | value = name; 27 | } 28 | 29 | void ExternalObjectReference::setUri(const std::string& uri) { 30 | type = ObjectRefType::URI; 31 | value = uri; 32 | } 33 | 34 | ExternalReference::ExternalReference(std::string const& id) : Object(id) { 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sources/src/citygml/featureobject.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace citygml { 6 | 7 | FeatureObject::FeatureObject(const std::string& gmlID) : Object(gmlID) 8 | { 9 | setEnvelope(new Envelope()); 10 | } 11 | 12 | const Envelope& FeatureObject::getEnvelope() const 13 | { 14 | return *m_envelope; 15 | } 16 | 17 | void FeatureObject::setEnvelope(Envelope* e) 18 | { 19 | m_envelope = std::unique_ptr(e); 20 | } 21 | 22 | FeatureObject::~FeatureObject() 23 | { 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /sources/src/citygml/geometrymanager.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace citygml { 8 | 9 | GeometryManager::GeometryManager(std::shared_ptr logger) 10 | { 11 | m_logger = logger; 12 | } 13 | 14 | void GeometryManager::addSharedGeometry(std::shared_ptr geom) 15 | { 16 | if (m_sharedGeometries.count(geom->getId()) > 0) { 17 | CITYGML_LOG_WARN(m_logger, "Duplicate definition of shared geometry with id '" << geom->getId() << "'... overwriting existing object."); 18 | } 19 | 20 | m_sharedGeometries[geom->getId()] = geom; 21 | } 22 | 23 | void GeometryManager::requestSharedGeometryForImplicitGeometry(ImplicitGeometry* geom, const std::string& geometryID) 24 | { 25 | m_geometryRequests.push_back(GeometryRequest(geom, geometryID)); 26 | } 27 | 28 | void GeometryManager::finish() 29 | { 30 | CITYGML_LOG_INFO(m_logger, "Start processing shared geometry requests (" << m_geometryRequests.size() << ")."); 31 | for (const GeometryRequest& request : m_geometryRequests) { 32 | 33 | auto it = m_sharedGeometries.find(request.geometryID); 34 | if (it == m_sharedGeometries.end()) { 35 | CITYGML_LOG_WARN(m_logger, "ImplicitGeometry object with id '" << request.target->getId() << "' requests Geometry with id '" << request.geometryID << "' but no such" 36 | << "shared Geometry object exists."); 37 | continue; 38 | } 39 | 40 | request.target->addGeometry(it->second); 41 | 42 | } 43 | 44 | m_sharedGeometries.clear(); 45 | m_geometryRequests.clear(); 46 | 47 | CITYGML_LOG_INFO(m_logger, "Finished processing shared geometry requests."); 48 | } 49 | 50 | GeometryManager::~GeometryManager() 51 | { 52 | 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /sources/src/citygml/georeferencedtexture.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace citygml { 4 | 5 | GeoreferencedTexture::GeoreferencedTexture(const std::string& id) : Texture( id, "GeoreferencedTexture" ), m_preferWorldFile(true) 6 | { 7 | 8 | } 9 | 10 | bool GeoreferencedTexture::getPreferWorldFile() const 11 | { 12 | return m_preferWorldFile; 13 | } 14 | 15 | void GeoreferencedTexture::setPreferWorldFile(bool value) 16 | { 17 | m_preferWorldFile = value; 18 | } 19 | 20 | std::shared_ptr GeoreferencedTexture::asTexture() 21 | { 22 | return std::static_pointer_cast(shared_from_this()); 23 | } 24 | 25 | std::shared_ptr GeoreferencedTexture::asTexture() const 26 | { 27 | return std::static_pointer_cast(shared_from_this()); 28 | } 29 | 30 | std::shared_ptr GeoreferencedTexture::asGeoreferencedTexture() 31 | { 32 | return std::static_pointer_cast(shared_from_this()); 33 | } 34 | 35 | std::shared_ptr GeoreferencedTexture::asGeoreferencedTexture() const 36 | { 37 | return std::static_pointer_cast(shared_from_this()); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /sources/src/citygml/implictgeometry.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace citygml { 5 | 6 | ImplicitGeometry::ImplicitGeometry(const std::string& id) : Object(id) 7 | { 8 | 9 | } 10 | 11 | void ImplicitGeometry::setTransformMatrix(const TransformationMatrix matrix) 12 | { 13 | m_matrix = matrix; 14 | } 15 | 16 | const TransformationMatrix& ImplicitGeometry::getTransformMatrix() const 17 | { 18 | return m_matrix; 19 | } 20 | 21 | void ImplicitGeometry::setReferencePoint(const TVec3d& referencePoint) 22 | { 23 | m_referencePoint = referencePoint; 24 | } 25 | 26 | TVec3d ImplicitGeometry::getReferencePoint() const 27 | { 28 | return m_referencePoint; 29 | } 30 | 31 | void ImplicitGeometry::addGeometry(std::shared_ptr geom) 32 | { 33 | m_geometries.push_back(geom); 34 | } 35 | 36 | unsigned int ImplicitGeometry::getGeometriesCount() const 37 | { 38 | return static_cast(m_geometries.size()); 39 | } 40 | 41 | Geometry& ImplicitGeometry::getGeometry(unsigned int i) const 42 | { 43 | return *m_geometries[i]; 44 | } 45 | 46 | std::string ImplicitGeometry::getSRSName() const 47 | { 48 | return m_srsName; 49 | } 50 | 51 | void ImplicitGeometry::setSRSName(const std::string& srsName) 52 | { 53 | m_srsName = srsName; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /sources/src/citygml/linestring.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | 7 | citygml::LineString::LineString(const std::string& id) : Object(id) 8 | { 9 | m_dimensions = -1; 10 | } 11 | 12 | int citygml::LineString::getDimensions() const 13 | { 14 | return m_dimensions; 15 | } 16 | 17 | const std::vector& citygml::LineString::getVertices2D() const 18 | { 19 | return m_vertices_2d; 20 | } 21 | 22 | const std::vector& citygml::LineString::getVertices3D() const 23 | { 24 | return m_vertices_3d; 25 | } 26 | 27 | std::vector& citygml::LineString::getVertices2D() 28 | { 29 | return m_vertices_2d; 30 | } 31 | 32 | std::vector& citygml::LineString::getVertices3D() 33 | { 34 | return m_vertices_3d; 35 | } 36 | 37 | void citygml::LineString::setVertices2D(const std::vector& vertices) 38 | { 39 | if (m_dimensions != 2) { 40 | setDimensions(2); 41 | } 42 | 43 | m_vertices_2d = vertices; 44 | } 45 | 46 | void citygml::LineString::setVertices3D(const std::vector& vertices) 47 | { 48 | if (m_dimensions != 3) { 49 | setDimensions(3); 50 | } 51 | 52 | m_vertices_3d = vertices; 53 | } 54 | 55 | void citygml::LineString::setDimensions(int dim) 56 | { 57 | m_dimensions = dim; 58 | if (dim != 2 && !m_vertices_2d.empty()) { 59 | throw std::runtime_error("LineString not set to dimension 2 but contains 2D vertices."); 60 | } else if (dim != 3 && !m_vertices_3d.empty()) { 61 | throw std::runtime_error("LineString not set to dimension 3 but contains 3D vertices."); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /sources/src/citygml/material.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace citygml { 4 | 5 | Material::Material(const std::string& id) : Appearance( id, "Material" ) 6 | { 7 | // Sets default values of the X3DMaterial definied in the citygml 1.0.0 spec see page 32 (section 9.3 Material) 8 | m_ambientIntensity = 0.2f; 9 | 10 | m_diffuse = TVec3f(0.8f, 0.8f, 0.8f); 11 | m_emissive = TVec3f(0.f, 0.f, 0.f); 12 | m_specular = TVec3f(1.f, 1.f, 1.f); 13 | 14 | m_shininess = 0.2f; 15 | m_transparency = 0.f; 16 | 17 | m_isSmooth = false; 18 | 19 | } 20 | 21 | bool Material::isSmooth() const 22 | { 23 | return m_isSmooth; 24 | } 25 | 26 | void Material::setIsSmooth(bool isSmooth) 27 | { 28 | m_isSmooth = isSmooth; 29 | } 30 | 31 | 32 | TVec3f Material::getDiffuse() const 33 | { 34 | return m_diffuse; 35 | } 36 | 37 | void Material::setDiffuse(TVec3f diffuse) 38 | { 39 | m_diffuse = diffuse; 40 | } 41 | 42 | TVec3f Material::getEmissive() const 43 | { 44 | return m_emissive; 45 | } 46 | 47 | void Material::setEmissive(TVec3f emissive) 48 | { 49 | m_emissive = emissive; 50 | } 51 | 52 | TVec3f Material::getSpecular() const 53 | { 54 | return m_specular; 55 | } 56 | 57 | void Material::setSpecular(TVec3f specular) 58 | { 59 | m_specular = specular; 60 | } 61 | 62 | float Material::getAmbientIntensity() const 63 | { 64 | return m_ambientIntensity; 65 | } 66 | 67 | void Material::setAmbientIntensity(float intensity) 68 | { 69 | m_ambientIntensity = intensity; 70 | } 71 | 72 | float Material::getShininess() const 73 | { 74 | return m_shininess; 75 | } 76 | 77 | void Material::setShininess(float shininess) 78 | { 79 | m_shininess = shininess; 80 | } 81 | 82 | float Material::getTransparency() const 83 | { 84 | return m_transparency; 85 | } 86 | 87 | void Material::setTransparency(float transparancy) 88 | { 89 | m_transparency = transparancy; 90 | } 91 | 92 | std::shared_ptr Material::asMaterial() 93 | { 94 | return std::static_pointer_cast(shared_from_this()); 95 | } 96 | 97 | std::shared_ptr Material::asMaterial() const 98 | { 99 | return std::static_pointer_cast(shared_from_this()); 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /sources/src/citygml/materialtargetdefinition.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace citygml { 4 | 5 | MaterialTargetDefinition::MaterialTargetDefinition(const std::string& targetID, std::shared_ptr appearance, const std::string& id) : AppearanceTargetDefinition(targetID, appearance, id) 6 | { 7 | 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /sources/src/citygml/object.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | namespace citygml { 7 | 8 | Object::Object(const std::string& id) : m_id( id ) 9 | { 10 | if ( m_id == "" ) 11 | { 12 | std::stringstream ss; 13 | ss << "PtrId_" << this; 14 | m_id = ss.str(); 15 | } 16 | } 17 | 18 | const std::string&Object::getId() const 19 | { 20 | return m_id; 21 | } 22 | 23 | std::string Object::getAttribute(const std::string& name) const 24 | { 25 | AttributesMap::const_iterator elt = m_attributes.find( name ); 26 | return elt != m_attributes.end() ? elt->second.asString() : ""; 27 | } 28 | 29 | const AttributesMap& Object::getAttributes() const 30 | { 31 | return m_attributes; 32 | } 33 | 34 | AttributesMap& Object::getAttributes() 35 | { 36 | return m_attributes; 37 | } 38 | 39 | void Object::setAttribute(const std::string& name, const std::string& value, AttributeType type, bool overwrite) 40 | { 41 | if ( !overwrite ) 42 | { 43 | if ( m_attributes.count(name) > 1 ) return; 44 | } 45 | m_attributes[ name ] = AttributeValue(value, type); 46 | } 47 | 48 | std::ostream& operator<<( std::ostream& os, const Object& o ) 49 | { 50 | return os << o.getId(); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /sources/src/citygml/polygonmanager.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace citygml { 8 | 9 | PolygonManager::PolygonManager(std::shared_ptr logger) 10 | { 11 | m_logger = logger; 12 | } 13 | 14 | void PolygonManager::addPolygon(std::shared_ptr poly) 15 | { 16 | if (m_sharedPolygons.count(poly->getId()) > 0) { 17 | CITYGML_LOG_WARN(m_logger, "Duplicate definition of Polygon with id '" << poly->getId() << "'... overwriting existing object."); 18 | } 19 | 20 | m_sharedPolygons[poly->getId()] = poly; 21 | } 22 | 23 | void PolygonManager::requestSharedPolygonForGeometry(Geometry* geom, const std::string& polygonID) 24 | { 25 | m_polygonRequests.push_back(PolygonRequest(geom, polygonID)); 26 | } 27 | 28 | void PolygonManager::finish() 29 | { 30 | CITYGML_LOG_INFO(m_logger, "Start processing polygon requests (" << m_polygonRequests.size() << ")."); 31 | for (const PolygonRequest& request : m_polygonRequests) { 32 | 33 | auto it = m_sharedPolygons.find(request.polygonID); 34 | if (it == m_sharedPolygons.end()) { 35 | CITYGML_LOG_WARN(m_logger, "Geometry object with id '" << request.target->getId() << "' requests Polygon with id '" << request.polygonID << "' but no such" 36 | << " Polygon object exists."); 37 | continue; 38 | } 39 | 40 | request.target->addPolygon(it->second); 41 | 42 | } 43 | 44 | m_sharedPolygons.clear(); 45 | m_polygonRequests.clear(); 46 | 47 | CITYGML_LOG_INFO(m_logger, "Finished processing polygon requests."); 48 | } 49 | 50 | PolygonManager::~PolygonManager() 51 | { 52 | 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /sources/src/citygml/rectifiedgridcoverage.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace citygml { 4 | RectifiedGridCoverage::RectifiedGridCoverage(std::string const& id) : FeatureObject(id) { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /sources/src/citygml/tesselatorbase.cpp: -------------------------------------------------------------------------------- 1 | /* -*-c++-*- libcitygml - Copyright (c) 2010 Joachim Pouderoux, BRGM 2 | * 3 | * Contributors: 4 | * - Manuel Garnier, BRGM - better normal computation 5 | * 6 | * This file is part of libcitygml library 7 | * http://code.google.com/p/libcitygml 8 | * 9 | * libcitygml is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 2.1 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * libcitygml is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | */ 19 | 20 | #ifdef WIN32 21 | #define WINDOWS_LEAN_AND_MEAN 22 | #define NOMINMAX 23 | #endif 24 | 25 | #include 26 | #ifndef WIN32 27 | # include 28 | #endif 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | TesselatorBase::TesselatorBase(std::shared_ptr logger ) 38 | { 39 | _logger = logger; 40 | _keepVertices = false; 41 | } 42 | 43 | void TesselatorBase::init( const TVec3d& normal) 44 | { 45 | _vertices.clear(); 46 | _indices.clear(); 47 | _curIndices.clear(); 48 | _texCoordsLists.clear(); 49 | _outIndices.clear(); 50 | } 51 | 52 | TesselatorBase::~TesselatorBase() 53 | { 54 | } 55 | 56 | void TesselatorBase::setLogger(std::shared_ptr logger) 57 | { 58 | _logger = logger; 59 | } 60 | 61 | const std::vector& TesselatorBase::getVertices() const 62 | { 63 | return _vertices; 64 | } 65 | 66 | const std::vector& TesselatorBase::getIndices() const 67 | { 68 | return _outIndices; 69 | } 70 | 71 | void TesselatorBase::setKeepVertices(bool value) 72 | { 73 | _keepVertices = value; 74 | } 75 | 76 | bool TesselatorBase::keepVertices() const 77 | { 78 | return _keepVertices; 79 | } 80 | 81 | void TesselatorBase::addContour(const std::vector& pts, std::vector > textureCoordinatesLists ) 82 | { 83 | unsigned int len = static_cast(pts.size()); 84 | if ( len < 3 ) return; 85 | 86 | for (size_t i = 0; i < textureCoordinatesLists.size(); i++) { 87 | 88 | std::vector& texCoords = textureCoordinatesLists.at(i); 89 | 90 | 91 | 92 | if (texCoords.size() != pts.size()) { 93 | if (!texCoords.empty()) { 94 | CITYGML_LOG_ERROR(_logger, "Invalid call to 'addContour'. The number of texture coordinates in list " << i << " (" << texCoords.size() << ") " 95 | "does not match the number of vertices (" << pts.size() << "). The texture coordinates list will be resized which may cause invalid texture coordinates."); 96 | } 97 | 98 | texCoords.resize(pts.size(), TVec2f(0.f, 0.f)); 99 | } 100 | } 101 | 102 | for (size_t i = 0; i < std::max(_texCoordsLists.size(), textureCoordinatesLists.size()); i++) { 103 | 104 | if (i >= _texCoordsLists.size()) { 105 | std::vector texCoords(_vertices.size(), TVec2f(0.f, 0.f)); 106 | texCoords.insert(texCoords.end(), textureCoordinatesLists.at(i).begin(), textureCoordinatesLists.at(i).end()); 107 | _texCoordsLists.push_back(texCoords); 108 | } else if (i >= textureCoordinatesLists.size()) { 109 | _texCoordsLists.at(i).resize(_texCoordsLists.at(i).size() + pts.size(), TVec2f(0.f, 0.f)); 110 | } else { 111 | _texCoordsLists.at(i).insert(_texCoordsLists.at(i).end(), textureCoordinatesLists.at(i).begin(), textureCoordinatesLists.at(i).end()); 112 | } 113 | 114 | } 115 | 116 | unsigned int pos = static_cast(_vertices.size()); 117 | 118 | for ( unsigned int i = 0; i < len; i++ ) 119 | { 120 | _vertices.push_back( pts[i] ); 121 | _indices.push_back(pos + i); 122 | } 123 | 124 | #ifndef NDEBUG 125 | for (size_t i = 0; i < _texCoordsLists.size(); i++) { 126 | assert(_texCoordsLists.at(i).size() == _vertices.size()); 127 | } 128 | #endif 129 | } 130 | -------------------------------------------------------------------------------- /sources/src/citygml/texture.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace citygml { 5 | 6 | Texture::Texture(const std::string& id) : Appearance( id, "Texture" ), m_repeat( false ), m_wrapMode( WrapMode::WM_NONE ) 7 | { 8 | 9 | } 10 | 11 | Texture::Texture(const std::string& id, const std::string& type) : Appearance( id, type ), m_repeat( false ), m_wrapMode( WrapMode::WM_NONE ) 12 | { 13 | 14 | } 15 | 16 | std::string Texture::getUrl() const 17 | { 18 | return m_url; 19 | } 20 | 21 | void Texture::setUrl(const std::string& url) 22 | { 23 | m_url = url; 24 | } 25 | 26 | bool Texture::getRepeat() const 27 | { 28 | return m_repeat; 29 | } 30 | 31 | Texture::WrapMode Texture::getWrapMode() const 32 | { 33 | return m_wrapMode; 34 | } 35 | 36 | void Texture::setWrapMode(Texture::WrapMode mode) 37 | { 38 | m_wrapMode = mode; 39 | } 40 | 41 | bool Texture::setWrapModeFromString(std::string wrapMode) 42 | { 43 | if ( ci_string_compare( wrapMode, "wrap" ) ) { 44 | this->setWrapMode(Texture::WrapMode::WM_WRAP); 45 | } 46 | else if ( ci_string_compare( wrapMode, "mirror" ) ) { 47 | this->setWrapMode(Texture::WrapMode::WM_MIRROR); 48 | } 49 | else if ( ci_string_compare( wrapMode, "clamp" ) ) { 50 | this->setWrapMode(Texture::WrapMode::WM_CLAMP); 51 | } 52 | else if ( ci_string_compare( wrapMode, "border" ) ) { 53 | this->setWrapMode(Texture::WrapMode::WM_BORDER); 54 | } 55 | else if ( ci_string_compare( wrapMode, "none" ) ) { 56 | this->setWrapMode(Texture::WrapMode::WM_NONE); 57 | } 58 | else { 59 | return false; 60 | } 61 | 62 | return true; 63 | } 64 | 65 | TVec4f Texture::getBorderColor() const 66 | { 67 | return m_borderColor; 68 | } 69 | 70 | void Texture::setBorderColor(TVec4f color) 71 | { 72 | m_borderColor = color; 73 | } 74 | 75 | std::string Texture::toString() const 76 | { 77 | return Appearance::toString() + " (url: " + m_url + ")"; 78 | } 79 | 80 | std::shared_ptr Texture::asTexture() 81 | { 82 | return std::static_pointer_cast(shared_from_this()); 83 | } 84 | 85 | std::shared_ptr Texture::asTexture() const 86 | { 87 | return std::static_pointer_cast(shared_from_this()); 88 | } 89 | 90 | Texture::~Texture() 91 | { 92 | } 93 | 94 | 95 | } 96 | -------------------------------------------------------------------------------- /sources/src/citygml/texturecoordinates.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace citygml { 5 | 6 | TextureCoordinates::TextureCoordinates(std::string id, std::string targetID) : Object(id) 7 | { 8 | m_targetID = targetID; 9 | } 10 | 11 | bool TextureCoordinates::targets(const LinearRing& ring) const 12 | { 13 | return m_targetID == ring.getId(); 14 | } 15 | 16 | std::string TextureCoordinates::getTargetLinearRingID() const 17 | { 18 | return m_targetID; 19 | } 20 | 21 | bool TextureCoordinates::eraseCoordinate(unsigned int i) 22 | { 23 | if (i < m_coordlist.size()) { 24 | m_coordlist.erase(m_coordlist.begin() + i); 25 | return true; 26 | } 27 | return false; 28 | } 29 | 30 | const std::vector& TextureCoordinates::getCoords() const 31 | { 32 | return m_coordlist; 33 | } 34 | 35 | void TextureCoordinates::setCoords(std::vector texCoords) 36 | { 37 | m_coordlist = texCoords; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /sources/src/citygml/texturetargetdefinition.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace citygml { 5 | 6 | TextureTargetDefinition::TextureTargetDefinition(const std::string& targetID, std::shared_ptr appearance, const std::string& id) : AppearanceTargetDefinition(targetID, appearance, id) 7 | { 8 | } 9 | 10 | unsigned int TextureTargetDefinition::getTextureCoordinatesCount() const 11 | { 12 | return static_cast(m_coordinatesList.size()); 13 | } 14 | 15 | std::shared_ptr TextureTargetDefinition::getTextureCoordinates(unsigned int i) 16 | { 17 | return m_coordinatesList.at(i); 18 | } 19 | 20 | std::shared_ptr TextureTargetDefinition::getTextureCoordinates(unsigned int i) const 21 | { 22 | return m_coordinatesList.at(i); 23 | } 24 | 25 | std::shared_ptr TextureTargetDefinition::getTextureCoordinatesForID(const std::string& ringID) 26 | { 27 | auto it = m_idTexCoordMap.find(ringID); 28 | if (it != m_idTexCoordMap.end()) { 29 | return it->second; 30 | } 31 | return nullptr; 32 | } 33 | 34 | std::shared_ptr TextureTargetDefinition::getTextureCoordinatesForID(const std::string& ringID) const 35 | { 36 | const auto it = m_idTexCoordMap.find(ringID); 37 | if (it != m_idTexCoordMap.end()) { 38 | return it->second; 39 | } 40 | return nullptr; 41 | } 42 | 43 | void TextureTargetDefinition::addTexCoordinates(std::shared_ptr texCoords) 44 | { 45 | m_coordinatesList.push_back(texCoords); 46 | m_idTexCoordMap[texCoords->getTargetLinearRingID()] = texCoords; 47 | } 48 | 49 | TextureTargetDefinition::~TextureTargetDefinition() 50 | { 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /sources/src/citygml/transformmatrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace citygml { 4 | 5 | TransformationMatrix::TransformationMatrix() : Object("") 6 | { 7 | for (int i = 0; i < 4; i++) { 8 | for (int j = 0; j < 4; j++) { 9 | m_matrix[i + j * 4] = i == j; 10 | m_transposedMatrix[i + j * 4] = i == j; 11 | } 12 | } 13 | } 14 | 15 | TransformationMatrix::TransformationMatrix(double* matrix) : Object("") 16 | { 17 | for (size_t i = 0; i < 16; ++i) { 18 | m_matrix[i] = matrix[i]; 19 | } 20 | 21 | for (size_t i = 0; i < 4; ++i) { 22 | for (size_t j = 0; j < 4; ++j) { 23 | m_transposedMatrix[i+j*4] = m_matrix[j+i*4]; 24 | } 25 | } 26 | } 27 | 28 | const double* TransformationMatrix::getMatrix() const 29 | { 30 | return m_matrix; 31 | } 32 | 33 | const double* TransformationMatrix::getTransposedMatrix() const 34 | { 35 | return m_transposedMatrix; 36 | } 37 | 38 | TransformationMatrix::~TransformationMatrix() 39 | { 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /sources/src/parser/attributes.cpp: -------------------------------------------------------------------------------- 1 | #include "parser/attributes.h" 2 | #include "parser/parserutils.hpp" 3 | #include "parser/documentlocation.h" 4 | 5 | #include 6 | 7 | #include "sstream" 8 | 9 | namespace citygml { 10 | 11 | Attributes::Attributes(std::shared_ptr logger) 12 | { 13 | m_logger = logger; 14 | } 15 | 16 | std::string Attributes::getCityGMLIDAttribute() const 17 | { 18 | std::string id = getAttribute("gml:id", ""); 19 | if (id.empty()) { 20 | std::stringstream defaultID; 21 | defaultID << "genID_" << getDocumentLocation().getDocumentFileName() << "_" << getDocumentLocation().getCurrentLine() << "_" << + getDocumentLocation().getCurrentColumn(); 22 | id = defaultID.str(); 23 | } 24 | return id; 25 | } 26 | 27 | bool Attributes::hasXLinkAttribute() const 28 | { 29 | return !getAttribute("xlink:href", "").empty(); 30 | } 31 | 32 | std::string Attributes::getXLinkValue() 33 | { 34 | return parseReference(getAttribute("xlink:href", ""), m_logger, getDocumentLocation()); 35 | } 36 | 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /sources/src/parser/citygmlelementparser.cpp: -------------------------------------------------------------------------------- 1 | #include "parser/citygmlelementparser.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "parser/citygmldocumentparser.h" 7 | #include "parser/documentlocation.h" 8 | #include "parser/nodetypes.h" 9 | 10 | #include 11 | 12 | namespace citygml { 13 | 14 | CityGMLElementParser::CityGMLElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger) 15 | : ElementParser(documentParser, logger), m_factory(factory), m_boundElement(NodeType::InvalidNode) 16 | { 17 | } 18 | 19 | bool CityGMLElementParser::startElement(const NodeType::XMLNode& node, Attributes& attributes) 20 | { 21 | if (!node.valid()) { 22 | CITYGML_LOG_ERROR(m_logger, "Invalid xml start tag (no name) found at " << getDocumentLocation()); 23 | throw std::runtime_error("Error parsing xml document. Invalid start tag."); 24 | } 25 | 26 | if (!m_boundElement.valid()) { 27 | m_boundElement = node; 28 | return parseElementStartTag(node, attributes); 29 | } else { 30 | return parseChildElementStartTag(node, attributes); 31 | } 32 | } 33 | 34 | bool CityGMLElementParser::endElement(const NodeType::XMLNode& node, const std::string& characters) 35 | { 36 | if (!m_boundElement.valid()) { 37 | // This might happen if an container element that usally contains a child element links to an exting object using XLink an thus 38 | // uses a combined start/end element: e.g.: 39 | // For such elements a child parser must only be created if there is no xlink attribute. 40 | // It can also happen in cases when a only contains ignored elements. 41 | CITYGML_LOG_WARN(m_logger, "CityGMLElementParser::endElement called on unbound " << elementParserName() << " object for element <" << node << "> at " << getDocumentLocation()); 42 | m_documentParser.removeCurrentElementParser(this); 43 | return true; 44 | } 45 | 46 | if (m_boundElement == node) { 47 | m_documentParser.removeCurrentElementParser(this); 48 | return parseElementEndTag(node, characters); 49 | } else { 50 | return parseChildElementEndTag(node, characters); 51 | } 52 | } 53 | 54 | CityGMLElementParser::~CityGMLElementParser() 55 | { 56 | 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /sources/src/parser/delayedchoiceelementparser.cpp: -------------------------------------------------------------------------------- 1 | #include "parser/delayedchoiceelementparser.h" 2 | 3 | #include "parser/documentlocation.h" 4 | #include "parser/citygmldocumentparser.h" 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace citygml { 12 | 13 | DelayedChoiceElementParser::DelayedChoiceElementParser(CityGMLDocumentParser& documentParser, std::shared_ptr logger, std::vector choices) 14 | : ElementParser(documentParser, logger) 15 | { 16 | m_choices = choices; 17 | } 18 | 19 | bool DelayedChoiceElementParser::startElement(const NodeType::XMLNode& node, Attributes& attributes) 20 | { 21 | ElementParser* choosenParser = nullptr; 22 | for (ElementParser* parser : m_choices) { 23 | 24 | if (choosenParser == nullptr && parser->handlesElement(node)) { 25 | choosenParser = parser; 26 | } else { 27 | delete parser; 28 | } 29 | 30 | } 31 | 32 | if (choosenParser != nullptr) { 33 | m_documentParser.removeCurrentElementParser(this); 34 | m_documentParser.setCurrentElementParser(choosenParser); 35 | return choosenParser->startElement(node, attributes); 36 | } else { 37 | CITYGML_LOG_ERROR(m_logger, "DelayedChoiceElementParser could not find a parser to handle <" << node << "> at " << getDocumentLocation()); 38 | throw std::runtime_error("No parser for XML element found."); 39 | } 40 | } 41 | 42 | bool DelayedChoiceElementParser::endElement(const NodeType::XMLNode&, const std::string&) 43 | { 44 | throw std::runtime_error("DelayedChoiceElementParser::endElement must never be called."); 45 | } 46 | 47 | bool DelayedChoiceElementParser::handlesElement(const NodeType::XMLNode& node) const 48 | { 49 | for (const ElementParser* parser : m_choices) { 50 | if (parser->handlesElement(node)) { 51 | return true; 52 | } 53 | } 54 | return false; 55 | } 56 | 57 | std::string DelayedChoiceElementParser::elementParserName() const 58 | { 59 | std::stringstream ss; 60 | ss << "DelayedChoiceElementParser ("; 61 | for (size_t i = 0; i < m_choices.size(); i++) { 62 | 63 | if (i > 0) { 64 | ss << " | "; 65 | } 66 | 67 | ss << m_choices[i]->elementParserName(); 68 | } 69 | 70 | ss << ")"; 71 | return ss.str(); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /sources/src/parser/elementparser.cpp: -------------------------------------------------------------------------------- 1 | #include "parser/elementparser.h" 2 | 3 | #include "parser/citygmldocumentparser.h" 4 | 5 | namespace citygml { 6 | 7 | void ElementParser::setParserForNextElement(ElementParser* parser) 8 | { 9 | m_documentParser.setCurrentElementParser(parser); 10 | } 11 | 12 | const DocumentLocation& ElementParser::getDocumentLocation() const 13 | { 14 | return m_documentParser.getDocumentLocation(); 15 | } 16 | 17 | ElementParser::~ElementParser() 18 | { 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /sources/src/parser/externalreferenceparser.cpp: -------------------------------------------------------------------------------- 1 | #include "parser/externalreferenceparser.h" 2 | 3 | #include "parser/attributes.h" 4 | #include "parser/documentlocation.h" 5 | #include "parser/nodetypes.h" 6 | #include 7 | #include 8 | 9 | namespace citygml { 10 | ExternalReferenceParser::ExternalReferenceParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, std::function callback) 11 | : GMLObjectElementParser(documentParser, factory, logger) { 12 | this->callback = callback; 13 | } 14 | 15 | std::string ExternalReferenceParser::elementParserName() const { 16 | return "ExternalReferenceParser"; 17 | } 18 | 19 | bool ExternalReferenceParser::handlesElement(NodeType::XMLNode const& node) const { 20 | return (node.typeID() == NodeType::CORE_ExternalReferenceNode.typeID() || node.typeID() == NodeType::CORE_InformationSystemNode.typeID()); 21 | } 22 | 23 | bool ExternalReferenceParser::parseElementStartTag(NodeType::XMLNode const& node, Attributes & attributes) { 24 | if (!handlesElement(node)) { 25 | CITYGML_LOG_ERROR(m_logger, "Expected start tag <" << NodeType::CORE_ExternalReferenceNode << "> but got <" << node.name() << "> at " << getDocumentLocation()); 26 | } 27 | 28 | model.reset(m_factory.createExternalReference(attributes.getCityGMLIDAttribute())); 29 | 30 | return true; 31 | } 32 | 33 | bool ExternalReferenceParser::parseElementEndTag(NodeType::XMLNode const& node, std::string const&) { 34 | callback(model.release()); 35 | return true; 36 | } 37 | 38 | bool ExternalReferenceParser::parseChildElementStartTag(NodeType::XMLNode const& node, Attributes & attributes) { 39 | if (model == nullptr) { 40 | throw std::runtime_error("ExternalReferenceParser::parseChildElementStartTag called before ExternalReferenceParser::parseElementStartTag"); 41 | } 42 | 43 | if (node == NodeType::CORE_ExternalObjectNode 44 | || node == NodeType::CORE_InformationSystemNode 45 | || node == NodeType::CORE_NameNode 46 | || node == NodeType::CORE_UriNode) { 47 | return true; 48 | } 49 | 50 | return GMLObjectElementParser::parseChildElementStartTag(node, attributes); 51 | } 52 | 53 | bool ExternalReferenceParser::parseChildElementEndTag(NodeType::XMLNode const& node, std::string const& characters) { 54 | if (model == nullptr) { 55 | throw std::runtime_error("ExternalReferenceParser::parseChildElementEndTag called before ExternalReferenceParser::parseElementStartTag"); 56 | } 57 | 58 | if (node == NodeType::CORE_ExternalObjectNode) { 59 | return true; 60 | } else if (node == NodeType::CORE_InformationSystemNode) { 61 | model->informationSystem = characters; 62 | } else if (node == NodeType::CORE_NameNode) { 63 | model->externalObject.setName(characters); 64 | } else if (node == NodeType::CORE_UriNode) { 65 | model->externalObject.setUri(characters); 66 | } 67 | 68 | return GMLObjectElementParser::parseChildElementEndTag(node, characters); 69 | } 70 | 71 | Object * ExternalReferenceParser::getObject() { 72 | return model.get(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /sources/src/parser/georeferencedtextureelementparser.cpp: -------------------------------------------------------------------------------- 1 | #include "parser/georeferencedtextureelementparser.h" 2 | 3 | #include 4 | 5 | #include "parser/nodetypes.h" 6 | #include "parser/attributes.h" 7 | #include "parser/documentlocation.h" 8 | #include "parser/skipelementparser.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace citygml { 17 | 18 | GeoReferencedTextureElementParser::GeoReferencedTextureElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, 19 | std::function)> callback) 20 | : CityGMLElementParser(documentParser, factory, logger) 21 | { 22 | m_callback = callback; 23 | } 24 | 25 | std::string GeoReferencedTextureElementParser::elementParserName() const 26 | { 27 | return "GeoReferencedTextureElementParser"; 28 | } 29 | 30 | bool GeoReferencedTextureElementParser::handlesElement(const NodeType::XMLNode& node) const 31 | { 32 | return node == NodeType::APP_GeoreferencedTextureNode; 33 | } 34 | 35 | bool GeoReferencedTextureElementParser::parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) 36 | { 37 | if (node != NodeType::APP_GeoreferencedTextureNode) { 38 | CITYGML_LOG_ERROR(m_logger, "Expected start tag <" << NodeType::APP_GeoreferencedTextureNode.name() << "> got " << node << " at " << getDocumentLocation()); 39 | throw std::runtime_error("Unexpected start tag found."); 40 | } 41 | 42 | CITYGML_LOG_WARN(m_logger, "Skipping contents of GeoReferencedTextureElement at " << getDocumentLocation() << ". (Currently not supported!)"); 43 | 44 | return true; 45 | } 46 | 47 | bool GeoReferencedTextureElementParser::parseElementEndTag(const NodeType::XMLNode&, const std::string&) 48 | { 49 | // Not Implemented 50 | return true; 51 | } 52 | 53 | bool GeoReferencedTextureElementParser::parseChildElementStartTag(const NodeType::XMLNode&, Attributes&) 54 | { 55 | setParserForNextElement(new SkipElementParser(m_documentParser, m_logger)); 56 | return true; 57 | } 58 | 59 | bool GeoReferencedTextureElementParser::parseChildElementEndTag(const NodeType::XMLNode&, const std::string&) 60 | { 61 | setParserForNextElement(new SkipElementParser(m_documentParser, m_logger)); 62 | return true; 63 | } 64 | 65 | 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /sources/src/parser/gmlfeaturecollectionparser.cpp: -------------------------------------------------------------------------------- 1 | #include "parser/gmlfeaturecollectionparser.h" 2 | 3 | #include "parser/attributes.h" 4 | #include "parser/citygmldocumentparser.h" 5 | #include "parser/parserutils.hpp" 6 | #include "parser/nodetypes.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | #include 16 | 17 | namespace citygml { 18 | 19 | GMLFeatureCollectionElementParser::GMLFeatureCollectionElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger) 20 | : GMLObjectElementParser(documentParser, factory, logger) 21 | { 22 | m_bounds = nullptr; 23 | m_sourceSRSOverride = false; 24 | std::string paramsSrcSRS = documentParser.getParserParams().srcSRS; 25 | if (!paramsSrcSRS.empty()) { 26 | m_bounds = new Envelope(paramsSrcSRS); 27 | m_sourceSRSOverride = true; 28 | } 29 | } 30 | 31 | bool GMLFeatureCollectionElementParser::parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) 32 | { 33 | if (getFeatureObject() == nullptr) { 34 | throw std::runtime_error("Invalid call to GMLFeatureCollectionElementParser::parseChildElementStartTag"); 35 | } 36 | 37 | if (node == NodeType::GML_LowerCornerNode 38 | || node == NodeType::GML_UpperCornerNode 39 | || node == NodeType::GML_BoundedByNode) { 40 | return true; 41 | } else if (node == NodeType::GML_EnvelopeNode) { 42 | 43 | if (m_sourceSRSOverride) { 44 | return true; 45 | } 46 | if (m_bounds != nullptr) { 47 | CITYGML_LOG_WARN(m_logger, "Duplicate definition of " << NodeType::GML_EnvelopeNode << " at " << getDocumentLocation()); 48 | return true; 49 | } 50 | m_bounds = new Envelope(attributes.getAttribute("srsName")); 51 | return true; 52 | } 53 | 54 | return GMLObjectElementParser::parseChildElementStartTag(node, attributes); 55 | } 56 | 57 | bool GMLFeatureCollectionElementParser::parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) 58 | { 59 | if (getFeatureObject() == nullptr) { 60 | throw std::runtime_error("Invalid call to GMLFeatureCollectionElementParser::parseChildElementEndTag"); 61 | } 62 | 63 | if (node == NodeType::GML_LowerCornerNode) { 64 | 65 | if (m_bounds != nullptr) { 66 | m_bounds->setLowerBound(parseValue(characters, m_logger, getDocumentLocation())); 67 | } else { 68 | CITYGML_LOG_WARN(m_logger, "Definition of " << NodeType::GML_LowerCornerNode << " outside " << NodeType::GML_EnvelopeNode << " at " << getDocumentLocation()); 69 | } 70 | return true; 71 | } else if (node == NodeType::GML_UpperCornerNode) { 72 | 73 | if (m_bounds != nullptr) { 74 | m_bounds->setUpperBound(parseValue(characters, m_logger, getDocumentLocation())); 75 | } else { 76 | CITYGML_LOG_WARN(m_logger, "Definition of " << NodeType::GML_UpperCornerNode << " outside " << NodeType::GML_EnvelopeNode << " at " << getDocumentLocation()); 77 | } 78 | return true; 79 | } else if (node == NodeType::GML_EnvelopeNode) { 80 | 81 | getFeatureObject()->setEnvelope(m_bounds); 82 | return true; 83 | } else if (node == NodeType::GML_BoundedByNode) { 84 | 85 | return true; 86 | } 87 | 88 | return GMLObjectElementParser::parseChildElementEndTag(node, characters); 89 | } 90 | 91 | Object* GMLFeatureCollectionElementParser::getObject() 92 | { 93 | return getFeatureObject(); 94 | } 95 | 96 | const Envelope& GMLFeatureCollectionElementParser::getEnvelope() const 97 | { 98 | return *m_bounds; 99 | } 100 | 101 | bool GMLFeatureCollectionElementParser::getSourceSRSOverride() const 102 | { 103 | return m_sourceSRSOverride; 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /sources/src/parser/gmlobjectparser.cpp: -------------------------------------------------------------------------------- 1 | #include "parser/gmlobjectparser.h" 2 | 3 | #include 4 | 5 | namespace citygml { 6 | 7 | GMLObjectElementParser::GMLObjectElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger) 8 | : CityGMLElementParser(documentParser, factory, logger) 9 | { 10 | 11 | } 12 | 13 | bool GMLObjectElementParser::parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) 14 | { 15 | if (getObject() == nullptr) { 16 | throw std::runtime_error("Invalid call to GMLObjectElementParser::parseChildElementStartTag"); 17 | } 18 | 19 | if ( node == NodeType::GML_DescriptionNode 20 | || node == NodeType::GML_IdentifierNode 21 | || node == NodeType::GML_NameNode 22 | || node == NodeType::GML_DescriptionReferenceNode 23 | || node == NodeType::GML_MetaDataPropertyNode) { 24 | 25 | return true; 26 | } 27 | 28 | return false; 29 | } 30 | 31 | bool GMLObjectElementParser::parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) 32 | { 33 | if (getObject() == nullptr) { 34 | throw std::runtime_error("Invalid call to GMLObjectElementParser::parseChildElementEndTag"); 35 | } 36 | 37 | if ( node == NodeType::GML_DescriptionNode 38 | || node == NodeType::GML_IdentifierNode 39 | || node == NodeType::GML_NameNode 40 | || node == NodeType::GML_DescriptionReferenceNode 41 | || node == NodeType::GML_MetaDataPropertyNode) { 42 | 43 | getObject()->setAttribute(node.name(), characters); 44 | return true; 45 | } 46 | 47 | return false; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /sources/src/parser/linearringelementparser.cpp: -------------------------------------------------------------------------------- 1 | #include "parser/linearringelementparser.h" 2 | 3 | #include 4 | 5 | #include "parser/nodetypes.h" 6 | #include "parser/attributes.h" 7 | #include "parser/documentlocation.h" 8 | #include "parser/parserutils.hpp" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace citygml { 17 | 18 | LinearRingElementParser::LinearRingElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, bool interior, std::function callback) 19 | : GMLObjectElementParser(documentParser, factory, logger) 20 | { 21 | m_callback = callback; 22 | m_interior = interior; 23 | } 24 | 25 | std::string LinearRingElementParser::elementParserName() const 26 | { 27 | return "LinearRingElementParser"; 28 | } 29 | 30 | bool LinearRingElementParser::handlesElement(const NodeType::XMLNode& node) const 31 | { 32 | return node == NodeType::GML_LinearRingNode; 33 | } 34 | 35 | bool LinearRingElementParser::parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) 36 | { 37 | 38 | if (!handlesElement(node)) { 39 | CITYGML_LOG_ERROR(m_logger, "Expected start tag <" << NodeType::GML_LinearRingNode << "> but got <" << node << "> at " << getDocumentLocation()); 40 | throw std::runtime_error("Unexpected start tag found."); 41 | } 42 | 43 | m_model = new LinearRing(attributes.getCityGMLIDAttribute(), !m_interior); 44 | return true; 45 | 46 | } 47 | 48 | bool LinearRingElementParser::parseElementEndTag(const NodeType::XMLNode&, const std::string&) 49 | { 50 | if (m_model->getVertices().size() < 4) { 51 | CITYGML_LOG_WARN(m_logger, "LinearRing with end tag at " << getDocumentLocation() << " contains less than 4 vertices."); 52 | } 53 | m_callback(m_model); 54 | return true; 55 | } 56 | 57 | 58 | 59 | bool LinearRingElementParser::parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) 60 | { 61 | if (m_model == nullptr) { 62 | throw std::runtime_error("LinearRingElementParser::parseChildElementStartTag called before LinearRingElementParser::parseElementStartTag"); 63 | } 64 | 65 | if (node == NodeType::GML_PosListNode || node == NodeType::GML_PosNode) { 66 | std::string dimensions = attributes.getAttribute("srsDimension", "3"); 67 | if (dimensions != "3") { 68 | CITYGML_LOG_WARN(m_logger, "Attribute srsDimension of element " << node << " contains unsupported value '" << dimensions << "' (only 3 dimensions are support). Trying to parse it anyway..."); 69 | } 70 | return true; 71 | } 72 | 73 | return GMLObjectElementParser::parseChildElementStartTag(node, attributes); 74 | } 75 | 76 | bool LinearRingElementParser::parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) 77 | { 78 | 79 | if (m_model == nullptr) { 80 | throw std::runtime_error("LinearRingElementParser::parseChildElementEndTag called before LinearRingElementParser::parseElementStartTag"); 81 | } 82 | 83 | if (node == NodeType::GML_PosListNode) { 84 | m_model->setVertices(parseVecList(characters, m_logger, getDocumentLocation())); 85 | return true; 86 | } else if (node == NodeType::GML_PosNode) { 87 | m_model->addVertex(parseValue(characters, m_logger, getDocumentLocation())); 88 | return true; 89 | } 90 | 91 | return GMLObjectElementParser::parseChildElementEndTag(node, characters); 92 | 93 | } 94 | 95 | Object* LinearRingElementParser::getObject() 96 | { 97 | return m_model; 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /sources/src/parser/linestringelementparser.cpp: -------------------------------------------------------------------------------- 1 | #include "parser/linestringelementparser.h" 2 | 3 | #include 4 | 5 | #include "parser/nodetypes.h" 6 | #include "parser/attributes.h" 7 | #include "parser/documentlocation.h" 8 | #include "parser/parserutils.hpp" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace citygml { 18 | 19 | LineStringElementParser::LineStringElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, std::function)> callback) 20 | : GMLObjectElementParser(documentParser, factory, logger) 21 | { 22 | m_callback = callback; 23 | } 24 | 25 | std::string LineStringElementParser::elementParserName() const 26 | { 27 | return "LineStringElementParser"; 28 | } 29 | 30 | bool LineStringElementParser::handlesElement(const NodeType::XMLNode& node) const 31 | { 32 | return node == NodeType::GML_LineStringNode || node == NodeType::GML_PointNode; 33 | } 34 | 35 | bool LineStringElementParser::parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) 36 | { 37 | 38 | if (!handlesElement(node)) { 39 | CITYGML_LOG_ERROR(m_logger, "Expected start tag <" << NodeType::GML_LineStringNode << "> or <" << NodeType::GML_PointNode << "> but got <" << node.name() << "> at " << getDocumentLocation()); 40 | throw std::runtime_error("Unexpected start tag found."); 41 | } 42 | 43 | m_model = m_factory.createLineString(attributes.getCityGMLIDAttribute()); 44 | 45 | parseDimension(attributes); 46 | 47 | return true; 48 | 49 | } 50 | 51 | bool LineStringElementParser::parseElementEndTag(const NodeType::XMLNode&, const std::string&) 52 | { 53 | m_callback(m_model); 54 | return true; 55 | } 56 | 57 | bool LineStringElementParser::parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) 58 | { 59 | if (m_model == nullptr) { 60 | throw std::runtime_error("LineStringElementParser::parseChildElementStartTag called before LineStringElementParser::parseElementStartTag"); 61 | } 62 | 63 | if (node == NodeType::GML_PosListNode 64 | || node == NodeType::GML_PosNode) { 65 | parseDimension(attributes); 66 | return true; 67 | } 68 | 69 | return GMLObjectElementParser::parseChildElementStartTag(node, attributes); 70 | } 71 | 72 | bool LineStringElementParser::parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) 73 | { 74 | 75 | if (m_model == nullptr) { 76 | throw std::runtime_error("LineStringElementParser::parseChildElementEndTag called before LineStringElementParser::parseElementStartTag"); 77 | } 78 | 79 | if (node == NodeType::GML_PosListNode 80 | || node == NodeType::GML_PosNode) { 81 | 82 | if (m_model->getDimensions() < 0) { 83 | CITYGML_LOG_ERROR(m_logger, "No srsDimension given for LineString before or as attribute of <" << NodeType::GML_PosListNode << "> child element at " << getDocumentLocation()); 84 | } else if (m_model->getDimensions() == 2) { 85 | m_model->setVertices2D(parseVecList(characters, m_logger, getDocumentLocation())); 86 | } else if (m_model->getDimensions() == 3) { 87 | m_model->setVertices3D(parseVecList(characters, m_logger, getDocumentLocation())); 88 | } else { 89 | CITYGML_LOG_WARN(m_logger, "Unsupported dimension of LineString positions at " << getDocumentLocation() << ". Only 2 and 3 dimensions are supported."); 90 | } 91 | 92 | return true; 93 | } 94 | 95 | return GMLObjectElementParser::parseChildElementEndTag(node, characters); 96 | 97 | } 98 | 99 | Object* LineStringElementParser::getObject() 100 | { 101 | return m_model.get(); 102 | } 103 | 104 | void LineStringElementParser::parseDimension(Attributes& attributes) 105 | { 106 | std::string dim_str = attributes.getAttribute("srsDimension", ""); 107 | 108 | if (dim_str.empty()) { 109 | return; 110 | } 111 | 112 | int dim = std::stoi(dim_str); 113 | m_model->setDimensions(dim); 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /sources/src/parser/polygonelementparser.cpp: -------------------------------------------------------------------------------- 1 | #include "parser/polygonelementparser.h" 2 | 3 | #include 4 | 5 | #include "parser/nodetypes.h" 6 | #include "parser/attributes.h" 7 | #include "parser/documentlocation.h" 8 | #include "parser/linearringelementparser.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace citygml { 18 | 19 | 20 | // The nodes that are valid Polygon Objects 21 | std::unordered_set typeIDSet; 22 | bool typeIDSetInitialized = false; 23 | std::mutex polygonElementParser_initializedTypeIDMutex; 24 | 25 | PolygonElementParser::PolygonElementParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, std::function)> callback) 26 | : GMLObjectElementParser(documentParser, factory, logger) 27 | { 28 | m_callback = callback; 29 | } 30 | 31 | std::string PolygonElementParser::elementParserName() const 32 | { 33 | return "PolygonElementParser"; 34 | } 35 | 36 | bool PolygonElementParser::handlesElement(const NodeType::XMLNode& node) const 37 | { 38 | if (!typeIDSetInitialized) { 39 | std::lock_guard lock(polygonElementParser_initializedTypeIDMutex); 40 | 41 | if(!typeIDSetInitialized) { 42 | typeIDSet.insert(NodeType::GML_TriangleNode.typeID()); 43 | typeIDSet.insert(NodeType::GML_RectangleNode.typeID()); 44 | typeIDSet.insert(NodeType::GML_PolygonNode.typeID()); 45 | typeIDSet.insert(NodeType::GML_PolygonPatchNode.typeID()); 46 | typeIDSetInitialized = true; 47 | } 48 | } 49 | 50 | return typeIDSet.count(node.typeID()) > 0; 51 | } 52 | 53 | bool PolygonElementParser::parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) 54 | { 55 | 56 | if (!handlesElement(node)) { 57 | CITYGML_LOG_ERROR(m_logger, "Expected start tag of PolygonObject but got <" << node.name() << "> at " << getDocumentLocation()); 58 | throw std::runtime_error("Unexpected start tag found."); 59 | } 60 | 61 | m_model = m_factory.createPolygon(attributes.getCityGMLIDAttribute()); 62 | return true; 63 | 64 | } 65 | 66 | bool PolygonElementParser::parseElementEndTag(const NodeType::XMLNode&, const std::string&) 67 | { 68 | m_callback(m_model); 69 | return true; 70 | } 71 | 72 | 73 | 74 | bool PolygonElementParser::parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) 75 | { 76 | if (m_model == nullptr) { 77 | throw std::runtime_error("PolygonElementParser::parseChildElementStartTag called before PolygonElementParser::parseElementStartTag"); 78 | } 79 | 80 | if (node == NodeType::GML_InteriorNode) { 81 | 82 | parseRingElement(true); 83 | return true; 84 | } else if (node == NodeType::GML_ExteriorNode) { 85 | 86 | parseRingElement(false); 87 | return true; 88 | } 89 | 90 | return GMLObjectElementParser::parseChildElementStartTag(node, attributes); 91 | } 92 | 93 | bool PolygonElementParser::parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) 94 | { 95 | 96 | if (m_model == nullptr) { 97 | throw std::runtime_error("PolygonElementParser::parseChildElementEndTag called before PolygonElementParser::parseElementStartTag"); 98 | } 99 | 100 | if (node == NodeType::GML_InteriorNode || node == NodeType::GML_ExteriorNode) { 101 | 102 | return true; 103 | } 104 | 105 | return GMLObjectElementParser::parseChildElementEndTag(node, characters); 106 | 107 | } 108 | 109 | Object* PolygonElementParser::getObject() 110 | { 111 | return m_model.get(); 112 | } 113 | 114 | void PolygonElementParser::parseRingElement(bool interior) 115 | { 116 | setParserForNextElement(new LinearRingElementParser(m_documentParser, m_factory, m_logger, interior, [this](LinearRing* ring){ 117 | m_model->addRing(ring); 118 | })); 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /sources/src/parser/rectifiedgridcoverageparser.cpp: -------------------------------------------------------------------------------- 1 | #include "parser/rectifiedgridcoverageparser.h" 2 | 3 | #include "parser/nodetypes.h" 4 | #include "parser/attributes.h" 5 | #include "parser/documentlocation.h" 6 | #include "parser/cityobjectelementparser.h" 7 | #include "parser/appearanceelementparser.h" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace citygml { 17 | RectifiedGridCoverageParser::RectifiedGridCoverageParser(CityGMLDocumentParser& documentParser, CityGMLFactory& factory, std::shared_ptr logger, std::function callback) 18 | : GMLFeatureCollectionElementParser(documentParser, factory, logger) 19 | { 20 | m_callback = callback; 21 | m_model = nullptr; 22 | } 23 | 24 | bool RectifiedGridCoverageParser::handlesElement(const NodeType::XMLNode& node) const 25 | { 26 | return node == NodeType::GML_RectifiedGridCoverageNode; 27 | } 28 | 29 | std::string RectifiedGridCoverageParser::elementParserName() const 30 | { 31 | return "RectifiedGridCoverageParser"; 32 | } 33 | 34 | bool RectifiedGridCoverageParser::parseElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) 35 | { 36 | if (node != NodeType::GML_RectifiedGridCoverageNode) { 37 | CITYGML_LOG_ERROR(m_logger, "Expected start tag <" << NodeType::CORE_CityModelNode.name() << "> got <" << node.name() << "> at " << getDocumentLocation()); 38 | throw std::runtime_error("Unexpected start tag found."); 39 | } 40 | 41 | m_model = m_factory.createRectifiedGridCoverage(attributes.getCityGMLIDAttribute()); 42 | return true; 43 | } 44 | 45 | bool RectifiedGridCoverageParser::parseElementEndTag(const NodeType::XMLNode& node, const std::string&) 46 | { 47 | if (node != NodeType::GML_RectifiedGridCoverageNode) { 48 | CITYGML_LOG_WARN(m_logger, "Expected end tag <" << NodeType::CORE_CityModelNode.name() << "> got <" << node.name() << "> at " << getDocumentLocation()); 49 | } 50 | 51 | if (getSourceSRSOverride()) { 52 | Envelope *envelope = new Envelope(getEnvelope().srsName()); 53 | envelope->setLowerBound(m_model->getEnvelope().getLowerBound()); 54 | envelope->setUpperBound(m_model->getEnvelope().getUpperBound()); 55 | m_model->setEnvelope(envelope); 56 | } 57 | m_callback(m_model); 58 | return true; 59 | } 60 | 61 | 62 | bool RectifiedGridCoverageParser::parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes) 63 | { 64 | if (m_model == nullptr) { 65 | throw std::runtime_error("RectifiedGridCoverage::parseChildElementStartTag called before RectifiedGridCoverage::parseElementStartTag"); 66 | } 67 | 68 | return GMLObjectElementParser::parseChildElementStartTag(node, attributes); 69 | } 70 | 71 | bool RectifiedGridCoverageParser::parseChildElementEndTag(const NodeType::XMLNode& node, const std::string& characters) 72 | { 73 | 74 | if (m_model == nullptr) { 75 | throw std::runtime_error("RectifiedGridCoverage::parseChildElementEndTag called before RectifiedGridCoverage::parseElementStartTag"); 76 | } 77 | 78 | return GMLObjectElementParser::parseChildElementEndTag(node, characters); 79 | } 80 | 81 | FeatureObject* RectifiedGridCoverageParser::getFeatureObject() 82 | { 83 | return m_model; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /sources/src/parser/sequenceparser.cpp: -------------------------------------------------------------------------------- 1 | #include "parser/sequenceparser.h" 2 | 3 | #include 4 | #include "parser/documentlocation.h" 5 | #include "parser/citygmldocumentparser.h" 6 | 7 | namespace citygml { 8 | 9 | SequenceParser::SequenceParser(CityGMLDocumentParser& documentParser, std::shared_ptr logger, std::function childParserFactory, const NodeType::XMLNode& parentElement) 10 | : ElementParser(documentParser, logger) 11 | { 12 | m_childParserFactory = childParserFactory; 13 | m_containerType = parentElement; 14 | m_childParserInstance = nullptr; 15 | } 16 | 17 | bool SequenceParser::startElement(const NodeType::XMLNode& node, Attributes& attributes) 18 | { 19 | // Note that at this point the start tag of the parent element has already been parsed... hence node must be a child element 20 | ElementParser* childParser = m_childParserFactory(); 21 | setParserForNextElement(childParser); 22 | return childParser->startElement(node, attributes); 23 | } 24 | 25 | bool SequenceParser::endElement(const NodeType::XMLNode& node, const std::string&) 26 | { 27 | if (node != m_containerType) { 28 | CITYGML_LOG_ERROR(m_logger, "Sequence parser was bound to container element <" << m_containerType << "> but found unexpected" 29 | " end tag <" << node << "> at " << getDocumentLocation() << ". Ignoring tag..."); 30 | return false; 31 | 32 | } else { 33 | m_documentParser.removeCurrentElementParser(this); 34 | } 35 | 36 | return true; 37 | } 38 | 39 | bool SequenceParser::handlesElement(const NodeType::XMLNode& node) const 40 | { 41 | return getChildParserDummyInstance().handlesElement(node); 42 | } 43 | 44 | std::string SequenceParser::elementParserName() const 45 | { 46 | return "SequenceParser (" + getChildParserDummyInstance().elementParserName() + ")"; 47 | } 48 | 49 | ElementParser& SequenceParser::getChildParserDummyInstance() const 50 | { 51 | // Lazy initialize the dummy object (its only used for logging and error reporting) 52 | if (m_childParserInstance == nullptr) { 53 | m_childParserInstance = std::unique_ptr(m_childParserFactory()); 54 | } 55 | return *m_childParserInstance; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /sources/src/parser/skipelementparser.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | namespace citygml { 8 | 9 | SkipElementParser::SkipElementParser(CityGMLDocumentParser& documentParser, std::shared_ptr logger, const NodeType::XMLNode& skipNode) 10 | : ElementParser(documentParser, logger) 11 | { 12 | m_skipNode = skipNode; 13 | if (skipNode.valid()) { 14 | m_depth = 1; 15 | } 16 | } 17 | 18 | std::string SkipElementParser::elementParserName() const 19 | { 20 | return "SkipElementParser"; 21 | } 22 | 23 | bool SkipElementParser::handlesElement(const NodeType::XMLNode&) const 24 | { 25 | return true; 26 | } 27 | 28 | bool SkipElementParser::startElement(const NodeType::XMLNode& node, Attributes&) 29 | { 30 | if (!m_skipNode.valid()) { 31 | CITYGML_LOG_TRACE(m_logger, "Skipping element <" << node << "> at " << getDocumentLocation()); 32 | m_skipNode = node; 33 | m_depth = 1; 34 | } else if (node == m_skipNode) { 35 | m_depth++; 36 | } 37 | 38 | return true; 39 | } 40 | 41 | bool SkipElementParser::endElement(const NodeType::XMLNode& node, const std::string&) 42 | { 43 | if (!m_skipNode.valid()) { 44 | m_documentParser.removeCurrentElementParser(this); 45 | } else if (node == m_skipNode) { 46 | m_depth--; 47 | 48 | if (m_depth == 0) { 49 | m_documentParser.removeCurrentElementParser(this); 50 | } 51 | } 52 | 53 | return true; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /systemTests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(FetchContent) 2 | 3 | if (NOT ${LIBCITYGML_STATIC_CRT}) 4 | set(gtest_force_shared_crt ON) 5 | endif() 6 | 7 | set(BUILD_GMOCK OFF) 8 | 9 | FetchContent_Declare( 10 | gtest 11 | GIT_REPOSITORY https://github.com/google/googletest.git 12 | GIT_TAG v1.15.2) 13 | FetchContent_MakeAvailable(gtest) 14 | 15 | add_executable(citygmlSystemTests 16 | systemTestsMain.cpp 17 | FileReadTests.cpp 18 | ) 19 | 20 | target_include_directories(citygmlSystemTests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../sources/include) 21 | 22 | target_link_libraries(citygmlSystemTests PRIVATE citygml gtest) 23 | 24 | install(TARGETS citygmlSystemTests RUNTIME DESTINATION ${BIN_INSTALL_DIR}) 25 | -------------------------------------------------------------------------------- /systemTests/systemTestsMain.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "gtest/gtest.h" 3 | 4 | 5 | int main(int argc, char **argv) { 6 | ::testing::InitGoogleTest(&argc, argv); 7 | return RUN_ALL_TESTS(); 8 | } 9 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | IF(WIN32) 2 | SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:MSVCRT") 3 | ENDIF() 4 | 5 | IF( LIBCITYGML_USE_OPENGL) 6 | FIND_PACKAGE( OpenGL REQUIRED ) 7 | ENDIF( LIBCITYGML_USE_OPENGL ) 8 | FIND_PACKAGE( XercesC ) 9 | IF( NOT XercesC_FOUND ) 10 | FIND_PACKAGE( Xerces REQUIRED ) 11 | ENDIF( NOT XercesC_FOUND) 12 | 13 | IF( LIBCITYGML_DYNAMIC ) 14 | ADD_DEFINITIONS( -DLIBCITYGML_DYNAMIC ) 15 | ELSE( LIBCITYGML_DYNAMIC ) 16 | ADD_DEFINITIONS( -DLIBCITYGML_STATIC ) 17 | ENDIF( LIBCITYGML_DYNAMIC ) 18 | 19 | # INCLUDE_DIRECTORIES( ${CITYGML_INCLUDE_DIR} ) 20 | INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../sources/include ${CMAKE_BINARY_DIR}/sources/include) 21 | 22 | SET( PRG_SRCS citygmltest.cpp ) 23 | 24 | ADD_EXECUTABLE( citygmltest ${PRG_SRCS} ) 25 | 26 | IF( XercesC_FOUND ) 27 | TARGET_LINK_LIBRARIES( citygmltest citygml XercesC::XercesC) 28 | ELSE( XercesC_FOUND ) 29 | TARGET_LINK_LIBRARIES( citygmltest citygml ${XERCESC_LIBRARY} ) 30 | ENDIF( XercesC_FOUND ) 31 | IF(LIBCITYGML_USE_OPENGL) 32 | TARGET_COMPILE_DEFINITIONS( citygmltest PUBLIC LIBCITYGML_USE_OPENGL) 33 | TARGET_LINK_LIBRARIES( citygmltest citygml ${OPENGL_LIBRARIES} ) 34 | ENDIF(LIBCITYGML_USE_OPENGL) 35 | 36 | install(TARGETS citygmltest RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 37 | 38 | 39 | add_test(NAME System_Tests COMMAND citygmlSystemTests) 40 | add_test(NAME berlin_open_data_sample_data COMMAND citygmltest ../../data/berlin_open_data_sample_data.citygml) 41 | add_test(NAME b1_lod2_s COMMAND citygmltest ../../data/b1_lod2_s.gml) 42 | add_test(NAME FZK-Haus-LoD0-KIT-IAI-KHH-B36-V1 COMMAND citygmltest ../../data/FZK-Haus-LoD0-KIT-IAI-KHH-B36-V1.gml) --------------------------------------------------------------------------------