This adds a new function, `compare_meshes`, as a replacement for `BKE_mesh_cmp`. The main benefits of the new version are the following: - The code is written in c++, and makes use of the new attributes API. - It adds an additional check, to see if the meshes only differ by their indices. This is useful to verify correctness of new algorithmic changes in mesh code, which might produce mesh elements in a different order than the original algorithm. The tests will still fail, but the error will show that the indices changed. Some downsides: - The code is more complex, due to having to be index-independent. - The code is probably slower due to having to do comparisons "index- independently". I have not tested this, as correctness was my priority for this patch. A future update could look to improve the speed, if that is desired. - This is technically a breaking API change, since it changes the returned values of `rna_Mesh_unit_test_compare`. I don't think that there are many people (if any) using this, besides our own unit tests. All tests that pass with `BKE_mesh_cmp` still pass with the new version. **NOTE:** Currently, mesh edge indices are allowed to be different in the comparison, because `BKE_mesh_cmp` also allowed this. There are some tests which would fail otherwise. These tests should be updated, and then the corresponding code as well. I wrote up a more detailed explanation of the algorithm here: https://hackmd.io/@bo-JY945TOmvepQ1tAWy6w/SyuaFtay6 Pull Request: https://projects.blender.org/blender/blender/pulls/112794
39 lines
1.3 KiB
C++
39 lines
1.3 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#pragma once
|
|
|
|
#include "BKE_mesh_types.hh"
|
|
|
|
/** \file
|
|
* \ingroup bke
|
|
*/
|
|
|
|
namespace blender::bke::compare_meshes {
|
|
|
|
enum class MeshMismatch : int8_t;
|
|
|
|
/**
|
|
* Convert the mismatch to a human-readable string for display.
|
|
*/
|
|
const char *mismatch_to_string(const MeshMismatch &mismatch);
|
|
|
|
/**
|
|
* \brief Checks if the two meshes are different, returning the type of mismatch if any. Changes in
|
|
* index order are detected, but treated as a mismatch.
|
|
*
|
|
* \details Instead of just blindly comparing the two meshes, the code tries to determine if they
|
|
* are isomorphic. Two meshes are considered isomorphic, if, for each domain, there is a bijection
|
|
* between the two meshes such that the bijections preserve connectivity.
|
|
*
|
|
* In general, determining if two graphs are isomorphic is a very difficult problem (no polynomial
|
|
* time algorithm is known). Because we have more information than just connectivity (attributes),
|
|
* we can compute it in a more reasonable time in most cases.
|
|
*
|
|
* \returns The type of mismatch that was detected, if there is any.
|
|
*/
|
|
std::optional<MeshMismatch> compare_meshes(const Mesh &mesh1, const Mesh &mesh2, float threshold);
|
|
|
|
} // namespace blender::bke::compare_meshes
|