libsurf
Programmer's Documentation

subsurface.h (r6227/r5337)
1 
2 /* Copyright (C) 2015 David Eller <david@larosterna.com>
3  *
4  * Commercial License Usage
5  * Licensees holding valid commercial licenses may use this file in accordance
6  * with the terms contained in their respective non-exclusive license agreement.
7  * For further information contact david@larosterna.com .
8  *
9  * GNU General Public License Usage
10  * Alternatively, this file may be used under the terms of the GNU General
11  * Public License version 3.0 as published by the Free Software Foundation and
12  * appearing in the file gpl.txt included in the packaging of this file.
13  */
14 
15 #ifndef SURF_SUBSURFACE_H
16 #define SURF_SUBSURFACE_H
17 
18 #include "forward.h"
19 #include "surface.h"
20 #include <genua/bounds.h>
21 
26 class SubSurface : public Surface
27 {
28 public:
29 
31  SubSurface(const Surface & s, const BndRect & br);
32 
34  SubSurface(const Surface & s, const Vct2 & plo, const Vct2 & phi);
35 
37  SubSurface(SurfacePtr p, const Vct2 & plo, const Vct2 & phi);
38 
40  Vct3 eval(Real u, Real v) const {
41  return psf->eval(umap(u), vmap(v));
42  }
43 
45  Vct3 derive(Real u, Real v, uint ku, uint kv) const {
46  Real f = pow(du,Real(ku))*pow(dv,Real(kv));
47  return f*psf->derive(umap(u), vmap(v), ku, kv);
48  }
49 
51  void plane(Real u, Real v, Vct3 & S, Vct3 & Su, Vct3 & Sv) const {
52  psf->plane(umap(u), vmap(v), S, Su, Sv);
53  Su *= du;
54  Sv *= dv;
55  }
56 
58  Vct3 normal(Real u, Real v) const {
59  return psf->normal(umap(u), vmap(v));
60  }
61 
63  bool project(const Vct3 & pt, Vct2 & q, Real tol=1e-6, Real dpmin=1e-6) const;
64 
66  void apply() {assert(!"Cannot transform SubSurface.");}
67 
69  XmlElement toXml(bool share=false) const;
70 
72  void fromXml(const XmlElement & xe);
73 
75  SubSurface *clone() const;
76 
78  void toLocal(PointList<2> & pts) const;
79 
81  void toGlobal(PointList<2> & pts) const;
82 
83 protected:
84 
86  void init(const Vct2 & plo, const Vct2 & phi) {
87  uo = plo[0];
88  du = phi[0]-plo[0];
89  vo = plo[1];
90  dv = phi[1]-plo[1];
91  }
92 
94  Real umap(Real t) const {return uo + t*du;}
95 
97  Real vmap(Real t) const {return vo + t*dv;}
98 
99 private:
100 
102  SurfacePtr psf;
103 
105  Real uo, du, vo, dv;
106 };
107 
108 #endif
Vct3 eval(Real u, Real v) const
evaluate surface
Definition: subsurface.h:40
void plane(Real u, Real v, Vct3 &S, Vct3 &Su, Vct3 &Sv) const
compute point and tangent derivatives at (u,v), for efficiency
Definition: subsurface.h:51
void fromXml(const XmlElement &xe)
XML input.
Definition: subsurface.cpp:43
bool project(const Vct3 &pt, Vct2 &q, Real tol=1e-6, Real dpmin=1e-6) const
find projection of pt on surface (needs a guess in q)
Definition: subsurface.cpp:26
void toLocal(PointList< 2 > &pts) const
map global points to local coordinates
Definition: subsurface.cpp:55
Vct3 normal(Real u, Real v) const
compute normal vector
Definition: subsurface.h:58
SubSurface * clone() const
generate a clone
Definition: subsurface.cpp:48
Real vmap(Real t) const
map v value
Definition: subsurface.h:97
void init(const Vct2 &plo, const Vct2 &phi)
initialize mapping
Definition: subsurface.h:86
XmlElement toXml(bool share=false) const
XML output.
Definition: subsurface.cpp:37
Rectangular parametric region of another surface.
Definition: subsurface.h:26
SurfacePtr psf
surface to evaluate
Definition: subsurface.h:102
Vct3 derive(Real u, Real v, uint ku, uint kv) const
compute derivative
Definition: subsurface.h:45
Real umap(Real t) const
map u value
Definition: subsurface.h:94
Surface interface.
Definition: surface.h:37
SubSurface(const Surface &s, const BndRect &br)
construct from mapping
Definition: subsurface.cpp:17
void apply()
coordinate transformation cannot be performed
Definition: subsurface.h:66
Real uo
region limits
Definition: subsurface.h:105
void toGlobal(PointList< 2 > &pts) const
map local points to global coordinates
Definition: subsurface.cpp:65
Generated on Wed Jan 19 2022 03:03:15 for libsurf by   doxygen 1.8.5