Merge branch 'master' of git.ucc.asn.au:ipdf/code
authorDavid Gow <[email protected]>
Mon, 7 Jul 2014 16:02:11 +0000 (00:02 +0800)
committerDavid Gow <[email protected]>
Mon, 7 Jul 2014 16:02:11 +0000 (00:02 +0800)
src/document.cpp
src/document.h
src/main.cpp
src/quadtree.h
src/view.cpp
src/view.h

index e49e52e..76a5349 100644 (file)
@@ -142,6 +142,12 @@ void Document::Load(const string & filename)
                }
        }
        Debug("Successfully loaded %u objects from \"%s\"", ObjectCount(), filename.c_str());
+#ifndef QUADTREE_DISABLED
+       if (m_quadtree.root_id == QUADTREE_EMPTY)
+       {
+               GenBaseQuadtree();
+       }
+#endif
 }
 
 void Document::Add(ObjectType type, const Rect & bounds, unsigned data_index)
index b02c798..0f2fea1 100644 (file)
@@ -26,7 +26,7 @@ namespace IPDF
                        unsigned AddBezierData(const Bezier & bezier);
 
 #ifndef QUADTREE_DISABLED
-                       inline const QuadTree& GetQuadTree() const { return m_quadtree; }
+                       inline const QuadTree& GetQuadTree() { if (m_quadtree.root_id == QUADTREE_EMPTY) { GenBaseQuadtree(); } return m_quadtree; }
 #endif
 
                private:
index 91e362c..2cfb73b 100644 (file)
@@ -98,6 +98,7 @@ int main(int argc, char ** argv)
                        }
                }
                doc.Add(BEZIER, Rect(0.1,0.1,0.8,0.8), 0);
+               doc.Add(CIRCLE_FILLED, Rect(0.1,0.1,0.8,0.8), 0);
        }
        Debug("Start!");
        Rect bounds(b[0],b[1],b[2],b[3]);
index 671ee0f..d5eddd8 100644 (file)
@@ -42,6 +42,7 @@ namespace IPDF
 
        struct QuadTree
        {
+               QuadTree() : root_id(QUADTREE_EMPTY) {}
                QuadTreeIndex root_id;
                std::vector<QuadTreeNode> nodes;
        };
index 73331ef..02859c5 100644 (file)
@@ -124,6 +124,28 @@ Rect View::TransformToViewCoords(const Rect& inp) const
  * @param height - Height of View to render
  */
 void View::Render(int width, int height)
+{
+#ifdef QUADTREE_DISABLED
+       RenderRange(width, height, 0, m_document.ObjectCount());
+#else
+       RenderQuadtreeNode(width, height, m_current_quadtree_node, m_quadtree_max_depth);
+#endif
+}
+
+#ifndef QUADTREE_DISABLED
+void View::RenderQuadtreeNode(int width, int height, QuadTreeIndex node, int remaining_depth)
+{
+       if (node == QUADTREE_EMPTY) return;
+       if (!remaining_depth) return;
+       RenderRange(width, height, m_document.GetQuadTree().nodes[node].object_begin, m_document.GetQuadTree().nodes[node].object_end);
+       RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].top_left, remaining_depth-1);
+       RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].top_right, remaining_depth-1);
+       RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].bottom_left, remaining_depth-1);
+       RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].bottom_right, remaining_depth-1);
+}
+#endif
+
+void View::RenderRange(int width, int height, unsigned first_obj, unsigned last_obj)
 {
        // View dimensions have changed (ie: Window was resized)
        int prev_width = m_cached_display.GetWidth();
@@ -168,10 +190,6 @@ void View::Render(int width, int height)
        m_cached_display.Bind(); //NOTE: This is redundant; Clear already calls Bind
        m_cached_display.Clear();
 
-       // When we QuadTree, this will be magic.
-       int first_obj = 0;
-       int last_obj = m_document.ObjectCount();
-
        // Render using GPU
        if (m_use_gpu_rendering) 
        {
index ca4c808..5e30ef7 100644 (file)
@@ -53,6 +53,8 @@ namespace IPDF
                        void PrepareRender(); // call when m_render_dirty is true
                        void UpdateObjBoundsVBO(); // call when m_buffer_dirty is true
 
+                       void RenderRange(int width, int height, unsigned first_obj, unsigned last_obj);
+
                        bool m_use_gpu_transform;
                        bool m_use_gpu_rendering;
                        bool m_bounds_dirty; // the view bounds has changed (occurs when changing view)
@@ -77,6 +79,7 @@ namespace IPDF
 #ifndef QUADTREE_DISABLED
                        QuadTreeIndex m_current_quadtree_node;  // The highest node we will traverse.
                        int m_quadtree_max_depth;               // The maximum quadtree depth.
+                       void RenderQuadtreeNode(int width, int height, QuadTreeIndex node, int remaining_depth);
 
 #endif
        };

UCC git Repository :: git.ucc.asn.au