Skip to content

Commit

Permalink
ゲームエンジンとの差異を埋めるテストモデルに変更(したがってテスト失敗)
Browse files Browse the repository at this point in the history
同上
  • Loading branch information
linoal committed Oct 23, 2023
1 parent d1ae8e1 commit bd5636e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
1 change: 0 additions & 1 deletion include/plateau/polygon_mesh/city_object_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ namespace plateau::polygonMesh {
*/
class LIBPLATEAU_EXPORT CityObjectList {
using TIdMap = std::map<CityObjectIndex, std::string>;

public:
CityObjectList() = default;
CityObjectList(const std::vector<std::tuple<CityObjectIndex, std::string>>& initial_val);
Expand Down
53 changes: 46 additions & 7 deletions test/test_granularity_convert/model_convert_test_patterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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};
}
Expand All @@ -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<Mesh> ModelConvertTestPatternsFactory::createTestMeshOfArea(std::vector<CityObjectIndex> city_object_indices, CityObjectList city_obj_list) {
std::unique_ptr<Mesh> ModelConvertTestPatternsFactory::createTestMeshOfArea(
std::vector<CityObjectIndex> city_object_indices, CityObjectList city_obj_list) {
TVec3d base_pos = {0, 0, 0};
unsigned int base_id = 0;
std::vector<TVec3d> vertices;
Expand Down Expand Up @@ -392,6 +416,21 @@ std::unique_ptr<Mesh> 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は無視されるので何の値でも良いです。
Expand Down Expand Up @@ -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"));
Expand Down
8 changes: 7 additions & 1 deletion test/test_granularity_convert/model_convert_test_patterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ModelConvertTestPatternsFactory {
ModelConvertTestPatterns createTestPatternsOfAtomic_OnlyRoot();

/// テスト用モデル(地域単位)で、主要地物のメッシュがないバージョンです。
ModelConvertTestPatterns createTestPatternsOfArea_OnlyAtomicMesh();
ModelConvertTestPatterns createTestPatternsFromArea_OnlyAtomicMesh();
/// テスト(主要地物)
ModelConvertTestPatterns createTestPatternsOfAtomic_OnlyAtomicMesh();
/// テスト(最小地物)
Expand All @@ -122,6 +122,12 @@ class ModelConvertTestPatternsFactory {

private:
std::unique_ptr<plateau::polygonMesh::Mesh> createTestMeshOfArea(std::vector<plateau::polygonMesh::CityObjectIndex> city_object_indices, plateau::polygonMesh::CityObjectList city_obj_list);

/// 最小地物単位の入力をテストするとき、そのテストデータは地域から最小に変換したものが利用されます。
/// しかし、地域から変換したものとゲームエンジンからの実際の入力には差異があります。
/// その差異を補正してテストデータを実際のゲームエンジンからの入力に近づけることを目的とします。
void adjustForTestModelForAtomic(plateau::polygonMesh::Model& model);

ModelConvertTestPatterns::TGranularityToExpect createExpectsForTestMeshArea();

const std::vector<plateau::polygonMesh::CityObjectIndex> test_indices_primary_and_atomic = {
Expand Down
6 changes: 3 additions & 3 deletions test/test_granularity_convert/test_granularity_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bd5636e

Please sign in to comment.