mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Integrated visualization modules to changelist 20202
p4#: 20204
This commit is contained in:
@@ -388,7 +388,7 @@ const BoundingBox BoundingBox::getTransformed(const Mat4d& matrix) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
String BoundingBox::toString() const
|
||||
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());
|
||||
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
void transform(const Mat4d& matrix);
|
||||
const BoundingBox getTransformed(const Mat4d& matrix) const;
|
||||
|
||||
String toString() const;
|
||||
String debugString() const;
|
||||
|
||||
private:
|
||||
Vec3d m_min;
|
||||
|
||||
@@ -245,6 +245,62 @@ void GeometryUtils::createDisc(double radius, uint numSlices, GeometryBuilder* b
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Create a disk with a hole in the middle
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void GeometryUtils::createDisc(double outerRadius, double innerRadius, uint numSlices, GeometryBuilder* builder)
|
||||
{
|
||||
CVF_ASSERT(numSlices >= 4);
|
||||
CVF_ASSERT(builder);
|
||||
|
||||
double da = 2*PI_D/numSlices;
|
||||
|
||||
Vec3fArray verts;
|
||||
verts.reserve(2*numSlices);
|
||||
|
||||
Vec3f point = Vec3f::ZERO;
|
||||
|
||||
uint i;
|
||||
for (i = 0; i < numSlices; i++)
|
||||
{
|
||||
// Precompute this one (A = i*da;)
|
||||
double sinA = Math::sin(i*da);
|
||||
double cosA = Math::cos(i*da);
|
||||
|
||||
point.x() = static_cast<float>(-sinA*innerRadius);
|
||||
point.y() = static_cast<float>( cosA*innerRadius);
|
||||
|
||||
verts.add(point);
|
||||
|
||||
point.x() = static_cast<float>(-sinA*outerRadius);
|
||||
point.y() = static_cast<float>( cosA*outerRadius);
|
||||
|
||||
verts.add(point);
|
||||
}
|
||||
|
||||
uint baseNodeIdx = builder->addVertices(verts);
|
||||
|
||||
uint conn[3] = { baseNodeIdx, 0, 0};
|
||||
|
||||
for (i = 0; i < numSlices - 1; ++i)
|
||||
{
|
||||
uint startIdx = baseNodeIdx + 2*i;
|
||||
|
||||
conn[0] = startIdx + 0;
|
||||
conn[1] = startIdx + 3;
|
||||
conn[2] = startIdx + 1;
|
||||
builder->addTriangle(conn[0], conn[1], conn[2]);
|
||||
|
||||
conn[0] = startIdx + 2;
|
||||
conn[1] = startIdx + 3;
|
||||
conn[2] = startIdx + 0;
|
||||
builder->addTriangle(conn[0], conn[1], conn[2]);
|
||||
}
|
||||
|
||||
builder->addTriangle(baseNodeIdx + 0, baseNodeIdx + 1, baseNodeIdx + numSlices*2 - 1);
|
||||
builder->addTriangle(baseNodeIdx + 0, baseNodeIdx + numSlices*2 - 1, baseNodeIdx + numSlices*2 - 2);
|
||||
}
|
||||
|
||||
|
||||
// void GeometryUtils::generatePointsOnCircle(double radius, int numPoints, Vec3fArray* generatedPoints)
|
||||
// {
|
||||
@@ -851,7 +907,7 @@ void GeometryUtils::removeUnusedVertices(const UIntValueArray& vertexIndices, UI
|
||||
newToOldMapping->squeeze();
|
||||
}
|
||||
|
||||
bool GeometryUtils::project(const Mat4d& projectionMultViewMatrix, const Vec2ui& viewportPosition, const Vec2ui& viewportSize, const Vec3d& point, Vec3d* out)
|
||||
bool GeometryUtils::project(const Mat4d& projectionMultViewMatrix, const Vec2i& viewportPosition, const Vec2ui& viewportSize, const Vec3d& point, Vec3d* out)
|
||||
{
|
||||
CVF_ASSERT(out);
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ public:
|
||||
static void createBox(const Vec3f& centerPos, float extentX, float extentY, float extentZ, GeometryBuilder* builder);
|
||||
|
||||
static void createDisc(double radius, uint numSlices, GeometryBuilder* builder);
|
||||
static void createDisc(double outerRadius, double innerRadius, uint numSlices, GeometryBuilder* builder);
|
||||
|
||||
static void createSphere(double radius, uint numSlices, uint numStacks, GeometryBuilder* builder);
|
||||
|
||||
@@ -57,7 +58,7 @@ public:
|
||||
|
||||
static void removeUnusedVertices(const UIntValueArray& vertexIndices, UIntArray* newVertexIndices, UIntArray* newToOldMapping, uint maxVertexCount);
|
||||
|
||||
static bool project(const Mat4d& projectionMultViewMatrix, const Vec2ui& viewportPosition, const Vec2ui& viewportSize, const Vec3d& point, Vec3d* out);
|
||||
static bool project(const Mat4d& projectionMultViewMatrix, const Vec2i& viewportPosition, const Vec2ui& viewportSize, const Vec3d& point, Vec3d* out);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -39,9 +39,14 @@ namespace cvf {
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Ray::Ray()
|
||||
: m_origin(Vec3d::ZERO),
|
||||
m_direction(-Vec3d::Z_AXIS),
|
||||
m_minDistance(cvf::UNDEFINED_DOUBLE),
|
||||
m_maxDistance(cvf::UNDEFINED_DOUBLE),
|
||||
m_minDistanceSquared(cvf::UNDEFINED_DOUBLE),
|
||||
m_maxDistanceSquared(cvf::UNDEFINED_DOUBLE),
|
||||
m_distanceLimitedRay(false)
|
||||
{
|
||||
m_origin = Vec3d::ZERO;
|
||||
m_direction = -Vec3d::Z_AXIS;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +57,11 @@ Ray::Ray(const Ray& other) : Object()
|
||||
{
|
||||
m_origin = other.origin();
|
||||
m_direction = other.direction();
|
||||
m_minDistance = other.m_minDistance;
|
||||
m_maxDistance = other.m_maxDistance;
|
||||
m_minDistanceSquared = other.m_minDistanceSquared;
|
||||
m_maxDistanceSquared = other.m_maxDistanceSquared;
|
||||
m_distanceLimitedRay = other.m_distanceLimitedRay;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +70,6 @@ Ray::Ray(const Ray& other) : Object()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Ray::~Ray()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +171,22 @@ bool Ray::triangleIntersect(const Vec3d& v1, const Vec3d& v2, const Vec3d& v3, V
|
||||
}
|
||||
}
|
||||
|
||||
// Distance filtering
|
||||
if (m_distanceLimitedRay)
|
||||
{
|
||||
double distanceSquared = origin().pointDistanceSquared(fp);
|
||||
|
||||
if (m_minDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD && distanceSquared < m_minDistanceSquared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_maxDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD && distanceSquared > m_maxDistanceSquared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (intersectionPoint)
|
||||
{
|
||||
*intersectionPoint = fp;
|
||||
@@ -211,6 +236,22 @@ bool Ray::quadIntersect(const Vec3d& v1, const Vec3d& v2, const Vec3d& v3, const
|
||||
}
|
||||
}
|
||||
|
||||
// Distance filtering
|
||||
if (m_distanceLimitedRay)
|
||||
{
|
||||
double distanceSquared = origin().pointDistanceSquared(fp);
|
||||
|
||||
if (m_minDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD && distanceSquared < m_minDistanceSquared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_maxDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD && distanceSquared > m_maxDistanceSquared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (intersectionPoint)
|
||||
{
|
||||
*intersectionPoint = fp;
|
||||
@@ -312,6 +353,22 @@ bool Ray::boxIntersect(const BoundingBox& box, Vec3d* intersectionPoint) const
|
||||
}
|
||||
}
|
||||
|
||||
// Distance filtering
|
||||
if (m_distanceLimitedRay)
|
||||
{
|
||||
double distanceSquared = origin().pointDistanceSquared(hitPoint);
|
||||
|
||||
if (m_minDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD && distanceSquared < m_minDistanceSquared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_maxDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD && distanceSquared > m_maxDistanceSquared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (intersectionPoint)
|
||||
{
|
||||
*intersectionPoint = hitPoint;
|
||||
@@ -348,6 +405,22 @@ bool Ray::planeIntersect(const Plane& plane, Vec3d* intersectionPoint) const
|
||||
double t = v0/vd;
|
||||
if (t >= 0)
|
||||
{
|
||||
// Distance filtering
|
||||
if (m_distanceLimitedRay)
|
||||
{
|
||||
double distanceSquared = origin().pointDistanceSquared(m_origin + t*m_direction);
|
||||
|
||||
if (m_minDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD && distanceSquared < m_minDistanceSquared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_maxDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD && distanceSquared > m_maxDistanceSquared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (intersectionPoint)
|
||||
{
|
||||
*intersectionPoint = m_origin + t*m_direction;
|
||||
@@ -364,15 +437,78 @@ bool Ray::planeIntersect(const Plane& plane, Vec3d* intersectionPoint) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
String Ray::toString() const
|
||||
String Ray::debugString() const
|
||||
{
|
||||
String str = "Ray: ";
|
||||
str += " origin: x=" + String::number(m_origin.x()) + " y=" + String::number(m_origin.y()) + " z=" + String::number(m_origin.z());
|
||||
str += " direction: x=" + String::number(m_direction.x()) + " y=" + String::number(m_direction.y()) + " z=" + String::number(m_direction.z());
|
||||
str += " minDist: " + String::number(m_minDistance);
|
||||
str += " maxDist: " + String::number(m_maxDistance);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
} // namespace cvf
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Set the minimum distance (from the origin) that the ray will hit.
|
||||
///
|
||||
/// Useful for limiting the ray when picking on models with clipping planes.
|
||||
/// Set to tsv::UNDEFINED_DOUBLE
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Ray::setMinimumDistance(double distance)
|
||||
{
|
||||
m_minDistance = distance;
|
||||
|
||||
if (m_minDistance >= 0 && m_minDistance < cvf::UNDEFINED_DOUBLE_THRESHOLD)
|
||||
{
|
||||
m_minDistanceSquared = m_minDistance*m_minDistance;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_minDistanceSquared = cvf::UNDEFINED_DOUBLE;
|
||||
}
|
||||
|
||||
m_distanceLimitedRay = (m_minDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD) || (m_maxDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Set the maximum distance (from the origin) that the ray will hit.
|
||||
///
|
||||
/// Useful for limiting the ray when picking on models with clipping planes
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Ray::setMaximumDistance(double distance)
|
||||
{
|
||||
m_maxDistance = distance;
|
||||
|
||||
if (m_maxDistance >= 0 && m_maxDistance < cvf::UNDEFINED_DOUBLE_THRESHOLD)
|
||||
{
|
||||
m_maxDistanceSquared = m_maxDistance*m_maxDistance;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_maxDistanceSquared = cvf::UNDEFINED_DOUBLE;
|
||||
}
|
||||
|
||||
m_distanceLimitedRay = (m_minDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD) || (m_maxDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Minimum distance (from the origin) that the ray will hit.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double Ray::minimumDistance() const
|
||||
{
|
||||
return m_minDistance;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Maximum distance (from the origin) that the ray will hit
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double Ray::maximumDistance() const
|
||||
{
|
||||
return m_maxDistance;
|
||||
}
|
||||
|
||||
} // namespace cvf
|
||||
|
||||
@@ -47,6 +47,11 @@ public:
|
||||
void setDirection(const Vec3d& dir);
|
||||
const Vec3d& direction() const;
|
||||
|
||||
void setMinimumDistance(double distance);
|
||||
double minimumDistance() const;
|
||||
void setMaximumDistance(double distance);
|
||||
double maximumDistance() const;
|
||||
|
||||
void transform(const Mat4d& matrix);
|
||||
const Ray getTransformed(const Mat4d& matrix) const;
|
||||
|
||||
@@ -55,11 +60,16 @@ public:
|
||||
bool boxIntersect(const BoundingBox& box, Vec3d* intersectionPoint = NULL) const;
|
||||
bool planeIntersect(const Plane& plane, Vec3d* intersectionPoint = NULL) const;
|
||||
|
||||
String toString() const;
|
||||
String debugString() const;
|
||||
|
||||
private:
|
||||
Vec3d m_origin; ///< Starting point of ray
|
||||
Vec3d m_direction; ///< Vector specifying ray direction
|
||||
Vec3d m_origin; ///< Starting point of ray
|
||||
Vec3d m_direction; ///< Vector specifying ray direction
|
||||
double m_minDistance; ///< Minimum distance for a hit
|
||||
double m_maxDistance; ///< Maximum distance for a hit
|
||||
double m_minDistanceSquared;
|
||||
double m_maxDistanceSquared;
|
||||
bool m_distanceLimitedRay;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user