Skip to content

Commit ab86582

Browse files
authored
exclude_triangles_outside_extentがUV4に反映されない問題の修正 (Synesthesias#176)
* exclude_outside_trianglesがUV4に反映されない問題の修正 * バグ修正
1 parent 305d5b3 commit ab86582

File tree

18 files changed

+671
-709
lines changed

18 files changed

+671
-709
lines changed

include/plateau/polygon_mesh/city_object_list.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ namespace plateau::polygonMesh {
1111
int primary_index;
1212
int atomic_index;
1313

14+
CityObjectIndex()
15+
: primary_index(0)
16+
, atomic_index(0) {
17+
}
18+
19+
CityObjectIndex(const int primary_index, const int atomic_index)
20+
: primary_index(primary_index)
21+
, atomic_index(atomic_index) {
22+
}
23+
1424
static CityObjectIndex fromUV(const TVec2f& uv) {
1525
return {
1626
static_cast<int>(std::lround(uv.x)),

include/plateau/polygon_mesh/mesh_extract_options.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace plateau::polygonMesh {
3232
unit_scale(1.0),
3333
coordinate_zone_id(9), // 東京で歪みの少ない直交座標系をデフォルトとします。
3434
exclude_city_object_outside_extent(true),
35-
exclude_triangles_outside_extent(false),
35+
exclude_polygons_outside_extent(false),
3636
extent(geometry::Extent::all()) // 全範囲をデフォルトとします。
3737
{}
3838

@@ -71,7 +71,7 @@ namespace plateau::polygonMesh {
7171
* その方法とは、メッシュ操作によって、範囲外に存在するポリゴンを除外します。
7272
* この方法であれば 10km×10km の地形など巨大なオブジェクトにも対応できます。
7373
*/
74-
bool exclude_triangles_outside_extent;
74+
bool exclude_polygons_outside_extent;
7575

7676
geometry::Extent extent;
7777
};
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#pragma once
2+
3+
#include <plateau/polygon_mesh/mesh.h>
4+
#include <plateau/polygon_mesh/mesh_extract_options.h>
5+
#include <citygml/polygon.h>
6+
#include <citygml/cityobject.h>
7+
#include <list>
8+
#include "plateau/geometry/geo_reference.h"
9+
10+
namespace plateau::polygonMesh {
11+
12+
/**
13+
* citygml::Polygon(CityGMLパーサーの出力)をpolygonMesh::Mesh(3Dモデルデータ)に変換する機能を提供します。
14+
*/
15+
class LIBPLATEAU_EXPORT MeshFactory {
16+
public:
17+
MeshFactory(
18+
std::unique_ptr<Mesh>&& target = nullptr,
19+
const MeshExtractOptions& mesh_extract_options = MeshExtractOptions(),
20+
const geometry::GeoReference& geo_reference = geometry::GeoReference(9));
21+
22+
std::unique_ptr<Mesh> releaseMesh() {
23+
return std::move(mesh_);
24+
}
25+
26+
/**
27+
* citygml::Polygon の情報を Mesh 向けに変換し、 引数の mesh に書き加えます。
28+
* 引数で与えられたポリゴンのうち、次の情報を追加します。
29+
* ・頂点リスト、インデックスリスト、UV1、テクスチャ。
30+
* なおその他の情報のマージには未対応です。例えば LinearRing は考慮されません。
31+
* options.export_appearance の値によって、 mergeWithTexture または mergeWithoutTexture を呼び出します。
32+
*/
33+
void addPolygon(const citygml::Polygon& polygon, const std::string& gml_path) const;
34+
35+
/**
36+
* 主要地物の主要地物IDを設定しMeshをマージします。
37+
*/
38+
void addPolygonsInPrimaryCityObject(
39+
const citygml::CityObject& city_object, unsigned lod,
40+
const std::string& gml_path);
41+
42+
/**
43+
* 最小地物のMeshのuv4フィールドに最小地物IDを設定するために、最小地物を構成するPolygonに含まれるVertex数を取得します。
44+
*/
45+
static long long countVertices(const citygml::CityObject& city_object, unsigned int lod);
46+
47+
/**
48+
* 最小地物に含まれるすべてのポリゴンをメッシュに追加します。
49+
*/
50+
void addPolygonsInAtomicCityObject(
51+
const citygml::CityObject& parent_city_object,
52+
const citygml::CityObject& city_object,
53+
const unsigned lod, const std::string& gml_path);
54+
55+
/**
56+
* 最小地物に含まれるすべてのポリゴンをメッシュに追加します。
57+
*/
58+
void addPolygonsInAtomicCityObjects(
59+
const citygml::CityObject& parent_city_object,
60+
const std::list<const citygml::CityObject*>& city_objects,
61+
unsigned lod, const std::string& gml_path);
62+
63+
/**
64+
* city_obj に含まれるポリゴンをすべて検索し、リストで返します。
65+
* 子の CityObject は検索しません。
66+
* 子の Geometry は再帰的に検索します。
67+
*/
68+
static void findAllPolygons(const citygml::CityObject& city_obj, unsigned lod, std::list<const citygml::Polygon*>& out_polygons, long long& out_vertices_count, const plateau::geometry::Extent& extent = plateau::geometry::Extent::all());
69+
70+
/**
71+
* PLATEAUからメッシュを読み込んで座標軸を変換をするとき、このままだとメッシュが裏返ることがあります(座標軸が反転したりするので)。
72+
* 裏返りを補正する必要があるかどうかを bool で返します。
73+
*/
74+
static bool shouldInvertIndicesOnMeshConvert(plateau::geometry::CoordinateSystem sys);
75+
private:
76+
MeshExtractOptions options_;
77+
geometry::GeoReference geo_reference_;
78+
79+
std::unique_ptr<Mesh> mesh_;
80+
// 新規に主要地物を追加する際に利用可能なインデックス
81+
CityObjectIndex available_primary_index_;
82+
// 主要地物のgml::idに対して子(最小地物)を追加する際に利用可能なインデックス
83+
std::map<std::string, CityObjectIndex> available_atomic_indices_;
84+
85+
// 最後に個別に追加された最小地物のインデックスとその親のgml:idのキャッシュ(高速化用)
86+
CityObjectIndex last_atomic_index_cache_;
87+
std::string last_parent_gml_id_cache_;
88+
89+
CityObjectIndex createAvailableAtomicIndex(const std::string& parent_gml_id);
90+
};
91+
}
Lines changed: 5 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,18 @@
11
#pragma once
22

33
#include <plateau/polygon_mesh/mesh.h>
4-
#include <plateau/polygon_mesh/mesh_extract_options.h>
5-
#include <citygml/polygon.h>
6-
#include <citygml/cityobject.h>
7-
#include <list>
8-
#include "plateau/geometry/geo_reference.h"
94

105
namespace plateau::polygonMesh {
116

127
/**
13-
* citygml::Polygon(CityGMLパーサーの出力)をpolygonMesh::Mesh(3Dモデルデータ)に変換する機能を提供します
8+
* Meshを結合する機能を提供します
149
*/
15-
class LIBPLATEAU_EXPORT MeshFactory {
10+
class LIBPLATEAU_EXPORT MeshMerger {
1611
public:
17-
MeshFactory(
18-
std::unique_ptr<Mesh>&& target = nullptr,
19-
const MeshExtractOptions& mesh_extract_options = MeshExtractOptions(),
20-
const geometry::GeoReference& geo_reference = geometry::GeoReference(9));
21-
22-
std::unique_ptr<Mesh> releaseMesh() {
23-
return std::move(mesh_);
24-
}
25-
26-
/**
27-
* citygml::Polygon の情報を Mesh 向けに変換し、 引数の mesh に書き加えます。
28-
* 引数で与えられたポリゴンのうち、次の情報を追加します。
29-
* ・頂点リスト、インデックスリスト、UV1、テクスチャ。
30-
* なおその他の情報のマージには未対応です。例えば LinearRing は考慮されません。
31-
* options.export_appearance の値によって、 mergeWithTexture または mergeWithoutTexture を呼び出します。
32-
*/
33-
void addPolygon(const citygml::Polygon& polygon, const std::string& gml_path);
34-
35-
/**
36-
* Mesh に Polygon をマージする代わりに Mesh をマージする版です。
37-
*/
38-
void mergeMesh(const Mesh& other_mesh, bool invert_mesh_front_back, bool include_textures) const;
39-
40-
/**
41-
* Mesh に Polygon をマージする代わりに、データ配列を直接 move で渡す版です。
42-
*/
43-
void mergeMeshInfo(
44-
std::vector<TVec3d>&& vertices, std::vector<unsigned>&& indices,
45-
UV&& uv_1, std::vector<SubMesh>&& sub_meshes,
46-
plateau::geometry::CoordinateSystem mesh_axis_convert_from,
47-
plateau::geometry::CoordinateSystem mesh_axis_convert_to, bool include_texture);
48-
49-
/**
50-
* 主要地物の主要地物IDを設定しMeshをマージします。
51-
*/
52-
void addPolygonsInPrimaryCityObject(
53-
const citygml::CityObject& city_object, unsigned lod,
54-
const std::string& gml_path);
55-
56-
/**
57-
* 最小地物のMeshのuv4フィールドに最小地物IDを設定するために、最小地物を構成するPolygonに含まれるVertex数を取得します。
58-
*/
59-
static long long countVertices(const citygml::CityObject& city_object, unsigned int lod);
60-
61-
/**
62-
* 最小地物に含まれるすべてのポリゴンをメッシュに追加します。
63-
*/
64-
void addPolygonsInAtomicCityObject(
65-
const citygml::CityObject& parent_city_object,
66-
const citygml::CityObject& city_object,
67-
const unsigned lod, const std::string& gml_path);
68-
6912
/**
70-
* 最小地物に含まれるすべてのポリゴンをメッシュに追加します
13+
* Meshをマージします
7114
*/
72-
void addPolygonsInAtomicCityObjects(
73-
const citygml::CityObject& parent_city_object,
74-
const std::list<const citygml::CityObject*>& city_objects,
75-
unsigned lod, const std::string& gml_path);
76-
77-
/**
78-
* city_obj に含まれるポリゴンをすべて検索し、リストで返します。
79-
* 子の CityObject は検索しません。
80-
* 子の Geometry は再帰的に検索します。
81-
*/
82-
static void findAllPolygons(const citygml::CityObject& city_obj, unsigned lod, std::list<const citygml::Polygon*>& out_polygons, long long& out_vertices_count);
83-
84-
/**
85-
* PLATEAUからメッシュを読み込んで座標軸を変換をするとき、このままだとメッシュが裏返ることがあります(座標軸が反転したりするので)。
86-
* 裏返りを補正する必要があるかどうかを bool で返します。
87-
*/
88-
static bool shouldInvertIndicesOnMeshConvert(plateau::geometry::CoordinateSystem sys);
89-
private:
90-
MeshExtractOptions options_;
91-
geometry::GeoReference geo_reference_;
92-
93-
std::unique_ptr<Mesh> mesh_;
94-
// 新規に主要地物を追加する際に利用可能なインデックス
95-
CityObjectIndex available_primary_index_;
96-
// 主要地物のgml::idに対して子(最小地物)を追加する際に利用可能なインデックス
97-
std::map<std::string, CityObjectIndex> available_atomic_indices_;
98-
99-
// 最後に個別に追加された最小地物のインデックスとその親のgml:idのキャッシュ(高速化用)
100-
CityObjectIndex last_atomic_index_cache_;
101-
std::string last_parent_gml_id_cache_;
102-
103-
/**
104-
* merge関数 のテクスチャ無し版です。
105-
* 生成される Mesh の SubMesh はただ1つであり、そのテクスチャパスは空文字列となります。
106-
*/
107-
void mergeWithoutTexture(const Mesh& other_mesh, bool invert_mesh_front_back) const;
108-
109-
/**
110-
* merge関数 のテクスチャあり版です。
111-
* テクスチャについては、マージした結果、範囲とテクスチャを対応付ける SubMesh が追加されます。
112-
*/
113-
void mergeWithTexture(const Mesh& other_mesh, bool invert_mesh_front_back) const;
114-
115-
/**
116-
* 形状情報をマージします。merge関数における SubMesh を扱わない版です。
117-
*/
118-
void mergeShape(const Mesh& other_mesh, const bool invert_mesh_front_back) const {
119-
const auto prev_num_vertices = mesh_->getVertices().size();
120-
const auto other_num_vertices = other_mesh.getVertices().size();
121-
122-
mesh_->addVerticesList(other_mesh.getVertices());
123-
mesh_->addIndicesList(other_mesh.getIndices(), prev_num_vertices, invert_mesh_front_back);
124-
mesh_->addUV1(other_mesh.getUV1(), static_cast<unsigned>(other_num_vertices));
125-
mesh_->addUV4(other_mesh.getUV4(), static_cast<unsigned>(other_num_vertices));
126-
}
127-
128-
CityObjectIndex createAvailableAtomicIndex(const std::string& parent_gml_id);
15+
static void mergeMesh(
16+
Mesh& mesh, const Mesh& other_mesh, bool invert_mesh_front_back, bool include_textures);
12917
};
13018
}

0 commit comments

Comments
 (0)