DGtalTools  1.2.0
Functions
DGtal::functions::dec Namespace Reference

Functions

template<typename Calculus , DGtal::Dimension dim, DGtal::Duality duality>
DGtal::LinearOperator< Calculus, dim, duality, dim, duality > diagonal (const DGtal::KForm< Calculus, dim, duality > &kform)
 
template<typename Calculus , DGtal::Dimension dim, DGtal::Duality duality>
void squares (DGtal::KForm< Calculus, dim, duality > &kform)
 
template<typename Calculus , DGtal::Dimension dim, DGtal::Duality duality>
DGtal::LinearOperator< Calculus, dim, duality, dim, duality > squaredDiagonal (const DGtal::KForm< Calculus, dim, duality > &kform)
 
template<typename Image >
void writePixel (Image &image, typename Image::Point pt, typename Image::Value val, int pixel_size=1)
 
template<typename Image >
void writePrimalLinel (Image &image, typename Image::Point pt, typename Image::Value val, int pixel_size=1)
 
template<typename Image >
void writeDualLinel (Image &image, typename Image::Point pt, typename Image::Value val, int pixel_size=1)
 
template<typename Calculus , typename AnyForm2 , typename Image , typename Function >
void form2ToImage (const Calculus &calculus, const AnyForm2 &u, Image &image, const Function &functor, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
 
template<typename Calculus , typename Form1 , typename Image , typename Function , typename Predicate >
void form1ToImage (const Calculus &calculus, const Form1 &v, bool primal, Image &image, const Function &functor, const Predicate &predicate, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
 
template<typename Calculus , typename Image , typename Function , typename Predicate >
void dualForm1ToImage (const Calculus &calculus, const typename Calculus::DualForm1 &v, Image &image, const Function &functor, const Predicate &predicate, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
 
template<typename Calculus , typename Image , typename Function , typename Predicate >
void primalForm1ToImage (const Calculus &calculus, const typename Calculus::PrimalForm1 &v, Image &image, const Function &functor, const Predicate &predicate, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
 
template<typename Calculus , typename AnyForm2 , typename Image , typename Function >
void threeForms2ToImage (const Calculus &calculus, const AnyForm2 &u0, const AnyForm2 &u1, const AnyForm2 &u2, Image &image, const Function &functor, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
 
template<typename Calculus , typename AnyForm2 , typename Image >
void form2ToGreyLevelImage (const Calculus &calculus, const AnyForm2 &u, Image &image, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
 
template<typename Calculus , typename Image >
void primalForm1ToGreyLevelImage (const Calculus &calculus, const typename Calculus::PrimalForm1 &v, Image &image, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
 
template<typename Calculus , typename Image >
void dualForm1ToGreyLevelImage (const Calculus &calculus, const typename Calculus::DualForm1 &v, Image &image, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
 
template<typename Calculus , typename Image >
void primalForm1ToRGBColorImage (const Calculus &calculus, const typename Calculus::PrimalForm1 &v, Image &image, Color color, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
 
template<typename Calculus , typename Image >
void dualForm1ToRGBColorImage (const Calculus &calculus, const typename Calculus::DualForm1 &v, Image &image, Color color, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
 
template<typename Calculus , typename AnyForm2 , typename Image >
void threeForms2ToRGBColorImage (const Calculus &calculus, const AnyForm2 &u0, const AnyForm2 &u1, const AnyForm2 &u2, Image &image, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
 

Function Documentation

◆ diagonal()

template<typename Calculus , DGtal::Dimension dim, DGtal::Duality duality>
DGtal::LinearOperator<Calculus, dim, duality, dim, duality> DGtal::functions::dec::diagonal ( const DGtal::KForm< Calculus, dim, duality > &  kform)

Builds a diagonal linear operator from a k-form. These operators arise naturally when differentiating with respect to another variable (e.g. d/dx (vx)^t (vx) = diag(v^2) x).

Parameters
[in]kformany kform w.
Returns
the corresponding linear operator diag(w)
Template Parameters
Calculusany discrete exterior calculus.
dimthe dimension of the form.
dualityeither PRIMAL for a primal form or DUAL for a dual form.

Definition at line 72 of file DECImageHelpers.h.

73  {
74  typedef DGtal::LinearOperator<Calculus,dim, duality, dim, duality> Operator;
75  typedef typename Calculus::LinearAlgebraBackend::Triplet Triplet;
76  typedef typename Calculus::Index Index;
77  typedef std::vector<Triplet> Triplets;
78 
79  Triplets triplets;
80  for (Index index=0; index<kform.length(); index++)
81  triplets.push_back(Triplet(index, index, kform.myContainer(index)));
82 
83  Operator op( kform.myCalculus );
84  op.myContainer.setFromTriplets( triplets.begin(), triplets.end() );
85  return op;
86  }

Referenced by squaredDiagonal().

◆ dualForm1ToGreyLevelImage()

template<typename Calculus , typename Image >
void DGtal::functions::dec::dualForm1ToGreyLevelImage ( const Calculus &  calculus,
const typename Calculus::DualForm1 &  v,
Image &  image,
double  cut_low = 0.0,
double  cut_up = 1.0,
int  pixel_size = 1 
)

Standard method to output a dual 1-form into a grey-level image.

Displays the dual 1-form v in the given image. Scalar values of v are first cut up and low according to cut_low and cut_up, and then rescaled according to max and min value. If this value is belows 0.25, it is written in the image as a "line" of size pixel_size x 1 or 1 x pixel_size, depending on position.

Parameters
calculusthe discrete exterior calculus containing the 1-form v.
vany dual 1-form defined in calculus.
[in,out]imagethe image where v is written.
cut_lowevery value of u below is set to cut_low.
cut_upevery value of u above is set to cut_up.
pixel_sizeevery value of a 1-form is mapped into image as pixel_size x 1 pixels or 1 x pixel_size pixels.
Template Parameters
Calculusany discrete exterior calculus type.
Imageany image type (see concepts::CImage).

Definition at line 577 of file DECImageHelpers.h.

583  {
584  BOOST_CONCEPT_ASSERT(( concepts::CImage<Image> ));
585  // Threshold is 0.25 instead of 0.5 because an edge connecting
586  // two vertices with v=0 and v=1 should not belong to the
587  // discontinuity set.
588  dualForm1ToImage( calculus, v, image,
589  [] ( double x ) { return (unsigned char) ( round( x * 255.0 ) ); },
590  [] ( double x ) { return x < 0.25; },
591  cut_low, cut_up, pixel_size );
592  }
void dualForm1ToImage(const Calculus &calculus, const typename Calculus::DualForm1 &v, Image &image, const Function &functor, const Predicate &predicate, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)

References dualForm1ToImage().

◆ dualForm1ToImage()

template<typename Calculus , typename Image , typename Function , typename Predicate >
void DGtal::functions::dec::dualForm1ToImage ( const Calculus &  calculus,
const typename Calculus::DualForm1 &  v,
Image &  image,
const Function &  functor,
const Predicate &  predicate,
double  cut_low = 0.0,
double  cut_up = 1.0,
int  pixel_size = 1 
)

Displays the dual 1-form v in the given image. Scalar values of v are first cut up and low according to cut_low and cut_up, and then rescaled according to max and min value. Then these values are transformed to image values with the function functor. They are written in the image as "lines" of size pixel_size x 1 or 1 x pixel_size, depending on position and duality.

Parameters
calculusthe discrete exterior calculus containing the 1-form v.
vany dual 1-form defined in calculus.
[in,out]imagethe image where v is written.
functorthe function transforming scalar values to image values.
predicatethe predicate telling for a value if it must be displayed (returns true in this case).
cut_lowevery value of u below is set to cut_low.
cut_upevery value of u above is set to cut_up.
pixel_sizeevery value of a 1-form is mapped into image as pixel_size x 1 pixels or 1 x pixel_size pixels.
Template Parameters
Calculusany discrete exterior calculus type.
Imageany image type (see concepts::CImage).
Functionany function type (double) -> typename Image::Value to convert form value to Image value.
Predicateany function type (double) -> bool to select 1-forms to display.

Definition at line 359 of file DECImageHelpers.h.

366  {
367  BOOST_CONCEPT_ASSERT(( concepts::CImage<Image> ));
368  form1ToImage( calculus, v, false, image, functor, predicate,
369  cut_low, cut_up, pixel_size );
370  }
void form1ToImage(const Calculus &calculus, const Form1 &v, bool primal, Image &image, const Function &functor, const Predicate &predicate, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)

References form1ToImage().

Referenced by dualForm1ToGreyLevelImage(), and dualForm1ToRGBColorImage().

◆ dualForm1ToRGBColorImage()

template<typename Calculus , typename Image >
void DGtal::functions::dec::dualForm1ToRGBColorImage ( const Calculus &  calculus,
const typename Calculus::DualForm1 &  v,
Image &  image,
Color  color,
double  cut_low = 0.0,
double  cut_up = 1.0,
int  pixel_size = 1 
)

Standard method to output a dual 1-form into a color image.

Displays the dual 1-form v in the given image. Scalar values of v are first cut up and low according to cut_low and cut_up, and then rescaled according to max and min value. If this value is belows 0.25, it is written in the image as a "line" of size pixel_size x 1 or 1 x pixel_size, depending on position, and of color color.

Parameters
calculusthe discrete exterior calculus containing the 1-form v.
vany dual 1-form defined in calculus.
[in,out]imagethe image where v is written.
colorthe color for displaying 1-forms below 0.25.
cut_lowevery value of u below is set to cut_low.
cut_upevery value of u above is set to cut_up.
pixel_sizeevery value of a 1-form is mapped into image as pixel_size x 1 pixels or 1 x pixel_size pixels.
Template Parameters
Calculusany discrete exterior calculus type.
Imageany image type (see concepts::CImage).

Definition at line 655 of file DECImageHelpers.h.

661  {
662  BOOST_CONCEPT_ASSERT(( concepts::CImage<Image> ));
663  // Threshold is 0.25 instead of 0.5 because an edge connecting
664  // two vertices with v=0 and v=1 should not belong to the
665  // discontinuity set.
666  dualForm1ToImage( calculus, v, image,
667  [color] ( double x ) { return color; },
668  [] ( double x ) { return x < 0.25; },
669  cut_low, cut_up, pixel_size );
670  }

References dualForm1ToImage().

◆ form1ToImage()

template<typename Calculus , typename Form1 , typename Image , typename Function , typename Predicate >
void DGtal::functions::dec::form1ToImage ( const Calculus &  calculus,
const Form1 &  v,
bool  primal,
Image &  image,
const Function &  functor,
const Predicate &  predicate,
double  cut_low = 0.0,
double  cut_up = 1.0,
int  pixel_size = 1 
)

Displays the primal or dual 1-form v in the given image. Scalar values of v are first cut up and low according to cut_low and cut_up, and then rescaled according to max and min value. Then these values are transformed to image values with the function functor. They are written in the image as "lines" of size pixel_size x 1 or 1 x pixel_size, depending on position and duality.

Parameters
calculusthe discrete exterior calculus containing the 1-form v.
vany primal 1-form defined in calculus if primal is true, otherwise a dual 1-form.
primaltells if v is a primal 1-form (true), or a dual 1-form (false).
[in,out]imagethe image where v is written.
functorthe function transforming scalar values to image values.
predicatethe predicate telling for a value if it must be displayed (returns true in this case).
cut_lowevery value of u below is set to cut_low.
cut_upevery value of u above is set to cut_up.
pixel_sizeevery value of a 1-form is mapped into image as pixel_size x 1 pixels or 1 x pixel_size pixels.
Template Parameters
Calculusany discrete exterior calculus type.
Form1either a primal 1-form if primal is true, or dual 1-form is primal is false.
Imageany image type (see concepts::CImage).
Functionany function type (double) -> typename Image::Value to convert form value to Image value.
Predicateany function type (double) -> bool to select 1-forms to display.

Definition at line 297 of file DECImageHelpers.h.

304  {
305  BOOST_CONCEPT_ASSERT(( concepts::CImage<Image> ));
306  typedef typename Calculus::Index Index;
307  typedef typename Calculus::SCell SCell;
308  typedef typename Calculus::Scalar Scalar;
309  typedef typename Calculus::KSpace KSpace;
310  typedef typename KSpace::Point Point;
311  typedef typename KSpace::Integer Integer;
312  double min_v = NumberTraits<Scalar>::castToDouble( v.myContainer[ 0 ] );
313  double max_v = min_v;
314  for ( Index index = 0; index < v.myContainer.rows(); index++)
315  {
316  double w = NumberTraits<Scalar>::castToDouble( v.myContainer[ index ] );
317  min_v = std::min( min_v, w );
318  max_v = std::max( max_v, w );
319  }
320  if ( min_v < cut_low ) min_v = cut_low;
321  if ( max_v > cut_up ) max_v = cut_up;
322  for ( Index index = 0; index < v.myContainer.rows(); index++)
323  {
324  SCell cell = v.getSCell( index );
325  double u = NumberTraits<Scalar>::castToDouble( v.myContainer[ index ] );
326  if ( ! predicate( u ) ) continue;
327  double w = std::min( cut_up, std::max( cut_low, u ) );
328  if ( min_v != max_v ) w = ( w - min_v ) / ( max_v - min_v );
329  Point kpt = calculus.myKSpace.sKCoords( cell );
330  if ( primal ) writePrimalLinel( image, kpt, functor( w ), pixel_size );
331  else writeDualLinel ( image, kpt, functor( w ), pixel_size );
332  }
333  }
void writePrimalLinel(Image &image, typename Image::Point pt, typename Image::Value val, int pixel_size=1)
void writeDualLinel(Image &image, typename Image::Point pt, typename Image::Value val, int pixel_size=1)

References writeDualLinel(), and writePrimalLinel().

Referenced by dualForm1ToImage(), and primalForm1ToImage().

◆ form2ToGreyLevelImage()

template<typename Calculus , typename AnyForm2 , typename Image >
void DGtal::functions::dec::form2ToGreyLevelImage ( const Calculus &  calculus,
const AnyForm2 &  u,
Image &  image,
double  cut_low = 0.0,
double  cut_up = 1.0,
int  pixel_size = 1 
)

Standard method to output a 2-form into a grey-level image.

Displays the 2-form u in the given image. Scalar values of u are first cut up and low according to cut_low and cut_up, and then rescaled according to max and min value. They are written in the image as grey-level "pixels" of size pixel_size x pixel_size.

Parameters
calculusthe discrete exterior calculus containing the 2-form u.
uany primal or dual 2-form defined in calculus.
[in,out]imagethe image where u is written.
cut_lowevery value of u below is set to cut_low.
cut_upevery value of u above is set to cut_up.
pixel_sizeevery value of a 2-form is mapped into image as pixel_size x pixel_size pixels.
Template Parameters
Calculusany discrete exterior calculus type.
AnyForm2either a primal 2-form type or a dual 2-form type of the given Calculus.
Imageany image type (see concepts::CImage).

Definition at line 505 of file DECImageHelpers.h.

511  {
512  BOOST_CONCEPT_ASSERT(( concepts::CImage<Image> ));
513  form2ToImage( calculus, u, image,
514  [] ( double x ) { return (unsigned char) ( round( x * 255.0 ) ); },
515  cut_low, cut_up, pixel_size );
516  }
void form2ToImage(const Calculus &calculus, const AnyForm2 &u, Image &image, const Function &functor, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)

References form2ToImage().

◆ form2ToImage()

template<typename Calculus , typename AnyForm2 , typename Image , typename Function >
void DGtal::functions::dec::form2ToImage ( const Calculus &  calculus,
const AnyForm2 &  u,
Image &  image,
const Function &  functor,
double  cut_low = 0.0,
double  cut_up = 1.0,
int  pixel_size = 1 
)

Displays the 2-form u in the given image. Scalar values of u are first cut up and low according to cut_low and cut_up, and then rescaled according to max and min value. Then these values are transformed to image values with the function functor. They are written in the image as "pixels" of size pixel_size x pixel_size.

Parameters
calculusthe discrete exterior calculus containing the 2-form u.
uany primal or dual 2-form defined in calculus.
[in,out]imagethe image where u is written.
functorthe function transforming scalar values to image values.
cut_lowevery value of u below is set to cut_low.
cut_upevery value of u above is set to cut_up.
pixel_sizeevery value of a 2-form is mapped into image as pixel_size x pixel_size pixels.
Template Parameters
Calculusany discrete exterior calculus type.
AnyForm2either a primal 2-form type or a dual 2-form type of the given Calculus.
Imageany image type (see concepts::CImage).
Functionany function type (double) -> typename Image::Value to convert form value to Image value.

Definition at line 237 of file DECImageHelpers.h.

243  {
244  BOOST_CONCEPT_ASSERT(( concepts::CImage<Image> ));
245  typedef typename Calculus::Index Index;
246  typedef typename Calculus::SCell SCell;
247  typedef typename Calculus::Scalar Scalar;
248  typedef typename Calculus::KSpace KSpace;
249  typedef typename KSpace::Point Point;
250  typedef typename KSpace::Integer Integer;
251  double min_u = NumberTraits<Scalar>::castToDouble( u.myContainer[ 0 ] );
252  double max_u = min_u;
253  for ( Index index = 0; index < u.myContainer.rows(); index++)
254  {
255  double v = NumberTraits<Scalar>::castToDouble( u.myContainer[ index ] );
256  min_u = std::min( min_u, v );
257  max_u = std::max( max_u, v );
258  }
259  if ( min_u < cut_low ) min_u = cut_low;
260  if ( max_u > cut_up ) max_u = cut_up;
261  for ( Index index = 0; index < u.myContainer.rows(); index++)
262  {
263  SCell cell = u.getSCell( index );
264  double v = NumberTraits<Scalar>::castToDouble( u.myContainer[ index ] );
265  double w = std::min( cut_up, std::max( cut_low, v ) );
266  if ( min_u != max_u ) w = ( w - min_u ) / ( max_u - min_u );
267  writePixel( image, calculus.myKSpace.sCoords( cell ), functor( w ), pixel_size );
268  }
269  }
void writePixel(Image &image, typename Image::Point pt, typename Image::Value val, int pixel_size=1)

References writePixel().

Referenced by form2ToGreyLevelImage().

◆ primalForm1ToGreyLevelImage()

template<typename Calculus , typename Image >
void DGtal::functions::dec::primalForm1ToGreyLevelImage ( const Calculus &  calculus,
const typename Calculus::PrimalForm1 &  v,
Image &  image,
double  cut_low = 0.0,
double  cut_up = 1.0,
int  pixel_size = 1 
)

Standard method to output a primal 1-form into a grey-level image.

Displays the primal 1-form v in the given image. Scalar values of v are first cut up and low according to cut_low and cut_up, and then rescaled according to max and min value. If this value is belows 0.25, it is written in the image as a "line" of size pixel_size x 1 or 1 x pixel_size, depending on position.

Parameters
calculusthe discrete exterior calculus containing the 1-form v.
vany primal 1-form defined in calculus.
[in,out]imagethe image where v is written.
cut_lowevery value of u below is set to cut_low.
cut_upevery value of u above is set to cut_up.
pixel_sizeevery value of a 1-form is mapped into image as pixel_size x 1 pixels or 1 x pixel_size pixels.
Template Parameters
Calculusany discrete exterior calculus type.
Imageany image type (see concepts::CImage).

Definition at line 539 of file DECImageHelpers.h.

545  {
546  BOOST_CONCEPT_ASSERT(( concepts::CImage<Image> ));
547  // Threshold is 0.25 instead of 0.5 because an edge connecting
548  // two vertices with v=0 and v=1 should not belong to the
549  // discontinuity set.
550  primalForm1ToImage( calculus, v, image,
551  [] ( double x ) { return (unsigned char) ( round( x * 255.0 ) ); },
552  [] ( double x ) { return x < 0.25; },
553  cut_low, cut_up, pixel_size );
554  }
void primalForm1ToImage(const Calculus &calculus, const typename Calculus::PrimalForm1 &v, Image &image, const Function &functor, const Predicate &predicate, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)

References primalForm1ToImage().

◆ primalForm1ToImage()

template<typename Calculus , typename Image , typename Function , typename Predicate >
void DGtal::functions::dec::primalForm1ToImage ( const Calculus &  calculus,
const typename Calculus::PrimalForm1 &  v,
Image &  image,
const Function &  functor,
const Predicate &  predicate,
double  cut_low = 0.0,
double  cut_up = 1.0,
int  pixel_size = 1 
)

Displays the primal 1-form v in the given image. Scalar values of v are first cut up and low according to cut_low and cut_up, and then rescaled according to max and min value. Then these values are transformed to image values with the function functor. They are written in the image as "lines" of size pixel_size x 1 or 1 x pixel_size, depending on position and duality.

Parameters
calculusthe discrete exterior calculus containing the 1-form v.
vany primal 1-form defined in calculus.
[in,out]imagethe image where v is written.
functorthe function transforming scalar values to image values.
predicatethe predicate telling for a value if it must be displayed (returns true in this case).
cut_lowevery value of u below is set to cut_low.
cut_upevery value of u above is set to cut_up.
pixel_sizeevery value of a 1-form is mapped into image as pixel_size x 1 pixels or 1 x pixel_size pixels.
Template Parameters
Calculusany discrete exterior calculus type.
Imageany image type (see concepts::CImage).
Functionany function type (double) -> typename Image::Value to convert form value to Image value.
Predicateany function type (double) -> bool to select 1-forms to display.

Definition at line 396 of file DECImageHelpers.h.

403  {
404  BOOST_CONCEPT_ASSERT(( concepts::CImage<Image> ));
405  form1ToImage( calculus, v, true, image, functor, predicate,
406  cut_low, cut_up, pixel_size );
407  }

References form1ToImage().

Referenced by primalForm1ToGreyLevelImage(), and primalForm1ToRGBColorImage().

◆ primalForm1ToRGBColorImage()

template<typename Calculus , typename Image >
void DGtal::functions::dec::primalForm1ToRGBColorImage ( const Calculus &  calculus,
const typename Calculus::PrimalForm1 &  v,
Image &  image,
Color  color,
double  cut_low = 0.0,
double  cut_up = 1.0,
int  pixel_size = 1 
)

Standard method to output a primal 1-form into a color image.

Displays the primal 1-form v in the given image. Scalar values of v are first cut up and low according to cut_low and cut_up, and then rescaled according to max and min value. If this value is belows 0.25, it is written in the image as a "line" of size pixel_size x 1 or 1 x pixel_size, depending on position, and of color color.

Parameters
calculusthe discrete exterior calculus containing the 1-form v.
vany primal 1-form defined in calculus.
[in,out]imagethe image where v is written.
colorthe color for displaying 1-forms below 0.25.
cut_lowevery value of u below is set to cut_low.
cut_upevery value of u above is set to cut_up.
pixel_sizeevery value of a 1-form is mapped into image as pixel_size x 1 pixels or 1 x pixel_size pixels.
Template Parameters
Calculusany discrete exterior calculus type.
Imageany image type (see concepts::CImage).

Definition at line 616 of file DECImageHelpers.h.

622  {
623  BOOST_CONCEPT_ASSERT(( concepts::CImage<Image> ));
624  // Threshold is 0.25 instead of 0.5 because an edge connecting
625  // two vertices with v=0 and v=1 should not belong to the
626  // discontinuity set.
627  primalForm1ToImage( calculus, v, image,
628  [color] ( double x ) { return color; },
629  [] ( double x ) { return x < 0.25; },
630  cut_low, cut_up, pixel_size );
631  }

References primalForm1ToImage().

◆ squaredDiagonal()

template<typename Calculus , DGtal::Dimension dim, DGtal::Duality duality>
DGtal::LinearOperator<Calculus, dim, duality, dim, duality> DGtal::functions::dec::squaredDiagonal ( const DGtal::KForm< Calculus, dim, duality > &  kform)

Builds a diagonal linear operator from a k-form and squares it. These operators arise naturally when differentiating with respect to another variable (e.g. d/dx (vx)^t (vx) = diag(v^2) x).

Parameters
[in]kformany kform v
Returns
the corresponding linear operator diag(v^2)
Template Parameters
Calculusany discrete exterior calculus.
dimthe dimension of the form.
dualityeither PRIMAL for a primal form or DUAL for a dual form.

Definition at line 118 of file DECImageHelpers.h.

119  {
120  auto v2 = kform;
121  squares( v2 );
122  return diagonal( v2 );
123  }
DGtal::LinearOperator< Calculus, dim, duality, dim, duality > diagonal(const DGtal::KForm< Calculus, dim, duality > &kform)
void squares(DGtal::KForm< Calculus, dim, duality > &kform)

References diagonal(), and squares().

◆ squares()

template<typename Calculus , DGtal::Dimension dim, DGtal::Duality duality>
void DGtal::functions::dec::squares ( DGtal::KForm< Calculus, dim, duality > &  kform)

Squares the given k-form.

Parameters
[in,out]kformany kform.
Template Parameters
Calculusany discrete exterior calculus.
dimthe dimension of the form.
dualityeither PRIMAL for a primal form or DUAL for a dual form.

Definition at line 99 of file DECImageHelpers.h.

100  {
101  kform.myContainer.array() = kform.myContainer.array().square();
102  }

Referenced by squaredDiagonal().

◆ threeForms2ToImage()

template<typename Calculus , typename AnyForm2 , typename Image , typename Function >
void DGtal::functions::dec::threeForms2ToImage ( const Calculus &  calculus,
const AnyForm2 &  u0,
const AnyForm2 &  u1,
const AnyForm2 &  u2,
Image &  image,
const Function &  functor,
double  cut_low = 0.0,
double  cut_up = 1.0,
int  pixel_size = 1 
)

Displays the three 2-forms u0, u1, u2 in the given image. Scalar values of u0, u1, u2 are first cut up and low according to cut_low and cut_up, and then rescaled according to max and min value. Then these values are transformed to image values with the function functor. They are written in the image as "pixels" of size pixel_size x pixel_size.

Parameters
calculusthe discrete exterior calculus containing the 2-forms u0, u1, u2.
u0any primal or dual 2-form defined in calculus.
u1any primal or dual 2-form defined in calculus.
u2any primal or dual 2-form defined in calculus.
[in,out]imagethe image where u is written.
functorthe function transforming three scalar values to image values.
cut_lowevery value of u0, u1, u2 below is set to cut_low.
cut_upevery value of u0, u1, u2 above is set to cut_up.
pixel_sizeevery value of 2-forms is mapped into image as pixel_size x pixel_size pixels.
Template Parameters
Calculusany discrete exterior calculus type.
AnyForm2either a primal 2-form type or a dual 2-form type of the given Calculus.
Imageany image type (see concepts::CImage).
Functionany function type (double,double,double) -> typename Image::Value to convert form value to Image value.

Definition at line 433 of file DECImageHelpers.h.

441  {
442  BOOST_CONCEPT_ASSERT(( concepts::CImage<Image> ));
443  typedef typename Calculus::Index Index;
444  typedef typename Calculus::SCell SCell;
445  typedef typename Calculus::Scalar Scalar;
446  double min_u = NumberTraits<Scalar>::castToDouble( u0.myContainer[ 0 ] );
447  double max_u = min_u;
448  for ( Index index = 0; index < u0.myContainer.rows(); index++)
449  {
450  double v = NumberTraits<Scalar>::castToDouble( u0.myContainer[ index ] );
451  min_u = std::min( min_u, v );
452  max_u = std::max( max_u, v );
453  }
454  for ( Index index = 0; index < u1.myContainer.rows(); index++)
455  {
456  double v = NumberTraits<Scalar>::castToDouble( u1.myContainer[ index ] );
457  min_u = std::min( min_u, v );
458  max_u = std::max( max_u, v );
459  }
460  for ( Index index = 0; index < u2.myContainer.rows(); index++)
461  {
462  double v = NumberTraits<Scalar>::castToDouble( u2.myContainer[ index ] );
463  min_u = std::min( min_u, v );
464  max_u = std::max( max_u, v );
465  }
466  if ( min_u < cut_low ) min_u = cut_low;
467  if ( max_u > cut_up ) max_u = cut_up;
468  for ( Index index = 0; index < u0.myContainer.rows(); index++)
469  {
470  SCell cell = u0.getSCell( index );
471  double v0 = NumberTraits<Scalar>::castToDouble( u0.myContainer[ index ] );
472  double w0 = std::min( cut_up, std::max( cut_low, v0 ) );
473  if ( min_u != max_u ) w0 = ( w0 - min_u ) / ( max_u - min_u );
474  double v1 = NumberTraits<Scalar>::castToDouble( u1.myContainer[ index ] );
475  double w1 = std::min( cut_up, std::max( cut_low, v1 ) );
476  if ( min_u != max_u ) w1 = ( w1 - min_u ) / ( max_u - min_u );
477  double v2 = NumberTraits<Scalar>::castToDouble( u2.myContainer[ index ] );
478  double w2 = std::min( cut_up, std::max( cut_low, v2 ) );
479  if ( min_u != max_u ) w2 = ( w2 - min_u ) / ( max_u - min_u );
480  writePixel( image, calculus.myKSpace.sCoords( cell ), functor( w0, w1, w2 ), pixel_size );
481  }
482  }

References writePixel().

Referenced by threeForms2ToRGBColorImage().

◆ threeForms2ToRGBColorImage()

template<typename Calculus , typename AnyForm2 , typename Image >
void DGtal::functions::dec::threeForms2ToRGBColorImage ( const Calculus &  calculus,
const AnyForm2 &  u0,
const AnyForm2 &  u1,
const AnyForm2 &  u2,
Image &  image,
double  cut_low = 0.0,
double  cut_up = 1.0,
int  pixel_size = 1 
)

Standard method to output three 2-forms into a RGB Color image.

Displays the three 2-forms u0, u1, u2 in the given image as RGB colors. Scalar values of u0, u1, u2 are first cut up and low according to cut_low and cut_up, and then rescaled according to max and min value. Then these values are transformed to RGB color image values (u0 defines the intensity of the red channel, u1 the green channel, u2, the blue channel). They are written in the image as "pixels" of size pixel_size x pixel_size.

Parameters
calculusthe discrete exterior calculus containing the 2-forms u0, u1, u2.
u0any primal or dual 2-form defined in calculus.
u1any primal or dual 2-form defined in calculus.
u2any primal or dual 2-form defined in calculus.
[in,out]imagethe image where u is written.
cut_lowevery value of u0, u1, u2 below is set to cut_low.
cut_upevery value of u0, u1, u2 above is set to cut_up.
pixel_sizeevery value of 2-forms is mapped into image as pixel_size x pixel_size pixels.
Template Parameters
Calculusany discrete exterior calculus type.
AnyForm2either a primal 2-form type or a dual 2-form type of the given Calculus.
Imageany image type (see concepts::CImage).

Definition at line 698 of file DECImageHelpers.h.

706  {
707  BOOST_CONCEPT_ASSERT(( concepts::CImage<Image> ));
709  ( calculus, u0, u1, u2, image,
710  [] ( double r, double g, double b )
711  { return Color( (unsigned char) ( round( r * 255.0 ) ),
712  (unsigned char) ( round( g * 255.0 ) ),
713  (unsigned char) ( round( b * 255.0 ) ) ); },
714  cut_low, cut_up, pixel_size );
715  }
void threeForms2ToImage(const Calculus &calculus, const AnyForm2 &u0, const AnyForm2 &u1, const AnyForm2 &u2, Image &image, const Function &functor, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)

References threeForms2ToImage().

◆ writeDualLinel()

template<typename Image >
void DGtal::functions::dec::writeDualLinel ( Image &  image,
typename Image::Point  pt,
typename Image::Value  val,
int  pixel_size = 1 
)

Considers an image image to have pixels of size pixel_size x pixel_size, and writes the value val at the specified linel position pt.

Parameters
[in,out]imageany image of sufficient size.
pta linel Khalimsky coordinates.
valthe value to write in pixel_size x 1 pixels (if horizontal) or 1 x pixel_size pixels (if vertical).
pixel_sizethe chosen pixel_size (when 1, this is the normal setValue of an image).
Template Parameters
Imageany image type (see concepts::CImage).

Definition at line 197 of file DECImageHelpers.h.

199  {
200  BOOST_CONCEPT_ASSERT(( concepts::CImage<Image> ));
201  typedef typename Image::Point Point;
202  typedef typename Point::Coordinate Coordinate;
203  int pixel_size_x = NumberTraits<Coordinate>::even( pt[ 0 ] ) ? 0 : pixel_size-1;
204  int pixel_size_y = NumberTraits<Coordinate>::even( pt[ 1 ] ) ? 0 : pixel_size-1;
205  pt /= 2;
206  pt *= pixel_size;
207  for ( int y = pixel_size_y; y < pixel_size; y++ )
208  for ( int x = pixel_size_x; x < pixel_size; x++ )
209  {
210  Point q( (Coordinate) x, (Coordinate) y );
211  image.setValue( pt + q, val );
212  }
213  }

Referenced by form1ToImage().

◆ writePixel()

template<typename Image >
void DGtal::functions::dec::writePixel ( Image &  image,
typename Image::Point  pt,
typename Image::Value  val,
int  pixel_size = 1 
)

Considers an image image to have pixels of size pixel_size x pixel_size, and writes the value val at the specified pixel position pt.

Parameters
[in,out]imageany image of sufficient size.
pta pixel coordinate (which is multiplied by pixel_size within).
valthe value to write in pixel_size x pixel_size pixels.
pixel_sizethe chosen pixel_size (when 1, this is the normal setValue of an image).
Template Parameters
Imageany image type (see concepts::CImage).

Definition at line 138 of file DECImageHelpers.h.

140  {
141  BOOST_CONCEPT_ASSERT(( concepts::CImage<Image> ));
142  typedef typename Image::Point Point;
143  typedef typename Point::Coordinate Coordinate;
144  pt *= pixel_size;
145  for ( int y = 0; y < pixel_size; y++ )
146  for ( int x = 0; x < pixel_size; x++ )
147  {
148  Point q( (Coordinate) x, (Coordinate) y );
149  image.setValue( pt + q, val );
150  }
151  }

Referenced by form2ToImage(), and threeForms2ToImage().

◆ writePrimalLinel()

template<typename Image >
void DGtal::functions::dec::writePrimalLinel ( Image &  image,
typename Image::Point  pt,
typename Image::Value  val,
int  pixel_size = 1 
)

Considers an image image to have pixels of size pixel_size x pixel_size, and writes the value val at the specified linel position pt.

Parameters
[in,out]imageany image of sufficient size.
pta linel Khalimsky coordinates.
valthe value to write in pixel_size x 1 pixels (if horizontal) or 1 x pixel_size pixels (if vertical).
pixel_sizethe chosen pixel_size (when 1, this is the normal setValue of an image).
Template Parameters
Imageany image type (see concepts::CImage).

Definition at line 166 of file DECImageHelpers.h.

168  {
169  BOOST_CONCEPT_ASSERT(( concepts::CImage<Image> ));
170  typedef typename Image::Point Point;
171  typedef typename Point::Coordinate Coordinate;
172  int pixel_size_x = NumberTraits<Coordinate>::even( pt[ 0 ] ) ? 1 : pixel_size;
173  int pixel_size_y = NumberTraits<Coordinate>::even( pt[ 1 ] ) ? 1 : pixel_size;
174  pt /= 2;
175  pt *= pixel_size;
176  for ( int y = 0; y < pixel_size_y; y++ )
177  for ( int x = 0; x < pixel_size_x; x++ )
178  {
179  Point q( (Coordinate) x, (Coordinate) y );
180  image.setValue( pt + q, val );
181  }
182  }

Referenced by form1ToImage().