diff --git a/ApplicationCode/ReservoirDataModel/cvfGeometryTools.cpp b/ApplicationCode/ReservoirDataModel/cvfGeometryTools.cpp index 0c9a0d47a2..ec7ac7130d 100644 --- a/ApplicationCode/ReservoirDataModel/cvfGeometryTools.cpp +++ b/ApplicationCode/ReservoirDataModel/cvfGeometryTools.cpp @@ -36,6 +36,19 @@ cvf::Vec3d return centerCoord; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Vec3d GeometryTools::computeTriangleCenter( const cvf::Vec3d& v0, const cvf::Vec3d& v1, const cvf::Vec3d& v2 ) +{ + cvf::Vec3d centerCoord = v0; + centerCoord += v1; + centerCoord += v2; + centerCoord /= 3.0; + + return centerCoord; +} + //-------------------------------------------------------------------------------------------------- /// Ez = Plane normal, Ex = in XY plane (horizontal), Ey = semi vertical upwards //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ReservoirDataModel/cvfGeometryTools.h b/ApplicationCode/ReservoirDataModel/cvfGeometryTools.h index 8867a32f26..1388221585 100644 --- a/ApplicationCode/ReservoirDataModel/cvfGeometryTools.h +++ b/ApplicationCode/ReservoirDataModel/cvfGeometryTools.h @@ -36,6 +36,9 @@ class GeometryTools public: static cvf::Vec3d computeFaceCenter( const cvf::Vec3d& v0, const cvf::Vec3d& v1, const cvf::Vec3d& v2, const cvf::Vec3d& v3 ); + static cvf::Vec3d computeTriangleCenter( const cvf::Vec3d& v0, const cvf::Vec3d& v1, const cvf::Vec3d& v2 ); + template + static Vec3Type computePolygonCenter( const std::vector& polygon ); static cvf::Mat3f computePlaneHorizontalRotationMx( const cvf::Vec3f& inPlaneVec0, const cvf::Vec3f& inPlaneVec1 ); static cvf::Vec3d projectPointOnLine( const cvf::Vec3d& p1, diff --git a/ApplicationCode/ReservoirDataModel/cvfGeometryTools.inl b/ApplicationCode/ReservoirDataModel/cvfGeometryTools.inl index ef71726de7..4195f24fa2 100644 --- a/ApplicationCode/ReservoirDataModel/cvfGeometryTools.inl +++ b/ApplicationCode/ReservoirDataModel/cvfGeometryTools.inl @@ -21,6 +21,25 @@ namespace cvf { + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +template +Vec3Type GeometryTools::computePolygonCenter(const std::vector& polygon) +{ + Vec3Type s; + + for (int i = 0; i < polygon.size(); i++) + { + s.x() += polygon[i].x(); + s.y() += polygon[i].y(); + s.z() += polygon[i].z(); + } + s /= polygon.size(); + return s; +} + //-------------------------------------------------------------------------------------------------- /// //--------------------------------------------------------------------------------------------------