2025.6.1
This commit is contained in:
72
exchange/exchangesource/MeshViewer/utils/bounding_box.cpp
Normal file
72
exchange/exchangesource/MeshViewer/utils/bounding_box.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/***********************************************************************************************************************
|
||||
*
|
||||
* Copyright (c) 2010 - 2025 by Tech Soft 3D, Inc.
|
||||
* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret
|
||||
* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event
|
||||
* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized
|
||||
* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the
|
||||
* scope and manner of such use.
|
||||
*
|
||||
***********************************************************************************************************************/
|
||||
|
||||
#include "bounding_box.h"
|
||||
|
||||
namespace utils
|
||||
{
|
||||
namespace geometry
|
||||
{
|
||||
void BoundingBox::reset()
|
||||
{
|
||||
min = glm::vec3(std::numeric_limits<float>::max());
|
||||
max = glm::vec3(std::numeric_limits<float>::lowest());
|
||||
}
|
||||
void BoundingBox::add_point(const glm::vec3& point)
|
||||
{
|
||||
min.x = std::min(min.x, point.x);
|
||||
min.y = std::min(min.y, point.y);
|
||||
min.z = std::min(min.z, point.z);
|
||||
max.x = std::max(max.x, point.x);
|
||||
max.y = std::max(max.y, point.y);
|
||||
max.z = std::max(max.z, point.z);
|
||||
};
|
||||
void BoundingBox::add_box(const BoundingBox& box)
|
||||
{
|
||||
add_point(box.min);
|
||||
add_point(box.max);
|
||||
};
|
||||
BoundingBox BoundingBox::transform(const glm::mat4& mat) const
|
||||
{
|
||||
glm::vec3 trsf_min = glm::vec3(mat * glm::vec4(min, 1.));
|
||||
glm::vec3 trsf_max = glm::vec3(mat * glm::vec4(max, 1.));
|
||||
BoundingBox new_box;
|
||||
new_box.add_point(trsf_min);
|
||||
new_box.add_point(trsf_max);
|
||||
return new_box;
|
||||
};
|
||||
void BoundingBox::add_boxes(const BoundingBox& box, const std::vector<glm::mat4>& mat4s)
|
||||
{
|
||||
for (const auto& mat : mat4s)
|
||||
{
|
||||
add_box(box.transform(mat));
|
||||
}
|
||||
};
|
||||
glm::vec3 BoundingBox::diagonal() const
|
||||
{
|
||||
return max - min;
|
||||
}
|
||||
glm::vec3 BoundingBox::center() const
|
||||
{
|
||||
return ( max + min ) / 2.f;
|
||||
}
|
||||
double BoundingBox::size_max() const
|
||||
{
|
||||
double x = fabs(max.x - min.x);
|
||||
double y = fabs(max.y - min.y);
|
||||
double z = fabs(max.z - min.z);
|
||||
if (x > y)
|
||||
return x > z ? x : z;
|
||||
else
|
||||
return y > z ? y : z;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user