Blender  V3.3
Classes | Macros | Typedefs | Functions
bmesh_beautify.c File Reference
#include "BLI_heap.h"
#include "BLI_math.h"
#include "BLI_polyfill_2d_beautify.h"
#include "MEM_guardedalloc.h"
#include "bmesh.h"
#include "bmesh_beautify.h"

Go to the source code of this file.

Classes

struct  EdRotState
 

Macros

#define EDGE_ORD(v0, v1)
 

Typedefs

typedef struct EdRotState EdRotState
 

Functions

static GSeterot_gset_new (void)
 
static void erot_state_ex (const BMEdge *e, int v_index[2], int f_index[2])
 
static void erot_state_current (const BMEdge *e, EdRotState *e_state)
 
static void erot_state_alternate (const BMEdge *e, EdRotState *e_state)
 
static float bm_edge_calc_rotate_beauty__area (const float v1[3], const float v2[3], const float v3[3], const float v4[3], const bool lock_degenerate)
 
static float bm_edge_calc_rotate_beauty__angle (const float v1[3], const float v2[3], const float v3[3], const float v4[3])
 
float BM_verts_calc_rotate_beauty (const BMVert *v1, const BMVert *v2, const BMVert *v3, const BMVert *v4, const short flag, const short method)
 
static float bm_edge_calc_rotate_beauty (const BMEdge *e, const short flag, const short method)
 
BLI_INLINE bool edge_in_array (const BMEdge *e, const BMEdge **edge_array, const int edge_array_len)
 
static void bm_edge_update_beauty_cost_single (BMEdge *e, Heap *eheap, HeapNode **eheap_table, GSet **edge_state_arr, const BMEdge **edge_array, const int edge_array_len, const short flag, const short method)
 
static void bm_edge_update_beauty_cost (BMEdge *e, Heap *eheap, HeapNode **eheap_table, GSet **edge_state_arr, const BMEdge **edge_array, const int edge_array_len, const short flag, const short method)
 
void BM_mesh_beautify_fill (BMesh *bm, BMEdge **edge_array, const int edge_array_len, const short flag, const short method, const short oflag_edge, const short oflag_face)
 

Detailed Description

Beautify the mesh by rotating edges between triangles to more attractive positions until no more rotations can be made.

In principle this is very simple however there is the possibility of going into an eternal loop where edges keep rotating. To avoid this - each edge stores a set of it previous states so as not to rotate back.

TODO

Definition in file bmesh_beautify.c.

Macro Definition Documentation

◆ EDGE_ORD

#define EDGE_ORD (   v0,
  v1 
)
Value:
if (v0 > v1) { \
SWAP(int, v0, v1); \
} \
(void)0
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
SyclQueue void void size_t num_bytes void

Definition at line 97 of file bmesh_beautify.c.

Typedef Documentation

◆ EdRotState

typedef struct EdRotState EdRotState

Function Documentation

◆ bm_edge_calc_rotate_beauty()

static float bm_edge_calc_rotate_beauty ( const BMEdge e,
const short  flag,
const short  method 
)
static

Definition at line 264 of file bmesh_beautify.c.

References BM_verts_calc_rotate_beauty(), e, v1, and v2.

Referenced by bm_edge_update_beauty_cost_single(), and BM_mesh_beautify_fill().

◆ bm_edge_calc_rotate_beauty__angle()

static float bm_edge_calc_rotate_beauty__angle ( const float  v1[3],
const float  v2[3],
const float  v3[3],
const float  v4[3] 
)
static

Definition at line 203 of file bmesh_beautify.c.

References angle_normalized_v3v3(), normal_tri_v3(), v1, and v2.

Referenced by BM_verts_calc_rotate_beauty().

◆ bm_edge_calc_rotate_beauty__area()

static float bm_edge_calc_rotate_beauty__area ( const float  v1[3],
const float  v2[3],
const float  v3[3],
const float  v4[3],
const bool  lock_degenerate 
)
static

Check if input faces are already flipped. Logic for 'signum_i' addition is:

Accept:

  • (1, 1) or (-1, -1): same side (common case).
  • (-1/1, 0): one degenerate, OK since we may rotate into a valid state.

Ignore:

  • (-1, 1): opposite winding, ignore.
  • ( 0, 0): both degenerate, ignore.
Note
The cross product is divided by 'no_scale' so the rotation calculation is scale independent.

Important to lock degenerate here, since the triangle pars will be projected into different 2D spaces. Allowing to rotate out of a degenerate state can flip the faces (when performed iteratively).

Definition at line 134 of file bmesh_beautify.c.

References add_v3_v3v3(), axis_dominant_v3_to_m3(), BLI_assert, BLI_polyfill_beautify_quad_rotate_calc_ex(), cross_tri_v2(), cross_tri_v3(), e, ELEM, eps, mul_v2_m3v3(), normalize_v3(), NULL, signum_i_ex(), UNLIKELY, v1, and v2.

Referenced by BM_verts_calc_rotate_beauty().

◆ bm_edge_update_beauty_cost()

static void bm_edge_update_beauty_cost ( BMEdge e,
Heap eheap,
HeapNode **  eheap_table,
GSet **  edge_state_arr,
const BMEdge **  edge_array,
const int  edge_array_len,
const short  flag,
const short  method 
)
static

◆ bm_edge_update_beauty_cost_single()

static void bm_edge_update_beauty_cost_single ( BMEdge e,
Heap eheap,
HeapNode **  eheap_table,
GSet **  edge_state_arr,
const BMEdge **  edge_array,
const int  edge_array_len,
const short  flag,
const short  method 
)
static

◆ BM_mesh_beautify_fill()

void BM_mesh_beautify_fill ( BMesh bm,
BMEdge **  edge_array,
int  edge_array_len,
short  flag,
short  method,
short  oflag_edge,
short  oflag_face 
)

◆ BM_verts_calc_rotate_beauty()

float BM_verts_calc_rotate_beauty ( const BMVert v1,
const BMVert v2,
const BMVert v3,
const BMVert v4,
short  flag,
short  method 
)

Assuming we have 2 triangles sharing an edge (2 - 4), check if the edge running from (1 - 3) gives better results.

Returns
(negative number means the edge can be rotated, lager == better).

Definition at line 231 of file bmesh_beautify.c.

References bm_edge_calc_rotate_beauty__angle(), bm_edge_calc_rotate_beauty__area(), BM_elem_flag_test, BM_ELEM_TAG, BMVert::co, EDGE_RESTRICT_DEGENERATE, UNLIKELY, v1, v2, and VERT_RESTRICT_TAG.

Referenced by bm_edge_calc_rotate_beauty(), BM_face_triangulate(), and bmesh_calc_tessellation_for_face_beauty().

◆ edge_in_array()

BLI_INLINE bool edge_in_array ( const BMEdge e,
const BMEdge **  edge_array,
const int  edge_array_len 
)

Definition at line 278 of file bmesh_beautify.c.

References BM_elem_index_get, and e.

Referenced by bm_edge_update_beauty_cost_single().

◆ erot_gset_new()

static GSet* erot_gset_new ( void  )
static

◆ erot_state_alternate()

static void erot_state_alternate ( const BMEdge e,
EdRotState e_state 
)
static

◆ erot_state_current()

static void erot_state_current ( const BMEdge e,
EdRotState e_state 
)
static

Definition at line 121 of file bmesh_beautify.c.

References e, erot_state_ex(), EdRotState::f_pair, and EdRotState::v_pair.

Referenced by BM_mesh_beautify_fill().

◆ erot_state_ex()

static void erot_state_ex ( const BMEdge e,
int  v_index[2],
int  f_index[2] 
)
static