From b5345841989a53979260e136c5ca53b181676e13 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Wed, 8 Mar 2023 16:10:40 +0200 Subject: [PATCH 1/2] Improve unit tests which load subdivision models --- test/unit/utACImportExport.cpp | 23 +++++++++++++++++++++++ test/unit/utBlenderImportExport.cpp | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/test/unit/utACImportExport.cpp b/test/unit/utACImportExport.cpp index 9615a3a3e..c844603cf 100644 --- a/test/unit/utACImportExport.cpp +++ b/test/unit/utACImportExport.cpp @@ -43,6 +43,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include + using namespace Assimp; @@ -68,6 +70,27 @@ TEST(utACImportExport, importSampleSubdiv) { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/AC/sample_subdiv.ac", aiProcess_ValidateDataStructure); ASSERT_NE(nullptr, scene); + + // check approximate shape by averaging together all vertices + ASSERT_EQ(scene->mNumMeshes, 1u); + aiVector3D vertexAvg(0.0, 0.0, 0.0); + for (unsigned int i = 0; i < scene->mNumMeshes; i++) { + const aiMesh *mesh = scene->mMeshes[i]; + ASSERT_NE(mesh, nullptr); + + ai_real invVertexCount = 1.0 / mesh->mNumVertices; + for (unsigned int j = 0; j < mesh->mNumVertices; j++) { + vertexAvg += mesh->mVertices[j] * invVertexCount; + } + } + + // must not be inf or nan + ASSERT_TRUE(std::isfinite(vertexAvg.x)); + ASSERT_TRUE(std::isfinite(vertexAvg.y)); + ASSERT_TRUE(std::isfinite(vertexAvg.z)); + EXPECT_NEAR(vertexAvg.x, 0.079997420310974121, 0.0001); + EXPECT_NEAR(vertexAvg.y, 0.099498569965362549, 0.0001); + EXPECT_NEAR(vertexAvg.z, -0.10344827175140381, 0.0001); } TEST(utACImportExport, importSphereWithLight) { diff --git a/test/unit/utBlenderImportExport.cpp b/test/unit/utBlenderImportExport.cpp index c9cce72b4..c220b7daa 100644 --- a/test/unit/utBlenderImportExport.cpp +++ b/test/unit/utBlenderImportExport.cpp @@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include using namespace Assimp; @@ -156,6 +157,27 @@ TEST(utBlenderImporter, importSuzanneSubdiv_252) { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/SuzanneSubdiv_252.blend", aiProcess_ValidateDataStructure); ASSERT_NE(nullptr, scene); + + // check approximate shape by averaging together all vertices + ASSERT_EQ(scene->mNumMeshes, 1u); + aiVector3D vertexAvg(0.0, 0.0, 0.0); + for (unsigned int i = 0; i < scene->mNumMeshes; i++) { + const aiMesh *mesh = scene->mMeshes[i]; + ASSERT_NE(mesh, nullptr); + + ai_real invVertexCount = 1.0 / mesh->mNumVertices; + for (unsigned int j = 0; j < mesh->mNumVertices; j++) { + vertexAvg += mesh->mVertices[j] * invVertexCount; + } + } + + // must not be inf or nan + ASSERT_TRUE(std::isfinite(vertexAvg.x)); + ASSERT_TRUE(std::isfinite(vertexAvg.y)); + ASSERT_TRUE(std::isfinite(vertexAvg.z)); + EXPECT_NEAR(vertexAvg.x, 6.4022515289252624e-08, 0.0001); + EXPECT_NEAR(vertexAvg.y, 0.060569953173398972, 0.0001); + EXPECT_NEAR(vertexAvg.z, 0.31429031491279602, 0.0001); } TEST(utBlenderImporter, importTexturedCube_ImageGlob_248) { From f3767a4eb21f2f272102d0fe4020d4e4ca3154bc Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Wed, 8 Mar 2023 16:18:10 +0200 Subject: [PATCH 2/2] Use unordered_map for subdivision process edge map --- code/Common/Subdivision.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/Common/Subdivision.cpp b/code/Common/Subdivision.cpp index 705ea3fb3..ac4078b47 100644 --- a/code/Common/Subdivision.cpp +++ b/code/Common/Subdivision.cpp @@ -50,6 +50,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include + using namespace Assimp; void mydummy() {} @@ -78,7 +80,7 @@ public: }; typedef std::vector UIntVector; - typedef std::map EdgeMap; + typedef std::unordered_map EdgeMap; // --------------------------------------------------------------------------- // Hashing function to derive an index into an #EdgeMap from two given