Browse Source

Fix compilation issues.

Jeremie Dumas 3 years ago
parent
commit
54a4e4bafd

+ 1 - 3
include/igl/internal_angles.cpp

@@ -17,13 +17,11 @@ IGL_INLINE void igl::internal_angles(
   const Eigen::MatrixBase<DerivedF>& F,
   Eigen::PlainObjectBase<DerivedK> & K)
 {
-  using namespace Eigen;
-  using namespace std;
   typedef typename DerivedV::Scalar Scalar;
   if(F.cols() == 3)
   {
     // Edge lengths
-    Matrix<
+    Eigen::Matrix<
       Scalar,
       DerivedF::RowsAtCompileTime,
       DerivedF::ColsAtCompileTime> L_sq;

+ 2 - 4
include/igl/per_face_normals.cpp

@@ -42,8 +42,7 @@ IGL_INLINE void igl::per_face_normals(
   const Eigen::MatrixBase<DerivedF>& F,
   Eigen::PlainObjectBase<DerivedN> & N)
 {
-  using namespace Eigen;
-  Matrix<typename DerivedN::Scalar,3,1> Z(0,0,0);
+  Eigen::Matrix<typename DerivedN::Scalar,3,1> Z(0,0,0);
   return per_face_normals(V,F,Z,N);
 }
 
@@ -53,8 +52,7 @@ IGL_INLINE void igl::per_face_normals_stable(
   const Eigen::MatrixBase<DerivedF>& F,
   Eigen::PlainObjectBase<DerivedN> & N)
 {
-  using namespace Eigen;
-  typedef Matrix<typename DerivedV::Scalar,1,3> RowVectorV3;
+  typedef Eigen::Matrix<typename DerivedV::Scalar,1,3> RowVectorV3;
   typedef typename DerivedV::Scalar Scalar;
 
   const size_t m = F.rows();

+ 30 - 27
include/igl/tinyply.cpp

@@ -11,6 +11,8 @@
 #include <cstring>
 #include <cassert>
 
+namespace igl
+{
 namespace tinyply
 {
 template<typename T, typename T2> T2 endian_swap(const T & v) noexcept {assert(false);} //{ return v; }
@@ -174,9 +176,9 @@ IGL_INLINE int64_t find_property(const std::string & key, const std::vector<PlyP
 }
 
 // The `userData` table is an easy data structure for capturing what data the
-// user would like out of the ply file, but an inner-loop hash lookup is non-ideal. 
+// user would like out of the ply file, but an inner-loop hash lookup is non-ideal.
 // The property lookup table flattens the table down into a 2D array optimized
-// for parsing. The first index is the element, and the second index is the property. 
+// for parsing. The first index is the element, and the second index is the property.
 IGL_INLINE std::vector<std::vector<PlyFile::PlyFileImpl::PropertyLookup>> PlyFile::PlyFileImpl::make_property_lookup_table()
 {
     std::vector<std::vector<PropertyLookup>> element_property_lookup;
@@ -270,7 +272,7 @@ IGL_INLINE size_t PlyFile::PlyFileImpl::read_property_ascii(const Type & t, cons
     case Type::UINT32:     ply_cast_ascii<uint32_t>(dest, is);                break;
     case Type::FLOAT32:    ply_cast_ascii<float>(dest, is);                   break;
     case Type::FLOAT64:    ply_cast_ascii<double>(dest, is);                  break;
-    case Type::INVALID:    throw std::invalid_argument("invalid ply property"); 
+    case Type::INVALID:    throw std::invalid_argument("invalid ply property");
     }
     return stride;
 }
@@ -304,23 +306,23 @@ IGL_INLINE void PlyFile::PlyFileImpl::read(std::istream & is)
     std::vector<std::shared_ptr<PlyData>> buffers;
     for (auto & entry : userData) buffers.push_back(entry.second.data);
 
-    // Discover if we can allocate up front without parsing the file twice 
+    // Discover if we can allocate up front without parsing the file twice
     uint32_t list_hints = 0;
     for (auto & b : buffers) for (auto & entry : userData) {list_hints += entry.second.list_size_hint;(void)b;}
 
     // No list hints? Then we need to calculate how much memory to allocate
-    if (list_hints == 0) 
+    if (list_hints == 0)
     {
         parse_data(is, true);
     }
 
     // Count the number of properties (required for allocation)
     // e.g. if we have properties x y and z requested, we ensure
-    // that their buffer points to the same PlyData 
+    // that their buffer points to the same PlyData
     std::unordered_map<PlyData*, int32_t> unique_data_count;
     for (auto & ptr : buffers) unique_data_count[ptr.get()] += 1;
 
-    // Since group-requested properties share the same cursor, 
+    // Since group-requested properties share the same cursor,
     // we need to find unique cursors so we only allocate once
     std::sort(buffers.begin(), buffers.end());
     buffers.erase(std::unique(buffers.begin(), buffers.end()), buffers.end());
@@ -362,7 +364,7 @@ IGL_INLINE void PlyFile::PlyFileImpl::read(std::istream & is)
             uint8_t * data_ptr = b->buffer.get();
             const size_t stride = PropertyTable[b->t].stride;
             const size_t buffer_size_bytes = b->buffer.size_bytes();
-    
+
             switch (b->t)
             {
             case Type::INT16:   endian_swap_buffer<int16_t, int16_t>(data_ptr, buffer_size_bytes, stride);   break;
@@ -380,13 +382,13 @@ IGL_INLINE void PlyFile::PlyFileImpl::read(std::istream & is)
 IGL_INLINE void PlyFile::PlyFileImpl::write(std::ostream & os, bool _isBinary)
 {
     for (auto & d : userData) { d.second.cursor->byteOffset = 0; }
-    if (_isBinary) 
+    if (_isBinary)
     {
         isBinary = true;
         isBigEndian = false;
         write_binary_internal(os);
     }
-    else 
+    else
     {
         isBinary = false;
         isBigEndian = false;
@@ -412,7 +414,7 @@ IGL_INLINE void PlyFile::PlyFileImpl::write_binary_internal(std::ostream & os) n
         {
             size_t property_index = 0;
             for (auto & p : e.properties)
-            {   
+            {
                 auto & f = element_property_lookup[element_idx][property_index];
                 auto * helper = f.helper;
                 if (f.skip || helper == nullptr) continue;
@@ -535,14 +537,14 @@ IGL_INLINE std::shared_ptr<PlyData> PlyFile::PlyFileImpl::request_properties_fro
 
         // Each key in `propertyKey` gets an entry into the userData map (keyed by a hash of
         // element name and property name), but groups of properties (requested from the
-        // public api through this function) all share the same `ParsingHelper`. When it comes 
+        // public api through this function) all share the same `ParsingHelper`. When it comes
         // time to .read(), we check the number of unique PlyData shared pointers
-        // and allocate a single buffer that will be used by each property key group. 
+        // and allocate a single buffer that will be used by each property key group.
         // That way, properties like, {"x", "y", "z"} will all be put into the same buffer.
 
         ParsingHelper helper;
         helper.data = out_data;
-        helper.data->count = element.size; // how many items are in the element? 
+        helper.data->count = element.size; // how many items are in the element?
         helper.data->isList = false;
         helper.data->t = Type::INVALID;
         helper.cursor = std::make_shared<PlyDataCursor>();
@@ -594,8 +596,8 @@ IGL_INLINE std::shared_ptr<PlyData> PlyFile::PlyFileImpl::request_properties_fro
     return out_data;
 }
 
-IGL_INLINE void PlyFile::PlyFileImpl::add_properties_to_element(const std::string & elementKey, 
-    const std::vector<std::string> propertyKeys, 
+IGL_INLINE void PlyFile::PlyFileImpl::add_properties_to_element(const std::string & elementKey,
+    const std::vector<std::string> propertyKeys,
     const Type type, const size_t count, uint8_t * data, const Type listType, const size_t listCount)
 {
     ParsingHelper helper;
@@ -644,7 +646,7 @@ IGL_INLINE void PlyFile::PlyFileImpl::parse_data(std::istream & is, bool firstPa
     // has an additional big endian check to flip the data in place immediately
     // after reading. We do this as a performance optimization; endian flipping is
     // done on regular properties as a post-process after reading (also for optimization)
-    // but we need the correct little-endian list count as we read the file. 
+    // but we need the correct little-endian list count as we read the file.
     auto read_list_binary = [this](const Type & t, void * dst, size_t & destOffset, const size_t & stride, std::istream & _is) noexcept
     {
         destOffset += stride;
@@ -692,22 +694,22 @@ IGL_INLINE void PlyFile::PlyFileImpl::parse_data(std::istream & is, bool firstPa
     else
     {
         read = [this, &listSize, &dummyCount](PropertyLookup & f, const PlyProperty & p, uint8_t * dest, size_t & destOffset, std::istream & _is) noexcept
-        { 
+        {
             if (!p.isList)
             {
-                read_property_ascii(p.propertyType, f.prop_stride, dest + destOffset, destOffset, _is); 
+                read_property_ascii(p.propertyType, f.prop_stride, dest + destOffset, destOffset, _is);
             }
             else
             {
                 read_property_ascii(p.listType, f.list_stride, &listSize, dummyCount, _is); // the list size
-                for (size_t i = 0; i < listSize; ++i) 
+                for (size_t i = 0; i < listSize; ++i)
                 {
                     read_property_ascii(p.propertyType, f.prop_stride, dest + destOffset, destOffset, _is);
                 }
             }
         };
         skip = [this, &listSize, &dummyCount, &skip_ascii_buffer](PropertyLookup & f, const PlyProperty & p, std::istream & _is) noexcept
-        { 
+        {
             skip_ascii_buffer.clear();
             if (p.isList)
             {
@@ -738,22 +740,22 @@ IGL_INLINE void PlyFile::PlyFileImpl::parse_data(std::istream & is, bool firstPa
                 if (!lookup.skip)
                 {
                     helper = lookup.helper;
-                    if (firstPass) 
+                    if (firstPass)
                     {
                         helper->cursor->totalSizeBytes += skip(lookup, property, is);
 
-                        // These lines will be changed when tinyply supports 
+                        // These lines will be changed when tinyply supports
                         // variable length lists. We add it here so our header data structure
-                        // contains enough info to write it back out again (e.g. transcoding). 
-                        if (property.listCount == 0) property.listCount = listSize; 
+                        // contains enough info to write it back out again (e.g. transcoding).
+                        if (property.listCount == 0) property.listCount = listSize;
                         if (property.listCount != listSize) throw std::runtime_error("variable length lists are not supported yet.");
                     }
-                    else 
+                    else
                     {
                         read(lookup, property, helper->data->buffer.get(), helper->cursor->byteOffset, is);
                     }
                 }
-                else 
+                else
                 {
                     skip(lookup, property, is);
                 }
@@ -792,3 +794,4 @@ IGL_INLINE void PlyFile::add_properties_to_element(const std::string & elementKe
 }
 
 } // tinyply
+} // igl

+ 24 - 21
include/igl/tinyply.h

@@ -1,7 +1,7 @@
 /*
  * tinyply 2.3.2 (https://github.com/ddiakopoulos/tinyply)
  *
- * A single-header, zero-dependency (except the C++ STL) public domain implementation 
+ * A single-header, zero-dependency (except the C++ STL) public domain implementation
  * of the PLY mesh file format. Requires C++11; errors are handled through exceptions.
  *
  * This software is in the public domain. Where that dedication is not
@@ -13,7 +13,7 @@
  * tinyply.h may be included in many files, however in a single compiled file,
  * the implementation must be created with the following defined prior to header inclusion
  * #define TINYPLY_IMPLEMENTATION
- * 
+ *
  */
 
 ////////////////////////
@@ -35,6 +35,8 @@
 #include <algorithm>
 #include <functional>
 
+namespace igl
+{
 namespace tinyply
 {
 
@@ -99,7 +101,7 @@ namespace tinyply
     {
         PlyProperty(std::istream & is);
         PlyProperty(Type type, std::string & _name) : name(_name), propertyType(type) {}
-        PlyProperty(Type list_type, Type prop_type, std::string & _name, size_t list_count) 
+        PlyProperty(Type list_type, Type prop_type, std::string & _name, size_t list_count)
             : name(_name), propertyType(prop_type), isList(true), listType(list_type), listCount(list_count) {}
         std::string name;
         Type propertyType{ Type::INVALID };
@@ -126,26 +128,26 @@ namespace tinyply
         ~PlyFile();
 
         /*
-         * The ply format requires an ascii header. This can be used to determine at 
-         * runtime which properties or elements exist in the file. Limited validation of the 
-         * header is performed; it is assumed the header correctly reflects the contents of the 
-         * payload. This function may throw. Returns true on success, false on failure. 
-         */ 
+         * The ply format requires an ascii header. This can be used to determine at
+         * runtime which properties or elements exist in the file. Limited validation of the
+         * header is performed; it is assumed the header correctly reflects the contents of the
+         * payload. This function may throw. Returns true on success, false on failure.
+         */
         bool parse_header(std::istream & is);
 
-        /* 
-         * Execute a read operation. Data must be requested via `request_properties_from_element(...)` 
+        /*
+         * Execute a read operation. Data must be requested via `request_properties_from_element(...)`
          * prior to calling this function.
          */
         void read(std::istream & is);
 
-        /* 
-         * `write` performs no validation and assumes that the data passed into 
-         * `add_properties_to_element` is well-formed. 
+        /*
+         * `write` performs no validation and assumes that the data passed into
+         * `add_properties_to_element` is well-formed.
          */
         void write(std::ostream & os, bool isBinary);
 
-        /* 
+        /*
          * These functions are valid after a call to `parse_header(...)`. In the case of
          * writing, get_comments() reference may also be used to add new comments to the ply header.
          */
@@ -161,19 +163,20 @@ namespace tinyply
          * an expected list length that will apply to this element. Doing so results in an up-front
          * memory allocation and a single-pass import, a 2x performance optimization.
          */
-        std::shared_ptr<PlyData> request_properties_from_element(const std::string & elementKey, 
+        std::shared_ptr<PlyData> request_properties_from_element(const std::string & elementKey,
             const std::vector<std::string> propertyKeys, const uint32_t list_size_hint = 0);
 
-        void add_properties_to_element(const std::string & elementKey, 
-            const std::vector<std::string> propertyKeys, 
-            const Type type, 
-            const size_t count, 
-            uint8_t * data, 
-            const Type listType, 
+        void add_properties_to_element(const std::string & elementKey,
+            const std::vector<std::string> propertyKeys,
+            const Type type,
+            const size_t count,
+            uint8_t * data,
+            const Type listType,
             const size_t listCount);
     };
 
 } // end namespace tinyply
+} // end namespace igl
 
 #ifndef IGL_STATIC_LIBRARY
 // implementation moved to tinyply.cpp

+ 6 - 8
include/igl/two_axis_valuator_fixed_up.cpp

@@ -20,21 +20,19 @@ IGL_INLINE void igl::two_axis_valuator_fixed_up(
   const int mouse_y,
   Eigen::Quaternion<Scalarquat> & quat)
 {
-  using namespace Eigen;
-  Matrix<Scalarquat,3,1> axis(0,1,0);
+  Eigen::Matrix<Scalarquat,3,1> axis(0,1,0);
   quat = down_quat *
-    Quaternion<Scalarquat>(
-      AngleAxis<Scalarquat>(
+    Eigen::Quaternion<Scalarquat>(
+      Eigen::AngleAxis<Scalarquat>(
         PI*((Scalarquat)(mouse_x-down_x))/(Scalarquat)w*speed/2.0,
         axis.normalized()));
   quat.normalize();
   {
-    Matrix<Scalarquat,3,1> axis(1,0,0);
+    Eigen::Matrix<Scalarquat,3,1> axis(1,0,0);
     if(axis.norm() != 0)
     {
-      quat =
-        Quaternion<Scalarquat>(
-          AngleAxis<Scalarquat>(
+        quat = Eigen::Quaternion<Scalarquat>(
+                   Eigen::AngleAxis<Scalarquat>(
             PI*(mouse_y-down_y)/(Scalarquat)h*speed/2.0,
             axis.normalized())) * quat;
       quat.normalize();