#3498 Implement 2d grid projection prototype with regular grid.

This commit is contained in:
Gaute Lindkvist
2018-10-16 09:53:30 +02:00
parent 70ad291900
commit 222ac5137f
14 changed files with 734 additions and 5 deletions

View File

@@ -45,6 +45,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RivWellConnectionSourceInfo.h
${CMAKE_CURRENT_LIST_DIR}/RivSimWellConnectionSourceInfo.h
${CMAKE_CURRENT_LIST_DIR}/Riv3dWellLogDrawSurfaceGenerator.h
${CMAKE_CURRENT_LIST_DIR}/RivMeshLinesSourceInfo.h
${CMAKE_CURRENT_LIST_DIR}/Riv2dGridProjectionPartMgr.h
)
set (SOURCE_GROUP_SOURCE_FILES
@@ -88,6 +89,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RivWellConnectionSourceInfo.cpp
${CMAKE_CURRENT_LIST_DIR}/RivSimWellConnectionSourceInfo.cpp
${CMAKE_CURRENT_LIST_DIR}/Riv3dWellLogDrawSurfaceGenerator.cpp
${CMAKE_CURRENT_LIST_DIR}/RivMeshLinesSourceInfo.cpp
${CMAKE_CURRENT_LIST_DIR}/Riv2dGridProjectionPartMgr.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@@ -0,0 +1,118 @@
#include "Riv2dGridProjectionPartMgr.h"
#include "RivMeshLinesSourceInfo.h"
#include "RivScalarMapperUtils.h"
#include "Rim2dGridProjection.h"
#include "cafEffectGenerator.h"
#include "cvfGeometryBuilderFaceList.h"
#include "cvfGeometryUtils.h"
#include "cvfMeshEdgeExtractor.h"
#include "cvfPart.h"
#include "cvfPrimitiveSetIndexedUInt.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Riv2dGridProjectionPartMgr::Riv2dGridProjectionPartMgr(Rim2dGridProjection* gridProjection)
{
m_2dGridProjection = gridProjection;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Riv2dGridProjectionPartMgr::appendProjectionToModel(cvf::ModelBasicList* model, const caf::DisplayCoordTransform* displayCoordTransform) const
{
cvf::ref<cvf::DrawableGeo> drawable = createDrawable(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();
cvf::ScalarMapper* mapper = m_2dGridProjection->legendConfig()->scalarMapper();
RivScalarMapperUtils::applyTextureResultsToPart(part.p(), textureCoords.p(), mapper, 1.0, caf::FC_NONE, true);
part->setSourceInfo(new RivMeshLinesSourceInfo(m_2dGridProjection.p()));
model->addPart(part.p());
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::Vec2fArray> Riv2dGridProjectionPartMgr::createTextureCoords() const
{
cvf::Vec2ui patchSize = m_2dGridProjection->surfaceGridSize();
cvf::ref<cvf::Vec2fArray> textureCoords = new cvf::Vec2fArray(m_2dGridProjection->vertexCount());
for (uint j = 0; j < patchSize.y(); ++j)
{
for (uint i = 0; i < patchSize.x(); ++i)
{
double value = m_2dGridProjection->value(i, j);
(*textureCoords)[i + j * patchSize.x()] =
m_2dGridProjection->legendConfig()->scalarMapper()->mapToTextureCoord(value);
}
}
return textureCoords;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Riv2dGridProjectionPartMgr::removeTrianglesWithNoResult(cvf::UIntArray* vertices) const
{
std::vector<cvf::uint> trianglesWithResult;
for (size_t n = 0; n < vertices->size(); n += 3)
{
bool anyInvalid = false;
for (size_t t = 0; !anyInvalid && t < 3; ++t)
{
cvf::uint vertexNumber = (*vertices)[n + t];
cvf::Vec2ui ij = m_2dGridProjection->ijFromGridIndex(vertexNumber);
if (!m_2dGridProjection->hasResultAt(ij.x(), ij.y()))
{
anyInvalid = true;
}
}
for (size_t t = 0; !anyInvalid && t < 3; ++t)
{
cvf::uint vertexNumber = (*vertices)[n + t];
trianglesWithResult.push_back(vertexNumber);
}
}
(*vertices) = cvf::UIntArray(trianglesWithResult);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::DrawableGeo> Riv2dGridProjectionPartMgr::createDrawable(const caf::DisplayCoordTransform* displayCoordTransform) const
{
m_2dGridProjection->updateDefaultSampleSpacingFromGrid();
m_2dGridProjection->extractGridData();
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray;
m_2dGridProjection->generateVertices(vertexArray.p(), displayCoordTransform);
cvf::Vec2ui patchSize = m_2dGridProjection->surfaceGridSize();
// Surface
cvf::ref<cvf::UIntArray> faceList = new cvf::UIntArray;
cvf::GeometryUtils::tesselatePatchAsTriangles(patchSize.x(), patchSize.y(), 0u, true, faceList.p());
removeTrianglesWithNoResult(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;
}

View File

@@ -0,0 +1,47 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafPdmPointer.h"
#include "cafDisplayCoordTransform.h"
#include "cvfBase.h"
#include "cvfDrawableGeo.h"
#include "cvfModelBasicList.h"
#include "cvfObject.h"
class Rim2dGridProjection;
class Riv2dGridProjectionPartMgr : public cvf::Object
{
public:
Riv2dGridProjectionPartMgr(Rim2dGridProjection* gridProjection);
void appendProjectionToModel(cvf::ModelBasicList* model,
const caf::DisplayCoordTransform* displayCoordTransform) const;
cvf::ref<cvf::Vec2fArray> createTextureCoords() const;
void removeTrianglesWithNoResult(cvf::UIntArray* uintArray) const;
private:
cvf::ref<cvf::DrawableGeo> createDrawable(const caf::DisplayCoordTransform* displayCoordTransform) const;
private:
caf::PdmPointer<Rim2dGridProjection> m_2dGridProjection;
};