Blender V5.0
bmesh_log.cc File Reference
#include "MEM_guardedalloc.h"
#include "BLI_listbase.h"
#include "BLI_map.hh"
#include "BLI_math_vector.h"
#include "BLI_pool.hh"
#include "BLI_utildefines.h"
#include "BKE_customdata.hh"
#include "bmesh.hh"
#include "bmesh_log.hh"
#include "range_tree.h"
#include "BLI_strict_flags.h"

Go to the source code of this file.

Classes

struct  BMLogEntry
struct  BMLog
struct  BMLogVert
struct  BMLogFace

Functions

static uint bm_log_vert_id_get (BMLog *log, BMVert *v)
static void bm_log_vert_id_set (BMLog *log, BMVert *v, const uint id)
static BMVertbm_log_vert_from_id (BMLog *log, const uint id)
static uint bm_log_face_id_get (BMLog *log, BMFace *f)
static void bm_log_face_id_set (BMLog *log, BMFace *f, const uint id)
static BMFacebm_log_face_from_id (BMLog *log, const uint id)
static float vert_mask_get (BMVert *v, const int cd_vert_mask_offset)
static void vert_mask_set (BMVert *v, const float new_mask, const int cd_vert_mask_offset)
static void bm_log_vert_bmvert_copy (BMLogVert *lv, BMVert *v, const int cd_vert_mask_offset)
static BMLogVertbm_log_vert_alloc (BMLog *log, BMVert *v, const int cd_vert_mask_offset)
static BMLogFacebm_log_face_alloc (BMLog *log, BMFace *f)
static void bm_log_verts_unmake (BMesh *bm, BMLog *log, const blender::Map< uint, BMLogVert *, 0 > &verts)
static void bm_log_faces_unmake (BMesh *bm, BMLog *log, const blender::Map< uint, BMLogFace *, 0 > &faces)
static void bm_log_verts_restore (BMesh *bm, BMLog *log, const blender::Map< uint, BMLogVert *, 0 > &verts)
static void bm_log_faces_restore (BMesh *bm, BMLog *log, const blender::Map< uint, BMLogFace *, 0 > &faces)
static void bm_log_vert_values_swap (BMesh *bm, BMLog *log, const blender::Map< uint, BMLogVert *, 0 > &verts)
static void bm_log_face_values_swap (BMLog *log, const blender::Map< uint, BMLogFace *, 0 > &faces)
static void bm_log_assign_ids (BMesh *bm, BMLog *log)
static BMLogEntrybm_log_entry_create ()
static void bm_log_entry_free (BMLogEntry *entry)
BMLogBM_log_create (BMesh *bm)
void BM_log_cleanup_entry (BMLogEntry *entry)
BMLogBM_log_from_existing_entries_create (BMesh *bm, BMLogEntry *entry)
void BM_log_free (BMLog *log)
BMLogEntryBM_log_entry_add (BMLog *log)
void BM_log_entry_drop (BMLogEntry *entry)
void BM_log_undo (BMesh *bm, BMLog *log)
void BM_log_redo (BMesh *bm, BMLog *log)
void BM_log_vert_before_modified (BMLog *log, BMVert *v, const int cd_vert_mask_offset)
void BM_log_vert_added (BMLog *log, BMVert *v, const int cd_vert_mask_offset)
void BM_log_face_modified (BMLog *log, BMFace *f)
void BM_log_face_added (BMLog *log, BMFace *f)
void BM_log_vert_removed (BMLog *log, BMVert *v, const int cd_vert_mask_offset)
void BM_log_face_removed (BMLog *log, BMFace *f)
void BM_log_all_added (BMesh *bm, BMLog *log)
void BM_log_before_all_removed (BMesh *bm, BMLog *log)
const floatBM_log_find_original_vert_co (BMLog *log, BMVert *v)
const floatBM_log_find_original_vert_mask (BMLog *log, BMVert *v)
void BM_log_original_vert_data (BMLog *log, BMVert *v, const float **r_co, const float **r_no)
BMLogEntryBM_log_current_entry (BMLog *log)
RangeTreeUInt * BM_log_unused_ids (BMLog *log)
void BM_log_print (const BMLog *log, const char *description)
void BM_log_print_entry (BMesh *bm, BMLogEntry *entry)

Detailed Description

The BMLog is an interface for storing undo/redo steps as a BMesh is modified. It only stores changes to the BMesh, not full copies.

Currently it supports the following types of changes:

  • Adding and removing vertices
  • Adding and removing faces
  • Moving vertices
  • Setting vertex paint-mask values
  • Setting vertex hflags

Definition in file bmesh_log.cc.

Function Documentation

◆ BM_log_all_added()

void BM_log_all_added ( BMesh * bm,
BMLog * log )

◆ bm_log_assign_ids()

void bm_log_assign_ids ( BMesh * bm,
BMLog * log )
static

◆ BM_log_before_all_removed()

void BM_log_before_all_removed ( BMesh * bm,
BMLog * log )

◆ BM_log_cleanup_entry()

◆ BM_log_create()

BMLog * BM_log_create ( BMesh * bm)

Allocate, initialize, and assign a new BMLog.

Definition at line 392 of file bmesh_log.cc.

References bm, bm_log_assign_ids(), and log.

Referenced by BM_log_from_existing_entries_create(), and blender::ed::sculpt_paint::dyntopo::enable_ex().

◆ BM_log_current_entry()

BMLogEntry * BM_log_current_entry ( BMLog * log)

For internal use only (unit testing).

Definition at line 823 of file bmesh_log.cc.

References log.

◆ BM_log_entry_add()

BMLogEntry * BM_log_entry_add ( BMLog * log)

Start a new log entry and update the log entry list.

If the log entry list is empty, or if the current log entry is the last entry, the new entry is simply appended to the end.

Finally, the new entry is set as the current log entry.

Definition at line 512 of file bmesh_log.cc.

References BLI_addtail(), bm_log_entry_create(), BMLogEntry::log, and log.

Referenced by blender::ed::sculpt_paint::undo::bmesh_push().

◆ bm_log_entry_create()

BMLogEntry * bm_log_entry_create ( )
static

Definition at line 363 of file bmesh_log.cc.

Referenced by BM_log_entry_add().

◆ BM_log_entry_drop()

void BM_log_entry_drop ( BMLogEntry * entry)

Remove an entry from the log.

Uses entry->log as the log. If the log is NULL, the entry will be freed but not removed from any list, nor shall its IDs be released.

Warning
This operation is only valid on the first and last entries in the log. Deleting from the middle will assert.

Definition at line 526 of file bmesh_log.cc.

References BMLogEntry::added_faces, BMLogEntry::added_verts, BLI_assert, BLI_assert_msg, BLI_remlink(), bm_log_entry_free(), Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::keys(), BMLogEntry::log, log, BMLogEntry::next, and BMLogEntry::prev.

Referenced by blender::ed::sculpt_paint::undo::free_step_data().

◆ bm_log_entry_free()

◆ BM_log_face_added()

void BM_log_face_added ( BMLog * log,
BMFace * f )

Log a new face as added to the BMesh.

The new face gets a unique ID assigned. It is then added to a map of added faces, with the key being its ID and the value containing everything needed to reconstruct that face.

Definition at line 684 of file bmesh_log.cc.

References BLI_assert, bm_log_face_alloc(), bm_log_face_id_set(), BMFace::len, and log.

Referenced by BM_log_all_added(), and blender::bke::pbvh::pbvh_bmesh_face_create().

◆ bm_log_face_alloc()

◆ bm_log_face_from_id()

BMFace * bm_log_face_from_id ( BMLog * log,
const uint id )
static

Definition at line 153 of file bmesh_log.cc.

References log.

Referenced by bm_log_face_values_swap(), and bm_log_faces_unmake().

◆ bm_log_face_id_get()

uint bm_log_face_id_get ( BMLog * log,
BMFace * f )
static

Definition at line 140 of file bmesh_log.cc.

References log.

Referenced by BM_log_face_modified(), and BM_log_face_removed().

◆ bm_log_face_id_set()

void bm_log_face_id_set ( BMLog * log,
BMFace * f,
const uint id )
static

Definition at line 146 of file bmesh_log.cc.

References log.

Referenced by bm_log_assign_ids(), BM_log_face_added(), and bm_log_faces_restore().

◆ BM_log_face_modified()

void BM_log_face_modified ( BMLog * log,
BMFace * f )

Log a face before it is modified.

This is intended to handle only header flags and we always assume face has been added before.

Definition at line 676 of file bmesh_log.cc.

References bm_log_face_alloc(), bm_log_face_id_get(), and log.

Referenced by blender::ed::sculpt_paint::undo::bmesh_push().

◆ BM_log_face_removed()

void BM_log_face_removed ( BMLog * log,
BMFace * f )

Log a face as removed from the BMesh.

A couple things can happen here:

If the face was added as part of the current log entry, then it's deleted and forgotten about entirely. Its unique ID is returned to the unused pool.

If the face was already part of the BMesh before the current log entry, it is added to a map of deleted faces, with the key being its ID and the value containing everything needed to reconstruct that face.

Definition at line 720 of file bmesh_log.cc.

References Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), BMLogEntry::added_faces, BLI_assert, bm_log_face_alloc(), bm_log_face_id_get(), Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::contains(), BMLogEntry::deleted_faces, log, Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::lookup(), and Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::remove().

Referenced by BM_log_before_all_removed(), and blender::bke::pbvh::pbvh_bmesh_face_remove().

◆ bm_log_face_values_swap()

void bm_log_face_values_swap ( BMLog * log,
const blender::Map< uint, BMLogFace *, 0 > & faces )
static

Definition at line 329 of file bmesh_log.cc.

References bm_log_face_from_id(), faces, BMFace::head, BMHeader::hflag, and log.

Referenced by BM_log_redo(), and BM_log_undo().

◆ bm_log_faces_restore()

void bm_log_faces_restore ( BMesh * bm,
BMLog * log,
const blender::Map< uint, BMLogFace *, 0 > & faces )
static

◆ bm_log_faces_unmake()

void bm_log_faces_unmake ( BMesh * bm,
BMLog * log,
const blender::Map< uint, BMLogFace *, 0 > & faces )
static

◆ BM_log_find_original_vert_co()

const float * BM_log_find_original_vert_co ( BMLog * log,
BMVert * v )

Search the log for the original vertex coordinates.

Does not modify the log or the vertex.

Returns
the pointer or nullptr if the vertex isn't found.

Definition at line 784 of file bmesh_log.cc.

References bm_log_vert_id_get(), log, Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::lookup_try(), BMLogEntry::modified_verts, and v.

Referenced by blender::bke::pbvh::copy_original_vert(), and blender::ed::sculpt_paint::undo::restore_position_from_undo_step().

◆ BM_log_find_original_vert_mask()

const float * BM_log_find_original_vert_mask ( BMLog * log,
BMVert * v )

Search the log for the original vertex mask.

Does not modify the log or the vertex.

Returns
the pointer or nullptr if the vertex isn't found.

Definition at line 795 of file bmesh_log.cc.

References bm_log_vert_id_get(), log, Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::lookup_try(), BMLogEntry::modified_verts, and v.

Referenced by blender::ed::sculpt_paint::undo::restore_mask_from_undo_step().

◆ BM_log_free()

void BM_log_free ( BMLog * log)

Free all the data in a BMLog including the log itself.

Definition at line 497 of file bmesh_log.cc.

References LISTBASE_FOREACH, and log.

Referenced by blender::ed::sculpt_paint::dyntopo::disable(), and SculptSession::~SculptSession().

◆ BM_log_from_existing_entries_create()

BMLog * BM_log_from_existing_entries_create ( BMesh * bm,
BMLogEntry * entry )

Allocate and initialize a new BMLog using existing #BMLogEntries

The unused IDs field of the log will be initialized by taking all keys from all Maps in the log entry.

Parameters
entryThe last entry of the prior BMLog, its prev pointer will be followed back to reconstruct the log.

Definition at line 444 of file bmesh_log.cc.

References BMLogEntry::added_faces, BMLogEntry::added_verts, bm, BM_log_create(), BMLogEntry::deleted_faces, BMLogEntry::deleted_verts, Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::keys(), BMLogEntry::log, log, BMLogEntry::modified_faces, BMLogEntry::modified_verts, BMLogEntry::next, and BMLogEntry::prev.

Referenced by blender::ed::sculpt_paint::undo::bmesh_enable().

◆ BM_log_original_vert_data()

◆ BM_log_print()

void BM_log_print ( const BMLog * log,
const char * description )

Definition at line 836 of file bmesh_log.cc.

References i, log, BMLogEntry::next, and printf.

◆ BM_log_print_entry()

◆ BM_log_redo()

◆ BM_log_undo()

◆ BM_log_unused_ids()

RangeTreeUInt * BM_log_unused_ids ( BMLog * log)

For internal use only (unit testing)

Definition at line 828 of file bmesh_log.cc.

References log.

◆ BM_log_vert_added()

void BM_log_vert_added ( BMLog * log,
BMVert * v,
int cd_vert_mask_offset )

Log a new vertex as added to the BMesh.

The new vertex gets a unique ID assigned. It is then added to a map of added vertices, with the key being its ID and the value containing everything needed to reconstruct that vertex.

Definition at line 667 of file bmesh_log.cc.

References bm_log_vert_alloc(), bm_log_vert_id_set(), log, and v.

Referenced by BM_log_all_added(), and blender::bke::pbvh::pbvh_bmesh_vert_create().

◆ bm_log_vert_alloc()

◆ BM_log_vert_before_modified()

void BM_log_vert_before_modified ( BMLog * log,
BMVert * v,
int cd_vert_mask_offset )

Log a vertex before it is modified.

Before modifying vertex coordinates, masks, or hflags, call this function to log its current values. This is better than logging after the coordinates have been modified, because only those vertices that are modified need to have their original values stored.

Handles two separate cases:

If the vertex was added in the current log entry, update the vertex in the map of added vertices.

If the vertex already existed prior to the current log entry, a separate key/value map of modified vertices is used (using the vertex's ID as the key). The values stored in that case are the vertex's original state so that an undo can restore the previous state.

On undo, the current vertex state will be swapped with the stored state so that a subsequent redo operation will restore the newer vertex state.

Definition at line 652 of file bmesh_log.cc.

References BMLogEntry::added_verts, bm_log_vert_alloc(), bm_log_vert_bmvert_copy(), bm_log_vert_id_get(), Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::contains(), log, Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::lookup(), Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::lookup_or_add_cb(), BMLogEntry::modified_verts, and v.

Referenced by blender::ed::sculpt_paint::undo::bmesh_push(), and blender::bke::pbvh::pbvh_bmesh_collapse_edge().

◆ bm_log_vert_bmvert_copy()

void bm_log_vert_bmvert_copy ( BMLogVert * lv,
BMVert * v,
const int cd_vert_mask_offset )
static

◆ bm_log_vert_from_id()

BMVert * bm_log_vert_from_id ( BMLog * log,
const uint id )
static

Definition at line 134 of file bmesh_log.cc.

References log.

Referenced by bm_log_faces_restore(), bm_log_vert_values_swap(), and bm_log_verts_unmake().

◆ bm_log_vert_id_get()

◆ bm_log_vert_id_set()

void bm_log_vert_id_set ( BMLog * log,
BMVert * v,
const uint id )
static

Definition at line 127 of file bmesh_log.cc.

References log, and v.

Referenced by bm_log_assign_ids(), BM_log_vert_added(), and bm_log_verts_restore().

◆ BM_log_vert_removed()

void BM_log_vert_removed ( BMLog * log,
BMVert * v,
int cd_vert_mask_offset )

Log a vertex as removed from the BMesh.

A couple things can happen here:

If the vertex was added as part of the current log entry, then it's deleted and forgotten about entirely. Its unique ID is returned to the unused pool.

If the vertex was already part of the BMesh before the current log entry, it is added to a map of deleted vertices, with the key being its ID and the value containing everything needed to reconstruct that vertex.

If there's a move record for the vertex, that's used as the vertices original location, then the move record is deleted.

Definition at line 696 of file bmesh_log.cc.

References Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), BMLogEntry::added_verts, BLI_assert, bm_log_vert_alloc(), bm_log_vert_id_get(), Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::contains(), BMLogEntry::deleted_verts, log, Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::lookup(), Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::lookup_try(), BMLogEntry::modified_verts, Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::remove(), and v.

Referenced by BM_log_before_all_removed(), and blender::bke::pbvh::pbvh_bmesh_collapse_edge().

◆ bm_log_vert_values_swap()

void bm_log_vert_values_swap ( BMesh * bm,
BMLog * log,
const blender::Map< uint, BMLogVert *, 0 > & verts )
static

◆ bm_log_verts_restore()

◆ bm_log_verts_unmake()

void bm_log_verts_unmake ( BMesh * bm,
BMLog * log,
const blender::Map< uint, BMLogVert *, 0 > & verts )
static

◆ vert_mask_get()

float vert_mask_get ( BMVert * v,
const int cd_vert_mask_offset )
static

Definition at line 163 of file bmesh_log.cc.

References BM_ELEM_CD_GET_FLOAT, and v.

Referenced by bm_log_vert_bmvert_copy(), and bm_log_vert_values_swap().

◆ vert_mask_set()

void vert_mask_set ( BMVert * v,
const float new_mask,
const int cd_vert_mask_offset )
static

Definition at line 174 of file bmesh_log.cc.

References BM_ELEM_CD_SET_FLOAT, and v.

Referenced by bm_log_vert_values_swap(), and bm_log_verts_restore().