[Bf-blender-cvs] [9fc8ec77910] soc-2020-io-performance: Exporter: Add more OBJCurve tests

Ankit Meel noreply at git.blender.org
Mon Nov 16 15:33:37 CET 2020


Commit: 9fc8ec77910ff22398346a1b3cd9d5458251c543
Author: Ankit Meel
Date:   Mon Nov 16 20:01:59 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB9fc8ec77910ff22398346a1b3cd9d5458251c543

Exporter: Add more OBJCurve tests

File {F9302561}

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

M	source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
M	source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh

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

diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
index 6fd965f53ba..7fd9f7c725b 100644
--- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
+++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
@@ -105,6 +105,35 @@ TEST(obj_exporter_test_utils, append_positive_frame_to_filename)
   EXPECT_EQ_ARRAY(path_with_frame, path_truth, BLI_strlen_utf8(path_truth));
 }
 
+TEST_F(obj_exporter_test, OBJCurve_nurbs_points)
+{
+  if (!load_file_and_depsgraph(all_curve_objects_file)) {
+    ADD_FAILURE();
+    return;
+  }
+
+  OBJExportParamsDefault _export;
+  _export.params.export_curves_as_nurbs = true;
+  auto [objmeshes_unused, objcurves]{filter_supported_objects(depsgraph, _export.params)};
+
+  for (StealUniquePtr<OBJCurve> objcurve : objcurves) {
+    if (all_nurbs_truth.count(objcurve->get_curve_name()) != 1) {
+      ADD_FAILURE();
+      return;
+    }
+    const NurbsObject *const nurbs_truth = all_nurbs_truth.at(objcurve->get_curve_name()).get();
+    EXPECT_EQ(objcurve->total_splines(), nurbs_truth->total_splines());
+    for (int spline_index : IndexRange(objcurve->total_splines())) {
+      EXPECT_EQ(objcurve->total_spline_vertices(spline_index),
+                nurbs_truth->total_spline_vertices(spline_index));
+      EXPECT_EQ(objcurve->get_nurbs_degree(spline_index),
+                nurbs_truth->get_nurbs_degree(spline_index));
+      EXPECT_EQ(objcurve->total_spline_control_points(spline_index),
+                nurbs_truth->total_spline_control_points(spline_index));
+    }
+  }
+}
+
 TEST_F(obj_exporter_test, OBJCurve_coordinates)
 {
   if (!load_file_and_depsgraph(all_curve_objects_file)) {
diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh
index 39b4ec33894..d5ed833757a 100644
--- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh
+++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh
@@ -25,12 +25,20 @@ using array_float_3 = std::array<float, 3>;
 class NurbsObject {
  private:
   std::string nurbs_name_;
+  /* The indices in these vectors are spline indices. */
   std::vector<std::vector<array_float_3>> coordinates_;
+  std::vector<int> degrees_;
+  std::vector<int> control_points_;
 
  public:
   NurbsObject(const std::string nurbs_name,
-              const std::vector<std::vector<array_float_3>> coordinates)
-      : nurbs_name_(nurbs_name), coordinates_(coordinates)
+              const std::vector<std::vector<array_float_3>> coordinates,
+              const std::vector<int> degrees,
+              const std::vector<int> control_points)
+      : nurbs_name_(nurbs_name),
+        coordinates_(coordinates),
+        degrees_(degrees),
+        control_points_(control_points)
   {
   }
 
@@ -52,6 +60,16 @@ class NurbsObject {
   {
     return coordinates_[spline_index][vertex_index].data();
   }
+
+  int get_nurbs_degree(const int spline_index) const
+  {
+    return degrees_[spline_index];
+  }
+
+  int total_spline_control_points(const int spline_index) const
+  {
+    return control_points_[spline_index];
+  }
 };
 
 struct OBJExportParamsDefault {
@@ -97,7 +115,7 @@ const std::vector<std::vector<array_float_3>> coordinates_NurbsCircle{
      {10.463165, 0.000000, 1.000000},
      {10.463165, 0.000000, 0.000000},
      {10.463165, 0.000000, -1.000000}}};
-const std::vector<std::vector<array_float_3>> coordinates_NurbsPath{
+const std::vector<std::vector<array_float_3>> coordinates_NurbsPathCurve{
     {{17.690557, 0.000000, 0.000000},
      {16.690557, 0.000000, 0.000000},
      {15.690557, 0.000000, 0.000000},
@@ -110,12 +128,21 @@ const std::vector<std::vector<array_float_3>> coordinates_NurbsPath{
 
 const std::map<std::string, std::unique_ptr<NurbsObject>> all_nurbs_truth = []() {
   std::map<std::string, std::unique_ptr<NurbsObject>> all_nurbs;
-  all_nurbs.emplace("NurbsCurve",
-                    std::make_unique<NurbsObject>("NurbsCurve", coordinates_NurbsCurve));
-  all_nurbs.emplace("NurbsCircle",
-                    std::make_unique<NurbsObject>("NurbsCircle", coordinates_NurbsCircle));
-  all_nurbs.emplace("NurbsPath",
-                    std::make_unique<NurbsObject>("NurbsPath", coordinates_NurbsPath));
+  all_nurbs.emplace(
+      "NurbsCurve",
+      /* Name, coordinates, degrees of splines, control points of splines. */
+      std::make_unique<NurbsObject>(
+          "NurbsCurve", coordinates_NurbsCurve, std::vector<int>{3}, std::vector<int>{4}));
+  all_nurbs.emplace(
+      "NurbsCircle",
+      std::make_unique<NurbsObject>(
+          "NurbsCircle", coordinates_NurbsCircle, std::vector<int>{3}, std::vector<int>{11}));
+  /* This is actually an Object containing a NurbsPath and a NurbsCurve spline.  */
+  all_nurbs.emplace("NurbsPathCurve",
+                    std::make_unique<NurbsObject>("NurbsPathCurve",
+                                                  coordinates_NurbsPathCurve,
+                                                  std::vector<int>{3, 3},
+                                                  std::vector<int>{5, 4}));
   return all_nurbs;
 }();
 }  // namespace blender::io::obj



More information about the Bf-blender-cvs mailing list