diff --git a/include/plateau/polygon_mesh/city_object_list.h b/include/plateau/polygon_mesh/city_object_list.h index 48378dac..5695f870 100644 --- a/include/plateau/polygon_mesh/city_object_list.h +++ b/include/plateau/polygon_mesh/city_object_list.h @@ -129,7 +129,6 @@ namespace plateau::polygonMesh { */ class LIBPLATEAU_EXPORT CityObjectList { using TIdMap = std::map; - public: CityObjectList() = default; CityObjectList(const std::vector>& initial_val); diff --git a/test/test_granularity_convert/model_convert_test_patterns.cpp b/test/test_granularity_convert/model_convert_test_patterns.cpp index b8480286..22111cf0 100644 --- a/test/test_granularity_convert/model_convert_test_patterns.cpp +++ b/test/test_granularity_convert/model_convert_test_patterns.cpp @@ -8,7 +8,25 @@ using namespace plateau::polygonMesh; using namespace plateau::granularityConvert; -void NodeExpect::checkNode(const plateau::polygonMesh::Node* node) const { +namespace { + /// MeshのCityObjectListについて、AtomicとPrimaryの両方のIDがある場合、Primaryのみを除きます。 + /// こうすることで、ゲームエンジンから送られる情報とテストデータを合わせます。 + void removePrimaryFromCityObjectListWithAtomic(Mesh& mesh) { + auto& list = mesh.getCityObjectList(); + auto primary_size = list.getAllPrimaryIndices().size(); + auto atomic_size = list.size() - primary_size; + if(primary_size == 0 || atomic_size ==0) return; + + CityObjectList next_list; + for(const auto& [index, gml_id] : list) { + if(index.atomic_index == CityObjectIndex::invalidIndex()) continue; + next_list.add(index, gml_id); + } + mesh.setCityObjectList(next_list); + } +} + +void NodeExpect::checkNode(const Node* node) const { EXPECT_EQ(node->getName(), expect_node_name_); EXPECT_EQ(!(node->getMesh() == nullptr), expect_have_mesh_); if(node->getMesh() != nullptr) { @@ -145,13 +163,14 @@ ModelConvertTestPatterns ModelConvertTestPatternsFactory::createTestPatternsOfAt auto area_patterns = createTestPatternsOfArea_OnlyRoot(); auto option = GranularityConvertOption(MeshGranularity::PerAtomicFeatureObject, 10); auto atomic_model = GranularityConverter().convert(area_patterns.getModel(), option); + adjustForTestModelForAtomic(atomic_model); auto expects = area_patterns.getExpects(); auto& expect_primary = expects.at(MeshGranularity::PerPrimaryFeatureObject); return {std::move(atomic_model), expects}; } ModelConvertTestPatterns ModelConvertTestPatternsFactory::createTestPatternsOfPrimary_OnlyAtomicMesh() { - auto area_patterns = createTestPatternsOfArea_OnlyAtomicMesh(); + auto area_patterns = createTestPatternsFromArea_OnlyAtomicMesh(); auto option = GranularityConvertOption(MeshGranularity::PerPrimaryFeatureObject, 10); auto primary_model = GranularityConverter().convert(area_patterns.getModel(), option); auto primary_expect = area_patterns.getExpects(); @@ -164,7 +183,7 @@ ModelConvertTestPatterns ModelConvertTestPatternsFactory::createTestPatternsOfAr auto& node = model.addNode(Node("root_node")); node.setMesh(std::move(mesh)); - auto expects = createTestPatternsOfArea_OnlyAtomicMesh().getExpects(); + auto expects = createTestPatternsFromArea_OnlyAtomicMesh().getExpects(); auto& expect_atomic = expects.at(MeshGranularity::PerAtomicFeatureObject); auto& expect_primary = expects.at(MeshGranularity::PerPrimaryFeatureObject); auto& expect_area = expects.at(MeshGranularity::PerCityModelArea); @@ -216,6 +235,7 @@ ModelConvertTestPatterns ModelConvertTestPatternsFactory::createTestPatternsOfAt auto area_patterns = createTestPatternsOfArea_OnlyAtomicMesh_Root(); auto options = GranularityConvertOption(MeshGranularity::PerAtomicFeatureObject, 10); auto atomic_model = GranularityConverter().convert(area_patterns.getModel(), options); + adjustForTestModelForAtomic(atomic_model); auto expects = area_patterns.getExpects(); auto& expect_to_primary = expects.at(MeshGranularity::PerPrimaryFeatureObject); // auto expect_primary = ModelExpect({ @@ -312,9 +332,10 @@ ModelConvertTestPatterns ModelConvertTestPatternsFactory::createTestPatternsOfPr } ModelConvertTestPatterns ModelConvertTestPatternsFactory::createTestPatternsOfAtomic_WithoutCityObjList() { - auto area_patterns = createTestPatternsOfArea_OnlyAtomicMesh(); + auto area_patterns = createTestPatternsFromArea_OnlyAtomicMesh(); auto option = GranularityConvertOption(MeshGranularity::PerAtomicFeatureObject, 10); auto atomic_model = GranularityConverter().convert(area_patterns.getModel(), option); + adjustForTestModelForAtomic(atomic_model); auto atomic_expect = area_patterns.getExpects(); return {std::move(atomic_model), atomic_expect}; } @@ -327,21 +348,24 @@ ModelConvertTestPatterns ModelConvertTestPatternsFactory::createTestPatternsOfAt auto area_patterns = createTestPatternsOfArea(); auto option = GranularityConvertOption(MeshGranularity::PerAtomicFeatureObject, 10); auto atomic_model = GranularityConverter().convert(area_patterns.getModel(), option); + adjustForTestModelForAtomic(atomic_model); // 期待する変換結果は地域単位と同じです。 auto atomic_expect = area_patterns.getExpects(); return {std::move(atomic_model), atomic_expect}; } ModelConvertTestPatterns ModelConvertTestPatternsFactory::createTestPatternsOfAtomic_OnlyAtomicMesh() { - auto area_model = createTestPatternsOfArea_OnlyAtomicMesh(); + auto area_model = createTestPatternsFromArea_OnlyAtomicMesh(); auto option = GranularityConvertOption(MeshGranularity::PerAtomicFeatureObject, 10); auto atomic_model = GranularityConverter().convert(area_model.getModel(), option); + adjustForTestModelForAtomic(atomic_model); // 期待する変換結果は地域単位と同じです。 auto atomic_expect = area_model.getExpects(); return {std::move(atomic_model), atomic_expect}; } -std::unique_ptr ModelConvertTestPatternsFactory::createTestMeshOfArea(std::vector city_object_indices, CityObjectList city_obj_list) { +std::unique_ptr ModelConvertTestPatternsFactory::createTestMeshOfArea( + std::vector city_object_indices, CityObjectList city_obj_list) { TVec3d base_pos = {0, 0, 0}; unsigned int base_id = 0; std::vector vertices; @@ -392,6 +416,21 @@ std::unique_ptr ModelConvertTestPatternsFactory::createTestMeshOfArea(std: return mesh; } +void ModelConvertTestPatternsFactory::adjustForTestModelForAtomic(plateau::polygonMesh::Model& model) { + NodeQueue queue; + queue.pushRoot(&model); + while(!queue.empty()) { + auto node_path = queue.pop(); + auto node = node_path.toNode(&model); + node->setIsPrimary(false); + auto mesh = node->getMesh(); + if(mesh != nullptr) { + removePrimaryFromCityObjectListWithAtomic(*mesh); + } + queue.pushChildren(node_path, &model); + } +} + ModelConvertTestPatterns::TGranularityToExpect ModelConvertTestPatternsFactory::createExpectsForTestMeshArea() { // メッシュを持たないオブジェクトはCityObjectIndexは無視されるので何の値でも良いです。 @@ -484,7 +523,7 @@ ModelConvertTestPatterns::TGranularityToExpect ModelConvertTestPatternsFactory:: return convert_expects; } -ModelConvertTestPatterns ModelConvertTestPatternsFactory::createTestPatternsOfArea_OnlyAtomicMesh() { +ModelConvertTestPatterns ModelConvertTestPatternsFactory::createTestPatternsFromArea_OnlyAtomicMesh() { auto mesh = createTestMeshOfArea(test_indices_only_atomic, test_city_obj_list_indices_only_atomic); auto model = Model(); auto& gml_node = model.addNode(Node("gml_node")); diff --git a/test/test_granularity_convert/model_convert_test_patterns.h b/test/test_granularity_convert/model_convert_test_patterns.h index a407cfef..29716da1 100644 --- a/test/test_granularity_convert/model_convert_test_patterns.h +++ b/test/test_granularity_convert/model_convert_test_patterns.h @@ -103,7 +103,7 @@ class ModelConvertTestPatternsFactory { ModelConvertTestPatterns createTestPatternsOfAtomic_OnlyRoot(); /// テスト用モデル(地域単位)で、主要地物のメッシュがないバージョンです。 - ModelConvertTestPatterns createTestPatternsOfArea_OnlyAtomicMesh(); + ModelConvertTestPatterns createTestPatternsFromArea_OnlyAtomicMesh(); /// テスト(主要地物) ModelConvertTestPatterns createTestPatternsOfAtomic_OnlyAtomicMesh(); /// テスト(最小地物) @@ -122,6 +122,12 @@ class ModelConvertTestPatternsFactory { private: std::unique_ptr createTestMeshOfArea(std::vector city_object_indices, plateau::polygonMesh::CityObjectList city_obj_list); + + /// 最小地物単位の入力をテストするとき、そのテストデータは地域から最小に変換したものが利用されます。 + /// しかし、地域から変換したものとゲームエンジンからの実際の入力には差異があります。 + /// その差異を補正してテストデータを実際のゲームエンジンからの入力に近づけることを目的とします。 + void adjustForTestModelForAtomic(plateau::polygonMesh::Model& model); + ModelConvertTestPatterns::TGranularityToExpect createExpectsForTestMeshArea(); const std::vector test_indices_primary_and_atomic = { diff --git a/test/test_granularity_convert/test_granularity_converter.cpp b/test/test_granularity_convert/test_granularity_converter.cpp index e11e3c6d..053939b2 100644 --- a/test/test_granularity_convert/test_granularity_converter.cpp +++ b/test/test_granularity_convert/test_granularity_converter.cpp @@ -82,15 +82,15 @@ TEST_F(GranularityConverterTest, convertPrimaryToAtomic) { // NOLINT } TEST_F(GranularityConverterTest, convertAreaToAtomic_OnlyAtomic) { // NOLINT - ModelConvertTestPatternsFactory().createTestPatternsOfArea_OnlyAtomicMesh().test(MeshGranularity::PerAtomicFeatureObject); + ModelConvertTestPatternsFactory().createTestPatternsFromArea_OnlyAtomicMesh().test(MeshGranularity::PerAtomicFeatureObject); } TEST_F(GranularityConverterTest, convertAreaToPrimary_OnlyAtomic) { // NOLINT - ModelConvertTestPatternsFactory().createTestPatternsOfArea_OnlyAtomicMesh().test(MeshGranularity::PerPrimaryFeatureObject); + ModelConvertTestPatternsFactory().createTestPatternsFromArea_OnlyAtomicMesh().test(MeshGranularity::PerPrimaryFeatureObject); } TEST_F(GranularityConverterTest, convertAreaToArea_OnlyAtomic) { // NOLINT - ModelConvertTestPatternsFactory().createTestPatternsOfArea_OnlyAtomicMesh().test(MeshGranularity::PerCityModelArea); + ModelConvertTestPatternsFactory().createTestPatternsFromArea_OnlyAtomicMesh().test(MeshGranularity::PerCityModelArea); } TEST_F(GranularityConverterTest, convertAtomicToArea_OnlyAtomic) { // NOLINT