35 : m_g(&g), m_pt(&pt), m_gd(2) { }
40 m_g->eval_into(u, m_gd[0]);
41 result.resize(1, u.cols());
42 result.
at(0) = 0.5 * (m_gd[0]-*m_pt).squaredNorm();
47 bool sameElement =
false)
const
51 m_g->evalAllDers_into(u, n, m_gd, sameElement);
54 result[0].resize(1, 1);
55 result[0].at(0) = 0.5 * (m_gd[0]-*m_pt).squaredNorm();
59 auto jacT = m_gd[1].reshaped(u.rows(),m_pt->rows());
60 result[1].noalias() = jacT * (m_gd[0] - *m_pt);
64 tmp.noalias() = jacT * jacT.transpose();
65 index_t d2 = u.rows() * (u.rows()+1) / 2;
67 for (
index_t k=0; k < m_g->coefs().cols(); ++k )
69 hm = util::secDerToHessian(m_gd[2].block(k*d2,0,d2,1),u.rows()).reshaped(u.rows(),u.rows());
70 tmp += (m_gd[0].at(k)-m_pt->
at(k)) * hm;
72 util::hessianToSecDer(tmp,u.rows(),result[2]);
78 result.resize(u.rows(), u.cols());
79 for (
index_t i=0; i != u.cols(); i++ )
82 m_g->eval_into(tmp,m_gd[0]);
83 m_g->jacobian_into(tmp,m_gd[1]);
84 result.col(i).noalias() = m_gd[1].transpose() * (m_gd[0] - *m_pt);
92 m_g->eval_into(u,m_gd[0]);
93 m_g->jacobian_into(u,m_gd[1]);
94 result.noalias() = m_gd[1].transpose() * m_gd[1];
95 for (
index_t k=0; k < m_g->coefs().cols(); ++k )
97 tmp = m_g->hessian(u,k);
98 result.noalias() += (m_gd[0].at(k)-m_pt->
at(k))*tmp;
102 gsMatrix<T> support()
const {
return m_g->support() ;}
109 mutable std::vector<gsMatrix<T> > m_gd;
158: m_coefs(o.m_coefs), m_basis(o.m_basis != NULL ? o.basis().clone().release() : NULL), m_id(o.m_id)
162gsGeometry<T>::~gsGeometry()
167{ this->basis().evalFunc_into(u, m_coefs, result); }
171{ this->basis().derivFunc_into(u, m_coefs, result); }
175{ this->basis().deriv2Func_into(u, m_coefs, result); }
180 bool sameElement)
const
181{ this->basis().evalAllDersFunc_into(u, m_coefs, n, result, sameElement); }
194{
return this->basis().support(); }
199{
return this->basis().support(); }
208 m_basis = o.
basis().clone().release() ;
221 for (
index_t i=0; i != ind.size(); i++ )
223 coeffs.row(i) = m_coefs.row( ind(i,0) );
243 typename gsBasis<T>::uPtr Bs = this->basis().componentBasis_withIndices(bc, ind,
false);
246 for (
index_t i=0; i != ind.size(); i++ )
248 coefs.row(i) = m_coefs.row( ind(i,0) );
257 const int pDim = parDim();
258 const int gDim = geoDim();
264 if (1==gDim && 3>pDim)
265 for (
size_t i = 0; i!= mesh.numVertices(); ++i)
267 eval_into( mesh.vertex(i).topRows(pDim), tmp );
268 mesh.vertex(i).middleRows(pDim, gDim) = tmp;
271 for (
size_t i = 0; i!= mesh.numVertices(); ++i)
273 eval_into( mesh.vertex(i).topRows(pDim), tmp );
274 const index_t gd = math::min(3,gDim);
275 mesh.vertex(i).topRows(gd) = tmp.topRows(gd);
295 return this->m_coefs.row(this->basis().functionAtCorner(c));
302 return this->m_coefs.row(this->basis().functionAtCorner(c));
308 this->basis().uniformRefine_withCoefs( m_coefs, numKnots, mul, dir);
314 this->basis().uniformCoarsen_withCoefs( m_coefs, numKnots);
320 this->basis().refineElements_withCoefs(this->m_coefs, boxes );
326 this->basis().unrefineElements_withCoefs(this->m_coefs, boxes );
330inline typename gsGeometry<T>::uPtr gsGeometry<T>::coord(
const index_t c)
const {
return this->basis().makeGeometry( this->coefs().col(c) ); }
335 {
return this->basis().degree(i); }
342 const bool useInitialPoint)
const
344 GISMO_ASSERT( pt.rows() == targetDim(),
"Invalid input point." <<
345 pt.rows() <<
"!="<< targetDim() );
348 gsMinimizer<T> fmin(dist2);
350 result = fmin.currentDesign();
353 result = useInitialPoint ? dist2.argMin(accuracy*accuracy, 100, result)
354 : dist2.argMin(accuracy*accuracy, 100) ;
356 return math::sqrt( dist2.
eval(result).value() );
363 gsMatrix<T> uv = gsPointGrid<T>(this->support(),nsamples);
365 this->eval_into(uv,pts);
367 T maxDist=std::numeric_limits<T>::min();
369 for (
index_t k=0; k!=pts.cols(); k++)
371 maxDist = std::max(maxDist,other.
closestPointTo(pts.col(k),tmp,accuracy,
false));
373 return math::sqrt(2*maxDist);
379 T this2other, other2this;
380 this2other = this->directedHausdorffDistance(other,nsamples,accuracy);
386 return std::max(other2this,this2other);
394 const T accuracy)
const
397 for (
index_t i = 0; i!= xyz.rows(); ++i)
399 else if (i>k) ind[i-1]=i;
404 xyz = this->eval(uv);
412 os <<
"Geometry "<<
"R^"<< this->parDim() <<
413 " --> R^"<< this->geoDim()<<
", #control pnts= "<< coefsSize() <<
414 ": "<< coef(0) <<
" ... "<< coef(this->coefsSize()-1);
415 os<<
"\nBasis:\n" << this->basis();
429gsGeometry<T>::approximateLinearly()
const
455 this->eval_into(iPts, iVals);
458 std::swap(m_basis, g->
m_basis);
459 g->
coefs().swap(this->coefs());
468 this->eval_into(iPts, iVals);
471 std::swap(m_basis, g->
m_basis);
472 g->
coefs().swap(this->coefs());
481 this->eval_into(iPts, iVals);
484 std::swap(m_basis, g->
m_basis);
485 g->
coefs().swap(this->coefs());
494 this->eval_into(iPts, iVals);
497 std::swap(m_basis, g->
m_basis);
498 g->
coefs().swap(this->coefs());
501template<
class T>
void
505 const unsigned d = this->domainDim();
506 GISMO_ASSERT( coord<targetDim(),
"Invalid coordinate function "<<coord);
514 m_basis->deriv2_into(u, B) ;
516 m_basis->active_into(u, ind);
522 for (
index_t i=0; i< ind.rows() ; i++ )
524 unsigned r = i*d*(d+1)/2;
527 for (
unsigned k=0; k<d; ++k )
530 for (
unsigned l=k+1; l<d; ++l )
531 tmp(k,l) = tmp(l,k) = B(r + m++,0);
533 result += C(ind(i,j), coord) * tmp;
539{ basis().connectivity(m_coefs, mesh); }
544void extractRows(
const gsMatrix<T> &in,
typename gsMatrix<index_t>::constColumn actives,
gsMatrix<T> &out)
546 out.resize(actives.rows(), in.cols());
547 for (
index_t r=0; r<actives.rows();++r)
548 out.row(r)=in.row(actives(r,0));
556 const index_t numPt = in.cols();
557 const index_t numCo = m_coefs.cols();
559 gsFuncData<T> tmp(flags);
560 this->basis().compute(in, tmp);
562 out.values.resize(out.maxDeriv()+1);
563 out.dim.first = tmp.dim.first;
564 out.dim.second = numCo;
568 extractRows(m_coefs,tmp.active(0),coefM);
571 out.values[0].noalias()=coefM.transpose()*tmp.values[0];
574 const index_t derS = tmp.derivSize();
575 out.values[1].resize(derS*numCo,numPt);
576 for (
index_t p=0; p< numPt; ++p)
577 out.values[1].
reshapeCol(p, derS, numCo).noalias() = tmp.deriv(p)*coefM;
581 const index_t derS = tmp.deriv2Size();
582 out.values[2].resize(derS*numCo,numPt);
583 for (
index_t p=0; p< numPt; ++p)
584 out.values[2].
reshapeCol(p, derS, numCo).noalias() = tmp.deriv2(p)*coefM;
587 this->active_into(in.col(0), out.actives);
592 const index_t derS = tmp.derivSize();
593 const index_t der2S = tmp.deriv2Size();
595 if (flags &
NEED_VALUE) out.values[0].resize(numCo,numPt);
596 if (flags &
NEED_DERIV) out.values[1].resize(numCo*derS,numPt);
597 if (flags &
NEED_DERIV2) out.values[2].resize(numCo*der2S,numPt);
598 if (flags &
NEED_ACTIVE) this->active_into(in, out.actives);
602 extractRows(m_coefs,tmp.active(p),coefM);
604 out.values[0].reshapeCol(p,1,numCo).noalias() = tmp.eval(p)*coefM;
606 out.values[1].
reshapeCol(p, derS, numCo).noalias() = tmp.deriv(p)*coefM;
608 out.values[2].
reshapeCol(p, der2S, numCo).noalias() = tmp.deriv2(p)*coefM;
622 onGeo.resize(u.cols());
623 std::vector<boxSide> sides(u.cols());
625 for(
index_t i = 0; i < onGeo.size(); i++)
628 preIm.resize(geoDim(), u.cols());
631 for(
index_t i = 0; i < u.cols(); i++)
633 this->invertPoints(u.col(i), tmp, tol);
634 pr = this->parameterRange();
637 if ((tmp.array() >= pr.col(0).array() - 1.e-4).all()
638 && (tmp.array() <= pr.col(1).array() + 1.e-4).all())
646 if (lookForBoundary ==
true)
649 for (
int d = 0; d < geoDim(); d++) {
650 if ((math::abs(tmp(d, 0) - pr(d, 0)) < tol))
656 if ((math::abs(tmp(d, 0) - pr(d, 1)) < tol))
Struct which represents a certain side of a box.
Definition gsBoundary.h:85
short_t m_index
Index of the side.
Definition gsBoundary.h:92
virtual void degreeDecrease(short_t const &i=1, short_t const dir=-1)
Lower the degree of the basis by the given amount, preserving knots multiplicity.
Definition gsBasis.hpp:641
memory::unique_ptr< gsGeometry< T > > interpolateData(gsMatrix< T > const &vals, gsMatrix< T > const &pts) const
Applies interpolation given the parameter values pts and values vals.
Definition gsBasis.hpp:240
virtual void degreeReduce(short_t const &i=1, short_t const dir=-1)
Reduce the degree of the basis by the given amount, preserve smoothness.
Definition gsBasis.hpp:633
virtual void degreeIncrease(short_t const &i=1, short_t const dir=-1)
Elevate the degree of the basis by the given amount, preserve knots multiplicity.
Definition gsBasis.hpp:637
memory::unique_ptr< gsBasis > uPtr
Unique pointer for gsBasis.
Definition gsBasis.h:89
gsMatrix< T > anchors() const
Returns the anchor points that represent the members of the basis. There is exactly one anchor point ...
Definition gsBasis.h:437
virtual memory::unique_ptr< gsGeometry< T > > makeGeometry(gsMatrix< T > coefs) const =0
Create a gsGeometry of proper type for this basis with the given coefficient matrix.
virtual void degreeElevate(short_t const &i=1, short_t const dir=-1)
Elevate the degree of the basis by the given amount, preserve smoothness.
Definition gsBasis.hpp:629
Represents a certain component of a vector-valued function.
Definition gsFuncCoordinate.h:35
uPtr clone()
Clone methode. Produceds a deep copy inside a uPtr.
gsMatrix< T > eval(const gsMatrix< T > &u) const
Evaluate the function,.
Definition gsFunctionSet.hpp:120
A function from a n-dimensional domain to an m-dimensional image.
Definition gsFunction.h:60
virtual void invertPoints(const gsMatrix< T > &points, gsMatrix< T > &result, const T accuracy=1e-6, const bool useInitialPoint=false) const
Definition gsFunction.hpp:199
gsGeometrySlice is a class representing an iso parametric slice of a geometry object....
Definition gsGeometrySlice.h:28
Abstract base class representing a geometry map.
Definition gsGeometry.h:93
virtual void deriv2_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate second derivatives of the function at points u into result.
Definition gsGeometry.hpp:174
gsMatrix< T > & coefs()
Definition gsGeometry.h:340
T HausdorffDistance(const gsGeometry &other, const index_t nsamples=1000, const T accuracy=1e-6, const bool directed=false) const
Computes the Hausdorff distance between *this to other.
Definition gsGeometry.hpp:377
std::vector< gsGeometry * > boundary() const
Get boundary of this geometry as a vector of new gsGeometry instances.
Definition gsGeometry.hpp:437
virtual void uniformCoarsen(int numKnots=1)
Coarsen the geometry uniformly, removing numKnots new knots into each knot span.
Definition gsGeometry.hpp:312
gsMatrix< T >::RowXpr coefAtCorner(boxCorner const &c)
Returns the control point at corner c.
Definition gsGeometry.hpp:293
virtual void degreeElevate(short_t const i=1, short_t const dir=-1)
Elevate the degree by the given amount i for the direction dir. If dir is -1 then degree elevation is...
Definition gsGeometry.hpp:450
virtual void degreeIncrease(short_t const i=1, short_t const dir=-1)
Elevate the degree by the given amount i for the direction dir. If dir is -1 then degree elevation is...
Definition gsGeometry.hpp:476
short_t degree(const short_t &i) const
Returns the degree wrt direction i.
Definition gsGeometry.hpp:333
short_t coDim() const
Co-dimension of the geometric object.
Definition gsGeometry.hpp:187
void evaluateMesh(gsMesh< T > &mesh) const
Definition gsGeometry.hpp:255
memory::unique_ptr< gsGeometry > uPtr
Unique pointer for gsGeometry.
Definition gsGeometry.h:100
std::vector< boxSide > locateOn(const gsMatrix< T > &u, gsVector< bool > &onG2, gsMatrix< T > &preIm, bool lookForBoundary=false, real_t tol=1.e-6) const
Get back the side of point u.
Definition gsGeometry.hpp:620
virtual void evalAllDers_into(const gsMatrix< T > &u, int n, std::vector< gsMatrix< T > > &result, bool sameElement=false) const
Evaluate the nonzero functions and their derivatives up to order n at points u into result.
Definition gsGeometry.hpp:178
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the function at points u into result.
Definition gsGeometry.hpp:166
virtual void merge(gsGeometry *other)
Merge the given other geometry into this one.
Definition gsGeometry.hpp:420
gsGeometry()
Default constructor. Note: Derived constructors (except for the default) should assign m_basis to a v...
Definition gsGeometry.h:111
virtual void hessian_into(const gsMatrix< T > &u, gsMatrix< T > &result, index_t coord) const
Definition gsGeometry.hpp:502
virtual void compute(const gsMatrix< T > &in, gsFuncData< T > &out) const
Computes function data.
Definition gsGeometry.hpp:553
virtual std::vector< gsGeometry< T > * > uniformSplit(index_t dir=-1) const
Definition gsGeometry.hpp:280
void outerNormal_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Computes the outer normals at parametric points u.
Definition gsGeometry.hpp:433
void recoverPoints(gsMatrix< T > &xyz, gsMatrix< T > &uv, index_t k, const T accuracy) const
Recovers the points of the geometry from the given points xyz and parameters uv.
Definition gsGeometry.hpp:393
virtual void degreeReduce(short_t const i=1, short_t const dir=-1)
Reduces the degree by the given amount i for the direction dir. If dir is -1 then degree reduction is...
Definition gsGeometry.hpp:463
T directedHausdorffDistance(const gsGeometry &other, const index_t nsamples=1000, const T accuracy=1e-6) const
Definition gsGeometry.hpp:360
virtual short_t domainDim() const
Dimension d of the parameter domain (overriding gsFunction::domainDim()).
Definition gsGeometry.hpp:184
virtual const gsBasis< T > & basis() const =0
Returns a const reference to the basis of the geometry.
virtual gsGeometry::uPtr iface(const boundaryInterface &bi, const gsGeometry &other) const
Computes and returns the interface with other as a new geometry.
Definition gsGeometry.hpp:232
gsGeometry::uPtr component(boxComponent const &bc) const
Get parametrization of box component bc as a new gsGeometry uPtr.
Definition gsGeometry.hpp:240
virtual void uniformRefine(int numKnots=1, int mul=1, short_t const dir=-1)
Refine the geometry uniformly, inserting numKnots new knots into each knot span.
Definition gsGeometry.hpp:306
short_t parDim() const
Dimension d of the parameter domain (same as domainDim()).
Definition gsGeometry.hpp:190
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
gsBasis< T > * m_basis
Pointer to the basis of this geometry.
Definition gsGeometry.h:632
gsMatrix< T > support() const
Returns the range of parameters (same as parameterRange())
Definition gsGeometry.hpp:193
T closestPointTo(const gsVector< T > &pt, gsVector< T > &result, const T accuracy=1e-6, const bool useInitialPoint=false) const
Definition gsGeometry.hpp:339
gsMatrix< T > m_coefs
Coefficient matrix of size coefsSize() x geoDim()
Definition gsGeometry.h:629
size_t m_id
Definition gsGeometry.h:636
virtual std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition gsGeometry.hpp:410
void controlNet(gsMesh< T > &mesh) const
Return the control net of the geometry.
Definition gsGeometry.hpp:538
gsGeometrySlice< T > getIsoParametricSlice(index_t dir_fixed, T par) const
Definition gsGeometry.hpp:286
void refineElements(std::vector< index_t > const &boxes)
Refines the basis and adjusts the coefficients to keep the geometry the same.
Definition gsGeometry.hpp:318
virtual void insertKnot(T knot, index_t dir, index_t i=1)
Inserts knot knot at direction dir, i times.
Definition gsGeometry.hpp:444
virtual void degreeDecrease(short_t const i=1, short_t const dir=-1)
Reduces the degree by the given amount i for the direction dir. If dir is -1 then degree reduction is...
Definition gsGeometry.hpp:489
gsMatrix< T > parameterRange() const
Returns the range of parameters as a matrix with two columns, [lower upper].
Definition gsGeometry.hpp:198
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
gsAsMatrix< T, Dynamic, Dynamic > reshapeCol(index_t c, index_t n, index_t m)
Returns column c of the matrix resized to n x m matrix This function assumes that the matrix is size ...
Definition gsMatrix.h:231
T at(index_t i) const
Returns the i-th element of the vectorization of the matrix.
Definition gsMatrix.h:211
Class Representing a triangle mesh with 3D vertices.
Definition gsMesh.h:32
Squared distance function from a fixed point to a gsGeometry.
Definition gsGeometry.hpp:32
void evalAllDers_into(const gsMatrix< T > &u, int n, std::vector< gsMatrix< T > > &result, bool sameElement=false) const
Evaluate the nonzero functions and their derivatives up to order n at points u into result.
Definition gsGeometry.hpp:45
short_t targetDim() const
Dimension of the target space.
Definition gsGeometry.hpp:104
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the function at points u into result.
Definition gsGeometry.hpp:38
short_t domainDim() const
Dimension of the (source) domain.
Definition gsGeometry.hpp:103
void deriv_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate derivatives of the function at points u into result.
Definition gsGeometry.hpp:76
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
T at(index_t i) const
Returns the i-th element of the vector.
Definition gsVector.h:177
Provides declaration of Basis abstract interface.
#define short_t
Definition gsConfig.h:35
#define index_t
Definition gsConfig.h:32
#define GISMO_NO_IMPLEMENTATION
Definition gsDebug.h:129
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
Provides definition of the FuncCoordinate class.
This object is a cache for computed values from an evaluator.
Provides declaration of the gsGeometrySlice class.
Provides declaration of the Mesh class.
Provides functions to generate structured point data.
The G+Smo namespace, containing all definitions for the library.
@ SAME_ELEMENT
Enable optimizations based on the assumption that all evaluation points are in the same bezier domain...
Definition gsForwardDeclarations.h:89
@ NEED_VALUE
Value of the object.
Definition gsForwardDeclarations.h:72
@ NEED_DERIV2
Second derivatives.
Definition gsForwardDeclarations.h:80
@ NEED_DERIV
Gradient of the object.
Definition gsForwardDeclarations.h:73
@ NEED_ACTIVE
Active function ids.
Definition gsForwardDeclarations.h:84
S give(S &x)
Definition gsMemory.h:266
Struct which represents an interface between two patches.
Definition gsBoundary.h:650
Struct which represents a certain component (interior, face, egde, corner).
Definition gsBoundary.h:445
Struct which represents a certain corner of a hyper-cube.
Definition gsBoundary.h:292