FindDegeneratives: adapt unittests and add configs

This commit is contained in:
Kim Kulling
2017-11-12 22:09:18 +01:00
parent 9206d1b62b
commit 24b728b3ea
6 changed files with 89 additions and 50 deletions
+18 -13
View File
@@ -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
View File
@@ -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 Enable the instant removal of degenerated primitives
* @param d hm ... difficult to guess what this means, hu!?
*/
void EnableInstantRemoval(bool d) {
configRemoveDegenerates = d;
}
/// @brief Check whether instant removal is currently enabled
/// @return The instant removal state.
bool IsInstantRemoval() const;
// -------------------------------------------------------------------
/** @brief Check whether instant removal is currently enabled
* @return ...
*/
bool IsInstantRemoval() const {
return configRemoveDegenerates;
}
/// @brief Enable the area check for triangles.
/// @param enabled true for enabled.
void EnableAreaCheck( bool enabled );
// -------------------------------------------------------------------
/// @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
View File
@@ -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.