#3591 Improve edges on contour map.

This commit is contained in:
Gaute Lindkvist
2018-10-31 16:09:14 +01:00
parent f87f1430dc
commit ee388ca4b0
11 changed files with 131 additions and 45 deletions

View File

@@ -67,7 +67,7 @@ void caf::ContourLines::create(const std::vector<double>& dataXY, const std::vec
temp2 = std::max(saneValue(gridIndex1d(i + 1, j, nx), dataXY, contourLevels),
saneValue(gridIndex1d(i + 1, j + 1, nx), dataXY, contourLevels));
double dmax = std::max(temp1, temp2);
if (dmax < contourLevels[0] && dmin > contourLevels[nContourLevels - 1])
if (dmax < contourLevels[0] || dmin > contourLevels[nContourLevels - 1])
continue;
for (int k = 0; k < nContourLevels; k++)
@@ -78,7 +78,15 @@ void caf::ContourLines::create(const std::vector<double>& dataXY, const std::vec
{
if (m > 0)
{
h[m] = saneValue(gridIndex1d(i + im[m - 1], j + jm[m - 1], nx), dataXY, contourLevels) - contourLevels[k];
double value = saneValue(gridIndex1d(i + im[m - 1], j + jm[m - 1], nx), dataXY, contourLevels);
if (value == invalidValue(contourLevels))
{
h[m] = invalidValue(contourLevels);
}
else
{
h[m] = value - contourLevels[k];
}
xh[m] = xCoords[i + im[m - 1]];
yh[m] = yCoords[j + jm[m - 1]];
}
@@ -198,18 +206,34 @@ void caf::ContourLines::create(const std::vector<double>& dataXY, const std::vec
} /* j */
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double caf::ContourLines::contourRange(const std::vector<double>& contourLevels)
{
return std::max(1.0, contourLevels.back() - contourLevels.front());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double caf::ContourLines::invalidValue(const std::vector<double>& contourLevels)
{
return contourLevels.front() - 1000.0*contourRange(contourLevels);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double caf::ContourLines::saneValue(int index, const std::vector<double>& dataXY, const std::vector<double>& contourLevels)
{
CVF_ASSERT(index >= 0 && index < static_cast<int>(dataXY.size()));
double range = std::max(1.0, contourLevels.back() - contourLevels.front());
// Place all invalid values below the bottom contour level.
if (dataXY[index] == -std::numeric_limits<double>::infinity() ||
dataXY[index] == std::numeric_limits<double>::infinity())
{
return contourLevels.front() - range;
return invalidValue(contourLevels);
}
return dataXY[index];
}

View File

@@ -38,6 +38,8 @@ public:
const std::vector<double>& contourLevels,
std::vector<std::vector<cvf::Vec2d>>* polygons);
private:
static double contourRange(const std::vector<double>& contourLevels);
static double invalidValue(const std::vector<double>& contourLevels);
static double saneValue(int index, const std::vector<double>& dataXY, const std::vector<double>& contourLevels);
static double xsect(int p1, int p2, const std::vector<double>& h, const std::vector<double>& xh, const std::vector<double>& yh);
static double ysect(int p1, int p2, const std::vector<double>& h, const std::vector<double>& xh, const std::vector<double>& yh);