Print vertex IDs when inconsistent face is found.

PiperOrigin-RevId: 493311839
Change-Id: I0283d86bc6092fbe4f47b845fa8ec212bffdfa1a
This commit is contained in:
Alessio Quaglino
2022-12-06 08:23:45 -08:00
committed by Copybara-Service
parent e4f1d584ad
commit 7f459ab8ca
3 changed files with 21 additions and 12 deletions
+9 -4
View File
@@ -114,7 +114,8 @@ mjCMesh::mjCMesh(mjCModel* _model, mjCDef* _def) {
face = NULL;
graph = NULL;
needhull = false;
validorientation = true;
invalidorientation.first = -1;
invalidorientation.second = -1;
validarea = true;
validvolume = true;
valideigenvalue = true;
@@ -275,7 +276,8 @@ void mjCMesh::Compile(const mjVFS* vfs) {
std::sort(useredge.begin(), useredge.end());
auto iterator = std::adjacent_find(useredge.begin(), useredge.end());
if (iterator != useredge.end()) {
validorientation = false;
invalidorientation.first = iterator->first+1;
invalidorientation.second = iterator->second+1;
}
}
@@ -1195,8 +1197,11 @@ void mjCMesh::CheckMesh() {
if (!processed) {
return;
}
if (!validorientation)
throw mjCError(this, "faces have inconsistent orientation: %s", name.c_str());
if (invalidorientation.first>=0 || invalidorientation.second>=0)
throw mjCError(this,
"faces of mesh '%s' have inconsistent orientation. Please check the "
"faces containing the vertices %d and %d.",
name.c_str(), invalidorientation.first, invalidorientation.second);
if (!validarea)
throw mjCError(this, "mesh surface area is too small: %s", name.c_str());
if (!validvolume)
+6 -6
View File
@@ -494,12 +494,12 @@ class mjCMesh: public mjCBase {
void CheckMesh(void); // check if the mesh is valid
// mesh properties that indicate a well-formed mesh
bool validorientation; // false if mesh have inconsistent faces
bool validarea; // false if the area is too small
bool validvolume; // false if the volume is too small
bool valideigenvalue; // false if inertia eigenvalue is too small
bool validinequality; // false if inertia inequality is not satisfied
bool processed; // false if the mesh has not been processed yet
std::pair<int, int> invalidorientation; // indices of invalid edge; -1 if none
bool validarea; // false if the area is too small
bool validvolume; // false if the volume is too small
bool valideigenvalue; // false if inertia eigenvalue is too small
bool validinequality; // false if inertia inequality is not satisfied
bool processed; // false if the mesh has not been processed yet
// mesh properties computed by Compile
double pos_volume[3]; // CoM position
+6 -2
View File
@@ -222,7 +222,9 @@ TEST_F(MjCMeshTest, MalformedFaceFails) {
std::array<char, 1024> error;
mjModel* model = mj_loadXML(xml_path.c_str(), 0, error.data(), error.size());
EXPECT_THAT(model, testing::IsNull());
EXPECT_THAT(error.data(), HasSubstr("faces have inconsistent orientation"));
EXPECT_THAT(error.data(), HasSubstr(
"Error: faces of mesh 'malformed_face' have inconsistent orientation. "
"Please check the faces containing the vertices 1 and 2."));
}
TEST_F(MjCMeshTest, FlippedFaceFails) {
@@ -243,7 +245,9 @@ TEST_F(MjCMeshTest, FlippedFaceFails) {
std::array<char, 1024> error;
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
EXPECT_THAT(model, testing::IsNull());
EXPECT_THAT(error.data(), HasSubstr("faces have inconsistent orientation"));
EXPECT_THAT(error.data(), HasSubstr(
"Error: faces of mesh 'example_mesh' have inconsistent orientation. "
"Please check the faces containing the vertices 1 and 2."));
}
void CheckTetrahedronWasRescaled(mjModel* model) {