Example of vector field manipulation using Discrete Exterior Calculus.
#include <string>
#include "DECExamplesCommon.h"
#include "DGtal/math/linalg/EigenSupport.h"
#include "DGtal/dec/DiscreteExteriorCalculus.h"
#include "DGtal/dec/DiscreteExteriorCalculusSolver.h"
#include "DGtal/dec/DiscreteExteriorCalculusFactory.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/readers/GenericReader.h"
void usage2d()
{
trace.
beginBlock(
"2d discrete exterior calculus usage");
{
Calculus calculus = CalculusFactory::createFromDigitalSet(generateRingSet(
domain),
false);
calculus.eraseCell(calculus.myKSpace.uSpel(
Z2i::Point(8, 5)));
calculus.updateIndexes();
trace.
info() << calculus << endl;
board << calculus;
board.
saveSVG(
"usage_calculus_without_border.svg");
}
Calculus calculus = CalculusFactory::createFromDigitalSet(generateRingSet(
domain),
true);
calculus.eraseCell(calculus.myKSpace.uSpel(
Z2i::Point(8, 5)));
calculus.eraseCell(calculus.myKSpace.uCell(
Z2i::Point(18, 11)));
calculus.updateIndexes();
trace.
info() << calculus << endl;
{
board << calculus;
board.
saveSVG(
"usage_calculus_with_border.svg");
}
{
trace.
info() <<
"primal path" << endl;
Calculus::PrimalForm0 primal_zero_form(calculus);
for (Calculus::Index index=0; index<primal_zero_form.length(); index++)
{
const Calculus::SCell& cell = primal_zero_form.getSCell(index);
const Calculus::Scalar& value = Z2i::l2Metric(calculus.myKSpace.sKCoords(cell), center)/2;
primal_zero_form.myContainer(index) = value;
}
const Calculus::PrimalForm0 foo = 2 * primal_zero_form + primal_zero_form;
{
board << calculus;
board << primal_zero_form;
board.
saveSVG(
"usage_primal_zero_form.svg");
}
const Calculus::PrimalDerivative0 primal_zero_derivative = calculus.derivative<0, PRIMAL>();
const Calculus::PrimalForm1 primal_one_form = primal_zero_derivative * primal_zero_form;
const Calculus::PrimalVectorField primal_vector_field = calculus.sharp(primal_one_form);
{
board << calculus;
board << primal_one_form;
board << primal_vector_field;
board.
saveSVG(
"usage_primal_one_form.svg");
}
const Calculus::PrimalForm1 flat_sharp_primal_one_form = calculus.flat(primal_vector_field);
const Calculus::PrimalVectorField sharp_flat_primal_vector_field = calculus.sharp(flat_sharp_primal_one_form);
{
board << calculus;
board << flat_sharp_primal_one_form;
board << sharp_flat_primal_vector_field;
board.
saveSVG(
"usage_primal_one_form_sharp_flat.svg");
}
const Calculus::PrimalHodge1 primal_one_hodge = calculus.hodge<1, PRIMAL>();
const Calculus::DualForm1 dual_one_form = primal_one_hodge * primal_zero_derivative * primal_zero_form;
const Calculus::DualVectorField dual_vector_field = calculus.sharp(dual_one_form);
{
board << calculus;
board << dual_one_form;
board << dual_vector_field;
board << primal_vector_field;
board.
saveSVG(
"usage_primal_one_form_hodge.svg");
}
}
{
trace.
info() <<
"dual path" << endl;
Calculus::DualForm0 dual_zero_form(calculus);
for (Calculus::Index index=0; index<dual_zero_form.length(); index++)
{
const Calculus::SCell& cell = dual_zero_form.getSCell(index);
const Calculus::Scalar& value = Z2i::l2Metric(calculus.myKSpace.sKCoords(cell), center)/2;
dual_zero_form.myContainer(index) = value;
}
{
board << calculus;
board << dual_zero_form;
board.
saveSVG(
"usage_dual_zero_form.svg");
}
const Calculus::DualDerivative0 dual_zero_derivative = calculus.derivative<0, DUAL>();
const Calculus::DualForm1 dual_one_form = dual_zero_derivative * dual_zero_form;
const Calculus::DualVectorField dual_vector_field = calculus.sharp(dual_one_form);
{
board << calculus;
board << dual_one_form;
board << dual_vector_field;
board.
saveSVG(
"usage_dual_one_form.svg");
}
const Calculus::DualForm1 flat_sharp_dual_one_form = calculus.flat(dual_vector_field);
const Calculus::DualVectorField sharp_flat_dual_vector_field = -calculus.sharp(flat_sharp_dual_one_form);
{
board << calculus;
board << flat_sharp_dual_one_form;
board << -sharp_flat_dual_vector_field;
board.
saveSVG(
"usage_dual_one_form_sharp_flat.svg");
}
const Calculus::DualHodge1 dual_one_hodge = calculus.hodge<1, DUAL>();
const Calculus::PrimalForm1 primal_one_form = dual_one_hodge * dual_zero_derivative * dual_zero_form;
const Calculus::PrimalVectorField primal_vector_field = calculus.sharp(primal_one_form);
{
board << calculus;
board << primal_one_form;
board << primal_vector_field;
board << dual_vector_field;
board.
saveSVG(
"usage_dual_one_form_hodge.svg");
}
}
}
{
usage2d();
return 0;
}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Aim: This class provides static members to create DEC structures from various other DGtal structures.
Aim: DiscreteExteriorCalculus represents a calculus in the dec package. This is the main structure in...
void beginBlock(const std::string &keyword="")
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
DGtal is the top-level namespace which contains all DGtal functions and types.