31 os <<
"Trimmed surface with "<< nTrims()<<
" trim loop(s).\n";
32 os <<
"Master surface: "<< *m_surface <<
"\n";
33 os <<
"Domain: "<< *m_domain <<
"\n";
42 unsigned int ntcp = kv.
size() - kv.
degree() - 1;
49 DomCor << 0, 0, 1, 0, 1, 1, 0, 1, 0, 0;
50 for (
int ic=0; ic < 4; ic++)
54 for (
unsigned int i=0; i < ntcp; i++)
56 for (
unsigned int xi=0; xi < 2; xi++)
58 tcp(i,xi) = DomCor(ic,xi) + (T)(i) / ((T)(ntcp)-(T)(1)) * (DomCor(ic+1,xi)-DomCor(ic,xi));
72 this->m_domain = domain1;
73 this->m_surface = tp1;
79 std::vector< gsCurve<T>* > trimLoop = m_domain->outer().curves();
81 gsMatrix<T> CPside2 = (trimLoop[sourceID]->coefs());
83 AngleVertex << CPside2(0,0), CPside2(0,1);
84 return m_surface->jacobian(AngleVertex);
103 std::vector< gsCurve<T>* > trimLoop = m_domain->outer().curves();
105 gsMatrix<T> CPside2 = (trimLoop[sourceID]->coefs());
107 AngleVertex << CPside2(0,0), CPside2(0,1);
109 gsMatrix<T> targetCP = (trimLoop[targetID]->coefs());
111 TargetVertex << targetCP(0,0), targetCP(0,1);
113 gsMatrix<T> cuttingEdge = TargetVertex-AngleVertex;
116 gsMatrix<T> tangent_side1 = TangentCoefs_prev(sourceID);
117 gsMatrix<T> tangent_side2 = TangentCoefs_next(sourceID);
122 tangent_side1_space = corJacobian*tangent_side1;
123 tangent_side2_space = corJacobian*tangent_side2;
128 if (isCCWviewFromNormal==
false)
133 *angle1 = conditionedAngle<T>(cuttingEdge_space, tangent_side1_space, normal);
134 *angle2 = conditionedAngle<T>(tangent_side2_space, cuttingEdge_space, normal);
135 *angle = conditionedAngle<T>(tangent_side2_space, tangent_side1_space, normal);
141 assert( (loopNumber>=0) && (loopNumber < m_domain->numLoops()) );
143 gsMatrix<T> pts = m_domain->sampleLoop(loopNumber, npoints);
144 return m_surface->eval_into(pts, u);
148 void gsTrimSurface<T>::sampleCurve_into(
int loopNumber,
int curveNumber,
int npoints, gsMatrix<T> & u )
const
150 assert( (loopNumber>=0) && (loopNumber < m_domain->numLoops()) );
151 assert( (curveNumber>=0) && (curveNumber < m_domain->loop(loopNumber).size() ) );
153 gsMatrix<T> pts = m_domain->sampleCurve(loopNumber, curveNumber, npoints);
155 return m_surface->eval_into(pts, u);
163 gsMatrix<T> tangent_side1 = UnitTangentCoefs_prev(sourceID, corJacobian);
164 gsMatrix<T> tangent_side2 = UnitTangentCoefs_next(sourceID, corJacobian);
166 coefs(0) = tangent_side1(0) + tangent_side2(0);
167 coefs(1) = tangent_side1(1) + tangent_side2(1);
176 gsVector3d<T> tangent_side1 = UnitTangentCoefs_prev(sourceID, corJacobian);
177 gsVector3d<T> tangent_side2 = UnitTangentCoefs_next(sourceID, corJacobian);
179 coefs = TangentCoefs_bisect(sourceID);
180 return ( normal.dot( tangent_side1.cross( tangent_side2 ) ) >= 0 ) ? coefs: (-coefs).eval();
186 std::vector< gsCurve<T>* > trimLoop = m_domain->outer().curves();
187 int curveDeg = trimLoop[sourceID]->degree();
190 gsWarn<<
"gsTrimSurface: degree of trimming curve is less than 2, this will fail to work in most cases. The degree is set to 3 instead.\n";
195 gsMatrix<T> CPside2 = (trimLoop[sourceID]->coefs());
196 gsMatrix<T> targetCP = (trimLoop[targetID]->coefs());
214 preImage << kv[0],kv[kv.size()-1];
215 preNormal << kv[0],kv[kv.size()-1];
216 image.col(0) = CPside2.row(0);
217 image.col(1) = targetCP.row(0);
218 normal(0,0) = -tg1(1);
219 normal(1,0) = tg1(0);
220 normal(0,1) = -tg2(1);
221 normal(1,1) = tg2(0);
227 preImageApp << .5*kv[0]+.5*kv[kv.size()-1];
228 imageApp = .5*CPside2.row(0).transpose() + .5*targetCP.row(0).transpose();
231 return gsInterpolate(kv,preImage,image,preNormal,normal,preImageApp,imageApp,w_reg,w_app, pointResiduals, normalResiduals);
238 typename gsMesh<T>::uPtr msh = m_domain->toMesh(npoints);
242 for (
size_t i = 0; i!= msh->numVertices(); ++i)
244 m_surface->eval_into( msh->vertex(i).topRows(2), tmp );
245 msh->vertex(i).topRows(m_surface->geoDim() ) = tmp;
254 gsMatrix<T> tangent_side2 = TangentCoefs_next(sourceID);
255 gsMatrix<T> spatialTangent = tangent_side2(0)*corJacobian.col(0)+tangent_side2(1)*corJacobian.col(1);
256 tangent_side2 = tangent_side2*((T)(1)/spatialTangent.norm());
258 return tangent_side2;
264 gsMatrix<T> tangent_side1 = TangentCoefs_prev(sourceID);
265 gsMatrix<T> spatialTangent = tangent_side1(0)*corJacobian.col(0)+tangent_side1(1)*corJacobian.col(1);
266 tangent_side1 = tangent_side1*((T)(1)/spatialTangent.norm());
268 return tangent_side1;
274 std::vector< gsCurve<T>* > trimLoop = m_domain->outer().curves();
275 gsMatrix<T> CPside2 = (trimLoop[sourceID]->coefs());
277 tangent_side2 << CPside2(1,0)-CPside2(0,0),CPside2(1,1)-CPside2(0,1);
279 return tangent_side2;
285 std::vector< gsCurve<T>* > trimLoop = m_domain->outer().curves();
286 int priorToSource(0);
287 if ( sourceID>0 ) priorToSource = sourceID-1;
else priorToSource = trimLoop.size()-1;
288 gsMatrix<T> CPside1 = (trimLoop[priorToSource]->coefs());
289 int const nrow = CPside1.rows();
291 tangent_side1 << CPside1(nrow-2,0)-CPside1(nrow-1,0),CPside1(nrow-2,1)-CPside1(nrow-1,1);
292 return tangent_side1;
296 template <
typename T>
298 const int curveNumber,
300 const int nmbSegments)
const
302 const gsCurve<T>& curve = getCurve(loopNumber, curveNumber);
314 while (eps <
math::abs(length - newLength))
319 newLength = getLengthOfCurve(curve, params,
false);
338 m_surface->eval_into(curveResult, result);
342 template <
typename T>
346 const int quadPoints)
const
362 gaussRule.
mapTo(lower, upper, nodes, weights);
365 for (
int col = 0; col != nodes.cols(); col++)
368 param(0, 0) = nodes(0, col);
376 m_surface->jacobian_into(pointOnCurve, jacobian);
381 for (
int row = 0; row != derivative.rows(); row++)
383 value += derivative(row, 0) * derivative(row, 0);
386 value = math::sqrt(value);
387 length += weights(col) * value;
394 template <
typename T>
404 evalCurve_into(curve, params, points);
406 for (
int col = 0; col < points.cols() - 1; col++)
413 for (
int row = 0; row < p1.rows(); row++)
415 T tmp = (p1(row) - p2(row));
420 length += math::sqrt(dst);
425 for (
int col = 0; col != params.cols() - 1; col++)
427 const T a = params(0, col);
428 const T b = params(0, col + 1);
430 T arc = arcLength(curve, a, b);
440 template <
typename T>
442 const int curveNumber,
447 const gsCurve<T>& curve = getCurve(loopNumber, curveNumber);
456 parameters.resize(arcs.size());
460 T oldParam = supStart(0);
461 T newParam = oldParam;
464 for (
int p = 0; p != arcs.size(); p++)
466 const T arc = arcs(p);
472 newParam = par(0, parCounter);
475 T dst = arcLength(curve, oldParam, newParam);
478 if (parCounter == par.cols())
483 if (parCounter == par.cols() && p == arcs.size() - 1)
485 parameters(p) = supEnd(0);
489 if (parCounter == par.cols() && p != arcs.size() - 1)
491 GISMO_ERROR(
"This should not happen. Last arc is too long...\n");
500 parameters(p) = newParam;
505 T t = findParameter(curve,
506 arc, curArc, oldParam, newParam,
514 template <
typename T>
524 T arcLow = curArc - arcLength(curve, lowParam, uppParam);
531 midParam = lowParam + (uppParam - lowParam) / (T)(2);
534 T dst = arcLength(curve, midParam, uppParam);
536 if (arc == arcUpp - dst)
540 else if (arc < arcUpp - dst)
547 arcLow = arcUpp - dst;
552 midParam = lowParam + (uppParam - lowParam) / (T)(2);
Knot vector for B-splines.
A fixed-size, statically allocated 3D vector.
Definition: gsVector.h:218
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
A tensor product of d B-spline functions, with arbitrary target dimension.
Definition: gsTensorBSpline.h:44
T arcLength(const gsCurve< T > &curve, const T a, const T b, const int quadPoints=4) const
Definition: gsTrimSurface.hpp:343
S give(S &x)
Definition: gsMemory.h:266
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
size_t size() const
Number of knots (including repetitions).
Definition: gsKnotVector.h:242
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
void setNodes(gsVector< index_t > const &numNodes, unsigned digits=0)
Initialize quadrature rule with numNodes number of quadrature points per integration variable...
Definition: gsGaussRule.hpp:95
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
gsBSpline< T > gsInterpolate(gsKnotVector< T > &kv, const gsMatrix< T > &preImage, const gsMatrix< T > &image, const gsMatrix< T > &preNormal, const gsMatrix< T > &normal, const gsMatrix< T > &preImageApp, const gsMatrix< T > &imageApp, T const &w_reg, T const &w_app, gsMatrix< T > &outPointResiduals, gsMatrix< T > &outNormalResiduals)
Definition: gsModelingUtils.hpp:392
gsMatrix< T > derivatives(int sourceID) const
Definition: gsTrimSurface.hpp:77
#define gsWarn
Definition: gsDebug.h:50
virtual void deriv_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate derivatives of the function at points u into result.
Definition: gsGeometry.hpp:170
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
void fromArcsToParams(const int loopNumber, const int curveNumber, const gsVector< T > &arcs, gsVector< T > ¶meters, const T eps)
Definition: gsTrimSurface.hpp:441
Provides declaration of the Mesh class.
virtual void mapTo(const gsVector< T > &lower, const gsVector< T > &upper, gsMatrix< T > &nodes, gsVector< T > &weights) const
Maps quadrature rule (i.e., points and weights) from the reference domain to an element.
Definition: gsQuadRule.h:177
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
Represents a B-spline curve/function with one parameter.
Class representing a Planar domain with an outer boundary and a number of holes.
Definition: gsPlanarDomain.h:43
Utility functions required by gsModeling classes.
gsMatrix< T > support() const
Returns the range of parameters (same as parameterRange())
Definition: gsGeometry.hpp:193
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the function at points u into result.
Definition: gsGeometry.hpp:166
EIGEN_STRONG_INLINE grad_expr< E > grad(const E &u)
The gradient of a variable.
Definition: gsExpressions.h:4492
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
Class for representing a knot vector.
Definition: gsKnotVector.h:79
EIGEN_STRONG_INLINE abs_expr< E > abs(const E &u)
Absolute value.
Definition: gsExpressions.h:4488
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
Class that represents the (tensor) Gauss-Legendre quadrature rule.
Definition: gsGaussRule.h:27
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
int degree() const
Returns the degree of the knot vector.
Definition: gsKnotVector.hpp:700
memory::shared_ptr< gsTensorBSpline > Ptr
Shared pointer for gsTensorBSpline.
Definition: gsTensorBSpline.h:59
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...
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsTrimSurface.hpp:29