In this example, we show how to create a knot vector, and how to perform some basic operations on it.
First we include the library and use the gismo namespace.
Then we consider different knot vector initializations. Empty knot vector initialization:
A knot vector can be defined also by specifying the knot values directly via, passed to the constructor via a container. Knot vector container initialization:
To define uniform knot vector on \([0,1]\), we can use the following constructors:
Finally, here we show how to loop over the knots of a knot vector.
#include <iostream>
#include <string>
#include <algorithm>
void printKnotVector(
const gsKnotVector<>& kv,
const std::string& name);
void print(const real_t& el);
int main(int argc, char* argv[])
{
gsCmdLine cmd(
"Tutorial on gsKnotVector class.");
try { cmd.getValues(argc,argv); } catch (int rv) { return rv; }
gsInfo <<
"------------- Constructions -------------\n";
printKnotVector(kv0, "kv0");
printKnotVector(kv1, "kv1");
real_t a = 1;
real_t b = 3;
printKnotVector(kv2, "kv2");
printKnotVector(kv3, "kv3");
printKnotVector(kv4, "kv4");
std::vector<real_t> knotContainer;
knotContainer.push_back(0);
knotContainer.push_back(0.1);
knotContainer.push_back(0.5);
knotContainer.push_back(0.6);
knotContainer.push_back(0.9);
knotContainer.push_back(1);
printKnotVector(kv5, "kv5");
printKnotVector(kv6, "kv6");
printKnotVector(kv7, "kv7");
gsInfo <<
"------------- Some properties -------------\n"
<< "kv7: \n\n";
printKnotVector(kv7, "kv7");
<<
"kv7.findspan(1.5): " << kv7.
iFind(1.5) - kv7.
begin() <<
"\n"
<<
"kv7.findspan(2): " << kv7.
iFind(2) - kv7.
begin() <<
"\n"
<<
"kv7.has(2): " << kv7.
has(2) <<
"\n"
<<
"kv7.has(2.1): " << kv7.
has(2.1) <<
"\n"
<<
"kv7.isUniform(): " << kv7.
isUniform() <<
"\n"
<<
"kv7.isOpen(): " << kv7.
isOpen() <<
"\n"
<<
"kv7.multiplicity(4/3): " << kv7.
multiplicity(4./3) <<
"\n"
<<
"kv7.numKnotSpans(): " << kv7.
uSize() - 1 <<
"\n\n";
gsInfo <<
"------------- Some operations -------------\n";
printKnotVector(kv6, "kv6");
std::vector<real_t> unique = kv6.
unique();
gsInfo <<
"\nUnique knots: \n";
std::for_each(unique.begin(), unique.end(), print);
gsInfo <<
"\n\nGreville points: \n" << greville <<
"\n\n";
std::for_each(mult.begin(), mult.end(), print);
printKnotVector(kv6, "kv6");
gsInfo <<
"kv6.uniformRefine()\n";
printKnotVector(kv6);
gsInfo <<
"kv6.degreeElevate()\n";
printKnotVector(kv6);
<< "------------- Looping over knots -------------\n"
<< "kv4: \n";
{
}
{
}
gsInfo <<
"For other capabilites of gsKnotVector look at "
"src/gsNurbs/gsKnotVector.h\n" << "\n";
return 0;
}
void print(const real_t& el)
{
}
const std::string& name)
{
gsInfo << name <<
":\n" << kv <<
"\n";
for (gsKnotVector<>::const_iterator it = kv.
begin(); it != kv.
end(); it++)
{
}
}
{
for (gsKnotVector<>::const_iterator it = kv.
begin(); it != kv.
end(); it++)
{
}
}
Class for command-line argument parsing.
Definition gsCmdLine.h:57
bool isOpen() const
Definition gsKnotVector.h:882
size_t size() const
Number of knots (including repetitions).
Definition gsKnotVector.h:242
iterator begin() const
Returns iterator pointing to the beginning of the repeated knots.
Definition gsKnotVector.hpp:117
bool has(T knot) const
Definition gsKnotVector.h:819
void degreeElevate(const short_t &i=1)
Definition gsKnotVector.hpp:937
void uniformRefine(mult_t numKnots=1, mult_t mult=1)
Definition gsKnotVector.hpp:820
void initClamped(int degree, unsigned numKnots=2, unsigned mult_interior=1)
Definition gsKnotVector.hpp:693
knotContainer unique() const
Returns unique knots.
Definition gsKnotVector.h:273
multContainer multiplicities() const
Returns vector of multiplicities of the knots.
Definition gsKnotVector.hpp:714
bool isUniform(T tol=1e-9) const
Checks whether the knot vector is uniform.
Definition gsKnotVector.h:871
iterator iFind(const T u) const
Returns an iterator to the last occurrence of the knot at the beginning of the knot interval containi...
Definition gsKnotVector.hpp:779
size_t uSize() const
Number of unique knots (i.e., without repetitions).
Definition gsKnotVector.h:245
mult_t multiplicity(T u) const
Definition gsKnotVector.hpp:421
void initUniform(T first, T last, unsigned interior, unsigned mult_ends, unsigned mult_interior, short_t degree=-1)
Definition gsKnotVector.hpp:643
iterator end() const
Returns iterator pointing past the end of the repeated knots.
Definition gsKnotVector.hpp:124
gsMatrix< T > greville() const
Definition gsKnotVector.h:540