Skip to content

Commit

Permalink
修改命令行解析
Browse files Browse the repository at this point in the history
  • Loading branch information
scially committed Nov 17, 2022
1 parent 5847ae3 commit 4b231d9
Show file tree
Hide file tree
Showing 21 changed files with 563 additions and 518 deletions.
47 changes: 25 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,44 @@
## 命令行格式

```sh
Converter.exe --format <FORMAT> --input <INPUT> --output <OUTPUT> [OPTIONS]
Converter.exe --format <FORMAT> [OPTIONS] <INPUT> <OUTPUT>
```

## 示例命令

```sh
# from osgb dataset
Converter.exe --format osgb -input <OSGB Path> --output <Out Path> --yUpAxis true
Converter -f OSGB --yUpAxis <OSGB Path> <OUTPUT DIR>

# from single shp file
Converter.exe --format gdal --input <Shapefile Path> --output <DIR> --field height --layer <Shapefile Name>
Converter -f GDAL --field height <Shapefile Path> <OUTPUT DIR>

# from gdb file
Converter.exe --format gdal --input <GDB Path> --output <DIR> --field height --layer <Layer Name>
Converter -f GDAL --field height --layer <Layer Name> <GDB Path> <OUTPUT DIR>
```

## 参数说明
- `--format <FORMAT>` 输入数据格式。

`FORMAT` 可选:OSGB, GDAL

`可选:OSGB` 为倾斜摄影格式数据, `GDAL` 为GDAL支持的面(Polygon)数据

- `--input <PATH>` 输入数据的目录,osgb数据截止到 `<DIR>/Data` 目录的上一级,GDAL参考GDAL数据格式。

- `--output <DIR>` 输出目录。OSGB转换的3DTiles输出的数据文件位于 `<DIR>/Data` 目录, GDAL转换的3DTiles输出的数据文件位于`<DIR>/Tile`目录,`tileset.json`位于`<DIR>`根目录。

- `--field` 高度字段。指定GDAL数据集中的高度属性字段,此项为转换 GDAL 时的必须参数。

- `--offset` OSGB高度偏移字段。
- `--thread` 处理线程数量(仅对OSGB生效)
- `--yUpAxis` 是否将gltf模型转为y轴朝上

`yUpAxis` 可选: true, false
如果是用`Cesium for Unreal`加载数据,需要启用yUpAxis
```
Options:
-?, -h, --help Displays help on commandline options.
-f, --format <format> OSGB or GDAL(required), OSGB 为倾斜摄影格式数据, GDAL 为GDAL支持的面(Polygon)数据
-l, --level <level> OSGB max level, OSGB处理到的最大级别
-F, --field <field> height field name(required for gdal), 指定GDAL数据集中的高度属性字段,此项为转换 GDAL 时的必须参数。
-L, --layer <layer> layer name(required when input isn't shapefile)
-t, --thread <thread> thread number, 处理线程数量
-y, --yUpAxis y up axis, 是否将gltf模型转为y轴朝上(仅对OSGB生效),如果是用Cesium for Unreal,需要指定yUpAxis
-H, --height <height> height offset(default value 0), OSGB高度偏移字段
<INPUT PATH> 输入数据的目录,OSGB数据截止到 `<DIR>/Data` 目录的上一级,GDAL参考GDAL数据格式。
<OUTPUT DIR> 输出目录。OSGB转换的3DTiles输出的数据文件位于 <DIR>/Data`目录, GDAL转换的3DTiles输出的数据文件位于<DIR>/Tile目录,tileset.json位于<DIR>根目录。
```

# 数据要求及说明

Expand Down
81 changes: 17 additions & 64 deletions include/Cesium3DTiles/BoundingVolumeBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,71 +17,24 @@ namespace scially {
struct BoundingVolumeBox{
static constexpr const char* TypeName = "box";

BoundingVolumeBox() = default;
BoundingVolumeBox(BoundingVolumeRegion r) : region(r) {}

QJsonArray write() const;
void read(const QJsonArray& object);
double centerX() const{
return (region.east + region.west) / 2;
}
double centerY() const {
return (region.north + region.south) / 2;
}
double centerZ() const {
return (region.minHeight + region.maxHeight) / 2;
}

double directionX0 () const {
return 0;
}
double directionX1 () const {
return 0;
}
double halfXLength () const {
return (region.east - region.west) / 2;
}

double directionY0() const {
return 0;
}

double directionY1() const {
return 0;
}

double halfYLength () const {
return (region.north - region.south) / 2;
}

double directionZ0 () const {
return 0;
}

double directionZ1() const {
return 0;
}

double halfZLength () const {
return (region.maxHeight - region.minHeight) / 2;
}

void setMax(const osg::Vec3d& max);
void setMin(const osg::Vec3d& min);
void setMax(const osg::Vec3f& max);
void setMin(const osg::Vec3f& min);

void mergeMax(const osg::Vec3d& max);
void mergeMin(const osg::Vec3d& min);
void mergeMax(const osg::Vec3f& max);
void mergeMin(const osg::Vec3f& min);

BoundingVolumeBox merge(BoundingVolumeBox bounding) const;

double geometricError() const;
osg::Vec3d getMax() const;
osg::Vec3d getMin() const;

BoundingVolumeRegion region;
double geometricError() const noexcept;

double centerX = 0;
double centerY = 0;
double centerZ = 0;

double directionX0 = 0;
double directionX1 = 0;
double halfXLength = 0;

double directionY0 = 0;
double directionY1 = 0;
double halfYLength = 0;

double directionZ0 = 0;
double directionZ1 = 0;
double halfZLength = 0;
};
}
133 changes: 133 additions & 0 deletions include/CommandLineParse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#pragma once

#include <QCommandLineParser>
#include <QException>
#include <QFileInfo>

namespace scially {
class CommandLineParseException : public QException {
public:
explicit CommandLineParseException(const QString& err) : err_(err) {
}
void raise() const override { throw* this; }
CommandLineParseException* clone() const override { return new CommandLineParseException(*this); }
QString error() const noexcept { return err_; }
private:
QString err_;
};

class CommandLineParse
{
public:
CommandLineParse() {
parser_.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
parser_.setApplicationDescription("Convert OSGB, GDAL to Cesium 3DTiles");
parser_.addHelpOption();
parser_.addVersionOption();
}
void parse() {
parser_.addOptions({
{
QStringList() << "f" << "format",
"OSGB or GDAL(required)", "format"
},
{
QStringList() << "l" << "level",
"osgb max level", "level", "-1"
},
{
QStringList() << "F" << "field",
"height field name(required for gdal)", "field"
},
{
QStringList() << "L" << "layer",
"layer name(required when input isn't shapefile)", "layer"
},
{
QStringList() << "t" << "thread",
"thread number", "thread", "4"
},
{
QStringList() << "y" << "yUpAxis",
"y up axis", "yUpAxis"
},
{
QStringList() << "H" << "height",
"height offset(default value 0)", "height", "0"
}
});

parser_.process(*qApp);
thread_ = parser_.value("thread").toInt();

if (!parser_.isSet("format"))
throw CommandLineParseException("commandline format is requested");
format_ = parser_.value("format").toUpper();

if (format_ == "GDAL") {
parseGDAL();
}
else if (format_ == "OSGB") {
parseOSGB();
}
else
throw CommandLineParseException("format must be GDAL or OSGB");
parseIO();
}
void showHelp(int exitCode = -1) {
parser_.showHelp();
}
QString format() const noexcept { return format_; }
QString input() const noexcept { return input_; }
QString output() const noexcept { return output_; }
int level() const noexcept { return level_; }
int thread() const noexcept { return thread_; }
bool yUpAxis() const noexcept { return yUpAxis_; }
double height() const noexcept { return height_; }
QString field() const noexcept { return field_; }
QString layer() const noexcept { return layer_; }

private:
void parseOSGB() {
level_ = parser_.value("level") == "-1" ?
std::numeric_limits<int>::max() : parser_.value("level").toInt();
height_ = parser_.value("height") == "0" ? 0 : parser_.value("height").toDouble();
yUpAxis_ = parser_.isSet("yUpAxis");
}
void parseGDAL() {
if (!parser_.isSet("field"))
throw CommandLineParseException("commandline field is requested");
field_ = parser_.value("field");
}

void parseIO() {
const QStringList args = parser_.positionalArguments();
if (args.size() != 2) {
throw CommandLineParseException("input and out must be set");
}
input_ = args[0];
QFileInfo inputFile(input_);
if (!inputFile.exists()) {
throw CommandLineParseException("input file " + input_ + "not exist");
}
if (inputFile.fileName().indexOf(".shp") < 0 && !layer_.isEmpty()) {
throw CommandLineParseException("layer name must be set");
}
if (inputFile.fileName().indexOf(".shp") >= 0 && layer_.isEmpty()) {
layer_ = inputFile.baseName();
}
output_ = args[1];
}

QString format_;
QString input_;
QString output_;
int level_;
int thread_;
bool yUpAxis_;
double height_;
QString field_;
QString layer_;
QCommandLineParser parser_;
};
}
4 changes: 0 additions & 4 deletions include/GDALWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ namespace scially {
class GDALDriverWrapper {
public:
GDALDriverWrapper() {
#ifdef _WIN32
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO");
#else
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
#endif
std::string basePath = qApp->applicationDirPath().toStdString();
gdalData = basePath + "/gdal_data";
projData = basePath + "/proj_data";
Expand Down
45 changes: 22 additions & 23 deletions include/OSGBConvert.h
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
#pragma once

#include <Cesium3DTiles/BoundingVolumeRegion.h>
#include <Cesium3DTiles/BoundingVolumeBox.h>

#include <OSGBRegion.h>
#include <OSGBuildState.h>
#include <OSGBPageLodVisitor.h>
#include <QSharedPointer>
#include <QString>
#include <QDir>
#include <QVector>

#include <QFileInfo>
#include <QDir>

namespace scially {
class OSGBConvert {
public:
OSGBConvert() {}
OSGBConvert(const QString& name, const QString& path) :
nodeName(name), nodePath(path) {}
OSGBConvert(const QString& absoluteLocation) {
QDir location(absoluteLocation);
nodeName = location.dirName();
location.cdUp();
nodePath = location.absolutePath();
nodeName_(name), nodePath_(path) {
nodeLocation_ = QDir::cleanPath(path + "/" + name + ".osgb");
}

//double geometricError = 0;
BoundingVolumeRegion region;
OSGBConvert(const QString& absoluteLocation) : nodeLocation_(absoluteLocation){
QFileInfo location(nodeLocation_);
nodeName_ = location.baseName();
nodePath_ = location.path();
}

bool writeB3DM(const QByteArray& buffer, const QString& outLocation);
QByteArray toB3DM();

bool yUpAxis = false;
bool toB3DM(QByteArray& buffer);

void setYUpAxis(bool yUpAxis) noexcept { yUpAxis_ = yUpAxis; }
OSGBRegion region() const noexcept { return region_; }
bool yUpAxis() const noexcept { return yUpAxis_; }
QString nodeName() const noexcept { return nodeName_; }
QString nodePath() const noexcept { return nodePath_; }
private:
tinygltf::Material makeColorMaterialFromRGB(double r, double g, double b);
QByteArray convertGLB();
QString absoluteLocation() const;

QString nodeName;
QString nodePath;
bool convertGLB(QByteArray& buffer);

OSGBRegion region_;
bool yUpAxis_ = false;
QString nodeName_;
QString nodePath_;
QString nodeLocation_;
};
}

Expand Down
Loading

0 comments on commit 4b231d9

Please sign in to comment.