Skip to content

Commit

Permalink
shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
scially committed Sep 28, 2022
1 parent 18f957f commit 80c5856
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 42 deletions.
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.12)
project(CGT VERSION 2.3)
project(CGT VERSION 2.4)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${PROJECT_SOURCE_DIR}/cmake")
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
1. 支持投影坐标系以及WGS84之间坐标转换。
2. 支持根据矢量范围线导出对应瓦片。
3.
百度网盘下载地址: [https://pan.baidu.com/s/1AdLGNJiA2iKKYbFwmGKQ5g?pwd=lxsa](https://pan.baidu.com/s/1AdLGNJiA2iKKYbFwmGKQ5g?pwd=lxsa)
百度网盘下载地址: [https://pan.baidu.com/s/1wfpVE4SuvUKW-ceSdaLDdA?pwd=7np4](https://pan.baidu.com/s/1wfpVE4SuvUKW-ceSdaLDdA?pwd=7np4)

# 用法说明

Expand All @@ -25,7 +25,7 @@ Subcommands:
transform coordinate transform
export export osgb data

如果没有设置source-srs,source-origin选项,cgt默认会在输入根目录下寻找metadata.xml
如果没有设置source-srs,source-origin选项,cgt默认会在输入根目录下寻找metadata.xml,支持中文路径
```
### transform
```shell
Expand All @@ -42,7 +42,7 @@ cgt [options] export
Options:
--shapefile TEXT:FILE REQUIRED export extent
-c,--copy BOOLEAN copy tile(default: true)
默认会在范围线的Tile拷贝的out路径下通过设置 -c false 取消拷贝只输出符合要求的瓦片名
默认会在范围线的Tile拷贝的out路径下,通过设置 -c false 取消拷贝,只输出符合要求的瓦片名
```
## 示例命令

Expand All @@ -58,9 +58,11 @@ cgt.exe -i {DATA} -o ${OUT_DIR} export --shapefile {shp, geojson}
### 倾斜摄影数据

倾斜摄影数据仅支持 smart3d 格式的 osgb 组织方式:
- 每个瓦片目录下,必须有个和目录名同名的 osgb 文件,否则无法识别根节点;

正确的目录结构示意:
- 根目录下可以有多个Data文件夹,比如Data1,Data2等
- 最多有一个metadata.xml文件,且必须放在根目录下
- 每个瓦片目录下,必须有个和目录名同名的 osgb 文件,否则无法识别根节点;
正确的目录结构示意:

```
- Your-data-folder
Expand Down
14 changes: 8 additions & 6 deletions cgt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@ configure_file(
${PROJECT_SOURCE_DIR}/include/cgt/config.h.in
${PROJECT_SOURCE_DIR}/include/cgt/config.h)

add_library(cgtcore
add_library(cgtcore SHARED
"cgtcore.cpp"
"cgtmodel.cpp"
"tinyxml2.cpp"
"cgtproj.cpp"
"cgtvisitor.cpp"
"cgttransform.cpp"
"cgtexport.cpp" cgtpath.cpp)

add_executable(cgt
"main.cpp" ../include/cgt/cgtpath.h)

"cgtexport.cpp"
"cgtcommon.cpp")
target_link_libraries(cgtcore
${GDAL_LIBRARIES}
${OPENSCENEGRAPH_LIBRARIES})
target_compile_definitions(cgtcore
PRIVATE CGTEXPORT)

add_executable(cgt
"main.cpp")
target_link_libraries(cgt cgtcore)


add_custom_command(TARGET cgt
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/resources" "${EXECUTABLE_OUTPUT_PATH}"
Expand Down
2 changes: 1 addition & 1 deletion cgt/cgtpath.cpp → cgt/cgtcommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Created by adminstrator on 2022/9/28.
//

#include <cgt/cgtpath.h>
#include <cgt/cgtcommon.h>
#include <filesystem>

#if defined(_WIN32)
Expand Down
2 changes: 1 addition & 1 deletion cgt/cgtexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace scially {
layer->GetSpatialRef()->exportToWkt(&target_wktsrs);
modeldata.set_srs(target_wktsrs);
proj_ = std::make_unique<cgt_proj>(source_metadata_, modeldata);
delete target_wktsrs;
CPLFree(target_wktsrs);
}

bool osg_export::is_intersect(const osg::Node& node){
Expand Down
2 changes: 1 addition & 1 deletion cgt/cgtproj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//

#include <cgt/cgtproj.h>
#include <cgt/cgtpath.h>
#include <cgt/cgtcommon.h>
#include <osg/CoordinateSystemNode>
#include <osg/Math>

Expand Down
8 changes: 8 additions & 0 deletions include/cgt/cgtpath.h → include/cgt/cgtcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@

#if defined(_WIN32)
#define U8TEXT(s) osgDB::convertStringFromCurrentCodePageToUTF8(s)

#if defined(CGTEXPORT)
#define CGTLIBRARY __declspec(dllexport)
#else
#define CGTLIBRARY __declspec(dllimport)
#endif
#else
#define U8TEXT(s) s
#define CGTLIBRAR
#endif


namespace scially {
std::string get_process_filepath();
}
16 changes: 9 additions & 7 deletions include/cgt/cgtcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <cgt/cgtmodel.h>
#include <cgt/cgtproj.h>
#include <cgt/cgtpath.h>
#include <cgt/cgtcommon.h>
#include <spdlog/spdlog.h>

#include <osg/Node>
Expand All @@ -20,18 +20,20 @@
namespace scially {
using vec3_transform = std::function<osg::Vec3(osg::Vec3)>;

class node_operator {
class CGTLIBRARY node_operator {
public:
void read(const std::string& path);
void write(const std::string& dir);
void apply(const std::string& base_path, const vec3_transform&);
void read(const std::string &path);

void write(const std::string &dir);

void apply(const std::string &base_path, const vec3_transform &);

private:
osg::ref_ptr<osg::Node> node_;
std::string node_name_;
std::string node_name_;
};

class osg_base {
class CGTLIBRARY osg_base {
public:
static constexpr double DOUBLE_EPS = 1e-5;

Expand Down
16 changes: 10 additions & 6 deletions include/cgt/cgtexception.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
#pragma once

#include <cgt/cgtcommon.h>

#include <stdexcept>
#include <string>

namespace scially {

class cgt_exception : public std::runtime_error {
class CGTLIBRARY cgt_exception : public std::runtime_error {
public:
cgt_exception(const std::string& err)
: err(err),
std::runtime_error(err.data()){
cgt_exception(const std::string &err)
: err(err),
std::runtime_error(err.data()) {

}
virtual const char* what() const noexcept override {

virtual const char *what() const noexcept override {
return err.c_str();
}

private:
std::string err;
};
Expand Down
2 changes: 1 addition & 1 deletion include/cgt/cgtexport.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <vector>

namespace scially {
class osg_export : public osg_base {
class CGTLIBRARY osg_export : public osg_base {
public:
osg_export(const std::string &source_dir, const std::string &target_dir)
: osg_base(source_dir, target_dir) {
Expand Down
8 changes: 5 additions & 3 deletions include/cgt/cgtmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@
#include <sstream>

namespace scially {
std::vector<std::string> split(const std::string& str, const std::string& delimiters);
CGTLIBRARY std::vector<std::string> split(const std::string &str, const std::string &delimiters);

class osg_modeldata {
class CGTLIBRARY osg_modeldata {
public:
void load(const std::string &srs, const std::string &srs_origin);

void load_from_dir(const std::string &input);

void load_from_file(const std::string &input);

void write(const std::string &output);

std::string srs() const noexcept { return srs_; }
void set_srs(const std::string &srs) noexcept { srs_ = srs; }

void set_srs(const std::string &srs) noexcept { srs_ = srs; }
osg::Vec3 origin() const noexcept { return origin_; }
void set_origin(osg::Vec3 origin) noexcept { origin_ = origin;}

Expand Down
4 changes: 2 additions & 2 deletions include/cgt/cgtproj.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <functional>

namespace scially {
class gdal_init {
class CGTLIBRARY gdal_init {
public:
gdal_init();

Expand All @@ -26,7 +26,7 @@ namespace scially {
std::string proj_data_;
};

class cgt_proj {
class CGTLIBRARY cgt_proj {
public:
cgt_proj(const osg_modeldata &source_modeldata, const osg_modeldata &target_modeldata);

Expand Down
2 changes: 1 addition & 1 deletion include/cgt/cgttransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <cgt/cgtcore.h>

namespace scially {
class osg_transform : public osg_base {
class CGTLIBRARY osg_transform : public osg_base {
public:
osg_transform(const std::string &source_dir, const std::string &target_dir)
: osg_base(source_dir, target_dir) {
Expand Down
12 changes: 7 additions & 5 deletions include/cgt/cgtvisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
#include <osg/NodeVisitor>

namespace scially {
class geom_visitor : public osg::NodeVisitor {
class CGTLIBRARY geom_visitor : public osg::NodeVisitor {
public:
geom_visitor(const std::string base_path, const vec3_transform& algorithm)
: base_path_(base_path), algorithm_(algorithm){
geom_visitor(const std::string base_path, const vec3_transform &algorithm)
: base_path_(base_path), algorithm_(algorithm) {
setTraversalMode(TRAVERSE_ALL_CHILDREN);
}

virtual ~geom_visitor() {}

virtual void apply(osg::Geode& geode) override;
virtual void apply(osg::PagedLOD& lod) override;
virtual void apply(osg::Geode &geode) override;

virtual void apply(osg::PagedLOD &lod) override;

private:
vec3_transform algorithm_;
Expand Down
4 changes: 2 additions & 2 deletions include/cgt/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#include <cstdint>

constexpr uint32_t CGT_VERSION_MAJOR = 2;
constexpr uint32_t CGT_VERSION_MINOR = 3;
constexpr const char *CGT_VERSION = "2.3";
constexpr uint32_t CGT_VERSION_MINOR = 4;
constexpr const char *CGT_VERSION = "2.4";

0 comments on commit 80c5856

Please sign in to comment.