C++ Bitmap Library  release
Public Member Functions | List of all members
cartesian_canvas Class Reference

#include <bitmap_image.hpp>

Public Member Functions

 cartesian_canvas (const double x_length, const double y_length)
 
bool operator! ()
 
void rectangle (double x1, double y1, double x2, double y2)
 
void triangle (double x1, double y1, double x2, double y2, double x3, double y3)
 
void quadix (double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
 
void line_segment (double x1, double y1, double x2, double y2)
 
void horiztonal_line_segment (double x1, double x2, double y)
 
void vertical_line_segment (double y1, double y2, double x)
 
void ellipse (double centerx, double centery, double a, double b)
 
void circle (double centerx, double centery, double radius)
 
void fill_rectangle (double x1, double y1, double x2, double y2)
 
void fill_triangle (double x1, double y1, double x2, double y2, double x3, double y3)
 
void fill_quadix (double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
 
void fill_circle (double cx, double cy, double radius)
 
void plot_pen_pixel (double x, double y)
 
void plot_pixel (double x, double y)
 
void pen_width (const unsigned int &width)
 
void pen_color (const unsigned char &red, const unsigned char &green, const unsigned char &blue)
 
template<typename RGB >
void pen_color (const RGB colour)
 
const bitmap_imageimage () const
 
bitmap_imageimage ()
 
void set_widthheight (const double x_length, const double y_length)
 
double min_x () const
 
double min_y () const
 
double max_x () const
 
double max_y () const
 

Detailed Description

Definition at line 2379 of file bitmap_image.hpp.

Constructor & Destructor Documentation

◆ cartesian_canvas()

cartesian_canvas::cartesian_canvas ( const double  x_length,
const double  y_length 
)
inline

Definition at line 2383 of file bitmap_image.hpp.

2384  : width_div2_ (0.0),
2385  height_div2_(0.0),
2386  min_x_ (0.0),
2387  min_y_ (0.0),
2388  max_x_ (0.0),
2389  max_y_ (0.0),
2390  draw_ (image_)
2391  {
2392  setup_canvas(x_length,y_length);
2393  }

Member Function Documentation

◆ circle()

void cartesian_canvas::circle ( double  centerx,
double  centery,
double  radius 
)
inline

Definition at line 2471 of file bitmap_image.hpp.

Referenced by test19().

2472  {
2473  const int sc_cx = static_cast<int>(cart_to_screen_x(centerx));
2474  const int sc_cy = static_cast<int>(cart_to_screen_y(centery));
2475 
2476  draw_.circle(sc_cx, sc_cy, static_cast<int>(radius));
2477  }
void circle(int centerx, int centery, int radius)
Here is the caller graph for this function:

◆ ellipse()

void cartesian_canvas::ellipse ( double  centerx,
double  centery,
double  a,
double  b 
)
inline

Definition at line 2462 of file bitmap_image.hpp.

2463  {
2464 
2465  const int sc_cx = static_cast<int>(cart_to_screen_x(centerx));
2466  const int sc_cy = static_cast<int>(cart_to_screen_y(centery));
2467 
2468  draw_.ellipse(sc_cx, sc_cy, static_cast<int>(a), static_cast<int>(b));
2469  }
void ellipse(int centerx, int centery, int a, int b)

◆ fill_circle()

void cartesian_canvas::fill_circle ( double  cx,
double  cy,
double  radius 
)
inline

Definition at line 2590 of file bitmap_image.hpp.

2591  {
2592  const double delta = 1.0;
2593  double x = radius;
2594  double y = 0.0;
2595  double dx = delta - (2.0 * delta * radius);
2596  double dy = 0.0;
2597  double dr = 0.0;
2598 
2599  while (x >= y)
2600  {
2601  for (double i = cx - x; i <= cx + x; i += delta)
2602  {
2603  horiztonal_line_segment(cx - x, cx + x, cy + y);
2604  horiztonal_line_segment(cx - x, cx + x, cy - y);
2605  }
2606 
2607  for (double i = cx - y; i <= cx + y; i += delta)
2608  {
2609  horiztonal_line_segment(cx - y, cx + y, cy + x);
2610  horiztonal_line_segment(cx - y, cx + y, cy - x);
2611  }
2612 
2613  y += delta;
2614 
2615  dr += dy;
2616  dy += 2.0 * delta;
2617 
2618  if ((2.0 * delta * dr + dx) > 0)
2619  {
2620  x -= delta;
2621  dr += dx;
2622  dx += 2.0 * delta;
2623  }
2624  }
2625  }
void horiztonal_line_segment(double x1, double x2, double y)

◆ fill_quadix()

void cartesian_canvas::fill_quadix ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3,
double  x4,
double  y4 
)
inline

Definition at line 2584 of file bitmap_image.hpp.

2585  {
2586  fill_triangle(x1, y1, x2, y2, x3, y3);
2587  fill_triangle(x1, y1, x3, y3, x4, y4);
2588  }
void fill_triangle(double x1, double y1, double x2, double y2, double x3, double y3)

◆ fill_rectangle()

void cartesian_canvas::fill_rectangle ( double  x1,
double  y1,
double  x2,
double  y2 
)
inline

Definition at line 2479 of file bitmap_image.hpp.

2480  {
2481  if (y1 > y2)
2482  std::swap(y1, y2);
2483 
2484  for (double y = y1; y <= y2; y += 0.5)
2485  {
2486  line_segment(x1, y, x2, y);
2487  }
2488  }
void line_segment(double x1, double y1, double x2, double y2)

◆ fill_triangle()

void cartesian_canvas::fill_triangle ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3 
)
inline

Definition at line 2490 of file bitmap_image.hpp.

References horiztonal_line_segment(), and bitmap_image::operator=().

2491  {
2492  typedef std::pair<double,double> point_t;
2493 
2494  std::vector<point_t> p;
2495 
2496  p.push_back(std::make_pair(x1,y1));
2497  p.push_back(std::make_pair(x2,y2));
2498  p.push_back(std::make_pair(x3,y3));
2499 
2500  if (p[0].second > p[1].second)
2501  std::swap(p[0],p[1]);
2502  if (p[0].second > p[2].second)
2503  std::swap(p[0],p[2]);
2504  if (p[1].second > p[2].second)
2505  std::swap(p[1],p[2]);
2506 
2507  class draw_modes
2508  {
2509  private:
2510 
2511  cartesian_canvas& canvas;
2512 
2513  // Needed for incompetent and broken msvc compiler versions
2514  #ifdef _MSC_VER
2515  #pragma warning(push)
2516  #pragma warning(disable: 4822)
2517  #endif
2518  draw_modes& operator=(const draw_modes&);
2519  #ifdef _MSC_VER
2520  #pragma warning(pop)
2521  #endif
2522 
2523  public:
2524 
2525  draw_modes(cartesian_canvas& c)
2526  : canvas(c)
2527  {}
2528 
2529  void bottom(const point_t& p0, const point_t& p1, const point_t& p2)
2530  {
2531  double m0 = (p1.first - p0.first) / (2.0 * (p1.second - p0.second));
2532  double m1 = (p2.first - p0.first) / (2.0 * (p2.second - p0.second));
2533 
2534  double x0 = p0.first;
2535  double x1 = p0.first;
2536 
2537  for (double y = p0.second; y <= p1.second; y += 0.5)
2538  {
2539  canvas.horiztonal_line_segment(x0, x1, y);
2540 
2541  x0 += m0;
2542  x1 += m1;
2543  }
2544  }
2545 
2546  void top(const point_t& p0, const point_t& p1, const point_t& p2)
2547  {
2548  double m0 = (p2.first - p0.first) / (2.0 * (p2.second - p0.second));
2549  double m1 = (p2.first - p1.first) / (2.0 * (p2.second - p1.second));
2550 
2551  double x0 = p2.first;
2552  double x1 = p2.first;
2553 
2554  for (double y = p2.second; y >= p0.second; y -= 0.5)
2555  {
2556  canvas.horiztonal_line_segment(x0, x1, y);
2557 
2558  x0 -= m0;
2559  x1 -= m1;
2560  }
2561  }
2562  };
2563 
2564  draw_modes dm(*this);
2565 
2566  const double eps = 0.00001;
2567 
2568  if (std::abs(p[1].second - p[2].second) < eps)
2569  dm.bottom(p[0], p[1], p[2]);
2570  else if (std::abs(p[0].second - p[1].second) < eps)
2571  dm.top(p[0], p[1], p[2]);
2572  else
2573  {
2574  point_t p3;
2575 
2576  p3.first = (p[0].first + ((p[1].second - p[0].second) / (p[2].second - p[0].second)) * (p[2].first - p[0].first));
2577  p3.second = p[1].second;
2578 
2579  dm.bottom(p[0], p[1], p3);
2580  dm.top (p[1], p3, p[2]);
2581  }
2582  }
void horiztonal_line_segment(double x1, double x2, double y)
Here is the call graph for this function:

◆ horiztonal_line_segment()

void cartesian_canvas::horiztonal_line_segment ( double  x1,
double  x2,
double  y 
)
inline

Definition at line 2436 of file bitmap_image.hpp.

Referenced by fill_triangle(), and test19().

2437  {
2438  x1 = clamp_x(x1);
2439  x2 = clamp_x(x2);
2440  y = clamp_y( y);
2441 
2442  const int sc_x1 = static_cast<int>(cart_to_screen_x(x1));
2443  const int sc_x2 = static_cast<int>(cart_to_screen_x(x2));
2444  const int sc_y = static_cast<int>(cart_to_screen_y(y ));
2445 
2446  draw_.horiztonal_line_segment(sc_x1, sc_x2, sc_y);
2447  }
void horiztonal_line_segment(int x1, int x2, int y)
Here is the caller graph for this function:

◆ image() [1/2]

const bitmap_image& cartesian_canvas::image ( ) const
inline

Definition at line 2667 of file bitmap_image.hpp.

Referenced by test19().

2668  {
2669  return image_;
2670  }
Here is the caller graph for this function:

◆ image() [2/2]

bitmap_image& cartesian_canvas::image ( )
inline

Definition at line 2672 of file bitmap_image.hpp.

2673  {
2674  return image_;
2675  }

◆ line_segment()

void cartesian_canvas::line_segment ( double  x1,
double  y1,
double  x2,
double  y2 
)
inline

Definition at line 2423 of file bitmap_image.hpp.

Referenced by test19().

2424  {
2425  if (clip(x1, y1, x2, y2))
2426  {
2427  const int sc_x1 = static_cast<int>(cart_to_screen_x(x1));
2428  const int sc_x2 = static_cast<int>(cart_to_screen_x(x2));
2429  const int sc_y1 = static_cast<int>(cart_to_screen_y(y1));
2430  const int sc_y2 = static_cast<int>(cart_to_screen_y(y2));
2431 
2432  draw_.line_segment(sc_x1, sc_y1, sc_x2, sc_y2);
2433  }
2434  }
void line_segment(int x1, int y1, int x2, int y2)
Here is the caller graph for this function:

◆ max_x()

double cartesian_canvas::max_x ( ) const
inline

Definition at line 2684 of file bitmap_image.hpp.

Referenced by test19().

2684 { return max_x_; }
Here is the caller graph for this function:

◆ max_y()

double cartesian_canvas::max_y ( ) const
inline

Definition at line 2685 of file bitmap_image.hpp.

References bitmap_image::operator=().

Referenced by test19().

2685 { return max_y_; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ min_x()

double cartesian_canvas::min_x ( ) const
inline

Definition at line 2682 of file bitmap_image.hpp.

Referenced by test19().

2682 { return min_x_; }
Here is the caller graph for this function:

◆ min_y()

double cartesian_canvas::min_y ( ) const
inline

Definition at line 2683 of file bitmap_image.hpp.

Referenced by test19().

2683 { return min_y_; }
Here is the caller graph for this function:

◆ operator!()

bool cartesian_canvas::operator! ( )
inline

Definition at line 2395 of file bitmap_image.hpp.

2396  {
2397  return !image_;
2398  }

◆ pen_color() [1/2]

void cartesian_canvas::pen_color ( const unsigned char &  red,
const unsigned char &  green,
const unsigned char &  blue 
)
inline

Definition at line 2654 of file bitmap_image.hpp.

Referenced by test19().

2657  {
2658  draw_.pen_color(red,green,blue);
2659  }
void pen_color(const unsigned char &red, const unsigned char &green, const unsigned char &blue)
Here is the caller graph for this function:

◆ pen_color() [2/2]

template<typename RGB >
void cartesian_canvas::pen_color ( const RGB  colour)
inline

Definition at line 2662 of file bitmap_image.hpp.

2663  {
2664  draw_.pen_color(colour);
2665  }
void pen_color(const unsigned char &red, const unsigned char &green, const unsigned char &blue)

◆ pen_width()

void cartesian_canvas::pen_width ( const unsigned int &  width)
inline

Definition at line 2649 of file bitmap_image.hpp.

Referenced by test19().

2650  {
2651  draw_.pen_width(width);
2652  }
void pen_width(const unsigned int &width)
Here is the caller graph for this function:

◆ plot_pen_pixel()

void cartesian_canvas::plot_pen_pixel ( double  x,
double  y 
)
inline

Definition at line 2627 of file bitmap_image.hpp.

2628  {
2629  if ((x < min_x_) || (x > max_x_)) return;
2630  if ((y < min_y_) || (y > max_y_)) return;
2631 
2632  const int sc_x = static_cast<int>(cart_to_screen_x(x));
2633  const int sc_y = static_cast<int>(cart_to_screen_y(y));
2634 
2635  draw_.plot_pen_pixel(sc_x, sc_y);
2636  }
void plot_pen_pixel(int x, int y)

◆ plot_pixel()

void cartesian_canvas::plot_pixel ( double  x,
double  y 
)
inline

Definition at line 2638 of file bitmap_image.hpp.

2639  {
2640  if ((x < min_x_) || (x > max_x_)) return;
2641  if ((y < min_y_) || (y > max_y_)) return;
2642 
2643  const int sc_x = static_cast<int>(cart_to_screen_x(x));
2644  const int sc_y = static_cast<int>(cart_to_screen_y(y));
2645 
2646  draw_.plot_pixel(sc_x, sc_y);
2647  }
void plot_pixel(int x, int y)

◆ quadix()

void cartesian_canvas::quadix ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3,
double  x4,
double  y4 
)
inline

Definition at line 2415 of file bitmap_image.hpp.

2416  {
2417  line_segment(x1, y1, x2, y2);
2418  line_segment(x2, y2, x3, y3);
2419  line_segment(x3, y3, x4, y4);
2420  line_segment(x4, y4, x1, y1);
2421  }
void line_segment(double x1, double y1, double x2, double y2)

◆ rectangle()

void cartesian_canvas::rectangle ( double  x1,
double  y1,
double  x2,
double  y2 
)
inline

Definition at line 2400 of file bitmap_image.hpp.

Referenced by test19().

2401  {
2402  line_segment(x1, y1, x2, y1);
2403  line_segment(x2, y1, x2, y2);
2404  line_segment(x2, y2, x1, y2);
2405  line_segment(x1, y2, x1, y1);
2406  }
void line_segment(double x1, double y1, double x2, double y2)
Here is the caller graph for this function:

◆ set_widthheight()

void cartesian_canvas::set_widthheight ( const double  x_length,
const double  y_length 
)
inline

Definition at line 2677 of file bitmap_image.hpp.

2678  {
2679  setup_canvas(x_length, y_length);
2680  }

◆ triangle()

void cartesian_canvas::triangle ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3 
)
inline

Definition at line 2408 of file bitmap_image.hpp.

2409  {
2410  line_segment(x1, y1, x2, y2);
2411  line_segment(x2, y2, x3, y3);
2412  line_segment(x3, y3, x1, y1);
2413  }
void line_segment(double x1, double y1, double x2, double y2)

◆ vertical_line_segment()

void cartesian_canvas::vertical_line_segment ( double  y1,
double  y2,
double  x 
)
inline

Definition at line 2449 of file bitmap_image.hpp.

2450  {
2451  y1 = clamp_y(y1);
2452  y2 = clamp_y(y2);
2453  x = clamp_x( x);
2454 
2455  const int sc_y1 = static_cast<int>(cart_to_screen_y(y1));
2456  const int sc_y2 = static_cast<int>(cart_to_screen_y(y2));
2457  const int sc_x = static_cast<int>(cart_to_screen_x(x ));
2458 
2459  draw_.vertical_line_segment(sc_y1, sc_y2, sc_x);
2460  }
void vertical_line_segment(int y1, int y2, int x)

The documentation for this class was generated from the following file: