ClangFormat: apply to source, most of intern
[blender.git] / intern / opensubdiv / internal / opensubdiv_converter_factory.cc
index 0e8af7b..0c1514f 100644 (file)
 #include "opensubdiv_converter_capi.h"
 
 using opensubdiv_capi::min;
-using opensubdiv_capi::vector;
 using opensubdiv_capi::stack;
+using opensubdiv_capi::vector;
 
 struct TopologyRefinerData {
-  const OpenSubdiv_Converterconverter;
+  const OpenSubdiv_Converter *converter;
 };
 
 namespace OpenSubdiv {
 namespace OPENSUBDIV_VERSION {
 namespace Far {
 
-template <>
-inline bool
-TopologyRefinerFactory<TopologyRefinerData>::resizeComponentTopology(
-    TopologyRefiner& refiner,
-    const TopologyRefinerData& cb_data) {
-  const OpenSubdiv_Converter* converter = cb_data.converter;
+template<>
+inline bool TopologyRefinerFactory<TopologyRefinerData>::resizeComponentTopology(
+    TopologyRefiner &refiner, const TopologyRefinerData &cb_data)
+{
+  const OpenSubdiv_Converter *converter = cb_data.converter;
   // Faces and face-vertices.
   const int num_faces = converter->getNumFaces(converter);
   setNumBaseFaces(refiner, num_faces);
   for (int face_index = 0; face_index < num_faces; ++face_index) {
-    const int num_face_vertices =
-        converter->getNumFaceVertices(converter, face_index);
+    const int num_face_vertices = converter->getNumFaceVertices(converter, face_index);
     setNumBaseFaceVertices(refiner, face_index, num_face_vertices);
   }
   // Vertices.
@@ -70,31 +68,26 @@ TopologyRefinerFactory<TopologyRefinerData>::resizeComponentTopology(
   const int num_edges = converter->getNumEdges(converter);
   setNumBaseEdges(refiner, num_edges);
   for (int edge_index = 0; edge_index < num_edges; ++edge_index) {
-    const int num_edge_faces =
-        converter->getNumEdgeFaces(converter, edge_index);
+    const int num_edge_faces = converter->getNumEdgeFaces(converter, edge_index);
     setNumBaseEdgeFaces(refiner, edge_index, num_edge_faces);
   }
   // Vertex-faces and vertex-edges.
   for (int vertex_index = 0; vertex_index < num_vertices; ++vertex_index) {
-    const int num_vert_edges =
-        converter->getNumVertexEdges(converter, vertex_index);
-    const int num_vert_faces =
-        converter->getNumVertexFaces(converter, vertex_index);
+    const int num_vert_edges = converter->getNumVertexEdges(converter, vertex_index);
+    const int num_vert_faces = converter->getNumVertexFaces(converter, vertex_index);
     setNumBaseVertexEdges(refiner, vertex_index, num_vert_edges);
     setNumBaseVertexFaces(refiner, vertex_index, num_vert_faces);
   }
   return true;
 }
 
-template <>
-inline bool
-TopologyRefinerFactory<TopologyRefinerData>::assignComponentTopology(
-    TopologyRefiner& refiner,
-    const TopologyRefinerData& cb_data) {
+template<>
+inline bool TopologyRefinerFactory<TopologyRefinerData>::assignComponentTopology(
+    TopologyRefiner &refiner, const TopologyRefinerData &cb_data)
+{
   using Far::IndexArray;
-  const OpenSubdiv_Converter* converter = cb_data.converter;
-  const bool full_topology_specified =
-          converter->specifiesFullTopology(converter);
+  const OpenSubdiv_Converter *converter = cb_data.converter;
+  const bool full_topology_specified = converter->specifiesFullTopology(converter);
   // Face relations.
   const int num_faces = converter->getNumFaces(converter);
   for (int face_index = 0; face_index < num_faces; ++face_index) {
@@ -125,47 +118,41 @@ TopologyRefinerFactory<TopologyRefinerData>::assignComponentTopology(
   for (int vertex_index = 0; vertex_index < num_vertices; ++vertex_index) {
     // Vertex-faces.
     IndexArray dst_vertex_faces = getBaseVertexFaces(refiner, vertex_index);
-    const int num_vertex_faces =
-        converter->getNumVertexFaces(converter, vertex_index);
+    const int num_vertex_faces = converter->getNumVertexFaces(converter, vertex_index);
     vertex_faces.resize(num_vertex_faces);
     converter->getVertexFaces(converter, vertex_index, &vertex_faces[0]);
     // Vertex-edges.
     IndexArray dst_vertex_edges = getBaseVertexEdges(refiner, vertex_index);
-    const int num_vertex_edges =
-        converter->getNumVertexEdges(converter, vertex_index);
+    const int num_vertex_edges = converter->getNumVertexEdges(converter, vertex_index);
     vertex_edges.resize(num_vertex_edges);
     converter->getVertexEdges(converter, vertex_index, &vertex_edges[0]);
-    memcpy(&dst_vertex_edges[0], &vertex_edges[0],
-           sizeof(int) * num_vertex_edges);
-    memcpy(&dst_vertex_faces[0], &vertex_faces[0],
-           sizeof(int) * num_vertex_faces);
+    memcpy(&dst_vertex_edges[0], &vertex_edges[0], sizeof(int) * num_vertex_edges);
+    memcpy(&dst_vertex_faces[0], &vertex_faces[0], sizeof(int) * num_vertex_faces);
   }
   populateBaseLocalIndices(refiner);
   return true;
 }
 
-template <>
+template<>
 inline bool TopologyRefinerFactory<TopologyRefinerData>::assignComponentTags(
-    TopologyRefiner& refiner,
-    const TopologyRefinerData& cb_data) {
+    TopologyRefiner &refiner, const TopologyRefinerData &cb_data)
+{
   using OpenSubdiv::Sdc::Crease;
-  const OpenSubdiv_Converter* converter = cb_data.converter;
-  const bool full_topology_specified =
-          converter->specifiesFullTopology(converter);
+  const OpenSubdiv_Converter *converter = cb_data.converter;
+  const bool full_topology_specified = converter->specifiesFullTopology(converter);
   const int num_edges = converter->getNumEdges(converter);
   for (int edge_index = 0; edge_index < num_edges; ++edge_index) {
-    const float sharpness =
-        converter->getEdgeSharpness(converter, edge_index);
+    const float sharpness = converter->getEdgeSharpness(converter, edge_index);
     if (sharpness < 1e-6f) {
       continue;
     }
     if (full_topology_specified) {
       setBaseEdgeSharpness(refiner, edge_index, sharpness);
-    } else {
+    }
+    else {
       int edge_vertices[2];
       converter->getEdgeVertices(converter, edge_index, edge_vertices);
-      const int base_edge_index = findBaseEdge(
-          refiner, edge_vertices[0], edge_vertices[1]);
+      const int base_edge_index = findBaseEdge(refiner, edge_vertices[0], edge_vertices[1]);
       if (base_edge_index == OpenSubdiv::Far::INDEX_INVALID) {
         printf("OpenSubdiv Error: failed to find reconstructed edge\n");
         return false;
@@ -181,8 +168,7 @@ inline bool TopologyRefinerFactory<TopologyRefinerData>::assignComponentTags(
   for (int vertex_index = 0; vertex_index < num_vertices; ++vertex_index) {
     ConstIndexArray vertex_edges = getBaseVertexEdges(refiner, vertex_index);
     if (converter->isInfiniteSharpVertex(converter, vertex_index)) {
-      setBaseVertexSharpness(
-          refiner, vertex_index, Crease::SHARPNESS_INFINITE);
+      setBaseVertexSharpness(refiner, vertex_index, Crease::SHARPNESS_INFINITE);
       continue;
     }
     float sharpness = converter->getVertexSharpness(converter, vertex_index);
@@ -192,19 +178,18 @@ inline bool TopologyRefinerFactory<TopologyRefinerData>::assignComponentTags(
       const float sharpness1 = refiner._levels[0]->getEdgeSharpness(edge1);
       // TODO(sergey): Find a better mixing between edge and vertex sharpness.
       sharpness += min(sharpness0, sharpness1);
-      sharpness = min(sharpness, 1.0f);
+      sharpness = min(sharpness, 10.0f);
     }
     setBaseVertexSharpness(refiner, vertex_index, sharpness);
   }
   return true;
 }
 
-template <>
-inline bool
-TopologyRefinerFactory<TopologyRefinerData>::assignFaceVaryingTopology(
-    TopologyRefiner& refiner,
-    const TopologyRefinerData& cb_data) {
-  const OpenSubdiv_Converter* converter = cb_data.converter;
+template<>
+inline bool TopologyRefinerFactory<TopologyRefinerData>::assignFaceVaryingTopology(
+    TopologyRefiner &refiner, const TopologyRefinerData &cb_data)
+{
+  const OpenSubdiv_Converter *converter = cb_data.converter;
   const int num_layers = converter->getNumUVLayers(converter);
   if (num_layers <= 0) {
     // No UV maps, we can skip any face-varying data.
@@ -219,11 +204,9 @@ TopologyRefinerFactory<TopologyRefinerData>::assignFaceVaryingTopology(
     // TODO(sergey): Need to check whether converter changed the winding of
     // face to match OpenSubdiv's expectations.
     for (int face_index = 0; face_index < num_faces; ++face_index) {
-      Far::IndexArray dst_face_uvs =
-          getBaseFaceFVarValues(refiner, face_index, channel);
+      Far::IndexArray dst_face_uvs = getBaseFaceFVarValues(refiner, face_index, channel);
       for (int corner = 0; corner < dst_face_uvs.size(); ++corner) {
-        const int uv_index =
-           converter->getFaceCornerUVIndex(converter, face_index, corner);
+        const int uv_index = converter->getFaceCornerUVIndex(converter, face_index, corner);
         dst_face_uvs[corner] = uv_index;
       }
     }
@@ -232,10 +215,10 @@ TopologyRefinerFactory<TopologyRefinerData>::assignFaceVaryingTopology(
   return true;
 }
 
-template <>
+template<>
 inline void TopologyRefinerFactory<TopologyRefinerData>::reportInvalidTopology(
-    TopologyError /*errCode*/, const char* msg,
-    const TopologyRefinerData& /*mesh*/) {
+    TopologyError /*errCode*/, const char *msg, const TopologyRefinerData & /*mesh*/)
+{
   printf("OpenSubdiv Error: %s\n", msg);
 }
 
@@ -247,9 +230,9 @@ namespace opensubdiv_capi {
 
 namespace {
 
-OpenSubdiv::Sdc::Options::VtxBoundaryInterpolation
-getVtxBoundaryInterpolationFromCAPI(
-    OpenSubdiv_VtxBoundaryInterpolation boundary_interpolation) {
+OpenSubdiv::Sdc::Options::VtxBoundaryInterpolation getVtxBoundaryInterpolationFromCAPI(
+    OpenSubdiv_VtxBoundaryInterpolation boundary_interpolation)
+{
   using OpenSubdiv::Sdc::Options;
   switch (boundary_interpolation) {
     case OSD_VTX_BOUNDARY_NONE:
@@ -265,31 +248,28 @@ getVtxBoundaryInterpolationFromCAPI(
 
 }  // namespace
 
-OpenSubdiv::Far::TopologyRefinercreateOSDTopologyRefinerFromConverter(
-    OpenSubdiv_Converter* converter) {
-  using OpenSubdiv::Sdc::Options;
+OpenSubdiv::Far::TopologyRefiner *createOSDTopologyRefinerFromConverter(
+    OpenSubdiv_Converter *converter)
+{
   using OpenSubdiv::Far::TopologyRefinerFactory;
-  const OpenSubdiv::Sdc::SchemeType scheme_type =
-      getSchemeTypeFromCAPI(converter->getSchemeType(converter));
-  const Options::FVarLinearInterpolation linear_interpolation =
-      getFVarLinearInterpolationFromCAPI(
-          converter->getFVarLinearInterpolation(converter));
+  using OpenSubdiv::Sdc::Options;
+  const OpenSubdiv::Sdc::SchemeType scheme_type = getSchemeTypeFromCAPI(
+      converter->getSchemeType(converter));
+  const Options::FVarLinearInterpolation linear_interpolation = getFVarLinearInterpolationFromCAPI(
+      converter->getFVarLinearInterpolation(converter));
   Options options;
   options.SetVtxBoundaryInterpolation(
-      getVtxBoundaryInterpolationFromCAPI(
-          converter->getVtxBoundaryInterpolation(converter)));
+      getVtxBoundaryInterpolationFromCAPI(converter->getVtxBoundaryInterpolation(converter)));
   options.SetCreasingMethod(Options::CREASE_UNIFORM);
   options.SetFVarLinearInterpolation(linear_interpolation);
 
-  TopologyRefinerFactory<TopologyRefinerData>::Options topology_options(
-      scheme_type, options);
+  TopologyRefinerFactory<TopologyRefinerData>::Options topology_options(scheme_type, options);
 #ifdef OPENSUBDIV_VALIDATE_TOPOLOGY
   topology_options.validateFullTopology = true;
 #endif
   TopologyRefinerData cb_data;
   cb_data.converter = converter;
-  return TopologyRefinerFactory<TopologyRefinerData>::Create(
-      cb_data, topology_options);
+  return TopologyRefinerFactory<TopologyRefinerData>::Create(cb_data, topology_options);
 }
 
 }  // namespace opensubdiv_capi