Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/mesh/mesh_are_equivalent.cc
- This file was moved from extern/draco/dracoenc/src/draco/mesh/mesh_are_equivalent.cc.
| Show First 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | void MeshAreEquivalent::Init(const Mesh &mesh0, const Mesh &mesh1) { | ||||
| DRACO_DCHECK_EQ(mesh_infos_[0].ordered_index_of_face.size(), 0); | DRACO_DCHECK_EQ(mesh_infos_[0].ordered_index_of_face.size(), 0); | ||||
| DRACO_DCHECK_EQ(mesh_infos_[1].ordered_index_of_face.size(), 0); | DRACO_DCHECK_EQ(mesh_infos_[1].ordered_index_of_face.size(), 0); | ||||
| InitCornerIndexOfSmallestPointXYZ(); | InitCornerIndexOfSmallestPointXYZ(); | ||||
| InitOrderedFaceIndex(); | InitOrderedFaceIndex(); | ||||
| } | } | ||||
| bool MeshAreEquivalent::operator()(const Mesh &mesh0, const Mesh &mesh1) { | bool MeshAreEquivalent::operator()(const Mesh &mesh0, const Mesh &mesh1) { | ||||
| if (mesh0.num_faces() != mesh1.num_faces()) | if (mesh0.num_faces() != mesh1.num_faces()) { | ||||
| return false; | return false; | ||||
| if (mesh0.num_attributes() != mesh1.num_attributes()) | } | ||||
| if (mesh0.num_attributes() != mesh1.num_attributes()) { | |||||
| return false; | return false; | ||||
| } | |||||
| // The following function inits mesh info, i.e., computes the order of | // The following function inits mesh info, i.e., computes the order of | ||||
| // faces with respect to the lex order. This way one can then compare the | // faces with respect to the lex order. This way one can then compare the | ||||
| // the two meshes face by face. It also determines the first corner of each | // the two meshes face by face. It also determines the first corner of each | ||||
| // face with respect to lex order. | // face with respect to lex order. | ||||
| Init(mesh0, mesh1); | Init(mesh0, mesh1); | ||||
| // Check for every attribute that is valid that every corner is identical. | // Check for every attribute that is valid that every corner is identical. | ||||
| typedef GeometryAttribute::Type AttributeType; | typedef GeometryAttribute::Type AttributeType; | ||||
| const int att_max = AttributeType::NAMED_ATTRIBUTES_COUNT; | const int att_max = AttributeType::NAMED_ATTRIBUTES_COUNT; | ||||
| for (int att_id = 0; att_id < att_max; ++att_id) { | for (int att_id = 0; att_id < att_max; ++att_id) { | ||||
| // First check for existence of the attribute in both meshes. | // First check for existence of the attribute in both meshes. | ||||
| const PointAttribute *const att0 = | const PointAttribute *const att0 = | ||||
| mesh0.GetNamedAttribute(AttributeType(att_id)); | mesh0.GetNamedAttribute(AttributeType(att_id)); | ||||
| const PointAttribute *const att1 = | const PointAttribute *const att1 = | ||||
| mesh1.GetNamedAttribute(AttributeType(att_id)); | mesh1.GetNamedAttribute(AttributeType(att_id)); | ||||
| if (att0 == nullptr && att1 == nullptr) | if (att0 == nullptr && att1 == nullptr) { | ||||
| continue; | continue; | ||||
| if (att0 == nullptr) | } | ||||
| if (att0 == nullptr) { | |||||
| return false; | return false; | ||||
| if (att1 == nullptr) | } | ||||
| if (att1 == nullptr) { | |||||
| return false; | return false; | ||||
| if (att0->data_type() != att1->data_type()) | } | ||||
| if (att0->data_type() != att1->data_type()) { | |||||
| return false; | return false; | ||||
| if (att0->num_components() != att1->num_components()) | } | ||||
| if (att0->num_components() != att1->num_components()) { | |||||
| return false; | return false; | ||||
| if (att0->normalized() != att1->normalized()) | } | ||||
| if (att0->normalized() != att1->normalized()) { | |||||
| return false; | return false; | ||||
| if (att0->byte_stride() != att1->byte_stride()) | } | ||||
| if (att0->byte_stride() != att1->byte_stride()) { | |||||
| return false; | return false; | ||||
| } | |||||
| DRACO_DCHECK(att0->IsValid()); | DRACO_DCHECK(att0->IsValid()); | ||||
| DRACO_DCHECK(att1->IsValid()); | DRACO_DCHECK(att1->IsValid()); | ||||
| // Prepare blocks of memory to hold data of corners for this attribute. | // Prepare blocks of memory to hold data of corners for this attribute. | ||||
| std::unique_ptr<uint8_t[]> data0(new uint8_t[att0->byte_stride()]); | std::unique_ptr<uint8_t[]> data0(new uint8_t[att0->byte_stride()]); | ||||
| std::unique_ptr<uint8_t[]> data1(new uint8_t[att0->byte_stride()]); | std::unique_ptr<uint8_t[]> data1(new uint8_t[att0->byte_stride()]); | ||||
| Show All 11 Lines | for (int i = 0; i < num_faces_; ++i) { | ||||
| // Map it to the right index for that attribute. | // Map it to the right index for that attribute. | ||||
| const AttributeValueIndex index0 = att0->mapped_index(corner0); | const AttributeValueIndex index0 = att0->mapped_index(corner0); | ||||
| const AttributeValueIndex index1 = att1->mapped_index(corner1); | const AttributeValueIndex index1 = att1->mapped_index(corner1); | ||||
| // Obtaining the data. | // Obtaining the data. | ||||
| att0->GetValue(index0, data0.get()); | att0->GetValue(index0, data0.get()); | ||||
| att1->GetValue(index1, data1.get()); | att1->GetValue(index1, data1.get()); | ||||
| // Compare the data as is in memory. | // Compare the data as is in memory. | ||||
| if (memcmp(data0.get(), data1.get(), att0->byte_stride()) != 0) | if (memcmp(data0.get(), data1.get(), att0->byte_stride()) != 0) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| return true; | return true; | ||||
| } | } | ||||
| bool MeshAreEquivalent::FaceIndexLess::operator()(FaceIndex f0, | bool MeshAreEquivalent::FaceIndexLess::operator()(FaceIndex f0, | ||||
| FaceIndex f1) const { | FaceIndex f1) const { | ||||
| if (f0 == f1) | if (f0 == f1) { | ||||
| return false; | return false; | ||||
| } | |||||
| const int c0 = mesh_info.corner_index_of_smallest_vertex[f0]; | const int c0 = mesh_info.corner_index_of_smallest_vertex[f0]; | ||||
| const int c1 = mesh_info.corner_index_of_smallest_vertex[f1]; | const int c1 = mesh_info.corner_index_of_smallest_vertex[f1]; | ||||
| for (int i = 0; i < 3; ++i) { | for (int i = 0; i < 3; ++i) { | ||||
| const Vector3f vf0 = GetPosition(mesh_info.mesh, f0, (c0 + i) % 3); | const Vector3f vf0 = GetPosition(mesh_info.mesh, f0, (c0 + i) % 3); | ||||
| const Vector3f vf1 = GetPosition(mesh_info.mesh, f1, (c1 + i) % 3); | const Vector3f vf1 = GetPosition(mesh_info.mesh, f1, (c1 + i) % 3); | ||||
| if (vf0 < vf1) | if (vf0 < vf1) { | ||||
| return true; | return true; | ||||
| if (vf1 < vf0) | } | ||||
| if (vf1 < vf0) { | |||||
| return false; | return false; | ||||
| } | } | ||||
| } | |||||
| // In case the two faces are equivalent. | // In case the two faces are equivalent. | ||||
| return false; | return false; | ||||
| } | } | ||||
| } // namespace draco | } // namespace draco | ||||