63 return "The number of points is different";
65 return "The number of edges is different";
67 return "The number of corners is different";
69 return "The number of faces is different";
71 return "The number of curves is different";
73 return "Some values of the point attributes are different";
75 return "Some values of the edge attributes are different";
77 return "Some values of the corner attributes are different";
79 return "Some values of the face attributes are different";
81 return "Some values of the curve attributes are different";
83 return "Some values of the layer attributes are different";
85 return "The edge topology is different";
87 return "The face topology is different";
89 return "The curve topology is different";
91 return "The sets of attribute ids are different";
93 return "Some attributes with the same name have different types";
95 return "The geometries are the same up to a change of indices";
97 return "The number of Grease Pencil layers is different";
99 return "The number of Grease Pencil frames on some layer is different";
101 return "The Grease Pencil layer order is different";
103 return "The Grease Pencil keyframes on some layer are different";
114 inverted_map[map[i]] = i;
157 std::stable_sort(indices.
begin(), indices.
end(), [&](
const int i1,
const int i2) {
158 return values[i1] < values[i2];
170 std::stable_sort(indices.
begin(), indices.
end(), [&](
int i1,
int i2) {
171 return set_ids[values_to_sorted[values[i1]]] < set_ids[values_to_sorted[values[i2]]];
184 while (i < set_sizes.
size()) {
185 const int set_size = set_sizes[i];
209 while (i < sorted_to_domain1.
size()) {
210 const int set_size = set_sizes[i];
236 if constexpr (std::is_same_v<T, float>) {
240 return value1 != value2;
256 const float threshold)
259 const float value_threshold = 5 * threshold;
263 T previous = values1[0];
266 const T value1 = values1[sorted_to_values1[i]];
267 const T value2 = values2[sorted_to_values2[i]];
270 std::cout <<
"Attribute different: " << name <<
"\n";
271 std::cout <<
" 1: " << value1 <<
"\n";
272 std::cout <<
" 2: " << value2 <<
"\n";
306 int previous = value_set_ids[values1_to_sorted[domain_to_values1[sorted_to_domain1[0]]]];
308 for (
const int i : sorted_to_domain1.
index_range()) {
309 const int value_id1 =
310 value_set_ids[values1_to_sorted[domain_to_values1[sorted_to_domain1[i]]]];
311 const int value_id2 =
312 value_set_ids[values2_to_sorted[domain_to_values2[sorted_to_domain2[i]]]];
313 if (value_id1 != value_id2) {
317 if (value_id1 != previous || set_ids[i] == i) {
320 previous = value_id1;
333 int i = set_ids.
size() - 1;
337 int set_size = i - set_ids[i] + 1;
339 for (
int k = i - set_size + 1; k <= i; k++) {
340 set_sizes[k] = set_size;
352 const int2 e = edges[i];
353 r_edges[i] =
OrderedEdge(vert_set_ids[verts_to_sorted[
e.x]],
354 vert_set_ids[verts_to_sorted[
e.y]]);
404 corners.from_sorted1,
405 corners.from_sorted2);
412 corners.from_sorted1,
413 corners.from_sorted2);
414 if (!corners_line_up) {
426 for (
const int face_i : smallest_corner_ids.
index_range()) {
427 const int face_start = face_offsets[face_i];
428 const int face_end = face_offsets[face_i + 1];
429 int smallest = corner_set_ids[corners_to_sorted[face_start]];
431 for (
const int corner_i : corners.drop_front(1)) {
432 const int corner_id = corner_set_ids[corners_to_sorted[corner_i]];
433 smallest = std::min(corner_id, smallest);
435 smallest_corner_ids[face_i] = smallest;
451 face_offsets1, corners.to_sorted1, corners.set_ids, smallest_corner_ids1);
453 face_offsets2, corners.to_sorted2, corners.set_ids, smallest_corner_ids2);
457 smallest_corner_ids1.
as_span(),
458 smallest_corner_ids2.
as_span());
461 smallest_corner_ids1.
as_span(),
462 smallest_corner_ids2.
as_span(),
466 if (!faces_line_up) {
483 ELEM(name,
".uv_select_vert",
".uv_select_edge",
".uv_select_face");
500 if (names_1 != names_2) {
501 std::string mismatched_names;
504 if (!mismatched_names.empty()) {
505 mismatched_names.append(
", ");
507 mismatched_names.append(name);
511 if (!names_1.contains(name)) {
512 if (!mismatched_names.empty()) {
513 mismatched_names.append(
", ");
515 mismatched_names.append(name);
518 CLOG_WARN(&
LOG,
"Attribute names not the same: %s", mismatched_names.c_str());
524 if (!reader1 || !reader2) {
576template<
typename T,
typename ComponentT>
578 const int components_num,
582 const T *
data =
static_cast<const T *
>(values.
data());
584 dst[i] = ComponentT(
data[i * components_num + component]);
593 fn.template operator()<
bool>();
603 fn.template operator()<
int>();
618 const float threshold,
664 const float threshold)
669 for (
const StringRef name : excluded_attributes) {
678 if (reader1.
domain != domain) {
694 if (components->is_float) {
697 for (
const int component :
IndexRange(components->num)) {
709 for (
const int component :
IndexRange(components->num)) {
735 int match = sorted_i;
736 for (
const int other_index :
745 for (
const int other_set_i :
749 indices.
set_ids[other_set_i] = sorted_i + 1;
752 indices.
set_ids[sorted_i] = sorted_i;
759 for (
const int size : set_sizes) {
794 mesh1.edges(), mesh1.
verts_num, vert_to_edge_offsets1, vert_to_edge_indices1);
798 mesh2.edges(), mesh2.
verts_num, vert_to_edge_offsets2, vert_to_edge_indices2);
803 const Span<int> edges1 = vert_to_edge_map1[vert1];
809 const Span<int> edges2 = vert_to_edge_map2[vert2];
810 if (edges1.
size() != edges2.
size()) {
813 bool vert_matches =
true;
814 for (
const int edge1 : edges1) {
815 bool found_matching_edge =
false;
816 for (
const int edge2 : edges2) {
818 found_matching_edge =
true;
822 if (!found_matching_edge) {
823 vert_matches =
false;
828 matching_verts.
append(index_in_set);
842 int index_in_set = matching_verts.
first();
843 for (
const int other_index_in_set : matching_verts) {
844 const int other_sorted_index = verts.
set_ids[sorted_i] + other_index_in_set;
846 index_in_set = other_index_in_set;
854 verts.
set_ids[other_set_i] = sorted_i + 1;
857 verts.
set_ids[sorted_i] = sorted_i;
874 const float threshold)
891 std::optional<GeoMismatch> mismatch = {};
911 if (!
sort_edges(mesh1.edges(), mesh2.edges(), verts, edges)) {
916 mesh1_attributes, mesh2_attributes,
AttrDomain::Edge, {
".edge_verts"}, edges, threshold);
936 {
".corner_vert",
".corner_edge"},
944 corners.recalculate_inverse_maps();
952 mesh1_attributes, mesh2_attributes,
AttrDomain::Face, {}, faces, threshold);
964 if (!
sort_edges(mesh1.edges(), mesh2.edges(), verts, edges)) {
982 corners.recalculate_inverse_maps();
999 for (
const int sorted_i : corners.from_sorted1.index_range()) {
1000 if (corners.from_sorted1[sorted_i] != corners.from_sorted2[sorted_i]) {
1011 return std::nullopt;
1030 curve_point_counts1.
as_span(),
1031 curve_point_counts2.
as_span());
1034 curve_point_counts1.
as_span(),
1035 curve_point_counts2.
as_span(),
1039 if (!curves_sizes_match) {
1048 const float threshold)
1058 std::optional<GeoMismatch> mismatch = {};
1069 curves1_attributes, curves2_attributes,
AttrDomain::Point, {}, points, threshold);
1091 for (
const int sorted_i :
curves.from_sorted1.index_range()) {
1092 if (
curves.from_sorted1[sorted_i] !=
curves.from_sorted2[sorted_i]) {
1098 return std::nullopt;
1115 const int num_points = lattice1.
pntsu * lattice1.
pntsv * lattice1.
pntsw;
1119 const float3 co1 = bpoints1[i].vec;
1120 const float3 co2 = bpoints2[i].vec;
1129 return std::nullopt;
1136 const float threshold)
1138 if (layer_1.name() != layer_2.name()) {
1141 if (layer_1.
frames().size() != layer_2.
frames().size()) {
1148 if (sorted_keys_1[i] != sorted_keys_2[i]) {
1153 std::optional<GeoMismatch> mismatch = {};
1157 if ((frame_1 ==
nullptr) != (frame_2 ==
nullptr)) {
1160 if (frame_1 ==
nullptr) {
1165 if ((drawing_1 ==
nullptr) != (drawing_2 ==
nullptr)) {
1168 if (drawing_1 ==
nullptr) {
1179 return std::nullopt;
1184 const float threshold)
1188 if (layers_1.
size() != layers_2.
size()) {
1192 std::optional<GeoMismatch> mismatch = {};
1194 const AttributeAccessor grease_pencil_1_attributes = grease_pencil_1.attributes();
1195 const AttributeAccessor grease_pencil_2_attributes = grease_pencil_2.attributes();
1203 grease_pencil_2_attributes,
1221 grease_pencil_1, grease_pencil_2, *layers_1[
layer], *layers_2[
layer], threshold);
1228 return std::nullopt;
Low-level operations for grease pencil.
#define CLOG_WARN(clg_ref,...)
#define BLI_assert_unreachable()
Span< T > as_span() const
MutableSpan< T > as_mutable_span()
IndexRange index_range() const
void fill(const T &value) const
const void * data() const
const CPPType & type() const
constexpr IndexRange()=default
constexpr int64_t size() const
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
constexpr bool is_empty() const
constexpr T * end() const
constexpr T * begin() const
constexpr IndexRange index_range() const
bool remove_as(const ForwardKey &key)
bool contains(const Key &key) const
int64_t remove_if(Predicate &&predicate)
constexpr int64_t size() const
constexpr IndexRange index_range() const
void append(const T &value)
Set< StringRefNull > all_names() const
GAttributeReader lookup(const StringRef name) const
AttributeAccessor attributes() const
Span< int > offsets() const
IndexMapping(const int64_t domain_size)
void recalculate_inverse_maps()
Array< int > from_sorted2
Array< int > from_sorted1
const bke::CurvesGeometry & strokes() const
const Map< FramesMapKeyT, GreasePencilFrame > & frames() const
const GreasePencilFrame * frame_at(const int frame_number) const
Span< FramesMapKeyT > sorted_keys() const
constexpr bool startswith(StringRef prefix) const
IndexRange index_range() const
static bool sort_curves(const OffsetIndices< int > offset_indices1, const OffsetIndices< int > offset_indices2, IndexMapping &curves)
std::optional< GeoMismatch > compare_meshes(const Mesh &mesh1, const Mesh &mesh2, float threshold)
Checks if the two meshes are different, returning the type of mismatch if any. Changes in index order...
static bool update_set_ids_with_id_maps(MutableSpan< int > set_ids, const Span< int > domain_to_values1, const Span< int > domain_to_values2, const Span< int > values1_to_sorted, const Span< int > values2_to_sorted, const Span< int > value_set_ids, const Span< int > sorted_to_domain1, const Span< int > sorted_to_domain2)
static bool ignored_attribute(const StringRef name)
static bool sort_using_values(const StringRef name, const Span< T > values1, const Span< T > values2, const float threshold, IndexMapping &maps)
static void edges_from_vert_sets(const Span< int2 > edges, const Span< int > verts_to_sorted, const Span< int > vert_set_ids, MutableSpan< OrderedEdge > r_edges)
static std::optional< GeoMismatch > verify_attributes_compatible(const AttributeAccessor &attributes1, const AttributeAccessor &attributes2)
static void to_static_int_component_type(const AttrType type, Fn &&fn)
static bool sort_corners_based_on_domain(const Span< int > corner_domain1, const Span< int > corner_domain2, const IndexMapping &domain, IndexMapping &corners)
static void make_set_sizes_one(IndexMapping &indices)
static void update_set_sizes(const Span< int > set_ids, MutableSpan< int > set_sizes)
static bool sort_edges(const Span< int2 > edges1, const Span< int2 > edges2, const IndexMapping &verts, IndexMapping &edges)
static void gather_component(const GSpan values, const int components_num, const int component, MutableSpan< ComponentT > dst)
static void calc_smallest_corner_ids(const Span< int > face_offsets, const Span< int > corners_to_sorted, const Span< int > corner_set_ids, MutableSpan< int > smallest_corner_ids)
static bool update_set_ids(StringRef name, MutableSpan< int > set_ids, const Span< T > values1, const Span< T > values2, const Span< int > sorted_to_values1, const Span< int > sorted_to_values2, const float threshold)
static bool all_set_sizes_one(const Span< int > set_sizes)
static std::optional< GeoMismatch > compare_grease_pencil_layer(const GreasePencil &grease_pencil_1, const GreasePencil &grease_pencil_2, const greasepencil::Layer &layer_1, const greasepencil::Layer &layer_2, const float threshold)
static std::optional< GeoMismatch > construct_vert_mapping(const Mesh &mesh1, const Mesh &mesh2, IndexMapping &verts, IndexMapping &edges)
std::optional< GeoMismatch > compare_grease_pencil(const GreasePencil &grease_pencil_1, const GreasePencil &grease_pencil_2, float threshold)
Checks if two Grease Pencil geometries are different, returning the type of mismatch if any.
std::optional< GeoMismatch > compare_curves(const CurvesGeometry &curves1, const CurvesGeometry &curves2, float threshold)
Checks if the two curves geometries are different, returning the type of mismatch if any....
static std::optional< GeoMismatch > sort_domain_using_attributes(const AttributeAccessor &attributes1, const AttributeAccessor &attributes2, const AttrDomain domain, const Span< StringRef > excluded_attributes, IndexMapping &maps, const float threshold)
static bool values_different(const T value1, const T value2, const float threshold)
static void sort_per_set_with_id_maps(const Span< int > set_sizes, const Span< int > values1, const Span< int > values2, const Span< int > values1_to_sorted, const Span< int > values2_to_sorted, const Span< int > value_set_ids, MutableSpan< int > sorted_to_domain1, MutableSpan< int > sorted_to_domain2)
static GeoMismatch attribute_mismatch_for_domain(const AttrDomain domain)
static void sort_indices(MutableSpan< int > indices, const Span< T > values)
static std::optional< AttributeComponents > get_attribute_components(const AttrType type)
static void sort_per_set_based_on_attributes(const Span< int > set_sizes, MutableSpan< int > sorted_to_domain1, MutableSpan< int > sorted_to_domain2, const Span< T > values1, const Span< T > values2)
static bool sort_faces_based_on_corners(const IndexMapping &corners, const Span< int > face_offsets1, const Span< int > face_offsets2, IndexMapping &faces)
static void sort_indices_with_id_maps(MutableSpan< int > indices, const Span< int > values, const Span< int > values_to_sorted, const Span< int > set_ids)
const char * mismatch_to_string(const GeoMismatch &mismatch)
std::optional< GeoMismatch > compare_lattices(const Lattice &lattice1, const Lattice &lattice2, float threshold)
Checks if the two lattices are different, returning the type of mismatch if any.
GroupedSpan< int > build_vert_to_edge_map(Span< int2 > edges, int verts_num, Array< int > &r_offsets, Array< int > &r_indices)
bool attribute_name_is_anonymous(const StringRef name)
AttrType cpp_type_to_attribute_type(const CPPType &type)
void copy_group_sizes(OffsetIndices< int > offsets, const IndexMask &mask, MutableSpan< int > sizes)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE bool compare_threshold_relative(float value1, float value2, float thresh)
VecBase< int32_t, 2 > int2
BMesh const char void * data
VecBase< float, 3 > float3
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
OrderedEdge(const int v1, const int v2)