Move display transforms from contour map

This commit is contained in:
Gaute Lindkvist 2018-12-20 10:38:20 +01:00
parent 648250290e
commit d259f8f33a
3 changed files with 101 additions and 66 deletions

View File

@ -153,8 +153,17 @@ cvf::ref<cvf::Vec2fArray> RivContourMapProjectionPartMgr::createTextureCoords()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
cvf::ref<cvf::DrawableGeo> RivContourMapProjectionPartMgr::createProjectionMapDrawable(const caf::DisplayCoordTransform* displayCoordTransform) const cvf::ref<cvf::DrawableGeo> RivContourMapProjectionPartMgr::createProjectionMapDrawable(const caf::DisplayCoordTransform* displayCoordTransform) const
{ {
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray; std::vector<cvf::Vec3d> vertices = m_contourMapProjection->generateVertices();
m_contourMapProjection->generateVertices(vertexArray.p(), displayCoordTransform); 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(); cvf::Vec2ui patchSize = m_contourMapProjection->numberOfVerticesIJ();
// Surface // Surface
@ -174,17 +183,26 @@ cvf::ref<cvf::DrawableGeo> RivContourMapProjectionPartMgr::createProjectionMapDr
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
std::vector<cvf::ref<cvf::DrawableGeo>> RivContourMapProjectionPartMgr::createContourPolygons(const caf::DisplayCoordTransform* displayCoordTransform) const std::vector<cvf::ref<cvf::DrawableGeo>> RivContourMapProjectionPartMgr::createContourPolygons(const caf::DisplayCoordTransform* displayCoordTransform) const
{ {
RimContourMapProjection::ClosedContourPolygons contourPolygons = m_contourMapProjection->generateContourPolygons(displayCoordTransform); m_contourMapProjection->generateContourPolygons();
const std::vector<RimContourMapProjection::ContourPolygons>& contourPolygons = m_contourMapProjection->contourPolygons();
std::vector<cvf::ref<cvf::DrawableGeo>> contourDrawables; std::vector<cvf::ref<cvf::DrawableGeo>> contourDrawables;
for (size_t i = 0; i < contourPolygons.size(); ++i) for (size_t i = 0; i < contourPolygons.size(); ++i)
{ {
for (size_t j = 0; j < contourPolygons[i].size(); ++j) for (size_t j = 0; j < contourPolygons[i].size(); ++j)
{ {
cvf::ref<cvf::Vec3fArray> vertexArray = contourPolygons[i][j]; if (contourPolygons[i][j].empty()) continue;
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(contourPolygons[i][j].size());
for (size_t v = 0; v < contourPolygons[i][j].size(); ++v)
{
cvf::Vec3f displayVertex(displayCoordTransform->transformToDisplayCoord(contourPolygons[i][j][v]));
(*vertexArray)[v] = displayVertex;
}
std::vector<cvf::uint> indices; std::vector<cvf::uint> indices;
indices.reserve(contourPolygons[i][j]->size()); indices.reserve(vertexArray->size());
for (cvf::uint k = 0; k < contourPolygons[i][j]->size(); ++k) for (cvf::uint k = 0; k < vertexArray->size(); ++k)
{ {
indices.push_back(k); indices.push_back(k);
} }
@ -209,14 +227,25 @@ std::vector<cvf::ref<cvf::DrawableGeo>> RivContourMapProjectionPartMgr::createCo
cvf::ref<cvf::DrawableGeo> cvf::ref<cvf::DrawableGeo>
RivContourMapProjectionPartMgr::createPickPointVisDrawable(const caf::DisplayCoordTransform* displayCoordTransform) const 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); for (size_t i = 0; i < pickPointPolygon.size(); ++i)
if (pickPointPolygon.notNull() && pickPointPolygon->size() > 0u) {
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; std::vector<cvf::uint> indices;
indices.reserve(pickPointPolygon->size()); indices.reserve(vertexArray->size());
for (cvf::uint j = 0; j < pickPointPolygon->size(); ++j) for (cvf::uint j = 0; j < vertexArray->size(); ++j)
{ {
indices.push_back(j); indices.push_back(j);
} }
@ -228,7 +257,7 @@ cvf::ref<cvf::DrawableGeo>
geo = new cvf::DrawableGeo; geo = new cvf::DrawableGeo;
geo->addPrimitiveSet(indexedUInt.p()); geo->addPrimitiveSet(indexedUInt.p());
geo->setVertexArray(pickPointPolygon.p()); geo->setVertexArray(vertexArray.p());
} }
return geo; return geo;
} }

View File

@ -24,6 +24,7 @@
#include "RimEclipseResultDefinition.h" #include "RimEclipseResultDefinition.h"
#include "RimProject.h" #include "RimProject.h"
#include "RimRegularLegendConfig.h" #include "RimRegularLegendConfig.h"
#include "RimTextAnnotation.h"
#include "cafContourLines.h" #include "cafContourLines.h"
#include "cafPdmUiDoubleSliderEditor.h" #include "cafPdmUiDoubleSliderEditor.h"
@ -84,6 +85,7 @@ RimContourMapProjection::RimContourMapProjection()
m_weightingResult.uiCapability()->setUiTreeChildrenHidden(true); m_weightingResult.uiCapability()->setUiTreeChildrenHidden(true);
m_weightingResult = new RimEclipseResultDefinition; m_weightingResult = new RimEclipseResultDefinition;
m_weightingResult->findField("MResultType")->uiCapability()->setUiName("Result Type"); m_weightingResult->findField("MResultType")->uiCapability()->setUiName("Result Type");
setName("Map Projection"); setName("Map Projection");
nameField()->uiCapability()->setUiReadOnly(true); nameField()->uiCapability()->setUiReadOnly(true);
@ -102,11 +104,10 @@ RimContourMapProjection::~RimContourMapProjection()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimContourMapProjection::generateVertices(cvf::Vec3fArray* vertices, const caf::DisplayCoordTransform* displayCoordTransform) std::vector<cvf::Vec3d> RimContourMapProjection::generateVertices()
{ {
CVF_ASSERT(vertices);
size_t nVertices = numberOfVertices(); size_t nVertices = numberOfVertices();
vertices->resize(nVertices); std::vector<cvf::Vec3d> vertices(nVertices, cvf::Vec3d::ZERO);
#pragma omp parallel for #pragma omp parallel for
for (int index = 0; index < static_cast<int>(nVertices); ++index) for (int index = 0; index < static_cast<int>(nVertices); ++index)
@ -117,10 +118,10 @@ void RimContourMapProjection::generateVertices(cvf::Vec3fArray* vertices, const
globalPos.x() -= m_sampleSpacing * 0.5; globalPos.x() -= m_sampleSpacing * 0.5;
globalPos.y() -= m_sampleSpacing * 0.5; globalPos.y() -= m_sampleSpacing * 0.5;
cvf::Vec3d globalVertexPos(globalPos, m_fullBoundingBox.min().z() - 1.0); cvf::Vec3d globalVertexPos(globalPos, m_fullBoundingBox.min().z());
cvf::Vec3f displayVertexPos(displayCoordTransform->transformToDisplayCoord(globalVertexPos)); vertices[index] = globalVertexPos;
(*vertices)[index] = displayVertexPos;
} }
return vertices;
} }
@ -128,9 +129,10 @@ void RimContourMapProjection::generateVertices(cvf::Vec3fArray* vertices, const
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RimContourMapProjection::ClosedContourPolygons RimContourMapProjection::generateContourPolygons(const caf::DisplayCoordTransform* displayCoordTransform) void RimContourMapProjection::generateContourPolygons()
{ {
ClosedContourPolygons contourPolygons; std::vector<ContourPolygons> contourPolygons;
if (minValue() != std::numeric_limits<double>::infinity() && if (minValue() != std::numeric_limits<double>::infinity() &&
maxValue() != -std::numeric_limits<double>::infinity() && maxValue() != -std::numeric_limits<double>::infinity() &&
std::fabs(maxValue() - minValue()) > 1.0e-8) std::fabs(maxValue() - minValue()) > 1.0e-8)
@ -157,12 +159,11 @@ RimContourMapProjection::ClosedContourPolygons RimContourMapProjection::generate
{ {
for (size_t j = 0; j < closedContourLines[i].size(); ++j) for (size_t j = 0; j < closedContourLines[i].size(); ++j)
{ {
cvf::ref<cvf::Vec3fArray> contourPolygon = new cvf::Vec3fArray(closedContourLines[i][j].size()); ContourPolygon contourPolygon; contourPolygon.reserve(closedContourLines[i][j].size());
for (size_t k = 0; k < closedContourLines[i][j].size(); ++k) for (size_t k = 0; k < closedContourLines[i][j].size(); ++k)
{ {
cvf::Vec3d contourPoint3d = cvf::Vec3d(closedContourLines[i][j][k], m_fullBoundingBox.min().z()); cvf::Vec3d contourPoint3d = cvf::Vec3d(closedContourLines[i][j][k], m_fullBoundingBox.min().z());
cvf::Vec3d displayPoint3d = displayCoordTransform->transformToDisplayCoord(contourPoint3d); contourPolygon.push_back(contourPoint3d);
(*contourPolygon)[k] = cvf::Vec3f(displayPoint3d);
} }
contourPolygons[i].push_back(contourPolygon); contourPolygons[i].push_back(contourPolygon);
} }
@ -170,21 +171,21 @@ RimContourMapProjection::ClosedContourPolygons RimContourMapProjection::generate
} }
} }
} }
return contourPolygons; m_contourPolygons = contourPolygons;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
cvf::ref<cvf::Vec3fArray> std::vector<cvf::Vec3d>
RimContourMapProjection::generatePickPointPolygon(const caf::DisplayCoordTransform* displayCoordTransform) RimContourMapProjection::generatePickPointPolygon()
{ {
cvf::ref<cvf::Vec3fArray> pickPolygon; std::vector<cvf::Vec3d> points;
if (!m_pickPoint.isUndefined()) if (!m_pickPoint.isUndefined())
{ {
double zPos = m_fullBoundingBox.min().z(); double zPos = m_fullBoundingBox.min().z();
std::vector<cvf::Vec3d> points;
{ {
cvf::Vec2d gridorigin(m_fullBoundingBox.min().x(), m_fullBoundingBox.min().y()); cvf::Vec2d gridorigin(m_fullBoundingBox.min().x(), m_fullBoundingBox.min().y());
@ -209,16 +210,8 @@ RimContourMapProjection::generatePickPointPolygon(const caf::DisplayCoordTransfo
points.push_back(cvf::Vec3d(m_pickPoint - cvf::Vec2d(0.0, 0.5 * m_sampleSpacing), zPos)); points.push_back(cvf::Vec3d(m_pickPoint - cvf::Vec2d(0.0, 0.5 * m_sampleSpacing), zPos));
points.push_back(cvf::Vec3d(m_pickPoint + cvf::Vec2d(0.0, 0.5 * m_sampleSpacing), zPos)); points.push_back(cvf::Vec3d(m_pickPoint + cvf::Vec2d(0.0, 0.5 * m_sampleSpacing), zPos));
} }
pickPolygon = new cvf::Vec3fArray(points.size());
for (size_t i = 0; i < points.size(); ++i)
{
cvf::Vec3d displayPoint = displayCoordTransform->transformToDisplayCoord(points[i]);
(*pickPolygon)[i] = cvf::Vec3f(displayPoint);
}
} }
return pickPolygon; return points;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -285,6 +278,14 @@ void RimContourMapProjection::generateResults()
} }
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const std::vector<RimContourMapProjection::ContourPolygons>& RimContourMapProjection::contourPolygons() const
{
return m_contourPolygons;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -60,49 +60,52 @@ public:
RESULTS_HC_COLUMN RESULTS_HC_COLUMN
}; };
typedef caf::AppEnum<ResultAggregationEnum> ResultAggregation; typedef caf::AppEnum<ResultAggregationEnum> ResultAggregation;
typedef std::vector<std::vector<cvf::ref<cvf::Vec3fArray>>> ClosedContourPolygons; typedef std::vector<cvf::Vec3d> ContourPolygon;
typedef std::vector<ContourPolygon> ContourPolygons;
RimContourMapProjection(); RimContourMapProjection();
~RimContourMapProjection() override; ~RimContourMapProjection() override;
void generateVertices(cvf::Vec3fArray* vertices, const caf::DisplayCoordTransform* displayCoordTransform); std::vector<cvf::Vec3d> generateVertices();
ClosedContourPolygons generateContourPolygons(const caf::DisplayCoordTransform* displayCoordTransform); void generateContourPolygons();
cvf::ref<cvf::Vec3fArray> generatePickPointPolygon(const caf::DisplayCoordTransform* displayCoordTransform); std::vector<cvf::Vec3d> generatePickPointPolygon();
void generateResults(); void generateResults();
ResultAggregation resultAggregation() const; const std::vector<ContourPolygons>& contourPolygons() const;
double sampleSpacing() const;
double sampleSpacingFactor() const;
bool showContourLines() const;
QString resultAggregationText() const; ResultAggregation resultAggregation() const;
QString resultDescriptionText() const; double sampleSpacing() const;
QString weightingParameter() const; double sampleSpacingFactor() const;
bool showContourLines() const;
double maxValue() const; QString resultAggregationText() const;
double minValue() const; QString resultDescriptionText() const;
double meanValue() const; QString weightingParameter() const;
double sumAllValues() const;
cvf::Vec2ui numberOfElementsIJ() const; double maxValue() const;
cvf::Vec2ui numberOfVerticesIJ() const; double minValue() const;
double meanValue() const;
double sumAllValues() const;
bool isColumnResult() const; cvf::Vec2ui numberOfElementsIJ() const;
cvf::Vec2ui numberOfVerticesIJ() const;
double valueAtVertex(uint i, uint j) const; bool isColumnResult() const;
bool hasResultAtVertex(uint i, uint j) const;
RimRegularLegendConfig* legendConfig() const; double valueAtVertex(uint i, uint j) const;
void updateLegend(); bool hasResultAtVertex(uint i, uint j) const;
uint numberOfCells() const; RimRegularLegendConfig* legendConfig() const;
uint numberOfValidCells() const; void updateLegend();
size_t numberOfVertices() const;
void updatedWeightingResult(); uint numberOfCells() const;
uint numberOfValidCells() const;
size_t numberOfVertices() const;
bool checkForMapIntersection(const cvf::Vec3d& localPoint3d, cvf::Vec2d* contourMapPoint, cvf::Vec2ui* contourMapCell, double* valueAtPoint) const; void updatedWeightingResult();
void setPickPoint(cvf::Vec2d pickedPoint);
bool checkForMapIntersection(const cvf::Vec3d& localPoint3d, cvf::Vec2d* contourMapPoint, cvf::Vec2ui* contourMapCell, double* valueAtPoint) const;
void setPickPoint(cvf::Vec2d pickedPoint);
protected: protected:
void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
@ -161,6 +164,7 @@ protected:
caf::PdmField<bool> m_showContourLines; caf::PdmField<bool> m_showContourLines;
caf::PdmField<bool> m_weightByParameter; caf::PdmField<bool> m_weightByParameter;
caf::PdmChildField<RimEclipseResultDefinition*> m_weightingResult; caf::PdmChildField<RimEclipseResultDefinition*> m_weightingResult;
cvf::ref<cvf::UByteArray> m_cellGridIdxVisibility; cvf::ref<cvf::UByteArray> m_cellGridIdxVisibility;
std::vector<double> m_aggregatedResults; std::vector<double> m_aggregatedResults;
@ -177,4 +181,5 @@ protected:
cvf::Vec2ui m_mapSize; cvf::Vec2ui m_mapSize;
cvf::BoundingBox m_fullBoundingBox; cvf::BoundingBox m_fullBoundingBox;
double m_sampleSpacing; double m_sampleSpacing;
std::vector<ContourPolygons> m_contourPolygons;
}; };