Skip to content

Commit

Permalink
Merge pull request #74 from topheg/make_opengl_optional
Browse files Browse the repository at this point in the history
Make opengl optional
  • Loading branch information
jklimke authored Feb 14, 2023
2 parents d2b327f + b414dc7 commit 9b72e39
Show file tree
Hide file tree
Showing 22 changed files with 354 additions and 184 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ IF( MSVC AND LIBCITYGML_STATIC_CRT )
ENDFOREACH( flag_var )
ENDIF( MSVC AND LIBCITYGML_STATIC_CRT )


OPTION(LIBCITYGML_USE_OPENGL "Set to OFF to prevent use of GL libraries. Tesselator won't be compiled." ON)

# core
ADD_SUBDIRECTORY( sources )

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ Dependencies:

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.

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.

GDAL is required if coordinate transformations should be applied during paring.
Set the cmake option "LIBCITYGML_USE_GDAL" to OFF to disable the use of GDAL.

OpenSceneGraph is required for building the plugin.
OpenSceneGraph is required to build the plugin.
Set the cmake option "LIBCITYGML_OSGPLUGIN" to ON to enable the build of the plugin.

Test Data Attribution
=====================
Expand Down
40 changes: 33 additions & 7 deletions sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ ENDIF (NOT DEFINED CMAKE_MODULE_PATH)

SET( target citygml )

FIND_PACKAGE( OpenGL REQUIRED )
IF( LIBCITYGML_USE_OPENGL)
FIND_PACKAGE( OpenGL REQUIRED )
ELSE( LIBCITYGML_USE_OPENGL )
SET( GLU_INCLUDE_PATH "" )
ENDIF( LIBCITYGML_USE_OPENGL )
FIND_PACKAGE( Xerces REQUIRED )

# gdal library
Expand Down Expand Up @@ -53,7 +57,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include
SET(SOURCES
src/citygml/attributesmap.cpp
src/citygml/citymodel.cpp
src/citygml/tesselator.cpp
src/citygml/tesselatorbase.cpp
src/citygml/object.cpp
src/citygml/featureobject.cpp
src/citygml/appearance.cpp
Expand Down Expand Up @@ -112,9 +116,12 @@ SET(SOURCES
src/parser/implicitgeometryelementparser.cpp
src/parser/addressparser.cpp
)

if(UNIX)
if (APPLE)
set_source_files_properties(src/citygml/tesselator.cpp PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations") # for warnings: 'glu*' is deprecated...
if (LIBCITYGML_USE_OPENGL)
set_source_files_properties(src/citygml/tesselator.cpp PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations") # for warnings: 'glu*' is deprecated...
endif (LIBCITYGML_USE_OPENGL)
endif (APPLE)
endif(UNIX)

Expand All @@ -139,7 +146,7 @@ SET(PUBLIC_HEADER
include/citygml/citygml.h
include/citygml/transformmatrix.h
include/citygml/implictgeometry.h
include/citygml/tesselator.h
include/citygml/tesselatorbase.h
include/citygml/texture.h
include/citygml/appearancetargetdefinition.h
include/citygml/texturetargetdefinition.h
Expand All @@ -153,12 +160,24 @@ SET(PUBLIC_HEADER
include/citygml/externalreference.h
)


if(LIBCITYGML_USE_OPENGL)
SET(SOURCES
${SOURCES}
src/citygml/tesselator.cpp
)

SET(PUBLIC_HEADER
${PUBLIC_HEADER}
include/citygml/tesselator.h
)
endif(LIBCITYGML_USE_OPENGL)

SET(HEADERS
${PUBLIC_HEADER}

${CMAKE_MODULE_PATH}/citygml_api.h.in

include/citygml/tesselator.h
include/citygml/utils.h
include/citygml/appearancemanager.h
include/citygml/polygonmanager.h
Expand Down Expand Up @@ -205,7 +224,10 @@ generate_export_header(citygml
EXPORT_MACRO_NAME LIBCITYGML_EXPORT
EXPORT_FILE_NAME ${EXPORT_HEADER_FILE_NAME})

TARGET_LINK_LIBRARIES( ${target} PUBLIC ${XERCESC_LIBRARIES} ${OPENGL_LIBRARIES} )
TARGET_LINK_LIBRARIES( ${target} PUBLIC ${XERCESC_LIBRARIES} )
if(LIBCITYGML_USE_OPENGL)
TARGET_LINK_LIBRARIES( ${target} PUBLIC ${OPENGL_LIBRARIES} )
endif(LIBCITYGML_USE_OPENGL)
if(LIBCITYGML_USE_GDAL)
TARGET_LINK_LIBRARIES( ${target} PUBLIC ${GDAL_LIBRARY} )
endif(LIBCITYGML_USE_GDAL)
Expand Down Expand Up @@ -284,7 +306,11 @@ else()
set(LIBCITYGML_POSTFIX "")
endif()

set(PKG_CONFIG_REQUIRES "xerces-c glu")
set(PKG_CONFIG_REQUIRES "xerces-c")

if(LIBCITYGML_USE_OPENGL)
set(PKG_CONFIG_REQUIRES "${PKG_CONFIG_REQUIRES} glu")
endif(LIBCITYGML_USE_OPENGL)

if (LIBCITYGML_USE_GDAL)
set(PKG_CONFIG_REQUIRES "${PKG_CONFIG_REQUIRES} gdal")
Expand Down
2 changes: 0 additions & 2 deletions sources/include/citygml/appearancemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <citygml/object.h>
#include <citygml/vecs.hpp>

class Tesselator;

namespace citygml {

class CityGMLLogger;
Expand Down
8 changes: 3 additions & 5 deletions sources/include/citygml/citygml.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
#include <citygml/vecs.hpp>
#include <citygml/cityobject.h>
#include <citygml/envelope.h>


class Tesselator;
#include <citygml/tesselatorbase.h>

namespace citygml
{
Expand Down Expand Up @@ -88,8 +86,8 @@ namespace citygml
std::string srcSRS;
};

LIBCITYGML_EXPORT std::shared_ptr<const CityModel> load( std::istream& stream, const ParserParams& params, std::shared_ptr<CityGMLLogger> logger = nullptr);
LIBCITYGML_EXPORT std::shared_ptr<const CityModel> load( std::istream& stream, const ParserParams& params, std::unique_ptr<TesselatorBase> tesselator, std::shared_ptr<CityGMLLogger> logger = nullptr);

LIBCITYGML_EXPORT std::shared_ptr<const CityModel> load( const std::string& fileName, const ParserParams& params, std::shared_ptr<CityGMLLogger> logger = nullptr);
LIBCITYGML_EXPORT std::shared_ptr<const CityModel> load( const std::string& fileName, const ParserParams& params, std::unique_ptr<TesselatorBase> tesselator, std::shared_ptr<CityGMLLogger> logger = nullptr);

}
4 changes: 3 additions & 1 deletion sources/include/citygml/citymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <citygml/cityobject.h>
#include <citygml/featureobject.h>

class TesselatorBase;

namespace citygml {

class AppearanceManager;
Expand Down Expand Up @@ -39,7 +41,7 @@ namespace citygml {

const std::string& getSRSName() const;

void finish(Tesselator& tesselator, bool optimize, bool tesselate, std::shared_ptr<CityGMLLogger> logger);
void finish(TesselatorBase* tesselator, bool optimize, bool tesselate, std::shared_ptr<CityGMLLogger> logger);

std::vector<std::string> themes() const;
void setThemes(std::vector<std::string> themes);
Expand Down
4 changes: 2 additions & 2 deletions sources/include/citygml/cityobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <citygml/enum_type_bitmask.h>
#include <citygml/rectifiedgridcoverage.h>
#include <citygml/externalreference.h>
class Tesselator;
class TesselatorBase;

namespace citygml {

Expand Down Expand Up @@ -119,7 +119,7 @@ namespace citygml {
ExternalReference const* externalReference() const;
void setExternalReference(ExternalReference * externalReference);

void finish(Tesselator& tesselator, bool optimize, bool tesselate, std::shared_ptr<citygml::CityGMLLogger> logger);
void finish(TesselatorBase* tesselator, bool optimize, std::shared_ptr<citygml::CityGMLLogger> logger);

virtual ~CityObject();

Expand Down
4 changes: 2 additions & 2 deletions sources/include/citygml/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <citygml/citygml_api.h>
#include <citygml/appearancetarget.h>

class Tesselator;
class TesselatorBase;

namespace citygml {

Expand Down Expand Up @@ -73,7 +73,7 @@ namespace citygml {
* @param tesselator the tesselator to be used for tesselation
* @param mergePolygons determines wether all polygons are merged into one
*/
void finish(Tesselator& tesselator, bool optimize, bool tesselate, std::shared_ptr<CityGMLLogger> logger);
void finish(TesselatorBase* tesselator, bool optimize, std::shared_ptr<CityGMLLogger> logger);

~Geometry();

Expand Down
8 changes: 4 additions & 4 deletions sources/include/citygml/polygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <citygml/linearring.h>
#include <citygml/geometry.h>

class Tesselator;
class TesselatorBase;

namespace citygml {

Expand Down Expand Up @@ -82,7 +82,7 @@ namespace citygml {

void addRing( LinearRing* );

void finish(Tesselator& tesselator , bool optimize, bool tesselate, std::shared_ptr<CityGMLLogger> logger);
void finish(TesselatorBase* tesselator , bool optimize, std::shared_ptr<CityGMLLogger> logger);

std::shared_ptr<LinearRing> exteriorRing(){
return m_exteriorRing;
Expand Down Expand Up @@ -112,9 +112,9 @@ namespace citygml {
* @param tesselate if true the tesselator will be used to tesselate the linear rings
* @param tesselator the Tesselator object
*/
void computeIndices(Tesselator& tesselator, std::shared_ptr<CityGMLLogger> logger);
void computeIndices(TesselatorBase* tesselator, std::shared_ptr<CityGMLLogger> logger);
void createSimpleIndices(std::shared_ptr<CityGMLLogger> logger);
void createIndicesWithTesselation(Tesselator& tesselator, std::shared_ptr<CityGMLLogger> logger);
void createIndicesWithTesselation(TesselatorBase* tesselator, std::shared_ptr<CityGMLLogger> logger);
void removeDuplicateVerticesInRings(std::shared_ptr<CityGMLLogger> logger);
std::vector<TVec2f> getTexCoordsForRingAndTheme(const LinearRing& ring, const std::string& theme, bool front);
std::vector<std::vector<TVec2f> > getTexCoordListsForRing(const LinearRing& ring, const std::vector<std::string>& themesFront, const std::vector<std::string>& themesBack);
Expand Down
33 changes: 7 additions & 26 deletions sources/include/citygml/tesselator.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,30 @@
#endif

#include <citygml/citygml_api.h>
#include <citygml/tesselatorbase.h>
#include <citygml/vecs.hpp>
#include <vector>
#include <list>
#include <memory>

namespace citygml {
class CityGMLLogger;
}

// GLU based polygon tesselator
class LIBCITYGML_EXPORT Tesselator
class LIBCITYGML_EXPORT Tesselator: public TesselatorBase
{
public:
Tesselator( std::shared_ptr<citygml::CityGMLLogger> logger );
Tesselator( std::shared_ptr<citygml::CityGMLLogger> logger, GLenum winding_rule = GLU_TESS_WINDING_ODD);
~Tesselator();

void init(const TVec3d& normal, GLenum winding_rule = GLU_TESS_WINDING_ODD );
void init(const TVec3d& normal) override;

/**
* @brief Add a new contour - add the exterior ring first, then interiors
* @param textureCoordinatesLists a list of texture coordinates lists for the countour. Each list contains one texture coordinate for each vertex.
*/
void addContour(const std::vector<TVec3d>&, std::vector<std::vector<TVec2f> > textureCoordinatesLists);
void addContour(const std::vector<TVec3d>&, std::vector<std::vector<TVec2f> > textureCoordinatesLists) override;

// Let's tesselate!
void compute();

// Tesselation result access
const std::vector<TVec3d> getVertices() const;
const std::vector<std::vector<TVec2f> >& getTexCoords() const { return _texCoordsLists; }
const std::vector<unsigned int>& getIndices() const;

void setKeepVertices(bool val);
bool keepVertices() const;
void compute() override;

private:
typedef void (APIENTRY *GLU_TESS_CALLBACK)();
Expand All @@ -77,16 +67,7 @@ class LIBCITYGML_EXPORT Tesselator
private:
GLUtesselator *_tobj;
GLenum _curMode;

std::list<TVec3d> _vertices;
std::vector<std::vector<TVec2f> > _texCoordsLists;
std::list<unsigned int> _indices;
std::vector<unsigned int> _outIndices;

std::vector<unsigned int> _curIndices;
std::shared_ptr<citygml::CityGMLLogger> _logger;

bool _keepVertices;
GLenum _windingRule;
};

#endif // __TESSELATOR_H__
69 changes: 69 additions & 0 deletions sources/include/citygml/tesselatorbase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* -*-c++-*- libcitygml - Copyright (c) 2010 Joachim Pouderoux, BRGM
*
* This file is part of libcitygml library
* http://code.google.com/p/libcitygml
*
* libcitygml is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* libcitygml is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*/

#ifndef __TESSELATORBASE_H__
#define __TESSELATORBASE_H__

#include <citygml/citygml_api.h>
#include <citygml/vecs.hpp>
#include <vector>
#include <memory>

namespace citygml {
class CityGMLLogger;
}

// base class for polygon tesselator
class LIBCITYGML_EXPORT TesselatorBase
{
public:
TesselatorBase( std::shared_ptr<citygml::CityGMLLogger> logger );
virtual ~TesselatorBase();

void setLogger(std::shared_ptr<citygml::CityGMLLogger> logger);

virtual void init(const TVec3d& normal) = 0;

/**
* @brief Add a new contour - add the exterior ring first, then interiors
* @param textureCoordinatesLists a list of texture coordinates lists for the countour. Each list contains one texture coordinate for each vertex.
*/
virtual void addContour(const std::vector<TVec3d>&, std::vector<std::vector<TVec2f> > textureCoordinatesLists);

// Let's tesselate!
virtual void compute() = 0;

// Tesselation result access
const std::vector<TVec3d>& getVertices() const;
const std::vector<std::vector<TVec2f> >& getTexCoords() const { return _texCoordsLists; }
const std::vector<unsigned int>& getIndices() const;

void setKeepVertices(bool val);
bool keepVertices() const;

protected:
std::vector<TVec3d> _vertices;
std::vector<std::vector<TVec2f> > _texCoordsLists;
std::vector<unsigned int> _indices;
std::vector<unsigned int> _outIndices;

std::vector<unsigned int> _curIndices;
std::shared_ptr<citygml::CityGMLLogger> _logger;

bool _keepVertices;
};

#endif // __TESSELATORBASE_H__
4 changes: 3 additions & 1 deletion sources/include/parser/citygmldocumentparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace citygml {

class CityGMLDocumentParser {
public:
CityGMLDocumentParser(const ParserParams& params, std::shared_ptr<CityGMLLogger> logger);
CityGMLDocumentParser(const ParserParams& params, std::shared_ptr<CityGMLLogger> logger, std::unique_ptr<TesselatorBase> tesselator);

std::shared_ptr<const CityModel> getModel();

Expand Down Expand Up @@ -80,6 +80,8 @@ namespace citygml {
std::shared_ptr<CityModel> m_rootModel;
ParserParams m_parserParams;

std::unique_ptr<TesselatorBase> m_tesselator;

bool m_currentElementUnknownOrUnexpected;
int m_unknownElementOrUnexpectedElementDepth;
std::string m_unknownElementOrUnexpectedElementName;
Expand Down
Loading

0 comments on commit 9b72e39

Please sign in to comment.