diff --git a/assets/ACModel/test.acim b/assets/ACModel/test.acim index 28eba855d..a03cb11eb 100644 --- a/assets/ACModel/test.acim +++ b/assets/ACModel/test.acim @@ -1,9 +1,8 @@ - NotDone + NotDone Cut#1 - NotDone -4.4408920985e-16 -1.33226762955e-15 -8.07965638975e-07 1.85073895234 -1.33226762955e-15 -8.07965638975e-07 diff --git a/src/AIAC/ACInfoModel.cpp b/src/AIAC/ACInfoModel.cpp index 7142032e1..2ed9eb87f 100644 --- a/src/AIAC/ACInfoModel.cpp +++ b/src/AIAC/ACInfoModel.cpp @@ -12,10 +12,13 @@ namespace AIAC ///< Base Component void TimberInfo::Component::SetAsCurrent() { m_State = ACIMState::CURRENT; + +#ifndef HEADLESS_TEST AIAC_APP.GetLayer()->GetACInfoModel().GetDoc().child("acim").child("timber").child("current").last_child().set_value(m_ID.c_str()); AIAC_APP.GetLayer()->GetACInfoModel().Save(); AIAC_APP.GetRenderer()->SetGlobalViewToActivatedComponent(Renderer::StandardView::TOP); +#endif } void TimberInfo::Component::SetAsDone() { diff --git a/src/AIAC/ACInfoModel.h b/src/AIAC/ACInfoModel.h index e740768cb..fe66922b2 100644 --- a/src/AIAC/ACInfoModel.h +++ b/src/AIAC/ACInfoModel.h @@ -88,7 +88,9 @@ class TimberInfo{ class Component { public: Component(std::string type) : m_Type(type) { +#ifndef HEADLESS_TEST m_Scale = AIAC::Config::Get(AIAC::Config::SEC_AIAC, AIAC::Config::SCALE_FACTOR, 1.0f); +#endif } virtual void SetAsCurrent(); virtual void SetAsDone(); @@ -235,8 +237,8 @@ class TimberInfo{ }; inline bool IsSingleFace() const { return m_NonExposedFaceIDs.size() == 1; } - inline Face& GetFace(std::string id) { return m_Faces[id]; } - inline Edge& GetEdge(std::string id) { return m_Edges[id]; } + inline Face& GetFace(std::string id) { if(m_Faces.count(id) == 0) throw std::invalid_argument("Face ID does not exist."); return m_Faces[id]; } + inline Edge& GetEdge(std::string id) { if(m_Edges.count(id) == 0) throw std::invalid_argument("Edge ID does not exist."); return m_Edges[id]; } inline std::map& GetAllFaces() { return m_Faces; } inline std::map& GetAllEdges() { return m_Edges; } inline std::set& GetAllNonExposedFaceIDs() { return m_NonExposedFaceIDs; } @@ -358,7 +360,9 @@ class ACInfoModel { public: ACInfoModel(){ +#ifndef HEADLESS_TEST m_Scale = AIAC::Config::Get(AIAC::Config::SEC_AIAC, AIAC::Config::SCALE_FACTOR, 1.0f); +#endif }; ~ACInfoModel(){}; @@ -454,7 +458,7 @@ class ACInfoModel float m_EdgeWeight = 1.1f; float m_LabelSize = 0.75f; - float m_Scale; + float m_Scale = 1.0f; float m_MeasuredBboxLength; std::string m_FilePath; diff --git a/src/AIAC/Log.h b/src/AIAC/Log.h index 32970e0d4..27431ea89 100644 --- a/src/AIAC/Log.h +++ b/src/AIAC/Log.h @@ -21,7 +21,7 @@ namespace AIAC }; } -#ifdef SILENT_LOGGING +#if (defined SILENT_LOGGING && !defined HEADLESS_TEST) #define AIAC_INFO(...) SPDLOG_LOGGER_INFO(AIAC::Log::GetLogger(), __VA_ARGS__) #define AIAC_WARN(...) SPDLOG_LOGGER_WARN(AIAC::Log::GetLogger(), __VA_ARGS__) #define AIAC_ERROR(...) SPDLOG_LOGGER_ERROR(AIAC::Log::GetLogger(), __VA_ARGS__) diff --git a/tests/unit_tests/InfoModelTest.cc b/tests/unit_tests/InfoModelTest.cc new file mode 100644 index 000000000..7aa1d6e50 --- /dev/null +++ b/tests/unit_tests/InfoModelTest.cc @@ -0,0 +1,87 @@ +#include +#include "AIAC/ACInfoModel.h" + +#include +#include + +auto const MAX_ABS_ERROR = 1e-3f; + +class InfoModelTest : public ::testing::Test { +protected: + void SetUp() override { } + + void TearDown() override {} +}; + +TEST_F(InfoModelTest, FileIO) { + AIAC::ACInfoModel acim; + + std::string path = "../assets/ACModel/test.acim"; + acim.Load(path); + + EXPECT_EQ(acim.GetFilePath(), path); + EXPECT_EQ(acim.GetName(), "test"); +} + +TEST_F(InfoModelTest, ContentParsing) { + AIAC::ACInfoModel acim; + + std::string path = "../assets/ACModel/test.acim"; + acim.Load(path); + + auto& timberInfo = acim.GetTimberInfo(); + + // bounding box + auto bboxPts = timberInfo.GetBoundingBox(); + EXPECT_EQ(bboxPts.size(), 8); + + ASSERT_TRUE(glm::distance(glm::vec3(0, 0, -8.07965638975e-07f), bboxPts[0]) < MAX_ABS_ERROR); + ASSERT_TRUE(glm::distance(glm::vec3(1.85073895234f, 0, 0.130034050856f), bboxPts[5]) < MAX_ABS_ERROR); + ASSERT_TRUE(glm::distance(glm::vec3(0, 0.129643784514f, 0.130034050856f), bboxPts[7]) < MAX_ABS_ERROR); + + // components + std::vector allComponentsIDs = timberInfo.GetAllComponentsIDs(); + std::unordered_set allComponentsIDsSet(allComponentsIDs.begin(), allComponentsIDs.end()); + + std::vector expectedIDs = { + "Hole#1", "Hole#2", "Hole#3", "Hole#4", "Hole#5", "Hole#6", "Hole#7", "Hole#8", "Hole#9", "Hole#10", + "Cut#1", "Cut#2", "Cut#3", "Cut#4", "Cut#5", "Cut#6", "Cut#7" + }; + + ASSERT_EQ(allComponentsIDsSet.size(), expectedIDs.size()); + for (auto& id : expectedIDs) { + ASSERT_NE(allComponentsIDsSet.find(id), allComponentsIDsSet.end()); + } + + // holes + auto hole1 = static_cast(timberInfo.GetComponent("Hole#1")); + ASSERT_EQ(hole1->GetRadius(), 0.025f); + ASSERT_EQ(hole1->GetStartPointGO()->GetPosition(), glm::vec3(0.171164716736f, 0.0874013529763f, 0.130030809657f)); + ASSERT_EQ(hole1->GetEndPointGO()->GetPosition(), glm::vec3(0.171164716736f, 0.0874013529763f, 6.34902733979e-16f)); + ASSERT_EQ(hole1->GetCenter(), glm::vec3(0.171164716736f, 0.0874013529763f, 0.0650154048285f)); + + // cuts + auto cut1 = static_cast(timberInfo.GetComponent("Cut#1")); + ASSERT_EQ(cut1->GetCenter(), glm::vec3(0.543917917169f, 0.064821892257f, 0.10202644336f)); + ASSERT_EQ(cut1->GetAllFaces().size(), 3); // 3 unexposed faces + ASSERT_EQ(cut1->GetAllEdges().size(), 12); + + auto face1 = cut1->GetFace("1"); + auto edges = face1.GetEdges(); + ASSERT_EQ(edges.size(), 4); + auto edgeIdSet = std::unordered_set(edges.begin(), edges.end()); + for(auto& edgeId : {"0", "2", "5", "7"}) { + ASSERT_NE(edgeIdSet.find(edgeId), edgeIdSet.end()); + } + + auto corners = face1.GetCorners(); + ASSERT_EQ(corners.size(), 4); + ASSERT_TRUE(glm::distance(corners[0], glm::vec3(0.650908f, 0.129637f, 0.074019f)) < MAX_ABS_ERROR); + ASSERT_TRUE(glm::distance(corners[1], glm::vec3(0.583188f, 0.000000f, 0.074019f)) < MAX_ABS_ERROR); + ASSERT_TRUE(glm::distance(corners[2], glm::vec3(0.583188f, -0.000000f, 0.130034f)) < MAX_ABS_ERROR); + ASSERT_TRUE(glm::distance(corners[3], glm::vec3(0.650908f, 0.129644f, 0.130034f)) < MAX_ABS_ERROR); + + auto edge0 = cut1->GetEdge("0"); + ASSERT_EQ(edge0.GetStartPt().GetPosition(), glm::vec3(0.583187494871f, -1.33226762955e-15f, 0.130034050856f)); + ASSERT_EQ(edge0.GetEndPt().GetPosition(), glm::vec3(0.583187494871f, 6.66133814775e-16f, 0.0740188358647f)); +} \ No newline at end of file