[Bf-blender-cvs] [a628ca9] master: Update Carve to upstream version be054bc7ed86
Sergey Sharybin
noreply at git.blender.org
Thu Nov 28 09:01:09 CET 2013
Commit: a628ca9ebe3a5296e197f12adf5988cb37f6050b
Author: Sergey Sharybin
Date: Thu Nov 28 13:51:17 2013 +0600
http://developer.blender.org/rBa628ca9ebe3a5296e197f12adf5988cb37f6050b
Update Carve to upstream version be054bc7ed86
===================================================================
M extern/carve/include/carve/aabb.hpp
M extern/carve/include/carve/aabb_impl.hpp
M extern/carve/include/carve/csg.hpp
M extern/carve/include/carve/debug_hooks.hpp
M extern/carve/include/carve/face_impl.hpp
M extern/carve/include/carve/geom.hpp
M extern/carve/include/carve/geom2d.hpp
M extern/carve/include/carve/geom3d.hpp
M extern/carve/include/carve/geom_impl.hpp
M extern/carve/include/carve/interpolator.hpp
M extern/carve/include/carve/mesh.hpp
M extern/carve/include/carve/mesh_impl.hpp
M extern/carve/include/carve/polyhedron_impl.hpp
M extern/carve/include/carve/polyline_decl.hpp
M extern/carve/include/carve/polyline_impl.hpp
M extern/carve/include/carve/rtree.hpp
M extern/carve/include/carve/win32.h
M extern/carve/lib/geom2d.cpp
M extern/carve/lib/intersect.cpp
M extern/carve/lib/intersect_face_division.cpp
===================================================================
diff --git a/extern/carve/include/carve/aabb.hpp b/extern/carve/include/carve/aabb.hpp
index 20ee028..c2fb2f6 100644
--- a/extern/carve/include/carve/aabb.hpp
+++ b/extern/carve/include/carve/aabb.hpp
@@ -120,6 +120,12 @@ namespace carve {
template<unsigned ndim>
std::ostream &operator<<(std::ostream &o, const aabb<ndim> &a);
+ template<unsigned ndim>
+ double distance2(const aabb<3> &a, const vector<ndim> &v);
+
+ template<unsigned ndim>
+ double distance(const aabb<3> &a, const vector<ndim> &v);
+
template<unsigned ndim, typename obj_t>
diff --git a/extern/carve/include/carve/aabb_impl.hpp b/extern/carve/include/carve/aabb_impl.hpp
index ccdddef..9564885 100644
--- a/extern/carve/include/carve/aabb_impl.hpp
+++ b/extern/carve/include/carve/aabb_impl.hpp
@@ -316,6 +316,23 @@ namespace carve {
return o;
}
+ template<unsigned ndim>
+ double distance2(const aabb<3> &a, const vector<ndim> &v) {
+ double d2 = 0.0;
+ for (unsigned i = 0; i < ndim; ++i) {
+ double d = ::fabs(v.v[i] - a.pos.v[i]) - a.extent.v[i];
+ if (d > 0.0) {
+ d2 += d * d;
+ }
+ }
+ return d2;
+ }
+
+ template<unsigned ndim>
+ double distance(const aabb<3> &a, const vector<ndim> &v) {
+ return ::sqrt(distance2(a, v));
+ }
+
template<>
inline bool aabb<3>::intersects(const ray<3> &ray) const {
vector<3> t = pos - ray.v;
diff --git a/extern/carve/include/carve/csg.hpp b/extern/carve/include/carve/csg.hpp
index b098cd8..92b03a4 100644
--- a/extern/carve/include/carve/csg.hpp
+++ b/extern/carve/include/carve/csg.hpp
@@ -87,6 +87,11 @@ namespace carve {
const meshset_t::face_t * /* orig_face */,
bool /* flipped */) {
}
+ virtual void edgeDivision(const meshset_t::edge_t * /* orig_edge */,
+ size_t /* orig_edge_idx */,
+ const meshset_t::vertex_t * /* v1 */,
+ const meshset_t::vertex_t * /* v2 */) {
+ }
virtual ~Hook() {
}
@@ -103,11 +108,13 @@ namespace carve {
RESULT_FACE_HOOK = 0,
PROCESS_OUTPUT_FACE_HOOK = 1,
INTERSECTION_VERTEX_HOOK = 2,
- HOOK_MAX = 3,
+ EDGE_DIVISION_HOOK = 3,
+ HOOK_MAX = 4,
RESULT_FACE_BIT = 0x0001,
PROCESS_OUTPUT_FACE_BIT = 0x0002,
- INTERSECTION_VERTEX_BIT = 0x0004
+ INTERSECTION_VERTEX_BIT = 0x0004,
+ EDGE_DIVISION_BIT = 0x0008
};
std::vector<std::list<Hook *> > hooks;
@@ -125,6 +132,11 @@ namespace carve {
const meshset_t::face_t *orig_face,
bool flipped);
+ void edgeDivision(const meshset_t::edge_t *orig_edge,
+ size_t orig_edge_idx,
+ const meshset_t::vertex_t *v1,
+ const meshset_t::vertex_t *v2);
+
void registerHook(Hook *hook, unsigned hook_bits);
void unregisterHook(Hook *hook);
diff --git a/extern/carve/include/carve/debug_hooks.hpp b/extern/carve/include/carve/debug_hooks.hpp
index 9ef7fc8..d942a82 100644
--- a/extern/carve/include/carve/debug_hooks.hpp
+++ b/extern/carve/include/carve/debug_hooks.hpp
@@ -35,11 +35,11 @@ void map_histogram(std::ostream &out, const MAP &map) {
}
hist[n]++;
}
- int total = map.size();
+ int total = (int)map.size();
std::string bar(50, '*');
for (size_t i = 0; i < hist.size(); i++) {
if (hist[i] > 0) {
- out << std::setw(5) << i << " : " << std::setw(5) << hist[i] << " " << bar.substr(50 - hist[i] * 50 / total) << std::endl;
+ out << std::setw(5) << i << " : " << std::setw(5) << hist[i] << " " << bar.substr((size_t)(50 - hist[i] * 50 / total)) << std::endl;
}
}
}
diff --git a/extern/carve/include/carve/face_impl.hpp b/extern/carve/include/carve/face_impl.hpp
index 771ba76..e1a9ed3 100644
--- a/extern/carve/include/carve/face_impl.hpp
+++ b/extern/carve/include/carve/face_impl.hpp
@@ -42,7 +42,9 @@ namespace carve {
template<unsigned ndim>
template<typename iter_t>
Face<ndim> *Face<ndim>::init(const Face<ndim> *base, iter_t vbegin, iter_t vend, bool flipped) {
- vertices.reserve(std::distance(vbegin, vend));
+ CARVE_ASSERT(vbegin < vend);
+
+ vertices.reserve((size_t)std::distance(vbegin, vend));
if (flipped) {
std::reverse_copy(vbegin, vend, std::back_inserter(vertices));
diff --git a/extern/carve/include/carve/geom.hpp b/extern/carve/include/carve/geom.hpp
index 421083e..360f14f 100644
--- a/extern/carve/include/carve/geom.hpp
+++ b/extern/carve/include/carve/geom.hpp
@@ -138,6 +138,9 @@ namespace carve {
template<unsigned ndim, typename iter_t, typename adapt_t>
void bounds(iter_t begin, iter_t end, adapt_t adapt, vector<ndim> &min, vector<ndim> &max);
+ template<unsigned ndim, typename iter_t>
+ void centroid(iter_t begin, iter_t end, vector<ndim> &c);
+
template<unsigned ndim, typename iter_t, typename adapt_t>
void centroid(iter_t begin, iter_t end, adapt_t adapt, vector<ndim> &c);
@@ -300,6 +303,7 @@ namespace carve {
aabb<ndim> getAABB() const;
+ tri() { }
tri(vector_t _v[3]);
tri(const vector_t &a, const vector_t &b, const vector_t &c);
diff --git a/extern/carve/include/carve/geom2d.hpp b/extern/carve/include/carve/geom2d.hpp
index 731e229..ef10b68 100644
--- a/extern/carve/include/carve/geom2d.hpp
+++ b/extern/carve/include/carve/geom2d.hpp
@@ -347,7 +347,7 @@ namespace carve {
PolyInclusionInfo pointInPoly(const std::vector<T> &points, adapt_t adapt, const P2 &p) {
P2Vector::size_type l = points.size();
for (unsigned i = 0; i < l; i++) {
- if (equal(adapt(points[i]), p)) return PolyInclusionInfo(POINT_VERTEX, i);
+ if (equal(adapt(points[i]), p)) return PolyInclusionInfo(POINT_VERTEX, (int)i);
}
for (unsigned i = 0; i < l; i++) {
@@ -358,7 +358,7 @@ namespace carve {
std::min(adapt(points[i]).y, adapt(points[j]).y) - EPSILON < p.y &&
std::max(adapt(points[i]).y, adapt(points[j]).y) + EPSILON > p.y &&
distance2(carve::geom::rayThrough(adapt(points[i]), adapt(points[j])), p) < EPSILON2) {
- return PolyInclusionInfo(POINT_EDGE, i);
+ return PolyInclusionInfo(POINT_EDGE, (int)i);
}
}
diff --git a/extern/carve/include/carve/geom3d.hpp b/extern/carve/include/carve/geom3d.hpp
index faeb565..fda43cc 100644
--- a/extern/carve/include/carve/geom3d.hpp
+++ b/extern/carve/include/carve/geom3d.hpp
@@ -45,56 +45,57 @@ namespace carve {
template<typename iter_t, typename adapt_t>
bool fitPlane(iter_t begin, iter_t end, adapt_t adapt, Plane &plane) {
- Vector centroid;
- carve::geom::centroid(begin, end, adapt, centroid);
- iter_t i;
+ std::vector<Vector> p;
+ for (; begin != end; ++begin) {
+ p.push_back(adapt(*begin));
+ }
- Vector n = Vector::ZERO();
- Vector v;
- Vector p1, p2, p3, c1, c2;
- if (begin == end) return false;
+ if (p.size() < 3) {
+ return false;
+ }
- i = begin;
- p1 = c1 = adapt(*i); if (++i == end) return false;
- p2 = c2 = adapt(*i); if (++i == end) return false;
+ Vector C;
+ carve::geom::centroid(p.begin(), p.end(), C);
-#if defined(CARVE_DEBUG)
- size_t N = 2;
-#endif
- do {
- p3 = adapt(*i);
- v = cross(p3 - p2, p1 - p2);
- if (v.v[largestAxis(v)]) v.negate();
- n += v;
- p1 = p2; p2 = p3;
-#if defined(CARVE_DEBUG)
- ++N;
-#endif
- } while (++i != end);
+ Vector n;
+
+ if (p.size() == 3) {
+ n = cross(p[1] - p[0], p[2] - p[0]);
+ } else {
+ const size_t N = p.size();
+
+ n = cross(p[N-1] - C, p[0] - C);
+ if (n < Vector::ZERO()) n.negate();
+ for (size_t i = 1; i < p.size(); ++i) {
+ Vector v = cross(p[i] - C, p[i-1] - C);
+ if (v < Vector::ZERO()) v.negate();
+ n += v;
+ }
+ }
- p1 = p2; p2 = p3; p3 = c1;
- v = cross(p3 - p2, p1 - p2);
- if (v.v[largestAxis(v)]) v.negate();
- n += v;
+ double l = n.length();
- p1 = p2; p2 = p3; p3 = c2;
- v = cross(p3 - p2, p1 - p2);
- if (v.v[largestAxis(v)]) v.negate();
- n += v;
+ if (l == 0.0) {
+ n.x = 1.0;
+ n.y = 0.0;
+ n.z = 0.0;
+ } else {
+ n.normalize();
+ }
- n.normalize();
plane.N = n;
- plane.d = -dot(n, centroid);
+ plane.d = -dot(n, C);
+
#if defined(CARVE_DEBUG)
- if (N > 3) {
- std::cerr << "N = " << N << " fitted distance:";
- for (i = begin; i != end; ++i) {
- Vector p = adapt(*i);
- std::cerr << " {" << p << "} " << distance(plane, p);
+ if (p.size() > 3) {
+ std::cerr << "N-gon with " << p.size() << " vertices: fitted distance:";
+ for (size_t i = 0; i < N; ++i) {
+ std::cerr << " {" << p[i] << "} " << distance(plane, p[i]);
}
std::cerr << std::endl;
}
#endif
+
return true;
}
diff --git a/extern/carve/include/carve/geom_impl.hpp b/extern/carve/include/carve/geom_impl.hpp
index 044655b..c4b6a9d 100644
--- a/extern/carve/include/carve/geom_impl.hpp
+++ b/extern/carve/include/carve/geom_impl.hpp
@@ -26,13 +26,26 @@ namespace carve {
template<unsigned ndim>
double vector<ndim>::length2() const { return dot(*this, *this); }
+
template<unsigned ndim>
double vector<ndim>::length() const { return sqrt(dot(*this, *this)); }
template<unsigned ndim>
- vector<ndim> &vector<ndim>::normalize() { *this /= length(); return *this; }
+ vector<ndim> &vector<ndim>::normalize() {
+#if defined(CARVE_DEBUG)
+ CARVE_ASSERT(length() > 0.0);
+#endif
+ *this /= length();
+ return *this;
+ }
+
template<unsigned ndim>
- vector<ndim> vector<ndim>::normalized() const { return *this
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list