mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3881 Smooth outer contour line and clip geometry
This commit is contained in:
@@ -37,18 +37,11 @@ void RivContourMapProjectionPartMgr::appendProjectionToModel(cvf::ModelBasicList
|
||||
{
|
||||
cvf::ScalarMapper* mapper = m_contourMapProjection->legendConfig()->scalarMapper();
|
||||
|
||||
cvf::ref<cvf::DrawableGeo> drawable = createProjectionMapDrawable(displayCoordTransform);
|
||||
if (drawable.notNull() && drawable->boundingBox().isValid())
|
||||
{
|
||||
cvf::ref<cvf::Part> part = new cvf::Part;
|
||||
part->setDrawable(drawable.p());
|
||||
|
||||
cvf::ref<cvf::Vec2fArray> textureCoords = createTextureCoords();
|
||||
RivScalarMapperUtils::applyTextureResultsToPart(part.p(), textureCoords.p(), mapper, 1.0f, caf::FC_NONE, true, m_parentContourMap->backgroundColor());
|
||||
|
||||
part->setSourceInfo(new RivObjectSourceInfo(m_contourMapProjection.p()));
|
||||
|
||||
model->addPart(part.p());
|
||||
std::vector<std::vector<cvf::ref<cvf::Drawable>>> contourDrawablesForAllLevels = createContourPolygons(displayCoordTransform);
|
||||
cvf::ref<cvf::Part> mapPart = createProjectionMapPart(displayCoordTransform);
|
||||
if (mapPart.notNull())
|
||||
{
|
||||
model->addPart(mapPart.p());
|
||||
}
|
||||
|
||||
if (m_contourMapProjection->showContourLines())
|
||||
@@ -56,7 +49,6 @@ void RivContourMapProjectionPartMgr::appendProjectionToModel(cvf::ModelBasicList
|
||||
std::vector<double> tickValues;
|
||||
mapper->majorTickValues(&tickValues);
|
||||
|
||||
std::vector<std::vector<cvf::ref<cvf::Drawable>>> contourDrawablesForAllLevels = createContourPolygons(displayCoordTransform);
|
||||
for (size_t i = 0; i < contourDrawablesForAllLevels.size(); ++i)
|
||||
{
|
||||
std::vector<cvf::ref<cvf::Drawable>> contourDrawables = contourDrawablesForAllLevels[i];
|
||||
@@ -78,7 +70,7 @@ void RivContourMapProjectionPartMgr::appendProjectionToModel(cvf::ModelBasicList
|
||||
part->setDrawable(contourDrawable.p());
|
||||
part->setEffect(effect.p());
|
||||
part->setSourceInfo(new RivMeshLinesSourceInfo(m_contourMapProjection.p()));
|
||||
|
||||
|
||||
model->addPart(part.p());
|
||||
}
|
||||
}
|
||||
@@ -112,54 +104,24 @@ void RivContourMapProjectionPartMgr::appendPickPointVisToModel(cvf::ModelBasicLi
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<cvf::Vec2fArray> RivContourMapProjectionPartMgr::createTextureCoords() const
|
||||
cvf::ref<cvf::Vec2fArray> RivContourMapProjectionPartMgr::createTextureCoords(const std::vector<double>& values) const
|
||||
{
|
||||
cvf::Vec2ui patchSize = m_contourMapProjection->numberOfVerticesIJ();
|
||||
|
||||
cvf::ref<cvf::Vec2fArray> textureCoords = new cvf::Vec2fArray(m_contourMapProjection->numberOfVertices());
|
||||
cvf::ref<cvf::Vec2fArray> textureCoords = new cvf::Vec2fArray(values.size());
|
||||
|
||||
#pragma omp parallel for
|
||||
for (int j = 0; j < static_cast<int>(patchSize.y()); ++j)
|
||||
for (int i = 0; i < (int) values.size(); ++i)
|
||||
{
|
||||
for (int i = 0; i < static_cast<int>(patchSize.x()); ++i)
|
||||
if (values[i] != std::numeric_limits<double>::infinity())
|
||||
{
|
||||
if (m_contourMapProjection->hasResultAtVertex(i, j))
|
||||
{
|
||||
double value = m_contourMapProjection->valueAtVertex(i, j);
|
||||
cvf::Vec2f textureCoord = m_contourMapProjection->legendConfig()->scalarMapper()->mapToTextureCoord(value);
|
||||
textureCoord.y() = 0.0;
|
||||
(*textureCoords)[i + j * patchSize.x()] = textureCoord;
|
||||
}
|
||||
else
|
||||
{
|
||||
RiaWeightedMeanCalculator<double> calc;
|
||||
for (int jj = j - 1; jj <= j + 1; ++jj)
|
||||
{
|
||||
for (int ii = i - 1; ii <= i + 1; ++ii)
|
||||
{
|
||||
if (jj >= 0 && ii >= 0 && jj < static_cast<int>(patchSize.y()) && ii < static_cast<int>(patchSize.x()))
|
||||
{
|
||||
if (!(ii == i && jj == j) && m_contourMapProjection->hasResultAtVertex(ii, jj))
|
||||
{
|
||||
double value = m_contourMapProjection->valueAtVertex(ii, jj);
|
||||
calc.addValueAndWeight(value, 1. / std::sqrt((i - ii)*(i - ii) + (j - jj)*(j - jj)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (calc.validAggregatedWeight())
|
||||
{
|
||||
const double maxTheoreticalWeightSum = 4.0 + 4.0 / std::sqrt(2.0);
|
||||
double value = calc.weightedMean();
|
||||
cvf::Vec2f textureCoord = m_contourMapProjection->legendConfig()->scalarMapper()->mapToTextureCoord(value);
|
||||
textureCoord.y() = 1.0 - calc.aggregatedWeight() / maxTheoreticalWeightSum;
|
||||
(*textureCoords)[i + j * patchSize.x()] = textureCoord;
|
||||
}
|
||||
else
|
||||
{
|
||||
(*textureCoords)[i + j * patchSize.x()] = cvf::Vec2f(0.0, 1.0);
|
||||
}
|
||||
}
|
||||
cvf::Vec2f textureCoord = m_contourMapProjection->legendConfig()->scalarMapper()->mapToTextureCoord(values[i]);
|
||||
textureCoord.y() = 0.0;
|
||||
(*textureCoords)[i] = textureCoord;
|
||||
}
|
||||
else
|
||||
{
|
||||
(*textureCoords)[i] = cvf::Vec2f(0.0, 1.0);
|
||||
}
|
||||
}
|
||||
return textureCoords;
|
||||
@@ -170,14 +132,14 @@ cvf::ref<cvf::Vec2fArray> RivContourMapProjectionPartMgr::createTextureCoords()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<cvf::DrawableText> RivContourMapProjectionPartMgr::createTextLabel(const cvf::Color3f& textColor, const cvf::Color3f& backgroundColor)
|
||||
{
|
||||
auto font = RiaFontCache::getFont(RiaFontCache::FONT_SIZE_8);
|
||||
auto font = RiaFontCache::getFont(RiaFontCache::FONT_SIZE_10);
|
||||
|
||||
cvf::ref<cvf::DrawableText> labelDrawable = new cvf::DrawableText();
|
||||
labelDrawable->setFont(font.p());
|
||||
labelDrawable->setCheckPosVisible(true);
|
||||
labelDrawable->setUseDepthBuffer(true);
|
||||
labelDrawable->setDrawBorder(true);
|
||||
labelDrawable->setDrawBackground(true);
|
||||
labelDrawable->setDrawBorder(false);
|
||||
labelDrawable->setDrawBackground(false);
|
||||
labelDrawable->setBackgroundColor(backgroundColor);
|
||||
labelDrawable->setVerticalAlignment(cvf::TextDrawer::BASELINE);
|
||||
labelDrawable->setTextColor(textColor);
|
||||
@@ -188,31 +150,43 @@ cvf::ref<cvf::DrawableText> RivContourMapProjectionPartMgr::createTextLabel(cons
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<cvf::DrawableGeo> RivContourMapProjectionPartMgr::createProjectionMapDrawable(const caf::DisplayCoordTransform* displayCoordTransform) const
|
||||
cvf::ref<cvf::Part> RivContourMapProjectionPartMgr::createProjectionMapPart(const caf::DisplayCoordTransform* displayCoordTransform) const
|
||||
{
|
||||
std::vector<cvf::Vec3d> vertices = m_contourMapProjection->generateVertices();
|
||||
if (vertices.empty()) return nullptr;
|
||||
|
||||
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(vertices.size());
|
||||
|
||||
for (size_t i = 0; i < vertices.size(); ++i)
|
||||
std::vector<cvf::Vec4d> vertices = m_contourMapProjection->generateTriangles();
|
||||
if (vertices.size() < 3u)
|
||||
{
|
||||
cvf::Vec3f displayVertexPos (displayCoordTransform->transformToDisplayCoord(vertices[i]));
|
||||
(*vertexArray)[i] = displayVertexPos;
|
||||
return cvf::ref<cvf::Part>();
|
||||
}
|
||||
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(vertices.size());
|
||||
cvf::ref<cvf::UIntArray> faceList = new cvf::UIntArray(vertices.size());
|
||||
std::vector<double> values(vertices.size());
|
||||
for (uint i = 0; i < vertices.size(); ++i)
|
||||
{
|
||||
cvf::Vec3d globalVertex = cvf::Vec3d(vertices[i].x(), vertices[i].y(), vertices[i].z()) + m_contourMapProjection->origin3d();
|
||||
cvf::Vec3f displayVertexPos (displayCoordTransform->transformToDisplayCoord(globalVertex));
|
||||
(*vertexArray)[i] = displayVertexPos;
|
||||
(*faceList)[i] = i;
|
||||
values[i] = vertices[i].w();
|
||||
}
|
||||
|
||||
cvf::Vec2ui patchSize = m_contourMapProjection->numberOfVerticesIJ();
|
||||
|
||||
// Surface
|
||||
cvf::ref<cvf::UIntArray> faceList = new cvf::UIntArray;
|
||||
cvf::GeometryUtils::tesselatePatchAsTriangles(patchSize.x(), patchSize.y(), 0u, true, faceList.p());
|
||||
|
||||
cvf::ref<cvf::PrimitiveSetIndexedUInt> indexUInt = new cvf::PrimitiveSetIndexedUInt(cvf::PrimitiveType::PT_TRIANGLES, faceList.p());
|
||||
|
||||
cvf::ref<cvf::DrawableGeo> geo = new cvf::DrawableGeo;
|
||||
geo->addPrimitiveSet(indexUInt.p());
|
||||
geo->setVertexArray(vertexArray.p());
|
||||
return geo;
|
||||
|
||||
cvf::ref<cvf::Part> part = new cvf::Part;
|
||||
part->setDrawable(geo.p());
|
||||
|
||||
cvf::ScalarMapper* mapper = m_contourMapProjection->legendConfig()->scalarMapper();
|
||||
|
||||
cvf::ref<cvf::Vec2fArray> textureCoords = createTextureCoords(values);
|
||||
RivScalarMapperUtils::applyTextureResultsToPart(
|
||||
part.p(), textureCoords.p(), mapper, 1.0f, caf::FC_NONE, true, m_parentContourMap->backgroundColor());
|
||||
|
||||
part->setSourceInfo(new RivObjectSourceInfo(m_contourMapProjection.p()));
|
||||
|
||||
return part;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -241,13 +215,14 @@ std::vector<std::vector<cvf::ref<cvf::Drawable>>> RivContourMapProjectionPartMgr
|
||||
if (contourPolygons[i][j].vertices.empty()) continue;
|
||||
|
||||
size_t nVertices = contourPolygons[i][j].vertices.size();
|
||||
size_t nLabels = m_contourMapProjection->showContourLabels() ? std::max((size_t)1, nVertices / 150u) : 0u;
|
||||
size_t nLabels = m_contourMapProjection->showContourLabels() ? std::max((size_t)1, nVertices / 100u) : 0u;
|
||||
for (size_t l = 0; l < nLabels; ++l)
|
||||
{
|
||||
cvf::ref<cvf::DrawableText> label = createTextLabel(textColor, backgroundColor);
|
||||
cvf::Vec3f labelVertex(displayCoordTransform->transformToDisplayCoord(contourPolygons[i][j].vertices[(nVertices * l) / nLabels]));
|
||||
labelVertex.z() += 3.0f;
|
||||
label->addText(contourPolygons[i][j].label, labelVertex);
|
||||
cvf::Vec3d globalVertex = contourPolygons[i][j].vertices[(nVertices * l) / nLabels] + m_contourMapProjection->origin3d();
|
||||
cvf::Vec3f displayVertex(displayCoordTransform->transformToDisplayCoord(globalVertex));
|
||||
displayVertex.z() += 3.0f;
|
||||
label->addText(cvf::String(contourPolygons[i][j].value), displayVertex);
|
||||
bool overlaps = false;
|
||||
cvf::BoundingBox bbox = label->boundingBox();
|
||||
for (cvf::ref<cvf::Drawable> existingLabel : labelDrawables)
|
||||
@@ -264,12 +239,11 @@ std::vector<std::vector<cvf::ref<cvf::Drawable>>> RivContourMapProjectionPartMgr
|
||||
}
|
||||
}
|
||||
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(nVertices);
|
||||
for (size_t v = 0; v < nVertices; v += 2)
|
||||
for (size_t v = 0; v < nVertices; ++v)
|
||||
{
|
||||
cvf::Vec3d displayVertex1 = displayCoordTransform->transformToDisplayCoord(contourPolygons[i][j].vertices[v]);
|
||||
cvf::Vec3d displayVertex2 = displayCoordTransform->transformToDisplayCoord(contourPolygons[i][j].vertices[v + 1]);
|
||||
cvf::Vec3d globalVertex = contourPolygons[i][j].vertices[v] + m_contourMapProjection->origin3d();
|
||||
cvf::Vec3d displayVertex1 = displayCoordTransform->transformToDisplayCoord(globalVertex);
|
||||
(*vertexArray)[v] = cvf::Vec3f(displayVertex1);
|
||||
(*vertexArray)[v + 1] = cvf::Vec3f(displayVertex2);
|
||||
}
|
||||
|
||||
std::vector<cvf::uint> indices;
|
||||
@@ -279,7 +253,7 @@ std::vector<std::vector<cvf::ref<cvf::Drawable>>> RivContourMapProjectionPartMgr
|
||||
indices.push_back(k);
|
||||
}
|
||||
|
||||
cvf::ref<cvf::PrimitiveSetIndexedUInt> indexedUInt = new cvf::PrimitiveSetIndexedUInt(cvf::PrimitiveType::PT_LINES);
|
||||
cvf::ref<cvf::PrimitiveSetIndexedUInt> indexedUInt = new cvf::PrimitiveSetIndexedUInt(cvf::PrimitiveType::PT_LINE_LOOP);
|
||||
cvf::ref<cvf::UIntArray> indexArray = new cvf::UIntArray(indices);
|
||||
indexedUInt->setIndices(indexArray.p());
|
||||
|
||||
@@ -315,7 +289,8 @@ cvf::ref<cvf::DrawableGeo>
|
||||
|
||||
for (size_t i = 0; i < pickPointPolygon.size(); ++i)
|
||||
{
|
||||
cvf::Vec3f displayPoint(displayCoordTransform->transformToDisplayCoord(pickPointPolygon[i]));
|
||||
cvf::Vec3d globalPoint = pickPointPolygon[i] + m_contourMapProjection->origin3d();
|
||||
cvf::Vec3f displayPoint(displayCoordTransform->transformToDisplayCoord(globalPoint));
|
||||
(*vertexArray)[i] = displayPoint;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,11 +40,11 @@ public:
|
||||
void appendPickPointVisToModel(cvf::ModelBasicList* model,
|
||||
const caf::DisplayCoordTransform* displayCoordTransform) const;
|
||||
|
||||
cvf::ref<cvf::Vec2fArray> createTextureCoords() const;
|
||||
cvf::ref<cvf::Vec2fArray> createTextureCoords(const std::vector<double>& values) const;
|
||||
|
||||
private:
|
||||
static cvf::ref<cvf::DrawableText> createTextLabel(const cvf::Color3f& textColor, const cvf::Color3f& backgroundColor);
|
||||
cvf::ref<cvf::DrawableGeo> createProjectionMapDrawable(const caf::DisplayCoordTransform* displayCoordTransform) const;
|
||||
cvf::ref<cvf::Part> createProjectionMapPart(const caf::DisplayCoordTransform* displayCoordTransform) const;
|
||||
std::vector<std::vector<cvf::ref<cvf::Drawable>>> createContourPolygons(const caf::DisplayCoordTransform* displayCoordTransform) const;
|
||||
cvf::ref<cvf::DrawableGeo> createPickPointVisDrawable(const caf::DisplayCoordTransform* displayCoordTransform) const;
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user