24 #include <eiquadprog.hpp>
83 typedef memory::shared_ptr< gsTemplate >
Ptr;
93 GISMO_ASSERT(i<=2 ,
"Template with more than one hole not implemented yet.");
104 m_pdomain.outer().reverse();
128 addSkeleton( gsNurbsCreator<T>::BSplineLineSegment(xi.col(0),-0.534694*xi.col(0)+0*xi.col(1)).
release() );
129 addSkeleton( gsNurbsCreator<T>::BSplineLineSegment(xi.col(1),-0.534694*xi.col(0)+0*xi.col(1)).
release() );
130 addSkeleton( gsNurbsCreator<T>::BSplineLineSegment(xi.col(2),-0.534694*xi.col(0)+0*xi.col(1)).
release() );
131 addSkeleton( gsNurbsCreator<T>::BSplineLineSegment(xi.col(3),-0.534694*xi.col(0)+0*xi.col(1)).
release() );
140 addSkeleton( gsNurbsCreator<T>::BSplineLineSegment(xi.col(0)*(0.25) +
141 xi.col(1)*(0.732),(0.25)*xi.col(0)+xi.col(1)*(0.55)).
release());
151 gsKnotVector<T> kk(0,1,2,3,1,2);
152 gsBSpline<T> *Trick2 =
new gsBSpline<T>(kk,cc);
156 addSkeleton( gsNurbsCreator<T>::BSplineLineSegment(xi.col(0)*(0.25) +
157 xi.col(1)*(0.363),( 0.25)*xi.col(0)+xi.col(1)*(0.55)).
release());
159 addSkeleton( gsNurbsCreator<T>::BSplineLineSegment(xi.col(0)*(0.064) +
160 xi.col(1)*(0.55),( 0.25)*xi.col(0)+xi.col(1)*(0.55)).
release());
164 gsMatrix<T> coeff(3,2);
165 coeff<<-0.583, 0.876,
168 gsKnotVector<T> kv(0,1,0,3,2);
169 gsBSpline<T> * ArcUpLeft =
new gsBSpline<T>(kv,coeff);
170 addSkeleton(ArcUpLeft);
176 gsBSpline<T> * ArcCenterLeft =
new gsBSpline<T>(kv, coeff);
177 addSkeleton(ArcCenterLeft);
183 gsBSpline<T> * ArcCenterRight =
new gsBSpline<T>(kv,coeff);
184 addSkeleton(ArcCenterRight);
193 gsBSpline<T> *CentralArc =
new gsBSpline<T>(kv,coeff);
194 addSkeleton(CentralArc);
197 addSkeleton( gsNurbsCreator<T>::BSplineLineSegment(xi.col(0)*(0.25) +
198 xi.col(1)*(0.986),( 0.25)*xi.col(0)+xi.col(1)*(0.732)).
release());
205 gsBSpline<T> * ArcUpRight =
new gsBSpline<T>(kv,coeff);
206 addSkeleton(ArcUpRight);
211 addSkeleton( gsNurbsCreator<T>::BSplineLineSegment(xi.col(0)*(0.10) +
212 xi.col(1)*(-0.366),(0.10)*xi.col(0)+xi.col(1)*(-0.55)).
release());
214 addSkeleton( gsNurbsCreator<T>::BSplineLineSegment(xi.col(0)*(0.288) +
215 xi.col(1)*(-0.55),(0.10)*xi.col(0)+xi.col(1)*(-0.55)).
release());
218 addSkeleton( gsNurbsCreator<T>::BSplineLineSegment(xi.col(0)*(0.10) +
219 xi.col(1)*(-0.993),(0.10)*xi.col(0)+xi.col(1)*(-0.55)).
release());
221 addSkeleton( gsNurbsCreator<T>::BSplineLineSegment(xi.col(0)*(-0.078) +
222 xi.col(1)*(-0.55),(0.10)*xi.col(0)+xi.col(1)*(-0.55)).
release());
225 coeff<< -0.638,-0.837,
228 gsBSpline<T> * ArcLowLeft =
new gsBSpline<T>(kv,coeff);
229 addSkeleton(ArcLowLeft);
232 addSkeleton( gsNurbsCreator<T>::BSplineLineSegment(xi.col(0)*(0.10) +
233 xi.col(1)*(-0.990),(0.10)*xi.col(0)+xi.col(1)*(-0.718)).
release());
238 coeff<<0.690, -0.824,
241 gsBSpline<T>* ArcLowRight =
new gsBSpline<T>(kv,coeff);
242 addSkeleton(ArcLowRight);
250 gsBSpline<T> * Archetto1 =
new gsBSpline<T> (kv,coeff);
251 addSkeleton(Archetto1);
257 gsBSpline<T> * Archetto2 =
new gsBSpline<T>(kv,coeff);
258 addSkeleton(Archetto2);
264 gsBSpline<T>* Archetto3 =
new gsBSpline<T>(kv,coeff);
265 addSkeleton(Archetto3);
271 gsBSpline<T>* Archetto4 =
new gsBSpline<T>(kv,coeff);
272 addSkeleton(Archetto4);
280 gsBSpline<T>* Archetto5 =
new gsBSpline<T>(kv,coeff);
281 addSkeleton(Archetto5);
284 coeff<< 0.288, -0.55,
287 gsBSpline<T>* Archetto6 =
new gsBSpline<T>(kv,coeff);
288 addSkeleton(Archetto6);
294 gsBSpline<T>* Archetto7 =
new gsBSpline<T>(kv,coeff);
295 addSkeleton(Archetto7);
299 coeff<< -0.078, -0.55,
302 gsBSpline<T> *Archetto8 =
new gsBSpline<T>(kv, coeff);
303 addSkeleton(Archetto8);
341 gsWarn<<
"Empty template.\n";
377 gsMatrix<T> uniformPoints = gsPointGrid<T>(0,1,102);
378 int numCols = uniformPoints.cols();
380 gsMatrix<T>storage0(2, numCols),storage1(2,numCols),storage2(2,numCols),storage3(2,numCols);
382 storage0.row(0)=uniformPoints.row(0);
385 storage1.row(0)=uniformPoints.row(0);
388 storage2.row(1)=uniformPoints.row(0);
391 storage3.row(1)=uniformPoints.row(0);
396 for(
int i=1; i<storage0.cols()-1;++i)
403 std::vector< gsCurve<T> *> BoundaryCurves;
404 BoundaryCurves.push_back(boundaryB);
405 BoundaryCurves.push_back(boundaryR);
406 BoundaryCurves.push_back(boundaryU);
407 BoundaryCurves.push_back(boundaryL);
436 tcp << verts(i, 0), verts(i, 1), verts((i + 1) % n, 0), verts((i + 1) % n, 1);
438 loop->insertCurve(tcurve);
441 m_pdomain.insertHole(loop);
449 gsMatrix<T> Tang1i = (verts.row((startIdx + n - 1) % n) - startPoint).normalized();
450 gsMatrix<T> Tang1o = (verts.row((startIdx + 1) % n) - startPoint).normalized();
451 gsMatrix<T> Tang2i = (verts.row((endIdx + n - 1) % n) - endPoint).normalized();
452 gsMatrix<T> Tang2o = (verts.row((endIdx + 1) % n) - endPoint).normalized();
456 normals.col(0) = startNormal.transpose();
457 normals.col(1) = endNormal.transpose();
461 constraints.setZero();
462 constraints.block(0, 0, 2, 2).setIdentity();
463 constraints.block(2, 6, 2, 2).setIdentity();
464 constraints.block(4, 0, 1, 2) = - startNormal;
465 constraints.block(4, 2, 1, 2) = startNormal;
466 constraints.block(5, 4, 1, 2) = - endNormal;
467 constraints.block(5, 6, 1, 2) = endNormal;
470 constraintsRHS.segment(0, 2) = startPoint.transpose();
471 constraintsRHS.segment(2, 2) = endPoint.transpose();
472 constraintsRHS.segment(4, 2).setZero();
478 inequalities.setZero();
482 for(
int idxE = 0; idxE < n; idxE++)
484 gsMatrix<T> edgeDiff = verts.row((idxE + 1) % n) - verts.row(idxE);
485 for(
int idxCP = 0; idxCP < 4; idxCP++)
487 inequalities.block(idxE * 4 + idxCP, 2 * idxCP, 1, 2) << -edgeDiff(0, 1), edgeDiff(0, 0);
488 ineqRHS(idxE * 4 + idxCP) = -edgeDiff(0, 1) * verts(idxE, 0) + edgeDiff(0, 0) * verts(idxE, 1);
494 secondDifference.setZero();
495 for(
size_t i = 0; i < 4; i++)
497 secondDifference(i, i) = 1;
498 secondDifference(i, i + 2) = -2;
499 secondDifference(i, i + 4) = 1;
504 costFromSec.setIdentity();
505 costFromSec(0, 2) = costFromSec(1, 3) = costFromSec(2, 0) = costFromSec(3, 1) = 0.5;
508 gsMatrix<T> totalCost = secondDifference.transpose() * costFromSec * secondDifference;
514 constraints.transposeInPlace();
515 inequalities.transposeInPlace();
517 constraintsRHS *= -1;
520 solve_quadprog(totalCost, zeroCost,
521 constraints , constraintsRHS,
522 inequalities, ineqRHS,
525 for(
size_t i = 0; i < 4; i++)
527 imageCoefs.col(i) = imageCoefsConcat.segment(2 * i, 2);
529 GISMO_ASSERT((imageCoefs.col(0) - startPoint.transpose()).norm() < 0.0001 &&
530 (imageCoefs.col(imageCoefs.cols() - 1) - endPoint.transpose()).norm() < 0.0001,
531 "Quadratic optimization failed to satisfy constraints");
536 g << 1,-3,3,-1,0,3,-6,3,0,0,3,-3,0,0,0,1;
538 T k0 = (T(1) - curveProportion) / 2;
539 T k1 = curveProportion;
547 k(i, j) = k0 * k(i - 1, j);
548 if(j > 0) k(i, j) += k1 * k(i - 1, j - 1);
552 gsMatrix<T> transformedCoefs = imageCoefs * g * k * g.inverse();
558 transformedCoefs.transposeInPlace();
576 std::ostream &
print(std::ostream &os)
const
578 if ( this->size() > 0 )
580 os <<
"gsTemplate (" << this->size() <<
").\n";
584 os <<
"gsTemplate ( empty! ).\n";
598 void addSkeleton( gsBSpline<T> * bs )
600 m_skeleton.push_back( bs );
603 std::vector< gsBSpline<T> * > skeleton()
608 gsBSpline<T> * skeleton(
size_t const & i)
610 return m_skeleton[i];
614 gsPlanarDomain<T>
const & domain()
const
619 const gsCurveLoop<T> & outer()
621 return m_pdomain.outer();
624 const gsCurveLoop<T> & loop(
int i)
const
626 return m_pdomain.loop(i);
631 return m_skeleton.size();
639 std::vector< gsBSpline<T> * > m_skeleton;
648 # define Eigen gsEigen
649 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
656 std::ostream &operator<<(std::ostream &os, const gsTemplate<T>& b)
657 {
return b.print(os); }
Class gsNurbsCreator provides some simple examples of Nurbs Geometries.
Definition: gsNurbsCreator.h:36
std::vector< T * > release(std::vector< unique_ptr< T > > &cont)
Takes a vector of smart pointers, releases them and returns the corresponding raw pointers...
Definition: gsMemory.h:228
Class gsTemplate object.
Definition: gsTemplate.h:77
Provides declaration of the BoxTopology class.
short_t dim() const
Dimension of the boxes.
Definition: gsBoxTopology.h:98
#define short_t
Definition: gsConfig.h:35
Provides structs and classes related to interfaces and boundaries.
S give(S &x)
Definition: gsMemory.h:266
Provides declaration of Geometry abstract interface.
#define index_t
Definition: gsConfig.h:32
gsTemplate(const std::vector< T > &intervalWidths, const gsMatrix< T > &verts, size_t startIdx, size_t endIdx, T curveProportion)
Definition: gsTemplate.h:422
gsTemplate()
Default empty constructor.
Definition: gsTemplate.h:89
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
gsMatrix< T > * m_corners
List of corner points.
Definition: gsTemplate.h:637
A B-spline function of one argument, with arbitrary target dimension.
Definition: gsBSpline.h:50
static BSplinePtr BSplineFatCircle(T const &r=(T)(1), T const &x=0, T const &y=0)
Inexact circle using B-splines.
Definition: gsNurbsCreator.hpp:1034
memory::shared_ptr< gsBoxTopology > Ptr
Shared pointer for gsBoxTopology.
Definition: gsBoxTopology.h:43
#define gsWarn
Definition: gsDebug.h:50
void freeAll(It begin, It end)
Frees all pointers in the range [begin end)
Definition: gsMemory.h:312
Class representing a Planar domain with an outer boundary and a number of holes.
Definition: gsPlanarDomain.h:43
index_t nPatches() const
Number of patches.
Definition: gsTemplate.h:591
Provides functions to generate structured point data.
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsTemplate.h:576
gsTemplate * clone() const
Clone function. Used to make a copy of the object.
Definition: gsTemplate.h:568
A closed loop given by a collection of curves.
Definition: gsCurveLoop.h:36
Defines a topological arrangement of a collection of "boxes" (e.g., parameter domains that map to phy...
Definition: gsBoxTopology.h:38
gsTemplate(int r, bool)
square template constructed providing the 4 corners Bb matrix (2,4) (x and y coord.)
Definition: gsTemplate.h:347
Provides declaration of the NurbsCreator struct.
Interface for gsCurveLoop class, representing a loop of curves, in anticlockwise order.
gsBoxTopology Base
Shared pointer for gsTemplate.
Definition: gsTemplate.h:82