|
Blender V4.3
|
#include <math.h>#include <stdlib.h>#include "MEM_guardedalloc.h"#include "BLI_boxpack_2d.h"#include "BLI_listbase.h"#include "BLI_utildefines.h"#include "BLI_sort.h"#include "BLI_strict_flags.h"Go to the source code of this file.
Classes | |
| struct | BoxVert |
| struct | VertSortContext |
Macros | |
| #define | qsort_r BLI_qsort_r |
| #define | USE_MERGE |
| #define | USE_FREE_STRIP |
| #define | USE_PACK_BIAS |
| #define | EPSILON 0.0000001f |
| #define | EPSILON_MERGE 0.00001f |
| #define | EPSILON_BIAS 0.000001f |
| #define | BLF 1 |
| #define | TRF 2 |
| #define | TLF 4 |
| #define | BRF 8 |
| #define | CORNERFLAGS (BLF | TRF | TLF | BRF) |
| #define | BL 0 |
| #define | TR 1 |
| #define | TL 2 |
| #define | BR 3 |
| #define | A (vert->trb->v[TL]) |
| #define | B (vert->tlb->v[TR]) |
| #define | MASK (BLF | BRF) |
| #define | A (vert->blb->v[BR]) |
| #define | B (vert->brb->v[BL]) |
| #define | MASK (TRF | TLF) |
| #define | A (vert->blb->v[TL]) |
| #define | B (vert->tlb->v[BL]) |
| #define | MASK (TRF | BRF) |
| #define | A (vert->brb->v[TR]) |
| #define | B (vert->trb->v[BR]) |
| #define | MASK (TLF | BLF) |
Typedefs | |
| typedef struct BoxVert | BoxVert |
Functions | |
| BLI_INLINE int | quad_flag (uint q) |
| static float | max_ff (const float a, const float b) |
| static void | vert_bias_update (BoxVert *v) |
| void | BLI_box_pack_2d (BoxPack *boxarray, const uint len, const bool sort_boxes, float *r_tot_x, float *r_tot_y) |
| void | BLI_box_pack_2d_fixedarea (ListBase *boxes, int width, int height, ListBase *packed) |
Box Accessor Functions | |
| static float | box_xmin_get (const BoxPack *box) |
| static float | box_xmax_get (const BoxPack *box) |
| static float | box_ymin_get (const BoxPack *box) |
| static float | box_ymax_get (const BoxPack *box) |
Box Placement | |
| BLI_INLINE void | box_v34x_update (BoxPack *box) |
| BLI_INLINE void | box_v34y_update (BoxPack *box) |
| static void | box_xmin_set (BoxPack *box, const float f) |
| static void | box_xmax_set (BoxPack *box, const float f) |
| static void | box_ymin_set (BoxPack *box, const float f) |
| static void | box_ymax_set (BoxPack *box, const float f) |
Box Utils | |
| static float | box_area (const BoxPack *box) |
| static bool | box_isect (const BoxPack *box_a, const BoxPack *box_b) |
Box/Vert Sorting | |
| static int | box_areasort (const void *p1, const void *p2) |
| static int | vertex_sort (const void *p1, const void *p2, void *vs_ctx_p) |
Referenced by bake_differentials(), BLI_box_pack_2d(), BLI_ewa_filter(), bsdf_hair_huang_eval_trrt(), btDoSimplex2(), btDoSimplex3(), btDoSimplex4(), slim::build_linear_system(), Freestyle::ViewEdgeXBuilder::BuildSmoothFEdge(), Freestyle::GridHelpers::closestPointToSegment(), GivensRotation::columnRotation(), Freestyle::ViewMapBuilder::computeCusps(), Freestyle::ViewMapBuilder::ComputeRayCastingVisibility(), libmv::ComputeTrackingEquation(), Freestyle::crossesProscenium(), dBoxBox2(), Freestyle::GeomUtils::distPointSegment(), libmv::EightPointSolver(), GivensRotation::fill(), btLemkeAlgorithm::findLexicographicMinimum(), Freestyle::ViewMapBuilder::FindOccludee(), Freestyle::findOccludee(), blender::ed::object::followpath_path_animate_exec(), libmv::FundamentalFrom7CorrespondencesLinear(), btLemkeAlgorithm::GaussJordanEliminationStep(), Freestyle::ViewMap::getClosestFEdge(), Freestyle::ViewMap::getClosestViewEdge(), blender::math::interpolate(), Freestyle::GeomUtils::intersect2dSeg2dArea(), libmv::MatrixColumn(), libmv::MatrixColumn(), libmv::MatrixColumn(), libmv::euclidean_resection::MatrixToConstraint(), md5_process_block(), libmv::MeanAndVarianceAlongRows(), libmv::Dogleg< Function, Jacobian, Solver >::minimize(), libmv::LevenbergMarquardt< Function, Jacobian, Solver >::minimize(), newPerlin(), Freestyle::Functions0D::Curvature2DAngleF0D::operator()(), Freestyle::Functions0D::VertexOrientation2DF0D::operator()(), Freestyle::Functions0D::VertexOrientation3DF0D::operator()(), GivensRotation::operator*(), polarDecomposition(), blender::ed::greasepencil::primitive_calulate_curve_positions(), GivensRotation::rowRotation(), libmv::SelectKeyframesBasedOnGRICAndVariance(), SIM_hair_volume_solve_divergence(), singularValueDecomposition(), btLemkeAlgorithm::solve(), solve_least_squares(), libmv::SolveCubicPolynomial(), btLemkeSolver::solveMLCP(), btSolveProjectedGaussSeidel::solveMLCP(), SolveP3(), KDL::svd_eigen_HH(), and Freestyle::StrokeTesselator::Tesselate().
Referenced by BLI_box_pack_2d().
| #define BL 0 |
Definition at line 83 of file boxpack_2d.c.
Referenced by BLI_box_pack_2d(), box_v34x_update(), box_v34y_update(), box_xmax_set(), box_xmin_get(), box_xmin_set(), box_ymax_set(), box_ymin_get(), and box_ymin_set().
| #define BLF 1 |
Definition at line 71 of file boxpack_2d.c.
Referenced by BLI_box_pack_2d().
| #define BR 3 |
Definition at line 86 of file boxpack_2d.c.
Referenced by BKE_idtype_idcode_to_index(), BKE_idtype_idfilter_to_index(), BLI_box_pack_2d(), box_v34x_update(), and box_v34y_update().
| #define BRF 8 |
Definition at line 74 of file boxpack_2d.c.
Referenced by BLI_box_pack_2d().
Definition at line 75 of file boxpack_2d.c.
Referenced by BLI_box_pack_2d().
| #define EPSILON 0.0000001f |
Definition at line 66 of file boxpack_2d.c.
Referenced by box_isect().
| #define EPSILON_BIAS 0.000001f |
Definition at line 69 of file boxpack_2d.c.
Referenced by vert_bias_update().
| #define EPSILON_MERGE 0.00001f |
Definition at line 67 of file boxpack_2d.c.
Referenced by BLI_box_pack_2d().
| #define qsort_r BLI_qsort_r |
Definition at line 19 of file boxpack_2d.c.
Referenced by BLI_box_pack_2d().
| #define TL 2 |
Definition at line 85 of file boxpack_2d.c.
Referenced by BLI_box_pack_2d(), box_v34x_update(), and box_v34y_update().
| #define TLF 4 |
Definition at line 73 of file boxpack_2d.c.
Referenced by BLI_box_pack_2d().
| #define TR 1 |
Definition at line 84 of file boxpack_2d.c.
Referenced by BLI_box_pack_2d(), box_v34x_update(), box_v34y_update(), box_xmax_get(), box_xmax_set(), box_xmin_set(), box_ymax_get(), box_ymax_set(), box_ymin_set(), and bsdf_hair_huang_sample().
| #define TRF 2 |
Definition at line 72 of file boxpack_2d.c.
Referenced by BLI_box_pack_2d().
| #define USE_FREE_STRIP |
Definition at line 30 of file boxpack_2d.c.
| #define USE_MERGE |
Definition at line 28 of file boxpack_2d.c.
| #define USE_PACK_BIAS |
Definition at line 32 of file boxpack_2d.c.
| typedef struct BoxVert BoxVert |
| void BLI_box_pack_2d | ( | BoxPack * | boxarray, |
| unsigned int | len, | ||
| bool | sort_boxes, | ||
| float * | r_tot_x, | ||
| float * | r_tot_y ) |
Main box-packing function accessed from other functions This sets boxes x,y to positive values, sorting from 0,0 outwards. There is no limit to the space boxes may take, only that they will be packed tightly into the lower left hand corner (0,0)
| box_array | a pre-allocated array of boxes. only the 'box->x' and 'box->y' are set, 'box->w' and 'box->h' are used, 'box->index' is not used at all, the only reason its there is that the box array is sorted by area and programs need to be able to have some way of writing the boxes back to the original data. |
| len | the number of boxes in the array. |
| sort_boxes | Sort box_array before packing. |
| r_tot_x,r_tot_y | set so you can normalize the data. |
Definition at line 271 of file boxpack_2d.c.
References A, B, BL, BoxVert::blb, BLF, BLI_assert, box_areasort(), VertSortContext::box_height, box_isect(), VertSortContext::box_width, box_xmax_get(), box_xmax_set(), box_xmin_get(), box_xmin_set(), box_ymax_get(), box_ymax_set(), box_ymin_get(), box_ymin_set(), BR, BoxVert::brb, BRF, CORNERFLAGS, ELEM, EPSILON_MERGE, fabsf, BoxVert::free, BoxPack::h, BoxVert::index, BoxVert::isect_cache, len, max_ff(), MEM_freeN(), MEM_mallocN, NULL, qsort_r, quad_flag(), TL, BoxVert::tlb, TLF, TR, BoxVert::trb, TRF, UNLIKELY, BoxVert::used, BoxPack::v, vert_bias_update(), VertSortContext::vertarray, vertex_sort(), BoxPack::w, BoxVert::x, and BoxVert::y.
Referenced by M_Geometry_box_pack_2d(), and blender::geometry::pack_island_box_pack_2d().
| void BLI_box_pack_2d_fixedarea | ( | struct ListBase * | boxes, |
| int | width, | ||
| int | height, | ||
| struct ListBase * | packed ) |
Packs boxes into a fixed area.
Boxes and packed are linked lists containing structs that can be cast to FixedSizeBoxPack (i.e. contains a FixedSizeBoxPack as its first element). Boxes that were packed successfully are placed into *packed and removed from *boxes.
The algorithm is a simplified version of https://github.com/TeamHypersomnia/rectpack2D. Better ones could be used, but for the current use case (packing Image tiles into GPU textures) this is fine.
Note that packing efficiency depends on the order of the input boxes. Generally speaking, larger boxes should come first, though how exactly size is best defined (e.g. area, perimeter) depends on the particular application.
Definition at line 663 of file boxpack_2d.c.
References BLI_addhead(), BLI_addtail(), BLI_freelistN(), BLI_remlink(), FixedSizeBoxPack::h, LISTBASE_FOREACH, LISTBASE_FOREACH_MUTABLE, MEM_callocN, MEM_freeN(), NULL, FixedSizeBoxPack::w, FixedSizeBoxPack::x, and FixedSizeBoxPack::y.
Referenced by gpu_texture_create_tile_array().
Definition at line 164 of file boxpack_2d.c.
Referenced by box_areasort().
|
static |
Definition at line 204 of file boxpack_2d.c.
References box_area().
Referenced by BLI_box_pack_2d().
Definition at line 169 of file boxpack_2d.c.
References box_xmax_get(), box_xmin_get(), box_ymax_get(), box_ymin_get(), and EPSILON.
Referenced by BLI_box_pack_2d().
| BLI_INLINE void box_v34x_update | ( | BoxPack * | box | ) |
Definition at line 118 of file boxpack_2d.c.
References BL, BR, TL, and TR.
Referenced by box_xmax_set(), and box_xmin_set().
| BLI_INLINE void box_v34y_update | ( | BoxPack * | box | ) |
Definition at line 124 of file boxpack_2d.c.
References BL, BR, TL, and TR.
Referenced by box_ymax_set(), and box_ymin_set().
Definition at line 97 of file boxpack_2d.c.
References TR.
Referenced by BLI_box_pack_2d(), and box_isect().
Definition at line 137 of file boxpack_2d.c.
References BL, box_v34x_update(), and TR.
Referenced by BLI_box_pack_2d().
Definition at line 92 of file boxpack_2d.c.
References BL.
Referenced by BLI_box_pack_2d(), and box_isect().
Definition at line 130 of file boxpack_2d.c.
References BL, box_v34x_update(), and TR.
Referenced by BLI_box_pack_2d().
Definition at line 107 of file boxpack_2d.c.
References TR.
Referenced by BLI_box_pack_2d(), and box_isect().
Definition at line 151 of file boxpack_2d.c.
References BL, box_v34y_update(), and TR.
Referenced by BLI_box_pack_2d().
Definition at line 102 of file boxpack_2d.c.
References BL.
Referenced by BLI_box_pack_2d(), and box_isect().
Definition at line 144 of file boxpack_2d.c.
References BL, box_v34y_update(), and TR.
Referenced by BLI_box_pack_2d().
Definition at line 180 of file boxpack_2d.c.
References b.
Referenced by BLI_box_pack_2d(), and vertex_sort().
| BLI_INLINE int quad_flag | ( | uint | q | ) |
|
static |
Definition at line 187 of file boxpack_2d.c.
References BLI_assert, EPSILON_BIAS, and v.
Referenced by BLI_box_pack_2d().
|
static |
Definition at line 229 of file boxpack_2d.c.
References BoxVert::bias, VertSortContext::box_height, VertSortContext::box_width, BoxVert::free, max_ff(), UNLIKELY, v2, VertSortContext::vertarray, BoxVert::x, and BoxVert::y.
Referenced by BLI_box_pack_2d().