[Bf-blender-cvs] [3a5273458cb] soc-2019-fast-io: [Fast import/export] Refactored iterators and added code to test copying data

Hugo Sales noreply at git.blender.org
Fri Jun 14 14:44:15 CEST 2019


Commit: 3a5273458cb4759816e8869fc44364b96335adc0
Author: Hugo Sales
Date:   Fri Jun 14 13:42:31 2019 +0100
Branches: soc-2019-fast-io
https://developer.blender.org/rB3a5273458cb4759816e8869fc44364b96335adc0

[Fast import/export] Refactored iterators and added code to test copying data

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

M	release/scripts/addons
M	release/scripts/addons_contrib
M	source/blender/editors/io/CMakeLists.txt
M	source/blender/editors/io/intern/common.cpp
M	source/blender/editors/io/intern/common.hpp
A	source/blender/editors/io/intern/iterators.hpp
M	source/blender/editors/io/intern/obj.cpp
M	source/blender/editors/io/intern/stl.cpp
M	source/tools

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

diff --git a/release/scripts/addons b/release/scripts/addons
index 290ed760cb8..fcf7d4c16b1 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 290ed760cb83079f7889fafab8f7bb7383736d54
+Subproject commit fcf7d4c16b17c34579fc080386425e0774a502d2
diff --git a/release/scripts/addons_contrib b/release/scripts/addons_contrib
index 929e9e75703..97fa83e16f2 160000
--- a/release/scripts/addons_contrib
+++ b/release/scripts/addons_contrib
@@ -1 +1 @@
-Subproject commit 929e9e75703444689704cad809f5af1ffad6c9b0
+Subproject commit 97fa83e16f290b24f0a9c50153c2469b68b8c0aa
diff --git a/source/blender/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt
index 5904d9f131f..684b5efcbf1 100644
--- a/source/blender/editors/io/CMakeLists.txt
+++ b/source/blender/editors/io/CMakeLists.txt
@@ -54,10 +54,11 @@ set(SRC
 
   intern/obj.cpp
   intern/obj.h
-  intern/common.cpp
-  intern/common.hpp
   intern/stl.cpp
   intern/stl.h
+  intern/common.cpp
+  intern/common.hpp
+  intern/iterators.hpp
 )
 
 set(LIB
@@ -87,4 +88,6 @@ if(WITH_INTERNATIONAL)
   add_definitions(-DWITH_INTERNATIONAL)
 endif()
 
+add_definitions(-Wfatal-errors)
+
 blender_add_lib(bf_editor_io "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/editors/io/intern/common.cpp b/source/blender/editors/io/intern/common.cpp
index 6653e935fb2..3f29341071a 100644
--- a/source/blender/editors/io/intern/common.cpp
+++ b/source/blender/editors/io/intern/common.cpp
@@ -25,6 +25,7 @@ extern "C" {
 #include <chrono>
 
 #include "common.hpp"
+#include "iterators.hpp"
 
 // Anonymous namespace for internal functions
 namespace {
@@ -78,8 +79,9 @@ bool object_type_is_exportable(const Object *const ob)
   switch (ob->type) {
     case OB_MESH:
       return !object_is_smoke_sim(ob);
-      /* case OB_CURVE: */
-      /* case OB_SURF: */
+    case OB_CURVE:
+    case OB_SURF:
+      return true;
     case OB_LAMP:
     case OB_EMPTY:
     case OB_CAMERA:
@@ -232,7 +234,7 @@ bool export_end(bContext *UNUSED(C), ExportSettings *const settings)
 bool time_export(bContext *C,
                  ExportSettings *const settings,
                  void (*start)(bContext *C, ExportSettings *const settings),
-                 void (*end)(bContext *C, ExportSettings *const settings))
+                 bool (*end)(bContext *C, ExportSettings *const settings))
 {
   auto f = std::chrono::steady_clock::now();
   start(C, settings);
@@ -247,4 +249,73 @@ const std::array<float, 3> calculate_normal(const Mesh *const mesh, const MPoly
   BKE_mesh_calc_poly_normal(&mp, mesh->mloop + mp.loopstart, mesh->mvert, no);
   return std::array<float, 3>{no[0], no[1], no[2]};
 }
+
+std::vector<std::array<float, 3>> get_normals(const Mesh *const mesh)
+{
+  std::vector<std::array<float, 3>> normals{};
+  normals.reserve(mesh->totvert);
+  const float(*loop_no)[3] = static_cast<float(*)[3]>(
+      CustomData_get_layer(&mesh->ldata, CD_NORMAL));
+  unsigned loop_index = 0;
+  MVert *verts = mesh->mvert;
+  MPoly *mp = mesh->mpoly;
+  MLoop *mloop = mesh->mloop;
+  MLoop *ml = mloop;
+
+  // TODO someone Should -0 be converted to 0?
+  if (loop_no) {
+    for (int i = 0, e = mesh->totpoly; i < e; ++i, ++mp) {
+      ml = mesh->mloop + mp->loopstart + (mp->totloop - 1);
+      for (int j = 0; j < mp->totloop; --ml, ++j, ++loop_index) {
+        const float(&no)[3] = loop_no[ml->v];
+        normals.push_back(std::array<float, 3>{no[0], no[1], no[2]});
+      }
+    }
+  }
+  else {
+    float no[3];
+    for (int i = 0, e = mesh->totpoly; i < e; ++i, ++mp) {
+      ml = mloop + mp->loopstart + (mp->totloop - 1);
+
+      /* Flat shaded, use common normal for all verts. */
+      if ((mp->flag & ME_SMOOTH) == 0) {
+        BKE_mesh_calc_poly_normal(mp, ml - (mp->totloop - 1), verts, no);
+        normals.push_back(std::array<float, 3>{no[0], no[1], no[2]});
+        ml -= mp->totloop;
+        loop_index += mp->totloop;
+      }
+      else {
+        /* Smooth shaded, use individual vert normals. */
+        for (int j = 0; j < mp->totloop; --ml, ++j, ++loop_index) {
+          normal_short_to_float_v3(no, verts[ml->v].no);
+          normals.push_back(std::array<float, 3>{no[0], no[1], no[2]});
+        }
+      }
+    }
+  }
+  normals.shrink_to_fit();
+  return normals;
+}
+std::vector<std::array<float, 2>> get_uv(const Mesh *const mesh)
+{
+  std::vector<std::array<float, 2>> uvs{};
+  uvs.reserve(mesh->totloop);
+  for (int i = 0, e = mesh->totloop; i < e; ++i) {
+    const float(&uv)[2] = mesh->mloopuv[i].uv;
+    uvs.push_back(std::array<float, 2>{uv[0], uv[1]});
+  }
+  return uvs;
+}
+
+std::vector<std::array<float, 3>> get_vertices(const Mesh *const mesh)
+{
+  std::vector<std::array<float, 3>> vxs{};
+  vxs.reserve(mesh->totvert);
+  for (int i = 0, e = mesh->totvert; i < e; ++i) {
+    const MVert &v = mesh->mvert[i];
+    vxs.push_back(std::array<float, 3>{v.co[0], v.co[1], v.co[2]});
+  }
+  return vxs;
+}
+
 }  // namespace common
diff --git a/source/blender/editors/io/intern/common.hpp b/source/blender/editors/io/intern/common.hpp
index 6f4dc39ef2d..0d8a9e17dfc 100644
--- a/source/blender/editors/io/intern/common.hpp
+++ b/source/blender/editors/io/intern/common.hpp
@@ -7,53 +7,52 @@
 /* #include "DNA_object_types.h" */
 
 extern "C" {
+/* clang-format off */
+#include "BKE_global.h"
+#include "BKE_mesh.h"
+#include "BKE_mesh_runtime.h"
+#include "BKE_modifier.h"
+#include "BKE_library.h"
+#include "BKE_customdata.h"
+#include "BKE_scene.h"
 
-#  include "BKE_global.h"
-#  include "BKE_mesh.h"
-#  include "BKE_mesh_runtime.h"
-#  include "BKE_modifier.h"
-#  include "BKE_library.h"
-#  include "BKE_customdata.h"
-#  include "BKE_scene.h"
-
-#  include "MEM_guardedalloc.h"
+#include "MEM_guardedalloc.h"
 
 /* SpaceType struct has a member called 'new' which obviously conflicts with C++
  * so temporarily redefining the new keyword to make it compile. */
-#  define new extern_new
-#  include "BKE_screen.h"
-#  undef new
+#define new extern_new
+#include "BKE_screen.h"
+#undef new
 
-#  include "BLI_listbase.h"
-#  include "BLI_math_matrix.h"
-#  include "BLI_math_vector.h"
-#  include "BLI_utildefines.h"
+#include "BLI_listbase.h"
+#include "BLI_math_matrix.h"
+#include "BLI_math_vector.h"
+#include "BLI_utildefines.h"
 
-#  include "bmesh.h"
-#  include "bmesh_tools.h"
+#include "bmesh.h"
+#include "bmesh_tools.h"
 
-#  include "DNA_layer_types.h"
-#  include "DNA_meshdata_types.h"
-#  include "DNA_mesh_types.h"
-#  include "DNA_modifier_types.h"
-#  include "DNA_object_types.h"
+#include "DNA_layer_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
 
-#  include "DEG_depsgraph_build.h"
-#  include "DEG_depsgraph_query.h"
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
 
-#  include "../io_common.h"
+#include "../io_common.h"
 }
 
-#  include <utility>
-#  include <string>
-#  include <vector>
-#  include <set>
-#  include <array>
-#  include <typeinfo>
-#  include <iterator>
+#include <utility>
+#include <string>
+#include <vector>
+#include <set>
+#include <array>
+#include <typeinfo>
+#include <iterator>
 
-#  include <boost/iterator/iterator_facade.hpp>
-#  include <boost/iterator/iterator_adaptor.hpp>
+/* clang-format on */
 
 namespace common {
 using ulong = unsigned long;
@@ -90,491 +89,12 @@ bool time_export(bContext *C,
 
 const std::array<float, 3> calculate_normal(const Mesh *const mesh, const MPoly &mp);
 
-// --- TEMPLATES ---
-
-// Adapt a pointer-size pair as a random access iterator
-// This makes use of `boost::iterator_facade` and makes it possible to use
-// for each style loops, as well as cleanly hiding how the underlying Blender
-// data structures are accessed
-template<typename SourceT, typename Tag = std::random_access_iterator_tag>
-struct pointer_iterator
-    : public boost::iterator_facade<pointer_iterator<SourceT, Tag>, SourceT &, Tag> {
-  pointer_iterator() : first(nullptr)
-  {
-  }
-  pointer_iterator(const pointer_iterator<SourceT, Tag> &) = default;
-  pointer_iterator(pointer_iterator<SourceT, Tag> &&) = default;
-  explicit pointer_iterator(SourceT *p) : it(p), first(p), size(0)
-  {
-  }
-  explicit pointer_iterator(SourceT *p, size_t size) : it(p), first(p), size(size)
-  {
-  }
-  operator SourceT *() const
-  {
-    return it;
-  }
-  pointer_iterator &operator=(const pointer_iterator<SourceT, Tag> &p)
-  {
-    // Placement new: construct a new object in the position of `this`
-    // Doesn't actually allocate memory
-    new (this) pointer_iterator(p);
-    return *this;
-  }
-  // pointer_iterator & operator=(pointer_iterator<SourceT, Tag> &&p) = default;//  {
-  // 	return pointer_iterator<SourceT, Tag>(p);
-  // }
-  pointer_iterator begin() const
-  {
-    return pointer_iterator{first, size};
-  }
-  const pointer_iterator cbegin() const
-  {
-    return pointer_iterator{first, size};
-  }
-  pointer_iterator end() const
-  {
-    return pointer_iterator{first + size, size};
-  }
-  const pointer_iterator cend() const
-  {
-    return pointer_iterator{first + size, size};
-  }
-  friend class boost::iterator_core_access;
-  void increment()
-  {
-    ++it;
-  }
-  void decrement()
-  {
-    --it;
-  }
-  void advance(ptrdiff_t n)
-  {
-    it += n;
-  }
-  ptrdiff_t distance_to(const pointer_iterator &other)
-  {
-    return other.it - it;
-  }
-  bool equal(const pointer_iterator &other) const
-  {
-    return it == other.it;
-  }
-  SourceT &dereference() const
-  {
-    return *this->it;
-  }
-  SourceT *it;
-  SourceT *const first;
-  size_t size;
-};
-
-// This is another iterator, whcih makes use of `boost::iterator_adaptor` to change  how the
-// underlying iterator behaves. Specifically, it uses the derived class' `dereference` method. This
-// makes use of CRTP, the curiously recurring template pattern This means that the base class has,
-// as a template paramater, the type of the derived class which means that it can hold a pointer to
-// said derived class and call it's `dereference` method.
-template<typename SourceT,
-         typename ResT,
-         typename CRTP,
-         typename Base = poin

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list