Skip to content

Commit 96d455a

Browse files
committed
MeshCodeを親クラスGridCodeに移行中
gitignore cmakelists.txt gitignore clangd grid_code.h standard map grid GridCode::create grid実装中 同上 ビルド通る C++テスト通る fix c wrapper gmlfile::gridCode 同上 以降途中 移行中
1 parent dfee250 commit 96d455a

37 files changed

+634
-208
lines changed

.clangd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CompileFlags:
2+
If:
3+
PathMatch: [.*]
4+
Condition: "system(windows)"
5+
CompilationDatabase: out/build/x64-Debug-Unity
6+
Remove: [-fPIC]
7+
Add: [--target=x86_64-pc-windows-msvc]

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# fbx_sdk は再配布禁止のため、ご自分で用意していただく形になります。
32
/3rdparty/fbx_sdk/
43

@@ -22,8 +21,10 @@ _deps
2221
obj
2322
bin
2423

25-
# Visual Studio
24+
# Editor settings
2625
.vs
26+
.vscode
27+
.idea
2728

2829
# Resharper User config
2930
*.DotSettings.user

.idea/vcs.xml

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# .soファイルが存在しても、 .so が依存する .so ファイルが存在しない場合に DllNotFoundException になります。
2323
# 次のコマンドで .so がどのようなライブラリに依存するか調べると良いです。
2424
# objdump -x libplateau.so | grep NEEDED
25-
# ldd ./libplateau.so | grep "not found
25+
# ldd ./libplateau.so | grep "not found"
2626

2727

2828
cmake_minimum_required(VERSION 3.8)
@@ -79,6 +79,9 @@ if(WIN32) # CMake文法上の WIN32
7979
add_definitions(-D WIN32) # C言語の #define キーワードとしての WIN32
8080
endif()
8181

82+
# clangdで静的解析するための情報を出力
83+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
84+
8285
# libjpeg-turboが複数architecture向けビルドをサポートしていないため限定
8386
# https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/CMakeLists.txt#L101
8487
set(COUNT 1)

include/plateau/dataset/gml_file.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ namespace plateau::dataset {
2020

2121
const std::string& getPath() const;
2222
void setPath(const std::string& path);
23-
MeshCode getMeshCode() const;
23+
std::shared_ptr<GridCode> getGridCode() const;
24+
GridCode* getGridCodeRaw() const; // 寿命管理をDLL利用者に任せる用です
2425
const std::string& getFeatureType() const;
2526
PredefinedCityModelPackage getPackage() const;
2627
std::string getAppearanceDirectoryPath() const;
@@ -61,7 +62,7 @@ namespace plateau::dataset {
6162

6263
private:
6364
std::string path_;
64-
std::string code_;
65+
std::shared_ptr<GridCode> grid_code_;
6566
std::string feature_type_;
6667
bool is_valid_;
6768
bool is_local_;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <memory>
5+
#include <libplateau_api.h>
6+
#include "plateau/geometry/geo_coordinate.h"
7+
8+
namespace plateau::dataset {
9+
/**
10+
* \brief 地図の区画を表すコードの基底クラスです。
11+
*
12+
* メッシュコードや国土基本図図郭など、地図の区画を表現するコードシステムの共通機能を提供します。
13+
*/
14+
class LIBPLATEAU_EXPORT GridCode {
15+
public:
16+
virtual ~GridCode() = default;
17+
18+
/**
19+
* \brief コードを文字列として取得します。
20+
*/
21+
virtual std::string get() const = 0;
22+
23+
/**
24+
* \brief コードが表す緯度経度範囲を取得します。
25+
*/
26+
virtual geometry::Extent getExtent() const = 0;
27+
28+
/**
29+
* \brief このコードが他のコードに内包されるかどうかを計算します。
30+
*/
31+
virtual bool isWithin(const GridCode& other) const = 0;
32+
33+
/**
34+
* \brief コードが適切な値かどうかを返します。
35+
*/
36+
virtual bool isValid() const = 0;
37+
38+
/**
39+
* \brief 与えられたコードから適切なGridCodeの派生クラスのインスタンスを作成します。
40+
* \param code コード文字列
41+
* \return コードの形式に応じてMeshCodeまたはStandardMapGridのインスタンスを返します。
42+
* \throw std::invalid_argument コードの形式が不正な場合
43+
*/
44+
static std::shared_ptr<GridCode> create(const std::string& code);
45+
46+
/**
47+
* \brief 与えられたコードから適切なGridCodeの派生クラスのインスタンスを作成します。
48+
* \param code コード文字列
49+
* \return コードの形式に応じてMeshCodeまたはStandardMapGridのインスタンスを返します。生ポインタで返されます。
50+
* \throw std::invalid_argument コードの形式が不正な場合
51+
*/
52+
static GridCode* createRaw(const std::string& code);
53+
54+
};
55+
56+
struct GridCodeComparator {
57+
bool operator()(const std::shared_ptr<GridCode>& lhs, const std::shared_ptr<GridCode>& rhs) const {
58+
if(lhs == nullptr || rhs == nullptr) return false;
59+
return lhs->get() < rhs->get();
60+
}
61+
};
62+
}

include/plateau/dataset/i_dataset_accessor.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <libplateau_api.h>
44
#include <plateau/dataset/gml_file.h>
55
#include <plateau/dataset/city_model_package.h>
6+
#include <plateau/dataset/grid_code.h>
7+
#include <memory>
68

79
namespace plateau::geometry {
810
class GeoReference;
@@ -129,7 +131,7 @@ namespace plateau::dataset {
129131
/**
130132
* \brief 都市モデルデータが存在する地域メッシュのリストを取得します。
131133
*/
132-
virtual std::set<MeshCode>& getMeshCodes() = 0;
134+
virtual std::set<std::shared_ptr<GridCode>, GridCodeComparator>& getGridCodes() = 0;
133135

134136
virtual TVec3d calculateCenterPoint(const plateau::geometry::GeoReference& geo_reference) = 0;
135137

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#pragma once
2+
3+
#include <libplateau_api.h>
4+
#include "plateau/dataset/grid_code.h"
5+
#include "plateau/geometry/geo_coordinate.h"
6+
7+
namespace plateau::dataset {
8+
/**
9+
* \brief 無効なグリッドコードを表すクラスです。
10+
*
11+
* GridCodeの派生クラスとして、無効なグリッドコードを表現します。
12+
* このクラスのインスタンスは常に無効(isValid() == false)です。
13+
*/
14+
class LIBPLATEAU_EXPORT InvalidGridCode : public GridCode {
15+
public:
16+
InvalidGridCode() = default;
17+
18+
/**
19+
* \brief 無効なグリッドコードを文字列として取得します。
20+
* \return 常に空文字列を返します。
21+
*/
22+
std::string get() const override { return ""; }
23+
24+
/**
25+
* \brief 無効なグリッドコードの緯度経度範囲を取得します。
26+
* \return 原点(0,0,0)を中心とする無効な範囲を返します。
27+
*/
28+
geometry::Extent getExtent() const override {
29+
return geometry::Extent(
30+
geometry::GeoCoordinate(0, 0, 0),
31+
geometry::GeoCoordinate(0, 0, 0)
32+
);
33+
}
34+
35+
/**
36+
* \brief このコードが他のコードに内包されるかどうかを計算します。
37+
* \return 常にfalseを返します。
38+
*/
39+
bool isWithin(const GridCode& other) const override { return false; }
40+
41+
/**
42+
* \brief コードが適切な値かどうかを返します。
43+
* \return 常にfalseを返します。
44+
*/
45+
bool isValid() const override { return false; }
46+
};
47+
}

include/plateau/dataset/mesh_code.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@
55

66
#include <libplateau_api.h>
77
#include "plateau/geometry/geo_coordinate.h"
8+
#include "plateau/dataset/grid_code.h"
89

910
namespace plateau::dataset {
1011
/**
1112
* \brief 地域メッシュコードを表します。
1213
*
1314
* 2~5次メッシュの緯度経度範囲の取得、緯度経度範囲を内包する3次メッシュの取得を行う機能を提供しています。
1415
*/
15-
class LIBPLATEAU_EXPORT MeshCode {
16+
class LIBPLATEAU_EXPORT MeshCode : public GridCode {
1617
public:
1718
explicit MeshCode(const std::string& code);
1819
MeshCode() = default;
1920

2021
/**
2122
* \brief メッシュコードを文字列として取得します。
2223
*/
23-
std::string get() const;
24+
std::string get() const override;
2425

2526
/**
2627
* \brief メッシュコードの次数を取得します。
@@ -30,7 +31,7 @@ namespace plateau::dataset {
3031
/**
3132
* \brief メッシュコードの緯度経度範囲を取得します。
3233
*/
33-
geometry::Extent getExtent() const;
34+
geometry::Extent getExtent() const override;
3435

3536
/**
3637
* \brief 座標点を含む3次メッシュを取得します。
@@ -50,7 +51,7 @@ namespace plateau::dataset {
5051
/**
5152
* \brief 地域メッシュが内包されるかどうかを計算します。
5253
*/
53-
bool isWithin(const MeshCode& other) const;
54+
bool isWithin(const GridCode& other) const override;
5455

5556
/**
5657
* \brief 地域メッシュを2次メッシュとして取得します。
@@ -65,7 +66,7 @@ namespace plateau::dataset {
6566
/**
6667
* \brief メッシュコードが適切な値かどうかを返します。
6768
*/
68-
bool isValid() const;
69+
bool isValid() const override;
6970

7071
bool operator==(const MeshCode& other) const;
7172

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#pragma once
2+
3+
#include <string>
4+
5+
#include <libplateau_api.h>
6+
#include "plateau/geometry/geo_coordinate.h"
7+
#include "plateau/dataset/grid_code.h"
8+
9+
namespace plateau::dataset {
10+
/**
11+
* \brief 国土基本図図郭を表します。
12+
*
13+
* 国土基本図の図郭コードを扱い、緯度経度範囲の取得などの機能を提供します。
14+
*/
15+
class LIBPLATEAU_EXPORT StandardMapGrid : public GridCode {
16+
public:
17+
explicit StandardMapGrid(const std::string& code);
18+
StandardMapGrid() = default;
19+
20+
/**
21+
* \brief 図郭コードを文字列として取得します。
22+
*/
23+
std::string get() const override;
24+
25+
/**
26+
* \brief 図郭の緯度経度範囲を取得します。
27+
*/
28+
geometry::Extent getExtent() const override;
29+
30+
/**
31+
* \brief 図郭が他の図郭に内包されるかどうかを計算します。
32+
*/
33+
bool isWithin(const GridCode& other) const override;
34+
35+
/**
36+
* \brief 図郭コードが適切な値かどうかを返します。
37+
*/
38+
bool isValid() const override;
39+
40+
bool operator==(const StandardMapGrid& other) const;
41+
bool operator<(StandardMapGrid& other) const;
42+
bool operator<(const StandardMapGrid& other) const;
43+
44+
private:
45+
std::string code_; // 図郭コード
46+
bool is_valid_; // コードが有効かどうか
47+
};
48+
}

0 commit comments

Comments
 (0)