mirror of
https://github.com/microsoft/UVAtlas
synced 2024-11-09 13:50:05 +00:00
More use of constexpr
This commit is contained in:
parent
13a0760265
commit
962b431d2f
@ -13,8 +13,8 @@
|
||||
|
||||
namespace GeodesicDist
|
||||
{
|
||||
const size_t FLAG_INVALID_SIZE_T = size_t(-1); // denote invalid pointer
|
||||
const uint32_t FLAG_INVALIDDWORD = uint32_t(-1); // denote invalid face index, vertex index, edge index
|
||||
constexpr size_t FLAG_INVALID_SIZE_T = size_t(-1); // denote invalid pointer
|
||||
constexpr uint32_t FLAG_INVALIDDWORD = uint32_t(-1); // denote invalid face index, vertex index, edge index
|
||||
|
||||
// used to access the position of each vertex in a mesh
|
||||
struct _vertex
|
||||
|
@ -68,7 +68,7 @@ namespace DirectX
|
||||
UVATLAS_LIMIT_FACE_STRETCH = 0x08,
|
||||
};
|
||||
|
||||
static const float UVATLAS_DEFAULT_CALLBACK_FREQUENCY = 0.0001f;
|
||||
constexpr float UVATLAS_DEFAULT_CALLBACK_FREQUENCY = 0.0001f;
|
||||
|
||||
//============================================================================
|
||||
//
|
||||
|
@ -400,7 +400,7 @@ void CUVAtlasRepacker::ComputeFinalAtlasRect()
|
||||
\***************************************************************************/
|
||||
void CUVAtlasRepacker::InitialSpacePercent()
|
||||
{
|
||||
const float AdjustFactor = 1.01f;
|
||||
constexpr float AdjustFactor = 1.01f;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
|
@ -16,20 +16,20 @@ namespace IsochartRepacker
|
||||
{
|
||||
|
||||
// Represent the four sides of chart or UV atlas
|
||||
const int UV_UPSIDE = 0;
|
||||
const int UV_RIGHTSIDE = 1;
|
||||
const int UV_DOWNSIDE = 2;
|
||||
const int UV_LEFTSIDE = 3;
|
||||
constexpr int UV_UPSIDE = 0;
|
||||
constexpr int UV_RIGHTSIDE = 1;
|
||||
constexpr int UV_DOWNSIDE = 2;
|
||||
constexpr int UV_LEFTSIDE = 3;
|
||||
|
||||
const size_t CHART_THRESHOLD = 30;
|
||||
const size_t MAX_ITERATION = 200;
|
||||
constexpr size_t CHART_THRESHOLD = 30;
|
||||
constexpr size_t MAX_ITERATION = 200;
|
||||
|
||||
// the size of input vertex buffer unit
|
||||
const size_t VertexSize = 20;
|
||||
constexpr size_t VertexSize = 20;
|
||||
|
||||
// specify the initial size of the atlas is 3*3 times larger
|
||||
// than the user defined atlas
|
||||
const int INITIAL_SIZE_FACTOR = 2;
|
||||
constexpr int INITIAL_SIZE_FACTOR = 2;
|
||||
|
||||
// convert the index buffer into this structure for convenience
|
||||
// use template to handle 16-bit index and 32-bit index
|
||||
|
@ -16,7 +16,7 @@ using namespace DirectX;
|
||||
|
||||
namespace
|
||||
{
|
||||
const size_t BC_MAX_ITERATION = 10000;
|
||||
constexpr size_t BC_MAX_ITERATION = 10000;
|
||||
|
||||
class CBoundaryIter
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ using namespace Isochart;
|
||||
namespace
|
||||
{
|
||||
// Scale original model into the cubic with ISOCHART_MODELSCALE edge length. 500 is a experiential value
|
||||
const float ISOCHART_MODELSCALE = 500.0f;
|
||||
constexpr float ISOCHART_MODELSCALE = 500.0f;
|
||||
}
|
||||
|
||||
CBaseMeshInfo::CBaseMeshInfo() :
|
||||
|
@ -19,13 +19,13 @@ namespace Isochart
|
||||
#define MERGE_TURN_ON_LSCM 0// Turn on LSCM during merge
|
||||
|
||||
//Perform LSCM only when the input stretch is larger than the criteria
|
||||
const float SMALL_STRETCH_TO_TURNON_LSCM = 0.95f;
|
||||
constexpr float SMALL_STRETCH_TO_TURNON_LSCM = 0.95f;
|
||||
|
||||
#define PARAM_TURN_ON_BARYCENTRIC 1 // Turn on barycenteric method during partition
|
||||
#define MERGE_TURN_ON_BARYCENTRIC 1 // Turn on barycenteric method during merge
|
||||
|
||||
//Perform Barycentric method only when the input stretch is larger than the criteria
|
||||
const float SMALL_STRETCH_TO_TURNON_BARY = 0.95f;
|
||||
constexpr float SMALL_STRETCH_TO_TURNON_BARY = 0.95f;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//////////////////ISOMAP Configuration////////////////////////////////
|
||||
@ -37,11 +37,11 @@ namespace Isochart
|
||||
// More vertices left caused more accurate parameterization, but
|
||||
// also more time cost.
|
||||
// 80 is based on examination of Kun
|
||||
const size_t MIN_PM_VERT_NUMBER = 85;
|
||||
constexpr size_t MIN_PM_VERT_NUMBER = 85;
|
||||
|
||||
// A mesh must use at least MIN_LANDMARK_NUMBER vertices to apply
|
||||
// isomap algorithm.
|
||||
const size_t MIN_LANDMARK_NUMBER = 25;
|
||||
constexpr size_t MIN_LANDMARK_NUMBER = 25;
|
||||
|
||||
// 1 means:
|
||||
// Using the combination of signal and geodesic distance to apply isomap.
|
||||
@ -64,9 +64,9 @@ namespace Isochart
|
||||
#define PIECEWISE_CONSTANT_IMT 1
|
||||
|
||||
#if PIECEWISE_CONSTANT_IMT
|
||||
const size_t IMT_DIM = 3; // Piecewise constant imt
|
||||
constexpr size_t IMT_DIM = 3; // Piecewise constant imt
|
||||
#else
|
||||
const size_t IMT_DIM = 6; // Piecewise linear imt
|
||||
constexpr size_t IMT_DIM = 6; // Piecewise linear imt
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -84,7 +84,7 @@ namespace Isochart
|
||||
// Don't check overlapping
|
||||
#define CHECK_OVER_LAPPING_BEFORE_OPT_INFINIT 1
|
||||
|
||||
const float INFINITE_STRETCH = FLT_MAX;
|
||||
constexpr float INFINITE_STRETCH = FLT_MAX;
|
||||
|
||||
// 1 means :
|
||||
// Using dihedral angel as criterion to optimize boundary when paritition.
|
||||
@ -94,7 +94,7 @@ namespace Isochart
|
||||
|
||||
// When optimize chart by signal, just amplify the geometric stretch criteria
|
||||
// to give more freedom when moving vertices
|
||||
const float POW_OF_IMT_GEO_L2_STRETCH = 0.2f;
|
||||
constexpr float POW_OF_IMT_GEO_L2_STRETCH = 0.2f;
|
||||
|
||||
// 1 means :
|
||||
// If current chart has been optimized, don't optimize it any more until it is paritioned again.
|
||||
@ -104,46 +104,46 @@ namespace Isochart
|
||||
|
||||
// This parameter is used to control the signal stretch optimization. If we don't want to get
|
||||
// too large triangles, just set this parameter to a value in the range of 0 to 1.
|
||||
const float FACE_MIN_L2_STRETCH = 0.0f;
|
||||
constexpr float FACE_MIN_L2_STRETCH = 0.0f;
|
||||
|
||||
//Using the optimal scaling method given by John Synder can generate too large or too small
|
||||
//charts, the too large charts will waste large space, too small charts can easily give trouble
|
||||
// to mip map.
|
||||
const float OPTIMAL_SCALE_FACTOR = 2.5f;
|
||||
constexpr float OPTIMAL_SCALE_FACTOR = 2.5f;
|
||||
|
||||
// Optimize L^n Stretch
|
||||
const size_t INFINITE_VERTICES_OPTIMIZE_COUNT = 12; //Times to optimize all infinite vertices
|
||||
const size_t RAND_OPTIMIZE_INFINIT_COUNT = 12; // Times to randomly optimize one vertex
|
||||
constexpr size_t INFINITE_VERTICES_OPTIMIZE_COUNT = 12; //Times to optimize all infinite vertices
|
||||
constexpr size_t RAND_OPTIMIZE_INFINIT_COUNT = 12; // Times to randomly optimize one vertex
|
||||
|
||||
// Optimize signal L^2 Stretch
|
||||
const size_t L2_PREV_OPTIMIZESIG_COUNT = 6; //Times to optimize all vertices before optimize whole charts.
|
||||
const size_t L2_POST_OPTIMIZESIG_COUNT = 4; //Times to optimize all vertices after optimize who charts
|
||||
const size_t RAND_OPTIMIZE_L2_COUNT = 9;
|
||||
constexpr size_t L2_PREV_OPTIMIZESIG_COUNT = 6; //Times to optimize all vertices before optimize whole charts.
|
||||
constexpr size_t L2_POST_OPTIMIZESIG_COUNT = 4; //Times to optimize all vertices after optimize who charts
|
||||
constexpr size_t RAND_OPTIMIZE_L2_COUNT = 9;
|
||||
|
||||
// Optimize geometric L^2 stretch. For the boundary vertices, using L^n stretch optimization
|
||||
// to replace L^2 stretch
|
||||
const size_t L2_OPTIMIZE_COUNT = 7;
|
||||
const size_t LN_OPTIMIZE_COUNT = 2;
|
||||
const size_t RAND_OPTIMIZE_LN_COUNT = 9;
|
||||
const float STRETCH_TO_STOP_LN_OPTIMIZE = 2.0f;
|
||||
constexpr size_t L2_OPTIMIZE_COUNT = 7;
|
||||
constexpr size_t LN_OPTIMIZE_COUNT = 2;
|
||||
constexpr size_t RAND_OPTIMIZE_LN_COUNT = 9;
|
||||
constexpr float STRETCH_TO_STOP_LN_OPTIMIZE = 2.0f;
|
||||
|
||||
// When performing affine transformation to a face or a chart to decrease their signal stretch,
|
||||
// using these paramters to avoid to much geometric distoration.
|
||||
const float FACE_MAX_SCALE_FACTOR = 2.0f;
|
||||
const float CHART_MAX_SCALE_FACTOR = 2.0f;
|
||||
constexpr float FACE_MAX_SCALE_FACTOR = 2.0f;
|
||||
constexpr float CHART_MAX_SCALE_FACTOR = 2.0f;
|
||||
|
||||
// How many overturn vertices are acceptable. Now we just don't want any overturn faces. After
|
||||
// parameterization
|
||||
const float Overturn_TOLERANCE = 0.0f;
|
||||
constexpr float Overturn_TOLERANCE = 0.0f;
|
||||
|
||||
// Chart must large than some criterion, this parameter used to avoid too small charts.
|
||||
const float SMALLEST_CHART_PIXEL_AREA = 100.0f / (512 * 512);
|
||||
constexpr float SMALLEST_CHART_PIXEL_AREA = 100.0f / (512 * 512);
|
||||
////////////////////////////////////////////////////////////////////
|
||||
////////////////Merage Charts Configuration////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
const float MAX_MERGE_RATIO = 0.7f;
|
||||
const float MAX_MERGE_FACE_NUMBER = 700;
|
||||
constexpr float MAX_MERGE_RATIO = 0.7f;
|
||||
constexpr float MAX_MERGE_FACE_NUMBER = 700;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
////////////////Packing Charts Configuration////////////////////////////
|
||||
@ -153,6 +153,6 @@ namespace Isochart
|
||||
// parameter as an estimate value. Then we can compute the length of pixel in uvatlas.
|
||||
|
||||
// Larger value will generate larger pixel size. After experiment, 0.5 is a good estimation.
|
||||
const float STANDARD_SPACE_RATE = 0.5f;
|
||||
constexpr float STANDARD_SPACE_RATE = 0.5f;
|
||||
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ namespace
|
||||
/////////// Configuration of internal stretch /////////////
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
const float ISOCHART_MAX_STRETCH_RATIO = FLT_MAX; // 1e8f;
|
||||
constexpr float ISOCHART_MAX_STRETCH_RATIO = FLT_MAX; // 1e8f;
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
/////////// Configuration of applying isomap///////////////
|
||||
@ -71,16 +71,16 @@ namespace
|
||||
// The eigen values and vectors need to compute, when
|
||||
// processing the sub-charts which have been partitioned
|
||||
// before.
|
||||
const size_t SUB_CHART_EIGEN_DIMENSION = 4;
|
||||
constexpr size_t SUB_CHART_EIGEN_DIMENSION = 4;
|
||||
|
||||
// Using to ignore the eigen vectors whose eigen value are too small.
|
||||
// Only cosider the larger eigen values which consume 90%
|
||||
// percent of all energy presenting by sum of all eigen values.
|
||||
const float PRIMARY_EIGEN_ENERGY_PERCENT = 0.90f;
|
||||
constexpr float PRIMARY_EIGEN_ENERGY_PERCENT = 0.90f;
|
||||
|
||||
// To check if current chart is a special-shape, each vertex must has
|
||||
// a 3 dimension vector.
|
||||
const size_t DIMENSION_TO_CHECK_SPECIAL_SHAPE = 3;
|
||||
constexpr size_t DIMENSION_TO_CHECK_SPECIAL_SHAPE = 3;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
@ -23,17 +23,17 @@
|
||||
namespace Isochart
|
||||
{
|
||||
|
||||
const uint32_t INVALID_FACE_ID = 0xffffffff; // INVALID FACE ID
|
||||
const uint32_t INVALID_VERT_ID = 0xffffffff; // INVALID VERTEX ID
|
||||
const uint32_t INVALID_INDEX = 0xffffffff; // INVALID_INDEX
|
||||
constexpr uint32_t INVALID_FACE_ID = 0xffffffff; // INVALID FACE ID
|
||||
constexpr uint32_t INVALID_VERT_ID = 0xffffffff; // INVALID VERTEX ID
|
||||
constexpr uint32_t INVALID_INDEX = 0xffffffff; // INVALID_INDEX
|
||||
|
||||
// Vertex with MUST_RESERVE importance order must be reserved.
|
||||
const int MUST_RESERVE = -1;
|
||||
constexpr int MUST_RESERVE = -1;
|
||||
|
||||
// The eigen values and vectors need to compute when
|
||||
// processing the original charts which haven't been partitioned
|
||||
// before.
|
||||
const size_t ORIGINAL_CHART_EIGEN_DIMENSION = 10;
|
||||
constexpr size_t ORIGINAL_CHART_EIGEN_DIMENSION = 10;
|
||||
|
||||
inline bool isInArray(const std::vector<uint32_t>& v, uint32_t item)
|
||||
{
|
||||
|
@ -18,8 +18,8 @@ namespace Isochart
|
||||
{
|
||||
// values between ISOCHART_ZERO_EPS and -ISOCHART_ZERO_EPS
|
||||
// will be regarded as zero
|
||||
const float ISOCHART_ZERO_EPS = 1e-6f;
|
||||
const float ISOCHART_ZERO_EPS2 = 1e-12f;
|
||||
constexpr float ISOCHART_ZERO_EPS = 1e-6f;
|
||||
constexpr float ISOCHART_ZERO_EPS2 = 1e-12f;
|
||||
|
||||
// Check if to segments intersect together.
|
||||
bool IsochartIsSegmentsIntersect(
|
||||
|
@ -19,7 +19,7 @@ using namespace DirectX;
|
||||
|
||||
namespace
|
||||
{
|
||||
const size_t LSCM_MAX_ITERATION = 10000;
|
||||
constexpr size_t LSCM_MAX_ITERATION = 10000;
|
||||
enum EQUATION_POSITION
|
||||
{
|
||||
IN_COEFFICIENT,
|
||||
|
@ -16,7 +16,7 @@ using namespace DirectX;
|
||||
|
||||
namespace
|
||||
{
|
||||
const size_t MAX_FACE_NUMBER = 0xfffffffe;
|
||||
constexpr size_t MAX_FACE_NUMBER = 0xfffffffe;
|
||||
};
|
||||
|
||||
|
||||
|
@ -28,10 +28,10 @@ using namespace DirectX;
|
||||
namespace
|
||||
{
|
||||
// face number limit, below this limit, new geodesic algorithm is used, otherwise the old KS98 is used
|
||||
const size_t LIMIT_FACENUM_USENEWGEODIST = _LIMIT_FACENUM_USENEWGEODIST;
|
||||
constexpr size_t LIMIT_FACENUM_USENEWGEODIST = _LIMIT_FACENUM_USENEWGEODIST;
|
||||
|
||||
// Used to combine geodesic and signal distance. See [Kun04], 6 section.
|
||||
const float SIGNAL_DISTANCE_WEIGHT = 0.30f;
|
||||
constexpr float SIGNAL_DISTANCE_WEIGHT = 0.30f;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
@ -34,12 +34,12 @@ namespace
|
||||
{
|
||||
// Define the percent of faces in chart that are need to
|
||||
// re-decide chart ID by graph cut.
|
||||
const float FUZYY_REGION_PERCENT = 0.30f;
|
||||
constexpr float FUZYY_REGION_PERCENT = 0.30f;
|
||||
|
||||
// Graph cut optimize consider two factors: stretch and angle
|
||||
// OPTIMAL_CUT_STRETCH_WEIGHT indicates stretch factor, then
|
||||
// angle factor will be 1-OPTIMAL_CUT_STRETCH_WEIGHT
|
||||
const float OPTIMAL_CUT_STRETCH_WEIGHT = 0.35f;
|
||||
constexpr float OPTIMAL_CUT_STRETCH_WEIGHT = 0.35f;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
@ -138,20 +138,20 @@ namespace
|
||||
|
||||
// When vertex being optimized, if the distance between new and old
|
||||
// positions less than OPTIMIZE_TOLERANCE, stop optimize
|
||||
const float OPTIMIZE_TOLERANCE = 1e-4f;
|
||||
constexpr float OPTIMIZE_TOLERANCE = 1e-4f;
|
||||
|
||||
// If the max stretch changes less than MINIMAL_OPTIMIZE_CHANGE, stop optimize.
|
||||
// Because more optimization won't improve result.
|
||||
const float MINIMAL_OPTIMIZE_CHANGE = 0.01f;
|
||||
constexpr float MINIMAL_OPTIMIZE_CHANGE = 0.01f;
|
||||
|
||||
// When moving vertex within its 1-ring neighbor range. A max moving distance
|
||||
// should be computed to avoid overlapping. After computing the max distance,
|
||||
// scale it with CONSERVATIVE_OPTIMIZE_FACTOR to make sure the vertex is not too
|
||||
// close to other edges.
|
||||
const float CONSERVATIVE_OPTIMIZE_FACTOR = 0.80f;
|
||||
constexpr float CONSERVATIVE_OPTIMIZE_FACTOR = 0.80f;
|
||||
|
||||
// Direction: left, right, top, bottom
|
||||
const size_t BOUND_DIRECTION_NUMBER = 4;
|
||||
constexpr size_t BOUND_DIRECTION_NUMBER = 4;
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,20 +88,20 @@ namespace
|
||||
// E.g. CHART_ROTATION_NUMBER = 6 means the chart will choose the best pose
|
||||
// from rotation of 0, 60, 120, 180, 240, 300 degrees.
|
||||
|
||||
const size_t CHART_ROTATION_NUMBER = 4;
|
||||
constexpr size_t CHART_ROTATION_NUMBER = 4;
|
||||
|
||||
// The algorithm moves charts along the tangent direction of atlas borders searching the
|
||||
// best position to add new chart. The searching step can be controled by 2 ways:
|
||||
//.SEARCH_STEP_LENGTH = 2 means moving 2 pixels each step.
|
||||
//.SEARCH_STEP_COUNT = 120 means at most searching 120 steps.
|
||||
// Using CONTROL_SEARCH_BY_STEP_COUNT to swich between these 2 ways.
|
||||
const size_t SEARCH_STEP_LENGTH = 2;
|
||||
const size_t SEARCH_STEP_COUNT = 120;
|
||||
constexpr size_t SEARCH_STEP_LENGTH = 2;
|
||||
constexpr size_t SEARCH_STEP_COUNT = 120;
|
||||
|
||||
//Based on experiment, when gutter = 2, Width = 512, Height = 512, the space rate of
|
||||
// finial UV-atlas.
|
||||
const float STANDARD_UV_SIZE = 512;
|
||||
const float STANDARD_GUTTER = 2;
|
||||
constexpr float STANDARD_UV_SIZE = 512;
|
||||
constexpr float STANDARD_GUTTER = 2;
|
||||
|
||||
// Tables for precomputed triangle values.
|
||||
float g_PackingCosTable[CHART_ROTATION_NUMBER];
|
||||
@ -3452,7 +3452,7 @@ void CIsochartMesh::OptimizeAtlasSignalStretch(
|
||||
return;
|
||||
}
|
||||
|
||||
const float ShiftError = 1e-4f;
|
||||
constexpr float ShiftError = 1e-4f;
|
||||
|
||||
float fTotal2DArea = 0;
|
||||
float fTotal = 0;
|
||||
|
@ -29,7 +29,7 @@ namespace
|
||||
// MAX_PM_ERROR, just stop simplify mesh. Otherwise, some important
|
||||
// geodesic information may be lost. 0.9 is based on examination of
|
||||
// Kun
|
||||
const float MAX_PM_ERROR = 0.90f;
|
||||
constexpr float MAX_PM_ERROR = 0.90f;
|
||||
|
||||
void IsochartVec3Substract(
|
||||
XMFLOAT3* pOut,
|
||||
|
@ -17,7 +17,7 @@ namespace Isochart
|
||||
MANUAL,
|
||||
};
|
||||
|
||||
const size_t NOT_IN_HEAP = 0xffffffff;
|
||||
constexpr size_t NOT_IN_HEAP = 0xffffffff;
|
||||
typedef size_t pos_type;
|
||||
|
||||
template <class Ty1, class Ty2>
|
||||
|
Loading…
Reference in New Issue
Block a user