mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Merge branch 'dev' into measurement
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "RivContourMapProjectionPartMgr.h"
|
||||
|
||||
#include "RiaColorTools.h"
|
||||
#include "RiaFontCache.h"
|
||||
#include "RiaWeightedMeanCalculator.h"
|
||||
#include "RivMeshLinesSourceInfo.h"
|
||||
#include "RivScalarMapperUtils.h"
|
||||
@@ -9,11 +11,13 @@
|
||||
|
||||
#include "cafEffectGenerator.h"
|
||||
|
||||
#include "cvfDrawableText.h"
|
||||
#include "cvfGeometryBuilderFaceList.h"
|
||||
#include "cvfGeometryUtils.h"
|
||||
#include "cvfMeshEdgeExtractor.h"
|
||||
#include "cvfPart.h"
|
||||
#include "cvfPrimitiveSetIndexedUInt.h"
|
||||
#include "cvfScalarMapper.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
@@ -31,6 +35,8 @@ RivContourMapProjectionPartMgr::RivContourMapProjectionPartMgr(RimContourMapProj
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivContourMapProjectionPartMgr::appendProjectionToModel(cvf::ModelBasicList* model, const caf::DisplayCoordTransform* displayCoordTransform) const
|
||||
{
|
||||
cvf::ScalarMapper* mapper = m_contourMapProjection->legendConfig()->scalarMapper();
|
||||
|
||||
cvf::ref<cvf::DrawableGeo> drawable = createProjectionMapDrawable(displayCoordTransform);
|
||||
if (drawable.notNull() && drawable->boundingBox().isValid())
|
||||
{
|
||||
@@ -38,7 +44,6 @@ void RivContourMapProjectionPartMgr::appendProjectionToModel(cvf::ModelBasicList
|
||||
part->setDrawable(drawable.p());
|
||||
|
||||
cvf::ref<cvf::Vec2fArray> textureCoords = createTextureCoords();
|
||||
cvf::ScalarMapper* mapper = m_contourMapProjection->legendConfig()->scalarMapper();
|
||||
RivScalarMapperUtils::applyTextureResultsToPart(part.p(), textureCoords.p(), mapper, 1.0f, caf::FC_NONE, true, m_parentContourMap->backgroundColor());
|
||||
|
||||
part->setSourceInfo(new RivObjectSourceInfo(m_contourMapProjection.p()));
|
||||
@@ -48,22 +53,34 @@ void RivContourMapProjectionPartMgr::appendProjectionToModel(cvf::ModelBasicList
|
||||
|
||||
if (m_contourMapProjection->showContourLines())
|
||||
{
|
||||
std::vector<cvf::ref<cvf::DrawableGeo>> contourDrawables = createContourPolygons(displayCoordTransform);
|
||||
for (cvf::ref<cvf::DrawableGeo> contourDrawable : contourDrawables)
|
||||
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)
|
||||
{
|
||||
if (contourDrawable.notNull() && contourDrawable->boundingBox().isValid())
|
||||
std::vector<cvf::ref<cvf::Drawable>> contourDrawables = contourDrawablesForAllLevels[i];
|
||||
|
||||
cvf::Color3f backgroundColor(mapper->mapToColor(tickValues[i]));
|
||||
cvf::Color3f lineColor = RiaColorTools::constrastColor(backgroundColor, true);
|
||||
|
||||
for (cvf::ref<cvf::Drawable> contourDrawable : contourDrawables)
|
||||
{
|
||||
caf::MeshEffectGenerator meshEffectGen(cvf::Color3::BLACK);
|
||||
meshEffectGen.setLineWidth(1.0f);
|
||||
meshEffectGen.createAndConfigurePolygonOffsetRenderState(caf::PO_1);
|
||||
cvf::ref<cvf::Effect> effect = meshEffectGen.generateCachedEffect();
|
||||
if (contourDrawable.notNull() && contourDrawable->boundingBox().isValid())
|
||||
{
|
||||
caf::MeshEffectGenerator meshEffectGen(lineColor);
|
||||
meshEffectGen.setLineWidth(1.0f);
|
||||
meshEffectGen.createAndConfigurePolygonOffsetRenderState(caf::PO_1);
|
||||
|
||||
cvf::ref<cvf::Part> part = new cvf::Part;
|
||||
part->setDrawable(contourDrawable.p());
|
||||
part->setEffect(effect.p());
|
||||
part->setSourceInfo(new RivMeshLinesSourceInfo(m_contourMapProjection.p()));
|
||||
cvf::ref<cvf::Effect> effect = meshEffectGen.generateCachedEffect();
|
||||
|
||||
model->addPart(part.p());
|
||||
cvf::ref<cvf::Part> part = new cvf::Part;
|
||||
part->setDrawable(contourDrawable.p());
|
||||
part->setEffect(effect.p());
|
||||
part->setSourceInfo(new RivMeshLinesSourceInfo(m_contourMapProjection.p()));
|
||||
|
||||
model->addPart(part.p());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,13 +165,42 @@ cvf::ref<cvf::Vec2fArray> RivContourMapProjectionPartMgr::createTextureCoords()
|
||||
return textureCoords;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<cvf::DrawableText> RivContourMapProjectionPartMgr::createTextLabel(const cvf::Color3f& textColor, const cvf::Color3f& backgroundColor)
|
||||
{
|
||||
auto font = RiaFontCache::getFont(RiaFontCache::FONT_SIZE_8);
|
||||
|
||||
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->setBackgroundColor(backgroundColor);
|
||||
labelDrawable->setVerticalAlignment(cvf::TextDrawer::BASELINE);
|
||||
labelDrawable->setTextColor(textColor);
|
||||
|
||||
return labelDrawable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<cvf::DrawableGeo> RivContourMapProjectionPartMgr::createProjectionMapDrawable(const caf::DisplayCoordTransform* displayCoordTransform) const
|
||||
{
|
||||
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray;
|
||||
m_contourMapProjection->generateVertices(vertexArray.p(), displayCoordTransform);
|
||||
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)
|
||||
{
|
||||
cvf::Vec3f displayVertexPos (displayCoordTransform->transformToDisplayCoord(vertices[i]));
|
||||
(*vertexArray)[i] = displayVertexPos;
|
||||
}
|
||||
|
||||
cvf::Vec2ui patchSize = m_contourMapProjection->numberOfVerticesIJ();
|
||||
|
||||
// Surface
|
||||
@@ -172,33 +218,86 @@ cvf::ref<cvf::DrawableGeo> RivContourMapProjectionPartMgr::createProjectionMapDr
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<cvf::ref<cvf::DrawableGeo>> RivContourMapProjectionPartMgr::createContourPolygons(const caf::DisplayCoordTransform* displayCoordTransform) const
|
||||
std::vector<std::vector<cvf::ref<cvf::Drawable>>> RivContourMapProjectionPartMgr::createContourPolygons(const caf::DisplayCoordTransform* displayCoordTransform) const
|
||||
{
|
||||
RimContourMapProjection::ContourPolygons contourPolygons = m_contourMapProjection->generateContourPolygons(displayCoordTransform);
|
||||
m_contourMapProjection->generateContourPolygons();
|
||||
const std::vector<RimContourMapProjection::ContourPolygons>& contourPolygons = m_contourMapProjection->contourPolygons();
|
||||
|
||||
std::vector<cvf::ref<cvf::DrawableGeo>> contourDrawables;
|
||||
contourDrawables.reserve(contourPolygons.size());
|
||||
for (size_t i = 0; i < contourPolygons.size(); ++i)
|
||||
const cvf::ScalarMapper* mapper = m_contourMapProjection->legendConfig()->scalarMapper();
|
||||
std::vector<double> tickValues;
|
||||
mapper->majorTickValues(&tickValues);
|
||||
|
||||
std::vector<std::vector<cvf::ref<cvf::Drawable>>> contourDrawablesForAllLevels;
|
||||
std::vector<cvf::ref<cvf::Drawable>> labelDrawables;
|
||||
for (int64_t i = (int64_t) contourPolygons.size() - 1; i > 0; --i)
|
||||
{
|
||||
cvf::ref<cvf::Vec3fArray> vertexArray = contourPolygons[i];
|
||||
std::vector<cvf::uint> indices;
|
||||
indices.reserve(contourPolygons[i]->size());
|
||||
for (cvf::uint j = 0; j < contourPolygons[i]->size(); ++j)
|
||||
std::vector<cvf::ref<cvf::Drawable>> contourDrawables;
|
||||
|
||||
cvf::Color3f backgroundColor(mapper->mapToColor(tickValues[i]));
|
||||
cvf::Color3f textColor = RiaColorTools::constrastColor(backgroundColor);
|
||||
|
||||
for (size_t j = 0; j < contourPolygons[i].size(); ++j)
|
||||
{
|
||||
indices.push_back(j);
|
||||
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;
|
||||
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);
|
||||
bool overlaps = false;
|
||||
cvf::BoundingBox bbox = label->boundingBox();
|
||||
for (cvf::ref<cvf::Drawable> existingLabel : labelDrawables)
|
||||
{
|
||||
if (existingLabel->boundingBox().intersects(bbox))
|
||||
{
|
||||
overlaps = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!overlaps)
|
||||
{
|
||||
labelDrawables.push_back(label);
|
||||
}
|
||||
}
|
||||
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(nVertices);
|
||||
for (size_t v = 0; v < nVertices; v += 2)
|
||||
{
|
||||
cvf::Vec3d displayVertex1 = displayCoordTransform->transformToDisplayCoord(contourPolygons[i][j].vertices[v]);
|
||||
cvf::Vec3d displayVertex2 = displayCoordTransform->transformToDisplayCoord(contourPolygons[i][j].vertices[v + 1]);
|
||||
(*vertexArray)[v] = cvf::Vec3f(displayVertex1);
|
||||
(*vertexArray)[v + 1] = cvf::Vec3f(displayVertex2);
|
||||
}
|
||||
|
||||
std::vector<cvf::uint> indices;
|
||||
indices.reserve(vertexArray->size());
|
||||
for (cvf::uint k = 0; k < vertexArray->size(); ++k)
|
||||
{
|
||||
indices.push_back(k);
|
||||
}
|
||||
|
||||
cvf::ref<cvf::PrimitiveSetIndexedUInt> indexedUInt = new cvf::PrimitiveSetIndexedUInt(cvf::PrimitiveType::PT_LINES);
|
||||
cvf::ref<cvf::UIntArray> indexArray = new cvf::UIntArray(indices);
|
||||
indexedUInt->setIndices(indexArray.p());
|
||||
|
||||
cvf::ref<cvf::DrawableGeo> geo = new cvf::DrawableGeo;
|
||||
|
||||
geo->addPrimitiveSet(indexedUInt.p());
|
||||
geo->setVertexArray(vertexArray.p());
|
||||
contourDrawables.push_back(geo);
|
||||
}
|
||||
for (cvf::ref<cvf::Drawable> labelDrawable : labelDrawables)
|
||||
{
|
||||
contourDrawables.push_back(labelDrawable);
|
||||
}
|
||||
|
||||
cvf::ref<cvf::PrimitiveSetIndexedUInt> indexedUInt = new cvf::PrimitiveSetIndexedUInt(cvf::PrimitiveType::PT_LINES);
|
||||
cvf::ref<cvf::UIntArray> indexArray = new cvf::UIntArray(indices);
|
||||
indexedUInt->setIndices(indexArray.p());
|
||||
|
||||
cvf::ref<cvf::DrawableGeo> geo = new cvf::DrawableGeo;
|
||||
|
||||
geo->addPrimitiveSet(indexedUInt.p());
|
||||
geo->setVertexArray(vertexArray.p());
|
||||
contourDrawables.push_back(geo);
|
||||
contourDrawablesForAllLevels.push_back(contourDrawables);
|
||||
}
|
||||
return contourDrawables;
|
||||
|
||||
return contourDrawablesForAllLevels;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -207,14 +306,25 @@ std::vector<cvf::ref<cvf::DrawableGeo>> RivContourMapProjectionPartMgr::createCo
|
||||
cvf::ref<cvf::DrawableGeo>
|
||||
RivContourMapProjectionPartMgr::createPickPointVisDrawable(const caf::DisplayCoordTransform* displayCoordTransform) const
|
||||
{
|
||||
cvf::ref<cvf::DrawableGeo> geo = nullptr;
|
||||
std::vector<cvf::Vec3d> pickPointPolygon = m_contourMapProjection->generatePickPointPolygon();
|
||||
if (pickPointPolygon.empty())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(pickPointPolygon.size());
|
||||
|
||||
cvf::ref<cvf::Vec3fArray> pickPointPolygon = m_contourMapProjection->generatePickPointPolygon(displayCoordTransform);
|
||||
if (pickPointPolygon.notNull() && pickPointPolygon->size() > 0u)
|
||||
for (size_t i = 0; i < pickPointPolygon.size(); ++i)
|
||||
{
|
||||
cvf::Vec3f displayPoint(displayCoordTransform->transformToDisplayCoord(pickPointPolygon[i]));
|
||||
(*vertexArray)[i] = displayPoint;
|
||||
}
|
||||
|
||||
cvf::ref<cvf::DrawableGeo> geo = nullptr;
|
||||
if (vertexArray->size() > 0u)
|
||||
{
|
||||
std::vector<cvf::uint> indices;
|
||||
indices.reserve(pickPointPolygon->size());
|
||||
for (cvf::uint j = 0; j < pickPointPolygon->size(); ++j)
|
||||
indices.reserve(vertexArray->size());
|
||||
for (cvf::uint j = 0; j < vertexArray->size(); ++j)
|
||||
{
|
||||
indices.push_back(j);
|
||||
}
|
||||
@@ -226,7 +336,7 @@ cvf::ref<cvf::DrawableGeo>
|
||||
geo = new cvf::DrawableGeo;
|
||||
|
||||
geo->addPrimitiveSet(indexedUInt.p());
|
||||
geo->setVertexArray(pickPointPolygon.p());
|
||||
geo->setVertexArray(vertexArray.p());
|
||||
}
|
||||
return geo;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfDrawableGeo.h"
|
||||
#include "cvfDrawableText.h"
|
||||
#include "cvfModelBasicList.h"
|
||||
#include "cvfObject.h"
|
||||
|
||||
@@ -42,11 +43,12 @@ public:
|
||||
cvf::ref<cvf::Vec2fArray> createTextureCoords() const;
|
||||
|
||||
private:
|
||||
cvf::ref<cvf::DrawableGeo> createProjectionMapDrawable(const caf::DisplayCoordTransform* displayCoordTransform) const;
|
||||
std::vector<cvf::ref<cvf::DrawableGeo>> createContourPolygons(const caf::DisplayCoordTransform* displayCoordTransform) const;
|
||||
cvf::ref<cvf::DrawableGeo> createPickPointVisDrawable(const caf::DisplayCoordTransform* displayCoordTransform) const;
|
||||
static cvf::ref<cvf::DrawableText> createTextLabel(const cvf::Color3f& textColor, const cvf::Color3f& backgroundColor);
|
||||
cvf::ref<cvf::DrawableGeo> createProjectionMapDrawable(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:
|
||||
caf::PdmPointer<RimContourMapProjection> m_contourMapProjection;
|
||||
caf::PdmPointer<RimContourMapView> m_parentContourMap;
|
||||
caf::PdmPointer<RimContourMapProjection> m_contourMapProjection;
|
||||
caf::PdmPointer<RimContourMapView> m_parentContourMap;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user