G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
bSplineCurve_example.cpp

Annotated source file

Here is the full file examples/bSplineCurve_example.cpp. Clicking on a function or class name will lead you to its reference documentation.

#include <iostream>
#include <gismo.h>
using namespace gismo;
int main(int argc, char *argv[])
{
bool plot = false; // If set to true, paraview file is generated and launched on exit
bool trim = false; // If set to true, trim/merge operations are displayed
bool intersect = false; // If set to true, intersection example is displayed
gsCmdLine cmd("Tutorial 01 shows the use of BSpline curves.");
cmd.addSwitch("plot", "Plot result in ParaView format", plot);
cmd.addSwitch("trim", "Basic trim/merge operations", trim);
cmd.addSwitch("intersect", "Intersection operations", intersect);
try { cmd.getValues(argc,argv); } catch (int rv) { return rv; }
// Make a BSpline curve
gsKnotVector<> kv(0, 1, 1, 3);//start,end,interior knots, start/end multiplicites of knots
gsMatrix<> coefs(4, 3);
coefs << 0, 0, 0,
1, 2, 3,
2, 1, 4,
4, 4, 4;
gsBSpline<> curve(kv, coefs);
// Print the Bspline curve
gsInfo << "I am a " << curve << "\n";
if (plot)
{
// Output a paraview file
coefs.transposeInPlace();
gsWriteParaview( curve, "bsplinecurve0", 100);
gsWriteParaview( curve, "bsplinecurve", 100, true, true);
gsWriteParaviewPoints( coefs, "coefficients");
gsFileManager::open("bsplinecurve0.pvd");
}
else
gsInfo << "Done. No output created, re-run with --plot to get a ParaView "
"file containing the solution.\n";
// Basic trim/merge operations on BSpline curves - @Ye
if (trim)
{
gsInfo << "Original BSpline curve: " << curve << "\n";
gsWriteParaview( curve, "originalCurve", 100); // Output the original curve
// Segment this BSpline curve between parameters 0.3 and 0.8
gsBSpline<> segment = curve.segmentFromTo(0.3, 0.8);
gsInfo << "Curve segment from u0 = 0.3 to u1 = 0.8: " << segment << "\n";
gsWriteParaview(segment, "segment", 100); // Output the curve segment
// Split the curve at parameter 0.4 into two parts
gsBSpline<> segmentLeft, segmentRight;
curve.splitAt(0.4, segmentLeft, segmentRight);
gsInfo << "Curve segment from u0 = 0.0 to u1 = 0.4: " << segmentLeft << "\n";
gsInfo << "Curve segment from u0 = 0.4 to u1 = 1.0: " << segmentRight << "\n";
gsWriteParaview( segmentLeft, "segmentLeft", 100);
gsWriteParaview( segmentRight, "segmentRight", 100);
// Merge the left and right segments back to the original curve
// Note: Due to the segmentation, an inner knot value of 0.4 is introduced, while
// the geometry remains exactly the same as the original one
gsBSpline<> mergedCurve = segmentLeft;
mergedCurve.merge(&segmentRight);
gsInfo << "The merged curve: " << mergedCurve << "\n";
gsWriteParaview( mergedCurve, "mergedCurve", 100);
// convert it into bezier segments
gsMultiPatch<> bezSegments = mergedCurve.toBezier();
gsWriteParaview(bezSegments, "bezierContainer", 100);
}
else
gsInfo << "Done. Re-run with --trim to learn basic trim/merge operations\n";
// Basic intersection operations between two BSpline curves - @Ye
if (intersect)
{
gsMatrix<real_t> ctrPts1(4, 2);
ctrPts1 << 0,0, 1,1, 2,1, 3,1;
gsBSpline<real_t> bsp1(0, 1, 0, 3, ctrPts1);
gsMatrix<real_t> ctrPts2(4, 2);
ctrPts2 << 0,0, 1,2, 2,2, 3,0;
gsBSpline<real_t> bsp2(0, 1, 0, 3, ctrPts2);
auto intersectPts = bsp1.intersect(bsp2, 1e-5);
gsInfo << intersectPts.size() << " intersections are found!" << "\n";
gsMatrix<> iPts(bsp1.geoDim(), intersectPts.size());
for (size_t j = 0; j < intersectPts.size(); ++j)
{
iPts.col(j) = intersectPts[j].getPoint();
}
if (!intersectPts.empty())
{
gsWriteParaviewPoints(iPts, "intersect");
}
gsWriteParaview(bsp1, "bsp1", 2000);
gsWriteParaview(bsp2, "bsp2", 2000);
}
else
gsInfo << "Done. Re-run with --intersect to learn intersection operations\n";
return 0;
}
A B-spline function of one argument, with arbitrary target dimension.
Definition gsBSpline.h:51
void merge(gsGeometry< T > *otherG)
Merge other B-spline into this one.
Definition gsBSpline.hpp:29
void splitAt(T u0, gsBSpline< T > &left, gsBSpline< T > &right, T tolerance=1e-15) const
Definition gsBSpline.hpp:255
gsBSpline< T > segmentFromTo(T u0, T u1, T tolerance=1e-15) const
Definition gsBSpline.hpp:87
Class for command-line argument parsing.
Definition gsCmdLine.h:57
static void open(const std::string &fn)
Opens the file fn using the preferred application of the OS.
Definition gsFileManager.cpp:688
Class for representing a knot vector.
Definition gsKnotVector.h:80
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition gsMultiPatch.h:100
Main header to be included by clients using the G+Smo library.
#define gsInfo
Definition gsDebug.h:43
The G+Smo namespace, containing all definitions for the library.
void gsWriteParaviewPoints(gsMatrix< T > const &X, gsMatrix< T > const &Y, std::string const &fn)
Export 2D Point set to Paraview file.
Definition gsWriteParaview.hpp:1383