Commit e2be2889 authored by Nghia Truong's avatar Nghia Truong

REFAC: Rename OctreePrimitiveData to OctreePrimitive

parent 367857dd
......@@ -177,7 +177,7 @@ OctreeNode::removeEmptyDescendants()
}
void
OctreeNode::keepPrimitive(OctreePrimitiveData* const pPrimitive, const OctreePrimitiveType type)
OctreeNode::keepPrimitive(OctreePrimitive* const pPrimitive, const OctreePrimitiveType type)
{
pPrimitive->m_pNode = this;
pPrimitive->m_bValid = true;
......@@ -190,7 +190,7 @@ OctreeNode::keepPrimitive(OctreePrimitiveData* const pPrimitive, const OctreePri
}
void
OctreeNode::insertPoint(OctreePrimitiveData* const pPrimitive)
OctreeNode::insertPoint(OctreePrimitive* const pPrimitive)
{
// Type alias, to reduce copy/past errors
static const auto type = OctreePrimitiveType::Point;
......@@ -218,7 +218,7 @@ OctreeNode::insertPoint(OctreePrimitiveData* const pPrimitive)
}
void
OctreeNode::insertNonPointPrimitive(OctreePrimitiveData* const pPrimitive, const OctreePrimitiveType type)
OctreeNode::insertNonPointPrimitive(OctreePrimitive* const pPrimitive, const OctreePrimitiveType type)
{
const auto lowerCorner = pPrimitive->m_LowerCorner;
const auto upperCorner = pPrimitive->m_UpperCorner;
......@@ -482,7 +482,7 @@ LooseOctree::addPointSet(const std::shared_ptr<PointSet>& pointset)
addGeometry(geomIdx);
const auto numNewPrimitives = static_cast<uint32_t>(pointset->getNumVertices());
const auto pPrimitiveBlock = new OctreePrimitiveData[numNewPrimitives];
const auto pPrimitiveBlock = new OctreePrimitive[numNewPrimitives];
m_pPrimitiveBlocks[type].push_back(pPrimitiveBlock);
auto& vPrimitivePtrs = m_vPrimitivePtrs[type];
......@@ -490,7 +490,7 @@ LooseOctree::addPointSet(const std::shared_ptr<PointSet>& pointset)
for (uint32_t idx = 0; idx < numNewPrimitives; ++idx)
{
const auto pPrimitive = &pPrimitiveBlock[idx];
new(pPrimitive) OctreePrimitiveData(pGeometry, geomIdx, idx); // Placement new
new(pPrimitive) OctreePrimitive(pGeometry, geomIdx, idx); // Placement new
vPrimitivePtrs.push_back(pPrimitive);
}
......@@ -509,7 +509,7 @@ LooseOctree::addTriangleMesh(const std::shared_ptr<SurfaceMesh>& surfMesh)
addGeometry(geomIdx);
const auto numNewPrimitives = static_cast<uint32_t>(surfMesh->getNumTriangles());
const auto pPrimitiveBlock = new OctreePrimitiveData[numNewPrimitives];
const auto pPrimitiveBlock = new OctreePrimitive[numNewPrimitives];
m_pPrimitiveBlocks[type].push_back(pPrimitiveBlock);
auto& vPrimitivePtrs = m_vPrimitivePtrs[type];
......@@ -517,7 +517,7 @@ LooseOctree::addTriangleMesh(const std::shared_ptr<SurfaceMesh>& surfMesh)
for (uint32_t triIdx = 0; triIdx < numNewPrimitives; ++triIdx)
{
const auto pPrimitive = &pPrimitiveBlock[triIdx];
new(pPrimitive) OctreePrimitiveData(pGeometry, geomIdx, triIdx); // Placement new
new(pPrimitive) OctreePrimitive(pGeometry, geomIdx, triIdx); // Placement new
vPrimitivePtrs.push_back(pPrimitive);
}
......@@ -535,11 +535,11 @@ LooseOctree::addAnalyticalGeometry(const std::shared_ptr<Geometry>& geometry)
const auto geomIdx = pGeometry->getGlobalIndex();
addGeometry(geomIdx);
const auto pPrimitiveBlock = new OctreePrimitiveData[1];
const auto pPrimitiveBlock = new OctreePrimitive[1];
m_pPrimitiveBlocks[type].push_back(pPrimitiveBlock);
const auto pPrimitive = &pPrimitiveBlock[0];
new(pPrimitive) OctreePrimitiveData(pGeometry, geomIdx, 0); // Placement new
new(pPrimitive) OctreePrimitive(pGeometry, geomIdx, 0); // Placement new
m_vPrimitivePtrs[type].push_back(pPrimitive);
LOG(INFO) << "Added a new analytical geometry to " << m_Name;
......@@ -867,8 +867,8 @@ LooseOctree::removeInvalidPrimitivesFromNodes()
continue;
}
OctreePrimitiveData* pIter = pOldHead;
OctreePrimitiveData* pNewHead = nullptr;
OctreePrimitive* pIter = pOldHead;
OctreePrimitive* pNewHead = nullptr;
uint32_t count = 0;
while (pIter) {
const auto pNext = pIter->m_pNext;
......@@ -910,7 +910,7 @@ LooseOctree::reinsertInvalidPrimitives(const OctreePrimitiveType type)
}
void
LooseOctree::computePrimitiveBoundingBox(OctreePrimitiveData* const pPrimitive, const OctreePrimitiveType type)
LooseOctree::computePrimitiveBoundingBox(OctreePrimitive* const pPrimitive, const OctreePrimitiveType type)
{
#if defined(DEBUG) || defined(_DEBUG) || !defined(NDEBUG)
LOG_IF(FATAL, (type == OctreePrimitiveType::Point))
......
......@@ -33,6 +33,7 @@
#include <unordered_set>
#include <vector>
#pragma warning(disable : 4201)
namespace imstk
{
class OctreeNode;
......@@ -55,21 +56,24 @@ enum OctreePrimitiveType
};
///
/// \brief The OctreePrimitiveData struct
/// \brief The OctreePrimitive struct
/// For each octree primitive (point/triangle/analytical geometry), store its relevant data
///
struct OctreePrimitiveData
struct OctreePrimitive
{
OctreePrimitiveData() : m_pGeometry(nullptr), m_GeomIdx(0), m_Idx(0) {}
OctreePrimitiveData(Geometry* const pGeometry, const uint32_t geomIdx, const uint32_t idx = 0) :
OctreePrimitive(const OctreePrimitive&) = delete;
OctreePrimitive& operator=(const OctreePrimitive&) = delete;
OctreePrimitive() : m_pGeometry(nullptr), m_GeomIdx(0), m_Idx(0) {}
OctreePrimitive(Geometry* const pGeometry, const uint32_t geomIdx, const uint32_t idx = 0) :
m_pGeometry(pGeometry), m_GeomIdx(geomIdx), m_Idx(idx) {}
Geometry* const m_pGeometry; ///> Pointer to the parent geometry that the primitive belong to
const uint32_t m_GeomIdx; ///> Global index of the parent geometry
const uint32_t m_Idx; ///> Index of the primitive in the parent geometry (such as index of the triangle in a mesh)
Geometry* const m_pGeometry; ///> Pointer to the parent geometry that the primitive belong to
const uint32_t m_GeomIdx; ///> Global index of the parent geometry
const uint32_t m_Idx; ///> Index of the primitive in the parent geometry (such as index of the triangle in a mesh)
OctreeNode* m_pNode = nullptr; ///> Pointer to the octree node containing the primitive
OctreePrimitiveData* m_pNext = nullptr; ///> Pointer to the next node in the primitive list of the octree node
OctreeNode* m_pNode = nullptr; ///> Pointer to the octree node containing the primitive
OctreePrimitive* m_pNext = nullptr; ///> Pointer to the next node in the primitive list of the octree node
union
{
......@@ -98,8 +102,12 @@ struct OctreeNodeBlock;
class OctreeNode
{
friend class LooseOctree;
friend class OctreeBasedCD;
friend class LooseOctreeTest;
public:
OctreeNode(const OctreeNode&) = delete;
OctreeNode& operator=(const OctreeNode&) = delete;
///
/// \brief Dummy constructor, called only during memory allocation in memory pool
///
......@@ -132,7 +140,7 @@ public:
///
/// \brief For the given primitive type, return the head node of the primitive list of that type
///
OctreePrimitiveData* getPrimitiveList(const OctreePrimitiveType type) const { return m_pPrimitiveListHeads[type]; }
OctreePrimitive* getPrimitiveList(const OctreePrimitiveType type) const { return m_pPrimitiveListHeads[type]; }
///
/// \brief Get the number of primitives of the given type in this node
......@@ -165,17 +173,17 @@ public:
///
/// \brief Keep the primitive at this node as cannot pass it down further to any child node
///
void keepPrimitive(OctreePrimitiveData* const pPrimitive, const OctreePrimitiveType type);
void keepPrimitive(OctreePrimitive* const pPrimitive, const OctreePrimitiveType type);
///
/// \brief Insert a point primitive into the subtree in a top-down manner
///
void insertPoint(OctreePrimitiveData* const pPrimitive);
void insertPoint(OctreePrimitive* const pPrimitive);
///
/// \brief Insert a non-point primitive into the subtree in a top-down manner
///
void insertNonPointPrimitive(OctreePrimitiveData* const pPrimitive, const OctreePrimitiveType type);
void insertNonPointPrimitive(OctreePrimitive* const pPrimitive, const OctreePrimitiveType type);
///
/// \brief Check if the given point is contained exactly in the node boundary (bounding box)
......@@ -276,7 +284,7 @@ private:
bool m_bIsLeaf = true; ///> True if this node does not have any child node (a node should have either 0 or 8 children)
/// Heads of the link lists storing (Classified) primitives
OctreePrimitiveData* m_pPrimitiveListHeads[OctreePrimitiveType::NumPrimitiveTypes];
OctreePrimitive* m_pPrimitiveListHeads[OctreePrimitiveType::NumPrimitiveTypes];
/// Count the number of (classified) primitives stored in this node
uint32_t m_PrimitiveCounts[OctreePrimitiveType::NumPrimitiveTypes];
......@@ -481,7 +489,7 @@ protected:
///
/// \brief Compute the AABB bounding box of a non-point primitive
///
void computePrimitiveBoundingBox(OctreePrimitiveData* const pPrimitive, const OctreePrimitiveType type);
void computePrimitiveBoundingBox(OctreePrimitive* const pPrimitive, const OctreePrimitiveType type);
///
/// \brief Request a block of 8 tree nodes from memory pool (this is called only during splitting node)
......@@ -528,11 +536,11 @@ protected:
std::vector<OctreeNodeBlock*> m_pNodeBigBlocks;
/// Store pointers of primitives created from geometry elements, such as points, triangles, analytical geometries
std::vector<OctreePrimitiveData*> m_vPrimitivePtrs[OctreePrimitiveType::NumPrimitiveTypes];
std::vector<OctreePrimitive*> m_vPrimitivePtrs[OctreePrimitiveType::NumPrimitiveTypes];
/// During memory allocation for primitives, multiple primitives are allocated at the same time from a big memory block
/// This variable store the first address of such big memory block, used during primitive deallocation
std::vector<OctreePrimitiveData*> m_pPrimitiveBlocks[OctreePrimitiveType::NumPrimitiveTypes];
std::vector<OctreePrimitive*> m_pPrimitiveBlocks[OctreePrimitiveType::NumPrimitiveTypes];
/// List of all indices of the added geometries, to check for duplication such that one geometry cannot be mistakenly added multiple times
std::unordered_set<uint32_t> m_sGeometryIndices;
......@@ -548,3 +556,4 @@ protected:
bool m_bDrawNonEmptyParent = true;
};
} // end namespace imstk
#pragma warning(default : 4201)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment