Commit: d2e83dc4b24476ca76fb5289fae63d7f4941abd0
Author: Hugo Sales
Date:   Wed Jun 5 17:37:07 2019 +0100
Branches: soc-2019-fast-io
https://developer.blender.org/rBd2e83dc4b24476ca76fb5289fae63d7f4941abd0

[Fast import/export] Fixed UV and deduplicated iterator, and other bug fixes

===================================================================

M       source/blender/editors/io/intern/common.hpp
M       source/blender/editors/io/intern/obj.cpp

===================================================================

diff --git a/source/blender/editors/io/intern/common.hpp 
b/source/blender/editors/io/intern/common.hpp
index 9b7aa398e70..4e6aef2674e 100644
--- a/source/blender/editors/io/intern/common.hpp
+++ b/source/blender/editors/io/intern/common.hpp
@@ -309,13 +309,23 @@ namespace common {
                return f;
        }
 
+       template<size_t N>
+       inline float too_similar(const std::array<float, N> &lhs, const 
std::array<float, N> &rhs,
+                                const float th) {
+               bool b = true;
+               for(int i = 0; i < N; ++i)
+                       b &= (lhs[i] - rhs[i]) < th;
+               return b;
+       }
+
        struct threshold_comparator {
-               threshold_comparator(const float th) : thsq(th * th) {}
+               threshold_comparator(const float th) : th(th) {}
                template<typename key_t>
                bool operator()(const key_t &lhs, const key_t &rhs) const {
-                       return len_sq(lhs.first, rhs.first) < thsq && lhs.first 
< rhs.first;
+                       return // too_similar(lhs.first, rhs.first, th) &&
+                               lhs.first < rhs.first;
                }
-               const float thsq;
+               const float th;
        };
 
        template<typename key_t>
@@ -337,35 +347,28 @@ namespace common {
                                                 SourceIter, ResT, Tag, ResT> {
                deduplicated_iterator() = default;
                explicit deduplicated_iterator(const Mesh * const mesh, 
dedup_pair_t<KeyT> &dp,
-                                              ulong &total, ulong reserve, 
SourceIter &&it)
+                                              ulong &total, SourceIter it)
                        : deduplicated_iterator::iterator_adaptor_(it), 
mesh(mesh),
-                         dedup_pair(dp), total(total) {
+                         dedup_pair(dp), total(total) {}
+               explicit deduplicated_iterator(const Mesh * const mesh, 
dedup_pair_t<KeyT> &dp,
+                                              ulong &total, ulong reserve)
+                       : deduplicated_iterator(mesh, dp, total, 
SourceIter{mesh}) {
                        // Reserve space so we don't constantly allocate
                        dedup_pair.second.reserve(reserve);
                        // Need to insert the first element, because we need to 
dereference before incrementing
-                       auto p = dedup_pair.first.insert(std::make_pair(*it, 
total));
+                       auto p = 
dedup_pair.first.insert(std::make_pair(*this->base(), total++));
                        dedup_pair.second.push_back(p.first);
+                       ++this->base_reference();
                }
-               explicit deduplicated_iterator(const Mesh * const mesh, 
dedup_pair_t<KeyT> &dp,
-                                              ulong &total, ulong reserve)
-                       : deduplicated_iterator(mesh, dp, total, reserve, 
SourceIter{mesh}) {}
-               deduplicated_iterator begin() const {
-                       return deduplicated_iterator(mesh, dedup_pair, total, 
total);
-               }
+               deduplicated_iterator begin() const { return *this; }
                deduplicated_iterator end() const {
-                       return deduplicated_iterator(mesh, dedup_pair, total, 
total, this->base().end());
-               }
-               const deduplicated_iterator cbegin() const {
-                       return deduplicated_iterator(mesh, dedup_pair, total, 
total);
-               }
-               const deduplicated_iterator cend() const {
-                       return deduplicated_iterator(mesh, dedup_pair, total, 
total, this->base().end());
-               }
+                       return deduplicated_iterator(mesh, dedup_pair, total, 
this->base().end()); }
                friend class boost::iterator_core_access;
                void increment() {
+                       // Handle everything until the next different element
                        while(this->base() != this->base().end()) {
+                               auto p = 
dedup_pair.first.insert(std::make_pair(*this->base(), total));
                                ++this->base_reference();
-                               auto p = 
dedup_pair.first.insert(std::make_pair(*this->base_reference(), total));
                                dedup_pair.second.push_back(p.first);
                                if (p.second) {
                                        ++total;
@@ -387,8 +390,7 @@ namespace common {
 
        struct deduplicated_uv_iter : deduplicated_iterator<uv_key_t, uv_iter> {
                deduplicated_uv_iter(const Mesh * const mesh, ulong &total, 
dedup_pair_t<uv_key_t> &dp)
-                       : deduplicated_iterator<uv_key_t, uv_iter>
-                       (mesh, dp, total, total + mesh->totloop) {}
+                       : deduplicated_iterator<uv_key_t, uv_iter>(mesh, dp, 
total, total + mesh->totloop) {}
        };
 
        // C++14/17 would be useful here...
diff --git a/source/blender/editors/io/intern/obj.cpp 
b/source/blender/editors/io/intern/obj.cpp
index 7582b7ccf62..2be32db3352 100644
--- a/source/blender/editors/io/intern/obj.cpp
+++ b/source/blender/editors/io/intern/obj.cpp
@@ -144,13 +144,16 @@ namespace {
 
                if (settings->export_normals) {
                        fs << std::fixed << std::setprecision(4);
-                       if (settings->dedup_normals)
-                               for (const std::array<float, 3> &no :
-                                            
common::deduplicated_normal_iter{mesh, no_total, no_mapping_pair})
-                                       fs << "vn " << no[0] << ' ' << no[1] << 
' ' << no[2] << '\n';
-                       else
-                               for (const std::array<float, 3> &no : 
common::normal_iter{mesh})
-                                       fs << "vn " << no[0] << ' ' << no[1] << 
' ' << no[2] << '\n';
+                       // if (settings->dedup_normals)
+                       //      for (const std::array<float, 3> &no :
+                       //                   
common::deduplicated_normal_iter{mesh, no_total, no_mapping_pair})
+                       //              fs << "vn " << no[0] << ' ' << no[1] << 
' ' << no[2] << '\n';
+                       // else
+                       for (const std::array<float, 3> &no : 
common::normal_iter{mesh}) {
+                               ++no_total;
+                               std::cerr << "vn " << no[0] << ' ' << no[1] << 
' ' << no[2] << '\n';
+                               fs << "vn " << no[0] << ' ' << no[1] << ' ' << 
no[2] << '\n';
+                       }
                }
 
                if (settings->export_edges) {
@@ -162,9 +165,6 @@ namespace {
                std::cerr << "Totals: "  << uv_total << " " << no_total
                          << "\nSizes: " << uv_mapping.size() << " " << 
no_mapping.size()  << '\n';
 
-               char c;
-               std::cin >> c;
-
                for (int p_i = 0, p_e = mesh->totpoly; p_i < p_e; ++p_i) {
                        fs << 'f';
                        MPoly *p = mesh->mpoly + p_i;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to