Forráskód Böngészése

Merge pull request #4387 from assimp/kimkulling/fbx_use_ai_epsilon

Refactoring: add usage of ai_epsilon to fbx.
Kim Kulling 3 éve
szülő
commit
510504a2c6

+ 3 - 3
code/AssetLib/Collada/ColladaLoader.cpp

@@ -357,9 +357,9 @@ void ColladaLoader::BuildLightsForNode(const ColladaParser &pParser, const Node
             out->mAngleInnerCone = AI_DEG_TO_RAD(srcLight->mFalloffAngle);
 
             // ... some extension magic.
-            if (srcLight->mOuterAngle >= ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET * (1 - 1e-6f)) {
+            if (srcLight->mOuterAngle >= ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET * (1 - ai_epsilon)) {
                 // ... some deprecation magic.
-                if (srcLight->mPenumbraAngle >= ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET * (1 - 1e-6f)) {
+                if (srcLight->mPenumbraAngle >= ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET * (1 - ai_epsilon)) {
                     // Need to rely on falloff_exponent. I don't know how to interpret it, so I need to guess ....
                     // epsilon chosen to be 0.1
                     float f = 1.0f;
@@ -1065,7 +1065,7 @@ void insertMorphTimeValue(std::vector<MorphTimeValues> &values, float time, floa
         return;
     }
     for (unsigned int i = 0; i < values.size(); i++) {
-        if (std::abs(time - values[i].mTime) < 1e-6f) {
+        if (std::abs(time - values[i].mTime) < ai_epsilon) {
             values[i].mKeys.push_back(k);
             return;
         } else if (time > values[i].mTime && time < values[i + 1].mTime) {

+ 2 - 0
code/AssetLib/FBX/FBXCommon.h

@@ -80,8 +80,10 @@ enum TransformInheritance {
 
     TransformInheritance_MAX // end-of-enum sentinel
 };
+
 } // namespace FBX
 } // namespace Assimp
+
 #endif // ASSIMP_BUILD_NO_FBX_EXPORTER
 
 #endif // AI_FBXCOMMON_H_INC

+ 3 - 2
code/AssetLib/FBX/FBXConverter.cpp

@@ -653,7 +653,7 @@ bool FBXConverter::NeedsComplexTransformationChain(const Model &model) {
     const PropertyTable &props = model.Props();
     bool ok;
 
-    const float zero_epsilon = 1e-6f;
+    const float zero_epsilon = ai_epsilon;
     const aiVector3D all_ones(1.0f, 1.0f, 1.0f);
     for (size_t i = 0; i < TransformationComp_MAXIMUM; ++i) {
         const TransformationComp comp = static_cast<TransformationComp>(i);
@@ -3187,7 +3187,8 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
     }
 
     bool ok = false;
-    const float zero_epsilon = 1e-6f;
+    
+    const float zero_epsilon = ai_epsilon;
 
     const aiVector3D& preRotation = PropertyGet<aiVector3D>(props, "PreRotation", ok);
     if (ok && preRotation.SquareLength() > zero_epsilon) {

+ 9 - 9
code/AssetLib/IFC/IFCBoolean.cpp

@@ -66,12 +66,12 @@ bool IntersectSegmentPlane(const IfcVector3 &p, const IfcVector3 &n, const IfcVe
 
     // if segment ends on plane, do not report a hit. We stay on that side until a following segment starting at this
     // point leaves the plane through the other side
-    if (std::abs(dotOne + dotTwo) < 1e-6)
+    if (std::abs(dotOne + dotTwo) < ai_epsilon)
         return false;
 
     // if segment starts on the plane, report a hit only if the end lies on the *other* side
-    if (std::abs(dotTwo) < 1e-6) {
-        if ((assumeStartOnWhiteSide && dotOne + dotTwo < 1e-6) || (!assumeStartOnWhiteSide && dotOne + dotTwo > -1e-6)) {
+    if (std::abs(dotTwo) < ai_epsilon) {
+        if ((assumeStartOnWhiteSide && dotOne + dotTwo < ai_epsilon) || (!assumeStartOnWhiteSide && dotOne + dotTwo > -ai_epsilon)) {
             out = e0;
             return true;
         } else {
@@ -81,7 +81,7 @@ bool IntersectSegmentPlane(const IfcVector3 &p, const IfcVector3 &n, const IfcVe
 
     // ignore if segment is parallel to plane and far away from it on either side
     // Warning: if there's a few thousand of such segments which slowly accumulate beyond the epsilon, no hit would be registered
-    if (std::abs(dotOne) < 1e-6)
+    if (std::abs(dotOne) < ai_epsilon)
         return false;
 
     // t must be in [0..1] if the intersection point is within the given segment
@@ -163,7 +163,7 @@ void ProcessBooleanHalfSpaceDifference(const Schema_2x3::IfcHalfSpaceSolid *hs,
     for (iit = begin; iit != end; vidx += *iit++) {
 
         unsigned int newcount = 0;
-        bool isAtWhiteSide = (in[vidx] - p) * n > -1e-6;
+        bool isAtWhiteSide = (in[vidx] - p) * n > -ai_epsilon;
         for (unsigned int i = 0; i < *iit; ++i) {
             const IfcVector3 &e0 = in[vidx + i], e1 = in[vidx + (i + 1) % *iit];
 
@@ -259,7 +259,7 @@ bool IntersectsBoundaryProfile(const IfcVector3 &e0, const IfcVector3 &e1, const
         // segment-segment intersection
         // solve b0 + b*s = e0 + e*t for (s,t)
         const IfcFloat det = (-b.x * e.y + e.x * b.y);
-        if (std::abs(det) < 1e-6) {
+        if (std::abs(det) < ai_epsilon) {
             // no solutions (parallel lines)
             continue;
         }
@@ -316,7 +316,7 @@ bool IntersectsBoundaryProfile(const IfcVector3 &e0, const IfcVector3 &e1, const
 
         // for a valid intersection, s and t should be in range [0,1]. Including a bit of epsilon on s, potential double
         // hits on two consecutive boundary segments are filtered
-        if (s >= -1e-6 * b_sqlen_inv && s <= 1.0 + 1e-6 * b_sqlen_inv && t >= 0.0 && (t <= 1.0 || halfOpen)) {
+        if (s >= -ai_epsilon * b_sqlen_inv && s <= 1.0 + ai_epsilon * b_sqlen_inv && t >= 0.0 && (t <= 1.0 || halfOpen)) {
             // only insert the point into the list if it is sufficiently far away from the previous intersection point.
             // This way, we avoid duplicate detection if the intersection is directly on the vertex between two segments.
             if (!intersect_results.empty() && intersect_results.back().first == i - 1) {
@@ -431,14 +431,14 @@ void ProcessPolygonalBoundedBooleanHalfSpaceDifference(const Schema_2x3::IfcPoly
 
             // if the poly is parallel to the plane, put it completely on the black or white side
             if (std::abs(polyNormal * n) > 0.9999) {
-                bool isOnWhiteSide = (srcVertices[0] - p) * n > -1e-6;
+                bool isOnWhiteSide = (srcVertices[0] - p) * n > -ai_epsilon;
                 std::vector<IfcVector3> &targetSide = isOnWhiteSide ? whiteside : blackside;
                 targetSide.insert(targetSide.end(), srcVertices, srcVertices + srcVtxCount);
             } else {
                 // otherwise start building one polygon for each side. Whenever the current line segment intersects the plane
                 // we put a point there as an end of the current segment. Then we switch to the other side, put a point there, too,
                 // as a beginning of the current segment, and simply continue accumulating vertices.
-                bool isCurrentlyOnWhiteSide = ((srcVertices[0]) - p) * n > -1e-6;
+                bool isCurrentlyOnWhiteSide = ((srcVertices[0]) - p) * n > -ai_epsilon;
                 for (size_t a = 0; a < srcVtxCount; ++a) {
                     IfcVector3 e0 = srcVertices[a];
                     IfcVector3 e1 = srcVertices[(a + 1) % srcVtxCount];

+ 5 - 7
code/AssetLib/IFC/IFCGeometry.cpp

@@ -380,21 +380,19 @@ void ProcessSweptDiskSolid(const Schema_2x3::IfcSweptDiskSolid &solid, TempMesh&
         bool take_any = false;
 
         for (unsigned int j = 0; j < 2; ++j, take_any = true) {
-            if ((last_dir == 0 || take_any) && std::abs(d.x) > 1e-6) {
+            if ((last_dir == 0 || take_any) && std::abs(d.x) > ai_epsilon) {
                 q.y = startvec.y;
                 q.z = startvec.z;
                 q.x = -(d.y * q.y + d.z * q.z) / d.x;
                 last_dir = 0;
                 break;
-            }
-            else if ((last_dir == 1 || take_any) && std::abs(d.y) > 1e-6) {
+            } else if ((last_dir == 1 || take_any) && std::abs(d.y) > ai_epsilon) {
                 q.x = startvec.x;
                 q.z = startvec.z;
                 q.y = -(d.x * q.x + d.z * q.z) / d.y;
                 last_dir = 1;
                 break;
-            }
-            else if ((last_dir == 2 && std::abs(d.z) > 1e-6) || take_any) {
+            } else if ((last_dir == 2 && std::abs(d.z) > ai_epsilon) || take_any) {
                 q.y = startvec.y;
                 q.x = startvec.x;
                 q.z = -(d.y * q.y + d.x * q.x) / d.z;
@@ -529,7 +527,7 @@ IfcMatrix3 DerivePlaneCoordinateSpace(const TempMesh& curmesh, bool& ok, IfcVect
     return m;
 }
 
-const auto closeDistance = 1e-6;
+const auto closeDistance = ai_epsilon;
 
 bool areClose(Schema_2x3::IfcCartesianPoint pt1,Schema_2x3::IfcCartesianPoint pt2) {
     if(pt1.Coordinates.size() != pt2.Coordinates.size())
@@ -561,7 +559,7 @@ void ProcessExtrudedArea(const Schema_2x3::IfcExtrudedAreaSolid& solid, const Te
     // Outline: 'curve' is now a list of vertex points forming the underlying profile, extrude along the given axis,
     // forming new triangles.
     const bool has_area = solid.SweptArea->ProfileType == "AREA" && curve.mVerts.size() > 2;
-    if( solid.Depth < 1e-6 ) {
+    if (solid.Depth < ai_epsilon) {
         if( has_area ) {
             result.Append(curve);
         }

+ 3 - 3
code/AssetLib/IFC/IFCOpenings.cpp

@@ -1133,7 +1133,7 @@ IfcMatrix4 ProjectOntoPlane(std::vector<IfcVector2>& out_contour, const TempMesh
     }
 
     for(size_t i = 0; i < out_contour.size(); ++i) {
-        ai_assert((out_contour[i]-out_contour2[i]).SquareLength() < 1e-6);
+        ai_assert((out_contour[i] - out_contour2[i]).SquareLength() < ai_epsilon);
     }
 #endif
 
@@ -1435,7 +1435,7 @@ std::vector<IfcVector2> GetContourInPlane2D(std::shared_ptr<TempMesh> mesh,IfcMa
 
     const auto outernor = ((mesh->mVerts[2] - mesh->mVerts[0]) ^ (mesh->mVerts[1] - mesh->mVerts[0])).Normalize();
     const IfcFloat dot = planeNor * outernor;
-    if(std::fabs(dot) < 1.f - 1e-6f) {
+    if (std::fabs(dot) < 1.f - ai_epsilon) {
         std::stringstream msg;
         msg << "Skipping: Unaligned opening (" << planeNor.x << ", " << planeNor.y << ", " << planeNor.z << ")";
         msg << " . ( " << outernor.x << ", " << outernor.y << ", " << outernor.z << ") = " << dot;
@@ -1476,7 +1476,7 @@ std::vector<IfcVector2> GetContourInPlane2D(std::shared_ptr<TempMesh> mesh,IfcMa
     return contour;
 }
 
-const float close { 1e-6f };
+const float close{ ai_epsilon };
 
 static bool isClose(IfcVector2 first,IfcVector2 second) {
     auto diff = (second - first);

+ 11 - 13
code/AssetLib/IFC/IFCUtil.cpp

@@ -228,25 +228,24 @@ void TempMesh::ComputePolygonNormals(std::vector<IfcVector3>& normals,
 
 // ------------------------------------------------------------------------------------------------
 // Compute the normal of the last polygon in the given mesh
-IfcVector3 TempMesh::ComputeLastPolygonNormal(bool normalize) const
-{
+IfcVector3 TempMesh::ComputeLastPolygonNormal(bool normalize) const {
     return ComputePolygonNormal(&mVerts[mVerts.size() - mVertcnt.back()], mVertcnt.back(), normalize);
 }
 
-struct CompareVector
-{
-    bool operator () (const IfcVector3& a, const IfcVector3& b) const
-    {
+struct CompareVector {
+    bool operator () (const IfcVector3& a, const IfcVector3& b) const {
         IfcVector3 d = a - b;
-        IfcFloat eps = 1e-6;
+        IfcFloat eps = ai_epsilon;
         return d.x < -eps || (std::abs(d.x) < eps && d.y < -eps) || (std::abs(d.x) < eps && std::abs(d.y) < eps && d.z < -eps);
     }
 };
-struct FindVector
-{
+
+struct FindVector {
     IfcVector3 v;
     FindVector(const IfcVector3& p) : v(p) { }
-    bool operator () (const IfcVector3& p) { return FuzzyVectorCompare(1e-6)(p, v); }
+    bool operator()(const IfcVector3 &p) {
+        return FuzzyVectorCompare(ai_epsilon)(p, v);
+    }
 };
 
 // ------------------------------------------------------------------------------------------------
@@ -357,8 +356,7 @@ void TempMesh::FixupFaceOrientation()
                 // to reverse the neighbour
                 nb_vidx = (nb_vidx + 1) % nbvc;
                 size_t oursideidx = (a + 1) % vc;
-                if( FuzzyVectorCompare(1e-6)(mVerts[vsi + oursideidx], mVerts[nbvsi + nb_vidx]) )
-                {
+                if (FuzzyVectorCompare(ai_epsilon)(mVerts[vsi + oursideidx], mVerts[nbvsi + nb_vidx])) {
                     std::reverse(mVerts.begin() + nbvsi, mVerts.begin() + nbvsi + nbvc);
                     std::reverse(neighbour.begin() + nbvsi, neighbour.begin() + nbvsi + nbvc);
                     for (size_t aa = 0; aa < nbvc - 1; ++aa) {
@@ -564,7 +562,7 @@ void ConvertDirection(IfcVector3& out, const Schema_2x3::IfcDirection& in)
         out[static_cast<unsigned int>(i)] = in.DirectionRatios[i];
     }
     const IfcFloat len = out.Length();
-    if (len<1e-6) {
+    if (len < ai_epsilon) {
         IFCImporter::LogWarn("direction vector magnitude too small, normalization would result in a division by zero");
         return;
     }

+ 1 - 1
code/PostProcessing/FindDegenerates.cpp

@@ -221,7 +221,7 @@ bool FindDegeneratesProcess::ExecuteOnMesh( aiMesh* mesh) {
             if ( mConfigCheckAreaOfTriangle ) {
                 if ( face.mNumIndices == 3 ) {
                     ai_real area = calculateAreaOfTriangle( face, mesh );
-                    if ( area < 1e-6 ) {
+                    if (area < ai_epsilon) {
                         if ( mConfigRemoveDegenerates ) {
                             remove_me[ a ] = true;
                             ++deg;

+ 3 - 3
include/assimp/defs.h

@@ -279,11 +279,11 @@ typedef unsigned int ai_uint;
 #define AI_MATH_HALF_PI_F (AI_MATH_PI_F * 0.5f)
 
 /* Tiny macro to convert from radians to degrees and back */
-#define AI_DEG_TO_RAD(x) ((x) * (ai_real)0.0174532925)
-#define AI_RAD_TO_DEG(x) ((x) * (ai_real)57.2957795)
+#define AI_DEG_TO_RAD(x) ((x) * (ai_real) 0.0174532925)
+#define AI_RAD_TO_DEG(x) ((x) * (ai_real) 57.2957795)
 
 /* Numerical limits */
-static const ai_real ai_epsilon = (ai_real)0.00001;
+static const ai_real ai_epsilon = (ai_real) 1e-6;
 
 /* Support for big-endian builds */
 #if defined(__BYTE_ORDER__)

+ 1 - 1
include/assimp/matrix3x3.h

@@ -95,7 +95,7 @@ public:
     bool operator== (const aiMatrix3x3t<TReal>& m) const;
     bool operator!= (const aiMatrix3x3t<TReal>& m) const;
 
-    bool Equal(const aiMatrix3x3t<TReal>& m, TReal epsilon = 1e-6) const;
+    bool Equal(const aiMatrix3x3t<TReal> &m, TReal epsilon = ai_epsilon) const;
 
     template <typename TOther>
     operator aiMatrix3x3t<TOther> () const;

+ 1 - 1
include/assimp/matrix4x4.h

@@ -110,7 +110,7 @@ public:
     bool operator== (const aiMatrix4x4t& m) const;
     bool operator!= (const aiMatrix4x4t& m) const;
 
-    bool Equal(const aiMatrix4x4t& m, TReal epsilon = 1e-6) const;
+    bool Equal(const aiMatrix4x4t &m, TReal epsilon = ai_epsilon) const;
 
     // matrix multiplication.
     aiMatrix4x4t& operator *= (const aiMatrix4x4t& m);

+ 1 - 1
include/assimp/quaternion.h

@@ -92,7 +92,7 @@ public:
     // transform vector by matrix
     aiQuaterniont& operator *= (const aiMatrix4x4t<TReal>& mat);
 
-    bool Equal(const aiQuaterniont& o, TReal epsilon = 1e-6) const;
+    bool Equal(const aiQuaterniont &o, TReal epsilon = ai_epsilon) const;
 
 public:
 

+ 1 - 1
include/assimp/vector2.h

@@ -85,7 +85,7 @@ public:
     bool operator== (const aiVector2t& other) const;
     bool operator!= (const aiVector2t& other) const;
 
-    bool Equal(const aiVector2t& other, TReal epsilon = 1e-6) const;
+    bool Equal(const aiVector2t &other, TReal epsilon = ai_epsilon) const;
 
     aiVector2t& operator= (TReal f);
     const aiVector2t SymMul(const aiVector2t& o);

+ 1 - 1
include/assimp/vector3.h

@@ -114,7 +114,7 @@ public:
     bool operator < (const aiVector3t& other) const;
 
     /// @brief  
-    bool Equal(const aiVector3t& other, TReal epsilon = 1e-6) const;
+    bool Equal(const aiVector3t &other, TReal epsilon = ai_epsilon) const;
 
     template <typename TOther>
     operator aiVector3t<TOther> () const;

+ 1 - 1
test/unit/utglTF2ImportExport.cpp

@@ -573,7 +573,7 @@ TEST_F(utglTF2ImportExport, export_normalized_normals) {
     scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxBadNormals-glTF-Binary/BoxBadNormals_out.glb", aiProcess_ValidateDataStructure);
     for ( auto i = 0u; i < scene->mMeshes[0]->mNumVertices; ++i ) {
         const auto length = scene->mMeshes[0]->mNormals[i].Length();
-        EXPECT_TRUE(abs(length) < 1e-6 || abs(length - 1) < 1e-6);
+        EXPECT_TRUE(abs(length) < 1e-6 || abs(length - 1) < ai_epsilon);
     }
 }