[Bf-blender-cvs] [4b40cce6716] soc-2020-io-performance: Cleanup: rename, comments.

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


Commit: 4b40cce6716016fe30612a07ca324afcc851a271
Author: Ankit Meel
Date:   Mon Nov 16 18:43:16 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB4b40cce6716016fe30612a07ca324afcc851a271

Cleanup: rename, comments.

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

M	source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
M	source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc
M	source/blender/io/wavefront_obj/exporter/obj_export_nurbs.hh
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/exporter/obj_export_file_writer.cc b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
index e096cae90ef..2fd0b3c918d 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
@@ -403,18 +403,17 @@ void OBJWriter::write_edges_indices(const OBJMesh &obj_mesh_data) const
  */
 void OBJWriter::write_nurbs_curve(const OBJCurve &obj_nurbs_data) const
 {
-  const int tot_nurbs = obj_nurbs_data.total_splines();
-  for (int i = 0; i < tot_nurbs; i++) {
-    /* Total control points in a nurbs. */
-    const int tot_points = obj_nurbs_data.total_nurbs_points(i);
-    for (int point_idx = 0; point_idx < tot_points; point_idx++) {
-      const float3 point_coord = obj_nurbs_data.get_nurbs_point_coords(
-          i, point_idx, export_params_.scaling_factor);
-      fprintf(outfile_, "v %f %f %f\n", point_coord[0], point_coord[1], point_coord[2]);
+  const int total_splines = obj_nurbs_data.total_splines();
+  for (int spline_idx = 0; spline_idx < total_splines; spline_idx++) {
+    const int total_vertices = obj_nurbs_data.total_spline_vertices(spline_idx);
+    for (int vertex_idx = 0; vertex_idx < total_vertices; vertex_idx++) {
+      const float3 vertex_coords = obj_nurbs_data.vertex_coordinates(
+          spline_idx, vertex_idx, export_params_.scaling_factor);
+      fprintf(outfile_, "v %f %f %f\n", vertex_coords[0], vertex_coords[1], vertex_coords[2]);
     }
 
     const char *nurbs_name = obj_nurbs_data.get_curve_name();
-    const int nurbs_degree = obj_nurbs_data.get_nurbs_degree(i);
+    const int nurbs_degree = obj_nurbs_data.get_nurbs_degree(spline_idx);
     fprintf(outfile_,
             "g %s\n"
             "cstype bspline\n"
@@ -422,22 +421,23 @@ void OBJWriter::write_nurbs_curve(const OBJCurve &obj_nurbs_data) const
             nurbs_name,
             nurbs_degree);
     /**
-     * The numbers here are indices into the vertex coordinates written
-     * above, relative to the line that is going to be written.
+     * The numbers written here are indices into the vertex coordinates written
+     * earlier, relative to the line that is going to be written.
      * [0.0 - 1.0] is the curve parameter range.
-     * 0.0 1.0 -1 -2 -3 -4 for a non-cyclic curve with 4 points.
-     * 0.0 1.0 -1 -2 -3 -4 -1 -2 -3 for a cyclic curve with 4 points.
+     * 0.0 1.0 -1 -2 -3 -4 for a non-cyclic curve with 4 vertices.
+     * 0.0 1.0 -1 -2 -3 -4 -1 -2 -3 for a cyclic curve with 4 vertices.
      */
-    const int total_control_points = obj_nurbs_data.get_nurbs_num(i);
+    const int total_control_points = obj_nurbs_data.total_spline_control_points(spline_idx);
     fputs("curv 0.0 1.0", outfile_);
     for (int i = 0; i < total_control_points; i++) {
-      /* "+1" to keep indices one-based, even if they're negative. */
-      fprintf(outfile_, " %d", -((i % tot_points) + 1));
+      /* "+1" to keep indices one-based, even if they're negative: i.e., -1 refers to the last
+       * vertex coordinate, -2 second last. */
+      fprintf(outfile_, " %d", -((i % total_vertices) + 1));
     }
     fputs("\n", outfile_);
 
     /**
-     * In "parm u 0 0.1 .." line:, total control points + 2 equidistant numbers in the parameter
+     * In "parm u 0 0.1 .." line:, (total control points + 2) equidistant numbers in the parameter
      * range are inserted.
      */
     fputs("parm u 0.000000 ", outfile_);
diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc
index bd040ee13b8..6e368c307a2 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc
@@ -68,20 +68,24 @@ int OBJCurve::total_splines() const
   return BLI_listbase_count(&export_curve_->nurb);
 }
 
-int OBJCurve::total_nurbs_points(const int spline_index) const
+/**
+ * \param spline_index: Zero-based index of spline of interest.
+ * \return: Total vertices in a spline.
+ */
+int OBJCurve::total_spline_vertices(const int spline_index) const
 {
-  const Nurb *nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
+  const Nurb *const nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
   return nurb->pntsu * nurb->pntsv;
 }
 
 /**
- * Get coordinates of the vertex at the given index.
+ * Get coordinates of the vertex at the given index on the given spline.
  */
-float3 OBJCurve::get_nurbs_point_coords(const int spline_index,
-                                        const int vertex_index,
-                                        const float scaling_factor) const
+float3 OBJCurve::vertex_coordinates(const int spline_index,
+                                    const int vertex_index,
+                                    const float scaling_factor) const
 {
-  const Nurb *nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
+  const Nurb *const nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
   float3 r_coord;
   const BPoint &bpoint = nurb->bp[vertex_index];
   copy_v3_v3(r_coord, bpoint.vec);
@@ -91,11 +95,12 @@ float3 OBJCurve::get_nurbs_point_coords(const int spline_index,
 }
 
 /**
- * Get total control points of the NURBS Curve at the given index.
+ * Get total control points of the NURBS spline at the given index. This is different than total
+ * vertices of a spline.
  */
-int OBJCurve::get_nurbs_num(const int spline_index) const
+int OBJCurve::total_spline_control_points(const int spline_index) const
 {
-  const Nurb *nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
+  const Nurb *const nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
   const int r_nurbs_degree = nurb->orderu - 1;
   /* Total control points = Number of points in the curve (+ degree of the
    * curve if it is cyclic). */
@@ -107,11 +112,11 @@ int OBJCurve::get_nurbs_num(const int spline_index) const
 }
 
 /**
- * Get the degree of the NURBS Curve at the given index.
+ * Get the degree of the NURBS spline at the given index.
  */
 int OBJCurve::get_nurbs_degree(const int spline_index) const
 {
-  const Nurb *nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
+  const Nurb *const nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
   return nurb->orderu - 1;
 }
 
diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.hh b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.hh
index ab5585eb520..6a34891ca8a 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.hh
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.hh
@@ -33,7 +33,7 @@ namespace blender::io::obj {
  * Provides access to the a Curve Object's properties.
  * Only #CU_NURBS type is supported.
  *
- * \note Used for Curves to be exported in parameter form, not converted to meshes.
+ * \note Used for Curves to be exported in parameter form, and not converted to meshes.
  */
 class OBJCurve : NonCopyable {
  private:
@@ -46,11 +46,11 @@ class OBJCurve : NonCopyable {
 
   const char *get_curve_name() const;
   int total_splines() const;
-  int total_nurbs_points(const int spline_index) const;
-  float3 get_nurbs_point_coords(const int spline_index,
-                                const int vertex_index,
-                                const float scaling_factor) const;
-  int get_nurbs_num(const int spline_index) const;
+  int total_spline_vertices(const int spline_index) const;
+  float3 vertex_coordinates(const int spline_index,
+                            const int vertex_index,
+                            const float scaling_factor) const;
+  int total_spline_control_points(const int spline_index) const;
   int get_nurbs_degree(const int spline_index) const;
 
  private:
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 79d54b5f410..1e65631e940 100644
--- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
+++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
@@ -125,12 +125,10 @@ TEST_F(Export_OBJ, OBJCurve)
     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_nurbs_points(spline_index),
-                nurbs_truth->total_nurbs_points(spline_index));
-      for (int vertex_index : IndexRange(objcurve->total_nurbs_points(spline_index))) {
-        EXPECT_V3_NEAR(objcurve->get_nurbs_point_coords(
+      for (int vertex_index : IndexRange(objcurve->total_spline_vertices(spline_index))) {
+        EXPECT_V3_NEAR(objcurve->vertex_coordinates(
                            spline_index, vertex_index, _export.params.scaling_factor),
-                       nurbs_truth->get_nurbs_point_coords(spline_index, vertex_index),
+                       nurbs_truth->vertex_coordinates(spline_index, vertex_index),
                        0.000001f);
       }
     }
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 56464aa1eb5..3d655e228c9 100644
--- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh
+++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh
@@ -19,8 +19,8 @@ namespace blender::io::obj {
 using array_float_3 = std::array<float, 3>;
 
 /**
- * This matches OBJCurve's member functions, except that all the numbers and names are known
- * constants. Used to store expected values of NURBS objects.
+ * This matches #OBJCurve's member functions, except that all the numbers and names are known
+ * constants. Used to store expected values of NURBS Curve sobjects.
  */
 class NurbsObject {
  private:
@@ -39,7 +39,7 @@ class NurbsObject {
     return coordinates_.size();
   }
 
-  int total_nurbs_points(const int spline_index) const
+  int total_spline_vertices(

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list