ENH: support construction of pointIndexHit from pointHit

STYLE: combine templated/non-templated headers (reduced clutter)

STYLE: use hitPoint(const point&) combined setter

- same as setHit() + setPoint(const point&)

ENH: expose and use labelOctBits::pack method for addressing
This commit is contained in:
Mark Olesen
2022-10-13 11:23:35 +02:00
parent 454f7960b0
commit 9433898941
29 changed files with 689 additions and 760 deletions

View File

@ -365,7 +365,7 @@ Foam::volumeType Foam::dynamicIndexedOctree<Type>::calcVolumeType
}
// Store octant type
nodeTypes_.set((nodeI<<3)+octant, subType);
nodeTypes_.set(labelBits::pack(nodeI, octant), subType);
// Combine sub node types into type for treeNode. Result is 'mixed' if
// types differ among subnodes.
@ -393,7 +393,11 @@ Foam::volumeType Foam::dynamicIndexedOctree<Type>::getVolumeType
direction octant = nod.bb_.subOctant(sample);
volumeType octantType = volumeType::type(nodeTypes_.get((nodeI<<3)+octant));
volumeType octantType =
volumeType::type
(
nodeTypes_.get(labelBits::pack(nodeI, octant))
);
if (octantType == volumeType::INSIDE)
{
@ -1418,9 +1422,8 @@ void Foam::dynamicIndexedOctree<Type>::traverseNode
{
// Hit so pt is nearer than nearestPoint.
// Update hit info
hitInfo.setHit();
hitInfo.hitPoint(pt);
hitInfo.setIndex(shapeI);
hitInfo.setPoint(pt);
return;
}
}
@ -1456,9 +1459,8 @@ void Foam::dynamicIndexedOctree<Type>::traverseNode
// Hit so pt is nearer than nearestPoint.
nearestPoint = pt;
// Update hit info
hitInfo.setHit();
hitInfo.hitPoint(pt);
hitInfo.setIndex(shapeI);
hitInfo.setPoint(pt);
}
}

View File

@ -383,7 +383,7 @@ Foam::volumeType Foam::indexedOctree<Type>::calcVolumeType
}
// Store octant type
nodeTypes_.set((nodeI<<3)+octant, subType);
nodeTypes_.set(labelBits::pack(nodeI, octant), subType);
// Combine sub node types into type for treeNode. Result is 'mixed' if
// types differ among subnodes.
@ -411,7 +411,10 @@ Foam::volumeType Foam::indexedOctree<Type>::getVolumeType
direction octant = nod.bb_.subOctant(sample);
volumeType octantType = volumeType::type(nodeTypes_.get((nodeI<<3)+octant));
volumeType octantType = volumeType::type
(
nodeTypes_.get(labelBits::pack(nodeI, octant))
);
if (octantType == volumeType::INSIDE)
{
@ -1448,9 +1451,8 @@ void Foam::indexedOctree<Type>::traverseNode
{
// Hit so pt is nearer than nearestPoint.
// Update hit info
hitInfo.setHit();
hitInfo.hitPoint(pt);
hitInfo.setIndex(shapeI);
hitInfo.setPoint(pt);
return;
}
}
@ -1480,9 +1482,8 @@ void Foam::indexedOctree<Type>::traverseNode
// Hit so pt is nearer than nearestPoint.
nearestPoint = pt;
// Update hit info
hitInfo.setHit();
hitInfo.hitPoint(pt);
hitInfo.setIndex(shapeI);
hitInfo.setPoint(pt);
}
}

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,17 +28,15 @@ Class
Foam::labelBits
Description
A 29bits label and 3bits direction packed into single label
SourceFiles
A 29bits (or 61bits) integer label with 3bits direction
(eg, octant) packed into single label
\*---------------------------------------------------------------------------*/
#ifndef labelBits_H
#define labelBits_H
#ifndef Foam_labelBits_H
#define Foam_labelBits_H
#include "label.H"
//#include "uLabel.H"
#include "direction.H"
#include "error.H"
@ -46,20 +45,33 @@ SourceFiles
namespace Foam
{
// Forward Declarations
class labelBits;
/*---------------------------------------------------------------------------*\
Class labelBits Declaration
Class labelBits Declaration
\*---------------------------------------------------------------------------*/
class labelBits
{
// Private data
// Private Data
//- Integer value and (octant) direction
label data_;
inline static label pack(const label val, const direction bits)
public:
// Static Functions
#ifdef FULLDEBUG
//- Pack integer value and bits (octant) into a label
inline static label pack
(
const label val,
const direction bits
)
{
#ifdef FULLDEBUG
if (bits > 7 || (((val<<3)>>3) != val))
{
FatalErrorInFunction
@ -68,51 +80,64 @@ class labelBits
<< label(8*sizeof(label)-3) << " bit representation"
<< abort(FatalError);
}
#endif
return (val<<3) | bits;
}
public:
#else
//- Pack integer value and bits (octant) into a label
static constexpr label pack
(
const label val,
const direction bits
) noexcept
{
return (val<<3) | bits;
}
#endif
// Constructors
//- Construct null
inline labelBits()
//- Default construct as zero initialized
constexpr labelBits() noexcept
:
data_(0)
{}
//- Construct from components
inline labelBits(const label val, const direction bits)
labelBits(const label val, const direction bits)
:
data_(pack(val, bits))
{}
//- Construct from Istream
inline labelBits(Istream& is)
//- Read construct from Istream
explicit labelBits(Istream& is)
{
is >> data_;
}
// Member Functions
inline label val() const
{
return data_ >> 3;
}
//- The raw data value
label data() const noexcept { return data_; }
inline direction bits() const
{
return data_ & 7;
}
//- Return the integer value
label val() const noexcept { return (data_ >> 3); }
inline void setVal(const label val)
//- Return the octant direction
direction bits() const noexcept { return (data_ & 7); }
//- Set the integer value
void setVal(const label val)
{
data_ = pack(val, bits());
}
inline void setBits(const direction bits)
//- Set the octant direction
void setBits(const direction bits)
{
data_ = pack(val(), bits);
}
@ -120,26 +145,31 @@ public:
// Member Operators
inline friend bool operator==(const labelBits& a, const labelBits& b)
inline friend
bool operator==(const labelBits& a, const labelBits& b)
{
return a.data_ == b.data_;
}
inline friend bool operator!=(const labelBits& a, const labelBits& b)
inline friend
bool operator!=(const labelBits& a, const labelBits& b)
{
return !(a == b);
}
// IOstream Operators
inline friend Istream& operator>>(Istream& is, labelBits& lb)
inline friend
Istream& operator>>(Istream& is, labelBits& rhs)
{
return is >> lb.data_;
return is >> rhs.data_;
}
inline friend Ostream& operator<<(Ostream& os, const labelBits& lb)
inline friend
Ostream& operator<<(Ostream& os, const labelBits& rhs)
{
return os << lb.data_;
return os << rhs.data_;
}
};

View File

@ -107,7 +107,7 @@ public:
//- Construct from integer
explicit volumeType(const int t)
:
t_(static_cast<volumeType::type>(t))
t_(static_cast<volumeType::type>(t & 0x3))
{}