Statistics Contourmap UI updates (#12060)

* Enable time step selections and controls in view
* Support loading just what we need for statistics contour maps by using custom reader settings
* Close case once done with it unless there are active views.
* Add selection of user interface case (for result selection, display of wells, faults...)
* Avoid int overflow for nested progresses by using double
* Improve auto naming
* Misc. UI improvements
This commit is contained in:
jonjenssen
2025-01-14 21:52:54 +01:00
committed by GitHub
parent ba1224c9de
commit b999faf293
47 changed files with 1238 additions and 774 deletions

View File

@@ -323,11 +323,11 @@ static std::vector<size_t>& progressSpanStack()
/// Calculate the total maximum value for the progress bar composed
/// of the complete stack
//--------------------------------------------------------------------------------------------------
static size_t currentTotalMaxProgressValue()
static double currentTotalMaxProgressValue()
{
std::vector<size_t>& maxProgressStack_v = maxProgressStack();
size_t levCount = 1;
double levCount = 1.0;
for ( size_t levelDepth = 0; levelDepth < maxProgressStack_v.size(); ++levelDepth )
{
levCount *= maxProgressStack_v[levelDepth];
@@ -338,7 +338,7 @@ static size_t currentTotalMaxProgressValue()
//--------------------------------------------------------------------------------------------------
/// Calculate the total progress value based on the current level subdivision and progress
//--------------------------------------------------------------------------------------------------
static size_t currentTotalProgress()
static double currentTotalProgress()
{
double progress = 0;
@@ -349,12 +349,12 @@ static size_t currentTotalProgress()
for ( int i = static_cast<int>( progressStack_v.size() ) - 1; i >= 0; --i )
{
size_t span = ( i < 1 ) ? 1 : progressSpanStack_v[i - 1];
progress = span * ( progress + progressStack_v[i] ) / (double)maxProgressStack_v[i];
progress = 1.0 * span * ( progress + progressStack_v[i] ) / (double)maxProgressStack_v[i];
}
size_t totalIntProgress = static_cast<size_t>( currentTotalMaxProgressValue() * progress );
double totalProgress = currentTotalMaxProgressValue() * progress;
return totalIntProgress;
return totalProgress;
}
//--------------------------------------------------------------------------------------------------
@@ -533,8 +533,9 @@ void ProgressInfoStatic::start( ProgressInfo& progressInfo,
if ( dialog )
{
dialog->setMaximum( static_cast<int>( currentTotalMaxProgressValue() ) );
dialog->setValue( static_cast<int>( currentTotalProgress() ) );
double value = currentTotalProgress() / currentTotalMaxProgressValue();
dialog->setMaximum( 100 );
dialog->setValue( (int)( 100.0 * value ) );
dialog->setLabelText( currentComposedLabel() );
}
@@ -583,10 +584,10 @@ void ProgressInfoStatic::setProgress( size_t progressValue )
progressStack_v.back() = progressValue;
progressSpanStack_v.back() = 1;
int totalProgress = static_cast<int>( currentTotalProgress() );
int totalMaxProgress = static_cast<int>( currentTotalMaxProgressValue() );
double totalProgress = currentTotalProgress();
double totalMaxProgress = currentTotalMaxProgressValue();
if ( static_cast<int>( totalProgress ) > totalMaxProgress )
if ( totalProgress > totalMaxProgress )
{
reportError( "totalProgress > totalMaxProgress"
", totalProgress == " +
@@ -597,8 +598,9 @@ void ProgressInfoStatic::setProgress( size_t progressValue )
QProgressDialog* dialog = progressDialog();
if ( dialog )
{
dialog->setMaximum( totalMaxProgress );
dialog->setValue( totalProgress );
double value = currentTotalProgress() / currentTotalMaxProgressValue();
dialog->setMaximum( 100 );
dialog->setValue( (int)( 100.0 * value ) );
}
if ( s_shouldProcessEvents ) QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents );

View File

@@ -45,409 +45,432 @@ namespace cvf {
//==================================================================================================
///
/// \class cvf::BoundingBox
/// \ingroup Geometry
///
/// The BoundingBox class implements an axis-aligned bounding box.
///
//==================================================================================================
//==================================================================================================
///
/// \class cvf::BoundingBox
/// \ingroup Geometry
///
/// The BoundingBox class implements an axis-aligned bounding box.
///
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
BoundingBox::BoundingBox()
{
reset();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
BoundingBox::BoundingBox(const Vec3d& min, const Vec3d& max)
: m_min(min), m_max(max)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
BoundingBox::BoundingBox(const Vec3f& min, const Vec3f& max)
: m_min(min), m_max(max)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
BoundingBox::BoundingBox(const BoundingBox& other)
: m_min(other.m_min),
m_max(other.m_max)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
BoundingBox& BoundingBox::operator=(const BoundingBox& rhs)
{
m_min = rhs.m_min;
m_max = rhs.m_max;
return *this;
}
//--------------------------------------------------------------------------------------------------
/// Initialize bounding box
//--------------------------------------------------------------------------------------------------
void BoundingBox::reset()
{
const double maxDouble = std::numeric_limits<double>::max();
m_max.set(-maxDouble, -maxDouble, -maxDouble);
m_min.set( maxDouble, maxDouble, maxDouble);
}
//--------------------------------------------------------------------------------------------------
/// Returns false if no input has been given
//--------------------------------------------------------------------------------------------------
bool BoundingBox::isValid() const
{
if (m_min.x() <= m_max.x() &&
m_min.y() <= m_max.y() &&
m_min.z() <= m_max.z())
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
BoundingBox::BoundingBox()
{
reset();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
BoundingBox::BoundingBox(const Vec3d& min, const Vec3d& max)
: m_min(min), m_max(max)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
BoundingBox::BoundingBox(const Vec3f& min, const Vec3f& max)
: m_min(min), m_max(max)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
BoundingBox::BoundingBox(const BoundingBox& other)
: m_min(other.m_min),
m_max(other.m_max)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
BoundingBox& BoundingBox::operator=(const BoundingBox& rhs)
{
m_min = rhs.m_min;
m_max = rhs.m_max;
return *this;
}
//--------------------------------------------------------------------------------------------------
/// Initialize bounding box
//--------------------------------------------------------------------------------------------------
void BoundingBox::reset()
{
const double maxDouble = std::numeric_limits<double>::max();
m_max.set(-maxDouble, -maxDouble, -maxDouble);
m_min.set(maxDouble, maxDouble, maxDouble);
}
//--------------------------------------------------------------------------------------------------
/// Returns false if no input has been given
//--------------------------------------------------------------------------------------------------
bool BoundingBox::isValid() const
{
if (m_min.x() <= m_max.x() &&
m_min.y() <= m_max.y() &&
m_min.z() <= m_max.z())
{
return true;
}
else
{
return false;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void BoundingBox::add(const Vec3d& point)
{
if (point.x() < m_min.x()) m_min.x() = point.x();
if (point.y() < m_min.y()) m_min.y() = point.y();
if (point.z() < m_min.z()) m_min.z() = point.z();
if (point.x() > m_max.x()) m_max.x() = point.x();
if (point.y() > m_max.y()) m_max.y() = point.y();
if (point.z() > m_max.z()) m_max.z() = point.z();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void BoundingBox::add(const Vec3f& point)
{
if (point.x() < m_min.x()) m_min.x() = point.x();
if (point.y() < m_min.y()) m_min.y() = point.y();
if (point.z() < m_min.z()) m_min.z() = point.z();
if (point.x() > m_max.x()) m_max.x() = point.x();
if (point.y() > m_max.y()) m_max.y() = point.y();
if (point.z() > m_max.z()) m_max.z() = point.z();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void BoundingBox::add(const Vec3dArray& points)
{
size_t i;
for (i = 0; i < points.size(); i++)
{
add(points[i]);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void BoundingBox::add(const Vec3fArray& points)
{
size_t i;
for (i = 0; i < points.size(); i++)
{
add(points[i]);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void BoundingBox::add(const BoundingBox& bb)
{
if (bb.isValid())
{
add(bb.min());
add(bb.max());
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void BoundingBox::addValid(const BoundingBox& bb)
{
if (bb.m_min.x() < m_min.x()) m_min.x() = bb.m_min.x();
if (bb.m_min.y() < m_min.y()) m_min.y() = bb.m_min.y();
if (bb.m_min.z() < m_min.z()) m_min.z() = bb.m_min.z();
if (bb.m_max.x() > m_max.x()) m_max.x() = bb.m_max.x();
if (bb.m_max.y() > m_max.y()) m_max.y() = bb.m_max.y();
if (bb.m_max.z() > m_max.z()) m_max.z() = bb.m_max.z();
}
//--------------------------------------------------------------------------------------------------
/// Computes center of the bounding box
//--------------------------------------------------------------------------------------------------
Vec3d BoundingBox::center() const
{
CVF_TIGHT_ASSERT(isValid());
return (m_min + m_max) / 2.0;
}
//--------------------------------------------------------------------------------------------------
/// Computes the total size of the bounding box
//--------------------------------------------------------------------------------------------------
Vec3d BoundingBox::extent() const
{
if (!isValid()) return { 0,0,0 };
return (m_max - m_min);
}
//--------------------------------------------------------------------------------------------------
/// Compute radius as half the length of the box's diagonal
//--------------------------------------------------------------------------------------------------
double BoundingBox::radius() const
{
if (!isValid()) return 0.0;
return extent().length() / 2.0;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const Vec3d& BoundingBox::min() const
{
CVF_TIGHT_ASSERT(isValid());
return m_min;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const Vec3d& BoundingBox::max() const
{
CVF_TIGHT_ASSERT(isValid());
return m_max;
}
//--------------------------------------------------------------------------------------------------
/// Check if the bounding box contains the specified point
///
/// Note that a point on the box's surface is classified as being contained
//--------------------------------------------------------------------------------------------------
bool BoundingBox::contains(const Vec3d& point) const
{
if (!isValid()) return false;
if (point.x() >= m_min.x() && point.x() <= m_max.x() &&
point.y() >= m_min.y() && point.y() <= m_max.y() &&
point.z() >= m_min.z() && point.z() <= m_max.z())
{
return true;
}
else
{
return false;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool BoundingBox::intersects(const BoundingBox& box) const
{
if (!isValid() || !box.isValid()) return false;
if (m_max.x() < box.m_min.x() || m_min.x() > box.m_max.x()) return false;
if (m_max.y() < box.m_min.y() || m_min.y() > box.m_max.y()) return false;
if (m_max.z() < box.m_min.z() || m_min.z() > box.m_max.z()) return false;
return true;
}
else
//--------------------------------------------------------------------------------------------------
/// Get corner points of box
///
/// \param corners Array of Vec3d. Must be allocated 8 vectors long.
///
/// <PRE>
/// 7---------6
/// /| /| |z
/// / | / | | / y
/// 4---------5 | |/
/// | 3------|--2 *---x
/// | / | /
/// |/ |/
/// 0---------1 </PRE>
///
//--------------------------------------------------------------------------------------------------
void BoundingBox::cornerVertices(Vec3d corners[8]) const
{
return false;
corners[0].set(m_min.x(), m_min.y(), m_min.z());
corners[1].set(m_max.x(), m_min.y(), m_min.z());
corners[2].set(m_max.x(), m_max.y(), m_min.z());
corners[3].set(m_min.x(), m_max.y(), m_min.z());
corners[4].set(m_min.x(), m_min.y(), m_max.z());
corners[5].set(m_max.x(), m_min.y(), m_max.z());
corners[6].set(m_max.x(), m_max.y(), m_max.z());
corners[7].set(m_min.x(), m_max.y(), m_max.z());
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void BoundingBox::add(const Vec3d& point)
{
if (point.x() < m_min.x()) m_min.x() = point.x();
if (point.y() < m_min.y()) m_min.y() = point.y();
if (point.z() < m_min.z()) m_min.z() = point.z();
if (point.x() > m_max.x()) m_max.x() = point.x();
if (point.y() > m_max.y()) m_max.y() = point.y();
if (point.z() > m_max.z()) m_max.z() = point.z();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void BoundingBox::add(const Vec3f& point)
{
if (point.x() < m_min.x()) m_min.x() = point.x();
if (point.y() < m_min.y()) m_min.y() = point.y();
if (point.z() < m_min.z()) m_min.z() = point.z();
if (point.x() > m_max.x()) m_max.x() = point.x();
if (point.y() > m_max.y()) m_max.y() = point.y();
if (point.z() > m_max.z()) m_max.z() = point.z();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void BoundingBox::add(const Vec3dArray& points)
{
size_t i;
for (i = 0; i < points.size(); i++)
//--------------------------------------------------------------------------------------------------
/// Expands the bounding box by the given amount in all three directions
///
/// If a bounding box is expanded by 2, the bounding box's size will increase by 2 in each direction
/// \sa extent()
//--------------------------------------------------------------------------------------------------
void BoundingBox::expand(double amount)
{
add(points[i]);
double half = amount / 2;
m_min.x() -= half;
m_min.y() -= half;
m_min.z() -= half;
m_max.x() += half;
m_max.y() += half;
m_max.z() += half;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void BoundingBox::add(const Vec3fArray& points)
{
size_t i;
for (i = 0; i < points.size(); i++)
//--------------------------------------------------------------------------------------------------
/// Expands the bounding box by the given percent in all three directions
///
/// If a bounding box is expanded by 10%, the bounding box's size will increase by 5% in each direction
//--------------------------------------------------------------------------------------------------
void BoundingBox::expandPercent(double percent)
{
add(points[i]);
const auto ext = extent();
const double factor = percent / 100.0;
const double xHalf = (ext.x() / 2) * factor;
const double yHalf = (ext.y() / 2) * factor;
const double zHalf = (ext.z() / 2) * factor;
m_min.x() -= xHalf;
m_min.y() -= yHalf;
m_min.z() -= zHalf;
m_max.x() += xHalf;
m_max.y() += yHalf;
m_max.z() += zHalf;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void BoundingBox::add(const BoundingBox& bb)
{
if (bb.isValid())
//--------------------------------------------------------------------------------------------------
/// Transform the min and max coordinate with the given transformation matrix
//--------------------------------------------------------------------------------------------------
void BoundingBox::transform(const Mat4d& matrix)
{
add(bb.min());
add(bb.max());
// Check if box is invalid, and don't transform if so
if (!isValid()) return;
BoundingBox newBox;
newBox.reset();
Vec3d node;
node.set(m_min.x(), m_min.y(), m_min.z());
node.transformPoint(matrix);
newBox.add(node);
node.set(m_max.x(), m_min.y(), m_min.z());
node.transformPoint(matrix);
newBox.add(node);
node.set(m_max.x(), m_max.y(), m_min.z());
node.transformPoint(matrix);
newBox.add(node);
node.set(m_min.x(), m_max.y(), m_min.z());
node.transformPoint(matrix);
newBox.add(node);
node.set(m_min.x(), m_min.y(), m_max.z());
node.transformPoint(matrix);
newBox.add(node);
node.set(m_max.x(), m_min.y(), m_max.z());
node.transformPoint(matrix);
newBox.add(node);
node.set(m_max.x(), m_max.y(), m_max.z());
node.transformPoint(matrix);
newBox.add(node);
node.set(m_min.x(), m_max.y(), m_max.z());
node.transformPoint(matrix);
newBox.add(node);
*this = newBox;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void BoundingBox::addValid(const BoundingBox& bb)
{
if (bb.m_min.x() < m_min.x()) m_min.x() = bb.m_min.x();
if (bb.m_min.y() < m_min.y()) m_min.y() = bb.m_min.y();
if (bb.m_min.z() < m_min.z()) m_min.z() = bb.m_min.z();
if (bb.m_max.x() > m_max.x()) m_max.x() = bb.m_max.x();
if (bb.m_max.y() > m_max.y()) m_max.y() = bb.m_max.y();
if (bb.m_max.z() > m_max.z()) m_max.z() = bb.m_max.z();
}
//--------------------------------------------------------------------------------------------------
/// Computes center of the bounding box
//--------------------------------------------------------------------------------------------------
Vec3d BoundingBox::center() const
{
CVF_TIGHT_ASSERT(isValid());
return (m_min + m_max) / 2.0;
}
//--------------------------------------------------------------------------------------------------
/// Computes the total size of the bounding box
//--------------------------------------------------------------------------------------------------
Vec3d BoundingBox::extent() const
{
if (!isValid()) return { 0,0,0 };
return (m_max - m_min);
}
//--------------------------------------------------------------------------------------------------
/// Compute radius as half the length of the box's diagonal
//--------------------------------------------------------------------------------------------------
double BoundingBox::radius() const
{
if (!isValid()) return 0.0;
return extent().length() / 2.0;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const Vec3d& BoundingBox::min() const
{
CVF_TIGHT_ASSERT(isValid());
return m_min;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const Vec3d& BoundingBox::max() const
{
CVF_TIGHT_ASSERT(isValid());
return m_max;
}
//--------------------------------------------------------------------------------------------------
/// Check if the bounding box contains the specified point
///
/// Note that a point on the box's surface is classified as being contained
//--------------------------------------------------------------------------------------------------
bool BoundingBox::contains(const Vec3d& point) const
{
if (!isValid()) return false;
if (point.x() >= m_min.x() && point.x() <= m_max.x() &&
point.y() >= m_min.y() && point.y() <= m_max.y() &&
point.z() >= m_min.z() && point.z() <= m_max.z())
//--------------------------------------------------------------------------------------------------
/// Returns this BoundingBox transformed with the given transformation matrix
//--------------------------------------------------------------------------------------------------
const BoundingBox BoundingBox::getTransformed(const Mat4d& matrix) const
{
return true;
BoundingBox box(*this);
box.transform(matrix);
return box;
}
else
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
String BoundingBox::debugString() const
{
return false;
String str = "BoundingBox:";
str += " min: x=" + String::number(m_min.x()) + " y=" + String::number(m_min.y()) + " z=" + String::number(m_min.z());
str += " max: x=" + String::number(m_max.x()) + " y=" + String::number(m_max.y()) + " z=" + String::number(m_max.z());
return str;
}
}
//--------------------------------------------------------------------------------------------------
/// Cuts the box at the given depth, to never go below the given depth
///
/// Note: cutting is a one time operation, adding new points to the box might extend the box below the cut depth
//--------------------------------------------------------------------------------------------------
void BoundingBox::cutBelow(double depth)
{
if (m_min.z() < depth) m_min.z() = depth;
if (m_max.z() < depth) m_max.z() = depth;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool BoundingBox::intersects(const BoundingBox& box) const
{
if (!isValid() || !box.isValid()) return false;
if (m_max.x() < box.m_min.x() || m_min.x() > box.m_max.x()) return false;
if (m_max.y() < box.m_min.y() || m_min.y() > box.m_max.y()) return false;
if (m_max.z() < box.m_min.z() || m_min.z() > box.m_max.z()) return false;
return true;
}
//--------------------------------------------------------------------------------------------------
/// Get corner points of box
///
/// \param corners Array of Vec3d. Must be allocated 8 vectors long.
///
/// <PRE>
/// 7---------6
/// /| /| |z
/// / | / | | / y
/// 4---------5 | |/
/// | 3------|--2 *---x
/// | / | /
/// |/ |/
/// 0---------1 </PRE>
///
//--------------------------------------------------------------------------------------------------
void BoundingBox::cornerVertices(Vec3d corners[8]) const
{
corners[0].set(m_min.x(), m_min.y(), m_min.z());
corners[1].set(m_max.x(), m_min.y(), m_min.z());
corners[2].set(m_max.x(), m_max.y(), m_min.z());
corners[3].set(m_min.x(), m_max.y(), m_min.z());
corners[4].set(m_min.x(), m_min.y(), m_max.z());
corners[5].set(m_max.x(), m_min.y(), m_max.z());
corners[6].set(m_max.x(), m_max.y(), m_max.z());
corners[7].set(m_min.x(), m_max.y(), m_max.z());
}
//--------------------------------------------------------------------------------------------------
/// Expands the bounding box by the given amount in all three directions
///
/// If a bounding box is expanded by 2, the bounding box's size will increase by 2 in each direction
/// \sa extent()
//--------------------------------------------------------------------------------------------------
void BoundingBox::expand(double amount)
{
double half = amount/2;
m_min.x() -= half;
m_min.y() -= half;
m_min.z() -= half;
m_max.x() += half;
m_max.y() += half;
m_max.z() += half;
}
//--------------------------------------------------------------------------------------------------
/// Transform the min and max coordinate with the given transformation matrix
//--------------------------------------------------------------------------------------------------
void BoundingBox::transform(const Mat4d& matrix)
{
// Check if box is invalid, and don't transform if so
if (!isValid()) return;
BoundingBox newBox;
newBox.reset();
Vec3d node;
node.set(m_min.x(), m_min.y(), m_min.z());
node.transformPoint(matrix);
newBox.add(node);
node.set(m_max.x(), m_min.y(), m_min.z());
node.transformPoint(matrix);
newBox.add(node);
node.set(m_max.x(), m_max.y(), m_min.z());
node.transformPoint(matrix);
newBox.add(node);
node.set(m_min.x(), m_max.y(), m_min.z());
node.transformPoint(matrix);
newBox.add(node);
node.set(m_min.x(), m_min.y(), m_max.z());
node.transformPoint(matrix);
newBox.add(node);
node.set(m_max.x(), m_min.y(), m_max.z());
node.transformPoint(matrix);
newBox.add(node);
node.set(m_max.x(), m_max.y(), m_max.z());
node.transformPoint(matrix);
newBox.add(node);
node.set(m_min.x(), m_max.y(), m_max.z());
node.transformPoint(matrix);
newBox.add(node);
*this = newBox;
}
//--------------------------------------------------------------------------------------------------
/// Returns this BoundingBox transformed with the given transformation matrix
//--------------------------------------------------------------------------------------------------
const BoundingBox BoundingBox::getTransformed(const Mat4d& matrix) const
{
BoundingBox box(*this);
box.transform(matrix);
return box;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
String BoundingBox::debugString() const
{
String str = "BoundingBox:";
str += " min: x=" + String::number(m_min.x()) + " y=" + String::number(m_min.y()) + " z=" + String::number(m_min.z());
str += " max: x=" + String::number(m_max.x()) + " y=" + String::number(m_max.y()) + " z=" + String::number(m_max.z());
return str;
}
//--------------------------------------------------------------------------------------------------
/// Cuts the box at the given depth, to never go below the given depth
///
/// Note: cutting is a one time operation, adding new points to the box might extend the box below the cut depth
//--------------------------------------------------------------------------------------------------
void BoundingBox::cutBelow(double depth)
{
if (m_min.z() < depth) m_min.z() = depth;
if (m_max.z() < depth) m_max.z() = depth;
}
//--------------------------------------------------------------------------------------------------
/// Cuts the box at the given depth, to never go above the given depth
///
/// Note: cutting is a one time operation, adding new points to the box might extend the box below the cut depth
//--------------------------------------------------------------------------------------------------
void BoundingBox::cutAbove(double depth)
{
if (m_min.z() > depth) m_min.z() = depth;
if (m_max.z() > depth) m_max.z() = depth;
}
//--------------------------------------------------------------------------------------------------
/// Cuts the box at the given depth, to never go above the given depth
///
/// Note: cutting is a one time operation, adding new points to the box might extend the box below the cut depth
//--------------------------------------------------------------------------------------------------
void BoundingBox::cutAbove(double depth)
{
if (m_min.z() > depth) m_min.z() = depth;
if (m_max.z() > depth) m_max.z() = depth;
}

View File

@@ -44,56 +44,57 @@
namespace cvf {
//==================================================================================================
//
// Axis aligned bounding box
//
//==================================================================================================
class BoundingBox
{
public:
BoundingBox();
BoundingBox(const Vec3f& min, const Vec3f& max);
BoundingBox(const Vec3d& min, const Vec3d& max);
BoundingBox(const BoundingBox& other);
//==================================================================================================
//
// Axis aligned bounding box
//
//==================================================================================================
class BoundingBox
{
public:
BoundingBox();
BoundingBox(const Vec3f& min, const Vec3f& max);
BoundingBox(const Vec3d& min, const Vec3d& max);
BoundingBox(const BoundingBox& other);
BoundingBox& operator=(const BoundingBox& rhs);
BoundingBox& operator=(const BoundingBox& rhs);
void reset();
void reset();
bool isValid() const;
bool isValid() const;
void add(const Vec3f& vertex);
void add(const Vec3d& vertex);
void add(const Vec3fArray& vertices);
void add(const Vec3dArray& vertices);
void add(const BoundingBox& bb);
void addValid(const BoundingBox& bb);
void add(const Vec3f& vertex);
void add(const Vec3d& vertex);
void add(const Vec3fArray& vertices);
void add(const Vec3dArray& vertices);
void add(const BoundingBox& bb);
void addValid(const BoundingBox& bb);
const Vec3d& min() const;
const Vec3d& max() const;
const Vec3d& min() const;
const Vec3d& max() const;
Vec3d center() const;
Vec3d extent() const;
double radius() const;
Vec3d center() const;
Vec3d extent() const;
double radius() const;
bool contains(const Vec3d& point) const;
bool intersects(const BoundingBox& box) const;
bool contains(const Vec3d& point) const;
bool intersects(const BoundingBox& box) const;
void cornerVertices(Vec3d corners[8]) const;
void cornerVertices(Vec3d corners[8]) const;
void expand(double amount);
void transform(const Mat4d& matrix);
const BoundingBox getTransformed(const Mat4d& matrix) const;
void expand(double amount);
void expandPercent(double percent);
void transform(const Mat4d& matrix);
const BoundingBox getTransformed(const Mat4d& matrix) const;
void cutBelow(double depth);
void cutAbove(double depth);
void cutBelow(double depth);
void cutAbove(double depth);
String debugString() const;
String debugString() const;
private:
Vec3d m_min;
Vec3d m_max;
};
private:
Vec3d m_min;
Vec3d m_max;
};
}