├── CMakeLists.txt
├── COPYING
├── ChangeLog
├── Doxyfile
├── README
├── cmake
├── FindGLES.cmake
├── FindGLES2.cmake
├── FindGLEW.cmake
└── FindSDL_gles.cmake
├── doc
└── architecture.dia
├── examples
├── CMakeLists.txt
└── SimpleViewer.cc
├── libglosm-client
├── CMakeLists.txt
├── CheckGL.cc
├── FirstPersonViewer.cc
├── GPXLayer.cc
├── GPXTile.cc
├── GeometryLayer.cc
├── GeometryTile.cc
├── MercatorProjection.cc
├── OrthoViewer.cc
├── Projection.cc
├── SphericalProjection.cc
├── TerrainLayer.cc
├── TerrainTile.cc
├── TileManager.cc
├── glosm
│ ├── CheckGL.hh
│ ├── FirstPersonViewer.hh
│ ├── GPXLayer.hh
│ ├── GPXTile.hh
│ ├── GeometryLayer.hh
│ ├── GeometryTile.hh
│ ├── Layer.hh
│ ├── MercatorProjection.hh
│ ├── OrthoViewer.hh
│ ├── Projection.hh
│ ├── Renderable.hh
│ ├── SphericalProjection.hh
│ ├── TerrainLayer.hh
│ ├── TerrainTile.hh
│ ├── Tile.hh
│ ├── TileManager.hh
│ ├── VertexBuffer.hh
│ ├── Viewer.hh
│ └── util
│ │ └── gl.h
├── mglu.cc
└── mglu.h
├── libglosm-geomgen
├── CMakeLists.txt
├── GeometryGenerator.cc
├── MetricBasis.cc
└── glosm
│ ├── GeometryGenerator.hh
│ └── MetricBasis.hh
├── libglosm-server
├── BBox.cc
├── CMakeLists.txt
├── DummyHeightmap.cc
├── Exception.cc
├── Geometry.cc
├── GeometryOperations.cc
├── Guard.cc
├── ParsingHelpers.cc
├── PreloadedGPXDatasource.cc
├── PreloadedXmlDatasource.cc
├── SRTMDatasource.cc
├── Timer.cc
├── WayMerger.cc
├── XMLParser.cc
└── glosm
│ ├── BBox.hh
│ ├── DummyHeightmap.hh
│ ├── Exception.hh
│ ├── GPXDatasource.hh
│ ├── Geometry.hh
│ ├── GeometryDatasource.hh
│ ├── GeometryOperations.hh
│ ├── Guard.hh
│ ├── HeightmapDatasource.hh
│ ├── Math.hh
│ ├── Misc.hh
│ ├── NonCopyable.hh
│ ├── OsmDatasource.hh
│ ├── ParsingHelpers.hh
│ ├── PreloadedGPXDatasource.hh
│ ├── PreloadedXmlDatasource.hh
│ ├── SRTMDatasource.hh
│ ├── Timer.hh
│ ├── WayMerger.hh
│ ├── XMLParser.hh
│ ├── geomath.h
│ ├── id_map.hh
│ └── osmtypes.h
├── testdata
├── glosm.gpx
├── glosm.osm
├── grid.osm
└── halfgrid.osm
├── tests
├── CMakeLists.txt
├── ExceptionTest.cc
├── IdMapTest.cc
├── ProjectionBench.cc
├── ProjectionTest.cc
├── TypeTest.cc
└── testing.h
├── tiler
├── CMakeLists.txt
├── Main.cc
├── PBuffer.cc
├── PBuffer.hh
├── PixelBuffer.cc
├── PixelBuffer.hh
├── PngWriter.cc
└── PngWriter.hh
└── viewer
├── CMakeLists.txt
├── GLUTMain.cc
├── GlosmViewer.cc
├── GlosmViewer.hh
└── SDLMain.cc
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | PROJECT(glosm)
2 |
3 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
4 |
5 | SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
6 |
7 | # Global options
8 | IF(UNIX)
9 | SET(BUILD_TILER_DEFAULT ON)
10 | ELSE(UNIX)
11 | SET(BUILD_TILER_DEFAULT OFF)
12 | ENDIF(UNIX)
13 |
14 | IF(WIN32)
15 | SET(WITH_GLEW_DEFAULT ON)
16 | ELSE(WIN32)
17 | SET(WITH_GLEW_DEFAULT OFF)
18 | ENDIF(WIN32)
19 |
20 | OPTION(BUILD_VIEWER_SDL "Build first-person osm viewer (SDL version)" ON)
21 | OPTION(BUILD_VIEWER_GLUT "Build first-person osm viewer (GLUT version)" OFF)
22 | OPTION(BUILD_TILER "Build tile generator" ${BUILD_TILER_DEFAULT})
23 | OPTION(BUILD_EXAMPLES "Build examples" OFF)
24 | OPTION(BUILD_TESTS "Build tests" ON)
25 | OPTION(WITH_GLEW "Use GLEW (needed when you system uses archaic OpenGL)" ${WITH_GLEW_DEFAULT})
26 | OPTION(WITH_GLES "Use OpenGL ES 1.1" OFF)
27 | # TODO: this requires rewriting some legacy OpenGL code
28 | #OPTION(WITH_GLES2 "Use OpenGL ES 2.0" OFF)
29 | OPTION(WITH_TOUCHPAD "Tune control for touchpad instead of mouse" OFF)
30 | OPTION(DEBUG_TILING "Render tile bounds for debugging" OFF)
31 | OPTION(DEBUG_FPS "Don't limit FPS for profiling" OFF)
32 |
33 | # Global variables (still overridable via cmake -D ..)
34 | SET(BINDIR "bin" CACHE STRING "Install subdirectory for binaries")
35 | SET(LIBDIR "lib" CACHE STRING "Install subdirectory for libraries")
36 |
37 | # Conditionals
38 | IF(MINGW)
39 | # Leave console till we have better way to display "Loading..." message
40 | SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mconsole")
41 | ENDIF(MINGW)
42 |
43 | # TODO: these should be disabled if only server software is built
44 | IF(WITH_GLES)
45 | FIND_PACKAGE(GLES REQUIRED)
46 | ADD_DEFINITIONS(-DWITH_GLES)
47 | SET(GL_INCLUDE_DIRS ${GLES_INCLUDE_DIR})
48 | SET(GL_LIBRARIES ${GLES_LIBRARY})
49 | ELSEIF(WITH_GLES2)
50 | FIND_PACKAGE(GLES2 REQUIRED)
51 | ADD_DEFINITIONS(-DWITH_GLES2)
52 | SET(GL_INCLUDE_DIRS ${GLES2_INCLUDE_DIR})
53 | SET(GL_LIBRARIES ${GLES2_LIBRARY})
54 | ELSE(WITH_GLES)
55 | FIND_PACKAGE(OpenGL REQUIRED)
56 | SET(GL_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR})
57 | SET(GL_LIBRARIES ${OPENGL_gl_LIBRARY})
58 | ENDIF(WITH_GLES)
59 |
60 | IF(WITH_GLEW)
61 | FIND_PACKAGE(GLEW REQUIRED)
62 | ADD_DEFINITIONS(-DWITH_GLEW)
63 | SET(GL_INCLUDE_DIRS ${GL_INCLUDE_DIRS} ${GLEW_INCLUDE_DIR})
64 | SET(GL_LIBRARIES ${GL_LIBRARIES} ${GLEW_LIBRARY})
65 | ENDIF(WITH_GLEW)
66 |
67 | # Global definitions
68 | ADD_DEFINITIONS(-Wall -Wextra -Wno-unused-parameter)
69 | IF(DEBUG_TILING)
70 | ADD_DEFINITIONS(-DDEBUG_TILING)
71 | ENDIF(DEBUG_TILING)
72 | IF(DEBUG_FPS)
73 | ADD_DEFINITIONS(-DDEBUG_FPS)
74 | ENDIF(DEBUG_FPS)
75 |
76 | # Info
77 | MESSAGE(STATUS " Building SDL viewer: ${BUILD_VIEWER_SDL}")
78 | MESSAGE(STATUS " Building GLUT viewer: ${BUILD_VIEWER_GLUT}")
79 | MESSAGE(STATUS " Building tiler: ${BUILD_TILER}")
80 | MESSAGE(STATUS " Building examples: ${BUILD_EXAMPLES}")
81 | MESSAGE(STATUS " Building tests: ${BUILD_TESTS}")
82 | MESSAGE(STATUS "")
83 | MESSAGE(STATUS " GLEW support: ${WITH_GLEW}")
84 | MESSAGE(STATUS "OpenGL ES 1.1 support: ${WITH_GLES}")
85 | #MESSAGE(STATUS "OpenGL ES 2.0 support: ${WITH_GLES2}")
86 | MESSAGE(STATUS " Touchpad support: ${WITH_TOUCHPAD}")
87 |
88 | # Framework subdirs
89 | ADD_SUBDIRECTORY(libglosm-server)
90 | ADD_SUBDIRECTORY(libglosm-client)
91 | ADD_SUBDIRECTORY(libglosm-geomgen)
92 |
93 | # Application subdirs
94 | IF(BUILD_VIEWER_SDL OR BUILD_VIEWER_GLUT)
95 | ADD_SUBDIRECTORY(viewer)
96 | ENDIF(BUILD_VIEWER_SDL OR BUILD_VIEWER_GLUT)
97 | IF(BUILD_TILER)
98 | ADD_SUBDIRECTORY(tiler)
99 | ENDIF(BUILD_TILER)
100 | IF(BUILD_EXAMPLES)
101 | ADD_SUBDIRECTORY(examples)
102 | ENDIF(BUILD_EXAMPLES)
103 | IF(BUILD_TESTS)
104 | ENABLE_TESTING()
105 | ADD_SUBDIRECTORY(tests)
106 | ENDIF(BUILD_TESTS)
107 |
--------------------------------------------------------------------------------
/ChangeLog:
--------------------------------------------------------------------------------
1 | glosm-0.0.2 2011-02-27
2 | --------------------------------
3 | * Geometry tiling was implemented: there are now two layers of
4 | geometry, ground (lowres) and detail (3D objects) which are split
5 | into tiles which are loaded on demand in background thread
6 | * Viewer may now be built with either of SDL and GLUT. SDL version
7 | is recommended and is enabled by default
8 | * Library was split into three: libglosm-server (core features),
9 | libglosm-client (OpenGL stuff), libglosm-geomgen (geometry
10 | generator)
11 | * Navigation was improved (more speed control, height locking,
12 | disabling mouse grab, touchpad-friendly navigation mode)
13 | * Added Windows support through cross-compilation with mingw32
14 | * Added OpenGL ES 1.1 platforms support (namely Maemo)
15 | * Added Spherical projection (in which Earth looks like globe) in
16 | addition to Mercator (flat Earth)
17 | * Added support for man_made=tower and man_made=chimney area objects
18 | * Added support for building:roof:shape=conical as the alias for
19 | pyramidal, both are now supported for arbitrary shaped buildings
20 | * Fixed crash in geometry generator
21 |
22 | glosm-0.0.1 2011-01-18
23 | --------------------------------
24 | * First public release
25 |
--------------------------------------------------------------------------------
/Doxyfile:
--------------------------------------------------------------------------------
1 | # Doxyfile for glosm; please keep tags sourted and grouped as in
2 | # vanilla Doxyfile generated with `doxygen -g'
3 |
4 | # Project related configuration options
5 | PROJECT = glosm
6 | OUTPUT_DIRECTORY = doc
7 | OUTPUT_LANGUAGE = English
8 | JAVADOC_AUTOBRIEF = yes
9 | TAB_SIZE = 4
10 |
11 | # Build related configuration options
12 |
13 | # configuration options related to warning and progress messages
14 |
15 | # configuration options related to the input files
16 | INPUT = libglosm-server libglosm-client libgeomgen-default
17 | RECURSIVE = yes
18 | EXCLUDE = libglosm-server/glosm/id_map.hh
19 |
20 | # configuration options related to source browsing
21 |
22 | # configuration options related to the alphabetical class index
23 |
24 | # configuration options related to the HTML output
25 |
26 | # configuration options related to the LaTeX output
27 | GENERATE_LATEX = NO
28 |
29 | # configuration options related to the RTF output
30 |
31 | # configuration options related to the man page output
32 |
33 | # configuration options related to the XML output
34 |
35 | # configuration options for the AutoGen Definitions output
36 |
37 | # configuration options related to the Perl module output
38 |
39 | # Configuration options related to the preprocessor
40 | INCLUDE_PATH = libglosm-server/include libglosm-client/include libgeomgen-default/include
41 |
42 | # Configuration::additions related to external references
43 |
44 | # Configuration options related to the dot tool
45 | HAVE_DOT = yes
46 | CALL_GRAPH = yes
47 | CALLER_GRAPH = yes
48 |
--------------------------------------------------------------------------------
/cmake/FindGLES.cmake:
--------------------------------------------------------------------------------
1 | # Find GLES
2 | #
3 | # GLES_INCLUDE_DIR
4 | # GLES_LIBRARY
5 | # GLES_FOUND
6 |
7 | FIND_PATH(GLES_INCLUDE_DIR NAMES GLES/gl.h)
8 |
9 | FIND_LIBRARY(GLES_LIBRARY NAMES GLES_CM)
10 |
11 | INCLUDE(FindPackageHandleStandardArgs)
12 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLES DEFAULT_MSG GLES_LIBRARY GLES_INCLUDE_DIR)
13 |
14 | MARK_AS_ADVANCED(GLES_INCLUDE_DIR GLES_LIBRARY)
15 |
--------------------------------------------------------------------------------
/cmake/FindGLES2.cmake:
--------------------------------------------------------------------------------
1 | # Find GLES2
2 | #
3 | # GLES2_INCLUDE_DIR
4 | # GLES2_LIBRARY
5 | # GLES2_FOUND
6 |
7 | FIND_PATH(GLES2_INCLUDE_DIR NAMES GLES2/gl2.h)
8 |
9 | FIND_LIBRARY(GLES2_LIBRARY NAMES GLESv2)
10 |
11 | INCLUDE(FindPackageHandleStandardArgs)
12 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLES2 DEFAULT_MSG GLES2_LIBRARY GLES2_INCLUDE_DIR)
13 |
14 | MARK_AS_ADVANCED(GLES2_INCLUDE_DIR GLES2_LIBRARY)
15 |
--------------------------------------------------------------------------------
/cmake/FindGLEW.cmake:
--------------------------------------------------------------------------------
1 | # Find GLEW
2 | #
3 | # GLEW_INCLUDE_DIR
4 | # GLEW_LIBRARY
5 | # GLEW_FOUND
6 | #
7 |
8 | FIND_PATH(GLEW_INCLUDE_DIR NAMES GL/glew.h)
9 |
10 | FIND_LIBRARY(GLEW_LIBRARY NAMES GLEW glew glew32 GLEW)
11 |
12 | INCLUDE(FindPackageHandleStandardArgs)
13 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLEW DEFAULT_MSG GLEW_LIBRARY GLEW_INCLUDE_DIR)
14 |
15 | MARK_AS_ADVANCED(GLEW_INCLUDE_DIR GLEW_LIBRARY)
16 |
--------------------------------------------------------------------------------
/cmake/FindSDL_gles.cmake:
--------------------------------------------------------------------------------
1 | # Find SDL_gles
2 | #
3 | # SDLGLES_INCLUDE_DIR
4 | # SDLGLES_LIBRARY
5 | # SDLGLES_FOUND
6 |
7 | FIND_PATH(SDLGLES_INCLUDE_DIR NAMES SDL/SDL_gles.h)
8 |
9 | FIND_LIBRARY(SDLGLES_LIBRARY NAMES SDL_gles)
10 |
11 | INCLUDE(FindPackageHandleStandardArgs)
12 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDLGLES DEFAULT_MSG SDLGLES_LIBRARY SDLGLES_INCLUDE_DIR)
13 |
14 | MARK_AS_ADVANCED(SDLGLES_INCLUDE_DIR SDLGLES_LIBRARY)
15 |
--------------------------------------------------------------------------------
/doc/architecture.dia:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AMDmi3/glosm/98e39883ac437861dc62d147e4fb24bfe145ab5e/doc/architecture.dia
--------------------------------------------------------------------------------
/examples/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Depends
2 | FIND_PACKAGE(GLUT REQUIRED)
3 |
4 | IF(WITH_GLEW)
5 | FIND_PACKAGE(GLEW REQUIRED)
6 | ADD_DEFINITIONS(-DWITH_GLEW)
7 | ENDIF(WITH_GLEW)
8 |
9 | # Targets
10 | INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${GLUT_INCLUDE_DIR} ${GLEW_INCLUDE_DIR} ../libglosm-client ../libglosm-server ../libglosm-geomgen)
11 | ADD_DEFINITIONS(-DTESTDATA=\"${PROJECT_SOURCE_DIR}/testdata/glosm.osm\")
12 |
13 | ADD_EXECUTABLE(SimpleViewer SimpleViewer.cc)
14 | TARGET_LINK_LIBRARIES(SimpleViewer glosm-client glosm-server glosm-geomgen ${GLUT_LIBRARY} ${GLEW_LIBRARY})
15 |
--------------------------------------------------------------------------------
/examples/SimpleViewer.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | /*
22 | * This is nearly simplest possible glosm example.
23 | *
24 | * This application is basically glosm-viewer stripped of most
25 | * functionality to show you how glosm works.
26 | */
27 |
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 |
37 | #if defined(WITH_GLEW)
38 | # include
39 | #endif
40 | #include
41 | #include
42 | #include
43 |
44 | Viewer* g_viewer = NULL;
45 | GeometryLayer* g_layer = NULL;
46 |
47 | void Display(void) {
48 | glClearColor(0.5, 0.5, 0.5, 0.0);
49 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
50 |
51 | /*** glosm stuff begins ***/
52 |
53 | if (g_layer && g_viewer)
54 | g_layer->Render(*g_viewer);
55 |
56 | /*** glosm stuff ends ***/
57 |
58 | glFlush();
59 | }
60 |
61 | void KeyDown(unsigned char, int, int) {
62 | exit(0);
63 | }
64 |
65 | int main(int argc, char** argv) {
66 | /* GLUT init */
67 | glutInit(&argc, argv);
68 | glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
69 | glutInitWindowSize(800, 600);
70 | glutCreateWindow("SimpleViewer");
71 | glutDisplayFunc(Display);
72 | glutKeyboardFunc(KeyDown);
73 |
74 | #if defined WITH_GLEW
75 | glewInit();
76 | #endif
77 |
78 | /*** glosm stuff begins ***/
79 |
80 | /* 1) Load our data */
81 | PreloadedXmlDatasource osm_datasource;
82 | osm_datasource.Load(TESTDATA);
83 |
84 | /* 2) Create heightmap datasource */
85 | DummyHeightmap heightmap;
86 |
87 | /* 3) Create facility to translate OSM data to geometry */
88 | GeometryGenerator geometry_generator(osm_datasource, heightmap);
89 |
90 | /* 4) Create layer which will render that geometry */
91 | GeometryLayer layer(MercatorProjection(), geometry_generator);
92 |
93 | /* 5) Request all data to be loaded synchronously */
94 | layer.LoadArea(geometry_generator.GetBBox(), TileManager::SYNC);
95 |
96 | /* 6) Create viewer to control eye position and direction */
97 | FirstPersonViewer viewer;
98 | viewer.SetPos(Vector3i(geometry_generator.GetCenter(), 100 * GEOM_UNITSINMETER /* 100 meters */));
99 | viewer.SetAspect(800.0/600.0);
100 | viewer.SetRotation(-135.0 / 180.0 * M_PI, -60.0 / 180.0 * M_PI);
101 |
102 | /*** glosm stuff ends ***/
103 |
104 | g_viewer = &viewer;
105 | g_layer = &layer;
106 |
107 | /* main loop */
108 | glutMainLoop();
109 |
110 | return 0;
111 | }
112 |
--------------------------------------------------------------------------------
/libglosm-client/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Depends
2 | FIND_PACKAGE(Threads REQUIRED)
3 |
4 | # Checks
5 | IF(NOT CMAKE_CROSSCOMPILING)
6 | INCLUDE(CheckFunctionExists)
7 | SET(CMAKE_EXTRA_INCLUDE_FILES "math.h")
8 | SET(CMAKE_REQUIRED_LIBRARIES m)
9 | CHECK_FUNCTION_EXISTS(sincos HAVE_SINCOS)
10 | SET(CMAKE_REQUIRED_LIBRARIES)
11 | SET(CMAKE_EXTRA_INCLUDE_FILES)
12 | ENDIF(NOT CMAKE_CROSSCOMPILING)
13 |
14 | IF(HAVE_SINCOS)
15 | ADD_DEFINITIONS(-DHAVE_SINCOS)
16 | ENDIF(HAVE_SINCOS)
17 |
18 | # Targets
19 | SET(SOURCES
20 | CheckGL.cc
21 | FirstPersonViewer.cc
22 | GeometryLayer.cc
23 | GeometryTile.cc
24 | GPXLayer.cc
25 | GPXTile.cc
26 | MercatorProjection.cc
27 | mglu.cc
28 | OrthoViewer.cc
29 | Projection.cc
30 | SphericalProjection.cc
31 | TerrainLayer.cc
32 | TerrainTile.cc
33 | TileManager.cc
34 | )
35 |
36 | # We check whether GL functions != NULL there. These funcions may
37 | # really be either function pointers (which are perfectly OK to
38 | # compare with NULL) or normal functions (for which warning will
39 | # be generated, while comparison still gives correct result).
40 | # We have to ignore the warning because there can be mix of both
41 | SET_SOURCE_FILES_PROPERTIES(
42 | CheckGL.cc
43 | PROPERTIES
44 | COMPILE_FLAGS "-Wno-address"
45 | )
46 |
47 | SET(HEADERS
48 | glosm/CheckGL.hh
49 | glosm/FirstPersonViewer.hh
50 | glosm/GeometryLayer.hh
51 | glosm/GeometryTile.hh
52 | glosm/GPXLayer.hh
53 | glosm/GPXTile.hh
54 | glosm/Layer.hh
55 | glosm/MercatorProjection.hh
56 | glosm/OrthoViewer.hh
57 | glosm/Projection.hh
58 | glosm/Renderable.hh
59 | glosm/SphericalProjection.hh
60 | glosm/TerrainLayer.hh
61 | glosm/TerrainTile.hh
62 | glosm/Tile.hh
63 | glosm/TileManager.hh
64 | glosm/VertexBuffer.hh
65 | glosm/Viewer.hh
66 | )
67 |
68 | INCLUDE_DIRECTORIES(. ../libglosm-server ${EXPAT_INCLUDE_DIR} ${GL_INCLUDE_DIRS})
69 |
70 | ADD_LIBRARY(glosm-client SHARED ${SOURCES})
71 | TARGET_LINK_LIBRARIES(glosm-client glosm-server ${GL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
72 |
73 | # Installation
74 | # SET_TARGET_PROPERTIES(glosm-client PROPERTIES SOVERSION 1)
75 | INSTALL(FILES ${HEADERS} DESTINATION include/glosm)
76 | INSTALL(FILES glosm/util/gl.h DESTINATION include/glosm/util)
77 |
78 | IF(NOT CMAKE_CROSSCOMPILING)
79 | INSTALL(TARGETS glosm-client LIBRARY DESTINATION ${LIBDIR})
80 | ENDIF(NOT CMAKE_CROSSCOMPILING)
81 |
--------------------------------------------------------------------------------
/libglosm-client/CheckGL.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | #include
24 |
25 | #define CHECK_GL_FUNCTION(x) \
26 | if (x == NULL) \
27 | throw GLUnsupportedException() << "Required OpenGL function " << #x << " is not supported on this platform"; \
28 |
29 | void CheckGL() {
30 | CHECK_GL_FUNCTION(glBindBuffer);
31 | CHECK_GL_FUNCTION(glBufferData);
32 | CHECK_GL_FUNCTION(glDeleteBuffers);
33 | CHECK_GL_FUNCTION(glDrawArrays);
34 | CHECK_GL_FUNCTION(glGenBuffers);
35 | }
36 |
--------------------------------------------------------------------------------
/libglosm-client/FirstPersonViewer.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | #include "mglu.h"
29 |
30 | #include "glosm/util/gl.h"
31 |
32 | #include
33 |
34 | FirstPersonViewer::FirstPersonViewer(): heightmap_(NULL), pos_(), landscape_height_(0), yaw_(0), pitch_(0), fov_(90.0), aspect_(1.0) {
35 | }
36 |
37 | FirstPersonViewer::FirstPersonViewer(const Vector3i& pos): heightmap_(NULL), pos_(pos), landscape_height_(0), yaw_(0), pitch_(0), fov_(90.0), aspect_(1.0) {
38 | }
39 |
40 | FirstPersonViewer::FirstPersonViewer(const Vector3i& pos, float yaw, float pitch): heightmap_(NULL), pos_(pos), landscape_height_(0), yaw_(yaw), pitch_(pitch), fov_(90.0), aspect_(1.0) {
41 | }
42 |
43 | void FirstPersonViewer::SetupViewerMatrix(const Projection& projection) const {
44 | glMatrixMode(GL_PROJECTION);
45 | glLoadIdentity();
46 |
47 | /* length of a meter in local units */
48 | float meterlen = projection.Project(pos_.Flattened() + Vector3i(0, 0, GEOM_UNITSINMETER), pos_.Flattened()).z;
49 |
50 | /* viewer height in meters */
51 | float height = pos_.z / (float)GEOM_UNITSINMETER;
52 | if (height < 100.0f)
53 | height = 100.0f;
54 |
55 | /* viewing distances is [1meter..100km] at under 100m height
56 | * and increases linearly with going higher */
57 | float znear = 0.01f * height * meterlen;
58 | float zfar = 1000.0f * height * meterlen;
59 |
60 | mgluPerspective(fov_ / M_PI * 180.0f, aspect_, znear, zfar);
61 |
62 | glMatrixMode(GL_MODELVIEW);
63 | glLoadIdentity();
64 |
65 | Vector3f dir = GetDirection();
66 | Vector3f up = Vector3f(0.0f, 0.0f, 1.0f);
67 |
68 | mgluLookAt(0.0f, 0.0f, 0.0f, dir.x, dir.y, dir.z, up.x, up.y, up.z);
69 | }
70 |
71 | Vector3i FirstPersonViewer::GetPos(const Projection& /* unused*/) const {
72 | return pos_;
73 | }
74 |
75 | void FirstPersonViewer::SetFov(float fov) {
76 | fov_ = fov;
77 | }
78 |
79 | void FirstPersonViewer::SetAspect(float aspect) {
80 | aspect_ = aspect;
81 | }
82 |
83 | Vector3f FirstPersonViewer::GetDirection() const {
84 | return Vector3f::FromYawPitch(yaw_, pitch_);
85 | }
86 |
87 | void FirstPersonViewer::SetPos(Vector3i pos) {
88 | pos_ = pos;
89 |
90 | FixPosition();
91 | }
92 |
93 | void FirstPersonViewer::Move(int flags, float speed, float time) {
94 | /* 1 meter direction-collinear vector in OSM coordinate space */
95 | Vector3f dirbasis = Vector3f(
96 | GEOM_LONSPAN / WGS84_EARTH_EQ_LENGTH / cos(pos_.y * GEOM_DEG_TO_RAD),
97 | GEOM_LONSPAN / WGS84_EARTH_EQ_LENGTH,
98 | GEOM_UNITSINMETER
99 | );
100 |
101 | Vector3f dir = GetDirection();
102 | Vector3f worldup = Vector3f(0.0f, 0.0f, 1.0f);
103 | Vector3f right = dir.CrossProduct(worldup).Normalized();
104 | Vector3f relup = right.CrossProduct(dir).Normalized();
105 |
106 | if (flags & FORWARD)
107 | pos_ += dirbasis * dir * speed * time;
108 | if (flags & BACKWARD)
109 | pos_ -= dirbasis * dir * speed * time;
110 | if (flags & LEFT)
111 | pos_ -= dirbasis * right * speed * time;
112 | if (flags & RIGHT)
113 | pos_ += dirbasis * right * speed * time;
114 | if (flags & UP)
115 | pos_ += dirbasis * relup * speed * time;
116 | if (flags & DOWN)
117 | pos_ -= dirbasis * relup * speed * time;
118 | if (flags & HIGHER)
119 | pos_ += dirbasis * worldup * speed * time;
120 | if (flags & LOWER)
121 | pos_ -= dirbasis * worldup * speed * time;
122 |
123 | FixPosition();
124 | }
125 |
126 | void FirstPersonViewer::FixPosition() {
127 | /* Update landscape height */
128 | if (heightmap_)
129 | landscape_height_ = heightmap_->GetHeight(Vector2d(pos_.x, pos_.y));
130 |
131 | /* Wrap around */
132 | if (pos_.x > GEOM_MAXLON)
133 | pos_.x -= GEOM_LONSPAN;
134 | if (pos_.x < GEOM_MINLON)
135 | pos_.x += GEOM_LONSPAN;
136 |
137 | /* Limit poles */
138 | if (pos_.y > GEOM_MERCATOR_MAXLAT)
139 | pos_.y = GEOM_MERCATOR_MAXLAT;
140 | if (pos_.y < GEOM_MERCATOR_MINLAT)
141 | pos_.y = GEOM_MERCATOR_MINLAT;
142 |
143 | /* Limit height */
144 | if (pos_.z < landscape_height_ + 1)
145 | pos_.z = landscape_height_ + 1;
146 | if (pos_.z > std::numeric_limits::max())
147 | pos_.z = std::numeric_limits::max();
148 | }
149 |
150 | void FirstPersonViewer::FixRotation() {
151 | static const float PitchLimit = M_PI/2.0*0.9;
152 |
153 | if (pitch_ > PitchLimit)
154 | pitch_ = PitchLimit;
155 | if (pitch_ < -PitchLimit)
156 | pitch_ = -PitchLimit;
157 | if (yaw_ > M_PI)
158 | yaw_ -= M_PI*2.0;
159 | if (yaw_ < -M_PI)
160 | yaw_ += M_PI*2.0;
161 | }
162 |
163 | void FirstPersonViewer::SetRotation(float yaw, float pitch) {
164 | yaw_ = yaw;
165 | pitch_ = pitch;
166 |
167 | FixRotation();
168 | }
169 |
170 | void FirstPersonViewer::Rotate(float yawspeed, float pitchspeed, float time) {
171 | yaw_ += yawspeed * time;
172 | pitch_ += pitchspeed * time;
173 |
174 | FixRotation();
175 | }
176 |
177 | float FirstPersonViewer::GetYaw() const {
178 | return yaw_;
179 | }
180 |
181 | float FirstPersonViewer::GetPitch() const {
182 | return pitch_;
183 | }
184 |
185 | float FirstPersonViewer::GetFov() const {
186 | return fov_;
187 | }
188 |
189 | float FirstPersonViewer::GetAspect() const {
190 | return aspect_;
191 | }
192 |
193 | Vector3d& FirstPersonViewer::MutablePos() {
194 | return pos_;
195 | }
196 |
197 | void FirstPersonViewer::SetHeightmapDatasource(const HeightmapDatasource* heightmap) {
198 | heightmap_ = heightmap;
199 | }
200 |
--------------------------------------------------------------------------------
/libglosm-client/GPXLayer.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | #include
30 |
31 | GPXLayer::GPXLayer(const Projection projection, const GPXDatasource& datasource, const HeightmapDatasource& heightmap): TileManager(projection), projection_(projection), datasource_(datasource), heightmap_(heightmap) {
32 | }
33 |
34 | GPXLayer::~GPXLayer() {
35 | }
36 |
37 | void GPXLayer::Render(const Viewer& viewer) {
38 | /* Setup projection */
39 | viewer.SetupViewerMatrix(projection_);
40 |
41 | /* OpenGL attrs */
42 | glMatrixMode(GL_MODELVIEW);
43 | glEnable(GL_BLEND);
44 | glEnable(GL_CULL_FACE);
45 | glEnable(GL_DEPTH_TEST);
46 | glShadeModel(GL_FLAT);
47 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
48 |
49 | /* Lighting */
50 | GLfloat global_ambient[] = {0.0, 0.0, 0.0, 1.0};
51 | GLfloat light_position[] = {-0.2, -0.777, 0.63, 0.0};
52 | GLfloat light_diffuse[] = {0.45, 0.45, 0.45, 1.0};
53 | GLfloat light_ambient[] = {0.33, 0.33, 0.33, 1.0};
54 | GLfloat material_diffuse[] = {1.0, 1.0, 1.0, 0.9};
55 |
56 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
57 |
58 | glLightfv(GL_LIGHT0, GL_POSITION, light_position);
59 | glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
60 | glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
61 |
62 | glMaterialfv(GL_FRONT, GL_AMBIENT, material_diffuse);
63 | glMaterialfv(GL_FRONT, GL_DIFFUSE, material_diffuse);
64 |
65 | /* Render tile(s) */
66 | TileManager::Render(viewer);
67 | }
68 |
69 | Tile* GPXLayer::SpawnTile(const BBoxi& bbox, int flags) const {
70 | return new GPXTile(projection_, datasource_, heightmap_, bbox.GetCenter(), bbox);
71 | }
72 |
--------------------------------------------------------------------------------
/libglosm-client/GPXTile.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | #include
24 | #include
25 |
26 | #include
27 |
28 | #include
29 | #include
30 |
31 | GPXTile::GPXTile(const Projection& projection, const GPXDatasource& datasource, const HeightmapDatasource& heightmap, const Vector2i& ref, const BBoxi& bbox) : Tile(ref), size_(0) {
32 | std::vector points;
33 | datasource.GetPoints(points, bbox);
34 |
35 | if (!points.empty()) {
36 | points_.reset(new VertexBuffer(GL_ARRAY_BUFFER));
37 |
38 | points_->Data().reserve(2 * points.size());
39 | for (std::vector::const_iterator i = points.begin(); i != points.end(); ++i) {
40 | points_->Data().push_back(projection.Project(*i, ref));
41 | points_->Data().push_back(projection.Project(Vector3i(i->x, i->y, heightmap.GetHeight(*i)), ref));
42 | }
43 |
44 | size_ = points_->GetFootprint();
45 | }
46 | }
47 |
48 | GPXTile::~GPXTile() {
49 | }
50 |
51 | void GPXTile::Render() {
52 | if (points_.get()) {
53 | glDepthFunc(GL_LEQUAL);
54 |
55 | glColor4f(1.0f, 0.0f, 1.0f, 0.5f);
56 | glPointSize(3.0);
57 |
58 | points_->Bind();
59 |
60 | glEnableClientState(GL_VERTEX_ARRAY);
61 |
62 | glVertexPointer(3, GL_FLOAT, sizeof(Vector3f)*2, BUFFER_OFFSET(0));
63 | glDrawArrays(GL_POINTS, 0, points_->GetSize()/2);
64 |
65 | glVertexPointer(3, GL_FLOAT, sizeof(Vector3f), BUFFER_OFFSET(0));
66 | glDrawArrays(GL_LINES, 0, points_->GetSize());
67 |
68 | glDisableClientState(GL_VERTEX_ARRAY);
69 | }
70 | }
71 |
72 | size_t GPXTile::GetSize() const {
73 | return size_;
74 | }
75 |
--------------------------------------------------------------------------------
/libglosm-client/GeometryLayer.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | #include
30 |
31 | GeometryLayer::GeometryLayer(const Projection projection, const GeometryDatasource& datasource): TileManager(projection), projection_(projection), datasource_(datasource) {
32 | }
33 |
34 | GeometryLayer::~GeometryLayer() {
35 | }
36 |
37 | void GeometryLayer::Render(const Viewer& viewer) {
38 | /* Setup projection */
39 | viewer.SetupViewerMatrix(projection_);
40 |
41 | /* OpenGL attrs */
42 | glMatrixMode(GL_MODELVIEW);
43 | glEnable(GL_BLEND);
44 | glEnable(GL_CULL_FACE);
45 | glEnable(GL_DEPTH_TEST);
46 | glShadeModel(GL_FLAT);
47 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
48 |
49 | /* Lighting */
50 | GLfloat global_ambient[] = {0.0, 0.0, 0.0, 1.0};
51 | GLfloat light_position[] = {-0.2, -0.777, 0.63, 0.0};
52 | GLfloat light_diffuse[] = {0.45, 0.45, 0.45, 1.0};
53 | GLfloat light_ambient[] = {0.33, 0.33, 0.33, 1.0};
54 | GLfloat material_diffuse[] = {1.0, 1.0, 1.0, 0.9};
55 |
56 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
57 |
58 | glLightfv(GL_LIGHT0, GL_POSITION, light_position);
59 | glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
60 | glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
61 |
62 | glMaterialfv(GL_FRONT, GL_AMBIENT, material_diffuse);
63 | glMaterialfv(GL_FRONT, GL_DIFFUSE, material_diffuse);
64 |
65 | /* Render tile(s) */
66 | TileManager::Render(viewer);
67 | }
68 |
69 | Tile* GeometryLayer::SpawnTile(const BBoxi& bbox, int flags) const {
70 | Geometry geom;
71 | datasource_.GetGeometry(geom, bbox, flags);
72 | return new GeometryTile(projection_, geom, bbox.GetCenter(), bbox);
73 | }
74 |
--------------------------------------------------------------------------------
/libglosm-client/GeometryTile.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | #include
24 |
25 | #include
26 | #include
27 | #include
28 |
29 | GeometryTile::GeometryTile(const Projection& projection, const Geometry& geometry, const Vector2i& ref, const BBoxi& bbox) : Tile(ref), size_(0) {
30 | if (!geometry.GetLinesLengths().empty()) {
31 | lines_vertices_.reset(new VertexBuffer(GL_ARRAY_BUFFER));
32 | lines_indices_.reset(new VertexBuffer(GL_ELEMENT_ARRAY_BUFFER));
33 |
34 | const Geometry::VertexVector& vertices = geometry.GetLinesVertices();
35 | const Geometry::LengthVector& lengths = geometry.GetLinesLengths();
36 |
37 | lines_vertices_->Data().reserve(vertices.size());
38 |
39 | for (unsigned int i = 0, curpos = 0; i < lengths.size(); ++i) {
40 | #if defined(WITH_GLES)
41 | /* GL ES doesn't support VBOs larger than 65536 elements */
42 | /* @todo split into multiple VBOs */
43 | if (curpos + lengths[i] > 65536)
44 | break;
45 | #endif
46 |
47 | for (int j = 0; j < lengths[i]; ++j) {
48 | lines_vertices_->Data().push_back(projection.Project(vertices[curpos + j], ref));
49 | }
50 |
51 | for (int j = 1; j < lengths[i]; ++j) {
52 | lines_indices_->Data().push_back(curpos + j - 1);
53 | lines_indices_->Data().push_back(curpos + j);
54 | }
55 |
56 | curpos += lengths[i];
57 | }
58 |
59 | size_ += lines_vertices_->GetFootprint() + lines_indices_->GetFootprint();
60 | }
61 |
62 | if (!geometry.GetConvexLengths().empty()) {
63 | convex_vertices_.reset(new VertexBuffer(GL_ARRAY_BUFFER));
64 | convex_indices_.reset(new VertexBuffer(GL_ELEMENT_ARRAY_BUFFER));
65 |
66 | const Geometry::VertexVector& vertices = geometry.GetConvexVertices();
67 | const Geometry::LengthVector& lengths = geometry.GetConvexLengths();
68 |
69 | convex_vertices_->Data().reserve(vertices.size());
70 |
71 | for (unsigned int i = 0, curpos = 0; i < lengths.size(); ++i) {
72 | #if defined(WITH_GLES)
73 | /* GL ES doesn't support VBOs larger than 65536 elements */
74 | /* @todo split into multiple VBOs */
75 | if (curpos + lengths[i] > 65536)
76 | break;
77 | #endif
78 |
79 | for (int j = 0; j < lengths[i]; ++j) {
80 | convex_vertices_->Data().push_back(Vertex(projection.Project(vertices[curpos + j], ref)));
81 | }
82 |
83 | for (int j = 2; j < lengths[i]; ++j) {
84 | convex_indices_->Data().push_back(curpos);
85 | convex_indices_->Data().push_back(curpos + j - 1);
86 | convex_indices_->Data().push_back(curpos + j);
87 | }
88 |
89 | CalcFanNormal(&convex_vertices_->Data()[curpos], lengths[i]);
90 |
91 | curpos += lengths[i];
92 | }
93 |
94 | size_ += convex_vertices_->GetFootprint() + convex_indices_->GetFootprint();
95 | }
96 | }
97 |
98 | GeometryTile::~GeometryTile() {
99 | }
100 |
101 | void GeometryTile::CalcFanNormal(Vertex* vertices, int count) {
102 | Vector3f first = vertices[1].pos - vertices[0].pos;
103 | Vector3f normal;
104 | for (int i = 1; i < count; ++i) {
105 | Vector3f v = vertices[i].pos - vertices[0].pos;
106 |
107 | if ((normal = first.CrossProduct(v)).LengthSquare() > 0)
108 | break;
109 | }
110 | normal.Normalize();
111 |
112 | for (int i = 0; i < count; ++i)
113 | vertices[i].norm = normal;
114 | }
115 |
116 | void GeometryTile::Render() {
117 | if (lines_vertices_.get()) {
118 | glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
119 |
120 | lines_vertices_->Bind();
121 |
122 | glEnableClientState(GL_VERTEX_ARRAY);
123 | glVertexPointer(3, GL_FLOAT, sizeof(Vector3f), BUFFER_OFFSET(0));
124 |
125 | // lines_indices_->Bind();
126 | // glDrawElements(GL_LINES, lines_indices_->GetSize(), GL_UNSIGNED_INT, 0);
127 | glDrawElements(GL_LINES, lines_indices_->GetSize(), GL_UNSIGNED_INT, lines_indices_->Data().data());
128 | // lines_indices_->UnBind();
129 |
130 | glDisableClientState(GL_VERTEX_ARRAY);
131 | }
132 |
133 | if (convex_vertices_.get()) {
134 | /* zpass */
135 | /*glColor4f(0.0f, 0.0f, 0.0f, 0.0f);
136 | triangles_->Render();
137 | quads_->Render();
138 |
139 | glDepthFunc(GL_EQUAL);*/
140 |
141 | /* objects */
142 | glEnable(GL_LIGHTING);
143 | glEnable(GL_LIGHT0);
144 |
145 | convex_vertices_->Bind();
146 |
147 | glEnableClientState(GL_VERTEX_ARRAY);
148 | glVertexPointer(3, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(0));
149 |
150 | glEnableClientState(GL_NORMAL_ARRAY);
151 | glNormalPointer(GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(12));
152 |
153 | /* XXX: since we can't do PolygonOffset for lines, we offset all polygons instead */
154 | glPolygonOffset(1.0, 1.0);
155 | glEnable(GL_POLYGON_OFFSET_FILL);
156 |
157 | // convex_indices_->Bind();
158 | // glDrawElements(GL_TRIANGLES, convex_indices_->GetSize(), GL_UNSIGNED_INT, 0);
159 | glDrawElements(GL_TRIANGLES, convex_indices_->GetSize(), GL_UNSIGNED_INT, convex_indices_->Data().data());
160 | // convex_indices_->UnBind();
161 |
162 | glDisable(GL_POLYGON_OFFSET_FILL);
163 |
164 | glDisableClientState(GL_NORMAL_ARRAY);
165 | glDisableClientState(GL_VERTEX_ARRAY);
166 |
167 | glDisable(GL_LIGHT0);
168 | glDisable(GL_LIGHTING);
169 | }
170 | }
171 |
172 | size_t GeometryTile::GetSize() const {
173 | return size_;
174 | }
175 |
--------------------------------------------------------------------------------
/libglosm-client/MercatorProjection.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | #include
24 |
25 | #include
26 |
27 | MercatorProjection::MercatorProjection() : Projection(&ProjectImpl, &UnProjectImpl) {
28 | }
29 |
30 | Vector3f MercatorProjection::ProjectImpl(const Vector3i& point, const Vector3i& ref) {
31 | return Vector3f(
32 | (double)((osmlong_t)point.x - ref.x) * GEOM_DEG_TO_RAD,
33 | mercator((double)point.y * GEOM_DEG_TO_RAD) - mercator((double)ref.y * GEOM_DEG_TO_RAD),
34 | (double)(point.z - ref.z) / GEOM_UNITSINMETER / (WGS84_EARTH_EQ_RADIUS * cos((double)(point.y * GEOM_DEG_TO_RAD)))
35 | );
36 | }
37 |
38 | Vector3i MercatorProjection::UnProjectImpl(const Vector3f& point, const Vector3i& ref) {
39 | double y = unmercator((double)point.y + mercator((double)ref.y * GEOM_DEG_TO_RAD));
40 | return Vector3i(
41 | ref.x + (osmint_t)round(point.x * GEOM_RAD_TO_DEG),
42 | (osmint_t)round(y * GEOM_RAD_TO_DEG),
43 | ref.z + (osmint_t)round((double)point.z * GEOM_UNITSINMETER * WGS84_EARTH_EQ_RADIUS * cos(y))
44 | );
45 | }
46 |
--------------------------------------------------------------------------------
/libglosm-client/OrthoViewer.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | #include
24 | #include
25 |
26 | #include
27 |
28 | OrthoViewer::OrthoViewer() : bbox_(BBoxi::ForEarth()), skew_(0.0f) {
29 | }
30 |
31 | void OrthoViewer::SetupViewerMatrix(const Projection& projection) const {
32 | Vector3i center = GetPos(projection);
33 |
34 | float xspan = fabs(projection.Project(Vector2i(bbox_.left, 0), center).x);
35 | float yspan = fabs(projection.Project(Vector2i(0, bbox_.top), center).y);
36 |
37 | /* Take +/- 1km as Z range */
38 | float zspan = fabs(projection.Project(Vector3i(center.x, center.y, 1000 * GEOM_UNITSINMETER), Vector3i(center.x, center.y, 0)).z);
39 |
40 | /* undefined which is aspect: x/y or y/x */
41 | float perspective[] = {
42 | 1.0f/xspan, 0.0f, 0.0f, 0.0f,
43 | 0.0f, 1.0f/yspan, 0.0f, 0.0f,
44 | 0.0f, skew_/yspan, -1.0/zspan, 0.0f,
45 | 0.0f, 0.0f, 0.0f, 1.0f,
46 | };
47 |
48 | glMatrixMode(GL_PROJECTION);
49 | glLoadMatrixf(perspective);
50 | }
51 |
52 | Vector3i OrthoViewer::GetPos(const Projection& projection) const {
53 | /* `naive' center that doesn't take projection into account */
54 | Vector2i nearcenter = bbox_.GetCenter();
55 |
56 | /* real center that takes projectino into account; to minimize error, calculated relative to nearcenter */
57 | return projection.UnProject((projection.Project(bbox_.GetBottomLeft(), nearcenter) + projection.Project(bbox_.GetTopRight(), nearcenter))/2.0, nearcenter);
58 | }
59 |
60 | void OrthoViewer::SetBBox(const BBoxi& bbox) {
61 | bbox_ = bbox;
62 | }
63 |
64 | void OrthoViewer::SetSkew(float skew) {
65 | skew_ = skew;
66 | }
67 |
--------------------------------------------------------------------------------
/libglosm-client/Projection.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | Projection::Projection(ProjectFunction pf, UnProjectFunction uf): project_(pf), unproject_(uf) {
24 | }
25 |
26 | Vector3f Projection::Project(const Vector3i& point, const Vector3i& ref) const {
27 | return project_(point, ref);
28 | }
29 |
30 | Vector3i Projection::UnProject(const Vector3f& point, const Vector3i& ref) const {
31 | return unproject_(point, ref);
32 | }
33 |
34 | void Projection::ProjectPoints(const std::vector& in, const Vector3i& ref, std::vector& out) const {
35 | /* "slow" fallback implementation; though virtual calls
36 | * add overhead, it's too small (~3%) to even care; but this
37 | * may be redefined in subclasses */
38 | out.reserve(out.size() + in.size());
39 | for (std::vector::const_iterator i = in.begin(); i != in.end(); ++i)
40 | out.push_back(project_(*i, ref));
41 | }
42 |
--------------------------------------------------------------------------------
/libglosm-client/SphericalProjection.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | #include
24 |
25 | #include
26 |
27 | SphericalProjection::SphericalProjection() : Projection(&ProjectImpl, &UnProjectImpl) {
28 | }
29 |
30 | Vector3f SphericalProjection::ProjectImpl(const Vector3i& point, const Vector3i& ref) {
31 | double point_angle_x = ((double)point.x - (double)ref.x) * GEOM_DEG_TO_RAD;
32 | double point_angle_y = (double)point.y * GEOM_DEG_TO_RAD;
33 | double point_height = (double)point.z / GEOM_UNITSINMETER;
34 |
35 | double ref_angle_y = (double)ref.y * GEOM_DEG_TO_RAD;
36 | double ref_height = (double)ref.z / GEOM_UNITSINMETER;
37 |
38 | #ifdef HAVE_SINCOS
39 | double sinx, cosx, siny, cosy;
40 | sincos(point_angle_x, &sinx, &cosx);
41 | sincos(point_angle_y, &siny, &cosy);
42 | #else
43 | double cosx = cos(point_angle_x);
44 | double cosy = cos(point_angle_y);
45 | double sinx = sin(point_angle_x);
46 | double siny = sin(point_angle_y);
47 | #endif
48 | Vector3d point_vector(
49 | (WGS84_EARTH_EQ_RADIUS + point_height) * sinx * cosy,
50 | (WGS84_EARTH_EQ_RADIUS + point_height) * siny,
51 | (WGS84_EARTH_EQ_RADIUS + point_height) * cosx * cosy
52 | );
53 |
54 | #ifdef HAVE_SINCOS
55 | double sinay, cosay;
56 | sincos(ref_angle_y, &sinay, &cosay);
57 | #else
58 | double sinay = sin(ref_angle_y);
59 | double cosay = cos(ref_angle_y);
60 | #endif
61 | return Vector3f(
62 | point_vector.x,
63 | point_vector.y * cosay - point_vector.z * sinay,
64 | point_vector.y * sinay + point_vector.z * cosay - WGS84_EARTH_EQ_RADIUS - ref_height
65 | );
66 | }
67 |
68 | Vector3i SphericalProjection::UnProjectImpl(const Vector3f& point, const Vector3i& ref) {
69 | double ref_angle_y = (double)ref.y * GEOM_DEG_TO_RAD;
70 | double ref_height = (double)ref.z / GEOM_UNITSINMETER;
71 |
72 | #ifdef HAVE_SINCOS
73 | double sinay, cosay;
74 | sincos(ref_angle_y, &sinay, &cosay);
75 | #else
76 | double sinay = sin(ref_angle_y);
77 | double cosay = cos(ref_angle_y);
78 | #endif
79 | Vector3d point_vector(
80 | point.x,
81 | sinay * (WGS84_EARTH_EQ_RADIUS + ref_height + point.z) + cosay * point.y,
82 | cosay * (WGS84_EARTH_EQ_RADIUS + ref_height + point.z) - sinay * point.y
83 | );
84 |
85 | Vector3d spherical(
86 | atan2(point_vector.x, point_vector.z),
87 | atan2(point_vector.y, sqrt(point_vector.x * point_vector.x + point_vector.z * point_vector.z)),
88 | point_vector.Length() - WGS84_EARTH_EQ_RADIUS
89 | );
90 |
91 | return Vector3i(
92 | ref.x + (osmint_t)round(spherical.x * GEOM_RAD_TO_DEG),
93 | (osmint_t)round(spherical.y * GEOM_RAD_TO_DEG),
94 | (osmint_t)round(spherical.z * GEOM_UNITSINMETER)
95 | );
96 | }
97 |
--------------------------------------------------------------------------------
/libglosm-client/TerrainLayer.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | #include
29 |
30 | TerrainLayer::TerrainLayer(const Projection projection, HeightmapDatasource& datasource): TileManager(projection), projection_(projection), datasource_(datasource) {
31 | }
32 |
33 | TerrainLayer::~TerrainLayer() {
34 | }
35 |
36 | void TerrainLayer::Render(const Viewer& viewer) {
37 | /* Setup projection */
38 | viewer.SetupViewerMatrix(projection_);
39 |
40 | /* OpenGL attrs */
41 | glMatrixMode(GL_MODELVIEW);
42 | glEnable(GL_BLEND);
43 | glEnable(GL_CULL_FACE);
44 | glEnable(GL_DEPTH_TEST);
45 | glShadeModel(GL_SMOOTH);
46 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
47 |
48 | /* Lighting */
49 | GLfloat global_ambient[] = {0.0, 0.0, 0.0, 1.0};
50 | GLfloat light_position[] = {-0.2, -0.777, 0.63, 0.0};
51 | GLfloat light_diffuse[] = {0.45, 0.45, 0.45, 1.0};
52 | GLfloat light_ambient[] = {0.33, 0.33, 0.33, 1.0};
53 | float l = 0.85;
54 | GLfloat material_diffuse[] = {l, l, l, 1.0};
55 |
56 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
57 |
58 | glLightfv(GL_LIGHT0, GL_POSITION, light_position);
59 | glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
60 | glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
61 |
62 | glMaterialfv(GL_FRONT, GL_AMBIENT, material_diffuse);
63 | glMaterialfv(GL_FRONT, GL_DIFFUSE, material_diffuse);
64 |
65 | glEnable(GL_LIGHTING);
66 | glEnable(GL_LIGHT0);
67 |
68 | /* Render tile(s) */
69 |
70 | /* XXX: we use 2 here as 1 is used for geometry */
71 | glPolygonOffset(2.0, 2.0);
72 | glEnable(GL_POLYGON_OFFSET_FILL);
73 |
74 | TileManager::Render(viewer);
75 |
76 | glDisable(GL_POLYGON_OFFSET_FILL);
77 |
78 | glDisable(GL_LIGHT0);
79 | glDisable(GL_LIGHTING);
80 | }
81 |
82 | Tile* TerrainLayer::SpawnTile(const BBoxi& bbox, int flags) const {
83 | return new TerrainTile(projection_, datasource_, bbox.GetCenter(), bbox);
84 | }
85 |
--------------------------------------------------------------------------------
/libglosm-client/TerrainTile.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | #include
24 | #include
25 |
26 | #include
27 | #include
28 |
29 | #include
30 | #include
31 |
32 | TerrainTile::TerrainTile(const Projection& projection, HeightmapDatasource& datasource, const Vector2i& ref, const BBoxi& bbox) : Tile(ref) {
33 | HeightmapDatasource::Heightmap heightmap;
34 |
35 | /* we request heightmap with extra 1-point margin so we can
36 | * calculate correct normals for edge vertices */
37 | datasource.GetHeightmap(bbox, 1, heightmap);
38 |
39 | int width = heightmap.width - 2;
40 | int height = heightmap.height - 2;
41 |
42 | /* for each tile, we store position and normal for each
43 | * vertex in the grid; we also store index array which
44 | * arranges vertices into a single triangle strip */
45 |
46 | vbo_.reset(new VertexBuffer(GL_ARRAY_BUFFER));
47 | vbo_->Data().resize(width * height);
48 |
49 | /* temporary array of projected points */
50 | std::vector projected;
51 | projected.reserve(heightmap.width * heightmap.height);
52 | for (int y = 0; y < heightmap.height; ++y) {
53 | for (int x = 0; x < heightmap.width; ++x) {
54 | projected.push_back(projection.Project(Vector3i(
55 | (osmint_t)((double)heightmap.bbox.left) + ((double)heightmap.bbox.right - (double)heightmap.bbox.left) * ((double)x / (double)(heightmap.width - 1)),
56 | (osmint_t)((double)heightmap.bbox.bottom) + ((double)heightmap.bbox.top - (double)heightmap.bbox.bottom) * ((double)y / (double)(heightmap.height - 1)),
57 | heightmap.points[y * heightmap.width + x]
58 | ), ref));
59 | }
60 | }
61 |
62 | /* prepare vertices & normals */
63 | int n = 0;
64 | for (int y = 1; y < heightmap.height - 1; ++y) {
65 | for (int x = 1; x < heightmap.width - 1; ++x) {
66 | Vector3f v1 = projected[y * heightmap.width + x + 1] - projected[y * heightmap.width + x - 1];
67 | Vector3f v2 = projected[(y + 1) * heightmap.width + x] - projected[(y - 1) * heightmap.width + x];
68 |
69 | vbo_->Data()[n].pos = projected[y * heightmap.width + x];
70 | vbo_->Data()[n].norm = v1.CrossProduct(v2).Normalized();
71 |
72 | n++;
73 | }
74 | }
75 |
76 | /* clamp grid edges with tile bounds */
77 |
78 | double k1, k2;
79 | double cellheight = ((double)heightmap.bbox.top - (double)heightmap.bbox.bottom) / (double)(heightmap.height - 1);
80 | double cellwidth = ((double)heightmap.bbox.right - (double)heightmap.bbox.left) / (double)(heightmap.width - 1);
81 |
82 | /*
83 | * @todo this clamping is not quite correct: it doesn't
84 | * take the fact that terrain grid consists of triangles
85 | * into account
86 | */
87 |
88 | /* clamp bottom & top */
89 | k1 = ((double)bbox.bottom - (double)heightmap.bbox.bottom) / cellheight - 1.0;
90 | k2 = ((double)heightmap.bbox.top - (double)bbox.top) / cellheight - 1.0;
91 | for (int x = 0; x < width; ++x) {
92 | vbo_->Data()[x].pos = vbo_->Data()[x].pos * (1.0 - k1) + vbo_->Data()[width + x].pos * (k1);
93 | vbo_->Data()[x].norm = vbo_->Data()[x].norm * (1.0 - k1) + vbo_->Data()[width + x].norm * (k1);
94 |
95 | vbo_->Data()[(height - 1) * width + x].pos = vbo_->Data()[(height - 1) * width + x].pos * (1.0 - k2) + vbo_->Data()[(height - 2) * width + x].pos * (k2);
96 | vbo_->Data()[(height - 1) * width + x].norm = vbo_->Data()[(height - 1) * width + x].norm * (1.0 - k2) + vbo_->Data()[(height - 2) * width + x].norm * (k2);
97 | }
98 |
99 | /* clamp left & right */
100 | k1 = ((double)bbox.left - (double)heightmap.bbox.left) / cellwidth - 1.0;
101 | k2 = ((double)heightmap.bbox.right - (double)bbox.right) / cellwidth - 1.0;
102 | for (int y = 0; y < height; ++y) {
103 | vbo_->Data()[y * width].pos = vbo_->Data()[y * width].pos * (1.0 - k1) + vbo_->Data()[y * width + 1].pos * (k1);
104 | vbo_->Data()[y * width].norm = vbo_->Data()[y * width].norm * (1.0 - k1) + vbo_->Data()[y * width + 1].norm * (k1);
105 |
106 | vbo_->Data()[y * width + width - 1].pos = vbo_->Data()[y * width + width - 1].pos * (1.0 - k2) + vbo_->Data()[y * width + width - 2].pos * (k2);
107 | vbo_->Data()[y * width + width - 1].norm = vbo_->Data()[y * width + width - 1].norm * (1.0 - k2) + vbo_->Data()[y * width + width - 2].norm * (k2);
108 | }
109 |
110 | /* ought to be enough for anybody? test with hires hawaii heightmaps */
111 | if (vbo_->GetSize() > 65536)
112 | throw std::logic_error("error constructing TerrainTile: attempt to store more than 65536 vertices in a VBO indexed with SHORTs");
113 |
114 | /* prepare indices */
115 | ibo_.reset(new VertexBuffer(GL_ELEMENT_ARRAY_BUFFER));
116 | ibo_->Data().reserve((height - 1) * (width * 2 + 2) - 2);
117 | for (int y = 0; y < height - 1; ++y) {
118 | /* since strip is arranged per-row, we duplicate last and first
119 | * vertices in each row to make triangle between rows degraded
120 | * and thus not renderable */
121 | if (y > 0)
122 | ibo_->Data().push_back((y + 1) * width);
123 | for (int x = 0; x < width; ++x) {
124 | ibo_->Data().push_back((y + 1) * width + x);
125 | ibo_->Data().push_back(y * width + x);
126 | }
127 | if (y < height - 2)
128 | ibo_->Data().push_back(y * width + width - 1);
129 | }
130 |
131 | size_ = vbo_->GetFootprint() + ibo_->GetFootprint();
132 | }
133 |
134 | TerrainTile::~TerrainTile() {
135 | }
136 |
137 | void TerrainTile::Render() {
138 | vbo_->Bind();
139 |
140 | glEnableClientState(GL_VERTEX_ARRAY);
141 | glVertexPointer(3, GL_FLOAT, sizeof(TerrainVertex), BUFFER_OFFSET(0));
142 |
143 | glEnableClientState(GL_NORMAL_ARRAY);
144 | glNormalPointer(GL_FLOAT, sizeof(TerrainVertex), BUFFER_OFFSET(12));
145 |
146 | ibo_->Bind();
147 |
148 | glDrawElements(GL_TRIANGLE_STRIP, ibo_->GetSize(), GL_UNSIGNED_SHORT, BUFFER_OFFSET(0));
149 |
150 | ibo_->UnBind();
151 |
152 | glDisableClientState(GL_VERTEX_ARRAY);
153 | glDisableClientState(GL_NORMAL_ARRAY);
154 | }
155 |
156 | size_t TerrainTile::GetSize() const {
157 | return size_;
158 | }
159 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/CheckGL.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef CHECKGL_HH
22 | #define CHECKGL_HH
23 |
24 | #include
25 |
26 | /**
27 | * Exception that denotes unsupported OpenGL function
28 | */
29 | class GLUnsupportedException: public Exception {
30 | };
31 |
32 | /**
33 | * Checks whether OpenGL functions required by glosm are available
34 | *
35 | * Throws exception in case of error
36 | */
37 | void CheckGL();
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/FirstPersonViewer.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef FIRSTPERSONVIEWER_HH
22 | #define FIRSTPERSONVIEWER_HH
23 |
24 | #include
25 |
26 | class Projection;
27 | class HeightmapDatasource;
28 |
29 | /**
30 | * Viewer describing perspective projection.
31 | */
32 | class FirstPersonViewer : public Viewer {
33 | public:
34 | /**
35 | * Movement direction flags.
36 | *
37 | * These are used to describe in which way (relative to
38 | * look direction) a viewer should move to
39 | *
40 | * LOWER/HIGHER values are actually absolute up/down.
41 | */
42 | enum Direction {
43 | FORWARD = 0x0001,
44 | BACKWARD = 0x0002,
45 | LEFT = 0x0004,
46 | RIGHT = 0x0008,
47 | UP = 0x0010,
48 | DOWN = 0x0020,
49 | LOWER = 0x0040,
50 | HIGHER = 0x0080,
51 | };
52 |
53 | protected:
54 | Vector3f GetDirection() const;
55 | void FixRotation();
56 | void FixPosition();
57 |
58 | public:
59 | FirstPersonViewer();
60 | FirstPersonViewer(const Vector3i& pos);
61 | FirstPersonViewer(const Vector3i& pos, float yaw, float pitch);
62 |
63 | virtual void SetupViewerMatrix(const Projection& projection) const;
64 | virtual Vector3i GetPos(const Projection& projection) const;
65 |
66 | void SetFov(float fov);
67 | void SetAspect(float aspect);
68 |
69 | void SetPos(Vector3i pos);
70 |
71 | /**
72 | * Move viewer smoothly
73 | *
74 | * @param flags combination of Direction constants which
75 | * represents direction for viewer to move to
76 | * @param speed movement speed in meters/second
77 | * @param time time delta for movement in seconds
78 | */
79 | void Move(int flags, float speed, float time);
80 |
81 | void SetRotation(float yaw, float pitch);
82 |
83 | void Rotate(float yawspeed, float pitchspeed, float time);
84 |
85 | float GetPitch() const;
86 | float GetYaw() const;
87 |
88 | float GetFov() const;
89 | float GetAspect() const;
90 |
91 | Vector3d& MutablePos();
92 |
93 | void SetHeightmapDatasource(const HeightmapDatasource* heightmap);
94 |
95 | protected:
96 | const HeightmapDatasource* heightmap_;
97 |
98 | protected:
99 | /** Eye position */
100 | Vector3d pos_;
101 |
102 | /** Terrain elevation at eye point */
103 | osmint_t landscape_height_;
104 |
105 | float yaw_;
106 | float pitch_;
107 |
108 | float fov_;
109 | float aspect_;
110 | };
111 |
112 | #endif
113 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/GPXLayer.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef GPXLAYER_HH
22 | #define GPXLAYER_HH
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | class Viewer;
30 | class GPXDatasource;
31 | class HeightmapDatasource;
32 |
33 | /**
34 | * Layer with 3D OpenStreetMap data.
35 | */
36 | class GPXLayer : public Layer, public TileManager, private NonCopyable {
37 | public:
38 | enum Mode {
39 | NORMAL = 0, /* use real track elevations */
40 | FLAT = 1, /* place points on ground, don't use track elevations */
41 | SUBSTRACT = 2, /* substract heightmap from track elevation */
42 | };
43 |
44 | protected:
45 | const Projection projection_;
46 | const GPXDatasource& datasource_;
47 | const HeightmapDatasource& heightmap_;
48 |
49 | public:
50 | GPXLayer(const Projection projection, const GPXDatasource& datasource, const HeightmapDatasource& heightmap);
51 | virtual ~GPXLayer();
52 |
53 | void Render(const Viewer& viewer);
54 | virtual Tile* SpawnTile(const BBoxi& bbox, int flags) const;
55 | };
56 |
57 | #endif
58 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/GPXTile.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef GPXTILE_HH
22 | #define GPXTILE_HH
23 |
24 | #include
25 | #include
26 | #include
27 |
28 | #include
29 | #include
30 |
31 | template
32 | class VertexBuffer;
33 |
34 | class Projection;
35 | class GPXDatasource;
36 | class HeightmapDatasource;
37 |
38 | /**
39 | * A tile of GPX points
40 | *
41 | * This tile type is used by GPXLayer
42 | */
43 | class GPXTile : public Tile, private NonCopyable {
44 | protected:
45 | std::auto_ptr > points_;
46 |
47 | size_t size_;
48 |
49 | public:
50 | /**
51 | * Constructs tile from vector of points
52 | *
53 | * @param projection projection used to convert fixed-point geometry
54 | * @param points source points
55 | * @param ref reference point of this tile
56 | * @param bbox bounding box of this tile
57 | */
58 | GPXTile(const Projection& projection, const GPXDatasource& datasource, const HeightmapDatasource& heightmap, const Vector2i& ref, const BBoxi& bbox);
59 |
60 | /**
61 | * Destructor
62 | */
63 | virtual ~GPXTile();
64 |
65 | /**
66 | * Render this tile
67 | */
68 | virtual void Render();
69 |
70 | /**
71 | * Returns tile size in bytes
72 | */
73 | virtual size_t GetSize() const;
74 | };
75 |
76 | #endif
77 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/GeometryLayer.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef GEOMETRYLAYER_HH
22 | #define GEOMETRYLAYER_HH
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | class Viewer;
30 | class GeometryDatasource;
31 |
32 | /**
33 | * Layer with 3D OpenStreetMap data.
34 | */
35 | class GeometryLayer : public Layer, public TileManager, private NonCopyable {
36 | protected:
37 | const Projection projection_;
38 | const GeometryDatasource& datasource_;
39 |
40 | public:
41 | GeometryLayer(const Projection projection, const GeometryDatasource& datasource);
42 | virtual ~GeometryLayer();
43 |
44 | void Render(const Viewer& viewer);
45 | virtual Tile* SpawnTile(const BBoxi& bbox, int flags) const;
46 | };
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/GeometryTile.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef GEOMETRYTILE_HH
22 | #define GEOMETRYTILE_HH
23 |
24 | #include
25 | #include
26 | #include
27 |
28 | #include
29 |
30 | #include
31 | #include
32 |
33 | template
34 | class VertexBuffer;
35 |
36 | class Projection;
37 | class Geometry;
38 |
39 | /**
40 | * A tile of renderable geometry
41 | *
42 | * This tile type is used in GeometryLayer
43 | */
44 | class GeometryTile : public Tile, private NonCopyable {
45 | protected:
46 | struct Vertex {
47 | Vector3f pos;
48 | Vector3f norm;
49 |
50 | Vertex(const Vector3f& p): pos(p) {
51 | }
52 | };
53 |
54 | protected:
55 | std::auto_ptr > lines_vertices_;
56 | std::auto_ptr > lines_indices_;
57 |
58 | std::auto_ptr > convex_vertices_;
59 | std::auto_ptr > convex_indices_;
60 |
61 | size_t size_;
62 |
63 | protected:
64 | void CalcFanNormal(Vertex* vertices, int count);
65 |
66 | public:
67 | /**
68 | * Constructs tile from given geometry
69 | *
70 | * @param projection projection used to convert fixed-point geometry
71 | * @param geometry source geometry
72 | * @param ref reference point of this tile
73 | * @param bbox bounding box of this tile
74 | */
75 | GeometryTile(const Projection& projection, const Geometry& geometry, const Vector2i& ref, const BBoxi& bbox);
76 |
77 | /**
78 | * Destructor
79 | */
80 | virtual ~GeometryTile();
81 |
82 | /**
83 | * Render this tile
84 | */
85 | virtual void Render();
86 |
87 | /**
88 | * Returns tile size in bytes
89 | */
90 | virtual size_t GetSize() const;
91 | };
92 |
93 | #endif
94 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/Layer.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef LAYER_HH
22 | #define LAYER_HH
23 |
24 | /**
25 | * Abstact base class for all layers.
26 | *
27 | * Layer is a renderable representation of a single kind of geodata.
28 | */
29 | class Layer {
30 | public:
31 | virtual ~Layer() {
32 | }
33 | };
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/MercatorProjection.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef MERCATORPROJECTION_HH
22 | #define MERCATORPROJECTION_HH
23 |
24 | #include
25 |
26 | /**
27 | * Mercator/EPSG:3857 projection
28 | *
29 | * This represents Spherical Mercator projection common to OpenStreetMap.
30 | */
31 | class MercatorProjection : public Projection {
32 | protected:
33 | static Vector3f ProjectImpl(const Vector3i& point, const Vector3i& ref);
34 | static Vector3i UnProjectImpl(const Vector3f& point, const Vector3i& ref);
35 |
36 | public:
37 | MercatorProjection();
38 | };
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/OrthoViewer.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef ORTHOVIEWER_HH
22 | #define ORTHOVIEWER_HH
23 |
24 | #include
25 | #include
26 |
27 | /**
28 | * Viewer describing orthographic projection.
29 | *
30 | * This viewer is useful for tile rendering.
31 | */
32 | class OrthoViewer : public Viewer {
33 | public:
34 | OrthoViewer();
35 |
36 | virtual void SetupViewerMatrix(const Projection& projection) const;
37 | virtual Vector3i GetPos(const Projection& projection) const;
38 |
39 | /**
40 | * Sets bounding box of a viewport in global coordinades
41 | */
42 | void SetBBox(const BBoxi& pos);
43 |
44 | /**
45 | * Sets skew for pseudo-3D effect.
46 | *
47 | * To retain tile proportions, we can't do proper 3D by
48 | * changing viewing angle, but we can 'skew' objects that
49 | * have height so their sides appear on a top-down view.
50 | * Skew factor may be described as a tangent of desired
51 | * viewing angle, 1.0 is equal to 45 degrees.
52 | *
53 | * @param skew skew ratio
54 | */
55 | void SetSkew(float skew);
56 |
57 | protected:
58 | BBoxi bbox_;
59 | float skew_;
60 | };
61 |
62 | #endif
63 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/Projection.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef PROJECTION_HH
22 | #define PROJECTION_HH
23 |
24 | #include
25 |
26 | #include
27 |
28 | /**
29 | * Abstract base class for all projections.
30 | *
31 | * Provides a way to translate global fixed-point geometry coordinates
32 | * into relative floating point ones and vice versa.
33 | *
34 | * Since OpenGL works with float data, and float has not enough
35 | * precision to represent geographical coordinates for OpenStreetMap
36 | * objects (up to 1 meter error on high longitudes), we have to use
37 | * fixed point format for data interchange and relative floating-point
38 | * format for rendering.
39 | *
40 | * @note: this class is designed in a way that its derivatives can
41 | * be safely cast to Projection copied and passed by value.
42 | */
43 | class Projection {
44 | private:
45 | typedef Vector3f(*ProjectFunction)(const Vector3i&, const Vector3i&);
46 | typedef Vector3i(*UnProjectFunction)(const Vector3f&, const Vector3i&);
47 |
48 | private:
49 | ProjectFunction project_;
50 | UnProjectFunction unproject_;
51 |
52 | protected:
53 | Projection(ProjectFunction pf, UnProjectFunction uf);
54 |
55 | public:
56 | /**
57 | * Translates a point from global fixed-point to relative
58 | * floating-point coordinate system.
59 | *
60 | * @param point point to translate
61 | * @param ref reference point which denotes the center of
62 | * local coordinate system
63 | * @return translated point
64 | */
65 | Vector3f Project(const Vector3i& point, const Vector3i& ref) const;
66 |
67 | /**
68 | * Translates a point from relative floating-point to global
69 | * fixed-point coordinate system.
70 | *
71 | * @param point point to translate
72 | * @param ref reference point which denotes the center of
73 | * local coordinate system
74 | * @return translated point
75 | */
76 | Vector3i UnProject(const Vector3f& point, const Vector3i& ref) const;
77 |
78 | /**
79 | * Translates bunch of points from relative floating-point
80 | * to global fixed-point coordinate system.
81 | *
82 | * @param in reference to input vector of points
83 | * @param out reference to output vector of translated
84 | * points (which is appended)
85 | * @param ref reference point which denotes the center of
86 | * local coordinate system
87 | */
88 | void ProjectPoints(const std::vector& in, const Vector3i& ref, std::vector& out) const;
89 | };
90 |
91 | #endif
92 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/Renderable.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef RENDERABLE_HH
22 | #define RENDERABLE_HH
23 |
24 | /**
25 | * An abstract renderable object
26 | */
27 | class Renderable {
28 | public:
29 | virtual ~Renderable() {
30 | }
31 |
32 | virtual void Render() = 0;
33 | };
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/SphericalProjection.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef SPHERICALPROJECTION_HH
22 | #define SPHERICALPROJECTION_HH
23 |
24 | #include
25 |
26 | /**
27 | * Spherical projection
28 | *
29 | * This represents Spherical projection.
30 | */
31 | class SphericalProjection : public Projection {
32 | protected:
33 | static Vector3f ProjectImpl(const Vector3i& point, const Vector3i& ref);
34 | static Vector3i UnProjectImpl(const Vector3f& point, const Vector3i& ref);
35 |
36 | public:
37 | SphericalProjection();
38 | };
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/TerrainLayer.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef TERRAINLAYER_HH
22 | #define TERRAINLAYER_HH
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | class Viewer;
30 | class HeightmapDatasource;
31 |
32 | /**
33 | * Layer with 3D terrain data.
34 | */
35 | class TerrainLayer : public Layer, public TileManager, private NonCopyable {
36 | protected:
37 | const Projection projection_;
38 | HeightmapDatasource& datasource_;
39 |
40 | public:
41 | TerrainLayer(const Projection projection, HeightmapDatasource& datasource);
42 | virtual ~TerrainLayer();
43 |
44 | void Render(const Viewer& viewer);
45 | virtual Tile* SpawnTile(const BBoxi& bbox, int flags) const;
46 | };
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/TerrainTile.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef TERRAINTILE_HH
22 | #define TERRAINTILE_HH
23 |
24 | #include
25 | #include
26 | #include
27 |
28 | #include
29 |
30 | #include
31 | #include
32 |
33 | class SimpleVertexBuffer;
34 | class HeightmapDatasource;
35 |
36 | class Projection;
37 |
38 | template
39 | class VertexBuffer;
40 |
41 | /**
42 | * A terrain tile
43 | *
44 | * This tile type is used by TerrainLayer
45 | */
46 | class TerrainTile : public Tile, private NonCopyable {
47 | protected:
48 | struct TerrainVertex {
49 | Vector3f pos;
50 | Vector3f norm;
51 | };
52 |
53 | protected:
54 | std::auto_ptr > vbo_;
55 | std::auto_ptr > ibo_;
56 |
57 | size_t size_;
58 |
59 | public:
60 | TerrainTile(const Projection& projection, HeightmapDatasource& datasource, const Vector2i& ref, const BBoxi& bbox);
61 |
62 | /**
63 | * Destructor
64 | */
65 | virtual ~TerrainTile();
66 |
67 | /**
68 | * Render this tile
69 | */
70 | virtual void Render();
71 |
72 | /**
73 | * Returns tile size in bytes
74 | */
75 | virtual size_t GetSize() const;
76 | };
77 |
78 | #endif
79 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/Tile.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef TILE_HH
22 | #define TILE_HH
23 |
24 | #include
25 |
26 | #include /* for size_t */
27 |
28 | /**
29 | * Abstract class for all geodata tiles.
30 | *
31 | * Tile is just an abstract hunk of geodata ready for rendering.
32 | * Each tile has center stored in global fixed-point coords, while
33 | * all the actual data is stored in fixed-point format relative to
34 | * that center. As the tiles are expected to be small enough, this
35 | * prevents floating point errors to be noticeable.
36 | */
37 | class Tile {
38 | protected:
39 | /**
40 | * Global coordinates of tile center.
41 | */
42 | const Vector2i reference_;
43 |
44 | public:
45 | /**
46 | * Constructs tile
47 | */
48 | Tile(const Vector2i& ref) : reference_(ref) {}
49 |
50 | /**
51 | * Destructor
52 | */
53 | virtual ~Tile() {}
54 |
55 | /**
56 | * Renders tile
57 | */
58 | virtual void Render() = 0;
59 |
60 | /**
61 | * Returns tile size in bytes
62 | */
63 | virtual size_t GetSize() const = 0;
64 |
65 | /**
66 | * Returns tile reference point
67 | */
68 | const Vector2i& GetReference() const {
69 | return reference_;
70 | }
71 | };
72 |
73 | #endif
74 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/VertexBuffer.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef VERTEXBUFFER_HH
22 | #define VERTEXBUFFER_HH
23 |
24 | #include
25 | #include
26 |
27 | #include
28 |
29 | #include
30 |
31 | #include
32 | #include
33 | #include
34 | #include
35 |
36 | #define BUFFER_OFFSET(i) ((char *)NULL + (i))
37 |
38 | /**
39 | * Vertex Buffer Object
40 | *
41 | * This class is mainly a wrapper around OpenGL VBO's. However,
42 | * since delayed VBO creation is common in glosm, this may also
43 | * be used as a vector of vertex data, which turns into VBO on
44 | * first Bind() or Freeze() call.
45 | */
46 | template
47 | class VertexBuffer : private NonCopyable {
48 | public:
49 | typedef std::vector DataVector;
50 |
51 | protected:
52 | GLuint buffer_id_;
53 | size_t size_;
54 | GLenum type_;
55 | GLenum mode_;
56 | std::auto_ptr ram_data_;
57 |
58 | protected:
59 | void CreateBufferObject(const T* data, int count) {
60 | glGenBuffers(1, &buffer_id_);
61 | glBindBuffer(type_, buffer_id_);
62 | glBufferData(type_, count * sizeof(T), data, mode_);
63 | glBindBuffer(type_, 0);
64 | size_ = count;
65 | }
66 |
67 | public:
68 | /**
69 | * Constructs dynamic vertex buffer
70 | *
71 | * Vertex buffer constructed this way is ready to be filled
72 | * with data and be generally used as vector of T's via
73 | * Data() call. OpenGL buffers are not created until first
74 | * Bind() or Freeze() calls
75 | *
76 | * @param type buffer type (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER)
77 | */
78 | VertexBuffer(GLenum type = GL_ARRAY_BUFFER, GLenum mode = GL_STATIC_DRAW): buffer_id_(0), size_(0), type_(type), mode_(mode), ram_data_(new DataVector) {
79 | }
80 |
81 | /**
82 | * Constructs static vertex buffer
83 | *
84 | * Constructs OpenGL VBO directly from preexisting data.
85 | *
86 | * @param type buffer type (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER)
87 | * @param data pointer to array of data items
88 | * @param count number of items
89 | */
90 | VertexBuffer(GLenum type, const T* data, int count): type_(type) {
91 | CreateBufferObject(data, count);
92 | }
93 |
94 | /**
95 | * Destructor
96 | */
97 | ~VertexBuffer() {
98 | if (buffer_id_)
99 | glDeleteBuffers(1, &buffer_id_);
100 | }
101 |
102 | /**
103 | * Gives access to vector of vertex data
104 | *
105 | * @return reference to data vector
106 | */
107 | DataVector& Data() {
108 | assert(ram_data_.get());
109 | return *ram_data_;
110 | }
111 |
112 | /**
113 | * Forcibly converts data into OpenGL VBO
114 | *
115 | * @return true if VBO was created
116 | */
117 | bool Freeze() {
118 | if (ram_data_.get()) {
119 | CreateBufferObject(ram_data_->data(), ram_data_->size());
120 | ram_data_.reset(NULL);
121 | return true;
122 | }
123 | return false;
124 | }
125 |
126 | /**
127 | * Binds OpenGL buffer
128 | *
129 | * Creates it from vertex data if necessary
130 | */
131 | void Bind() {
132 | Freeze();
133 |
134 | assert(buffer_id_);
135 | glBindBuffer(type_, buffer_id_);
136 | }
137 |
138 | /**
139 | * Unbinds OpenGL buffer
140 | */
141 | void UnBind() {
142 | glBindBuffer(type_, 0);
143 | }
144 |
145 | /**
146 | * Returns number of items in VBO
147 | */
148 | size_t GetSize() const {
149 | if (ram_data_.get())
150 | return ram_data_->size();
151 | return size_;
152 | }
153 |
154 | /**
155 | * Returns size of VBO in bytes
156 | */
157 | size_t GetFootprint() const {
158 | if (ram_data_.get())
159 | return sizeof(T) * ram_data_->size();
160 | return sizeof(T) * size_;
161 | }
162 | };
163 |
164 | #endif
165 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/Viewer.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef VIEWER_HH
22 | #define VIEWER_HH
23 |
24 | #include
25 |
26 | class Projection;
27 |
28 | /**
29 | * Abstract base class for all viewers.
30 | *
31 | * Viewer is a way to represent which part of map we need to render.
32 | * For example, for first-person viewer that may be eye's position
33 | * and look direction. This class is used in rendering process to
34 | * properly setup projection matrix and in layers to determine which
35 | * objects are close enough to eye to be loaded and displayed.
36 | */
37 | class Viewer {
38 | public:
39 | /**
40 | * Setups OpenGL projection matrix for the viewer
41 | *
42 | * @param projection projection used in this world
43 | */
44 | virtual void SetupViewerMatrix(const Projection& projection) const = 0;
45 |
46 | /**
47 | * Returns pseudo-position of a viewer.
48 | *
49 | * @param projection projection used in the world
50 | * @return pseudo-position of a viewer
51 | */
52 | virtual Vector3i GetPos(const Projection& projection) const = 0;
53 | };
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/libglosm-client/glosm/util/gl.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef UTIL_GL_HH
22 | #define UTIL_GL_HH
23 |
24 | #if defined(WITH_GLEW)
25 | # include
26 | #else
27 | # define GL_GLEXT_PROTOTYPES
28 | #endif
29 |
30 | #if defined(WITH_GLES)
31 | # include
32 | # include
33 | #elif defined(WITH_GLES2)
34 | # include
35 | # include
36 | #elif defined(__APPLE__)
37 | # include
38 | # include
39 | #else
40 | # include
41 | # include
42 | #endif
43 |
44 | /*class OpenGLError : public Exception() {
45 | static void Check() {
46 | GLenum e;
47 | if ((e = glGetError()) == GL_NO_ERROR)
48 | return;
49 |
50 | OpenGLError e;
51 |
52 | while (glGetError) {
53 |
54 | }
55 | }
56 | };*/
57 |
58 | #endif
59 |
--------------------------------------------------------------------------------
/libglosm-client/mglu.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef MGLU_H
22 | #define MGLU_H
23 |
24 | #include "mglu.h"
25 |
26 | #include
27 |
28 | #include
29 |
30 | void mglFrustum(float left, float right, float bottom, float top, float znear, float zfar) {
31 | float matrix[16] = {
32 | 2.0f * znear / (right - left), 0.0f, 0.0f, 0.0f,
33 | 0.0f, 2.0f * znear / (top - bottom), 0.0f, 0.0f,
34 | (right + left) / (right - left), (top + bottom) / (top - bottom), - (zfar - znear) / (zfar - znear), -1.0f,
35 | 0.0f, 0.0f, -2.0f * znear * zfar / (zfar - znear), 0.0f,
36 | };
37 |
38 | glLoadMatrixf(matrix);
39 | }
40 |
41 | void mgluPerspective(float fovy, float aspect, float znear, float zfar) {
42 | float xmin, xmax, ymin, ymax;
43 |
44 | ymax = znear * tan(fovy * M_PI / 360.0f);
45 | ymin = -ymax;
46 | xmax = ymax * aspect;
47 | xmin = -xmax;
48 |
49 | mglFrustum(xmin, xmax, ymin, ymax, znear, zfar);
50 | }
51 |
52 | void mgluLookAt(float eyex, float eyey, float eyez, float centerx, float centery, float centerz, float upx, float upy, float upz) {
53 | Vector3f forward = (Vector3f(centerx, centery, centerz) - Vector3f(eyex, eyey, eyez)).Normalized();
54 | Vector3f side = forward.CrossProduct(Vector3f(upx, upy, upz)).Normalized();
55 | Vector3f up = side.CrossProduct(forward);
56 |
57 | float matrix[16] = {
58 | side.x, up.x, -forward.x, 0.0f,
59 | side.y, up.y, -forward.y, 0.0f,
60 | side.z, up.z, -forward.z, 0.0f,
61 | 0.0f, 0.0f, 0.0f, 1.0f,
62 | };
63 |
64 | glLoadMatrixf(matrix);
65 | glTranslatef(-eyex, -eyey, -eyez);
66 | }
67 |
68 | #endif
69 |
--------------------------------------------------------------------------------
/libglosm-client/mglu.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef MGLU_H
22 | #define MGLU_H
23 |
24 | /* Implementations of some libGLU functions */
25 |
26 | void mglFrustum(float left, float right, float bottom, float top, float znear, float zfar);
27 | void mgluPerspective(float fovy, float aspect, float znear, float zfar);
28 | void mgluLookAt(float eyex, float eyey, float eyez, float centerx, float centery, float centerz, float upx, float upy, float upz);
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/libglosm-geomgen/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Targets
2 | SET(SOURCES
3 | GeometryGenerator.cc
4 | MetricBasis.cc
5 | )
6 |
7 | SET(HEADERS
8 | glosm/GeometryGenerator.hh
9 | glosm/MetricBasis.hh
10 | )
11 |
12 | INCLUDE_DIRECTORIES(. ../libglosm-server)
13 |
14 | ADD_LIBRARY(glosm-geomgen SHARED ${SOURCES})
15 | TARGET_LINK_LIBRARIES(glosm-geomgen glosm-server)
16 |
17 | # Installation
18 | # SET_TARGET_PROPERTIES(glosm-geomgen PROPERTIES SOVERSION 1)
19 | INSTALL(FILES ${HEADERS} DESTINATION include/glosm)
20 |
21 | IF(NOT CMAKE_CROSSCOMPILING)
22 | INSTALL(TARGETS glosm-geomgen LIBRARY DESTINATION ${LIBDIR})
23 | ENDIF(NOT CMAKE_CROSSCOMPILING)
24 |
--------------------------------------------------------------------------------
/libglosm-geomgen/MetricBasis.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 | #include
23 |
24 | MetricBasis::MetricBasis(const Vector3i ref, const Vector3d& x, const Vector3d& y, const Vector3d& z):
25 | ref_(ref),
26 | x_(x),
27 | y_(y),
28 | z_(z) {
29 | }
30 |
31 | MetricBasis::MetricBasis(const Vector3i ref, const Vector3d& x):
32 | ref_(ref),
33 | x_(x),
34 | y_(-x.CrossProduct(Vector3d(0.0, 0.0, 1.0))),
35 | z_(Vector3d(0.0, 0.0, 1.0)) {
36 | }
37 |
38 | Vector3i MetricBasis::Get(double x, double y, double z) {
39 | return FromLocalMetric(x_ * x + y_ * y + z_ * z, ref_);
40 | }
41 |
--------------------------------------------------------------------------------
/libglosm-geomgen/glosm/GeometryGenerator.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef GEOMETRYGENERATOR_HH
22 | #define GEOMETRYGENERATOR_HH
23 |
24 | #include
25 | #include
26 | #include
27 |
28 | class OsmDatasource;
29 | class HeightmapDatasource;
30 | class Geometry;
31 |
32 | class GeometryGenerator : public GeometryDatasource {
33 | protected:
34 | const OsmDatasource& datasource_;
35 | HeightmapDatasource& heightmap_ds_;
36 |
37 | public:
38 | GeometryGenerator(const OsmDatasource& datasource, HeightmapDatasource& heightmapds);
39 | void GetGeometry(Geometry& geometry, const BBoxi& bbox, int flags = 0) const;
40 |
41 | virtual Vector2i GetCenter() const;
42 | virtual BBoxi GetBBox() const;
43 | };
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/libglosm-geomgen/glosm/MetricBasis.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef METRICBASIS_HH
22 | #define METRICBASIS_HH
23 |
24 | #include
25 |
26 | /**
27 | * Convenient metric basis class for geometry construction
28 | */
29 | class MetricBasis {
30 | public:
31 | /**
32 | * Creates basis out of 3 axis vectors (expected to be normalized)
33 | */
34 | MetricBasis(const Vector3i ref, const Vector3d& x, const Vector3d& y, const Vector3d& z);
35 |
36 | /**
37 | * Creates basis out of a single axis vectors (expected to be normalized)
38 | *
39 | * Z axis is considered to be [0, 0, 1] and Y is calculated as
40 | * perpendicular to XZ plane
41 | */
42 | MetricBasis(const Vector3i ref, const Vector3d& x);
43 |
44 | /**
45 | * Returns basis-relative point as global fixed-point coordinates
46 | */
47 | Vector3i Get(double x, double y, double z);
48 |
49 | protected:
50 | Vector3i ref_;
51 | Vector3d x_, y_, z_;
52 | };
53 |
54 | #endif
55 |
--------------------------------------------------------------------------------
/libglosm-server/BBox.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | #include
24 |
25 | #include
26 |
27 | template<>
28 | BBox BBox::ForEarth() {
29 | return BBox(-1800000000, -900000000, 1800000000, 900000000);
30 | }
31 |
32 | template<>
33 | BBox BBox::ForMercatorTile(int zoom, int x, int y) {
34 | double zoommult = 1.0 / (double)(1 << zoom);
35 |
36 | return BBox(
37 | (osmint_t)round(((double)x) * zoommult * 3600000000.0 - 1800000000.0),
38 | (osmint_t)round(-unmercator(((float)y + 1.0) * zoommult * M_PI * 2.0 - M_PI) / M_PI * 1800000000.0),
39 | (osmint_t)round(((double)x + 1.0) * zoommult * 3600000000.0 - 1800000000.0),
40 | (osmint_t)round(-unmercator(((float)y) * zoommult * M_PI * 2.0 - M_PI) / M_PI * 1800000000.0)
41 | );
42 | }
43 |
44 | template<>
45 | BBox BBox::ForGeoTile(int zoom, int x, int y) {
46 | double zoommult = 1.0 / (double)(1 << zoom);
47 |
48 | return BBox(
49 | (osmint_t)round(
50 | (double)x * zoommult * 3600000000.0 - 1800000000.0
51 | ),
52 | (osmint_t)round(
53 | -((double)y + 1.0) * zoommult * 1800000000.0 + 900000000.0
54 | ),
55 | (osmint_t)round(
56 | ((double)x + 1.0) * zoommult * 3600000000.0 - 1800000000.0
57 | ),
58 | (osmint_t)round(
59 | -(double)y * zoommult * 1800000000.0 + 900000000.0
60 | )
61 | );
62 | }
63 |
--------------------------------------------------------------------------------
/libglosm-server/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Depends
2 | FIND_PACKAGE(EXPAT REQUIRED)
3 | FIND_PACKAGE(Threads REQUIRED)
4 |
5 | # Type size checks
6 | INCLUDE(CheckTypeSize)
7 |
8 | SET(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/glosm/osmtypes.h")
9 | CHECK_TYPE_SIZE("osmid_t" OSMID_T_SIZE)
10 | CHECK_TYPE_SIZE("osmint_t" OSMINT_T_SIZE)
11 | CHECK_TYPE_SIZE("osmlong_t" OSMLONG_T_SIZE)
12 | CHECK_TYPE_SIZE("float" FLOAT_SIZE)
13 | SET(CMAKE_EXTRA_INCLUDE_FILES)
14 |
15 | IF (${OSMID_T_SIZE} LESS 8)
16 | MESSAGE(FATAL_ERROR "osmid_t size too small (likely easily fixable, see osmtypes.h)")
17 | ENDIF(${OSMID_T_SIZE} LESS 8)
18 | IF (${OSMINT_T_SIZE} LESS 4)
19 | MESSAGE(FATAL_ERROR "osmint_t size too small (likely easily fixable, see osmtypes.h)")
20 | ENDIF(${OSMINT_T_SIZE} LESS 4)
21 | IF (${OSMLONG_T_SIZE} LESS 8)
22 | MESSAGE(FATAL_ERROR "osmlong_t size too small (likely easily fixable, see osmtypes.h)")
23 | ENDIF(${OSMLONG_T_SIZE} LESS 8)
24 |
25 | # Options
26 | OPTION(TRUSTED_XML "Disable XML sanity checking for faster parsing" OFF)
27 |
28 | IF(TRUSTED_XML)
29 | ADD_DEFINITIONS(-DTRUSTED_XML)
30 | ENDIF(TRUSTED_XML)
31 |
32 | IF(WITH_GLES)
33 | ADD_DEFINITIONS(-DWITH_GLES)
34 | ENDIF(WITH_GLES)
35 |
36 | # Targets
37 | SET(SOURCES
38 | BBox.cc
39 | DummyHeightmap.cc
40 | Exception.cc
41 | Geometry.cc
42 | GeometryOperations.cc
43 | Guard.cc
44 | ParsingHelpers.cc
45 | PreloadedGPXDatasource.cc
46 | PreloadedXmlDatasource.cc
47 | SRTMDatasource.cc
48 | Timer.cc
49 | WayMerger.cc
50 | XMLParser.cc
51 | )
52 |
53 | SET(HEADERS
54 | glosm/BBox.hh
55 | glosm/DummyHeightmap.hh
56 | glosm/Exception.hh
57 | glosm/geomath.h
58 | glosm/Geometry.hh
59 | glosm/GeometryDatasource.hh
60 | glosm/GeometryOperations.hh
61 | glosm/GPXDatasource.hh
62 | glosm/Guard.hh
63 | glosm/HeightmapDatasource.hh
64 | glosm/id_map.hh
65 | glosm/Math.hh
66 | glosm/Misc.hh
67 | glosm/NonCopyable.hh
68 | glosm/OsmDatasource.hh
69 | glosm/osmtypes.h
70 | glosm/ParsingHelpers.hh
71 | glosm/PreloadedGPXDatasource.hh
72 | glosm/PreloadedXmlDatasource.hh
73 | glosm/SRTMDatasource.hh
74 | glosm/Timer.hh
75 | glosm/WayMerger.hh
76 | glosm/XMLParser.hh
77 | )
78 |
79 | INCLUDE_DIRECTORIES(. ${EXPAT_INCLUDE_DIR})
80 |
81 | ADD_LIBRARY(glosm-server SHARED ${SOURCES})
82 | TARGET_LINK_LIBRARIES(glosm-server ${EXPAT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
83 |
84 | # Installation
85 | # SET_TARGET_PROPERTIES(glosm-server PROPERTIES SOVERSION 1)
86 | INSTALL(FILES ${HEADERS} DESTINATION include/glosm)
87 |
88 | IF(NOT CMAKE_CROSSCOMPILING)
89 | INSTALL(TARGETS glosm-server LIBRARY DESTINATION ${LIBDIR})
90 | ENDIF(NOT CMAKE_CROSSCOMPILING)
91 |
--------------------------------------------------------------------------------
/libglosm-server/DummyHeightmap.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | DummyHeightmap::DummyHeightmap(osmint_t height) : height_(height) {
24 | }
25 |
26 | DummyHeightmap::~DummyHeightmap() {
27 | }
28 |
29 | void DummyHeightmap::GetHeightmap(const BBoxi& bbox, int extramargin, Heightmap& out) const {
30 | out.width = 2 + extramargin * 2;
31 | out.height = 2 + extramargin * 2;
32 |
33 | out.bbox = BBoxi(
34 | bbox.left - (bbox.right - bbox.left) * extramargin,
35 | bbox.bottom - (bbox.top - bbox.bottom) * extramargin,
36 | bbox.right + (bbox.right - bbox.left) * extramargin,
37 | bbox.top + (bbox.top - bbox.bottom) * extramargin
38 | );
39 |
40 | out.points.resize(out.width * out.height);
41 |
42 | for (Heightmap::HeightmapPoints::iterator i = out.points.begin(); i != out.points.end(); ++i)
43 | *i = height_;
44 | }
45 |
46 | osmint_t DummyHeightmap::GetHeight(const Vector2i& /*unused*/) const {
47 | return height_;
48 | }
49 |
--------------------------------------------------------------------------------
/libglosm-server/Exception.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | #include
24 | #include
25 |
26 | namespace Private {
27 | void SafeStringBuffer::EnsureSize(unsigned int size) {
28 | unsigned int newallocated_ = allocated_;
29 | while (size > newallocated_)
30 | newallocated_ *= 2;
31 |
32 | if (newallocated_ > allocated_) {
33 | char* newbuffer = new char[newallocated_];
34 | memcpy(newbuffer, buffer_, used_);
35 | delete[] buffer_;
36 | buffer_ = newbuffer;
37 | allocated_ = newallocated_;
38 | }
39 | }
40 |
41 | SafeStringBuffer::SafeStringBuffer(unsigned int reserve)
42 | : reserve_(reserve),
43 | allocated_(initial_size_ + reserve),
44 | used_(0),
45 | buffer_(new char[allocated_]) {
46 | }
47 |
48 | SafeStringBuffer::SafeStringBuffer(const char* message)
49 | : reserve_(0),
50 | allocated_(strlen(message) + 1),
51 | used_(allocated_ - 1),
52 | buffer_(new char[allocated_]) {
53 | strcpy(buffer_, message);
54 | }
55 |
56 | SafeStringBuffer::SafeStringBuffer(const SafeStringBuffer& other)
57 | : std::streambuf(),
58 | reserve_(other.reserve_),
59 | allocated_(other.allocated_),
60 | used_(other.used_),
61 | buffer_( new char[allocated_]) {
62 | memcpy(buffer_, other.buffer_, used_);
63 | }
64 |
65 | SafeStringBuffer::~SafeStringBuffer() {
66 | delete[] buffer_;
67 | }
68 |
69 | void SafeStringBuffer::SetReserve(unsigned int reserve) {
70 | EnsureSize(used_ + reserve + 1);
71 | reserve_ = reserve;
72 | }
73 |
74 | std::streamsize SafeStringBuffer::xsputn(const char* s, std::streamsize n) {
75 | EnsureSize(used_ + n + reserve_ + 1);
76 | memcpy(buffer_ + used_, s, n);
77 | used_ += n;
78 | return n;
79 | }
80 |
81 | std::streamsize SafeStringBuffer::AppendReserve(const char* s, std::streamsize n) throw() {
82 | if ((unsigned int)n > reserve_)
83 | n = reserve_;
84 |
85 | memcpy(buffer_ + used_, s, n);
86 | used_ += n;
87 | reserve_ -= n;
88 |
89 | return n;
90 | }
91 |
92 | const char* SafeStringBuffer::c_str() throw() {
93 | buffer_[used_] = '\0';
94 | return buffer_;
95 | }
96 |
97 | ExceptionBase::ExceptionBase() {
98 | }
99 |
100 | ExceptionBase::ExceptionBase(const ExceptionBase& e): std::exception(), message_(e.what()/*message_*/) {
101 | }
102 |
103 | ExceptionBase::~ExceptionBase() throw() {
104 | }
105 |
106 | const char* ExceptionBase::what() const throw() {
107 | return message_.c_str();
108 | }
109 | };
110 |
111 | SystemError::SystemError() : errno_(errno) {
112 | message_.SetReserve(strlen(strerror(errno_)) + 3);
113 | }
114 |
115 | SystemError::SystemError(int errn) : errno_(errn) {
116 | message_.SetReserve(strlen(strerror(errno_)) + 3);
117 | }
118 |
119 | SystemError::SystemError(const SystemError& e): Exception(e), errno_(e.errno_) {
120 | }
121 |
122 | SystemError::~SystemError() throw() {
123 | }
124 |
125 | const char* SystemError::what() const throw() {
126 | message_.AppendReserve(" (", 2);
127 | message_.AppendReserve(strerror(errno), strlen(strerror(errno)));
128 | message_.AppendReserve(")", 1);
129 | return message_.c_str();
130 | }
131 |
--------------------------------------------------------------------------------
/libglosm-server/Guard.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | Guard::Guard(pthread_mutex_t& mutex): mutex_(mutex) {
24 | pthread_mutex_lock(&mutex_);
25 | }
26 |
27 | Guard::~Guard() {
28 | pthread_mutex_unlock(&mutex_);
29 | }
30 |
--------------------------------------------------------------------------------
/libglosm-server/ParsingHelpers.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | int ParseCoord(const char* str) {
24 | return ParseInt<7>(str);
25 | }
26 |
27 | int ParseEle(const char* str) {
28 | return ParseInt<2>(str);
29 | }
30 |
31 | BBoxi ParseBounds(const char** atts) {
32 | BBoxi bbox(BBoxi::Empty());
33 |
34 | for (const char** att = atts; *att; ++att) {
35 | if (StrEq<-1>(*att, "minlat"))
36 | bbox.bottom = ParseCoord(*(++att));
37 | else if (StrEq<-1>(*att, "maxlat"))
38 | bbox.top = ParseCoord(*(++att));
39 | else if (StrEq<-1>(*att, "minlon"))
40 | bbox.left = ParseCoord(*(++att));
41 | else if (StrEq<-1>(*att, "maxlon"))
42 | bbox.right = ParseCoord(*(++att));
43 | else
44 | ++att;
45 | }
46 |
47 | if (bbox.IsEmpty())
48 | throw ParsingException() << "incorrect bounding box";
49 |
50 | return bbox;
51 | }
52 |
53 | BBoxi ParseBound(const char** atts) {
54 | BBoxi bbox(BBoxi::Empty());
55 |
56 | for (const char** att = atts; *att; ++att) {
57 | if (StrEq<-1>(*att, "box")) {
58 | std::string s(*(++att));
59 | /* comma positions */
60 | size_t cpos1, cpos2, cpos3;
61 | if ((cpos1 = s.find(',')) == std::string::npos)
62 | throw ParsingException() << "bad bbox format";
63 | if ((cpos2 = s.find(',', cpos1+1)) == std::string::npos)
64 | throw ParsingException() << "bad bbox format";
65 | if ((cpos3 = s.find(',', cpos2+1)) == std::string::npos)
66 | throw ParsingException() << "bad bbox format";
67 |
68 | bbox.bottom = ParseCoord(s.substr(0, cpos1).c_str());
69 | bbox.left = ParseCoord(s.substr(cpos1+1, cpos2-cpos1-1).c_str());
70 | bbox.top = ParseCoord(s.substr(cpos2+1, cpos3-cpos2-1).c_str());
71 | bbox.right = ParseCoord(s.substr(cpos3+1).c_str());
72 | } else {
73 | ++att;
74 | }
75 | }
76 |
77 | return bbox;
78 | }
79 |
--------------------------------------------------------------------------------
/libglosm-server/PreloadedGPXDatasource.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 | #include
23 |
24 | PreloadedGPXDatasource::PreloadedGPXDatasource() : XMLParser(XMLParser::HANDLE_ELEMENTS | XMLParser::HANDLE_CHARDATA) {
25 | }
26 |
27 | PreloadedGPXDatasource::~PreloadedGPXDatasource() {
28 | }
29 |
30 | void PreloadedGPXDatasource::StartElement(const char* name, const char** atts) {
31 | if (tag_level_ == 4 && current_tag_ == TRKPT && StrEq<-1>(name, "ele")) {
32 | current_tag_ = ELE;
33 | } else if (tag_level_ == 3 && current_tag_ == TRKSEG && StrEq<-1>(name, "trkpt")) {
34 | current_tag_ = TRKPT;
35 |
36 | int lat = 0;
37 | int lon = 0;
38 | for (const char** att = atts; *att; ++att) {
39 | if (StrEq<2>(*att, "lat"))
40 | lat = ParseCoord(*(++att));
41 | else if (StrEq<2>(*att, "lon"))
42 | lon = ParseCoord(*(++att));
43 | else
44 | ++att;
45 | }
46 |
47 | points_.push_back(Vector3i(lon, lat, 0));
48 | } else if (tag_level_ == 2 && current_tag_ == TRK && StrEq<-1>(name, "trkseg")) {
49 | current_tag_ = TRKSEG;
50 | } else if (tag_level_ == 1 && current_tag_ == GPX && StrEq<-1>(name, "trk")) {
51 | current_tag_ = TRK;
52 | } else if (tag_level_ == 0 && current_tag_ == NONE && StrEq<-1>(name, "gpx")) {
53 | current_tag_ = GPX;
54 | } else if (tag_level_ == 0) {
55 | throw ParsingException() << "unexpected root element (" << name << " instead of gpx)";
56 | }
57 |
58 | ++tag_level_;
59 | }
60 |
61 | void PreloadedGPXDatasource::EndElement(const char* /*name*/) {
62 | if (tag_level_ == 5 && current_tag_ == ELE)
63 | current_tag_ = TRKPT;
64 | else if (tag_level_ == 4 && current_tag_ == TRKPT)
65 | current_tag_ = TRKSEG;
66 | else if (tag_level_ == 3 && current_tag_ == TRKSEG)
67 | current_tag_ = TRK;
68 | else if (tag_level_ == 2 && current_tag_ == TRK)
69 | current_tag_ = GPX;
70 | else if (tag_level_ == 1 && current_tag_ == GPX)
71 | current_tag_ = NONE;
72 |
73 | --tag_level_;
74 | }
75 |
76 | void PreloadedGPXDatasource::CharacterData(const char* data, int len) {
77 | std::string buf(data, len);
78 | if (tag_level_ == 5 && current_tag_ == ELE)
79 | points_.back().z = ParseEle(buf.c_str());
80 | }
81 |
82 | void PreloadedGPXDatasource::Load(const char* filename) {
83 | current_tag_ = NONE;
84 | tag_level_ = 0;
85 |
86 | XMLParser::Load(filename);
87 | }
88 |
89 | void PreloadedGPXDatasource::GetPoints(std::vector& out, const BBoxi& bbox) const {
90 | for (PointsVector::const_iterator i = points_.begin(); i != points_.end(); ++i)
91 | if (bbox.Contains(*i))
92 | out.push_back(*i);
93 | }
94 |
--------------------------------------------------------------------------------
/libglosm-server/Timer.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | #include /* for NULL */
24 |
25 | Timer::Timer() {
26 | Count();
27 | }
28 |
29 | float Timer::Count() {
30 | struct timeval current;
31 | gettimeofday(¤t, NULL);
32 |
33 | float retval = (float)(current.tv_sec - last_.tv_sec) + (float)(current.tv_usec - last_.tv_usec)/1000000.0f;
34 |
35 | last_ = current;
36 |
37 | return retval;
38 | }
39 |
--------------------------------------------------------------------------------
/libglosm-server/WayMerger.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 | #include
23 |
24 | #include
25 | #include
26 |
27 | WayMerger::WayMerger() {
28 | }
29 |
30 | void WayMerger::AddWay(const OsmDatasource::Way::NodesList& nodes) {
31 | way_by_node.insert(std::make_pair(nodes.front(), &nodes));
32 | way_by_node_rev.insert(std::make_pair(nodes.back(), &nodes));
33 | }
34 |
35 | bool WayMerger::GetNextWay(OsmDatasource::Way::NodesList& outnodes) {
36 | OsmDatasource::Way::NodesList tempnodes;
37 |
38 | std::back_insert_iterator inserter(tempnodes);
39 |
40 | const OsmDatasource::Way::NodesList* next_chain;
41 | while (!way_by_node.empty()) {
42 | if (tempnodes.empty()) {
43 | /* no current nodes, add just any chain */
44 | next_chain = PickChain();
45 | assert(next_chain);
46 | std::copy(next_chain->begin(), next_chain->end(), inserter);
47 | } else {
48 | /* find next chain, first try front map, then reverse */
49 | if ((next_chain = PickChain(tempnodes.back())) != NULL) {
50 | std::copy(++next_chain->begin(), next_chain->end(), inserter);
51 | } else if ((next_chain = PickChain(tempnodes.back(), true)) != NULL) {
52 | std::copy(++next_chain->rbegin(), next_chain->rend(), inserter);
53 | } else {
54 | /* no suitable next chain, drop partial way */
55 | /* XXX: (or, we can return it if we need unclosed ways too */
56 | tempnodes.clear();
57 | }
58 | }
59 |
60 | /* check if we have complete cycle */
61 | if (!tempnodes.empty() && tempnodes.front() == tempnodes.back()) {
62 | outnodes.swap(tempnodes);
63 | return true;
64 | }
65 | }
66 |
67 | return false;
68 | }
69 |
70 | const OsmDatasource::Way::NodesList* WayMerger::PickChain(osmid_t id, bool reverse) {
71 | WayByTipMap& primary = reverse ? way_by_node_rev : way_by_node;
72 | WayByTipMap& secondary = reverse ? way_by_node : way_by_node_rev;
73 |
74 | /* find chain starting with given id in primary map */
75 | WayByTipMap::iterator primary_iterator = ((id == 0) ? primary.begin() : primary.find(id));
76 | if (primary_iterator == primary.end())
77 | return NULL;
78 |
79 | /* save chain poiter which we will return */
80 | const OsmDatasource::Way::NodesList* ret = primary_iterator->second;
81 |
82 | /* find the same chain in the other map */
83 | std::pair range =
84 | secondary.equal_range(reverse ? ret->front() : ret->back());
85 |
86 | WayByTipMap::iterator secondary_iterator;
87 | for (secondary_iterator = range.first; secondary_iterator != range.second; ++secondary_iterator) {
88 | if (secondary_iterator->second == ret) {
89 | break;
90 | }
91 | }
92 |
93 | assert(secondary_iterator != range.second);
94 |
95 | /* delete chain references from both maps */
96 | secondary.erase(secondary_iterator);
97 | primary.erase(primary_iterator);
98 |
99 | return ret;
100 | }
101 |
--------------------------------------------------------------------------------
/libglosm-server/XMLParser.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #include
22 |
23 | #include
24 | #include
25 | #include
26 |
27 | #include
28 |
29 | XMLParser::XMLParser(int flags) : flags_(flags) {
30 | }
31 |
32 | XMLParser::~XMLParser() {
33 | }
34 |
35 | void XMLParser::StartElementWrapper(void* userData, const char* name, const char** atts) {
36 | static_cast(userData)->StartElement(name, atts);
37 | }
38 |
39 | void XMLParser::EndElementWrapper(void* userData, const char* name) {
40 | static_cast(userData)->EndElement(name);
41 | }
42 |
43 | void XMLParser::CharacterDataWrapper(void* userData, const char* data, int len) {
44 | static_cast(userData)->CharacterData(data, len);
45 | }
46 |
47 | void XMLParser::StartElement(const char* /*unused*/, const char** /*unused*/) {
48 | }
49 |
50 | void XMLParser::EndElement(const char* /*unused*/) {
51 | }
52 |
53 | void XMLParser::CharacterData(const char* /*unused*/, int /*unused*/) {
54 | }
55 |
56 | void XMLParser::Load(const char* filename) {
57 | int f = 0;
58 | XML_Parser parser = NULL;
59 |
60 | /* if filename = "-", work with stdin */
61 | if (strcmp(filename, "-") != 0 && (f = open(filename, O_RDONLY)) == -1)
62 | throw SystemError() << "cannot open input file";
63 |
64 | /* Create and setup parser */
65 | if ((parser = XML_ParserCreate(NULL)) == NULL) {
66 | close(f);
67 | throw Exception() << "cannot create XML parser";
68 | }
69 |
70 | if (flags_ & HANDLE_ELEMENTS)
71 | XML_SetElementHandler(parser, StartElementWrapper, EndElementWrapper);
72 | if (flags_ & HANDLE_CHARDATA)
73 | XML_SetCharacterDataHandler(parser, CharacterDataWrapper);
74 |
75 | XML_SetUserData(parser, this);
76 |
77 | /* Parse file */
78 | try {
79 | char buf[65536];
80 | ssize_t len;
81 | do {
82 | if ((len = read(f, buf, sizeof(buf))) < 0)
83 | throw SystemError() << "input read error";
84 | if (XML_Parse(parser, buf, len, len == 0) == XML_STATUS_ERROR)
85 | throw ParsingException() << XML_ErrorString(XML_GetErrorCode(parser));
86 | } while (len != 0);
87 | } catch (ParsingException &e) {
88 | ParsingException verbose;
89 | verbose << "input parsing error: " << e.what() << " at line " << XML_GetCurrentLineNumber(parser) << " pos " << XML_GetCurrentColumnNumber(parser);
90 | close(f);
91 | XML_ParserFree(parser);
92 | throw verbose;
93 | } catch (...) {
94 | close(f);
95 | XML_ParserFree(parser);
96 | throw;
97 | }
98 |
99 | XML_ParserFree(parser);
100 | close(f);
101 | }
102 |
--------------------------------------------------------------------------------
/libglosm-server/glosm/DummyHeightmap.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef DUMMYHEIGHTMAP_HH
22 | #define DUMMYHEIGHTMAP_HH
23 |
24 | #include
25 |
26 | class DummyHeightmap : public HeightmapDatasource {
27 | protected:
28 | osmint_t height_;
29 |
30 | public:
31 | DummyHeightmap(osmint_t height = 0);
32 | virtual ~DummyHeightmap();
33 |
34 | virtual void GetHeightmap(const BBoxi& bbox, int extramargin, Heightmap& out) const;
35 | virtual osmint_t GetHeight(const Vector2i& where) const;
36 | };
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/libglosm-server/glosm/Exception.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef EXCEPTION_HH
22 | #define EXCEPTION_HH
23 |
24 | #include
25 | #include
26 |
27 | namespace Private {
28 | /**
29 | * Safe string buffer to be used in exceptions.
30 | *
31 | * As you may know, std::exception::what() is has no-throw
32 | * exception specifier, thus you should not throw in what(),
33 | * or else the program may terminate during exception
34 | * handling (even if all exceptions are handled properly).
35 | *
36 | * Stock IOstream stringbuf is unsafe from this point of view
37 | * as its str() method does construct string object which may
38 | * throw, so we use our own buffer here. It may be normally
39 | * used with std::ostream, yet it has safe c_str() method which
40 | * never throws. In addition to that, it handles space reserve
41 | * so data may be appended
42 | */
43 | class SafeStringBuffer : public std::streambuf {
44 | protected:
45 | /** initial size of a buffer */
46 | static const unsigned int initial_size_ = 64;
47 |
48 | protected:
49 | unsigned int reserve_;
50 | unsigned int allocated_;
51 | unsigned int used_;
52 | char* buffer_;
53 |
54 | protected:
55 | /**
56 | * Ensures that buffer has enough space expanding it if necessary
57 | *
58 | * @param size required buffer size
59 | */
60 | void EnsureSize(unsigned int size);
61 |
62 | public:
63 | /**
64 | * Constructs empty string buffer
65 | *
66 | * @param reserve specifies length of reserved buffer part
67 | */
68 | SafeStringBuffer(unsigned int reserve = 0);
69 |
70 | /**
71 | * Constructs buffer and initializes it with giver string
72 | *
73 | * @param message initial value
74 | */
75 | SafeStringBuffer(const char* message);
76 |
77 | /**
78 | * Constricts copy of other
79 | */
80 | SafeStringBuffer(const SafeStringBuffer& other);
81 |
82 | /**
83 | * Destructor
84 | */
85 | ~SafeStringBuffer();
86 |
87 | /**
88 | * Changes reserve for the buffer expanding it if necessry
89 | *
90 | * @param reserve new reserve value
91 | */
92 | void SetReserve(unsigned int reserve);
93 |
94 | /**
95 | * Append data to the buffer
96 | *
97 | * This function is used from ostream to append data to the buffer.
98 | *
99 | * @param s pointer to data
100 | * @param n data length
101 | *
102 | * @return number of bytes appended (always n)
103 | */
104 | std::streamsize xsputn(const char* s, std::streamsize n);
105 |
106 | /**
107 | * Safely append data to the buffer within the reserve
108 | *
109 | * This may be safely used in what() to append additional data
110 | * (such ass strerror) to the end of message.
111 | *
112 | * @param s pointer to data
113 | * @param n data length
114 | *
115 | * @return number of bytes appended
116 | */
117 | std::streamsize AppendReserve(const char* s, std::streamsize n) throw();
118 |
119 | /**
120 | * Safely get pointer to buffer contents
121 | *
122 | * @return pointer to null-terminated buffer contents
123 | */
124 | const char* c_str() throw();
125 | };
126 |
127 | /**
128 | * Convenient exception class which supports stream-like appending
129 | *
130 | * Example:
131 | * @code throw Exception("foo") << ", also baz and " << 1 << 2 << 3; @endcode
132 | */
133 | class ExceptionBase: public std::exception {
134 | protected:
135 | /* being mutable allows appending data to const
136 | * ExceptionBase. See operator<< below for the
137 | * explanation of why const is needed */
138 | mutable SafeStringBuffer message_;
139 |
140 | public:
141 | /**
142 | * Constructs empty exception
143 | */
144 | ExceptionBase();
145 |
146 | /**
147 | * Constructs copy of e
148 | */
149 | ExceptionBase(const ExceptionBase& e);
150 |
151 | /**
152 | * Destructor
153 | */
154 | virtual ~ExceptionBase() throw();
155 |
156 | /**
157 | * Appends data to exception's string buffer
158 | */
159 | template
160 | void Append(const T& t) const {
161 | std::ostream stream(&message_);
162 | (std::ostream&)stream << t;
163 | }
164 |
165 | /**
166 | * Returns exception buffer contetns as a C string
167 | */
168 | virtual const char* what() const throw();
169 | };
170 |
171 | /**
172 | * Append operator for exception
173 | *
174 | * This just forwards all << calls to Exception which in
175 | * turn forwards them to std::ostream build around
176 | * SafeStringBuffer.
177 | *
178 | * @note This is put under the namespace to not be visible
179 | * from other parts of the program.
180 | *
181 | * @node This is intended to be used on const Exception
182 | * classes because C++ doesn't allow references to non-const
183 | * temporary objects. Pity. However, C++0x brings r-value
184 | * references which can make this look a bit better.
185 | */
186 | template
187 | static const E& operator<<(const E& e, const T& t) {
188 | e.Append(t);
189 | return e;
190 | }
191 | };
192 |
193 | /**
194 | * Generic exception
195 | */
196 | class Exception: public Private::ExceptionBase {
197 | };
198 |
199 | /**
200 | * System error that automatically appends strerror to the message
201 | */
202 | class SystemError: public Exception {
203 | protected:
204 | int errno_;
205 |
206 | public:
207 | SystemError();
208 | SystemError(int errn);
209 | SystemError(const SystemError& e);
210 | virtual ~SystemError() throw();
211 | virtual const char* what() const throw();
212 | };
213 |
214 | #endif
215 |
--------------------------------------------------------------------------------
/libglosm-server/glosm/GPXDatasource.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef GPXDATASOURCE_HH
22 | #define GPXDATASOURCE_HH
23 |
24 | #include
25 | #include
26 |
27 | #include
28 |
29 | /**
30 | * Abstract base class for sources of GPX data.
31 | */
32 | class GPXDatasource {
33 | public:
34 | virtual void GetPoints(std::vector& out, const BBoxi& bbox) const = 0;
35 | };
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/libglosm-server/glosm/Geometry.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef GEOMETRY_HH
22 | #define GEOMETRY_HH
23 |
24 | #include
25 | #include
26 |
27 | #include
28 |
29 | /**
30 | * 3D geometry in global fixed-point coordinates.
31 | *
32 | * This class represents portable geometry which comes from
33 | * GeometryGenerator and may be stored, serialized/deserialized,
34 | * transferred via the net and in the end is to be converted to
35 | * local floating-point geometry for rendering.
36 | *
37 | * @todo this is pretty non-general approach: triangles and quads
38 | * should likely be merged into a single primitive. Need testing for
39 | * speed impact on quads vs. indexed triangle strips. If strips don't
40 | * bring too buch performance drop, quads should be eliminated. This
41 | * will also open door for further geom optimizations like merging
42 | * triangle groups into strips and fans.
43 | *
44 | * @note just for a note: most of polygon geometry generated for urban
45 | * area currently are quads (~10x more quads than triangles). Changing
46 | * quads to triangle pairs is 12% more geometry generation time, 20%
47 | * less fps and more memory, so for now they're quite useful.
48 | */
49 | class Geometry {
50 | public:
51 | typedef std::vector VertexVector;
52 | typedef std::vector LengthVector;
53 |
54 | protected:
55 | VertexVector lines_vertices_;
56 | LengthVector lines_lengths_;
57 |
58 | VertexVector convex_vertices_;
59 | LengthVector convex_lengths_;
60 |
61 | public:
62 | Geometry();
63 |
64 | void AddLine(const Vector3i& a, const Vector3i& b);
65 | void AddTriangle(const Vector3i& a, const Vector3i& b, const Vector3i& c);
66 | void AddQuad(const Vector3i& a, const Vector3i& b, const Vector3i& c, const Vector3i& d);
67 | void AddConvex(const std::vector& v);
68 | void AddLine(const std::vector& v);
69 |
70 | void StartLine();
71 | void AppendLine(const Vector3i& v);
72 |
73 | void StartConvex();
74 | void AppendConvex(const Vector3i& v);
75 |
76 | const VertexVector& GetLinesVertices() const;
77 | const LengthVector& GetLinesLengths() const;
78 |
79 | const VertexVector& GetConvexVertices() const;
80 | const LengthVector& GetConvexLengths() const;
81 |
82 | void Append(const Geometry& other);
83 | void AppendCropped(const Geometry& other, const BBoxi& bbox);
84 |
85 | void AddCroppedConvex(const Vector3i* v, unsigned int size, const BBoxi& bbox);
86 | void AddCroppedLine(const Vector3i* v, unsigned int size, const BBoxi& bbox);
87 |
88 | void Serialize() const;
89 | void DeSerialize();
90 | };
91 |
92 | #endif
93 |
--------------------------------------------------------------------------------
/libglosm-server/glosm/GeometryDatasource.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef GEOMETRYDATASOURCE_HH
22 | #define GEOMETRYDATASOURCE_HH
23 |
24 | #include
25 | #include
26 |
27 | class Geometry;
28 |
29 | /**
30 | * Abstract base class for all Geometry sources including Geometry
31 | * generators.
32 | */
33 | class GeometryDatasource {
34 | public:
35 | enum Flags {
36 | GROUND = 0x1,
37 | DETAIL = 0x2,
38 |
39 | EVERYTHING = 0x3,
40 | };
41 |
42 | public:
43 | virtual void GetGeometry(Geometry& geometry, const BBoxi& bbox, int flags = 0) const = 0;
44 |
45 | /** Returns the center of available area */
46 | virtual Vector2i GetCenter() const {
47 | return Vector2i(0, 0);
48 | }
49 |
50 | /** Returns the bounding box of available area */
51 | virtual BBoxi GetBBox() const {
52 | return BBoxi::ForEarth();
53 | }
54 | };
55 |
56 | #endif
57 |
--------------------------------------------------------------------------------
/libglosm-server/glosm/GeometryOperations.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef GEOMETRYOPERATIONS_HH
22 | #define GEOMETRYOPERATIONS_HH
23 |
24 | #include
25 | #include
26 |
27 | /**
28 | * Intersect segment with horizontal line
29 | *
30 | * @param one first point of segment
31 | * @param two second point of segment
32 | * @param y y-coordinate for line
33 | * @param out reference to output value
34 | * @return whether there was an intersection
35 | */
36 | bool IntersectSegmentWithHorizontal(const Vector3i& one, const Vector3i& two, osmint_t y, Vector3i& out);
37 |
38 | /**
39 | * Intersect segment with vertical line
40 | *
41 | * @param one first point of segment
42 | * @param two second point of segment
43 | * @param x x-coordinate of line
44 | * @param out reference to output value
45 | * @return whether there was an intersection
46 | */
47 | bool IntersectSegmentWithVertical(const Vector3i& one, const Vector3i& two, osmint_t x, Vector3i& out);
48 |
49 | /**
50 | * Intersect segment with one of bounding box sides
51 | *
52 | * @param one first point of segment
53 | * @param two second point of segment
54 | * @param bbox bounding box
55 | * @param side side of bounding box
56 | * @param out reference to output value
57 | * @return whether there was an intersection
58 | */
59 | bool IntersectSegmentWithBBoxSide(const Vector3i& one, const Vector3i& two, const BBoxi& bbox, BBoxi::Side side, Vector3i& out);
60 |
61 | /**
62 | * Intersect segment with one of bounding box sides (non-inclusive version)
63 | *
64 | * @see IntersectSegmentWithBBoxSide
65 | */
66 | static inline bool IntersectSegmentWithBBoxSideNI(const Vector3i& one, const Vector3i& two, const BBoxi& bbox, BBoxi::Side side, Vector3i& out) {
67 | return IntersectSegmentWithBBoxSide(one, two, bbox, side, out) && out != one && out != two;
68 | }
69 |
70 | /**
71 | * Intersect segment with bounding box
72 | *
73 | * @param one first point of segment
74 | * @param two second point of segment
75 | * @param bbox bounding box
76 | * @param out reference to output value
77 | * @return whether there was an intersection
78 | */
79 | BBoxi::Side IntersectSegmentWithBBox(const Vector3i& one, const Vector3i& two, const BBoxi& bbox, Vector3i& out);
80 |
81 | /**
82 | * Intersect segment with bounding box
83 | *
84 | * This function checks intersection with sides of the bounding box
85 | * in the reverse order compared to IntersectSegmentWithBBox, so if
86 | * there are two intersection points, IntersectSegmentWithBBox2 will
87 | * find another one
88 | *
89 | * @param one first point of segment
90 | * @param two second point of segment
91 | * @param bbox bounding box
92 | * @param out reference to output value
93 | * @return whether there was an intersection
94 | */
95 | BBoxi::Side IntersectSegmentWithBBox2(const Vector3i& one, const Vector3i& two, const BBoxi& bbox, Vector3i& out);
96 |
97 | /**
98 | * Crops segment with bounding box
99 | *
100 | * @param one first point of segment
101 | * @param two second point of segment
102 | * @param bbox bounding box
103 | * @param outone (output) first point of cropped segment
104 | * @param outone (output) second point of cropped segment
105 | * @return whether there was an intersection
106 | */
107 | bool CropSegmentByBBox(const Vector3i& one, const Vector3i& two, const BBoxi& bbox, Vector3i& outone, Vector3i& outtwo);
108 |
109 | Vector3d ToLocalMetric(const Vector3i& what, const Vector3i& ref);
110 | Vector3i FromLocalMetric(const Vector3d& what, const Vector3i& ref);
111 |
112 | float ApproxDistanceSquare(const BBoxi& bbox, const Vector3i& vec);
113 |
114 | #endif
115 |
--------------------------------------------------------------------------------
/libglosm-server/glosm/Guard.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef GUARD_HH
22 | #define GUARD_HH
23 |
24 | #include
25 |
26 | /**
27 | * Simple guard class
28 | */
29 | class Guard {
30 | public:
31 | Guard(pthread_mutex_t& mutex);
32 | ~Guard();
33 |
34 | protected:
35 | pthread_mutex_t& mutex_;
36 | };
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/libglosm-server/glosm/HeightmapDatasource.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef HEIGHTMAPDATASOURCE_HH
22 | #define HEIGHTMAPDATASOURCE_HH
23 |
24 | #include
25 | #include
26 |
27 | #include
28 |
29 | /**
30 | * Abstract base class for sources of heightmap data.
31 | */
32 | class HeightmapDatasource {
33 | public:
34 | struct Heightmap {
35 | typedef std::vector HeightmapPoints;
36 |
37 | HeightmapPoints points;
38 | int width;
39 | int height;
40 |
41 | BBoxi bbox;
42 | };
43 |
44 | public:
45 | virtual ~HeightmapDatasource() {}
46 |
47 | virtual void GetHeightmap(const BBoxi& bbox, int extramargin, Heightmap& out) const = 0;
48 | virtual osmint_t GetHeight(const Vector2i& where) const = 0;
49 | };
50 |
51 | #endif
52 |
--------------------------------------------------------------------------------
/libglosm-server/glosm/Misc.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef MISC_HH
22 | #define MISC_HH
23 |
24 | /* collection of reinvented bicycles; it's better than using weighty
25 | * boost while it's small enough */
26 |
27 | #define COMPILE_TIME_ASSERT(V) \
28 | { typedef int __libglosm_compile_time_assert_fail[1 - 2*!(V)]; }
29 |
30 | static inline bool IsBigEndian() {
31 | static const union {
32 | unsigned char bytes[4];
33 | uint32_t value;
34 | } endianess_checker = {
35 | { 0, 1, 2, 3 }
36 | };
37 |
38 | return endianess_checker.value == 0x00010203UL;
39 | }
40 |
41 | static inline bool IsLittleEndian() {
42 | static const union {
43 | unsigned char bytes[4];
44 | uint32_t value;
45 | } endianess_checker = {
46 | { 0, 1, 2, 3 }
47 | };
48 |
49 | return endianess_checker.value == 0x03020100UL;
50 | }
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/libglosm-server/glosm/NonCopyable.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef NONCOPYABLE_HH
22 | #define NONCOPYABLE_HH
23 |
24 | /**
25 | * A convenient way to disable copying of objects of specific classes
26 | */
27 | class NonCopyable {
28 | protected:
29 | NonCopyable() {
30 | }
31 |
32 | private:
33 | NonCopyable(const NonCopyable&);
34 | NonCopyable& operator =(const NonCopyable&);
35 | };
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/libglosm-server/glosm/OsmDatasource.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010-2012 Dmitry Marakasov
3 | *
4 | * This file is part of glosm.
5 | *
6 | * glosm is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, either version 3 of the
9 | * License, or (at your option) any later version.
10 | *
11 | * glosm 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 Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public
17 | * License along with glosm. If not, see
18 | * .
19 | */
20 |
21 | #ifndef OSMDATASOURCE_HH
22 | #define OSMDATASOURCE_HH
23 |
24 | #include
25 | #include
26 |
27 | #include
28 | #include
29 | #include