#1069 Added ellipsis tesselator

This commit is contained in:
Magne Sjaastad
2017-01-04 07:39:08 +01:00
parent dc970edf7e
commit f8ef9bddc7
3 changed files with 137 additions and 0 deletions

View File

@@ -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

View 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);
}
}
}

View 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;
};