Skip to content

Commit

Permalink
Merge pull request #10 from Forceflow/merge_14
Browse files Browse the repository at this point in the history
Merged upstream 2.14 release
  • Loading branch information
Forceflow authored Jul 28, 2019
2 parents fa23779 + a5b4895 commit 02175db
Show file tree
Hide file tree
Showing 22 changed files with 855 additions and 611 deletions.
2 changes: 1 addition & 1 deletion COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All other code distributed as part of trimesh2 is covered
by the following license:


Copyright (c) 2004-2018 Szymon Rusinkiewicz.
Copyright (c) 2004-2019 Szymon Rusinkiewicz.
All rights reserved.

This program is free software; you can redistribute it and/or
Expand Down
3 changes: 3 additions & 0 deletions Makerules
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ else
ifeq ($(ARCH),x86_64)
UNAME := Linux64
endif
ifeq ($(ARCH),aarch64)
UNAME := Linux64
endif
endif
ifeq ($(UNAME),Darwin)
IS64 := $(shell sysctl -n hw.cpu64bit_capable)
Expand Down
2 changes: 1 addition & 1 deletion gluit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ INCLUDES = -I../include -I../include/GL

include ../Makerules

COPTS += -Wno-unused-parameter -Wno-shadow
COPTS += -Wno-unused-parameter -Wno-shadow -Wno-implicit-fallthrough -Wno-cast-function-type -Wno-restrict -Wno-stringop-truncation

ifdef DONT_BUILD_FREEGLUT
CFILES =
Expand Down
2 changes: 2 additions & 0 deletions help/README
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ see how it's used. Here's a trivial program to help you get started:


#include "TriMesh.h"
#include <cstdlib>
#include <iostream>
using namespace trimesh;
using namespace std;

int main(int argc, char *argv[])
Expand Down
43 changes: 37 additions & 6 deletions include/KDtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,52 @@ class KDtree {
// Destructor - frees the whole tree
~KDtree();

// The queries: returns closest point to a point or a ray,
// provided it's within sqrt(maxdist2) and is compatible
// Returns closest point to a given point p,
// provided it's within sqrt(maxdist2) and is compatible.
// If an approximation epsilon is provided, the queries will
// return a point within a factor of (1+eps) of the closest.
const float *closest_to_pt(const float *p,
float maxdist2 = 0.0f,
const CompatFunc *iscompat = NULL) const;
const CompatFunc *iscompat = NULL,
float approx_eps = 0.0f) const;

// Shorthand with approx_eps but no iscompat
const float *closest_to_pt(const float *p,
float maxdist2,
float approx_eps) const
{ return closest_to_pt(p, maxdist2, NULL, approx_eps); }


// Returns closest point to a ray through p in direction dir
const float *closest_to_ray(const float *p, const float *dir,
float maxdist2 = 0.0f,
const CompatFunc *iscompat = NULL) const;
const CompatFunc *iscompat = NULL,
float approx_eps = 0.0f) const;

// Shorthand with approx_eps but no iscompat
const float *closest_to_ray(const float *p, const float *dir,
float maxdist2,
float approx_eps) const
{ return closest_to_ray(p, dir, maxdist2, NULL, approx_eps); }

// Find the k nearest neighbors
// Find the k nearest neighbors to p, filling in knn array
void find_k_closest_to_pt(::std::vector<const float *> &knn,
int k,
const float *p,
float maxdist2 = 0.0f,
const CompatFunc *iscompat = NULL) const;
const CompatFunc *iscompat = NULL,
float approx_eps = 0.0f) const;

// Shorthand with approx_eps but no iscompat
void find_k_closest_to_pt(::std::vector<const float *> &knn,
int k,
const float *p,
float maxdist2,
float approx_eps) const
{ return find_k_closest_to_pt(knn, k, p, maxdist2, NULL, approx_eps); }

// Is there a point within a given distance of a query?
bool exists_pt_within(const float *p, float maxdist) const;
};

} // namespace trimesh
Expand Down
10 changes: 10 additions & 0 deletions include/TriMesh_algo.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@ extern void find_overlap(TriMesh *mesh1, TriMesh *mesh2,
const KDtree *kd1, const KDtree *kd2,
float &area, float &rmsdist);

// Return intersection over union between mesh1 and mesh2
extern float iou(TriMesh *mesh1, TriMesh *mesh2);

extern float iou(TriMesh *mesh1, TriMesh *mesh2,
const xform &xf1, const xform &xf2);

extern float iou(TriMesh *mesh1, TriMesh *mesh2,
const xform &xf1, const xform &xf2,
const KDtree *kd1, const KDtree *kd2);

// Find separate mesh vertices that should be "shared": they lie on separate
// connected components, but they are within "tol" of each other.
extern void shared(TriMesh *mesh, float tol);
Expand Down
4 changes: 3 additions & 1 deletion include/XForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,9 @@ static inline void orthogonalize(XForm<T> &xf)
}


// Interpolate between xforms
// Interpolate between xforms, returning an xform that's a fraction "a" of
// the way from x to y. Performs screw decomposition, interpolates rotation
// and translation along screw axis, and constructs in-plane translation.
template <class T, class S>
static inline XForm<T> mix(const XForm<T> &x, const XForm<T> &y, const S &a)
{
Expand Down
21 changes: 12 additions & 9 deletions include/mathutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ static inline T fract(const T &x)
template <class T, class A, class B>
static inline T clamp(const T &x, const A &a, const B &b)
{
return (x > a) ? (x < b) ? x : T(b) : T(a); // returns a if x is NaN
return (x > T(a)) ? (x < T(b)) ? x : T(b) : T(a); // returns a if x is NaN
}

template <class T, class A>
Expand All @@ -241,7 +241,7 @@ static inline T mix(const T &x, const T &y, const A &a)
template <class T, class A>
static inline T step(const A &a, const T &x)
{
return (x < a) ? T(0) : T(1);
return (x < T(a)) ? T(0) : T(1);
}

template <class T, class A, class B>
Expand All @@ -256,16 +256,19 @@ static inline T smoothstep(const A &a, const B &b, const T &x)

// Fast, portable pseudorandom number generator using Marsaglia's xorshift.
// Returns random unsigned int. Pass in 0 to reset.
static inline unsigned xorshift_rnd(unsigned n = 1)
static inline unsigned xorshift_rnd(unsigned n = ~0u)
{
static unsigned x = 2463534242u;
if (unlikely(!n)) {
x = 2463534242u;
return 0;
if (likely(n == ~0u)) {
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
return x;
}
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
if (!n)
x = 2463534242u;
else
x = n;
return x;
}

Expand Down
73 changes: 46 additions & 27 deletions libsrc/GLManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ struct GLManager::UniformInfo
{
string name;
GLenum type;
UniformInfo() : type(GL_FLOAT)
GLint location;
UniformInfo() : type(GL_FLOAT), location(-1)
{}
};

Expand All @@ -401,8 +402,9 @@ struct GLManager::AttributeInfo
const float *p;
int floats_per_attribute;
size_t stride, offset;
GLint location;
AttributeInfo() : buf(0), p(0),
floats_per_attribute(0), stride(0), offset(0)
floats_per_attribute(0), stride(0), offset(0), location(-1)
{}
};

Expand Down Expand Up @@ -623,6 +625,7 @@ unsigned GLManager::make_shader(const char *name,
ui.type = type;
if (type == GL_SAMPLER_2D)
shaders.back()->texunit_binding.push_back(0);
ui.location = glGetUniformLocation(program, &uname[0]);
}

// Buggy on some drivers...
Expand All @@ -643,6 +646,7 @@ unsigned GLManager::make_shader(const char *name,
ai.floats_per_attribute = 3 * size;
else if (type == GL_FLOAT_VEC4)
ai.floats_per_attribute = 4 * size;
ai.location = glGetAttribLocation(program, &aname[0]);
}

// Make this shader active
Expand Down Expand Up @@ -700,7 +704,7 @@ bool GLManager::use_shader(unsigned ind)
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
for (size_t i = 0; i < current_shader->attribute_info.size(); i++)
if (current_shader->have_attribute[i])
glDisableVertexAttribArray(i);
glDisableVertexAttribArray(current_shader->attribute_info[i].location);

// Find new shader
for (size_t i = 0; i < shaders.size(); i++) {
Expand Down Expand Up @@ -757,9 +761,9 @@ bool GLManager::use_shader(unsigned ind)
continue;
AttributeInfo &ai = current_shader->attribute_info[i];
if (ai.buf)
attributearray(i, ai.floats_per_attribute, ai.buf, ai.stride, ai.offset);
attributearray(ai.location, ai.floats_per_attribute, ai.buf, ai.stride, ai.offset);
else if (ai.p)
attributearray(i, ai.floats_per_attribute, ai.p, ai.stride, ai.offset);
attributearray(ai.location, ai.floats_per_attribute, ai.p, ai.stride, ai.offset);
}

// Bind the textures we're using
Expand Down Expand Up @@ -822,16 +826,20 @@ bool GLManager::uniform_boilerplate(int ind, unsigned type)
eprintf("GLManager::uniform : no active shader program\n");
return false;
}
if (ind < 0 || ind >= (int) current_shader->have_uniform.size()) {
size_t which = 0;
for (which = 0; which < current_shader->uniform_info.size(); which++)
if (current_shader->uniform_info[which].location == ind)
break;
if (which == current_shader->uniform_info.size()) {
eprintf("GLManager::uniform : invalid uniform\n");
return false;
}
if (current_shader->uniform_info[ind].type != (GLenum) type) {
if (current_shader->uniform_info[which].type != (GLenum) type) {
eprintf("GLManager::uniform : type mismatch specifying uniform %s\n",
current_shader->uniform_info[ind].name.c_str());
current_shader->uniform_info[which].name.c_str());
return false;
}
current_shader->have_uniform[ind] = true;
current_shader->have_uniform[which] = true;
return true;
}

Expand Down Expand Up @@ -901,19 +909,23 @@ void GLManager::attributearray(int ind, int floats_per_attribute,
eprintf("GLManager::attribute : no active shader program\n");
return;
}
if (ind < 0 || ind >= (int) current_shader->have_attribute.size()) {
size_t which = 0;
for (which = 0; which < current_shader->attribute_info.size(); which++)
if (current_shader->attribute_info[which].location == ind)
break;
if (which == current_shader->attribute_info.size()) {
eprintf("GLManager::attribute : invalid attribute\n");
return;
}
if (current_shader->attribute_info[ind].floats_per_attribute !=
if (current_shader->attribute_info[which].floats_per_attribute !=
floats_per_attribute) {
eprintf("GLManager::attribute : type mismatch specifying attribute %s\n",
current_shader->attribute_info[ind].name.c_str());
current_shader->attribute_info[which].name.c_str());
return;
}
use_buffer();
current_shader->have_attribute[ind] = true;
AttributeInfo &ai = current_shader->attribute_info[ind];
current_shader->have_attribute[which] = true;
AttributeInfo &ai = current_shader->attribute_info[which];
ai.buf = 0;
ai.p = p;
ai.stride = stride;
Expand All @@ -932,19 +944,23 @@ void GLManager::attributearray(int ind, int floats_per_attribute, unsigned buf,
eprintf("GLManager::attribute : no active shader program\n");
return;
}
if (ind < 0 || ind >= (int) current_shader->have_attribute.size()) {
size_t which = 0;
for (which = 0; which < current_shader->attribute_info.size(); which++)
if (current_shader->attribute_info[which].location == ind)
break;
if (which == current_shader->attribute_info.size()) {
eprintf("GLManager::attribute : invalid attribute\n");
return;
}
AttributeInfo &ai = current_shader->attribute_info[ind];
AttributeInfo &ai = current_shader->attribute_info[which];
if (ai.floats_per_attribute != floats_per_attribute) {
eprintf("GLManager::attribute : type mismatch specifying attribute %s\n",
current_shader->attribute_info[ind].name.c_str());
current_shader->attribute_info[which].name.c_str());
return;
}
if (!use_buffer(buf))
return;
current_shader->have_attribute[ind] = true;
current_shader->have_attribute[which] = true;
ai.buf = buf;
ai.p = 0;
ai.stride = stride;
Expand All @@ -962,17 +978,21 @@ bool GLManager::attribute_boilerplate(int ind, int floats_per_attribute)
eprintf("GLManager::attribute : no active shader program\n");
return false;
}
if (ind < 0 || ind >= (int) current_shader->have_attribute.size()) {
size_t which = 0;
for (which = 0; which < current_shader->attribute_info.size(); which++)
if (current_shader->attribute_info[which].location == ind)
break;
if (which == current_shader->attribute_info.size()) {
eprintf("GLManager::attribute : invalid attribute\n");
return false;
}
AttributeInfo &ai = current_shader->attribute_info[ind];
AttributeInfo &ai = current_shader->attribute_info[which];
if (ai.floats_per_attribute != floats_per_attribute) {
eprintf("GLManager::attribute : type mismatch specifying attribute %s\n",
current_shader->attribute_info[ind].name.c_str());
current_shader->attribute_info[which].name.c_str());
return false;
}
current_shader->have_attribute[ind] = true;
current_shader->have_attribute[which] = true;
ai.buf = 0;
ai.p = 0;
ai.stride = 0;
Expand Down Expand Up @@ -1625,10 +1645,8 @@ bool GLManager::shader_ready()

// Check uniforms
for (size_t i = 0; i < current_shader->have_uniform.size(); i++) {
if (current_shader->have_uniform[i])
continue;
if (strncmp(current_shader->uniform_info[i].name.c_str(),
"gl_", 3) == 0)
if (current_shader->uniform_info[i].location < 0 ||
current_shader->have_uniform[i])
continue;
eprintf("GLManager::shader_ready : shader %s failed to set uniform %s\n",
current_shader->name.c_str(),
Expand All @@ -1638,7 +1656,8 @@ bool GLManager::shader_ready()

// Check attributes
for (size_t i = 0; i < current_shader->have_attribute.size(); i++) {
if (current_shader->have_attribute[i])
if (current_shader->attribute_info[i].location < 0 ||
current_shader->have_attribute[i])
continue;
const char *aname = current_shader->attribute_info[i].name.c_str();
if (strcmp(aname, current_shader->vertex_info.name.c_str()) == 0 && current_shader->have_vertex)
Expand Down
Loading

0 comments on commit 02175db

Please sign in to comment.