Skip to content

Commit

Permalink
实现根节点合并
Browse files Browse the repository at this point in the history
  • Loading branch information
scially committed Dec 4, 2023
1 parent 2ade12a commit 3496fb0
Show file tree
Hide file tree
Showing 76 changed files with 762 additions and 104 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ build
vsxmake*
app
vcpkg_installed
build
build
binary
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required (VERSION 3.10)
project(Cesium3DTilesConverter VERSION 3.0.0)
project(Cesium3DTilesConverter VERSION 3.1.0)

set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# About Project

基于C++17、Qt5的3DTiles转换工具
基于C++17、Qt5的3DTiles转换工具, 全网支持唯一根节点合并的开源工具

# 简介

Expand All @@ -23,16 +23,17 @@ Converter -f <FORMAT> [OPTIONS] <INPUT> <OUTPUT>

```sh
# from osgb dataset
Converter -f OSGB -i <OSGB> -o <OUTPUT>
Converter -f OSGB -m true -i <OSGB> -o <OUTPUT>
```

## 参数说明
```
Options:
-?, -h, --help displays help on commandline options.
-f, --format <format> OSGB or Vector(required), OSGB 为倾斜摄影格式数据, Vector为GDAL支持的面(Polygon)数据
-i, --input <INPUT> 输入数据的目录,OSGB数据截止到 `<DIR>/Data` 目录的上一级,GDAL参考GDAL数据格式。
-o, --ouput <OUTPUT> 输出目录。OSGB转换的3DTiles输出的数据文件位于 <DIR>/Data`目录, GDAL转换的3DTiles输出的数据文件位于<DIR>/Tile目录,tileset.json位于<DIR>根目录。
-?, -h, --help displays help on commandline options.
-f, --format <format> OSGB or Vector(required), OSGB 为倾斜摄影格式数据, Vector为GDAL支持的面(Polygon)数据
-m, --merge <true/false> 根节点合并开关选项
-i, --input <INPUT> 输入数据的目录,OSGB数据截止到 `<DIR>/Data` 目录的上一级,GDAL参考GDAL数据格式。
-o, --ouput <OUTPUT> 输出目录。OSGB转换的3DTiles输出的数据文件位于 <DIR>/Data`目录, GDAL转换的3DTiles输出的数据文件位于<DIR>/Tile目录,tileset.json位于<DIR>根目录。
```

# 数据要求及说明
Expand Down Expand Up @@ -68,7 +69,7 @@ Options:

# TODO
1. 目前只迁移了OSGB的转换转换工作,后面进行GDAL转换代码迁移
2. 根节点合并
2. 初步实现了根节点合并,目前只做到了Vertex简化,后面加入纹理简化

# Reference
1. 3dtiles specification [https://github.com/CesiumGS/3d-tiles](https://github.com/CesiumGS/3d-tiles)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions data/Production_5/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ModelMetadata version="1">
<!--Spatial Reference System-->
<SRS>PROJCS["ZS7CCGCS2000 / 3-degree Gauss-Kruger CM 113.22E",
<SRS>PROJCS["LOCAL0 / 3-degree Gauss-Kruger CM 113.36E",
GEOGCS["China Geodetic Coordinate System 2000",
DATUM["China_2000",
SPHEROID["CGCS2000",6378137,298.257222101,
Expand All @@ -14,7 +14,7 @@
AUTHORITY["EPSG","4490"]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",113.366666666666666666666667],
PARAMETER["central_meridian",113.37],
PARAMETER["scale_factor",1],
PARAMETER["false_easting",500000],
PARAMETER["false_northing",90],
Expand Down
2 changes: 1 addition & 1 deletion include/CesiumGLTF/CesiumB3DM.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace scially {
osg::Vec3d center;
QList<CesiumMesh> meshes;
private:
void toB3DM(const QByteArray& glb, QByteArray& buffer) const;
QByteArray toB3DM(const QByteArray& glb) const;
};

}
23 changes: 23 additions & 0 deletions include/Commons/OSGSimplify.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <osg/Node>
#include <osg/Group>

namespace scially {
class OSGSimplify {
public:
OSGSimplify(osg::Node& node) : mNode(node), mSNode(new osg::Group) {

}

bool simplify(double ratio);

osg::ref_ptr<osg::Node> node() {
return mSNode;
}

private:
osg::ref_ptr<osg::Group> mSNode;
osg::Node& mNode;
};
}
6 changes: 3 additions & 3 deletions include/Commons/TileStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ namespace scially {
static TileStorage::Ptr create(const QUrl& path);

virtual bool init() { return true; }
virtual bool saveJson(const QString& file, const QJsonObject& content) = 0;
virtual bool saveFile(const QString& file, const QByteArray& content) = 0;
virtual bool saveJson(const QString& file, const QJsonObject& content) const = 0;
virtual bool saveFile(const QString& file, const QByteArray& content) const = 0;

virtual bool exists(const QString& file) {
virtual bool exists(const QString& file) const{
return false;
}
};
Expand Down
10 changes: 5 additions & 5 deletions include/Commons/TileStorageDisk.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace scially {

TileStorageDisk(const QString& folder) : mFolder(folder) {}

virtual bool saveJson(const QString& file, const QJsonObject& content) override;
virtual bool saveFile(const QString& file, const QByteArray& content) override;
virtual bool saveJson(const QString& file, const QJsonObject& content) const override;
virtual bool saveFile(const QString& file, const QByteArray& content) const override;

virtual bool exists(const QString& file) override;
virtual bool exists(const QString& file) const override;
private:
QString cleanPath(const QString& path);
bool ensurePath(const QString& path);
QString cleanPath(const QString& path) const;
bool ensurePath(const QString& path) const;

QString mFolder;
};
Expand Down
4 changes: 2 additions & 2 deletions include/Commons/Version.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#define SCIALLY_PROJECT_VERSION_MAJOR 3
#define SCIALLY_PROJECT_VERSION_MINOR 0
#define SCIALLY_PROJECT_VERSION_MINOR 1
#define SCIALLY_PROJECT_VERSION_PATCH 0

constexpr const char* SCIALLY_PROJECT_VERSION = "3.0.0";
constexpr const char* SCIALLY_PROJECT_VERSION = "3.1.0";
constexpr const char* SCIALLY_PROJECT_NAME = "Cesium3DTilesConverter";
8 changes: 8 additions & 0 deletions include/ConvertApp/CLIParse.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace scially {
Format format;
QString input;
QString output;
bool mergeTop = false;

CLIParse() {
mParser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
Expand All @@ -31,6 +32,10 @@ namespace scially {
QStringList() << "f" << "format",
"OSGB or Vector(required)", "format"
},
{
QStringList() << "m" << "merge",
"OSGB Top Merge", "top merge", "false"
},
{
QStringList() << "i" << "input",
"data input(required)", "input"
Expand Down Expand Up @@ -70,6 +75,9 @@ namespace scially {

private:
bool parseOSGB() {
if (mParser.isSet("merge")) {
mergeTop = mParser.value("merge") == "true";
}
return parseIO();
}

Expand Down
7 changes: 5 additions & 2 deletions include/OSGConvert/OSGFolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ namespace scially {
public:
bool load(const OSGConvertOption& options);
bool toB3DMPerTile(const OSGConvertOption& options);
bool mergeTile() const;
bool mergeTop(const OSGConvertOption& options) const;

QList<OSGTile::Ptr> tiles() const;
private:
bool loadMetaData(const QString& input);
bool mergeTile() const;

BaseTile toBaseTile() const;

QList<OSGTile> mTiles;
QList<OSGTile::Ptr> mTiles;
SpatialReference::Ptr mInSRS;
SpatialReferenceMatrix mOutSRS;
SpatialTransform::Ptr mSTS;
Expand Down
9 changes: 5 additions & 4 deletions include/OSGConvert/OSGIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ namespace scially {
double geometricError = 0;
osg::BoundingBoxd boundingBox;
QList<TileNode::Ptr> nodes;

TileNode() {}


TileNode(const QString& tileName, const QString& fileName)
: mTileName(tileName)
, mFileName(fileName) {

}
virtual ~TileNode() {}

QString relativePath(const QString& suffix) const noexcept {
return mTileName + "/" + fileName(suffix);
Expand All @@ -46,7 +45,9 @@ namespace scially {

RootTile toRootTile(bool withChilden) const;

private:
protected:
TileNode() {}

QString mTileName;
QString mFileName;
};
Expand Down
3 changes: 2 additions & 1 deletion include/OSGConvert/OSGLodVisitor.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include <QList>
#include <QVector>
#include <QString>
#include <QVector>

#include <osg/BoundingBox>
#include <osg/NodeVisitor>

Expand Down
110 changes: 110 additions & 0 deletions include/OSGConvert/OSGMergeTopIndex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#include <Cesium3DTiles/RootTile.h>
#include <CesiumMath/SpatialTransform.h>
#include <OSGConvert/OSGTile.h>

#include <QList>
#include <QSharedPointer>

#include <osg/Node>

#include <algorithm>
#include <iterator>

namespace scially {
// pyramid
// t z = 1
// t t z = 2
//t t t t z = 3
// TODO:
// rebuild:
// MergeTileNode -> TileNode -> VirtualNode £¨OSGTile¡¢OSGFolder)
class MergeTileNode : public QEnableSharedFromThis<MergeTileNode> {
public:
using Ptr = QSharedPointer<MergeTileNode>;
friend class MergeTileNodeBuilder;

MergeTileNode(OSGTile::Ptr osgTile);
MergeTileNode(int32_t x, int32_t y, int32_t z);
virtual ~MergeTileNode() {}

bool parentIndex(uint32_t z, int32_t& x, int32_t& y) const;

const int32_t& xIndex() const { return mXIndex; }
const int32_t& yIndex() const { return mYIndex; }
const int32_t& zIndex() const { return mZIndex; }
const QString& tileName() const { return mTileName; }
const QString& fileName() const { return mFileName; }
const double& geometricError() const { return mGeometricError; }
const osg::BoundingBoxd& boundingBox() const { return mBoundingBox; }
const QList<MergeTileNode::Ptr>& nodes() const { return mNodes; }

int32_t& xIndex() { return mXIndex; }
int32_t& yIndex() { return mYIndex; }
int32_t& zIndex() { return mZIndex; }
double& geometricError() { return mGeometricError; }
osg::BoundingBoxd& boundingBox() { return mBoundingBox; }
QList<MergeTileNode::Ptr>& nodes() { return mNodes; }

QString relativePath(const QString& suffix) const {
return QString("top/top_%1_%2_%3%4")
.arg(zIndex())
.arg(xIndex())
.arg(yIndex())
.arg(suffix);
}

// convert to b3dm
MergeTileNode::Ptr toB3DM(
const SpatialTransform& transform,
const TileStorage& storage,
double splitPixel);

RootTile toRootTile() const;

bool operator== (const MergeTileNode& node);

private:
osg::ref_ptr<osg::Node> mOSGNode;
QList<MergeTileNode::Ptr> mNodes;

OSGTile::Ptr mOSGTile;

osg::BoundingBoxd mBoundingBox;
double mGeometricError = 0;
int32_t mXIndex;
int32_t mYIndex;
int32_t mZIndex;
QString mTileName;
QString mFileName;
};

class MergeTileNodeBuilder {
public:
static QList<MergeTileNode::Ptr>
BuildPyramidIndex(
const QList<MergeTileNode::Ptr>& nodes,
int32_t maxZ);

// read and simplyf all z level osg node
static void
GenerateOSGNodeInPyramid(
const QList<MergeTileNode::Ptr>& topNodes,
int32_t maxZ);

// convert to b3dm
static QList<MergeTileNode::Ptr> MergeOSGToB3DM(
const QList<MergeTileNode::Ptr>& topNodes,
const SpatialTransform& transform,
TileStorage& storage,
double splitPixel);

private:
// read and simplyf osg node
static void
GenerateOSGNodeInPyramidFromBottomToUp(
const QList<MergeTileNode::Ptr>& nodes,
uint32_t maxZ,
uint32_t z);
};

}
4 changes: 4 additions & 0 deletions include/OSGConvert/OSGParseVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ namespace scially {
const osg::Vec3d& tileCenter,
const SpatialTransform& transform);

QList<CesiumMesh> OSGBtoCesiumMesh(
osg::Node& osgNode,
const osg::Vec3d& tileCenter,
const SpatialTransform& transform);

class OSGParseVisitor: public osg::NodeVisitor {
public:
Expand Down
Loading

0 comments on commit 3496fb0

Please sign in to comment.