2
0
Эх сурвалжийг харах

FindDegeneratives: adapt unittests and add configs

Kim Kulling 7 жил өмнө
parent
commit
24b728b3ea

+ 18 - 13
code/FindDegenerates.cpp

@@ -56,7 +56,8 @@ using namespace Assimp;
 // ------------------------------------------------------------------------------------------------
 // Constructor to be privately used by Importer
 FindDegeneratesProcess::FindDegeneratesProcess()
-: configRemoveDegenerates (false) {
+: mConfigRemoveDegenerates( false )
+, mConfigCheckAreaOfTriangle( false ){
     // empty
 }
 
@@ -76,7 +77,8 @@ bool FindDegeneratesProcess::IsActive( unsigned int pFlags) const {
 // Setup import configuration
 void FindDegeneratesProcess::SetupProperties(const Importer* pImp) {
     // Get the current value of AI_CONFIG_PP_FD_REMOVE
-    configRemoveDegenerates = (0 != pImp->GetPropertyInteger(AI_CONFIG_PP_FD_REMOVE,0));
+    mConfigRemoveDegenerates = (0 != pImp->GetPropertyInteger(AI_CONFIG_PP_FD_REMOVE,0));
+    mConfigCheckAreaOfTriangle = ( 0 != pImp->GetPropertyInteger(AI_CONFIG_PP_FD_CHECKAREA) );
 }
 
 // ------------------------------------------------------------------------------------------------
@@ -126,7 +128,7 @@ void FindDegeneratesProcess::ExecuteOnMesh( aiMesh* mesh) {
     mesh->mPrimitiveTypes = 0;
 
     std::vector<bool> remove_me;
-    if (configRemoveDegenerates) {
+    if (mConfigRemoveDegenerates) {
         remove_me.resize( mesh->mNumFaces, false );
     }
 
@@ -166,21 +168,24 @@ void FindDegeneratesProcess::ExecuteOnMesh( aiMesh* mesh) {
                         first = false;
                     }
 
-                    if ( configRemoveDegenerates ) {
+                    if ( mConfigRemoveDegenerates ) {
                         remove_me[ a ] = true;
                         goto evil_jump_outside; // hrhrhrh ... yeah, this rocks baby!
                     }
                 }
             }
-            if ( face.mNumIndices == 3 ) {
-                ai_real area = calculateAreaOfTriangle( face, mesh );
-                if ( area < 1e-6 ) {
-                    if ( configRemoveDegenerates ) {
-                        remove_me[ a ] = true;
-                        goto evil_jump_outside;
-                    }
 
-                    // todo: check for index which is corrupt.
+            if ( mConfigCheckAreaOfTriangle ) {
+                if ( face.mNumIndices == 3 ) {
+                    ai_real area = calculateAreaOfTriangle( face, mesh );
+                    if ( area < 1e-6 ) {
+                        if ( mConfigRemoveDegenerates ) {
+                            remove_me[ a ] = true;
+                            goto evil_jump_outside;
+                        }
+
+                        // todo: check for index which is corrupt.
+                    }
                 }
             }
         }
@@ -206,7 +211,7 @@ evil_jump_outside:
     }
 
     // If AI_CONFIG_PP_FD_REMOVE is true, remove degenerated faces from the import
-    if (configRemoveDegenerates && deg) {
+    if (mConfigRemoveDegenerates && deg) {
         unsigned int n = 0;
         for (unsigned int a = 0; a < mesh->mNumFaces; ++a)
         {

+ 40 - 19
code/FindDegenerates.h

@@ -54,15 +54,11 @@ namespace Assimp    {
 // ---------------------------------------------------------------------------
 /** FindDegeneratesProcess: Searches a mesh for degenerated triangles.
 */
-class ASSIMP_API FindDegeneratesProcess : public BaseProcess
-{
+class ASSIMP_API FindDegeneratesProcess : public BaseProcess {
 public:
-
     FindDegeneratesProcess();
     ~FindDegeneratesProcess();
 
-public:
-
     // -------------------------------------------------------------------
     // Check whether step is active
     bool IsActive( unsigned int pFlags) const;
@@ -79,28 +75,53 @@ public:
     // Execute step on a given mesh
     void ExecuteOnMesh( aiMesh* mesh);
 
+    // -------------------------------------------------------------------
+    /// @brief Enable the instant removal of degenerated primitives
+    /// @param enabled  true for enabled.
+    void EnableInstantRemoval(bool enabled);
+
+    // -------------------------------------------------------------------
+    /// @brief Check whether instant removal is currently enabled
+    /// @return The instant removal state.
+    bool IsInstantRemoval() const;
 
     // -------------------------------------------------------------------
-    /** @brief Enable the instant removal of degenerated primitives
-     *  @param d hm ... difficult to guess what this means, hu!?
-     */
-    void EnableInstantRemoval(bool d) {
-        configRemoveDegenerates = d;
-    }
+    /// @brief Enable the area check for triangles.
+    /// @param enabled  true for enabled.
+    void EnableAreaCheck( bool enabled );
 
     // -------------------------------------------------------------------
-    /** @brief Check whether instant removal is currently enabled
-     *  @return ...
-     */
-    bool IsInstantRemoval() const {
-        return configRemoveDegenerates;
-    }
+    /// @brief Check whether the area check is enabled.
+    /// @return The area check state.
+    bool isAreaCheckEnabled() const;
 
 private:
-
     //! Configuration option: remove degenerates faces immediately
-    bool configRemoveDegenerates;
+    bool mConfigRemoveDegenerates;
+    //! Configuration option: check for area
+    bool mConfigCheckAreaOfTriangle;
 };
+
+inline
+void FindDegeneratesProcess::EnableInstantRemoval(bool enabled) {
+    mConfigRemoveDegenerates = enabled;
 }
 
+inline
+bool FindDegeneratesProcess::IsInstantRemoval() const {
+    return mConfigRemoveDegenerates;
+}
+
+inline
+void FindDegeneratesProcess::EnableAreaCheck( bool enabled ) {
+    mConfigCheckAreaOfTriangle = enabled;
+}
+
+inline
+bool FindDegeneratesProcess::isAreaCheckEnabled() const {
+    return mConfigCheckAreaOfTriangle;
+}
+
+} // Namespace Assimp
+
 #endif // !! AI_FINDDEGENERATESPROCESS_H_INC

+ 6 - 2
code/X3DExporter.cpp

@@ -240,8 +240,12 @@ list<SAttribute> attr_list;
 		if((rotate_angle != 0) && (rotate_axis.Length() > 0))
 			attr_list.push_back({"rotation", Rotation2String(rotate_axis, rotate_angle)});
 
-		if(!scale.Equal({1, 1, 1})) attr_list.push_back({"scale", Vector2String(scale)});
-		if(translate.Length() > 0) attr_list.push_back({"translation", Vector2String(translate)});
+        if(!scale.Equal({1.0,1.0,1.0})) {
+            attr_list.push_back({"scale", Vector2String(scale)});
+        }
+        if(translate.Length() > 0) {
+            attr_list.push_back({"translation", Vector2String(translate)});
+        }
 	}
 
 	// Begin node if need.

+ 9 - 0
include/assimp/config.h.in

@@ -266,6 +266,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #define AI_CONFIG_PP_FD_REMOVE \
     "PP_FD_REMOVE"
 
+// ---------------------------------------------------------------------------
+/**
+ *  @brief  Configures the #aiProcess_FindDegenerates to check the area of a
+ *  trinagle to be greates than e-6. If this is not the case the triangle will
+ *  be removed if #AI_CONFIG_PP_FD_REMOVE is set to true.
+ */
+#define AI_CONFIG_PP_FD_CHECKAREA \
+    "PP_FD_CHECKAREA"
+
 // ---------------------------------------------------------------------------
 /** @brief Configures the #aiProcess_OptimizeGraph step to preserve nodes
  * matching a name in a given list.

+ 4 - 5
include/assimp/vector3.h

@@ -65,11 +65,10 @@ template <typename TReal>
 class aiVector3t
 {
 public:
-
-    aiVector3t () : x(), y(), z() {}
-    aiVector3t (TReal _x, TReal _y, TReal _z) : x(_x), y(_y), z(_z) {}
-    explicit aiVector3t (TReal _xyz) : x(_xyz), y(_xyz), z(_xyz) {}
-    aiVector3t (const aiVector3t& o) : x(o.x), y(o.y), z(o.z) {}
+    aiVector3t() : x(), y(), z() {}
+    aiVector3t(TReal _x, TReal _y, TReal _z) : x(_x), y(_y), z(_z) {}
+    explicit aiVector3t (TReal _xyz ) : x(_xyz), y(_xyz), z(_xyz) {}
+    aiVector3t( const aiVector3t& o ) : x(o.x), y(o.y), z(o.z) {}
 
 public:
 

+ 12 - 11
test/unit/utFindDegenerates.cpp

@@ -58,8 +58,7 @@ protected:
 };
 
 // ------------------------------------------------------------------------------------------------
-void FindDegeneratesProcessTest::SetUp()
-{
+void FindDegeneratesProcessTest::SetUp() {
     mesh = new aiMesh();
     process = new FindDegeneratesProcess();
 
@@ -107,16 +106,12 @@ void FindDegeneratesProcessTest::SetUp()
     mesh->mNumUVComponents[1] = numFaces;
 }
 
-// ------------------------------------------------------------------------------------------------
-void FindDegeneratesProcessTest::TearDown()
-{
+void FindDegeneratesProcessTest::TearDown() {
     delete mesh;
     delete process;
 }
 
-// ------------------------------------------------------------------------------------------------
-TEST_F(FindDegeneratesProcessTest, testDegeneratesDetection)
-{
+TEST_F(FindDegeneratesProcessTest, testDegeneratesDetection) {
     process->EnableInstantRemoval(false);
     process->ExecuteOnMesh(mesh);
 
@@ -135,12 +130,18 @@ TEST_F(FindDegeneratesProcessTest, testDegeneratesDetection)
               mesh->mPrimitiveTypes);
 }
 
-// ------------------------------------------------------------------------------------------------
-TEST_F(FindDegeneratesProcessTest, testDegeneratesRemoval)
-{
+TEST_F(FindDegeneratesProcessTest, testDegeneratesRemoval) {
+    process->EnableAreaCheck(false);
     process->EnableInstantRemoval(true);
     process->ExecuteOnMesh(mesh);
 
     EXPECT_EQ(mesh->mNumUVComponents[1], mesh->mNumFaces);
 }
 
+TEST_F(FindDegeneratesProcessTest, testDegeneratesRemovalWithAreaCheck) {
+    process->EnableAreaCheck(true);
+    process->EnableInstantRemoval(true);
+    process->ExecuteOnMesh(mesh);
+
+    EXPECT_EQ(mesh->mNumUVComponents[1]-100, mesh->mNumFaces);
+}