BRL-CAD
pullback.h
Go to the documentation of this file.
1 /* P U L L B A C K . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2024 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 /** @addtogroup brep_pullback
22  *
23  * @brief
24  * point pullback.
25  *
26  */
27 
28 #ifndef BREP_PULLBACK_H
29 #define BREP_PULLBACK_H
30 
31 #include "common.h"
32 #include "brep/defines.h"
33 #include "brep/surfacetree.h"
34 
35 /** @{ */
36 /** @file brep/pullback.h */
37 
38 #ifdef __cplusplus
39 
40 __BEGIN_DECLS
41 
42 extern "C++" {
43 
44 typedef struct pbc_data {
45  double tolerance;
46  double flatness;
47  const ON_Curve *curve;
48  const ON_Surface *surf;
50  std::list<ON_2dPointArray *> *segments;
51  const ON_BrepEdge *edge;
54 
55 extern BREP_EXPORT int IsAtSingularity(const ON_Surface *surf, double u, double v, double tol = 1e-6);
56 extern BREP_EXPORT int IsAtSingularity(const ON_Surface *surf, const ON_2dPoint &pt, double tol = 1e-6);
57 extern BREP_EXPORT int IsAtSeam(const ON_Surface *surf,int dir,double u, double v,double tol = 0.0);
58 extern BREP_EXPORT int IsAtSeam(const ON_Surface *surf,double u, double v,double tol = 0.0);
59 extern BREP_EXPORT int IsAtSeam(const ON_Surface *surf,int dir,const ON_2dPoint &pt,double tol = 0.0);
60 extern BREP_EXPORT int IsAtSeam(const ON_Surface *surf,const ON_2dPoint &pt,double tol = 0.0);
61 extern BREP_EXPORT ON_2dPoint UnwrapUVPoint(const ON_Surface *surf,const ON_2dPoint &pt,double tol = 0.0);
62 extern BREP_EXPORT double DistToNearestClosedSeam(const ON_Surface *surf,const ON_2dPoint &pt);
63 extern BREP_EXPORT void SwapUVSeamPoint(const ON_Surface *surf,ON_2dPoint &p, int hint = 3);
64 extern BREP_EXPORT void ForceToClosestSeam(const ON_Surface *surf,ON_2dPoint &pt,double tol= 0.0);
65 extern BREP_EXPORT bool Find3DCurveSeamCrossing(PBCData &data,double t0,double t1,double offset,double &seam_t,ON_2dPoint &from,ON_2dPoint &to,double tol = 0.0, double same_point_tol=BREP_SAME_POINT_TOLERANCE,double within_distance_tol = BREP_EDGE_MISS_TOLERANCE);
66 extern BREP_EXPORT bool FindTrimSeamCrossing(const ON_BrepTrim &trim,double t0,double t1,double &seam_t,ON_2dPoint &from,ON_2dPoint &to,double tol = 0.0);
67 extern BREP_EXPORT bool surface_GetClosestPoint3dFirstOrder(const ON_Surface *surf,const ON_3dPoint& p,ON_2dPoint& p2d,ON_3dPoint& p3d,double &current_distance,int quadrant = 0,double same_point_tol=BREP_SAME_POINT_TOLERANCE,double within_distance_tol=BREP_EDGE_MISS_TOLERANCE);
68 extern BREP_EXPORT bool trim_GetClosestPoint3dFirstOrder(const ON_BrepTrim& trim,const ON_3dPoint& p,ON_2dPoint& p2d,double& t,double& distance,const ON_Interval* interval,double same_point_tol=BREP_SAME_POINT_TOLERANCE,double within_distance_tol=BREP_EDGE_MISS_TOLERANCE);
69 extern BREP_EXPORT bool ConsecutivePointsCrossClosedSeam(const ON_Surface *surf,const ON_2dPoint &pt,const ON_2dPoint &prev_pt, int &udir, int &vdir,double tol = 1e-6);
70 
71 extern BREP_EXPORT PBCData *pullback_samples(const ON_Surface *surf,const ON_Curve *curve,double tolerance = 1.0e-6,double flatness = 1.0e-3,double same_point_tol=BREP_SAME_POINT_TOLERANCE,double within_distance_tol=BREP_EDGE_MISS_TOLERANCE);
72 
73 extern BREP_EXPORT bool check_pullback_data(std::list<PBCData *> &pbcs);
74 
75 extern BREP_EXPORT int
76 check_pullback_singularity_bridge(const ON_Surface *surf, const ON_2dPoint &p1, const ON_2dPoint &p2);
77 
78 namespace brlcad {
79 
80  /**
81  * approach:
82  *
83  * - get an estimate using the surface tree (if non-null, create
84  * one otherwise)
85  *
86  * - find a point (u, v) for which S(u, v) is closest to _point_
87  * _ __
88  * -- minimize the distance function: D(u, v) = sqrt(|S(u, v)-pt|^2)
89  * _ __
90  * -- simplify by minimizing f(u, v) = |S(u, v)-pt|^2
91  *
92  * -- minimum occurs when the gradient is zero, i.e.
93  * \f[ \nabla f(u, v) = |\vec{S}(u, v)-\vec{p}|^2 = 0 \f]
94  */
95  BREP_EXPORT bool get_closest_point(ON_2dPoint& outpt,
96  const ON_BrepFace& face,
97  const ON_3dPoint& point,
98  const SurfaceTree* tree = NULL,
99  double tolerance = BREP_FCP_ROOT_EPSILON);
100 
101  /**
102  * Pull an arbitrary model-space *curve* onto the given *surface* as a
103  * curve within the surface's domain when, for each point c = C(t) on
104  * the curve and the closest point s = S(u, v) on the surface, we
105  * have: distance(c, s) <= *tolerance*.
106  *
107  * The resulting 2-dimensional curve will be approximated using the
108  * following process:
109  *
110  * 1. Adaptively sample the 3d curve in the domain of the surface
111  * (ensure tolerance constraint). Sampling terminates when the
112  * following flatness criterion is met:
113  *
114  * given two parameters on the curve t1 and t2 (which map to points p1
115  * and p2 on the curve) let m be a parameter randomly chosen near the
116  * middle of the interval [t1, t2] ____ then the curve between t1 and
117  * t2 is flat if distance(C(m), p1p2) < flatness
118  *
119  * 2. Use the sampled points to perform a global interpolation using
120  * universal knot generation to build a B-Spline curve.
121  *
122  * 3. If the curve is a line or an arc (determined with openNURBS
123  * routines), return the appropriate ON_Curve subclass (otherwise,
124  * return an ON_NurbsCurve).
125  */
126  extern ON_Curve *pullback_curve(ON_BrepFace *face,
127  const ON_Curve *curve,
128  SurfaceTree *tree = NULL,
129  double tolerance = BREP_FCP_ROOT_EPSILON,
130  double flatness = 1.0e-3);
131 } /* end namespace brlcad */
132 
133 
134 bool
136  double *t,
137  ON_3dPoint *cp,
138  const ON_NurbsCurve *nc,
139  const ON_3dPoint &p,
140  double maximum_distance = 0.0,
141  const ON_Interval *sub_domain = NULL
142  );
143 
144 
145 bool
147  double *t,
148  const ON_BrepTrim *trim,
149  const ON_3dPoint &p,
150  double maximum_distance = 0.0,
151  const ON_Interval *sub_domain = NULL
152  );
153 
154 extern BREP_EXPORT bool
156  double *dist,
157  double *t,
158  const ON_NurbsCurve *nc,
159  const ON_Line &l,
160  double maximum_distance = 0.0,
161  const ON_Interval *subdomain = NULL
162  );
163 
164 } /* extern C++ */
165 
166 __END_DECLS
167 
168 #endif
169 
170 /** @} */
171 
172 #endif /* BREP_PULLBACK_H */
173 
174 /*
175  * Local Variables:
176  * mode: C
177  * tab-width: 8
178  * indent-tabs-mode: t
179  * c-file-style: "stroustrup"
180  * End:
181  * ex: shiftwidth=4 tabstop=8
182  */
Header file for the BRL-CAD common definitions.
#define BREP_SAME_POINT_TOLERANCE
Definition: defines.h:171
#define BREP_EDGE_MISS_TOLERANCE
Definition: defines.h:169
#define BREP_FCP_ROOT_EPSILON
Definition: defines.h:147
double DistToNearestClosedSeam(const ON_Surface *surf, const ON_2dPoint &pt)
void SwapUVSeamPoint(const ON_Surface *surf, ON_2dPoint &p, int hint=3)
bool ON_NurbsCurve_GetClosestPoint(double *t, ON_3dPoint *cp, const ON_NurbsCurve *nc, const ON_3dPoint &p, double maximum_distance=0.0, const ON_Interval *sub_domain=NULL)
bool ConsecutivePointsCrossClosedSeam(const ON_Surface *surf, const ON_2dPoint &pt, const ON_2dPoint &prev_pt, int &udir, int &vdir, double tol=1e-6)
bool Find3DCurveSeamCrossing(PBCData &data, double t0, double t1, double offset, double &seam_t, ON_2dPoint &from, ON_2dPoint &to, double tol=0.0, double same_point_tol=BREP_SAME_POINT_TOLERANCE, double within_distance_tol=BREP_EDGE_MISS_TOLERANCE)
int check_pullback_singularity_bridge(const ON_Surface *surf, const ON_2dPoint &p1, const ON_2dPoint &p2)
ON_2dPoint UnwrapUVPoint(const ON_Surface *surf, const ON_2dPoint &pt, double tol=0.0)
int IsAtSingularity(const ON_Surface *surf, double u, double v, double tol=1e-6)
int IsAtSeam(const ON_Surface *surf, int dir, double u, double v, double tol=0.0)
bool FindTrimSeamCrossing(const ON_BrepTrim &trim, double t0, double t1, double &seam_t, ON_2dPoint &from, ON_2dPoint &to, double tol=0.0)
bool trim_GetClosestPoint3dFirstOrder(const ON_BrepTrim &trim, const ON_3dPoint &p, ON_2dPoint &p2d, double &t, double &distance, const ON_Interval *interval, double same_point_tol=BREP_SAME_POINT_TOLERANCE, double within_distance_tol=BREP_EDGE_MISS_TOLERANCE)
bool ON_NurbsCurve_ClosestPointToLineSegment(double *dist, double *t, const ON_NurbsCurve *nc, const ON_Line &l, double maximum_distance=0.0, const ON_Interval *subdomain=NULL)
struct pbc_data PBCData
bool check_pullback_data(std::list< PBCData * > &pbcs)
bool surface_GetClosestPoint3dFirstOrder(const ON_Surface *surf, const ON_3dPoint &p, ON_2dPoint &p2d, ON_3dPoint &p3d, double &current_distance, int quadrant=0, double same_point_tol=BREP_SAME_POINT_TOLERANCE, double within_distance_tol=BREP_EDGE_MISS_TOLERANCE)
void ForceToClosestSeam(const ON_Surface *surf, ON_2dPoint &pt, double tol=0.0)
bool ON_TrimCurve_GetClosestPoint(double *t, const ON_BrepTrim *trim, const ON_3dPoint &p, double maximum_distance=0.0, const ON_Interval *sub_domain=NULL)
PBCData * pullback_samples(const ON_Surface *surf, const ON_Curve *curve, double tolerance=1.0e-6, double flatness=1.0e-3, double same_point_tol=BREP_SAME_POINT_TOLERANCE, double within_distance_tol=BREP_EDGE_MISS_TOLERANCE)
void float float int int int int * interval
Definition: tig.h:131
Definition: bbnode.h:42
ON_Curve * pullback_curve(ON_BrepFace *face, const ON_Curve *curve, SurfaceTree *tree=NULL, double tolerance=BREP_FCP_ROOT_EPSILON, double flatness=1.0e-3)
bool get_closest_point(ON_2dPoint &outpt, const ON_BrepFace &face, const ON_3dPoint &point, const SurfaceTree *tree=NULL, double tolerance=BREP_FCP_ROOT_EPSILON)
NMG topological face.
Definition: topology.h:210
const ON_BrepEdge * edge
Definition: pullback.h:51
std::list< ON_2dPointArray * > * segments
Definition: pullback.h:50
const ON_Surface * surf
Definition: pullback.h:48
bool order_reversed
Definition: pullback.h:52
double tolerance
Definition: pullback.h:45
const ON_Curve * curve
Definition: pullback.h:47
double flatness
Definition: pullback.h:46
brlcad::SurfaceTree * surftree
Definition: pullback.h:49
Definition: tree.h:148