FindDegeneratives: adapt unittests and add configs

pull/1558/head
Kim Kulling 2017-11-12 22:09:18 +01:00
parent 9206d1b62b
commit 24b728b3ea
6 changed files with 89 additions and 50 deletions

View File

@ -56,7 +56,8 @@ using namespace Assimp;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer // Constructor to be privately used by Importer
FindDegeneratesProcess::FindDegeneratesProcess() FindDegeneratesProcess::FindDegeneratesProcess()
: configRemoveDegenerates (false) { : mConfigRemoveDegenerates( false )
, mConfigCheckAreaOfTriangle( false ){
// empty // empty
} }
@ -76,7 +77,8 @@ bool FindDegeneratesProcess::IsActive( unsigned int pFlags) const {
// Setup import configuration // Setup import configuration
void FindDegeneratesProcess::SetupProperties(const Importer* pImp) { void FindDegeneratesProcess::SetupProperties(const Importer* pImp) {
// Get the current value of AI_CONFIG_PP_FD_REMOVE // 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; mesh->mPrimitiveTypes = 0;
std::vector<bool> remove_me; std::vector<bool> remove_me;
if (configRemoveDegenerates) { if (mConfigRemoveDegenerates) {
remove_me.resize( mesh->mNumFaces, false ); remove_me.resize( mesh->mNumFaces, false );
} }
@ -166,16 +168,18 @@ void FindDegeneratesProcess::ExecuteOnMesh( aiMesh* mesh) {
first = false; first = false;
} }
if ( configRemoveDegenerates ) { if ( mConfigRemoveDegenerates ) {
remove_me[ a ] = true; remove_me[ a ] = true;
goto evil_jump_outside; // hrhrhrh ... yeah, this rocks baby! goto evil_jump_outside; // hrhrhrh ... yeah, this rocks baby!
} }
} }
} }
if ( mConfigCheckAreaOfTriangle ) {
if ( face.mNumIndices == 3 ) { if ( face.mNumIndices == 3 ) {
ai_real area = calculateAreaOfTriangle( face, mesh ); ai_real area = calculateAreaOfTriangle( face, mesh );
if ( area < 1e-6 ) { if ( area < 1e-6 ) {
if ( configRemoveDegenerates ) { if ( mConfigRemoveDegenerates ) {
remove_me[ a ] = true; remove_me[ a ] = true;
goto evil_jump_outside; goto evil_jump_outside;
} }
@ -184,6 +188,7 @@ void FindDegeneratesProcess::ExecuteOnMesh( aiMesh* mesh) {
} }
} }
} }
}
// We need to update the primitive flags array of the mesh. // We need to update the primitive flags array of the mesh.
switch (face.mNumIndices) switch (face.mNumIndices)
@ -206,7 +211,7 @@ evil_jump_outside:
} }
// If AI_CONFIG_PP_FD_REMOVE is true, remove degenerated faces from the import // If AI_CONFIG_PP_FD_REMOVE is true, remove degenerated faces from the import
if (configRemoveDegenerates && deg) { if (mConfigRemoveDegenerates && deg) {
unsigned int n = 0; unsigned int n = 0;
for (unsigned int a = 0; a < mesh->mNumFaces; ++a) for (unsigned int a = 0; a < mesh->mNumFaces; ++a)
{ {

View File

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

View File

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

View File

@ -266,6 +266,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define AI_CONFIG_PP_FD_REMOVE \ #define AI_CONFIG_PP_FD_REMOVE \
"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 /** @brief Configures the #aiProcess_OptimizeGraph step to preserve nodes
* matching a name in a given list. * matching a name in a given list.

View File

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

View File

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