|
1 | 1 | #pragma once |
2 | 2 |
|
3 | 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 | 4 |
|
10 | 5 | namespace plateau::polygonMesh { |
11 | 6 |
|
12 | 7 | /** |
13 | | - * citygml::Polygon(CityGMLパーサーの出力)をpolygonMesh::Mesh(3Dモデルデータ)に変換する機能を提供します。 |
| 8 | + * Meshを結合する機能を提供します。 |
14 | 9 | */ |
15 | | - class LIBPLATEAU_EXPORT MeshFactory { |
| 10 | + class LIBPLATEAU_EXPORT MeshMerger { |
16 | 11 | 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 | | - |
69 | 12 | /** |
70 | | - * 最小地物に含まれるすべてのポリゴンをメッシュに追加します。 |
| 13 | + * Meshをマージします。 |
71 | 14 | */ |
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); |
129 | 17 | }; |
130 | 18 | } |
0 commit comments