Freestyle: minor optimization for space from mesh importing to feature edge detection.
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Fri, 25 Jul 2014 04:26:24 +0000 (13:26 +0900)
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Sun, 19 Jul 2015 21:17:54 +0000 (06:17 +0900)
Several class member variables were removed (at the cost of computing their values
when retrieved) or changed to a type of smaller size.  Also fixed whitespace.

source/blender/freestyle/intern/view_map/FEdgeXDetector.cpp
source/blender/freestyle/intern/view_map/FEdgeXDetector.h
source/blender/freestyle/intern/winged_edge/Nature.h
source/blender/freestyle/intern/winged_edge/WEdge.cpp
source/blender/freestyle/intern/winged_edge/WEdge.h
source/blender/freestyle/intern/winged_edge/WXEdge.h
source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.cpp

index 9827ec68c5ddfcad3ab18f519a4f84d820f3445f..5ec8b545b4cbdec6a2d2320dbef23a0142d7cf0b 100644 (file)
@@ -55,8 +55,10 @@ void FEdgeXDetector::processShapes(WingedEdge& we)
                if (_pRenderMonitor && _pRenderMonitor->testBreak())
                        break;
                wxs = dynamic_cast<WXShape*>(*it);
+#if 0
                wxs->bbox(Min, Max);
                _bbox_diagonal = (Max - Min).norm();
+#endif
                if (_changes) {
                        vector<WFace*>& wfaces = wxs->GetFaceList();
                        for (vector<WFace*>::iterator wf = wfaces.begin(), wfend = wfaces.end(); wf != wfend; ++wf) {
@@ -117,7 +119,11 @@ void FEdgeXDetector::preProcessShape(WXShape *iWShape)
        _minKr = FLT_MAX;
        _maxKr = -FLT_MAX;
        _nPoints = 0;
+#if 0
        _meanEdgeSize = iWShape->getMeanEdgeSize();
+#else
+       _meanEdgeSize = iWShape->ComputeMeanEdgeSize();
+#endif
 
        vector<WFace*>& wfaces = iWShape->GetFaceList();
        vector<WFace*>::iterator f, fend;
index 8170fc5baab26d6421ce6479ece76f096e0b831c..9087d05939a6a3cd46decf9de7a1acba985cbf9c 100644 (file)
@@ -58,7 +58,9 @@ public:
                _pProgressBar = NULL;
                _pRenderMonitor = NULL;
                _computeViewIndependent = true;
+#if 0
                _bbox_diagonal = 1.0;
+#endif
                _meanEdgeSize = 0;
                _computeRidgesAndValleys = true;
                _computeSuggestiveContours = true;
@@ -211,7 +213,9 @@ public:
 
 protected:
        Vec3r _Viewpoint;
+#if 0
        real _bbox_diagonal; // diagonal of the current processed shape bbox
+#endif
        //oldtmp values
        bool _computeViewIndependent;
        real _meanK1;
index 99a3f902cd0208ea9e4bc64909279fc64f90ec82..b1b5c88df5a966a83eaa52c8ee8ebe3e3c014933 100644 (file)
@@ -34,6 +34,7 @@ namespace Freestyle {
 namespace Nature {
 
 /* XXX Why not using enums??? */
+/* In order to optimize for space (enum is int) - T.K. */
 
 typedef unsigned short VertexNature;
 /*! true for any 0D element */
index de166531d8bb877c3e1c803b8b74bdf283fa80a0..261aac67c9d8adf02106ab53c97831d719d746f4 100644 (file)
@@ -472,8 +472,10 @@ WShape::WShape(WShape& iBrother)
        _Id = iBrother.GetId();
        _Name = iBrother._Name;
        _FrsMaterials = iBrother._FrsMaterials;
+#if 0
        _meanEdgeSize = iBrother._meanEdgeSize;
        iBrother.bbox(_min, _max);
+#endif
        vector<WVertex *>& vertexList = iBrother.getVertexList();
        vector<WVertex *>::iterator v = vertexList.begin(), vend = vertexList.end();
        for (; v != vend; ++v) {
@@ -681,8 +683,10 @@ WFace *WShape::MakeFace(vector<WVertex *>& iVertexList, vector<bool>& iFaceEdgeM
                        // means that we just created a new edge and that we must add it to the shape's edges list
                        edge->setId(_EdgeList.size());
                        AddEdge(edge);
+#if 0
                        // compute the mean edge value:
                        _meanEdgeSize += edge->GetaOEdge()->GetVec().norm();
+#endif
                }
 
                edge->setMark(*mit);
@@ -696,4 +700,16 @@ WFace *WShape::MakeFace(vector<WVertex *>& iVertexList, vector<bool>& iFaceEdgeM
        return face;
 }
 
+real WShape::ComputeMeanEdgeSize() const
+{
+       real meanEdgeSize = 0.0;
+       for (vector<WEdge *>::const_iterator it = _EdgeList.begin(), itend = _EdgeList.end();
+            it != itend;
+            it++)
+       {
+               meanEdgeSize += (*it)->GetaOEdge()->GetVec().norm();
+       }
+       return meanEdgeSize / _EdgeList.size();
+}
+
 } /* namespace Freestyle */
index 97c282e1910e9ef806eb9e430f35dd8bff146e3f..9b04333123e036132a8256afbe194e15d0775a91 100644 (file)
@@ -72,7 +72,7 @@ protected:
        vector<WEdge*> _EdgeList;
        WShape *_Shape; // the shape to which the vertex belongs
        bool _Smooth; // flag to indicate whether the Vertex belongs to a smooth edge or not
-       int _Border; // 1 -> border, 0 -> no border, -1 -> not set
+       short _Border; // 1 -> border, 0 -> no border, -1 -> not set
 
 public:
        void *userdata; // designed to store specific user data
@@ -467,7 +467,6 @@ public:
                return _angle;
        }
 
-
        /*! modifiers */
 #if 0
        inline void SetaCWEdge(WOEdge *pe)
@@ -552,7 +551,7 @@ class WEdge
 protected:
        WOEdge *_paOEdge; // first oriented edge
        WOEdge *_pbOEdge; // second oriented edge
-       int _nOEdges;     // number of oriented edges associated with this edge. (1 means border edge)
+       short _nOEdges;   // number of oriented edges associated with this edge. (1 means border edge)
        bool _Mark;       // user-specified edge mark for feature edge detection
        int _Id;          // Identifier for the edge
 
@@ -633,7 +632,7 @@ public:
                return _pbOEdge;
        }
 
-       inline int GetNumberOfOEdges()
+       inline short GetNumberOfOEdges()
        {
                return _nOEdges;
        }
@@ -700,7 +699,7 @@ public:
                }
        }
 
-       inline void setNumberOfOEdges(int n)
+       inline void setNumberOfOEdges(short n)
        {
                _nOEdges = n;
        }
@@ -1027,15 +1026,21 @@ protected:
        int _Id;
        const char *_Name;
        static unsigned _SceneCurrentId;
+#if 0
        Vec3r _min;
        Vec3r _max;
+#endif
        vector<FrsMaterial> _FrsMaterials;
+#if 0
        real _meanEdgeSize;
+#endif
 
 public:
        inline WShape()
        {
+#if 0
                _meanEdgeSize = 0;
+#endif
                _Id = _SceneCurrentId;
                _SceneCurrentId++;
        }
@@ -1092,11 +1097,13 @@ public:
                return _Id;
        }
 
+#if 0
        inline void bbox(Vec3r& min, Vec3r& max)
        {
                min = _min;
                max = _max;
        }
+#endif
 
        inline const FrsMaterial& frs_material(unsigned i) const
        {
@@ -1108,10 +1115,12 @@ public:
                return _FrsMaterials;
        }
 
+#if 0
        inline const real getMeanEdgeSize() const
        {
                return _meanEdgeSize;
        }
+#endif
 
        inline const char *getName() const
        {
@@ -1144,11 +1153,13 @@ public:
                _Id = id;
        }
 
+#if 0
        inline void setBBox(const Vec3r& min, const Vec3r& max)
        {
                _min = min;
                _max = max;
        }
+#endif
 
        inline void setFrsMaterial(const FrsMaterial& frs_material, unsigned i)
        {
@@ -1240,6 +1251,7 @@ public:
                }
        }
 
+#if 0
        inline void ComputeBBox()
        {
                _min = _VertexList[0]->GetVertex();
@@ -1256,12 +1268,17 @@ public:
                        }
                }
        }
+#endif
 
+#if 0
        inline real ComputeMeanEdgeSize()
        {
                _meanEdgeSize = _meanEdgeSize / _EdgeList.size();
                return _meanEdgeSize;
        }
+#else
+       real ComputeMeanEdgeSize() const;
+#endif
 
 protected:
        /*! Builds the face passed as argument (which as already been allocated)
index 3c9ec7a7e3d4ff4ac2fb7a7bf8c95e6b9dd39b17..6e48860272abe15f5be71014d361edffed3665ae 100644 (file)
@@ -99,7 +99,6 @@ public:
 #ifdef WITH_CXX_GUARDEDALLOC
        MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXVertex")
 #endif
-
 };
 
 
@@ -117,7 +116,7 @@ private:
        // flag to indicate whether the edge is a silhouette edge or not
        WXNature _nature;
        // 0: the order doesn't matter. 1: the order is the orginal one. -1: the order is not good
-       int _order;
+       short _order;
        // A front facing edge is an edge for which the bording face which is the nearest from the viewpoint is front.
        // A back facing edge is the opposite.
        bool _front;
@@ -177,7 +176,7 @@ public:
                return _front;
        }
 
-       inline int order() const
+       inline short order() const
        {
                return _order;
        }
@@ -206,7 +205,6 @@ public:
 #ifdef WITH_CXX_GUARDEDALLOC
        MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXEdge")
 #endif
-
 };
 
 /**********************************
@@ -221,11 +219,10 @@ public:
 class WXSmoothEdge
 {
 public:
-       typedef enum {
-               EDGE_EDGE,
-               VERTEX_EDGE,
-               EDGE_VERTEX,
-       } Configuration;
+       typedef unsigned short Configuration;
+       static const Configuration EDGE_EDGE = 1;
+       static const Configuration VERTEX_EDGE = 2;
+       static const Configuration EDGE_VERTEX = 3;
 
        WOEdge *_woea; // Oriented edge from which the silhouette edge starts
        WOEdge *_woeb; // Oriented edge where the silhouette edge ends
@@ -403,7 +400,7 @@ public:
                return _ClosestPointIndex;
        }
 
-       inline Nature::EdgeNature nature() const
+       inline WXNature nature() const
        {
                return _Nature;
        }
@@ -700,7 +697,6 @@ public:
 #ifdef WITH_CXX_GUARDEDALLOC
        MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXFace")
 #endif
-
 };
 
 
@@ -801,7 +797,6 @@ public:
 #ifdef WITH_CXX_GUARDEDALLOC
        MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXShape")
 #endif
-
 };
 
 /*
index df990a3468f35f4b54bfd209a2ce24b52c734d02..2be46abc87deb9e36de8b0d8b43d4acb5a89dd46 100644 (file)
@@ -177,10 +177,12 @@ bool WingedEdgeBuilder::buildWShape(WShape& shape, IndexedFaceSet& ifs)
        if (shape.GetFaceList().size() == 0) // this may happen due to degenerate triangles
                return false;
 
+#if 0
        // compute bbox
        shape.ComputeBBox();
        // compute mean edge size:
        shape.ComputeMeanEdgeSize();
+#endif
 
        // Parse the built winged-edge shape to update post-flags
        set<Vec3r> normalsSet;