mirror of
https://github.com/overte-org/overte.git
synced 2025-06-07 01:41:39 +02:00
Starting to add the Items on the Octree
This commit is contained in:
parent
9c5670fc0f
commit
71e6c6e443
3 changed files with 67 additions and 23 deletions
|
@ -190,11 +190,12 @@ inline QDebug operator<<(QDebug debug, const ItemFilter& me) {
|
||||||
return debug;
|
return debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using ItemID = uint32_t;
|
||||||
|
|
||||||
class Item {
|
class Item {
|
||||||
public:
|
public:
|
||||||
typedef std::vector<Item> Vector;
|
typedef std::vector<Item> Vector;
|
||||||
typedef unsigned int ID;
|
typedef ItemID ID;
|
||||||
|
|
||||||
static const ID INVALID_ITEM_ID = 0;
|
static const ID INVALID_ITEM_ID = 0;
|
||||||
|
|
||||||
|
@ -420,7 +421,6 @@ typedef Item::PayloadPointer PayloadPointer;
|
||||||
typedef std::vector< PayloadPointer > Payloads;
|
typedef std::vector< PayloadPointer > Payloads;
|
||||||
|
|
||||||
// A few typedefs for standard containers of ItemIDs
|
// A few typedefs for standard containers of ItemIDs
|
||||||
using ItemID = Item::ID;
|
|
||||||
using ItemIDs = std::vector<ItemID>;
|
using ItemIDs = std::vector<ItemID>;
|
||||||
using ItemIDSet = std::set<ItemID>;
|
using ItemIDSet = std::set<ItemID>;
|
||||||
|
|
||||||
|
|
|
@ -125,11 +125,36 @@ Octree::Indices Octree::indexCellPath(const Locations& path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Octree::Index Octree::allocateBrick() {
|
||||||
|
Index brickIdx = _bricks.size();
|
||||||
|
_bricks.push_back(Brick());
|
||||||
|
return brickIdx;
|
||||||
|
}
|
||||||
|
|
||||||
|
Octree::Index Octree::accessCellBrick(const Location& loc, const CellBrickAccessor& accessor) {
|
||||||
|
auto cellId = indexCell(loc);
|
||||||
|
auto cell = editCell(cellId);
|
||||||
|
if (!cell.asBrick()) {
|
||||||
|
cell.setBrick(allocateBrick());
|
||||||
|
}
|
||||||
|
|
||||||
|
// access the brick
|
||||||
|
auto& brick = _bricks[cell.brick()];
|
||||||
|
|
||||||
|
// execute the accessor
|
||||||
|
accessor(brick, cell.brick());
|
||||||
|
|
||||||
|
return cell.brick();
|
||||||
|
}
|
||||||
|
|
||||||
void ItemSpatialTree::insert(const ItemBounds& items) {
|
void ItemSpatialTree::insert(const ItemBounds& items) {
|
||||||
for (auto& item : items) {
|
for (auto& item : items) {
|
||||||
if (!item.bound.isNull()) {
|
if (!item.bound.isNull()) {
|
||||||
auto cellIdx = indexCell(evalLocation(item.bound));
|
auto cellIdx = indexCell(evalLocation(item.bound));
|
||||||
|
|
||||||
|
accessCellBrick(evalLocation(item.bound), [&] (Brick& brick, Octree::Index cellID) {
|
||||||
|
brick.items.push_back(item.id);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,21 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <functional>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtx/bit.hpp>
|
#include <glm/gtx/bit.hpp>
|
||||||
#include <AABox.h>
|
#include <AABox.h>
|
||||||
|
|
||||||
|
// maybe we could avoid the Item inclusion here for the OCtree class?
|
||||||
|
#include "Item.h"
|
||||||
|
|
||||||
namespace render {
|
namespace render {
|
||||||
|
|
||||||
|
class Brick {
|
||||||
|
public:
|
||||||
|
std::vector<ItemID> items;
|
||||||
|
};
|
||||||
|
|
||||||
class Octree {
|
class Octree {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -40,8 +49,10 @@ namespace render {
|
||||||
NUM_OCTANTS,
|
NUM_OCTANTS,
|
||||||
|
|
||||||
Parent = NUM_OCTANTS,
|
Parent = NUM_OCTANTS,
|
||||||
|
BrickLink = Parent + 1,
|
||||||
|
|
||||||
|
NUM_LINKS = BrickLink + 1,
|
||||||
|
|
||||||
NUM_LINKS = NUM_OCTANTS + 1,
|
|
||||||
|
|
||||||
XAxis = 0x01,
|
XAxis = 0x01,
|
||||||
YAxis = 0x02,
|
YAxis = 0x02,
|
||||||
|
@ -150,27 +161,25 @@ namespace render {
|
||||||
bool asChild(Link octant) const { return child(octant) != INVALID; }
|
bool asChild(Link octant) const { return child(octant) != INVALID; }
|
||||||
void setChild(Link octant, Index child) { _links[octant] = child; }
|
void setChild(Link octant, Index child) { _links[octant] = child; }
|
||||||
|
|
||||||
|
Index brick() const { return _links[BrickLink]; }
|
||||||
|
bool asBrick() const { return _links[BrickLink] != INVALID; }
|
||||||
|
void setBrick(Index brick) { _links[BrickLink] = brick; }
|
||||||
|
|
||||||
Cell() :
|
Cell() :
|
||||||
_links({ { INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID } })
|
_links({ { INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID } })
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Cell(Index parent, Location loc) :
|
Cell(Index parent, Location loc) :
|
||||||
_location(loc),
|
_location(loc),
|
||||||
_links({ { INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, parent } })
|
_links({ { INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, parent, INVALID } })
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Index brick{ INVALID };
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Location _location;
|
|
||||||
std::array<Index, NUM_LINKS> _links;
|
std::array<Index, NUM_LINKS> _links;
|
||||||
|
Location _location;
|
||||||
};
|
};
|
||||||
using Cells = std::vector< Cell >;
|
using Cells = std::vector< Cell >;
|
||||||
|
|
||||||
class Brick {
|
|
||||||
public:
|
|
||||||
|
|
||||||
};
|
|
||||||
using Bricks = std::vector< Brick >;
|
using Bricks = std::vector< Brick >;
|
||||||
|
|
||||||
|
|
||||||
|
@ -194,15 +203,32 @@ namespace render {
|
||||||
assert(index < _cells.size());
|
assert(index < _cells.size());
|
||||||
return _cells[index];
|
return _cells[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Let s talk about the Cell Bricks now
|
||||||
|
using CellBrickAccessor = std::function<void(Brick& brick, Index brickIdx)>;
|
||||||
|
|
||||||
|
Index accessCellBrick(const Location& loc, const CellBrickAccessor& accessor);
|
||||||
|
|
||||||
|
const Brick& getBrick(Index index) const {
|
||||||
|
assert(index < _bricks.size());
|
||||||
|
return _bricks[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
Index allocateCell(Index parent, const Location& location);
|
Index allocateCell(Index parent, const Location& location);
|
||||||
|
Index allocateBrick();
|
||||||
|
|
||||||
|
Cell& editCell(Index index) {
|
||||||
|
assert(index < _cells.size());
|
||||||
|
return _cells[index];
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// CLose the namespace here before including the Item in the picture, maybe Octre could stay pure of it
|
|
||||||
#include "Item.h"
|
|
||||||
|
|
||||||
|
// CLose the namespace here before including the Item in the picture, maybe Octre could stay pure of it
|
||||||
namespace render {
|
namespace render {
|
||||||
|
|
||||||
// An octree of Items organizing them efficiently for culling
|
// An octree of Items organizing them efficiently for culling
|
||||||
|
@ -237,15 +263,8 @@ namespace render {
|
||||||
return AABox(evalPos(loc.pos, cellWidth), cellWidth);
|
return AABox(evalPos(loc.pos, cellWidth), cellWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Location evalLocation(const AABox& bound) const {
|
Location evalLocation(const AABox& bound) const {
|
||||||
auto minVec = bound.getMinimumPoint();
|
return Location::evalFromRange(evalCoord(bound.getMinimumPoint()), evalCoord(bound.getMaximumPoint()));
|
||||||
auto maxVec = bound.getMaximumPoint();
|
|
||||||
|
|
||||||
auto minPos = evalCoord(minVec);
|
|
||||||
auto maxPos = evalCoord(maxVec);
|
|
||||||
|
|
||||||
return Location::evalFromRange(minPos, maxPos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemSpatialTree() {}
|
ItemSpatialTree() {}
|
||||||
|
|
Loading…
Reference in a new issue