chombo-discharge
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
TriangleCollection Class Reference

Class that represents a set of triangles. More...

#include <CD_TriangleCollection.H>

Public Types

using Vec3 = Triangle::Vec3
 3D vector type, re-exported from Triangle for convenience.
 
using BV = EBGeometry::BoundingVolumes::AABBT< Real >
 Bounding volume type.
 

Public Member Functions

 TriangleCollection () noexcept
 Default constructor.
 
 TriangleCollection (const std::vector< std::shared_ptr< Triangle > > &a_triangles) noexcept
 Full constructor. Takes the input triangles and stores them in a BVH-tree.
 
 TriangleCollection (const std::string &a_filename, const std::string &a_vertexDataIdentifier)
 File-reading constructor. Reads a PLY or VTK mesh file and builds the BVH.
 
virtual ~TriangleCollection () noexcept
 Destructor (does nothing).
 
virtual void define (const std::vector< std::shared_ptr< Triangle > > &a_triangles) noexcept
 Build the BVH tree from a set of triangles.
 
virtual std::vector< std::pair< std::shared_ptr< const Triangle >, Real > > getClosestTriangles (const Vec3 &a_point) const noexcept
 Hierarchical BVH search that returns candidate closest triangles to a query point.
 

Static Public Attributes

static constexpr int K = 4
 Branching factor for BVH tree.
 

Protected Attributes

bool m_isDefined = false
 Is defined or not.
 
std::shared_ptr< EBGeometry::BVH::LinearBVH< Real, Triangle, BV, K > > m_bvh
 Triangle collection – stored in a BVH-tree for faster lookup.
 

Detailed Description

Class that represents a set of triangles.

This class uses the bounding volume hierarchies supplied by EBGeometry to organize and query a collection of Triangle objects.

Interpolation.** Each Triangle carries a scalar value at each of its three vertices. Given a query point, the typical workflow is:

  1. Call getClosestTriangles() to obtain the nearest triangle (first entry of the returned list).
  2. Call Triangle::interpolate() on that triangle to evaluate the scalar field at the query point.

Triangle::interpolate() uses two different strategies depending on where the query point falls:

The outside-triangle path is therefore a bounded, range-preserving extrapolation rather than an unconstrained linear extrapolation. Degenerate triangles (zero area) always return zero.

Constructor & Destructor Documentation

◆ TriangleCollection() [1/3]

TriangleCollection::TriangleCollection ( )
noexcept

Default constructor.

Leaves the object in an undefined state (m_isDefined = false). define() must be called before getClosestTriangles() can be used.

◆ TriangleCollection() [2/3]

TriangleCollection::TriangleCollection ( const std::vector< std::shared_ptr< Triangle > > &  a_triangles)
noexcept

Full constructor. Takes the input triangles and stores them in a BVH-tree.

Calls define(). The object is ready for use immediately after construction.

Parameters
[in]a_trianglesInput triangles. Must be non-empty and must already have their vertex positions and meta-data set.

◆ TriangleCollection() [3/3]

TriangleCollection::TriangleCollection ( const std::string a_filename,
const std::string a_vertexDataIdentifier 
)

File-reading constructor. Reads a PLY or VTK mesh file and builds the BVH.

Calls DataParser::readTriangles() to parse the file and populate Triangle vertex positions and metadata, then calls define() to build the BVH. Equivalent to constructing with the default constructor and then calling define(DataParser::readTriangles(a_filename, a_vertexDataIdentifier)). Issues a fatal error for unsupported file types and a warning if the vertex data identifier is not found in the file (vertex data defaults to zero in that case).

Parameters
[in]a_filenamePath to the input mesh file (.ply or .vtk).
[in]a_vertexDataIdentifierName of the per-vertex scalar property to read as Triangle vertex metadata.

Member Function Documentation

◆ define()

void TriangleCollection::define ( const std::vector< std::shared_ptr< Triangle > > &  a_triangles)
virtualnoexcept

Build the BVH tree from a set of triangles.

Packs each triangle into an axis-aligned bounding box, constructs a K-ary BVH using top-down partitioning, and flattens it into a linear layout for cache-friendly traversal. Sets m_isDefined to true on success. This is the same operation performed by the full constructor; use it to (re-)initialize an object that was default-constructed or needs to be rebuilt.

Parameters
[in]a_trianglesInput triangles. Must be non-empty and must already have their vertex positions and meta-data set.

◆ getClosestTriangles()

std::vector< std::pair< std::shared_ptr< const Triangle >, Real > > TriangleCollection::getClosestTriangles ( const Vec3 a_point) const
virtualnoexcept

Hierarchical BVH search that returns candidate closest triangles to a query point.

Traverses the BVH closest-node-first, pruning any node whose bounding volume distance exceeds the shortest triangle distance found so far. At each leaf the pruning threshold is tightened as each closer triangle is encountered, so the returned list contains every triangle that was the shortest-distance-so-far at the moment it was evaluated. As a result the list may include triangles that are not among the globally closest once the full traversal is complete; callers should use the first entry (index 0) as the definitive closest triangle. Requires define() to have been called first.

Parameters
[in]a_pointQuery point in 3D space.
Returns
Candidate triangles paired with their unsigned distance to a_point, sorted ascending by distance. The first entry is the closest triangle found.

The documentation for this class was generated from the following files: