GteIntpLinearNonuniform2.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 // Linear interpolation of a network of triangles whose vertices are of the
11 // form (x,y,f(x,y)). The function samples are F[i] and represent
12 // f(x[i],y[i]), where i is the index of the input vertex (x[i],y[i]) to
13 // Delaunay2.
14 //
15 // The TriangleMesh interface must support the following:
16 // bool GetIndices(int, std::array<int, 3>&) const;
17 // bool GetBarycentrics(int, Vector2<Real> const&,
18 // std::array<Real, 3>&) const;
19 // int GetContainingTriangle(Vector2<Real> const&) const;
20 
21 #include <LowLevel/GteLogger.h>
22 #include <Mathematics/GteVector2.h>
23 
24 namespace gte
25 {
26 
27 template <typename Real, typename TriangleMesh>
29 {
30 public:
31  // Construction.
32  IntpLinearNonuniform2(TriangleMesh const& mesh, Real const* F);
33 
34  // Linear interpolation. The return value is 'true' if and only if the
35  // input point P is in the convex hull of the input vertices, in which
36  // case the interpolation is valid.
37  bool operator()(Vector2<Real> const& P, Real& F) const;
38 
39 private:
40  TriangleMesh const* mMesh;
41  Real const* mF;
42 };
43 
44 
45 template <typename Real, typename TriangleMesh>
47  TriangleMesh const& mesh, Real const* F)
48  :
49  mMesh(&mesh),
50  mF(F)
51 {
52  LogAssert(mF != nullptr, "Invalid input.");
53 }
54 
55 template <typename Real, typename TriangleMesh>
57  Vector2<Real> const& P, Real& F) const
58 {
59  int t = mMesh->GetContainingTriangle(P);
60  if (t == -1)
61  {
62  // The point is outside the triangulation.
63  return false;
64  }
65 
66  // Get the barycentric coordinates of P with respect to the triangle,
67  // P = b0*V0 + b1*V1 + b2*V2, where b0 + b1 + b2 = 1.
68  std::array<Real, 3> bary;
69  if (!mMesh->GetBarycentrics(t, P, bary))
70  {
71  LogWarning("P is in a needle-like or degenerate triangle.");
72  return false;
73  }
74 
75  // The result is a barycentric combination of function values.
76  std::array<int, 3> indices;
77  mMesh->GetIndices(t, indices);
78  F = bary[0] * mF[indices[0]] + bary[1] * mF[indices[1]] +
79  bary[2] * mF[indices[2]];
80  return true;
81 }
82 
83 
84 }
#define LogAssert(condition, message)
Definition: GteLogger.h:86
GLsizei GLenum const void * indices
Definition: glcorearb.h:401
#define LogWarning(message)
Definition: GteLogger.h:95
GLdouble GLdouble t
Definition: glext.h:239
IntpLinearNonuniform2(TriangleMesh const &mesh, Real const *F)
bool operator()(Vector2< Real > const &P, Real &F) const


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:00