Cleanup: use braces in headers

This commit is contained in:
Campbell Barton 2023-09-24 14:52:38 +10:00
parent d1d570d318
commit 2721b937fb
63 changed files with 605 additions and 308 deletions

@ -222,10 +222,12 @@ struct ObjectKey {
ObjectKey(void *parent_, int id_[OBJECT_PERSISTENT_ID_SIZE], void *ob_, bool use_particle_hair_)
: parent(parent_), ob(ob_), use_particle_hair(use_particle_hair_)
{
if (id_)
if (id_) {
memcpy(id, id_, sizeof(id));
else
}
else {
memset(id, 0, sizeof(id));
}
}
bool operator<(const ObjectKey &k) const
@ -285,19 +287,23 @@ struct ParticleSystemKey {
ParticleSystemKey(void *ob_, int id_[OBJECT_PERSISTENT_ID_SIZE]) : ob(ob_)
{
if (id_)
if (id_) {
memcpy(id, id_, sizeof(id));
else
}
else {
memset(id, 0, sizeof(id));
}
}
bool operator<(const ParticleSystemKey &k) const
{
/* first id is particle index, we don't compare that */
if (ob < k.ob)
if (ob < k.ob) {
return true;
else if (ob == k.ob)
}
else if (ob == k.ob) {
return memcmp(id + 1, k.id + 1, sizeof(int) * (OBJECT_PERSISTENT_ID_SIZE - 1)) < 0;
}
return false;
}

@ -478,8 +478,9 @@ static inline string get_string(PointerRNA &ptr, const char *name)
char cstrbuf[1024];
char *cstr = RNA_string_get_alloc(&ptr, name, cstrbuf, sizeof(cstrbuf), NULL);
string str(cstr);
if (cstr != cstrbuf)
if (cstr != cstrbuf) {
MEM_freeN(cstr);
}
return str;
}
@ -500,8 +501,9 @@ static inline string blender_absolute_path(BL::BlendData &b_data, BL::ID &b_id,
BL::ID b_library_id(b_id.library());
dirname = blender_absolute_path(b_data, b_library_id, b_id.library().filepath());
}
else
else {
dirname = b_data.filepath();
}
return path_join(path_dirname(dirname), path.substr(2));
}
@ -534,12 +536,15 @@ static inline void mesh_texture_space(const ::Mesh &b_mesh, float3 &loc, float3
loc = make_float3(texspace_location[0], texspace_location[1], texspace_location[2]);
size = make_float3(texspace_size[0], texspace_size[1], texspace_size[2]);
if (size.x != 0.0f)
if (size.x != 0.0f) {
size.x = 0.5f / size.x;
if (size.y != 0.0f)
}
if (size.y != 0.0f) {
size.y = 0.5f / size.y;
if (size.z != 0.0f)
}
if (size.z != 0.0f) {
size.z = 0.5f / size.z;
}
loc = loc * size - make_float3(0.5f, 0.5f, 0.5f);
}

@ -151,8 +151,9 @@ ccl_device_noinline bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals kg,
prim_addr))
{
/* shadow ray early termination */
if (visibility & PATH_RAY_SHADOW_OPAQUE)
if (visibility & PATH_RAY_SHADOW_OPAQUE) {
return true;
}
}
break;
}

@ -13,8 +13,9 @@ ccl_device ccl_private ShaderClosure *closure_alloc(ccl_private ShaderData *sd,
{
kernel_assert(size <= sizeof(ShaderClosure));
if (sd->num_closure_left == 0)
if (sd->num_closure_left == 0) {
return NULL;
}
ccl_private ShaderClosure *sc = &sd->closure[sd->num_closure];

@ -33,12 +33,15 @@ ccl_device float bsdf_toon_get_intensity(float max_angle, float smooth, float an
{
float is;
if (angle < max_angle)
if (angle < max_angle) {
is = 1.0f;
else if (angle < (max_angle + smooth) && smooth != 0.0f)
}
else if (angle < (max_angle + smooth) && smooth != 0.0f) {
is = (1.0f - (angle - max_angle) / smooth);
else
}
else {
is = 0.0f;
}
return is;
}

@ -15,8 +15,9 @@ template<typename T> ccl_device_forceinline T tex_fetch(const TextureInfo &info,
ccl_device_inline int svm_image_texture_wrap_periodic(int x, int width)
{
x %= width;
if (x < 0)
if (x < 0) {
x += width;
}
return x;
}
@ -28,8 +29,9 @@ ccl_device_inline int svm_image_texture_wrap_clamp(int x, int width)
ccl_device_inline int svm_image_texture_wrap_mirror(int x, int width)
{
const int m = abs(x + (x < 0)) % (2 * width);
if (m >= width)
if (m >= width) {
return 2 * width - m - 1;
}
return m;
}

@ -37,8 +37,9 @@ ccl_device_inline void motion_triangle_verts_for_step(KernelGlobals kg,
}
else {
/* center step not store in this array */
if (step > numsteps)
if (step > numsteps) {
step--;
}
offset += step * numverts;
@ -64,8 +65,9 @@ ccl_device_inline void motion_triangle_normals_for_step(KernelGlobals kg,
}
else {
/* center step is not stored in this array */
if (step > numsteps)
if (step > numsteps) {
step--;
}
offset += step * numverts;

@ -282,19 +282,23 @@ ccl_device float patch_eval_float(KernelGlobals kg,
kg, sd->object, patch, u, v, channel, indices, weights, weights_du, weights_dv);
float val = 0.0f;
if (du)
if (du) {
*du = 0.0f;
if (dv)
}
if (dv) {
*dv = 0.0f;
}
for (int i = 0; i < num_control; i++) {
float v = kernel_data_fetch(attributes_float, offset + indices[i]);
val += v * weights[i];
if (du)
if (du) {
*du += v * weights_du[i];
if (dv)
}
if (dv) {
*dv += v * weights_dv[i];
}
}
return val;
@ -328,10 +332,12 @@ ccl_device float2 patch_eval_float2(KernelGlobals kg,
float2 v = kernel_data_fetch(attributes_float2, offset + indices[i]);
val += v * weights[i];
if (du)
if (du) {
*du += v * weights_du[i];
if (dv)
}
if (dv) {
*dv += v * weights_dv[i];
}
}
return val;
@ -356,19 +362,23 @@ ccl_device float3 patch_eval_float3(KernelGlobals kg,
kg, sd->object, patch, u, v, channel, indices, weights, weights_du, weights_dv);
float3 val = make_float3(0.0f, 0.0f, 0.0f);
if (du)
if (du) {
*du = make_float3(0.0f, 0.0f, 0.0f);
if (dv)
}
if (dv) {
*dv = make_float3(0.0f, 0.0f, 0.0f);
}
for (int i = 0; i < num_control; i++) {
float3 v = kernel_data_fetch(attributes_float3, offset + indices[i]);
val += v * weights[i];
if (du)
if (du) {
*du += v * weights_du[i];
if (dv)
}
if (dv) {
*dv += v * weights_dv[i];
}
}
return val;
@ -402,10 +412,12 @@ ccl_device float4 patch_eval_float4(KernelGlobals kg,
float4 v = kernel_data_fetch(attributes_float4, offset + indices[i]);
val += v * weights[i];
if (du)
if (du) {
*du += v * weights_du[i];
if (dv)
}
if (dv) {
*dv += v * weights_dv[i];
}
}
return val;
@ -440,10 +452,12 @@ ccl_device float4 patch_eval_uchar4(KernelGlobals kg,
color_uchar4_to_float4(kernel_data_fetch(attributes_uchar4, offset + indices[i])));
val += v * weights[i];
if (du)
if (du) {
*du += v * weights_du[i];
if (dv)
}
if (dv) {
*dv += v * weights_dv[i];
}
}
return val;

@ -400,10 +400,12 @@ ccl_device void integrator_intersect_closest(KernelGlobals kg,
bool has_receiver_ancestor = INTEGRATOR_STATE(state, path, mnee) & PATH_MNEE_RECEIVER_ANCESTOR;
INTEGRATOR_STATE_WRITE(state, path, mnee) &= ~PATH_MNEE_CULL_LIGHT_CONNECTION;
if (from_caustic_caster && has_receiver_ancestor)
if (from_caustic_caster && has_receiver_ancestor) {
INTEGRATOR_STATE_WRITE(state, path, mnee) |= PATH_MNEE_CULL_LIGHT_CONNECTION;
if (from_caustic_receiver)
}
if (from_caustic_receiver) {
INTEGRATOR_STATE_WRITE(state, path, mnee) |= PATH_MNEE_RECEIVER_ANCESTOR;
}
}
#endif /* __MNEE__ */

@ -236,8 +236,9 @@ ccl_device void volume_shadow_heterogeneous(KernelGlobals kg,
tp = *throughput * exp(sum);
/* stop if nearly all light is blocked */
if (reduce_max(tp) < VOLUME_THROUGHPUT_EPSILON)
if (reduce_max(tp) < VOLUME_THROUGHPUT_EPSILON) {
break;
}
}
}
@ -396,8 +397,9 @@ ccl_device Spectrum volume_emission_integrate(ccl_private VolumeShaderCoefficien
t;
}
}
else
else {
emission *= t;
}
return emission;
}

@ -1024,8 +1024,9 @@ ccl_device float3 surface_shader_average_normal(KernelGlobals kg, ccl_private co
for (int i = 0; i < sd->num_closure; i++) {
ccl_private const ShaderClosure *sc = &sd->closure[i];
if (CLOSURE_IS_BSDF_OR_BSSRDF(sc->type))
if (CLOSURE_IS_BSDF_OR_BSSRDF(sc->type)) {
N += sc->N * fabsf(average(sc->weight));
}
}
return (is_zero(N)) ? sd->N : normalize(N);

@ -81,10 +81,12 @@ ccl_device_inline float area_light_rect_sample(float3 P,
}
/* return pdf */
if (S != 0.0f)
if (S != 0.0f) {
return 1.0f / S;
else
}
else {
return 0.0f;
}
}
/* Light spread. */

@ -42,8 +42,9 @@ ccl_device_inline float triangle_light_pdf_area_sampling(const float3 Ng, const
{
float cos_pi = fabsf(dot(Ng, I));
if (cos_pi == 0.0f)
if (cos_pi == 0.0f) {
return 0.0f;
}
return t * t / cos_pi;
}

@ -714,8 +714,9 @@ ccl_device void osl_closure_diffuse_ramp_setup(KernelGlobals kg,
return;
}
for (int i = 0; i < 8; i++)
for (int i = 0; i < 8; i++) {
bsdf->colors[i] = closure->colors[i];
}
sd->flag |= bsdf_diffuse_ramp_setup(bsdf);
}
@ -741,8 +742,9 @@ ccl_device void osl_closure_phong_ramp_setup(KernelGlobals kg,
return;
}
for (int i = 0; i < 8; i++)
for (int i = 0; i < 8; i++) {
bsdf->colors[i] = closure->colors[i];
}
sd->flag |= bsdf_phong_ramp_setup(bsdf);
}

@ -738,22 +738,28 @@ ccl_device_extern bool osl_transform_triple(ccl_private ShaderGlobals *sg,
if (res) {
if (vectype == 2 /* TypeDesc::POINT */) {
if (p_in_derivs)
if (p_in_derivs) {
osl_transform_dvmdv(p_out, m, p_in);
else
}
else {
osl_transform_vmv(p_out, m, p_in);
}
}
else if (vectype == 3 /* TypeDesc::VECTOR */) {
if (p_in_derivs)
if (p_in_derivs) {
osl_transformv_dvmdv(p_out, m, p_in);
else
}
else {
osl_transformv_vmv(p_out, m, p_in);
}
}
else if (vectype == 4 /* TypeDesc::NORMAL */) {
if (p_in_derivs)
if (p_in_derivs) {
osl_transformn_dvmdv(p_out, m, p_in);
else
}
else {
osl_transformn_vmv(p_out, m, p_in);
}
}
else {
res = false;
@ -1630,19 +1636,24 @@ ccl_device_extern bool osl_texture(ccl_private ShaderGlobals *sg,
switch (type) {
case OSL_TEXTURE_HANDLE_TYPE_SVM: {
const float4 rgba = kernel_tex_image_interp(nullptr, slot, s, 1.0f - t);
if (nchannels > 0)
if (nchannels > 0) {
result[0] = rgba.x;
if (nchannels > 1)
}
if (nchannels > 1) {
result[1] = rgba.y;
if (nchannels > 2)
}
if (nchannels > 2) {
result[2] = rgba.z;
if (alpha)
}
if (alpha) {
*alpha = rgba.w;
}
return true;
}
case OSL_TEXTURE_HANDLE_TYPE_IES: {
if (nchannels > 0)
if (nchannels > 0) {
result[0] = kernel_ies_interp(nullptr, slot, s, t);
}
return true;
}
default: {
@ -1674,14 +1685,18 @@ ccl_device_extern bool osl_texture3d(ccl_private ShaderGlobals *sg,
switch (type) {
case OSL_TEXTURE_HANDLE_TYPE_SVM: {
const float4 rgba = kernel_tex_image_interp_3d(nullptr, slot, *P, INTERPOLATION_NONE);
if (nchannels > 0)
if (nchannels > 0) {
result[0] = rgba.x;
if (nchannels > 1)
}
if (nchannels > 1) {
result[1] = rgba.y;
if (nchannels > 2)
}
if (nchannels > 2) {
result[2] = rgba.z;
if (alpha)
}
if (alpha) {
*alpha = rgba.w;
}
return true;
}
default: {
@ -1706,14 +1721,18 @@ ccl_device_extern bool osl_environment(ccl_private ShaderGlobals *sg,
ccl_private float *dalphay,
ccl_private void *errormessage)
{
if (nchannels > 0)
if (nchannels > 0) {
result[0] = 1.0f;
if (nchannels > 1)
}
if (nchannels > 1) {
result[1] = 0.0f;
if (nchannels > 2)
}
if (nchannels > 2) {
result[2] = 1.0f;
if (alpha)
}
if (alpha) {
*alpha = 1.0f;
}
return false;
}
@ -2095,22 +2114,25 @@ ccl_device_extern void osl_sincos_dfdff(ccl_private const float *a,
ccl_private float *b,
ccl_private float *c)
{
for (int i = 0; i < 3; ++i)
for (int i = 0; i < 3; ++i) {
sincos(a[i], b + i, c);
}
}
ccl_device_extern void osl_sincos_dffdf(ccl_private const float *a,
ccl_private float *b,
ccl_private float *c)
{
for (int i = 0; i < 3; ++i)
for (int i = 0; i < 3; ++i) {
sincos(a[i], b, c + i);
}
}
ccl_device_extern void osl_sincos_dfdfdf(ccl_private const float *a,
ccl_private float *b,
ccl_private float *c)
{
for (int i = 0; i < 3; ++i)
for (int i = 0; i < 3; ++i) {
sincos(a[i], b + i, c + i);
}
}
ccl_device_extern void osl_sincos_vvv(ccl_private const float3 *a,
ccl_private float3 *b,
@ -2232,10 +2254,12 @@ ccl_device_extern void osl_calculatenormal(ccl_private float3 *res,
ccl_private ShaderGlobals *sg,
ccl_private const float3 *p)
{
if (sg->flipHandedness)
if (sg->flipHandedness) {
*res = cross(p[2], p[1]);
else
}
else {
*res = cross(p[1], p[2]);
}
}
ccl_device_extern float osl_area(ccl_private const float3 *p)
@ -2250,8 +2274,9 @@ ccl_device_extern float osl_filterwidth_fdf(ccl_private const float *x)
ccl_device_extern void osl_filterwidth_vdv(ccl_private float *res, ccl_private const float *x)
{
for (int i = 0; i < 3; ++i)
for (int i = 0; i < 3; ++i) {
res[i] = osl_filterwidth_fdf(x + i);
}
}
ccl_device_extern bool osl_raytype_bit(ccl_private ShaderGlobals *sg, int bit)

@ -6,18 +6,22 @@
float color_srgb_to_scene_linear(float c)
{
if (c < 0.04045)
if (c < 0.04045) {
return (c < 0.0) ? 0.0 : c * (1.0 / 12.92);
else
}
else {
return pow((c + 0.055) * (1.0 / 1.055), 2.4);
}
}
float color_scene_linear_to_srgb(float c)
{
if (c < 0.0031308)
if (c < 0.0031308) {
return (c < 0.0) ? 0.0 : c * 12.92;
else
}
else {
return 1.055 * pow(c, 1.0 / 2.4) - 0.055;
}
}
color color_srgb_to_scene_linear(color c)
@ -36,8 +40,9 @@ color color_scene_linear_to_srgb(color c)
color color_unpremultiply(color c, float alpha)
{
if (alpha != 1.0 && alpha != 0.0)
if (alpha != 1.0 && alpha != 0.0) {
return c / alpha;
}
return c;
}
@ -48,15 +53,19 @@ color xyY_to_xyz(float x, float y, float Y)
{
float X, Z;
if (y != 0.0)
if (y != 0.0) {
X = (x / y) * Y;
else
}
else {
X = 0.0;
}
if (y != 0.0 && Y != 0.0)
if (y != 0.0 && Y != 0.0) {
Z = ((1.0 - x - y) / y) * Y;
else
}
else {
Z = 0.0;
}
return color(X, Y, Z);
}
@ -93,17 +102,21 @@ color rgb_to_hsv(color rgb)
else {
c = (color(cmax, cmax, cmax) - rgb) / cdelta;
if (rgb[0] == cmax)
if (rgb[0] == cmax) {
h = c[2] - c[1];
else if (rgb[1] == cmax)
}
else if (rgb[1] == cmax) {
h = 2.0 + c[0] - c[2];
else
}
else {
h = 4.0 + c[1] - c[0];
}
h /= 6.0;
if (h < 0.0)
if (h < 0.0) {
h += 1.0;
}
}
return color(h, s, v);
@ -122,8 +135,9 @@ color hsv_to_rgb(color hsv)
rgb = color(v, v, v);
}
else {
if (h == 1.0)
if (h == 1.0) {
h = 0.0;
}
h *= 6.0;
i = floor(h);
@ -133,18 +147,24 @@ color hsv_to_rgb(color hsv)
q = v * (1.0 - (s * f));
t = v * (1.0 - (s * (1.0 - f)));
if (i == 0.0)
if (i == 0.0) {
rgb = color(v, t, p);
else if (i == 1.0)
}
else if (i == 1.0) {
rgb = color(q, v, p);
else if (i == 2.0)
}
else if (i == 2.0) {
rgb = color(p, v, t);
else if (i == 3.0)
}
else if (i == 3.0) {
rgb = color(p, q, v);
else if (i == 4.0)
}
else if (i == 4.0) {
rgb = color(t, p, v);
else
}
else {
rgb = color(v, p, q);
}
}
return rgb;

@ -30,20 +30,26 @@ color node_mix_overlay(float t, color col1, color col2)
color outcol = col1;
if (outcol[0] < 0.5)
if (outcol[0] < 0.5) {
outcol[0] *= tm + 2.0 * t * col2[0];
else
}
else {
outcol[0] = 1.0 - (tm + 2.0 * t * (1.0 - col2[0])) * (1.0 - outcol[0]);
}
if (outcol[1] < 0.5)
if (outcol[1] < 0.5) {
outcol[1] *= tm + 2.0 * t * col2[1];
else
}
else {
outcol[1] = 1.0 - (tm + 2.0 * t * (1.0 - col2[1])) * (1.0 - outcol[1]);
}
if (outcol[2] < 0.5)
if (outcol[2] < 0.5) {
outcol[2] *= tm + 2.0 * t * col2[2];
else
}
else {
outcol[2] = 1.0 - (tm + 2.0 * t * (1.0 - col2[2])) * (1.0 - outcol[2]);
}
return outcol;
}
@ -59,12 +65,15 @@ color node_mix_div(float t, color col1, color col2)
color outcol = col1;
if (col2[0] != 0.0)
if (col2[0] != 0.0) {
outcol[0] = tm * outcol[0] + t * outcol[0] / col2[0];
if (col2[1] != 0.0)
}
if (col2[1] != 0.0) {
outcol[1] = tm * outcol[1] + t * outcol[1] / col2[1];
if (col2[2] != 0.0)
}
if (col2[2] != 0.0) {
outcol[2] = tm * outcol[2] + t * outcol[2] / col2[2];
}
return outcol;
}
@ -95,30 +104,39 @@ color node_mix_dodge(float t, color col1, color col2)
if (outcol[0] != 0.0) {
float tmp = 1.0 - t * col2[0];
if (tmp <= 0.0)
if (tmp <= 0.0) {
outcol[0] = 1.0;
else if ((tmp = outcol[0] / tmp) > 1.0)
}
else if ((tmp = outcol[0] / tmp) > 1.0) {
outcol[0] = 1.0;
else
}
else {
outcol[0] = tmp;
}
}
if (outcol[1] != 0.0) {
float tmp = 1.0 - t * col2[1];
if (tmp <= 0.0)
if (tmp <= 0.0) {
outcol[1] = 1.0;
else if ((tmp = outcol[1] / tmp) > 1.0)
}
else if ((tmp = outcol[1] / tmp) > 1.0) {
outcol[1] = 1.0;
else
}
else {
outcol[1] = tmp;
}
}
if (outcol[2] != 0.0) {
float tmp = 1.0 - t * col2[2];
if (tmp <= 0.0)
if (tmp <= 0.0) {
outcol[2] = 1.0;
else if ((tmp = outcol[2] / tmp) > 1.0)
}
else if ((tmp = outcol[2] / tmp) > 1.0) {
outcol[2] = 1.0;
else
}
else {
outcol[2] = tmp;
}
}
return outcol;
@ -131,34 +149,46 @@ color node_mix_burn(float t, color col1, color col2)
color outcol = col1;
tmp = tm + t * col2[0];
if (tmp <= 0.0)
if (tmp <= 0.0) {
outcol[0] = 0.0;
else if ((tmp = (1.0 - (1.0 - outcol[0]) / tmp)) < 0.0)
}
else if ((tmp = (1.0 - (1.0 - outcol[0]) / tmp)) < 0.0) {
outcol[0] = 0.0;
else if (tmp > 1.0)
}
else if (tmp > 1.0) {
outcol[0] = 1.0;
else
}
else {
outcol[0] = tmp;
}
tmp = tm + t * col2[1];
if (tmp <= 0.0)
if (tmp <= 0.0) {
outcol[1] = 0.0;
else if ((tmp = (1.0 - (1.0 - outcol[1]) / tmp)) < 0.0)
}
else if ((tmp = (1.0 - (1.0 - outcol[1]) / tmp)) < 0.0) {
outcol[1] = 0.0;
else if (tmp > 1.0)
}
else if (tmp > 1.0) {
outcol[1] = 1.0;
else
}
else {
outcol[1] = tmp;
}
tmp = tm + t * col2[2];
if (tmp <= 0.0)
if (tmp <= 0.0) {
outcol[2] = 0.0;
else if ((tmp = (1.0 - (1.0 - outcol[2]) / tmp)) < 0.0)
}
else if ((tmp = (1.0 - (1.0 - outcol[2]) / tmp)) < 0.0) {
outcol[2] = 0.0;
else if (tmp > 1.0)
}
else if (tmp > 1.0) {
outcol[2] = 1.0;
else
}
else {
outcol[2] = tmp;
}
return outcol;
}
@ -240,20 +270,26 @@ color node_mix_linear(float t, color col1, color col2)
{
color outcol = col1;
if (col2[0] > 0.5)
if (col2[0] > 0.5) {
outcol[0] = col1[0] + t * (2.0 * (col2[0] - 0.5));
else
}
else {
outcol[0] = col1[0] + t * (2.0 * (col2[0]) - 1.0);
}
if (col2[1] > 0.5)
if (col2[1] > 0.5) {
outcol[1] = col1[1] + t * (2.0 * (col2[1] - 0.5));
else
}
else {
outcol[1] = col1[1] + t * (2.0 * (col2[1]) - 1.0);
}
if (col2[2] > 0.5)
if (col2[2] > 0.5) {
outcol[2] = col1[2] + t * (2.0 * (col2[2] - 0.5));
else
}
else {
outcol[2] = col1[2] + t * (2.0 * (col2[2]) - 1.0);
}
return outcol;
}

@ -19,8 +19,9 @@ float fresnel_dielectric_cos(float cosi, float eta)
float B = (c * (g + c) - 1) / (c * (g - c) + 1);
result = 0.5 * A * A * (1 + B * B);
}
else
else {
result = 1.0; /* TIR (no refracted component) */
}
return result;
}

@ -10,64 +10,72 @@
float safe_noise(float p)
{
float f = noise("noise", p);
if (isinf(f))
if (isinf(f)) {
return 0.5;
}
return f;
}
float safe_noise(vector2 p)
{
float f = noise("noise", p.x, p.y);
if (isinf(f))
if (isinf(f)) {
return 0.5;
}
return f;
}
float safe_noise(vector3 p)
{
float f = noise("noise", p);
if (isinf(f))
if (isinf(f)) {
return 0.5;
}
return f;
}
float safe_noise(vector4 p)
{
float f = noise("noise", vector3(p.x, p.y, p.z), p.w);
if (isinf(f))
if (isinf(f)) {
return 0.5;
}
return f;
}
float safe_snoise(float p)
{
float f = noise("snoise", p);
if (isinf(f))
if (isinf(f)) {
return 0.0;
}
return f;
}
float safe_snoise(vector2 p)
{
float f = noise("snoise", p.x, p.y);
if (isinf(f))
if (isinf(f)) {
return 0.0;
}
return f;
}
float safe_snoise(vector3 p)
{
float f = noise("snoise", p);
if (isinf(f))
if (isinf(f)) {
return 0.0;
}
return f;
}
float safe_snoise(vector4 p)
{
float f = noise("snoise", vector3(p.x, p.y, p.z), p.w);
if (isinf(f))
if (isinf(f)) {
return 0.0;
}
return f;
}

@ -28,16 +28,19 @@ color rgb_ramp_lookup(color ramp[], float at, int interpolate, int extrapolate)
/* clamp int as well in case of NaN */
int i = (int)f;
if (i < 0)
if (i < 0) {
i = 0;
if (i >= table_size)
}
if (i >= table_size) {
i = table_size - 1;
}
float t = f - (float)i;
color result = ramp[i];
if (interpolate && t > 0.0)
if (interpolate && t > 0.0) {
result = (1.0 - t) * result + t * ramp[i + 1];
}
return result;
}
@ -66,16 +69,19 @@ float rgb_ramp_lookup(float ramp[], float at, int interpolate, int extrapolate)
/* clamp int as well in case of NaN */
int i = (int)f;
if (i < 0)
if (i < 0) {
i = 0;
if (i >= table_size)
}
if (i >= table_size) {
i = table_size - 1;
}
float t = f - (float)i;
float result = ramp[i];
if (interpolate && t > 0.0)
if (interpolate && t > 0.0) {
result = (1.0 - t) * result + t * ramp[i + 1];
}
return result;
}

@ -23,8 +23,9 @@ ccl_device float svm_bevel_cubic_eval(const float radius, float r)
{
const float Rm = radius;
if (r >= Rm)
if (r >= Rm) {
return 0.0f;
}
/* integrate (2*pi*r * 10*(R - r)^3)/(pi * R^5) from 0 to R = 1 */
const float Rm5 = (Rm * Rm) * (Rm * Rm) * Rm;
@ -58,8 +59,9 @@ ccl_device_forceinline float svm_bevel_cubic_quintic_root_find(float xi)
float f = 10.0f * x2 - 20.0f * x3 + 15.0f * x2 * x2 - 4.0f * x2 * x3 - xi;
float f_ = 20.0f * (x * nx) * (nx * nx);
if (fabsf(f) < tolerance || f_ == 0.0f)
if (fabsf(f) < tolerance || f_ == 0.0f) {
break;
}
x = saturatef(x - f / f_);
}

@ -22,14 +22,17 @@ ccl_device_noinline void svm_node_camera(KernelGlobals kg,
zdepth = vector.z;
distance = len(vector);
if (stack_valid(out_vector))
if (stack_valid(out_vector)) {
stack_store_float3(stack, out_vector, normalize(vector));
}
if (stack_valid(out_zdepth))
if (stack_valid(out_zdepth)) {
stack_store_float(stack, out_zdepth, zdepth);
}
if (stack_valid(out_distance))
if (stack_valid(out_distance)) {
stack_store_float(stack, out_distance, distance);
}
}
CCL_NAMESPACE_END

@ -456,8 +456,9 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
/* rotate tangent */
float rotation = stack_load_float(stack, data_node.z);
if (rotation != 0.0f)
if (rotation != 0.0f) {
bsdf->T = rotate_around_axis(bsdf->T, bsdf->N, rotation * M_2PI_F);
}
if (anisotropy < 0.0f) {
bsdf->alpha_x = roughness / (1.0f + anisotropy);
@ -603,10 +604,12 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
bsdf->size = param1;
bsdf->smooth = param2;
if (type == CLOSURE_BSDF_DIFFUSE_TOON_ID)
if (type == CLOSURE_BSDF_DIFFUSE_TOON_ID) {
sd->flag |= bsdf_diffuse_toon_setup(bsdf);
else
}
else {
sd->flag |= bsdf_glossy_toon_setup(bsdf);
}
}
break;
}
@ -1014,8 +1017,9 @@ ccl_device_noinline void svm_node_closure_emission(ccl_private ShaderData *sd,
if (stack_valid(mix_weight_offset)) {
float mix_weight = stack_load_float(stack, mix_weight_offset);
if (mix_weight == 0.0f)
if (mix_weight == 0.0f) {
return;
}
weight *= mix_weight;
}
@ -1034,8 +1038,9 @@ ccl_device_noinline void svm_node_closure_background(ccl_private ShaderData *sd,
if (stack_valid(mix_weight_offset)) {
float mix_weight = stack_load_float(stack, mix_weight_offset);
if (mix_weight == 0.0f)
if (mix_weight == 0.0f) {
return;
}
weight *= mix_weight;
}
@ -1053,13 +1058,15 @@ ccl_device_noinline void svm_node_closure_holdout(ccl_private ShaderData *sd,
if (stack_valid(mix_weight_offset)) {
float mix_weight = stack_load_float(stack, mix_weight_offset);
if (mix_weight == 0.0f)
if (mix_weight == 0.0f) {
return;
}
closure_alloc(sd, sizeof(ShaderClosure), CLOSURE_HOLDOUT_ID, closure_weight * mix_weight);
}
else
else {
closure_alloc(sd, sizeof(ShaderClosure), CLOSURE_HOLDOUT_ID, closure_weight);
}
sd->flag |= SD_HOLDOUT;
}

@ -17,8 +17,9 @@ ccl_device_noinline void svm_node_gamma(ccl_private ShaderData *sd,
color = svm_math_gamma_color(color, gamma);
if (stack_valid(out_color))
if (stack_valid(out_color)) {
stack_store_float3(stack, out_color, color);
}
}
CCL_NAMESPACE_END

@ -41,10 +41,12 @@ ccl_device float svm_gradient(float3 p, NodeGradientType type)
* on float precision. */
float r = fmaxf(0.999999f - sqrtf(x * x + y * y + z * z), 0.0f);
if (type == NODE_BLEND_QUADRATIC_SPHERE)
if (type == NODE_BLEND_QUADRATIC_SPHERE) {
return r * r;
else if (type == NODE_BLEND_SPHERICAL)
}
else if (type == NODE_BLEND_SPHERICAL) {
return r;
}
}
return 0.0f;

@ -55,10 +55,12 @@ ccl_device_inline float kernel_ies_interp(KernelGlobals kg, int slot, float h_an
int h_i, v_i;
/* TODO(lukas): Consider using bisection.
* Probably not worth it for the vast majority of IES files. */
for (h_i = 0; IES_LOOKUP_ANGLE_H(h_i + 1) < h_angle; h_i++)
for (h_i = 0; IES_LOOKUP_ANGLE_H(h_i + 1) < h_angle; h_i++) {
;
for (v_i = 0; IES_LOOKUP_ANGLE_V(v_i + 1) < v_angle; v_i++)
}
for (v_i = 0; IES_LOOKUP_ANGLE_V(v_i + 1) < v_angle; v_i++) {
;
}
float h_frac = inverse_lerp(IES_LOOKUP_ANGLE_H(h_i), IES_LOOKUP_ANGLE_H(h_i + 1), h_angle);
float v_frac = inverse_lerp(IES_LOOKUP_ANGLE_V(v_i), IES_LOOKUP_ANGLE_V(v_i + 1), v_angle);

@ -24,8 +24,9 @@ ccl_device_noinline void svm_node_invert(ccl_private ShaderData *sd,
color.y = invert(color.y, factor);
color.z = invert(color.z, factor);
if (stack_valid(out_color))
if (stack_valid(out_color)) {
stack_store_float3(stack, out_color, color);
}
}
CCL_NAMESPACE_END

@ -24,11 +24,13 @@ ccl_device_noinline int svm_node_normal(KernelGlobals kg,
direction.z = __int_as_float(node1.z);
direction = normalize(direction);
if (stack_valid(out_normal_offset))
if (stack_valid(out_normal_offset)) {
stack_store_float3(stack, out_normal_offset, direction);
}
if (stack_valid(out_dot_offset))
if (stack_valid(out_dot_offset)) {
stack_store_float(stack, out_dot_offset, dot(direction, normalize(normal)));
}
return offset;
}

@ -24,8 +24,9 @@ ccl_device_noinline void svm_node_combine_color(KernelGlobals kg,
/* Combine, and convert back to RGB */
float3 color = svm_combine_color((NodeCombSepColorType)color_type, make_float3(r, g, b));
if (stack_valid(result_stack_offset))
if (stack_valid(result_stack_offset)) {
stack_store_float3(stack, result_stack_offset, color);
}
}
ccl_device_noinline void svm_node_separate_color(KernelGlobals kg,

@ -24,8 +24,9 @@ ccl_device_noinline int svm_node_combine_hsv(KernelGlobals kg,
/* Combine, and convert back to RGB */
float3 color = hsv_to_rgb(make_float3(hue, saturation, value));
if (stack_valid(color_out))
if (stack_valid(color_out)) {
stack_store_float3(stack, color_out, color);
}
return offset;
}

@ -16,8 +16,9 @@ ccl_device void svm_node_combine_vector(ccl_private ShaderData *sd,
{
float vector = stack_load_float(stack, in_offset);
if (stack_valid(out_offset))
if (stack_valid(out_offset)) {
stack_store_float(stack, out_offset + vector_index, vector);
}
}
ccl_device void svm_node_separate_vector(ccl_private ShaderData *sd,
@ -29,12 +30,15 @@ ccl_device void svm_node_separate_vector(ccl_private ShaderData *sd,
float3 vector = stack_load_float3(stack, ivector_offset);
if (stack_valid(out_offset)) {
if (vector_index == 0)
if (vector_index == 0) {
stack_store_float(stack, out_offset, vector.x);
else if (vector_index == 1)
}
else if (vector_index == 1) {
stack_store_float(stack, out_offset, vector.y);
else
}
else {
stack_store_float(stack, out_offset, vector.z);
}
}
}

@ -234,14 +234,18 @@ ccl_device void svm_eval_nodes(KernelGlobals kg,
return;
SVM_CASE(NODE_SHADER_JUMP)
{
if (type == SHADER_TYPE_SURFACE)
if (type == SHADER_TYPE_SURFACE) {
offset = node.y;
else if (type == SHADER_TYPE_VOLUME)
}
else if (type == SHADER_TYPE_VOLUME) {
offset = node.z;
else if (type == SHADER_TYPE_DISPLACEMENT)
}
else if (type == SHADER_TYPE_DISPLACEMENT) {
offset = node.w;
else
}
else {
return;
}
break;
}
SVM_CASE(NODE_CLOSURE_BSDF)
@ -276,12 +280,14 @@ ccl_device void svm_eval_nodes(KernelGlobals kg,
svm_node_mix_closure(sd, stack, node);
break;
SVM_CASE(NODE_JUMP_IF_ZERO)
if (stack_load_float(stack, node.z) <= 0.0f)
if (stack_load_float(stack, node.z) <= 0.0f) {
offset += node.y;
}
break;
SVM_CASE(NODE_JUMP_IF_ONE)
if (stack_load_float(stack, node.z) >= 1.0f)
if (stack_load_float(stack, node.z) >= 1.0f) {
offset += node.y;
}
break;
SVM_CASE(NODE_GEOMETRY)
svm_node_geometry(kg, sd, stack, node.y, node.z);

@ -44,10 +44,12 @@ ccl_device_noinline int svm_node_tex_voxel(
}
#endif
if (stack_valid(density_out_offset))
if (stack_valid(density_out_offset)) {
stack_store_float(stack, density_out_offset, r.w);
if (stack_valid(color_out_offset))
}
if (stack_valid(color_out_offset)) {
stack_store_float3(stack, color_out_offset, make_float3(r.x, r.y, r.z));
}
return offset;
}

@ -56,8 +56,9 @@ ccl_device_noinline_cpu float svm_wave(NodeWaveType type,
n += phase;
if (distortion != 0.0f)
if (distortion != 0.0f) {
n += distortion * (fractal_noise_3d(p * dscale, detail, droughness, 2.0f, true) * 2.0f - 1.0f);
}
if (profile == NODE_WAVE_PROFILE_SIN) {
return 0.5f + 0.5f * sinf(n - M_PI_2_F);

@ -64,8 +64,9 @@ ccl_device_inline float wireframe(KernelGlobals kg,
// At this point dot(crs, crs) / dot(edge, edge) is
// the square of area / length(edge) == square of the
// distance to the edge.
if (dot(crs, crs) < (dot(edge, edge) * pixelwidth))
if (dot(crs, crs) < (dot(edge, edge) * pixelwidth)) {
return 1.0f;
}
}
}
return 0.0f;

@ -74,8 +74,9 @@ ccl_device void differential_dudv(ccl_private differential *du,
float det = (dPdu.x * dPdv.y - dPdv.x * dPdu.y);
if (det != 0.0f)
if (det != 0.0f) {
det = 1.0f / det;
}
du->dx = (dP.dx.x * dPdv.y - dP.dx.y * dPdv.x) * det;
dv->dx = (dP.dx.y * dPdu.x - dP.dx.x * dPdu.y) * det;

@ -17,8 +17,9 @@ ccl_device float lookup_table_read(KernelGlobals kg, float x, int offset, int si
float t = x - index;
float data0 = kernel_data_fetch(lookup_table, index + offset);
if (t == 0.0f)
if (t == 0.0f) {
return data0;
}
float data1 = kernel_data_fetch(lookup_table, nindex + offset);
return (1.0f - t) * data0 + t * data1;
@ -34,8 +35,9 @@ ccl_device float lookup_table_read_2D(
float t = y - index;
float data0 = lookup_table_read(kg, x, offset + xsize * index, xsize);
if (t == 0.0f)
if (t == 0.0f) {
return data0;
}
float data1 = lookup_table_read(kg, x, offset + xsize * nindex, xsize);
return (1.0f - t) * data0 + t * data1;
@ -51,8 +53,9 @@ ccl_device float lookup_table_read_3D(
float t = z - index;
float data0 = lookup_table_read_2D(kg, x, y, offset + xsize * ysize * index, xsize, ysize);
if (t == 0.0f)
if (t == 0.0f) {
return data0;
}
float data1 = lookup_table_read_2D(kg, x, y, offset + xsize * ysize * nindex, xsize, ysize);
return (1.0f - t) * data0 + t * data1;

@ -135,9 +135,11 @@ class SVMCompiler {
bool empty()
{
for (int i = 0; i < SVM_STACK_SIZE; i++)
if (users[i])
for (int i = 0; i < SVM_STACK_SIZE; i++) {
if (users[i]) {
return false;
}
}
return true;
}
@ -146,8 +148,9 @@ class SVMCompiler {
{
printf("stack <");
for (int i = 0; i < SVM_STACK_SIZE; i++)
for (int i = 0; i < SVM_STACK_SIZE; i++) {
printf((users[i]) ? "*" : " ");
}
printf(">\n");
}

@ -92,8 +92,9 @@ class BoundBox {
/* todo: avoid using this */
__forceinline float safe_area() const
{
if (!((min.x <= max.x) && (min.y <= max.y) && (min.z <= max.z)))
if (!((min.x <= max.x) && (min.y <= max.y) && (min.z <= max.z))) {
return 0.0f;
}
return area();
}

@ -61,18 +61,22 @@ ccl_device_inline float4 color_uchar4_to_float4(uchar4 c)
ccl_device float color_srgb_to_linear(float c)
{
if (c < 0.04045f)
if (c < 0.04045f) {
return (c < 0.0f) ? 0.0f : c * (1.0f / 12.92f);
else
}
else {
return powf((c + 0.055f) * (1.0f / 1.055f), 2.4f);
}
}
ccl_device float color_linear_to_srgb(float c)
{
if (c < 0.0031308f)
if (c < 0.0031308f) {
return (c < 0.0f) ? 0.0f : c * 12.92f;
else
}
else {
return 1.055f * powf(c, 1.0f / 2.4f) - 0.055f;
}
}
ccl_device float3 rgb_to_hsv(float3 rgb)
@ -98,17 +102,21 @@ ccl_device float3 rgb_to_hsv(float3 rgb)
float3 cmax3 = make_float3(cmax, cmax, cmax);
c = (cmax3 - rgb) / cdelta;
if (rgb.x == cmax)
if (rgb.x == cmax) {
h = c.z - c.y;
else if (rgb.y == cmax)
}
else if (rgb.y == cmax) {
h = 2.0f + c.x - c.z;
else
}
else {
h = 4.0f + c.y - c.x;
}
h /= 6.0f;
if (h < 0.0f)
if (h < 0.0f) {
h += 1.0f;
}
}
else {
h = 0.0f;
@ -127,8 +135,9 @@ ccl_device float3 hsv_to_rgb(float3 hsv)
v = hsv.z;
if (s != 0.0f) {
if (h == 1.0f)
if (h == 1.0f) {
h = 0.0f;
}
h *= 6.0f;
i = floorf(h);
@ -138,18 +147,24 @@ ccl_device float3 hsv_to_rgb(float3 hsv)
q = v * (1.0f - (s * f));
t = v * (1.0f - (s * (1.0f - f)));
if (i == 0.0f)
if (i == 0.0f) {
rgb = make_float3(v, t, p);
else if (i == 1.0f)
}
else if (i == 1.0f) {
rgb = make_float3(q, v, p);
else if (i == 2.0f)
}
else if (i == 2.0f) {
rgb = make_float3(p, v, t);
else if (i == 3.0f)
}
else if (i == 3.0f) {
rgb = make_float3(p, q, v);
else if (i == 4.0f)
}
else if (i == 4.0f) {
rgb = make_float3(t, p, v);
else
}
else {
rgb = make_float3(v, p, q);
}
}
else {
rgb = make_float3(v, v, v);
@ -212,15 +227,19 @@ ccl_device float3 xyY_to_xyz(float x, float y, float Y)
{
float X, Z;
if (y != 0.0f)
if (y != 0.0f) {
X = (x / y) * Y;
else
}
else {
X = 0.0f;
}
if (y != 0.0f && Y != 0.0f)
if (y != 0.0f && Y != 0.0f) {
Z = (1.0f - x - y) / y * Y;
else
}
else {
Z = 0.0f;
}
return make_float3(X, Y, Z);
}

@ -500,8 +500,9 @@ static inline uint hash_string(const char *str)
{
uint i = 0, c;
while ((c = *str++))
while ((c = *str++)) {
i = i * 37 + c;
}
return i;
}

@ -382,10 +382,12 @@ ccl_device_inline float mix(float a, float b, float t)
ccl_device_inline float smoothstep(float edge0, float edge1, float x)
{
float result;
if (x < edge0)
if (x < edge0) {
result = 0.0f;
else if (x >= edge1)
}
else if (x >= edge1) {
result = 1.0f;
}
else {
float t = (x - edge0) / (edge1 - edge0);
result = (3.0f - 2.0f * t) * (t * t);
@ -464,10 +466,12 @@ ccl_device_inline float signf(float f)
ccl_device_inline float nonzerof(float f, float eps)
{
if (fabsf(f) < eps)
if (fabsf(f) < eps) {
return signf(f) * eps;
else
}
else {
return f;
}
}
/* `signum` function testing for zero. Matches GLSL and OSL functions. */
@ -620,16 +624,18 @@ ccl_device_inline float3 safe_divide_even_color(float3 a, float3 b)
x = y;
z = y;
}
else
else {
x = 0.5f * (y + z);
}
}
else if (b.y == 0.0f) {
if (b.z == 0.0f) {
y = x;
z = x;
}
else
else {
y = 0.5f * (x + z);
}
}
else if (b.z == 0.0f) {
z = 0.5f * (x + y);
@ -708,8 +714,9 @@ ccl_device float compatible_powf(float x, float y)
ccl_device float safe_powf(float a, float b)
{
if (UNLIKELY(a < 0.0f && b != float_to_int(b)))
if (UNLIKELY(a < 0.0f && b != float_to_int(b))) {
return 0.0f;
}
return compatible_powf(a, b);
}
@ -721,8 +728,9 @@ ccl_device float safe_divide(float a, float b)
ccl_device float safe_logf(float a, float b)
{
if (UNLIKELY(a <= 0.0f || b <= 0.0f))
if (UNLIKELY(a <= 0.0f || b <= 0.0f)) {
return 0.0f;
}
return safe_divide(logf(a), logf(b));
}

@ -304,8 +304,9 @@ ccl_device void math_matrix_jacobi_eigendecomposition(ccl_private float *A,
if (abs_element > singular_epsilon * fabsf(singular_diff)) {
float cot_2phi = 0.5f * singular_diff / element;
ratio = 1.0f / (fabsf(cot_2phi) + sqrtf(1.0f + cot_2phi * cot_2phi));
if (cot_2phi < 0.0f)
if (cot_2phi < 0.0f) {
ratio = -ratio; /* Copy sign. */
}
}
else {
ratio = element / singular_diff;

@ -386,8 +386,9 @@ __forceinline uint64_t bitscan(uint64_t v)
__forceinline uint32_t __bsf(const uint32_t x)
{
for (int i = 0; i < 32; i++) {
if (x & (1U << i))
if (x & (1U << i)) {
return i;
}
}
return 32;
}
@ -395,8 +396,9 @@ __forceinline uint32_t __bsf(const uint32_t x)
__forceinline uint32_t __bsr(const uint32_t x)
{
for (int i = 0; i < 32; i++) {
if (x & (1U << (31 - i)))
if (x & (1U << (31 - i))) {
return (31 - i);
}
}
return 32;
}
@ -410,8 +412,9 @@ __forceinline uint32_t __btc(const uint32_t x, const uint32_t bit)
__forceinline uint32_t __bsf(const uint64_t x)
{
for (int i = 0; i < 64; i++) {
if (x & (1UL << i))
if (x & (1UL << i)) {
return i;
}
}
return 64;
}
@ -419,8 +422,9 @@ __forceinline uint32_t __bsf(const uint64_t x)
__forceinline uint32_t __bsr(const uint64_t x)
{
for (int i = 0; i < 64; i++) {
if (x & (1UL << (63 - i)))
if (x & (1UL << (63 - i))) {
return (63 - i);
}
}
return 64;
}

@ -19,13 +19,13 @@ class Cubes {
/// Get a triangle
void getTriangle(int mask, int index, int indices[3])
{
for (int i = 0; i < 3; i++)
for (int i = 0; i < 3; i++) {
indices[i] = marching_cubes_tris[mask][index][i];
}
}
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("DUALCON:Cubes")
MEM_CXX_CLASS_ALLOC_FUNCS("DUALCON:Cubes")
#endif
};
};
#endif /* __CUBES_H__ */

@ -509,10 +509,12 @@ class Octree {
{
printf("INFO AT: %d %d %d\n", st[0] >> minshift, st[1] >> minshift, st[2] >> minshift);
LeafNode *leaf = (LeafNode *)locateLeafCheck(st);
if (leaf)
if (leaf) {
printInfo(leaf);
else
}
else {
printf("Leaf not exists!\n");
}
}
void printInfo(const LeafNode *leaf)

@ -74,8 +74,9 @@ class GHOST_EventDragnDrop : public GHOST_Event {
~GHOST_EventDragnDrop()
{
/* Free the dropped object data. */
if (m_dragnDropEventData.data == nullptr)
if (m_dragnDropEventData.data == nullptr) {
return;
}
switch (m_dragnDropEventData.dataType) {
case GHOST_kDragnDropTypeBitmap:
@ -85,8 +86,9 @@ class GHOST_EventDragnDrop : public GHOST_Event {
GHOST_TStringArray *strArray = (GHOST_TStringArray *)m_dragnDropEventData.data;
int i;
for (i = 0; i < strArray->count; i++)
for (i = 0; i < strArray->count; i++) {
free(strArray->strings[i]);
}
free(strArray->strings);
free(strArray);

@ -34,7 +34,8 @@ class GHOST_EventString : public GHOST_Event {
~GHOST_EventString()
{
if (m_data)
if (m_data) {
free(m_data);
}
}
};

@ -56,12 +56,15 @@ static inline Eigen::Matrix3d CreateMatrix(double xx,
static inline Eigen::Matrix3d RotationMatrix(double sine, double cosine, int axis)
{
if (axis == 0)
if (axis == 0) {
return CreateMatrix(1.0, 0.0, 0.0, 0.0, cosine, -sine, 0.0, sine, cosine);
else if (axis == 1)
}
else if (axis == 1) {
return CreateMatrix(cosine, 0.0, sine, 0.0, 1.0, 0.0, -sine, 0.0, cosine);
else
}
else {
return CreateMatrix(cosine, -sine, 0.0, sine, cosine, 0.0, 0.0, 0.0, 1.0);
}
}
static inline Eigen::Matrix3d RotationMatrix(double angle, int axis)
@ -74,32 +77,41 @@ static inline double EulerAngleFromMatrix(const Eigen::Matrix3d &R, int axis)
double t = sqrt(R(0, 0) * R(0, 0) + R(0, 1) * R(0, 1));
if (t > 16.0 * IK_EPSILON) {
if (axis == 0)
if (axis == 0) {
return -atan2(R(1, 2), R(2, 2));
else if (axis == 1)
}
else if (axis == 1) {
return atan2(-R(0, 2), t);
else
}
else {
return -atan2(R(0, 1), R(0, 0));
}
}
else {
if (axis == 0)
if (axis == 0) {
return -atan2(-R(2, 1), R(1, 1));
else if (axis == 1)
}
else if (axis == 1) {
return atan2(-R(0, 2), t);
else
}
else {
return 0.0f;
}
}
}
static inline double safe_acos(double f)
{
// acos that does not return NaN with rounding errors
if (f <= -1.0)
if (f <= -1.0) {
return M_PI;
else if (f >= 1.0)
}
else if (f >= 1.0) {
return 0.0;
else
}
else {
return acos(f);
}
}
static inline Eigen::Vector3d normalize(const Eigen::Vector3d &v)
@ -152,11 +164,12 @@ static inline Eigen::Vector3d SphericalRangeParameters(const Eigen::Matrix3d &R)
double num = 2.0 * (1.0 + R(1, 1));
// singularity at pi
if (fabs(num) < IK_EPSILON)
if (fabs(num) < IK_EPSILON) {
// TODO: this does now rotation of size pi over z axis, but could
// be any axis, how to deal with this I'm not sure, maybe don't
// enforce limits at all then.
return Eigen::Vector3d(0.0, tau, 1.0);
}
num = 1.0 / sqrt(num);
double ax = -R(2, 1) * num;
@ -184,8 +197,9 @@ static inline Eigen::Vector3d MatrixToAxisAngle(const Eigen::Matrix3d &R)
double c = safe_acos((R(0, 0) + R(1, 1) + R(2, 2) - 1) / 2);
double l = delta.norm();
if (!FuzzyZero(l))
if (!FuzzyZero(l)) {
delta *= c / l;
}
return delta;
}
@ -213,20 +227,24 @@ static inline bool EllipseClamp(double &ax, double &az, double *amin, double *am
}
if (FuzzyZero(xlim) || FuzzyZero(zlim)) {
if (x <= xlim && z <= zlim)
if (x <= xlim && z <= zlim) {
return false;
}
if (x > xlim)
if (x > xlim) {
x = xlim;
if (z > zlim)
}
if (z > zlim) {
z = zlim;
}
}
else {
double invx = 1.0 / (xlim * xlim);
double invz = 1.0 / (zlim * zlim);
if ((x * x * invx + z * z * invz) <= 1.0)
if ((x * x * invx + z * z * invz) <= 1.0) {
return false;
}
if (FuzzyZero(x)) {
x = 0.0;
@ -236,8 +254,9 @@ static inline bool EllipseClamp(double &ax, double &az, double *amin, double *am
double rico = z / x;
double old_x = x;
x = sqrt(1.0 / (invx + invz * rico * rico));
if (old_x < 0.0)
if (old_x < 0.0) {
x = -x;
}
z = rico * x;
}
}

@ -174,8 +174,9 @@ class ArrayND : public BaseArray {
/// Return the number of elements of the array.
int Size() const {
int size = 1;
for (int i = 0; i < N; ++i)
for (int i = 0; i < N; ++i) {
size *= Shape(i);
}
return size;
}
@ -191,8 +192,9 @@ class ArrayND : public BaseArray {
/// Distance between the first element and the element at position index.
int Offset(const Index& index) const {
int offset = 0;
for (int i = 0; i < N; ++i)
for (int i = 0; i < N; ++i) {
offset += index(i) * Stride(i);
}
return offset;
}
@ -260,9 +262,11 @@ class ArrayND : public BaseArray {
/// True if index is inside array.
bool Contains(const Index& index) const {
for (int i = 0; i < N; ++i)
if (index(i) < 0 || index(i) >= Shape(i))
for (int i = 0; i < N; ++i) {
if (index(i) < 0 || index(i) >= Shape(i)) {
return false;
}
}
return true;
}
@ -281,13 +285,16 @@ class ArrayND : public BaseArray {
}
bool operator==(const ArrayND<T, N>& other) const {
if (shape_ != other.shape_)
if (shape_ != other.shape_) {
return false;
if (strides_ != other.strides_)
}
if (strides_ != other.strides_) {
return false;
}
for (int i = 0; i < Size(); ++i) {
if (this->Data()[i] != other.Data()[i])
if (this->Data()[i] != other.Data()[i]) {
return false;
}
}
return true;
}
@ -401,8 +408,9 @@ void MultiplyElements(const AArrayType& a, const BArrayType& b, CArrayType* c) {
// The index starts at the maximum value for each dimension
const typename CArrayType::Index& cShape = c->Shape();
for (int i = 0; i < CArrayType::Index::SIZE; ++i)
for (int i = 0; i < CArrayType::Index::SIZE; ++i) {
index(i) = cShape(i) - 1;
}
// After each multiplication, the highest-dimensional index is reduced.
// if this reduces it less than zero, it resets to its maximum value

@ -35,8 +35,9 @@ namespace libmv {
/// is inside the image.
template <class Image, class Color>
inline void safePutPixel(int yc, int xc, const Color& col, Image* pim) {
if (!pim)
if (!pim) {
return;
}
if (pim->Contains(yc, xc)) {
(*pim)(yc, xc) = col;
}
@ -46,11 +47,13 @@ inline void safePutPixel(int yc, int xc, const Color& col, Image* pim) {
/// \note The color pointer col must have size as the image depth
template <class Image, class Color>
inline void safePutPixel(int yc, int xc, const Color* col, Image* pim) {
if (!pim)
if (!pim) {
return;
}
if (pim->Contains(yc, xc)) {
for (int i = 0; i < pim->Depth(); ++i)
for (int i = 0; i < pim->Depth(); ++i) {
(*pim)(yc, xc, i) = *(col + i);
}
}
}
@ -195,8 +198,9 @@ void DrawLine(int xa, int ya, int xb, int yb, const Color& col, Image* pim) {
&yup = ydir ? ny0 : ny1, &xdown = ydir ? nx1 : nx0,
&ydown = ydir ? ny1 : ny0;
if (xright < 0 || xleft >= width)
if (xright < 0 || xleft >= width) {
return;
}
if (xleft < 0) {
yleft -= xleft * (yright - yleft) / (xright - xleft);
xleft = 0;
@ -205,8 +209,9 @@ void DrawLine(int xa, int ya, int xb, int yb, const Color& col, Image* pim) {
yright -= (xright - width) * (yright - yleft) / (xright - xleft);
xright = width - 1;
}
if (ydown < 0 || yup >= height)
if (ydown < 0 || yup >= height) {
return;
}
if (yup < 0) {
xup -= yup * (xdown - xup) / (ydown - yup);
yup = 0;

@ -50,16 +50,18 @@ struct AsymmetricError {
static void Residuals(const Mat& H, const Mat& x1, const Mat& x2, Mat2X* dx) {
dx->resize(2, x1.cols());
Mat3X x2h_est;
if (x1.rows() == 2)
if (x1.rows() == 2) {
x2h_est = H * EuclideanToHomogeneous(static_cast<Mat2X>(x1));
else
} else {
x2h_est = H * x1;
}
dx->row(0) = x2h_est.row(0).array() / x2h_est.row(2).array();
dx->row(1) = x2h_est.row(1).array() / x2h_est.row(2).array();
if (x2.rows() == 2)
if (x2.rows() == 2) {
*dx = x2 - *dx;
else
} else {
*dx = HomogeneousToEuclidean(static_cast<Mat3X>(x2)) - *dx;
}
}
/**
* Computes the asymmetric residuals between a 2D point x2 and the transformed
@ -75,15 +77,17 @@ struct AsymmetricError {
*/
static void Residuals(const Mat& H, const Vec& x1, const Vec& x2, Vec2* dx) {
Vec3 x2h_est;
if (x1.rows() == 2)
if (x1.rows() == 2) {
x2h_est = H * EuclideanToHomogeneous(static_cast<Vec2>(x1));
else
} else {
x2h_est = H * x1;
if (x2.rows() == 2)
}
if (x2.rows() == 2) {
*dx = x2 - x2h_est.head<2>() / x2h_est[2];
else
} else {
*dx = HomogeneousToEuclidean(static_cast<Vec3>(x2)) -
x2h_est.head<2>() / x2h_est[2];
}
}
/**
* Computes the squared norm of the residuals between a set of 2D points x2
@ -190,14 +194,16 @@ struct AlgebraicError {
*/
static void Residuals(const Mat& H, const Vec& x1, const Vec& x2, Vec3* dx) {
Vec3 x2h_est;
if (x1.rows() == 2)
if (x1.rows() == 2) {
x2h_est = H * EuclideanToHomogeneous(static_cast<Vec2>(x1));
else
} else {
x2h_est = H * x1;
if (x2.rows() == 2)
}
if (x2.rows() == 2) {
*dx = SkewMat(EuclideanToHomogeneous(static_cast<Vec2>(x2))) * x2h_est;
else
} else {
*dx = SkewMat(x2) * x2h_est;
}
// TODO(julien) This is inefficient since it creates an
// identical 3x3 skew matrix for each evaluation.
}

@ -183,10 +183,11 @@ double Depth(const Mat3& R, const Vec3& t, const Vec4& X);
inline bool isInFrontOfCamera(const Mat34& P, const Vec4& X) {
double condition_1 = P.row(2).dot(X) * X[3];
double condition_2 = X[2] * X[3];
if (condition_1 > 0 && condition_2 > 0)
if (condition_1 > 0 && condition_2 > 0) {
return true;
else
} else {
return false;
}
}
inline bool isInFrontOfCamera(const Mat34& P, const Vec3& X) {

@ -229,12 +229,15 @@ class Dogleg {
}
Scalar rho = actual / predicted;
if (step == GAUSS_NEWTON)
if (step == GAUSS_NEWTON) {
printf(" GAUSS");
if (step == STEEPEST_DESCENT)
}
if (step == STEEPEST_DESCENT) {
printf(" STEE");
if (step == DOGLEG)
}
if (step == DOGLEG) {
printf(" DOGL");
}
printf(" %12g %12g %12g\n", rho, actual, predicted);

@ -158,10 +158,11 @@ template <typename TMat, typename TVec>
double Nullspace(TMat* A, TVec* nullspace) {
Eigen::JacobiSVD<TMat> svd(*A, Eigen::ComputeFullV);
(*nullspace) = svd.matrixV().col(A->cols() - 1);
if (A->rows() >= A->cols())
if (A->rows() >= A->cols()) {
return svd.singularValues()(A->cols() - 1);
else
} else {
return 0.0;
}
}
// Solve the linear system Ax = 0 via SVD. Finds two solutions, x1 and x2, such
@ -174,10 +175,11 @@ double Nullspace2(TMat* A, TVec1* x1, TVec2* x2) {
Eigen::JacobiSVD<TMat> svd(*A, Eigen::ComputeFullV);
*x1 = svd.matrixV().col(A->cols() - 1);
*x2 = svd.matrixV().col(A->cols() - 2);
if (A->rows() >= A->cols())
if (A->rows() >= A->cols()) {
return svd.singularValues()(A->cols() - 1);
else
} else {
return 0.0;
}
}
// In place transpose for square matrices.

@ -47,8 +47,9 @@ template<typename _Tp> struct MEM_Allocator {
_Tp *allocate(size_type __n, const void * = 0)
{
_Tp *__ret = NULL;
if (__n)
if (__n) {
__ret = static_cast<_Tp *>(MEM_mallocN(__n * sizeof(_Tp), "STL MEM_Allocator"));
}
return __ret;
}

@ -196,8 +196,9 @@ template<class T> class MEM_CacheLimiter {
while (!queue.empty() && mem_in_use > max) {
MEM_CacheElementPtr elem = get_least_priority_destroyable_element();
if (!elem)
if (!elem) {
break;
}
if (data_size_func) {
cur_size = data_size_func(elem->get()->get_data());
@ -255,24 +256,27 @@ template<class T> class MEM_CacheLimiter {
return false;
}
if (item_destroyable_func) {
if (!item_destroyable_func(elem->get()->get_data()))
if (!item_destroyable_func(elem->get()->get_data())) {
return false;
}
}
return true;
}
MEM_CacheElementPtr get_least_priority_destroyable_element(void)
{
if (queue.empty())
if (queue.empty()) {
return NULL;
}
MEM_CacheElementPtr best_match_elem = NULL;
if (!item_priority_func) {
for (iterator it = queue.begin(); it != queue.end(); it++) {
MEM_CacheElementPtr elem = *it;
if (!can_destroy_element(elem))
if (!can_destroy_element(elem)) {
continue;
}
best_match_elem = elem;
break;
}
@ -284,8 +288,9 @@ template<class T> class MEM_CacheLimiter {
for (i = 0; i < queue.size(); i++) {
MEM_CacheElementPtr elem = queue[i];
if (!can_destroy_element(elem))
if (!can_destroy_element(elem)) {
continue;
}
/* By default 0 means highest priority element. */
/* Casting a size type to int is questionable,

@ -106,8 +106,9 @@ class AtomicHashSet {
/* Get next power of two. Could be done more effiently with builtin_clz, but this is not
* performance-critical. */
kAnchorMask_ = 1;
while (kAnchorMask_ < capacity_)
while (kAnchorMask_ < capacity_) {
kAnchorMask_ *= 2;
}
/* Get mask for lower bits. */
kAnchorMask_ -= 1;

@ -274,8 +274,9 @@ template<typename Mesh> class Mikktspace {
nrTSpaces = 0;
for (uint f = 0; f < nrFaces; f++) {
const uint verts = mesh.GetNumVerticesOfFace(f);
if (verts != 3 && verts != 4)
if (verts != 3 && verts != 4) {
continue;
}
uint tA = uint(triangles.size());
triangles.emplace_back(f, nrTSpaces);
@ -295,8 +296,9 @@ template<typename Mesh> class Mikktspace {
float distSQ_02 = (mesh.GetTexCoord(f, 2) - mesh.GetTexCoord(f, 0)).length_squared();
float distSQ_13 = (mesh.GetTexCoord(f, 3) - mesh.GetTexCoord(f, 1)).length_squared();
bool quadDiagIs_02;
if (distSQ_02 != distSQ_13)
if (distSQ_02 != distSQ_13) {
quadDiagIs_02 = (distSQ_02 < distSQ_13);
}
else {
distSQ_02 = (mesh.GetPosition(f, 2) - mesh.GetPosition(f, 0)).length_squared();
distSQ_13 = (mesh.GetPosition(f, 3) - mesh.GetPosition(f, 1)).length_squared();
@ -456,12 +458,15 @@ template<typename Mesh> class Mikktspace {
uint vertFlag = (1u << triangles[t].faceVertex[0]) | (1u << triangles[t].faceVertex[1]) |
(1u << triangles[t].faceVertex[2]);
uint missingFaceVertex = 0;
if ((vertFlag & 2) == 0)
if ((vertFlag & 2) == 0) {
missingFaceVertex = 1;
else if ((vertFlag & 4) == 0)
}
else if ((vertFlag & 4) == 0) {
missingFaceVertex = 2;
else if ((vertFlag & 8) == 0)
}
else if ((vertFlag & 8) == 0) {
missingFaceVertex = 3;
}
uint faceIdx = triangles[t].faceIdx;
float3 dstP = mesh.GetPosition(faceIdx, missingFaceVertex);
@ -533,12 +538,14 @@ template<typename Mesh> class Mikktspace {
const float lenOs2 = vOs.length_squared();
const float lenOt2 = vOt.length_squared();
const float fS = triangle.orientPreserving ? 1.0f : (-1.0f);
if (not_zero(lenOs2))
if (not_zero(lenOs2)) {
triangle.tangent = vOs * (fS / sqrtf(lenOs2));
}
// if this is a good triangle
if (not_zero(lenOs2) && not_zero(lenOt2))
if (not_zero(lenOs2) && not_zero(lenOt2)) {
triangle.groupWithAny = false;
}
}
});
@ -556,10 +563,12 @@ template<typename Mesh> class Mikktspace {
// if this happens the quad has extremely bad mapping!!
if (triangleA.orientPreserving != triangleB.orientPreserving) {
bool chooseOrientFirstTri = false;
if (triangleB.groupWithAny)
if (triangleB.groupWithAny) {
chooseOrientFirstTri = true;
else if (calcTexArea(t) >= calcTexArea(t + 1))
}
else if (calcTexArea(t) >= calcTexArea(t + 1)) {
chooseOrientFirstTri = true;
}
// force match
const uint t0 = chooseOrientFirstTri ? t : (t + 1);
@ -681,17 +690,21 @@ template<typename Mesh> class Mikktspace {
// track down vertex
const uint vertRep = group.vertexRepresentative;
uint i = 3;
if (triangle.vertices[0] == vertRep)
if (triangle.vertices[0] == vertRep) {
i = 0;
else if (triangle.vertices[1] == vertRep)
}
else if (triangle.vertices[1] == vertRep) {
i = 1;
else if (triangle.vertices[2] == vertRep)
}
else if (triangle.vertices[2] == vertRep) {
i = 2;
}
assert(i < 3);
// early out
if (triangle.group[i] != UNSET_ENTRY)
if (triangle.group[i] != UNSET_ENTRY) {
return;
}
if (triangle.groupWithAny) {
// first to group with a group-with-anything triangle
@ -704,8 +717,9 @@ template<typename Mesh> class Mikktspace {
}
}
if (triangle.orientPreserving != group.orientPreserving)
if (triangle.orientPreserving != group.orientPreserving) {
return;
}
triangle.group[i] = groupId;

@ -134,8 +134,9 @@ class GLComputeEvaluator {
{
(void)deviceContext; // not used
GLComputeEvaluator *instance = new GLComputeEvaluator();
if (instance->Compile(srcDesc, dstDesc, duDesc, dvDesc, duuDesc, duvDesc, dvvDesc))
if (instance->Compile(srcDesc, dstDesc, duDesc, dvDesc, duuDesc, duvDesc, dvvDesc)) {
return instance;
}
delete instance;
return NULL;
}

@ -150,12 +150,14 @@ template<class T> inline int PatchMap::transformUVToQuadQuadrant(T const &median
{
int uHalf = (u >= median);
if (uHalf)
if (uHalf) {
u -= median;
}
int vHalf = (v >= median);
if (vHalf)
if (vHalf) {
v -= median;
}
return (vHalf << 1) | uHalf;
}
@ -207,13 +209,15 @@ inline PatchMap::Handle const *PatchMap::FindPatch(int faceid, double u, double
// to holes or otherwise unassigned (the root node for a patch will
// have all or no quadrants set):
//
if ((faceid < _minPatchFace) || (faceid > _maxPatchFace))
if ((faceid < _minPatchFace) || (faceid > _maxPatchFace)) {
return 0;
}
QuadNode const *node = &_quadtree[faceid - _minPatchFace];
if (!node->children[0].isSet)
if (!node->children[0].isSet) {
return 0;
}
//
// Search the tree for the sub-patch containing the given (u,v)

@ -743,13 +743,16 @@ BLI_INLINE int lineart_intersect_seg_seg(const double a1[2],
if (LRT_DOUBLE_CLOSE_ENOUGH(b1[0], b2[0])) {
y = interpd(a2[1], a1[1], ratio);
if (y > MAX2(b1[1], b2[1]) || y < MIN2(b1[1], b2[1]))
if (y > MAX2(b1[1], b2[1]) || y < MIN2(b1[1], b2[1])) {
return 0;
}
}
else if (ratio <= 0 || ratio > 1 || (b1[0] > b2[0] && x > b1[0]) ||
(b1[0] < b2[0] && x < b1[0]) || (b2[0] > b1[0] && x > b2[0]) ||
(b2[0] < b1[0] && x < b2[0]))
{
return 0;
}
if (LRT_DOUBLE_CLOSE_ENOUGH_TRI(*r_ratio, 1)) {
*r_ratio = 1;

@ -42,16 +42,18 @@ class FormatHandler : NonCopyable, NonMovable {
/* Write contents to the buffer(s) into a file, and clear the buffers. */
void write_to_file(FILE *f)
{
for (const auto &b : blocks_)
for (const auto &b : blocks_) {
fwrite(b.data(), 1, b.size(), f);
}
blocks_.clear();
}
std::string get_as_string() const
{
std::string s;
for (const auto &b : blocks_)
for (const auto &b : blocks_) {
s.append(b.data(), b.size());
}
return s;
}
size_t get_block_count() const