Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -285,25 +285,27 @@ std::vector<double> RigEnsembleFractureStatisticsCalculator::calculateAreaWeight
// TODO: heuristic to find conductivity name?
QString conductivityResultName = fractureDefinitions[0]->conductivityResultNames()[0];

std::vector<cvf::cref<RigFractureGrid>> grids =
RimEnsembleFractureStatistics::createFractureGrids( fractureDefinitions,
RiaDefines::EclipseUnitSystem::UNITS_METRIC,
conductivityResultName,
RimEnsembleFractureStatistics::MeshAlignmentType::PERFORATION_DEPTH );

auto [widthResultName, widthResultUnit] = RimStimPlanFractureTemplate::widthParameterNameAndUnit( fractureDefinitions[0] );
std::vector<cvf::cref<RigFractureGrid>> widthGrids =
RimEnsembleFractureStatistics::createFractureGrids( fractureDefinitions,
RiaDefines::EclipseUnitSystem::UNITS_METRIC,
widthResultName,
RimEnsembleFractureStatistics::MeshAlignmentType::PERFORATION_DEPTH );

CAF_ASSERT( grids.size() == widthGrids.size() );

for ( size_t i = 0; i < grids.size(); i++ )
// Create the grids one definition at a time, as a definition can lack conductivity or width data. This keeps the two grids paired.
for ( const auto& definition : fractureDefinitions )
{
double result = func( grids[i], widthGrids[i], RiaDefines::EclipseUnitSystem::UNITS_METRIC, widthResultUnit );
samples.push_back( result );
std::vector<cvf::ref<RigStimPlanFractureDefinition>> singleDefinition = { definition };

auto grids = RimEnsembleFractureStatistics::createFractureGrids( singleDefinition,
RiaDefines::EclipseUnitSystem::UNITS_METRIC,
conductivityResultName,
RimEnsembleFractureStatistics::MeshAlignmentType::PERFORATION_DEPTH );

auto widthGrids =
RimEnsembleFractureStatistics::createFractureGrids( singleDefinition,
RiaDefines::EclipseUnitSystem::UNITS_METRIC,
widthResultName,
RimEnsembleFractureStatistics::MeshAlignmentType::PERFORATION_DEPTH );

if ( grids.empty() || widthGrids.empty() ) continue;

samples.push_back( func( grids.front(), widthGrids.front(), RiaDefines::EclipseUnitSystem::UNITS_METRIC, widthResultUnit ) );
}

return samples;
Expand Down
41 changes: 41 additions & 0 deletions ApplicationLibCode/UnitTests/CvfCameraCrashTriage-Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,44 @@ TEST( CvfCameraCrashTriageTest, FitViewWithParallelDirAndUpProducesValidViewMatr
EXPECT_NEAR( c.direction() * c.right(), 0.0, 1e-6 );
EXPECT_NEAR( c.up() * c.right(), 0.0, 1e-6 );
}

//--------------------------------------------------------------------------------------------------
/// A zero view direction (eye == view reference point, as in caf::Viewer::zoomAll()) gave a zero up
/// vector and a zero-normal plane, which asserted in Plane::distanceToOrigin().
//--------------------------------------------------------------------------------------------------
TEST( CvfCameraCrashTriageTest, FitViewEyePositionWithZeroDirDoesNotCrash )
{
Camera c;

BoundingBox bb;
bb.add( Vec3d( 0, 0, 0 ) );
bb.add( Vec3d( 1, 1, 1 ) );

for ( const auto& dir : { Vec3d::ZERO, Vec3d::UNDEFINED } )
{
Vec3d eye = Camera::computeFitViewEyePosition( bb, dir, Vec3d( 0, 0, 1 ), 0.9, c.fieldOfViewYDeg(), 1.0 );

EXPECT_FALSE( eye.isUndefined() );
}
}

//--------------------------------------------------------------------------------------------------
/// fitView() must derive the up vector from the same valid direction as the eye position
//--------------------------------------------------------------------------------------------------
TEST( CvfCameraCrashTriageTest, FitViewWithZeroOrUndefinedDirProducesValidViewMatrix )
{
BoundingBox bb;
bb.add( Vec3d( 0, 0, 0 ) );
bb.add( Vec3d( 1, 1, 1 ) );

for ( const auto& dir : { Vec3d::ZERO, Vec3d::UNDEFINED } )
{
Camera c;
c.setViewport( 0, 0, 100, 100 );
c.fitView( bb, dir, Vec3d( 0, 0, 1 ), 0.9 );

EXPECT_NEAR( c.direction().length(), 1.0, 1e-6 );
EXPECT_NEAR( c.up().length(), 1.0, 1e-6 );
EXPECT_NEAR( c.right().length(), 1.0, 1e-6 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,24 @@ TEST( RigEnsembleFractureStatisticsCalculatorTest, EmptyDefinitionsProduceInvali
EXPECT_FALSE( histogramData.isHistogramVectorValid() );
}
}

//--------------------------------------------------------------------------------------------------
/// A definition with conductivity data but no width data must not produce mismatched grid lists
//--------------------------------------------------------------------------------------------------
TEST( RigEnsembleFractureStatisticsCalculatorTest, MissingWidthDataDoesNotCrash )
{
cvf::ref<RigStimPlanFractureDefinition> definition = new RigStimPlanFractureDefinition;
definition->addTimeStep( 1.0 );
definition->setDataAtTimeValue( "Conductivity", "md-m", { { 1.0, 1.0 }, { 1.0, 1.0 } }, 1.0 );

std::vector<cvf::ref<RigStimPlanFractureDefinition>> definitions = { definition };

auto width = RigEnsembleFractureStatisticsCalculator::calculateProperty( definitions,
RigEnsembleFractureStatisticsCalculator::PropertyType::WIDTH );
EXPECT_TRUE( width.empty() );

auto permeability =
RigEnsembleFractureStatisticsCalculator::calculateProperty( definitions,
RigEnsembleFractureStatisticsCalculator::PropertyType::PERMEABILITY );
EXPECT_TRUE( permeability.empty() );
}
21 changes: 19 additions & 2 deletions Fwk/VizFwk/LibRender/cvfCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,23 @@
#include "cvfBoundingBox.h"
#include "cvfGeometryUtils.h"

#include <limits>

namespace cvf {

namespace {

//--------------------------------------------------------------------------------------------------
/// A zero, undefined or non-finite view direction cannot define a view; fall back to looking along the Y axis
//--------------------------------------------------------------------------------------------------
Vec3d validViewDirection(const Vec3d& dir)
{
const double length = dir.length();
if (!dir.isUndefined() && length > 0.0 && length < std::numeric_limits<double>::max()) return dir;

return Vec3d::Y_AXIS;
}

//--------------------------------------------------------------------------------------------------
/// Returns an up vector guaranteed to be non-parallel to dir. If the passed up vector is already
/// non-parallel to dir, it is returned unchanged. Otherwise a corrected, orthogonal up vector is
Expand Down Expand Up @@ -310,8 +323,10 @@ void Camera::setProjectionAsPixelExact2D()
/// the view to. The relativeDistance parameter specifies the distance from the camera to the
/// center of the bounding box
//--------------------------------------------------------------------------------------------------
void Camera::fitView(const BoundingBox& boundingBox, const Vec3d& dir, const Vec3d& up, double coverageFactor)
void Camera::fitView(const BoundingBox& boundingBox, const Vec3d& dirIn, const Vec3d& up, double coverageFactor)
{
const cvf::Vec3d dir = validViewDirection(dirIn);

// dir and up may be parallel (degenerate camera orientation); derive a corrected, non-parallel
// up vector so both the eye computation and the final look-at matrix use a consistent basis.
cvf::Vec3d correctedUp = nonParallelUpVector(dir, up);
Expand All @@ -327,8 +342,10 @@ void Camera::fitView(const BoundingBox& boundingBox, const Vec3d& dir, const Vec
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Vec3d Camera::computeFitViewEyePosition(const BoundingBox& boundingBox, const Vec3d& dir, const Vec3d& up, double coverageFactor, double fieldOfViewYDeg, double aspectRatio)
Vec3d Camera::computeFitViewEyePosition(const BoundingBox& boundingBox, const Vec3d& dirIn, const Vec3d& up, double coverageFactor, double fieldOfViewYDeg, double aspectRatio)
{
const cvf::Vec3d dir = validViewDirection(dirIn);

cvf::Vec3d corners[8];
boundingBox.cornerVertices(corners);

Expand Down