Go to the documentation of this file.
16 #ifndef SURGSIM_DATASTRUCTURES_OCTREENODE_INL_H
17 #define SURGSIM_DATASTRUCTURES_OCTREENODE_INL_H
32 namespace DataStructures
45 m_boundingBox(boundingBox),
61 for (
size_t i = 0; i < other.
m_children.size(); i++)
65 m_children[i] =
nullptr;
69 m_children[i] = std::make_shared<OctreeNode<Data>>(*other.
m_children[i]);
82 for (
size_t i = 0; i < m_children.size(); i++)
87 m_children[i] =
nullptr;
91 m_children[i] = std::make_shared<OctreeNode<Data>>(*child);
110 return m_boundingBox;
122 m_isActive = isActive;
128 return m_hasChildren;
138 Vector3d childsSize = (m_boundingBox.max() - m_boundingBox.min()) / 2.0;
140 for (
int i = 0; i < 8; i++)
144 ((i & 2) == 0) ? 0 : 1,
145 ((i & 4) == 0) ? 0 : 1);
146 childsBoundingBox.min() = m_boundingBox.min().array() + regionIndex.array() * childsSize.array();
147 childsBoundingBox.max() = childsBoundingBox.min() + childsSize;
148 m_children[i] = std::make_shared<OctreeNode<Data>>(childsBoundingBox);
150 m_hasChildren =
true;
157 return doAddData(position, nodeData, level, 1);
162 const int currentLevel)
164 if (! m_boundingBox.contains(position))
169 if (currentLevel == level)
180 for (
auto child = m_children.begin(); child != m_children.end(); ++child)
182 if ((*child)->doAddData(position, nodeData, level, currentLevel + 1))
206 return m_children[index];
212 return m_children[index];
218 std::shared_ptr<OctreeNode<Data>> node = this->shared_from_this();
219 std::shared_ptr<OctreeNode<Data>> previous;
220 for (
auto index = path.cbegin(); index != path.cend(); ++index)
222 previous = std::move(node);
223 node = previous->getChild(*index);
228 node = std::move(previous);
233 SURGSIM_FAILURE() <<
"Octree path is invalid. Path is longer than octree is deep in this given branch.";
244 auto delegate = std::make_shared<OctreeNodePlyReaderDelegate<Data>>(this->shared_from_this());
247 SURGSIM_ASSERT(reader.isValid()) <<
"'" << fileName <<
"' is an invalid .ply file.";
249 "The input file " << fileName <<
" does not have the property required by the octree.";
260 #endif // SURGSIM_DATASTRUCTURES_OCTREENODE_INL_H
#define SURGSIM_ASSERT(condition)
Assert that condition is true.
Definition: Assert.h:77
std::array< std::shared_ptr< OctreeNode< Data > >, 8 > m_children
The children of this node.
Definition: OctreeNode.h:248
virtual std::shared_ptr< OctreeNode< Data > > getNode(const OctreePath &path, bool returnLastValid=false)
Get the node at the supplied path.
Definition: OctreeNode-inl.h:216
Timer class, measures execution times.
Definition: Timer.h:30
virtual ~OctreeNode()
Destructor.
Definition: OctreeNode-inl.h:97
#define SURGSIM_LOG_INFO(logger)
Logs a message to the specified logger at the INFO level.
Definition: LogMacros.h:86
bool doLoad(const std::string &filePath) override
Derived classes will overwrite this method to do actual loading.
Definition: OctreeNode-inl.h:241
std::array< std::shared_ptr< OctreeNode< Data > >, 8 > & getChildren()
Get the children of this node (non const version)
Definition: OctreeNode-inl.h:192
OctreeNode()
Constructor.
Definition: OctreeNode-inl.h:36
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
#define SURGSIM_FAILURE()
Report that something very bad has happened and abort program execution.
Definition: Assert.h:95
bool isActive() const
Is this node active.
Definition: OctreeNode-inl.h:114
Definition: CompoundShapeToGraphics.cpp:29
std::vector< size_t > OctreePath
Typedef of octree path The path is a vector of children indexes (each within 0 to 7) that lead to the...
Definition: OctreeNode.h:43
std::string getClassName() const override
Support serialization with a classname.
Definition: OctreeNode-inl.h:102
static std::shared_ptr< Logger > getDefaultLogger()
Get default logger.
Definition: Logger.h:116
SurgSim::Math::Aabbd m_boundingBox
The bounding box of the current OctreeNode.
Definition: OctreeNode.h:239
Eigen::AlignedBox< double, 3 > Aabbd
Wrapper around the Eigen type.
Definition: Aabb.h:30
std::shared_ptr< OctreeNode< Data > > getChild(size_t index)
Get a child of this node (non const version)
Definition: OctreeNode-inl.h:204
void endFrame()
End this frame by storing the duration since the current frame was begun.
Definition: Timer.cpp:45
double getCumulativeTime() const
Return the sum of the durations over all the stored frames.
Definition: Timer.cpp:66
Wrapper for the C .ply file parser This class wraps the main functionality for the original C ....
Definition: PlyReader.h:85
bool addData(const SurgSim::Math::Vector3d &position, const int level, const Data &nodeData=Data())
Add data to a node in this octree The octree will build the octree as necessary to add the node at th...
Definition: OctreeNode-inl.h:155
void subdivide()
Subdivide the node into 8 equal regions.
Definition: OctreeNode-inl.h:132
Octree data structure.
Definition: OctreeNode.h:131
bool hasChildren() const
Does this node have children.
Definition: OctreeNode-inl.h:126
bool m_hasChildren
True if the node has children.
Definition: OctreeNode.h:245
bool doAddData(const SurgSim::Math::Vector3d &position, const Data &nodeData, const int level, const int currentLevel)
Recursive function that does the adding of the data to the octree.
Definition: OctreeNode-inl.h:161
Eigen::AlignedBox< double, 3 > AxisAlignedBoundingBox
Bounding box type for convenience.
Definition: OctreeNode.h:140
void setIsActive(bool isActive)
Set active flag for this octree node.
Definition: OctreeNode-inl.h:120
bool m_isActive
True if there is any data inside this node, including data held by children, children's children,...
Definition: OctreeNode.h:242
Data data
Extra node data.
Definition: OctreeNode.h:224
const SurgSim::Math::Aabbd & getBoundingBox() const
Get the bounding box for this octree node.
Definition: OctreeNode-inl.h:108