GteIntpLinearNonuniform3.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,z,f(x,y,z)). The function samples are F[i] and represent
12 // f(x[i],y[i],z[i]), where i is the index of the input vertex
13 // (x[i],y[i],z[i]) to Delaunay3.
14 //
15 // The TetrahedronMesh interface must support the following:
16 // int GetContainingTetrahedron(Vector3<Real> const&) const;
17 // bool GetIndices(int, std::array<int, 4>&) const;
18 // bool GetBarycentrics(int, Vector3<Real> const&, Real[4]) const;
19 
20 #include <LowLevel/GteLogger.h>
21 #include <Mathematics/GteVector3.h>
22 
23 namespace gte
24 {
25 
26 template <typename Real, typename TetrahedronMesh>
28 {
29 public:
30  // Construction.
31  IntpLinearNonuniform3(TetrahedronMesh const& mesh, Real const* F);
32 
33  // Linear interpolation. The return value is 'true' if and only if the
34  // input point is in the convex hull of the input vertices, in which case
35  // the interpolation is valid.
36  bool operator()(Vector3<Real> const& P, Real& F) const;
37 
38 private:
39  TetrahedronMesh const* mMesh;
40  Real const* mF;
41 };
42 
43 
44 template <typename Real, typename TetrahedronMesh>
46  TetrahedronMesh const& mesh, Real const* F)
47  :
48  mMesh(&mesh),
49  mF(F)
50 {
51  LogAssert(mF != nullptr, "Invalid input.");
52 }
53 
54 template <typename Real, typename TetrahedronMesh>
56  Vector3<Real> const& P, Real& F) const
57 {
58  int t = mMesh->GetContainingTetrahedron(P);
59  if (t == -1)
60  {
61  // The point is outside the tetrahedralization.
62  return false;
63  }
64 
65  // Get the barycentric coordinates of P with respect to the tetrahedron,
66  // P = b0*V0 + b1*V1 + b2*V2 + b3*V3, where b0 + b1 + b2 + b3 = 1.
67  std::array<Real, 4> bary;
68  if (!mMesh->GetBarycentrics(t, P, bary))
69  {
70  LogWarning("P is in a needle-like, flat, or degenerate tetrahedron.");
71  return false;
72  }
73 
74  // The result is a barycentric combination of function values.
75  std::array<int, 4> indices;
76  mMesh->GetIndices(t, indices);
77  F = bary[0] * mF[indices[0]] + bary[1] * mF[indices[1]] +
78  bary[2] * mF[indices[2]] + bary[3] * mF[indices[4]];
79  return true;
80 }
81 
82 
83 }
bool operator()(Vector3< Real > const &P, Real &F) const
#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
IntpLinearNonuniform3(TetrahedronMesh const &mesh, Real const *F)


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