Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support window build #35

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e2f2bc3
fix compiler bug for MSVC
baothientran Nov 11, 2020
c6d3ffe
fix filesystem to string
baothientran Nov 11, 2020
441436b
fix MSVC compiler error in Tests
baothientran Nov 12, 2020
b9001da
add MSVC definition flags to prevent warning about deprecated CPP 17
baothientran Nov 12, 2020
dbaac6a
use ref to traverse loop
baothientran Nov 12, 2020
914b03c
remove jpeg dependency for OSG
baothientran Nov 12, 2020
6edae06
add visual studio config to gitignore
baothientran Nov 12, 2020
922a9b2
disable cxxopts examples and tests
baothientran Nov 12, 2020
7788db6
add OSG_LIBRARY_STATIC to make MSVC build
baothientran Nov 12, 2020
83dc6f6
add out directory to gitignore
baothientran Nov 12, 2020
9c8b8ad
change gdal setting in cmake
baothientran Nov 16, 2020
2207f88
make sure all test data files are closed before removing output direc…
baothientran Nov 29, 2020
6a3eb55
Merge branch 'master' into window-build
baothientran Nov 29, 2020
c67dd8e
fix simplified mesh test to make sure file close before removing outp…
baothientran Nov 29, 2020
afb7b41
update CHANGES.md
baothientran Nov 29, 2020
60f2c32
add window build instruction
baothientran Nov 29, 2020
6f7825b
fix image link for window build
baothientran Nov 29, 2020
34c8bcc
remove new line below window image in README
baothientran Nov 29, 2020
05e973c
specify the test executables for each build
baothientran Nov 29, 2020
343fd47
remove unused math header in Elevation
baothientran Nov 30, 2020
429f638
Merge branch 'master' into window-build
baothientran Dec 5, 2020
eec1c45
fix tab format
baothientran Dec 5, 2020
9d73c42
Merge branch 'master' into window-build
lilleyse Dec 7, 2020
95745e7
Update CHANGES.md
lilleyse Dec 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
*.user
*.vscode
*.vs
CMakeSettings.json
Build
build
out
7 changes: 3 additions & 4 deletions CDBTo3DTiles/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project(CDBTo3DTiles)

find_package(GDAL 3.0.4 REQUIRED)
find_package(GDAL 2.4.1 REQUIRED)

add_library(CDBTo3DTiles
src/Scene.cpp
Expand All @@ -26,7 +26,7 @@ set(PRIVATE_THIRD_PARTY_INCLUDE_PATHS
${osg_INCLUDE_DIRS}
${earcut_INCLUDE_DIRS}
${nlohmann_json_INCLUDE_DIRS}
${GDAL_INCLUDE_DIRS}
${GDAL_INCLUDE_DIR}
${tinygltf_INCLUDE_DIRS}
)

Expand All @@ -43,14 +43,13 @@ target_link_libraries(CDBTo3DTiles
osgdb_openflight
osgdb_rgb
osgdb_png
osgdb_jpeg
osgdb_zip
osgDB
osg
OpenThreads
meshoptimizer
Core
${GDAL_LIBRARIES})
${GDAL_LIBRARY})

set_property(TARGET CDBTo3DTiles
PROPERTY
Expand Down
8 changes: 4 additions & 4 deletions CDBTo3DTiles/src/CDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void CDB::traverseModelsAttributes(const CDBTile *root,
const auto &featureFile = root->getCustomContentURI();
if (featureFile) {
GDALDatasetUniquePtr attributesDataset = GDALDatasetUniquePtr(
(GDALDataset *) GDALOpenEx(featureFile->c_str(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr));
(GDALDataset *) GDALOpenEx(featureFile->string().c_str(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr));

if (attributesDataset) {
CDBModelsAttributes model(std::move(attributesDataset), *root, m_path);
Expand Down Expand Up @@ -228,7 +228,7 @@ void CDB::traverseModelsAttributes(const CDBTile *root,
auto elevationFile = m_path
/ (parentElevation->getRelativePath().string() + ".tif");
elevationData = GDALDatasetUniquePtr(
(GDALDataset *) GDALOpen(elevationFile.c_str(), GDALAccess::GA_ReadOnly));
(GDALDataset *) GDALOpen(elevationFile.string().c_str(), GDALAccess::GA_ReadOnly));

if (elevationData) {
for (auto &point : model.getCartographicPositions()) {
Expand Down Expand Up @@ -365,7 +365,7 @@ void CDB::clampPointsOnElevationTileset(std::vector<Core::Cartographic> &points,
const auto &elevationTile = elevation.first;
auto elevationFile = m_path / (elevationTile.getRelativePath().string() + ".tif");
GDALDatasetUniquePtr rasterData = GDALDatasetUniquePtr(
(GDALDataset *) GDALOpen(elevationFile.c_str(), GDALAccess::GA_ReadOnly));
(GDALDataset *) GDALOpen(elevationFile.string().c_str(), GDALAccess::GA_ReadOnly));

if (rasterData == nullptr) {
continue;
Expand Down Expand Up @@ -455,7 +455,7 @@ std::optional<CDBImagery> CDB::getImagery(const CDBTile &tile) const
}

auto imageryDataset = GDALDatasetUniquePtr(
(GDALDataset *) GDALOpen(imageryPath.c_str(), GDALAccess::GA_ReadOnly));
(GDALDataset *) GDALOpen(imageryPath.string().c_str(), GDALAccess::GA_ReadOnly));

if (!imageryDataset) {
return std::nullopt;
Expand Down
2 changes: 1 addition & 1 deletion CDBTo3DTiles/src/CDBAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ std::optional<CDBClassesAttributes> CDBModelsAttributes::createClassesAttributes
}

GDALDatasetUniquePtr dataset = GDALDatasetUniquePtr(
(GDALDataset *) GDALOpenEx(classLevelPath.c_str(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr));
(GDALDataset *) GDALOpenEx(classLevelPath.string().c_str(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr));
if (!dataset) {
return std::nullopt;
}
Expand Down
1 change: 0 additions & 1 deletion CDBTo3DTiles/src/CDBElevation.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "CDBElevation.h"
#include "BoundingRegion.h"
#include "Ellipsoid.h"
#include "Math.h"
#include "glm/gtc/type_ptr.hpp"
#include "meshoptimizer.h"

Expand Down
10 changes: 5 additions & 5 deletions CDBTo3DTiles/src/CDBGeometryVectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ std::optional<CDBGeometryVectors> CDBGeometryVectors::createFromFile(const std::
|| CS_2 == static_cast<int>(CDBVectorCS2::LinealFeature)
|| CS_2 == static_cast<int>(CDBVectorCS2::PolygonFeature)) {
GDALDatasetUniquePtr dataset = GDALDatasetUniquePtr(
(GDALDataset *) GDALOpenEx(file.c_str(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr));
(GDALDataset *) GDALOpenEx(file.string().c_str(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr));
if (dataset) {
auto geometryVector = CDBGeometryVectors(std::move(dataset), *tile, CDBPath);

Expand Down Expand Up @@ -93,7 +93,7 @@ void CDBGeometryVectors::createPoint(GDALDataset *vectorDataset)

auto center = m_mesh.aabb->center();
m_mesh.positionRTCs.reserve(m_mesh.positions.size());
for (auto position : m_mesh.positions) {
for (const auto &position : m_mesh.positions) {
m_mesh.positionRTCs.emplace_back(position - center);
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ void CDBGeometryVectors::createPolyline(GDALDataset *vectorDataset)

auto center = m_mesh.aabb->center();
m_mesh.positionRTCs.reserve(m_mesh.positions.size());
for (auto position : m_mesh.positions) {
for (const auto &position : m_mesh.positions) {
m_mesh.positionRTCs.emplace_back(position - center);
}
}
Expand Down Expand Up @@ -177,7 +177,7 @@ void CDBGeometryVectors::createPolygonOrMultiPolygon(GDALDataset *vectorDataset)

auto center = m_mesh.aabb->center();
m_mesh.positionRTCs.reserve(m_mesh.positions.size());
for (auto position : m_mesh.positions) {
for (const auto &position : m_mesh.positions) {
m_mesh.positionRTCs.emplace_back(position - center);
}
}
Expand Down Expand Up @@ -242,7 +242,7 @@ std::optional<CDBClassesAttributes> createClassesAttributes(const CDBTile &insta
}

GDALDatasetUniquePtr dataset = GDALDatasetUniquePtr(
(GDALDataset *) GDALOpenEx(classLevelPath.c_str(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr));
(GDALDataset *) GDALOpenEx(classLevelPath.string().c_str(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr));
if (!dataset) {
return std::nullopt;
}
Expand Down
19 changes: 10 additions & 9 deletions CDBTo3DTiles/src/CDBModels.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "CDBModels.h"
#include "CDB.h"
#include "Ellipsoid.h"
#include "Math.h"
#include "MathUtility.h"
#include "glm/glm.hpp"
#include "glm/gtc/epsilon.hpp"
#include "glm/gtc/matrix_transform.hpp"
Expand Down Expand Up @@ -147,8 +147,8 @@ void CDBModel3DResult::finalize()
for (auto &mesh : m_meshes) {
mesh.positionRTCs.reserve(mesh.positions.size());
auto center = mesh.aabb->center();
for (auto pos : mesh.positions) {
mesh.positionRTCs.emplace_back(pos - center);
for (const auto &position : mesh.positions) {
mesh.positionRTCs.emplace_back(position - center);
}
}
}
Expand Down Expand Up @@ -236,7 +236,7 @@ void CDBModel3DResult::processStateSet()
osg::Image *img = tex->getImage(0);
if ((img) && (!img->getFileName().empty())) {
std::filesystem::path texturePath = img->getFileName();
texture.uri = texturePath.stem().replace_extension(".png");
texture.uri = texturePath.stem().replace_extension(".png").string();
m_images.emplace_back(img);
m_textures.emplace_back(texture);
material.texture = static_cast<int>(m_textures.size() - 1);
Expand Down Expand Up @@ -363,8 +363,9 @@ const CDBModel3DResult *CDBGTModelCache::locateModel3D(const std::string &FACC,
for (std::filesystem::directory_entry featureCodeDir :
std::filesystem::directory_iterator(B_Subcartegory)) {
if (featureCodeDir.path().filename().string().substr(0, 3) == FACC.substr(2, 3)) {
osg::ref_ptr<osg::Node> geometry = osgDB::readRefNodeFile(featureCodeDir.path()
/ (key + ".flt"));
auto geometryFile = featureCodeDir.path()
/ (key + ".flt");
osg::ref_ptr<osg::Node> geometry = osgDB::readRefNodeFile(geometryFile.string());
if (geometry) {
CDBModel3DResult model3D;
geometry->accept(model3D);
Expand Down Expand Up @@ -551,7 +552,7 @@ std::optional<CDBGSModels> CDBGSModels::createFromModelsAttributes(CDBModelsAttr
// set relative path for GSModel
osg::ref_ptr<osgDB::Options> options = new osgDB::Options();
options->setObjectCacheHint(osgDB::Options::CACHE_NONE);
options->getDatabasePathList().push_front(GSModelZip.parent_path());
options->getDatabasePathList().push_front(GSModelZip.parent_path().string());

// find GSModelTexture zip file to search for texture
CDBTile GSModelTextureTile = CDBTile(attributeTile.getGeoCell(),
Expand All @@ -565,7 +566,7 @@ std::optional<CDBGSModels> CDBGSModels::createFromModelsAttributes(CDBModelsAttr
std::filesystem::path GSModelTextureRelPath = GSModelTextureTile.getRelativePath();
std::string GSModelTextureTileName = GSModelTextureRelPath.stem().string();
std::filesystem::path GSModelTextureZip = CDBPath / (GSModelTextureRelPath.string() + ".zip");
osgDB::ReaderWriter::ReadResult GSModelTextureRead = rw->openArchive(GSModelTextureZip,
osgDB::ReaderWriter::ReadResult GSModelTextureRead = rw->openArchive(GSModelTextureZip.string(),
osgDB::Archive::READ);
if (GSModelTextureRead.validArchive()) {
osg::ref_ptr<osgDB::Archive> GSModelTextureArchive = GSModelTextureRead.takeArchive();
Expand All @@ -576,7 +577,7 @@ std::optional<CDBGSModels> CDBGSModels::createFromModelsAttributes(CDBModelsAttr
}

// read GSModel geometry
osgDB::ReaderWriter::ReadResult GSModelRead = rw->openArchive(GSModelZip, osgDB::Archive::READ);
osgDB::ReaderWriter::ReadResult GSModelRead = rw->openArchive(GSModelZip.string(), osgDB::Archive::READ);
if (GSModelRead.validArchive()) {
osg::ref_ptr<osgDB::Archive> archive = GSModelRead.takeArchive();
return CDBGSModels(std::move(attributes), modelTile, archive, options);
Expand Down
17 changes: 9 additions & 8 deletions CDBTo3DTiles/src/CDBTo3DTiles.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "CDBTo3DTiles.h"
#include "CDB.h"
#include "Gltf.h"
#include "Math.h"
#include "MathUtility.h"
#include "TileFormatIO.h"
#include "cpl_conv.h"
#include "gdal.h"
Expand Down Expand Up @@ -465,7 +465,7 @@ Texture Converter::Impl::createImageryTexture(CDBImagery &imagery,
}

Texture texture;
texture.uri = textureRelativePath;
texture.uri = textureRelativePath.string();
texture.magFilter = TextureFilter::LINEAR;
texture.minFilter = TextureFilter::LINEAR_MIPMAP_NEAREST;

Expand Down Expand Up @@ -527,7 +527,9 @@ void Converter::Impl::addGTModelToTilesetCollection(const CDBGTModels &model,
// write to glb
tinygltf::TinyGLTF loader;
std::filesystem::path modelGltfURI = MODEL_GLTF_SUB_DIR / (modelKey + ".glb");
loader.WriteGltfSceneToFile(&gltf, tilesetDirectory / modelGltfURI, false, false, false, true);
auto modelGltfAbsolutePath = tilesetDirectory
/ modelGltfURI;
loader.WriteGltfSceneToFile(&gltf, modelGltfAbsolutePath.string(), false, false, false, true);
GTModelsToGltf.insert({modelKey, modelGltfURI});
}

Expand All @@ -545,7 +547,7 @@ void Converter::Impl::addGTModelToTilesetCollection(const CDBGTModels &model,
writeToCMPT(static_cast<uint32_t>(instances.size()), fs, [&](std::ofstream &os, size_t) {
const auto &GltfURI = GTModelsToGltf[instance->first];
const auto &instanceIndices = instance->second;
size_t totalWrite = writeToI3DM(GltfURI, modelsAttribs, instanceIndices, os);
size_t totalWrite = writeToI3DM(GltfURI.string(), modelsAttribs, instanceIndices, os);
instance = std::next(instance);
return totalWrite;
});
Expand Down Expand Up @@ -590,9 +592,9 @@ std::vector<Texture> Converter::Impl::writeModeTextures(const std::vector<Textur
for (size_t i = 0; i < modelTextures.size(); ++i) {
auto textureRelativePath = textureSubDir / modelTextures[i].uri;
auto textureAbsolutePath = gltfPath / textureSubDir / modelTextures[i].uri;

if (processedModelTextures.find(textureAbsolutePath) == processedModelTextures.end()) {
osgDB::writeImageFile(*images[i], textureAbsolutePath.string(), nullptr);
auto textureAbsolutePathStr = textureAbsolutePath.string();
if (processedModelTextures.find(textureAbsolutePathStr) == processedModelTextures.end()) {
osgDB::writeImageFile(*images[i], textureAbsolutePathStr, nullptr);
}

textures[i].uri = textureRelativePath.string();
Expand Down Expand Up @@ -854,7 +856,6 @@ void Converter::convert()
}

USE_OSGPLUGIN(png)
USE_OSGPLUGIN(jpeg)
USE_OSGPLUGIN(zip)
USE_OSGPLUGIN(rgb)
USE_OSGPLUGIN(OpenFlight)
Expand Down
2 changes: 1 addition & 1 deletion CDBTo3DTiles/src/TileFormatIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ void convertTilesetToJson(const CDBTile &tile, float geometricError, nlohmann::j
auto contentURI = tile.getCustomContentURI();
if (contentURI) {
json["content"] = nlohmann::json::object();
json["content"]["uri"] = *contentURI;
json["content"]["uri"] = contentURI->string();
}

const std::vector<CDBTile *> &children = tile.getChildren();
Expand Down
7 changes: 4 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
Change Log
==========

### 0.0.1 - 2020-??-??
### 0.1.0 - 2020-??-??

* Fixed a bug where GS model attributes and positions couldn't be processed due to too many files being open. [#23](https://github.com/CesiumGS/cdb-to-3dtiles/pull/23)
* Provide `--combine` option to combine multiple tilesets into one. [#19](https://github.com/CesiumGS/cdb-to-3dtiles/issues/19)
* Fixed a bug where empty simplified terrain mesh is exported to gltf. [#25](https://github.com/CesiumGS/cdb-to-3dtiles/pull/25)
* Fixed a bug where empty simplified terrain mesh is exported to glTF. [#25](https://github.com/CesiumGS/cdb-to-3dtiles/pull/25)
* Fixed a bug where leaf tiles were being given non-zero geometric errors. [#36](https://github.com/CesiumGS/cdb-to-3dtiles/pull/36)
* Added support for building with Visual Studio on Windows. [#17](https://github.com/CesiumGS/cdb-to-3dtiles/issues/17)
* Added `--combine` option to combine multiple tilesets into one. [#19](https://github.com/CesiumGS/cdb-to-3dtiles/issues/19)

### 0.0.0 - 2020-11-16

Expand Down
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ enable_testing()

function(configure_project target_name)
if (MSVC)
target_compile_options(${target_name} PRIVATE /W4 /WX /wd4201)
target_compile_options(${target_name} PRIVATE
/W4
/WX
/wd4201
/DOSG_LIBRARY_STATIC
/D_CRT_SECURE_NO_WARNINGS
/D_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING)
else()
target_compile_options(${target_name} PRIVATE -Werror -Wall -Wextra -Wconversion -Wpedantic -Wshadow)
endif()
Expand Down
2 changes: 1 addition & 1 deletion Core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(Core)

set(sources
"src/Math.cpp"
"src/MathUtility.cpp"
"src/Transforms.cpp"
"src/IntersectionTests.cpp"
"src/EllipsoidTangentPlane.cpp"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Core/src/Ellipsoid.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Ellipsoid.h"
#include "Math.h"
#include "MathUtility.h"

namespace Core {

Expand Down
2 changes: 1 addition & 1 deletion Core/src/GlobeRectangle.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "GlobeRectangle.h"
#include "Math.h"
#include "MathUtility.h"

namespace Core {

Expand Down
2 changes: 1 addition & 1 deletion Core/src/IntersectionTests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "IntersectionTests.h"
#include "Math.h"
#include "MathUtility.h"

namespace Core {

Expand Down
2 changes: 1 addition & 1 deletion Core/src/Math.cpp → Core/src/MathUtility.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Math.h"
#include "MathUtility.h"

namespace Core {
const double Math::EPSILON1 = 1e-1;
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Transforms.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Transforms.h"
#include "Math.h"
#include "MathUtility.h"

namespace Core {
glm::dmat4x4 Transforms::eastNorthUpToFixedFrame(const glm::dvec3 &origin, const Ellipsoid &ellipsoid)
Expand Down
Binary file added Doc/Window-Build-config.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Doc/Window-Build-directory.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Doc/Window-Build.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading