#2544 Well CF Visualization: Add geometry generator and source info object

rename


remove unused


move to separate file


rename
This commit is contained in:
Magne Sjaastad
2018-03-15 21:25:54 +01:00
parent eb6b7450eb
commit 4853957637
10 changed files with 596 additions and 392 deletions

View File

@@ -0,0 +1,222 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018 Statoil 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.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RivWellConnectionFactorGeometryGenerator.h"
#include "cvfArray.h"
#include "cvfDrawableGeo.h"
#include "cvfPrimitiveSetIndexedUInt.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivWellConnectionFactorGeometryGenerator::createStarGeometry(std::vector<cvf::Vec3f>* vertices,
std::vector<cvf::uint>* indices,
float radius,
float thickness)
{
auto p0 = cvf::Vec3f::Z_AXIS * radius;
auto p2 = cvf::Vec3f::X_AXIS * -radius;
auto p4 = -p0;
auto p6 = -p2;
float innerFactor = 5.0f;
auto p1 = (p0 + p2) / innerFactor;
auto p3 = (p2 + p4) / innerFactor;
auto p5 = -p1;
auto p7 = -p3;
auto p8 = cvf::Vec3f::Y_AXIS * thickness;
auto p9 = -p8;
vertices->push_back(p0);
vertices->push_back(p1);
vertices->push_back(p2);
vertices->push_back(p3);
vertices->push_back(p4);
vertices->push_back(p5);
vertices->push_back(p6);
vertices->push_back(p7);
vertices->push_back(p8);
vertices->push_back(p9);
// Top
indices->push_back(0);
indices->push_back(1);
indices->push_back(8);
indices->push_back(0);
indices->push_back(8);
indices->push_back(7);
indices->push_back(0);
indices->push_back(9);
indices->push_back(1);
indices->push_back(0);
indices->push_back(7);
indices->push_back(9);
// Left
indices->push_back(2);
indices->push_back(3);
indices->push_back(8);
indices->push_back(2);
indices->push_back(8);
indices->push_back(1);
indices->push_back(2);
indices->push_back(9);
indices->push_back(3);
indices->push_back(2);
indices->push_back(1);
indices->push_back(9);
// Bottom
indices->push_back(4);
indices->push_back(5);
indices->push_back(8);
indices->push_back(4);
indices->push_back(8);
indices->push_back(3);
indices->push_back(4);
indices->push_back(9);
indices->push_back(5);
indices->push_back(4);
indices->push_back(3);
indices->push_back(9);
// Right
indices->push_back(6);
indices->push_back(7);
indices->push_back(8);
indices->push_back(6);
indices->push_back(8);
indices->push_back(5);
indices->push_back(6);
indices->push_back(9);
indices->push_back(7);
indices->push_back(6);
indices->push_back(5);
indices->push_back(9);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivWellConnectionFactorGeometryGenerator::RivWellConnectionFactorGeometryGenerator(
std::vector<CompletionVizData>& centerColorPairs,
float radius)
: m_centerColorPairs(centerColorPairs)
, m_radius(radius)
, m_trianglesPerConnection(0)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivWellConnectionFactorGeometryGenerator::~RivWellConnectionFactorGeometryGenerator() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::DrawableGeo> RivWellConnectionFactorGeometryGenerator::createPipeSurface()
{
std::vector<cvf::Vec3f> verticesForOneObject;
std::vector<cvf::uint> indicesForOneObject;
RivWellConnectionFactorGeometryGenerator::createStarGeometry(
&verticesForOneObject, &indicesForOneObject, m_radius, m_radius * 0.3f);
cvf::ref<cvf::Vec3fArray> vertices = new cvf::Vec3fArray;
cvf::ref<cvf::UIntArray> indices = new cvf::UIntArray;
auto indexCount = m_centerColorPairs.size() * indicesForOneObject.size();
auto vertexCount = m_centerColorPairs.size() * verticesForOneObject.size();
indices->reserve(indexCount);
vertices->reserve(vertexCount);
for (const auto& item : m_centerColorPairs)
{
auto rotMatrix = rotationMatrixBetweenVectors(cvf::Vec3d::Y_AXIS, item.m_direction);
cvf::uint indexOffset = static_cast<cvf::uint>(vertices->size());
for (const auto& v : verticesForOneObject)
{
auto rotatedPoint = v.getTransformedPoint(rotMatrix);
vertices->add(cvf::Vec3f(item.m_anchor) + rotatedPoint);
}
for (const auto& i : indicesForOneObject)
{
indices->add(i + indexOffset);
}
}
cvf::ref<cvf::DrawableGeo> drawable = new cvf::DrawableGeo();
drawable->setVertexArray(vertices.p());
drawable->addPrimitiveSet(new cvf::PrimitiveSetIndexedUInt(cvf::PT_TRIANGLES, indices.p()));
drawable->computeNormals();
return drawable;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t RivWellConnectionFactorGeometryGenerator::globalCellIndexFromTriangleIndex(cvf::uint triangleIndex) const
{
size_t connectionIndex = triangleIndex / m_trianglesPerConnection;
return m_centerColorPairs[connectionIndex].m_globalCellIndex;
}
//--------------------------------------------------------------------------------------------------
/// Taken from OverlayNavigationCube::computeNewUpVector
/// Consider move to geometry util class
//--------------------------------------------------------------------------------------------------
cvf::Mat4f RivWellConnectionFactorGeometryGenerator::rotationMatrixBetweenVectors(const cvf::Vec3d& v1, const cvf::Vec3d& v2)
{
using namespace cvf;
Vec3d rotAxis = v1 ^ v2;
rotAxis.normalize();
// Guard acos against out-of-domain input
const double dotProduct = Math::clamp(v1 * v2, -1.0, 1.0);
const double angle = Math::acos(dotProduct);
Mat4d rotMat = Mat4d::fromRotation(rotAxis, angle);
Mat4f myMat(rotMat);
return myMat;
}