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::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
@ -174,17 +183,26 @@ cvf::ref<cvf::DrawableGeo> RivContourMapProjectionPartMgr::createProjectionMapDr
//--------------------------------------------------------------------------------------------------
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;
for (size_t i = 0; i < contourPolygons.size(); ++i)
{
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;
indices.reserve(contourPolygons[i][j]->size());
for (cvf::uint k = 0; k < contourPolygons[i][j]->size(); ++k)
indices.reserve(vertexArray->size());
for (cvf::uint k = 0; k < vertexArray->size(); ++k)
{
indices.push_back(k);
}
@ -209,14 +227,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);
}
@ -228,7 +257,7 @@ cvf::ref<cvf::DrawableGeo>
geo = new cvf::DrawableGeo;
geo->addPrimitiveSet(indexedUInt.p());
geo->setVertexArray(pickPointPolygon.p());
geo->setVertexArray(vertexArray.p());
}
return geo;
}

View File

@ -24,6 +24,7 @@
#include "RimEclipseResultDefinition.h"
#include "RimProject.h"
#include "RimRegularLegendConfig.h"
#include "RimTextAnnotation.h"
#include "cafContourLines.h"
#include "cafPdmUiDoubleSliderEditor.h"
@ -84,6 +85,7 @@ RimContourMapProjection::RimContourMapProjection()
m_weightingResult.uiCapability()->setUiTreeChildrenHidden(true);
m_weightingResult = new RimEclipseResultDefinition;
m_weightingResult->findField("MResultType")->uiCapability()->setUiName("Result Type");
setName("Map Projection");
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();
vertices->resize(nVertices);
std::vector<cvf::Vec3d> vertices(nVertices, cvf::Vec3d::ZERO);
#pragma omp parallel for
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.y() -= m_sampleSpacing * 0.5;
cvf::Vec3d globalVertexPos(globalPos, m_fullBoundingBox.min().z() - 1.0);
cvf::Vec3f displayVertexPos(displayCoordTransform->transformToDisplayCoord(globalVertexPos));
(*vertices)[index] = displayVertexPos;
cvf::Vec3d globalVertexPos(globalPos, m_fullBoundingBox.min().z());
vertices[index] = globalVertexPos;
}
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() &&
maxValue() != -std::numeric_limits<double>::infinity() &&
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)
{
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)
{
cvf::Vec3d contourPoint3d = cvf::Vec3d(closedContourLines[i][j][k], m_fullBoundingBox.min().z());
cvf::Vec3d displayPoint3d = displayCoordTransform->transformToDisplayCoord(contourPoint3d);
(*contourPolygon)[k] = cvf::Vec3f(displayPoint3d);
contourPolygon.push_back(contourPoint3d);
}
contourPolygons[i].push_back(contourPolygon);
}
@ -170,21 +171,21 @@ RimContourMapProjection::ClosedContourPolygons RimContourMapProjection::generate
}
}
}
return contourPolygons;
m_contourPolygons = contourPolygons;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::Vec3fArray>
RimContourMapProjection::generatePickPointPolygon(const caf::DisplayCoordTransform* displayCoordTransform)
std::vector<cvf::Vec3d>
RimContourMapProjection::generatePickPointPolygon()
{
cvf::ref<cvf::Vec3fArray> pickPolygon;
std::vector<cvf::Vec3d> points;
if (!m_pickPoint.isUndefined())
{
double zPos = m_fullBoundingBox.min().z();
std::vector<cvf::Vec3d> points;
{
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));
}
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
};
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() override;
void generateVertices(cvf::Vec3fArray* vertices, const caf::DisplayCoordTransform* displayCoordTransform);
ClosedContourPolygons generateContourPolygons(const caf::DisplayCoordTransform* displayCoordTransform);
cvf::ref<cvf::Vec3fArray> generatePickPointPolygon(const caf::DisplayCoordTransform* displayCoordTransform);
void generateResults();
std::vector<cvf::Vec3d> generateVertices();
void generateContourPolygons();
std::vector<cvf::Vec3d> generatePickPointPolygon();
void generateResults();
ResultAggregation resultAggregation() const;
double sampleSpacing() const;
double sampleSpacingFactor() const;
bool showContourLines() const;
const std::vector<ContourPolygons>& contourPolygons() const;
QString resultAggregationText() const;
QString resultDescriptionText() const;
QString weightingParameter() const;
ResultAggregation resultAggregation() const;
double sampleSpacing() const;
double sampleSpacingFactor() const;
bool showContourLines() const;
double maxValue() const;
double minValue() const;
double meanValue() const;
double sumAllValues() const;
QString resultAggregationText() const;
QString resultDescriptionText() const;
QString weightingParameter() const;
cvf::Vec2ui numberOfElementsIJ() const;
cvf::Vec2ui numberOfVerticesIJ() const;
double maxValue() 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 hasResultAtVertex(uint i, uint j) const;
bool isColumnResult() const;
RimRegularLegendConfig* legendConfig() const;
void updateLegend();
double valueAtVertex(uint i, uint j) const;
bool hasResultAtVertex(uint i, uint j) const;
uint numberOfCells() const;
uint numberOfValidCells() const;
size_t numberOfVertices() const;
RimRegularLegendConfig* legendConfig() const;
void updateLegend();
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 setPickPoint(cvf::Vec2d pickedPoint);
void updatedWeightingResult();
bool checkForMapIntersection(const cvf::Vec3d& localPoint3d, cvf::Vec2d* contourMapPoint, cvf::Vec2ui* contourMapCell, double* valueAtPoint) const;
void setPickPoint(cvf::Vec2d pickedPoint);
protected:
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_weightByParameter;
caf::PdmChildField<RimEclipseResultDefinition*> m_weightingResult;
cvf::ref<cvf::UByteArray> m_cellGridIdxVisibility;
std::vector<double> m_aggregatedResults;
@ -177,4 +181,5 @@ protected:
cvf::Vec2ui m_mapSize;
cvf::BoundingBox m_fullBoundingBox;
double m_sampleSpacing;
std::vector<ContourPolygons> m_contourPolygons;
};