mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1069 Added ellipsis tesselator
This commit is contained in:
@@ -50,6 +50,7 @@ ${CEE_CURRENT_LIST_DIR}RigCurveDataTools.h
|
||||
${CEE_CURRENT_LIST_DIR}RigSummaryCaseData.h
|
||||
${CEE_CURRENT_LIST_DIR}RigLasFileExporter.h
|
||||
${CEE_CURRENT_LIST_DIR}RigFracture.h
|
||||
${CEE_CURRENT_LIST_DIR}RigTesselatorTools.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
@@ -93,6 +94,7 @@ ${CEE_CURRENT_LIST_DIR}RigCurveDataTools.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RigSummaryCaseData.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RigLasFileExporter.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RigFracture.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RigTesselatorTools.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
||||
92
ApplicationCode/ReservoirDataModel/RigTesselatorTools.cpp
Normal file
92
ApplicationCode/ReservoirDataModel/RigTesselatorTools.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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 "RigTesselatorTools.h"
|
||||
|
||||
#include "cvfMath.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RigEllipsisTesselator::RigEllipsisTesselator(size_t numSlices)
|
||||
{
|
||||
computeCirclePoints(numSlices);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigEllipsisTesselator::tesselateEllipsis(float a, float b, std::vector<cvf::uint>* polygonIndices, std::vector<cvf::Vec3f>* nodeCoords)
|
||||
{
|
||||
// See http://mathworld.wolfram.com/Ellipse.html
|
||||
|
||||
for (auto v : m_circlePoints)
|
||||
{
|
||||
v.x() = v.x() * a;
|
||||
v.y() = v.y() * b;
|
||||
|
||||
nodeCoords->push_back(v);
|
||||
}
|
||||
|
||||
*polygonIndices = m_circleConnectivities;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigEllipsisTesselator::computeCirclePoints(size_t numSlices)
|
||||
{
|
||||
// Based on GeometryUtils::generatePointsOnCircle
|
||||
|
||||
double da = 2 * cvf::PI_D / numSlices;
|
||||
|
||||
cvf::Vec3f point = cvf::Vec3f::ZERO;
|
||||
|
||||
// Center of circle
|
||||
m_circlePoints.push_back(point);
|
||||
|
||||
for (size_t i = 0; i < numSlices; i++)
|
||||
{
|
||||
// Precompute this one (A = i*da;)
|
||||
double sinA = cvf::Math::sin(i*da);
|
||||
double cosA = cvf::Math::cos(i*da);
|
||||
|
||||
point.x() = static_cast<float>(-sinA);
|
||||
point.y() = static_cast<float>( cosA);
|
||||
|
||||
m_circlePoints.push_back(point);
|
||||
}
|
||||
|
||||
for (cvf::uint i = 0; i < static_cast<cvf::uint>(numSlices); i++)
|
||||
{
|
||||
// Center
|
||||
m_circleConnectivities.push_back(0);
|
||||
|
||||
m_circleConnectivities.push_back(i + 1);
|
||||
|
||||
if (i == (numSlices - 1))
|
||||
{
|
||||
// Connect the last slice to the first slice
|
||||
m_circleConnectivities.push_back(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_circleConnectivities.push_back(i + 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
43
ApplicationCode/ReservoirDataModel/RigTesselatorTools.h
Normal file
43
ApplicationCode/ReservoirDataModel/RigTesselatorTools.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfVector3.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RigEllipsisTesselator
|
||||
{
|
||||
public:
|
||||
RigEllipsisTesselator(size_t numSlices);
|
||||
|
||||
void tesselateEllipsis(float a, float b, std::vector<cvf::uint>* polygonIndices, std::vector<cvf::Vec3f>* nodeCoords);
|
||||
|
||||
private:
|
||||
void computeCirclePoints(size_t numSlices);
|
||||
|
||||
private:
|
||||
std::vector<cvf::Vec3f> m_circlePoints;
|
||||
std::vector<cvf::uint> m_circleConnectivities;
|
||||
};
|
||||
Reference in New Issue
Block a user