Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CC_OUTPUT_BSP_TREE_H_ | |
| 6 #define CC_OUTPUT_BSP_TREE_H_ | |
| 7 | |
| 8 #include <list> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "cc/base/scoped_ptr_deque.h" | |
| 13 #include "cc/base/scoped_ptr_vector.h" | |
| 14 #include "cc/output/bsp_compare_result.h" | |
| 15 #include "cc/output/bsp_controller.h" | |
| 16 #include "cc/quads/draw_polygon.h" | |
| 17 | |
| 18 namespace cc { | |
| 19 | |
| 20 struct BspNode { | |
| 21 // This represents the splitting plane. | |
| 22 scoped_ptr<DrawPolygon> node_data; | |
| 23 // This represents any coplanar geometry we found while building the BSP. | |
| 24 ScopedPtrVector<DrawPolygon> coplanars_front; | |
| 25 ScopedPtrVector<DrawPolygon> coplanars_back; | |
| 26 | |
| 27 scoped_ptr<BspNode> back_child; | |
| 28 scoped_ptr<BspNode> front_child; | |
| 29 | |
| 30 explicit BspNode(scoped_ptr<DrawPolygon> data); | |
| 31 ~BspNode(); | |
| 32 }; | |
| 33 | |
| 34 class BspTree { | |
| 35 public: | |
| 36 BspTree(BspController* bsp_controller, ScopedPtrVector<DrawPolygon>* list); | |
| 37 scoped_ptr<BspNode>& root() { return root_; } | |
| 38 | |
| 39 template <typename ActionHandlerType> | |
| 40 void TraverseWithActionHandler(ActionHandlerType* action_handler) const { | |
| 41 if (root_) { | |
| 42 WalkInOrderRecursion<ActionHandlerType>(action_handler, root_.get()); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 void Clear(); | |
| 47 ~BspTree(); | |
| 48 | |
| 49 private: | |
| 50 scoped_ptr<BspNode> root_; | |
| 51 BspController* controller_; | |
| 52 | |
| 53 void FromList(ScopedPtrVector<DrawPolygon>* list); | |
| 54 void BuildTree(BspNode* node, ScopedPtrDeque<DrawPolygon>* data); | |
| 55 | |
| 56 template <typename ActionHandlerType> | |
| 57 void WalkInOrderAction(ActionHandlerType* action_handler, | |
| 58 DrawPolygon* item) const { | |
| 59 (*action_handler)(item); | |
| 60 } | |
| 61 | |
| 62 template <typename ActionHandlerType> | |
| 63 void WalkInOrderVisitNodes( | |
| 64 ActionHandlerType* action_handler, | |
| 65 const BspNode* node, | |
| 66 const BspNode* first_child, | |
| 67 const BspNode* second_child, | |
| 68 const ScopedPtrVector<DrawPolygon>& first_coplanars, | |
| 69 const ScopedPtrVector<DrawPolygon>& second_coplanars) const { | |
| 70 if (first_child) { | |
| 71 WalkInOrderRecursion(action_handler, first_child); | |
| 72 } | |
| 73 for (unsigned int i = 0; i < first_coplanars.size(); i++) { | |
|
enne (OOO)
2014/07/28 21:38:20
unsigned int => size_t, here and elsewhere
troyhildebrandt
2014/07/29 00:04:33
Done.
| |
| 74 WalkInOrderAction(action_handler, first_coplanars[i]); | |
| 75 } | |
| 76 WalkInOrderAction(action_handler, node->node_data.get()); | |
| 77 for (unsigned int i = 0; i < second_coplanars.size(); i++) { | |
| 78 WalkInOrderAction(action_handler, second_coplanars[i]); | |
| 79 } | |
| 80 if (second_child) { | |
| 81 WalkInOrderRecursion(action_handler, second_child); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 template <typename ActionHandlerType> | |
| 86 void WalkInOrderRecursion(ActionHandlerType* action_handler, | |
| 87 const BspNode* node) const { | |
| 88 // If our view is in front of the the polygon | |
| 89 // in this node then walk back then front. | |
| 90 if (controller_->GetCameraPositionRelative(*(node->node_data)) == | |
| 91 BSP_FRONT) { | |
| 92 WalkInOrderVisitNodes<ActionHandlerType>(action_handler, | |
| 93 node, | |
| 94 node->back_child.get(), | |
| 95 node->front_child.get(), | |
| 96 node->coplanars_front, | |
| 97 node->coplanars_back); | |
| 98 } else { | |
| 99 WalkInOrderVisitNodes<ActionHandlerType>(action_handler, | |
| 100 node, | |
| 101 node->front_child.get(), | |
| 102 node->back_child.get(), | |
| 103 node->coplanars_back, | |
| 104 node->coplanars_front); | |
| 105 } | |
| 106 } | |
| 107 }; | |
| 108 | |
| 109 } // namespace cc | |
| 110 | |
| 111 #endif // CC_OUTPUT_BSP_TREE_H_ | |
| OLD | NEW |