38 typedef memory::shared_ptr<gsTrimSurface> Ptr;
39 typedef memory::unique_ptr<gsTrimSurface> uPtr;
46 : m_surface(g), m_domain(d)
54 gsTrimSurface(gsMatrix<T>
const & corner,
int patchDeg1,
int patchDeg2,
int curveDeg);
58 m_surface = other.m_surface;
59 m_domain = other.m_domain->clone().release();
64 m_surface = other.m_surface;
66 m_domain = other.m_domain->clone().release();
81 std::ostream &
print(std::ostream &os)
const;
83 friend std::ostream& operator<< (std::ostream& os,
const gsTrimSurface& ts)
84 {
return ts.
print(os); }
86 gsBasis<T> & basis()
const {
return m_surface->basis(); }
88 short_t geoDim()
const {
return m_surface->geoDim(); }
92 typename gsSurface<T>::Ptr getTP()
const {
return m_surface; }
94 int nTrims()
const {
return m_domain->numLoops(); }
105 return m_domain->curve(loopNumber, curveNumber);
108 void sampleLoop_into(
int loopNumber,
int npoints,
gsMatrix<T> & u)
const;
110 gsMatrix<T> sampleLoop(
int loopNumber,
int npoints = 100)
const
113 sampleLoop_into(loopNumber, npoints, u);
117 gsMatrix<T> sampleBoundary(
int npoints = 100)
const
118 {
return sampleLoop(0, npoints); }
120 void sampleCurve_into(
int loopNumber,
int curveNumber,
int npoints, gsMatrix<T> & u)
const;
122 gsMatrix<T> sampleCurve(
int loopNumber,
int curveNumber,
int npoints = 100)
const
125 sampleCurve_into(loopNumber, curveNumber, npoints, u);
138 GISMO_ASSERT(0 <= loopNumber && loopNumber < m_domain->numLoops(),
139 "Loop number is out of range!");
141 curveNumber < m_domain->loop(loopNumber).size(),
142 "Curve number is out of range!");
158 gsMatrix<T> sampleBoundaryCurve(
unsigned curveNumber,
int npoints = 100)
const
159 {
return sampleCurve(0, curveNumber, npoints); }
171 m_surface->eval_into(u, result);
188 const gsPlanarDomain<T> & domain()
const {
return *m_domain; }
195 {
return m_domain->splitCurve(loopId,curveId,lengthRatio);}
205 void cuttingAngles(
int const & sourceID,
int const & targetID,T* angle, T* angle1, T* angle2,
bool const & isCCWviewFromNormal=
true)
const;
218 memory::unique_ptr<gsMesh<T> >
toMesh(
int npoints = 50)
const;
232 gsMatrix<T> vertexCoord(
int const & loopID,
int const & curveID)
const
234 gsMatrix<T> cp = m_domain->curve(loopID,curveID).coefs();
237 vert << cp(0,0), cp(0,1);
238 (*m_surface).eval_into(vert,vert3D);
246 gsMatrix<T,3> res = Jacobian.col(0).cross(Jacobian.col(1)).normalized();
253 assert( (loopNumber>=0) && (loopNumber < m_domain->numLoops()) );
254 assert( (curveNumber>=0) && (curveNumber < m_domain->loop(loopNumber).size() ) );
259 gsMatrix<T> pts = m_domain->sampleCurve(loopNumber, curveNumber, npoints);
262 for (
size_t i=0; i < npoints; i++)
273 gsMatrix<T> interval = m_domain->curve(loopN,curveN).parameterRange();
276 gsMatrix<T> trimCur = m_domain->curve(loopN,curveN).eval(tval);
277 gsMatrix<T> trimCurDev = m_domain->curve(loopN,curveN).jacobian(tval);
278 gsMatrix<T> trimCurJac = m_surface->jacobian( trimCur );
282 for (
size_t i=0; i<=npoints-1; i++)
284 tangents.col(i) = trimCurJac.middleCols( 2*i,2 )*trimCurDev.col(i);
290 void cleanEndpoints(T eps)
294 size_t n = domain().loop(0).curves().size();
295 for(
size_t i = 0; i < n; i++)
297 gsCurve<T> &thisCurve = domain().loop(0).curve(i);
298 for(
size_t dim = 0; dim < 2; dim++)
301 GISMO_ASSERT(coefs(0, dim) >= supp(dim, 0) - eps,
"invalid curve endpoint");
302 coefs(0, dim) = std::max(coefs(0, dim), supp(dim, 0));
303 GISMO_ASSERT(coefs(coefs.rows() - 1, dim) <= supp(dim, 1) + eps,
"invalid curve endpoint");
304 coefs(coefs.rows() - 1, dim) = std::min(coefs(coefs.rows() - 1, dim), supp(dim, 1));
312 GISMO_ASSERT(spacePoint.rows() == 3 && spacePoint.cols() == 1,
"Invalid dimensions");
313 const gsCurve<T> & c = m_domain->curve(loopNumber, curveNumber);
315 gsVector<T> start = supp.col(0), end = supp.col(1);
317 gsMatrix<T> curveVal, curveDeriv, curveDeriv2, surfVal, surfDeriv, surfDeriv2;
318 T closestParam(10e100), closestSqDist(10e100);
320 for(
int idxTrial = 0; idxTrial < nTrialPoints; idxTrial++)
329 for(
int iteration = 0; iteration < nIterations; iteration++)
331 c.eval_into(u, curveVal);
332 c.jacobian_into(u, curveDeriv);
333 c.deriv2_into(u, curveDeriv2);
335 m_surface->eval_into(curveVal, surfVal);
336 m_surface->jacobian_into(curveVal, surfDeriv);
337 m_surface->deriv2_into(curveVal, surfDeriv2);
340 gsMatrix<T> sqDistDeriv = -2 * (spacePoint - surfVal).transpose() *
341 surfDeriv * curveDeriv;
342 GISMO_ASSERT(sqDistDeriv.rows() == 1 && sqDistDeriv.cols() == 1,
"Derivative should be 1x1");
349 for(
int idxJ = 0; idxJ < 3; idxJ++)
351 termFromSurfaceCurvature(idxJ, 0) = surfDeriv2(idxJ * 3) * curveDeriv(0, 0) * curveDeriv(0, 0) +
352 surfDeriv2(idxJ * 3 + 1) * curveDeriv(1, 0) * curveDeriv(1, 0) +
353 (T)(2) * surfDeriv2(idxJ * 3 + 2) * curveDeriv(0, 0) * curveDeriv(1, 0);
355 gsMatrix<T> sqDistDeriv2Term1 = (surfDeriv * curveDeriv).transpose();
356 sqDistDeriv2Term1 *= (surfDeriv * curveDeriv);
357 gsMatrix<T> sqDistDeriv2Term2 = (spacePoint - surfVal).transpose() * (termFromSurfaceCurvature + surfDeriv * curveDeriv2);
358 gsMatrix<T> sqDistDeriv2 = 2 * (sqDistDeriv2Term1 - sqDistDeriv2Term2);
359 GISMO_ASSERT(sqDistDeriv2.rows() == 1 && sqDistDeriv2.cols() == 1,
"Second derivative should be 1x1");
361 u -= sqDistDeriv / sqDistDeriv2(0, 0);
362 u(0, 0) = (u(0, 0) < supp(0, 0))? supp(0, 0): ((u(0, 0) > supp(0, 1)? supp(0, 1): u(0, 0)));
365 c.eval_into(u, curveVal);
366 m_surface->eval_into(curveVal, surfVal);
367 T sqDist = (spacePoint - surfVal).squaredNorm();
368 if(idxTrial == 0 || sqDist < closestSqDist)
370 closestParam = u(0, 0);
371 closestSqDist = sqDist;
379 const int curveNumber,
381 const int nmbSegments = 50)
const;
393 const int curveNumber,
402 for (
int pt = 0; pt != nmbParams; pt++)
404 arcs(pt) = length * (pt * 1.0 / (nmbParams - 1));
429 const int quadPoints = 4)
const;
441 bool linear =
false)
const;
456 const int curveNumber,
489 #ifndef GISMO_BUILD_LIB
490 #include GISMO_HPP_HEADER(gsTrimSurface.hpp)
A fixed-size, statically allocated 3D vector.
Definition: gsVector.h:218
gsCurve< T > & getCurve(int loopNumber, int curveNumber) const
Returns curveNumber-th curve in loopNumber-th loop.
Definition: gsTrimSurface.h:103
Class for a trim surface.
Definition: gsTrimSurface.h:33
Abstract base class representing a curve.
Definition: gsCurve.h:30
#define short_t
Definition: gsConfig.h:35
gsMatrix< T > evalSurface(const gsMatrix< T > &u) const
Definition: gsTrimSurface.h:179
T arcLength(const gsCurve< T > &curve, const T a, const T b, const int quadPoints=4) const
Definition: gsTrimSurface.hpp:343
Provides declaration of Surface abstract interface.
gsMatrix< T > TangentCoefs_prev(int const &sourceID) const
Return the coefficients of the representation of the unit tangent of the edge COMING to vertex source...
Definition: gsTrimSurface.hpp:283
gsMatrix< T > TangentCoefs_next(int const &sourceID) const
Return the coefficients of the representation of the unit tangent of the edge ENAMATING from vertex s...
Definition: gsTrimSurface.hpp:272
gsTrimSurface(typename gsSurface< T >::Ptr g, gsPlanarDomain< T > *d)
Constructor by a shared pointer.
Definition: gsTrimSurface.h:45
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
memory::unique_ptr< gsMesh< T > > toMesh(int npoints=50) const
Return a triangulation of the trimmed surface.
Definition: gsTrimSurface.hpp:236
gsMatrix< T > uniformPointGrid(const gsVector< T > &lower, const gsVector< T > &upper, int numPoints=1000)
Definition: gsPointGrid.hpp:94
gsVector3d< T > cornerNormal(int const &sourceID) const
Compute the surface normal at a corner.
Definition: gsTrimSurface.hpp:89
A B-spline function of one argument, with arbitrary target dimension.
Definition: gsBSpline.h:50
gsMatrix< T > trimCurTangents(int loopN, int curveN, size_t npoints) const
Return the tangent vectors of the trimming curve curveNumber in trimming loop loopNumber.
Definition: gsTrimSurface.h:271
gsMatrix< T > derivatives(int sourceID) const
Definition: gsTrimSurface.hpp:77
gsMatrix< T > sampleNormal(int loopNumber, int curveNumber, size_t npoints) const
sample standard unit normals along a trimming curve
Definition: gsTrimSurface.h:251
gsBSpline< T > cuttingCurve(int const &sourceID, int const &targetID) const
Define a spline curve connecting source-target
Definition: gsTrimSurface.hpp:184
gsMatrix< T > UnitTangentCoefs_prev(int const &sourceID, gsMatrix< T > const &corJacobian) const
Return the coefficients of the representation of the unit tangent of the edge COMING to vertex source...
Definition: gsTrimSurface.hpp:262
T getLengthOfCurve(const int loopNumber, const int curveNumber, const T eps=1e-6, const int nmbSegments=50) const
Computes length of curveNumber-th curve in loopNumber-th loop.
Definition: gsTrimSurface.hpp:297
gsMatrix< T > gsPointGrid(gsVector< T > const &a, gsVector< T > const &b, gsVector< unsigned > const &np)
Construct a Cartesian grid of uniform points in a hypercube, using np[i] points in direction i...
Definition: gsPointGrid.hpp:82
gsTrimSurface< T > * clone() const
Clone function. Used to make a copy of the (derived) geometry.
Definition: gsTrimSurface.h:78
gsCurveLoop< T > & boundaryLoop()
Get a boundary curve loop.
Definition: gsTrimSurface.h:97
void fromArcsToParams(const int loopNumber, const int curveNumber, const gsVector< T > &arcs, gsVector< T > ¶meters, const T eps)
Definition: gsTrimSurface.hpp:441
void evalCurve_into(int loopNumber, int curveNumber, const gsMatrix< T > &u, gsMatrix< T > &result) const
Definition: gsTrimSurface.h:133
void cuttingAngles(int const &sourceID, int const &targetID, T *angle, T *angle1, T *angle2, bool const &isCCWviewFromNormal=true) const
Compute angle discrepancy between the angles defined by the edge source-target with the sides of the ...
Definition: gsTrimSurface.hpp:101
const gsCurveLoop< T > & boundaryLoop() const
Look at (non-const) boundaryLoop.
Definition: gsTrimSurface.h:100
Abstract base class representing a surface.
Definition: gsSurface.h:30
Class representing a Planar domain with an outer boundary and a number of holes.
Definition: gsPlanarDomain.h:43
gsMatrix< T > unitNormal(gsMatrix< T > point) const
Compute the unit normal vector of the trimmed surface at a point in the parameter domain...
Definition: gsTrimSurface.h:243
memory::shared_ptr< gsSurface > Ptr
Shared pointer for gsSurface.
Definition: gsSurface.h:35
gsMatrix< T > splitCurve(size_t loopId, size_t curveId, T lengthRatio=.5)
Definition: gsTrimSurface.h:194
T nearestPoint(int loopNumber, int curveNumber, int nTrialPoints, int nIterations, const gsMatrix< T > &spacePoint)
find the parameter of the nearest point on a curve to a given point in space
Definition: gsTrimSurface.h:310
#define GISMO_UNUSED(x)
Definition: gsDebug.h:112
Provides functions to generate structured point data.
void evalSurface_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Definition: gsTrimSurface.h:168
gsTrimSurface()
Default empty constructor.
Definition: gsTrimSurface.h:42
gsVector< T > TangentCoefs_bisect(int const &sourceID) const
Compute the (scale of) tangent of the curve emanateing from a vertex in the parameter whose image bis...
Definition: gsTrimSurface.hpp:160
A closed loop given by a collection of curves.
Definition: gsCurveLoop.h:36
void getPhysicalyUniformCurveParameters(const int loopNumber, const int curveNumber, const int nmbParams, gsVector< T > ¶meters, const T eps=1e-6)
Definition: gsTrimSurface.h:392
gsMatrix< T > UnitTangentCoefs_next(int const &sourceID, gsMatrix< T > const &corJacobian) const
Return the coefficients of the representation of the unit tangent of the edge ENAMATING from vertex s...
Definition: gsTrimSurface.hpp:252
gsMatrix< T > evalCurve(int loopNumber, int curveNumber, const gsMatrix< T > &u) const
Look at evalCurve_into.
Definition: gsTrimSurface.h:149
T findParameter(const gsCurve< T > &curve, const T arc, T curArc, T lowParam, T uppParam, const T eps)
Definition: gsTrimSurface.hpp:515
Provides declaration of gsPlanarDomain class. The outer boundary (m_loops[0]) is a loop of curves...
gsMatrix< T > & coefs()
Definition: gsGeometry.h:340
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsTrimSurface.hpp:29