33#include "range_tree.h"
123 return log->elem_to_id.lookup(
reinterpret_cast<BMElem *
>(
v));
129 log->id_to_elem.add_overwrite(
id,
reinterpret_cast<BMElem *
>(
v));
130 log->elem_to_id.add_overwrite(
reinterpret_cast<BMElem *
>(
v),
id);
136 return reinterpret_cast<BMVert *
>(
log->id_to_elem.lookup(
id));
142 return log->elem_to_id.lookup(
reinterpret_cast<BMElem *
>(f));
148 log->id_to_elem.add_overwrite(
id,
reinterpret_cast<BMElem *
>(f));
149 log->elem_to_id.add_overwrite(
reinterpret_cast<BMElem *
>(f),
id);
155 return reinterpret_cast<BMFace *
>(
log->id_to_elem.lookup(
id));
165 if (cd_vert_mask_offset != -1) {
176 if (cd_vert_mask_offset != -1) {
187 lv->
hflag =
v->head.hflag;
232 for (
const auto item :
verts.items()) {
249 std::array<BMEdge *, 3> e_tri;
252 for (
uint i = 0;
i < e_tri.size();
i++, l_iter = l_iter->
next) {
253 e_tri[
i] = l_iter->
e;
258 for (
uint i = 0;
i < e_tri.size();
i++) {
273 for (
const auto item :
verts.items()) {
277 v->head.hflag = lv->
hflag;
290 for (
const auto item :
faces.items()) {
303 if (cd_face_sets != -1) {
316 for (
const auto item :
verts.items()) {
322 std::swap(
v->head.hflag, lv->
hflag);
332 for (
const auto item :
faces.items()) {
350 uint id = range_tree_uint_take_any(
log->unused_ids);
357 uint id = range_tree_uint_take_any(
log->unused_ids);
365 BMLogEntry *entry = MEM_new<BMLogEntry>(__func__);
394 BMLog *
log = MEM_new<BMLog>(__func__);
395 const uint reserve_num =
uint(
bm->totvert +
bm->totface);
397 log->unused_ids = range_tree_uint_alloc(0,
uint(-1));
398 log->id_to_elem.reserve(reserve_num);
399 log->elem_to_id.reserve(reserve_num);
414 range_tree_uint_retake(
log->unused_ids,
id);
417 range_tree_uint_retake(
log->unused_ids,
id);
420 range_tree_uint_retake(
log->unused_ids,
id);
423 range_tree_uint_retake(
log->unused_ids,
id);
426 range_tree_uint_retake(
log->unused_ids,
id);
429 range_tree_uint_retake(
log->unused_ids,
id);
449 log->current_entry = entry;
452 log->current_entry =
nullptr;
456 log->entries.first =
log->entries.last = entry;
459 while (entry->
prev) {
461 log->entries.first = entry;
464 while (entry->
next) {
466 log->entries.last = entry;
470 for (entry =
static_cast<BMLogEntry *
>(
log->entries.first); entry; entry = entry->
next) {
475 range_tree_uint_retake(
log->unused_ids,
id);
478 range_tree_uint_retake(
log->unused_ids,
id);
481 range_tree_uint_retake(
log->unused_ids,
id);
484 range_tree_uint_retake(
log->unused_ids,
id);
487 range_tree_uint_retake(
log->unused_ids,
id);
490 range_tree_uint_retake(
log->unused_ids,
id);
499 if (
log->unused_ids) {
500 range_tree_uint_free(
log->unused_ids);
506 entry->log =
nullptr;
521 log->current_entry = entry;
536 else if (entry->
next) {
572 else if (!entry->
next) {
578 range_tree_uint_release(
log->unused_ids,
id);
581 range_tree_uint_release(
log->unused_ids,
id);
588 if (
log->current_entry == entry) {
589 log->current_entry = entry->
prev;
602 log->current_entry = entry->
prev;
626 else if (entry->
next) {
635 log->current_entry = entry;
669 const uint v_id = range_tree_uint_take_any(
log->unused_ids);
673 log->current_entry->added_verts.add(v_id, lv);
681 log->current_entry->modified_faces.add(f_id,
lf);
686 const uint f_id = range_tree_uint_take_any(
log->unused_ids);
693 log->current_entry->added_faces.add(f_id,
lf);
705 range_tree_uint_release(
log->unused_ids, v_id);
714 *lv = *lv_mod.value();
729 range_tree_uint_release(
log->unused_ids, f_id);
743 if (
log->current_entry->added_verts.is_empty()) {
744 log->current_entry->added_verts.reserve(
bm->totvert);
747 if (
log->current_entry->added_faces.is_empty()) {
748 log->current_entry->added_faces.reserve(
bm->totface);
790 return log_vert.value()->position;
801 return &log_vert.value()->mask;
825 return log->current_entry;
830 return log->unused_ids;
839 const char *current =
" <-- current";
842 printf(
"%s:\n", description);
843 printf(
" % 2d: [ initial ]%s\n", 0, (!
log->current_entry) ? current :
"");
844 for (entry =
static_cast<const BMLogEntry *
>(
log->entries.first),
i = 1; entry;
845 entry = entry->
next,
i++)
847 printf(
" % 2d: [%p]%s\n",
i, entry, (entry ==
log->current_entry) ? current :
"");
854 printf(
"BM { totvert=%d totedge=%d totloop=%d faces_num=%d\n",
861 printf(
"%s: Warning: empty bmesh\n", __func__);
865 printf(
"BM { totvert=unknown totedge=unknown totloop=unknown faces_num=unknown\n");
868 printf(
"v | added: %d, removed: %d, modified: %d\n",
872 printf(
"f | added: %d, removed: %d, modified: %d\n",
CustomData interface, see also DNA_customdata_types.h.
int CustomData_get_offset_named(const CustomData *data, eCustomDataType type, blender::StringRef name)
#define BLI_assert_msg(a, msg)
#define LISTBASE_FOREACH(type, var, list)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void swap_v3_v3(float a[3], float b[3])
Read Guarded memory(de)allocation.
#define BM_ELEM_CD_SET_FLOAT(ele, offset, f)
#define BM_ELEM_CD_GET_FLOAT(ele, offset)
#define BM_ELEM_CD_SET_INT(ele, offset, f)
#define BM_FACE_FIRST_LOOP(p)
void BM_vert_kill(BMesh *bm, BMVert *v)
void BM_face_kill(BMesh *bm, BMFace *f)
BMFace * BM_face_create_verts(BMesh *bm, BMVert **vert_arr, const int len, const BMFace *f_example, const eBMCreateFlag create_flag, const bool create_edges)
void BM_edge_kill(BMesh *bm, BMEdge *e)
BMVert * BM_vert_create(BMesh *bm, const float co[3], const BMVert *v_example, const eBMCreateFlag create_flag)
Main function for creating a new vertex.
#define BM_ITER_MESH(ele, iter, bm, itype)
static void vert_mask_set(BMVert *v, const float new_mask, const int cd_vert_mask_offset)
static BMLogEntry * bm_log_entry_create()
void BM_log_all_added(BMesh *bm, BMLog *log)
static void bm_log_faces_unmake(BMesh *bm, BMLog *log, const blender::Map< uint, BMLogFace *, 0 > &faces)
void BM_log_face_added(BMLog *log, BMFace *f)
const float * BM_log_find_original_vert_mask(BMLog *log, BMVert *v)
static void bm_log_face_id_set(BMLog *log, BMFace *f, const uint id)
void BM_log_face_removed(BMLog *log, BMFace *f)
RangeTreeUInt * BM_log_unused_ids(BMLog *log)
static void bm_log_face_values_swap(BMLog *log, const blender::Map< uint, BMLogFace *, 0 > &faces)
static void bm_log_faces_restore(BMesh *bm, BMLog *log, const blender::Map< uint, BMLogFace *, 0 > &faces)
static void bm_log_assign_ids(BMesh *bm, BMLog *log)
void BM_log_free(BMLog *log)
void BM_log_cleanup_entry(BMLogEntry *entry)
static BMLogFace * bm_log_face_alloc(BMLog *log, BMFace *f)
void BM_log_original_vert_data(BMLog *log, BMVert *v, const float **r_co, const float **r_no)
static BMVert * bm_log_vert_from_id(BMLog *log, const uint id)
static void bm_log_vert_values_swap(BMesh *bm, BMLog *log, const blender::Map< uint, BMLogVert *, 0 > &verts)
void BM_log_print(const BMLog *log, const char *description)
BMLogEntry * BM_log_current_entry(BMLog *log)
const float * BM_log_find_original_vert_co(BMLog *log, BMVert *v)
void BM_log_vert_added(BMLog *log, BMVert *v, const int cd_vert_mask_offset)
static void bm_log_verts_restore(BMesh *bm, BMLog *log, const blender::Map< uint, BMLogVert *, 0 > &verts)
static float vert_mask_get(BMVert *v, const int cd_vert_mask_offset)
void BM_log_face_modified(BMLog *log, BMFace *f)
static void bm_log_vert_id_set(BMLog *log, BMVert *v, const uint id)
static void bm_log_verts_unmake(BMesh *bm, BMLog *log, const blender::Map< uint, BMLogVert *, 0 > &verts)
void BM_log_redo(BMesh *bm, BMLog *log)
static BMLogVert * bm_log_vert_alloc(BMLog *log, BMVert *v, const int cd_vert_mask_offset)
void BM_log_print_entry(BMesh *bm, BMLogEntry *entry)
static void bm_log_entry_free(BMLogEntry *entry)
static void bm_log_vert_bmvert_copy(BMLogVert *lv, BMVert *v, const int cd_vert_mask_offset)
static uint bm_log_vert_id_get(BMLog *log, BMVert *v)
static uint bm_log_face_id_get(BMLog *log, BMFace *f)
void BM_log_vert_removed(BMLog *log, BMVert *v, const int cd_vert_mask_offset)
void BM_log_vert_before_modified(BMLog *log, BMVert *v, const int cd_vert_mask_offset)
void BM_log_entry_drop(BMLogEntry *entry)
BMLog * BM_log_from_existing_entries_create(BMesh *bm, BMLogEntry *entry)
BMLog * BM_log_create(BMesh *bm)
static BMFace * bm_log_face_from_id(BMLog *log, const uint id)
void BM_log_undo(BMesh *bm, BMLog *log)
void BM_log_before_all_removed(BMesh *bm, BMLog *log)
BMLogEntry * BM_log_entry_add(BMLog *log)
void BM_face_as_array_vert_tri(BMFace *f, BMVert *r_verts[3])
BLI_INLINE bool BM_edge_is_wire(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
ATTR_WARN_UNUSED_RESULT const BMVert * v
std::optional< Value > lookup_try(const Key &key) const
bool add(const Key &key, const Value &value)
const Value & lookup(const Key &key) const
Value & lookup_or_add_cb(const Key &key, const CreateValueF &create_value)
bool remove(const Key &key)
KeyIterator keys() const &
bool contains(const Key &key) const
void append(const T &value)
T & construct(ForwardT &&...value)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
VecBase< float, 3 > float3
blender::Pool< BMLogFace > face_pool
blender::Map< uint, BMLogFace *, 0 > modified_faces
blender::Map< uint, BMLogVert *, 0 > added_verts
blender::Map< uint, BMLogFace *, 0 > deleted_faces
blender::Vector< BMLogVert *, 0 > allocated_verts
blender::Pool< BMLogVert > vert_pool
blender::Map< uint, BMLogVert *, 0 > deleted_verts
blender::Vector< BMLogFace *, 0 > allocated_faces
blender::Map< uint, BMLogFace *, 0 > added_faces
blender::Map< uint, BMLogVert *, 0 > modified_verts
std::array< uint, 3 > v_ids
blender::Map< uint, BMElem *, 0 > id_to_elem
RangeTreeUInt * unused_ids
blender::Map< BMElem *, uint, 0 > elem_to_id
BMLogEntry * current_entry