homog2d library
Classes | Enumerations | Functions
h2d::img Namespace Reference

Holds drawing related code, independent of back-end library. More...

Classes

struct  Color
 Color type , see DrawParams. More...
 
class  DrawParams
 Draw parameters, independent of back-end library. More...
 
class  Image
 Opaque data structure, will hold the image type, depending on back-end library. This type is the one used in all the drawing functions. More...
 
struct  SvgImage
 A svg image as a wrapper around a string, see manual, "Drawing things" section. More...
 

Enumerations

enum  PtStyle : uint8_t {
  PtStyle::Plus, PtStyle::Times, PtStyle::Star, PtStyle::Diam,
  PtStyle::Squ, PtStyle::Dot
}
 Point drawing style, see DrawParams. More...
 

Functions

std::vector< img::ColorgenRandomColors (size_t nb, int minval=20, int maxval=250)
 Helper function, will generate a vector of nb random RGB colors. More...
 
const char * getString (PtStyle t)
 
std::ostream & operator<< (std::ostream &f, const Image< SvgImage > &im)
 Streaming operator (only defined for SVG) More...
 

Detailed Description

Holds drawing related code, independent of back-end library.

Enumeration Type Documentation

◆ PtStyle

enum h2d::img::PtStyle : uint8_t
strong

Point drawing style, see DrawParams.

Demo: https://github.com/skramm/homog2d/blob/master/docs/homog2d_manual.md#drawing_params

Warning
Check nextPointStyle() in case of added values here!
Enumerator
Plus 

+ symbol

Times 

X symbol

Star 

* symbol

Diam 

diamond

Squ 

square (new 20241101 !)

Dot 

dot (circle)

484  : uint8_t
485 {
486  Plus,
487  Times,
488  Star,
489  Diam,
490  Squ,
491  Dot
492 };
square (new 20241101 !)

Function Documentation

◆ genRandomColors()

std::vector<img::Color> h2d::img::genRandomColors ( size_t  nb,
int  minval = 20,
int  maxval = 250 
)
inline

Helper function, will generate a vector of nb random RGB colors.

  • RGB values will be between minval and minval+coeff
454 {
455  if( maxval<=minval )
456  HOMOG2D_THROW_ERROR_1( "Illegal values for minval and maxval" );
457  std::vector<img::Color> vcol( nb );
458  std::srand( std::time(nullptr) );
459 
460  for( size_t i=0; i<nb; i++ )
461  {
462  auto colR = 1.0*std::rand() / RAND_MAX * (maxval-minval) + minval;
463  auto colG = 1.0*std::rand() / RAND_MAX * (maxval-minval) + minval;
464  auto colB = 1.0*std::rand() / RAND_MAX * (maxval-minval) + minval;
465  vcol[i] = img::Color(colR,colG,colB);
466  }
467  return vcol;
468 }
#define HOMOG2D_THROW_ERROR_1(msg)
Error throw wrapper macro.
Definition: homog2d.hpp:181
Here is the caller graph for this function:

◆ getString()

const char* h2d::img::getString ( PtStyle  t)
inline
497 {
498  const char* s=0;
499  switch( t )
500  {
501  case PtStyle::Plus: s="Plus"; break;
502  case PtStyle::Times: s="Times"; break;
503  case PtStyle::Star: s="Star"; break;
504  case PtStyle::Diam: s="Diam"; break;
505  case PtStyle::Squ: s="Square";break;
506  case PtStyle::Dot: s="Dot"; break; // WARNING: keep this as last one (assumed to be last one in some code)
507  default: assert(0);
508  }
509  return s;
510 }
Here is the caller graph for this function:

◆ operator<<()

std::ostream& h2d::img::operator<< ( std::ostream &  f,
const Image< SvgImage > &  im 
)
inline

Streaming operator (only defined for SVG)

12018 {
12019  f << "<svg version=\"1.1\" width=\"" << im._width
12020  << "\" height=\"" << im._height
12021  << "\" style=\"background-color:white;\" xmlns=\"http://www.w3.org/2000/svg\">\n"
12022  << "<style>\n"
12023  << ".txt1 { font: bold 12px sans-serif; };\n" // text style, you can change or add classes as required
12024  << "</style>\n";
12025 
12026  f << im._realImg._svgString.str();
12027  f << "</svg>\n";
12028 
12029  return f;
12030 }
img::Image< img::SvgImage > im(300, 400)