16 #ifndef SURGSIM_DATASTRUCTURES_OCTREENODE_INL_H 17 #define SURGSIM_DATASTRUCTURES_OCTREENODE_INL_H 23 #include "SurgSim/DataStructures/OctreeNodePlyReaderDelegate.h" 24 #include "SurgSim/DataStructures/PlyReader.h" 27 #include "SurgSim/Framework/Timer.h" 32 namespace DataStructures
61 for (
size_t i = 0; i < other.
m_children.size(); i++)
91 m_children[i] = std::make_shared<OctreeNode<Data>>(*child);
140 for (
int i = 0; i < 8; i++)
143 Vector3d regionIndex = Vector3d(((i & 1) == 0) ? 0 : 1,
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);
157 return doAddData(position, nodeData, level, 1);
162 const int currentLevel)
169 if (currentLevel == level)
182 if ((*child)->doAddData(position, nodeData, level, currentLevel + 1))
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 bool isActive() const
Is this node active.
Definition: OctreeNode-inl.h:114
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
SurgSim::Math::Aabbd m_boundingBox
The bounding box of the current OctreeNode.
Definition: OctreeNode.h:239
virtual ~OctreeNode()
Destructor.
Definition: OctreeNode-inl.h:97
std::shared_ptr< OctreeNode< Data > > getChild(size_t index)
Get a child of this node (non const version)
Definition: OctreeNode-inl.h:204
void setIsActive(bool isActive)
Set active flag for this octree node.
Definition: OctreeNode-inl.h:120
bool doLoad(const std::string &filePath) override
Derived classes will overwrite this method to do actual loading.
Definition: OctreeNode-inl.h:241
double getCumulativeTime() const
Return the sum of the durations over all the stored frames.
Definition: Timer.cpp:70
#define SURGSIM_ASSERT(condition)
Assert that condition is true.
Definition: Assert.h:77
#define SURGSIM_FAILURE()
Report that something very bad has happened and abort program execution.
Definition: Assert.h:95
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
The convenience header that provides the entirety of the logging API.
Timer class, measures execution times.
Definition: Timer.h:31
Wrapper for the C .ply file parser This class wraps the main functionality for the original C ...
Definition: PlyReader.h:85
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
OctreeNode()
Constructor.
Definition: OctreeNode-inl.h:36
bool hasChildren() const
Does this node have children.
Definition: OctreeNode-inl.h:126
void endFrame()
End this frame by storing the duration since the current frame was begun.
Definition: Timer.cpp:48
The header that provides the assertion API.
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
bool m_hasChildren
True if the node has children.
Definition: OctreeNode.h:245
bool m_isActive
True if there is any data inside this node, including data held by children, children's children...
Definition: OctreeNode.h:242
std::array< std::shared_ptr< OctreeNode< Data > >, 8 > & getChildren()
Get the children of this node (non const version)
Definition: OctreeNode-inl.h:192
#define SURGSIM_LOG_INFO(logger)
Logs a message to the specified logger at the INFO level.
Definition: LogMacros.h:86
Eigen::AlignedBox< double, 3 > AxisAlignedBoundingBox
Bounding box type for convenience.
Definition: OctreeNode.h:140
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
static std::shared_ptr< Logger > getDefaultLogger()
Get default logger.
Definition: Logger.h:116
std::array< std::shared_ptr< OctreeNode< Data > >, 8 > m_children
The children of this node.
Definition: OctreeNode.h:248
Data data
Extra node data.
Definition: OctreeNode.h:224
Octree data structure.
Definition: OctreeNode.h:131
std::string getClassName() const override
Support serialization with a classname.
Definition: OctreeNode-inl.h:102
const SurgSim::Math::Aabbd & getBoundingBox() const
Get the bounding box for this octree node.
Definition: OctreeNode-inl.h:108