Revision: 71963
          http://sourceforge.net/p/brlcad/code/71963
Author:   starseeker
Date:     2018-10-11 19:43:50 +0000 (Thu, 11 Oct 2018)
Log Message:
-----------
Revert back to the shared_ptr version for now - a valigrind 'bot chull' run of 
the lucy model didn't report any lost memory and timing indicated maybe a 2x 
increase in run time compared to the unique_ptr.

Modified Paths:
--------------
    brlcad/trunk/src/libbg/QuickHull.hpp

Modified: brlcad/trunk/src/libbg/QuickHull.hpp
===================================================================
--- brlcad/trunk/src/libbg/QuickHull.hpp        2018-10-11 19:26:08 UTC (rev 
71962)
+++ brlcad/trunk/src/libbg/QuickHull.hpp        2018-10-11 19:43:50 UTC (rev 
71963)
@@ -232,22 +232,22 @@
 
     template<typename T>
        class Pool {
-           std::vector<std::unique_ptr<T>> m_data;
+           std::vector<std::shared_ptr<T>> m_data;
            public:
            void clear() {
                m_data.clear();
            }
 
-           void reclaim(std::unique_ptr<T>& ptr) {
+           void reclaim(std::shared_ptr<T>& ptr) {
                m_data.push_back(std::move(ptr));
            }
 
-           std::unique_ptr<T> get() {
+           std::shared_ptr<T> get() {
                if (m_data.size()==0) {
-                   return std::unique_ptr<T>(new T());
+                   return std::shared_ptr<T>(new T());
                }
                auto it = m_data.end()-1;
-               std::unique_ptr<T> r = std::move(*it);
+               std::shared_ptr<T> r = std::move(*it);
                m_data.erase(it);
                return r;
            }
@@ -344,7 +344,7 @@
                    std::uint8_t m_isVisibleFaceOnCurrentIteration : 1;
                    std::uint8_t m_inFaceStack : 1;
                    std::uint8_t m_horizonEdgesOnCurrentIteration : 3; // Bit 
for each half edge assigned to this face, each being 0 or 1 depending on 
whether the edge belongs to horizon edge
-                   std::unique_ptr<std::vector<IndexType>> 
m_pointsOnPositiveSide;
+                   std::shared_ptr<std::vector<IndexType>> 
m_pointsOnPositiveSide;
 
                    Face() : m_he(std::numeric_limits<IndexType>::max()),
                    m_mostDistantPointDist(0),
@@ -357,34 +357,6 @@
 
                    }
 
-                       Face& operator=(const Face& old)
-                       {
-                               m_he = old.m_he;
-                               m_P = old.m_P;
-                               m_mostDistantPointDist = 
old.m_mostDistantPointDist;
-                               m_mostDistantPoint = old.m_mostDistantPoint;
-                               m_visibilityCheckedOnIteration = 
old.m_visibilityCheckedOnIteration;
-                               m_isVisibleFaceOnCurrentIteration = 
old.m_isVisibleFaceOnCurrentIteration;
-                               m_inFaceStack = old.m_inFaceStack;
-                               m_horizonEdgesOnCurrentIteration = 
old.m_horizonEdgesOnCurrentIteration;
-                               //m_pointsOnPositiveSide = 
std::move(getIndexVectorFromPool());
-                               
//std::copy(old.m_pointsOnPositiveSide->begin(), 
old.m_pointsOnPositiveSide->end(), std::back_inserter(*m_pointsOnPositiveSide));
-                               //m_pointsOnPositiveSide = 
std::move(old.m_pointsOnPositiveSide);
-                               return *this;
-                       }
-                       Face(const Face& old)
-                       {
-                               m_he = old.m_he;
-                               m_P = old.m_P;
-                               m_mostDistantPointDist = 
old.m_mostDistantPointDist;
-                               m_mostDistantPoint = old.m_mostDistantPoint;
-                               m_visibilityCheckedOnIteration = 
old.m_visibilityCheckedOnIteration;
-                               m_isVisibleFaceOnCurrentIteration = 
old.m_isVisibleFaceOnCurrentIteration;
-                               m_inFaceStack = old.m_inFaceStack;
-                               m_horizonEdgesOnCurrentIteration = 
old.m_horizonEdgesOnCurrentIteration;
-                               //m_pointsOnPositiveSide = 
std::move(old.m_pointsOnPositiveSide);
-                       }
-
                    void disable() {
                        m_he = std::numeric_limits<IndexType>::max();
                    }
@@ -428,7 +400,7 @@
                }
 
                // Mark a face as disabled and return a pointer to the points 
that were on the positive of it.
-               std::unique_ptr<std::vector<IndexType>> disableFace(IndexType 
faceIndex) {
+               std::shared_ptr<std::vector<IndexType>> disableFace(IndexType 
faceIndex) {
                    auto& f = m_faces[faceIndex];
                    f.disable();
                    m_disabledFaces.push_back(faceIndex);
@@ -676,7 +648,7 @@
 
     template<typename T>
        class ConvexHull {
-           std::unique_ptr<std::vector<Vector3<T>>> m_optimizedVertexBuffer;
+           std::shared_ptr<std::vector<Vector3<T>>> m_optimizedVertexBuffer;
            VertexDataSource<T> m_vertices;
            std::vector<size_t> m_indices;
            public:
@@ -837,7 +809,7 @@
            // Temporary variables used during iteration process
            std::vector<IndexType> m_newFaceIndices;
            std::vector<IndexType> m_newHalfEdgeIndices;
-           std::vector< std::unique_ptr<std::vector<IndexType>> > 
m_disabledFacePointVectors;
+           std::vector< std::shared_ptr<std::vector<IndexType>> > 
m_disabledFacePointVectors;
 
            // Create a half edge mesh representing the base tetrahedron from
            // which the QuickHull iteration proceeds. m_extremeValues must be
@@ -865,8 +837,8 @@
            // amount of std::vectors we have to deal with, and impact on
            // performance is remarkable.
            Pool<std::vector<IndexType>> m_indexVectorPool;
-           inline std::unique_ptr<std::vector<IndexType>> 
getIndexVectorFromPool();
-           inline void 
reclaimToIndexVectorPool(std::unique_ptr<std::vector<IndexType>>& ptr);
+           inline std::shared_ptr<std::vector<IndexType>> 
getIndexVectorFromPool();
+           inline void 
reclaimToIndexVectorPool(std::shared_ptr<std::vector<IndexType>>& ptr);
 
            // Associates a point with a face if the point resides on the
            // positive side of the plane. Returns true if the points was on
@@ -965,7 +937,7 @@
      */
 
     template<typename T>
-       std::unique_ptr<std::vector<IndexType>> 
QuickHull<T>::getIndexVectorFromPool() {
+       std::shared_ptr<std::vector<IndexType>> 
QuickHull<T>::getIndexVectorFromPool() {
            auto r = std::move(m_indexVectorPool.get());
            r->clear();
            return r;
@@ -972,13 +944,13 @@
        }
 
     template<typename T>
-       void 
QuickHull<T>::reclaimToIndexVectorPool(std::unique_ptr<std::vector<IndexType>>& 
ptr) {
+       void 
QuickHull<T>::reclaimToIndexVectorPool(std::shared_ptr<std::vector<IndexType>>& 
ptr) {
            const size_t oldSize = ptr->size();
            if ((oldSize+1)*128 < ptr->capacity()) {
                // Reduce memory usage! Huge vectors are needed at the
                // beginning of iteration when faces have many points on their
                // positive side. Later on, smaller vectors will suffice.
-               ptr.reset(nullptr);
+               ptr.reset();
                return;
            }
            m_indexVectorPool.reclaim(ptr);

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to