biped-stabilizer 1.5.0
Stabilizer for Biped Locomotion
Loading...
Searching...
No Matches
wykobi_graphics_vcl.hpp
Go to the documentation of this file.
1/*
2(***********************************************************************)
3(* *)
4(* Wykobi Computational Geometry Library *)
5(* Release Version 0.0.5 *)
6(* http://www.wykobi.com *)
7(* Copyright (c) 2005-2017 Arash Partow, All Rights Reserved. *)
8(* *)
9(* The Wykobi computational geometry library and its components are *)
10(* supplied under the terms of the open source MIT License. *)
11(* The contents of the Wykobi computational geometry library and its *)
12(* components may not be copied or disclosed except in accordance with *)
13(* the terms of the MIT License. *)
14(* *)
15(* URL: https://opensource.org/licenses/MIT *)
16(* *)
17(***********************************************************************)
18*/
19
20#ifndef INCLUDE_WYKOBI_GRAPHICS_VCL
21#define INCLUDE_WYKOBI_GRAPHICS_VCL
22
23#include <Graphics.hpp>
24#include <cmath>
25#include <iostream>
26#include <iterator>
27#include <string>
28#include <vector>
29
30#include "wykobi.hpp"
31
32namespace wykobi {
33template <typename T>
35 public:
36 wykobi_graphics_vcl(TCanvas* c, unsigned int w, unsigned int h)
37 : canvas(c), _width(w), _height(h), color(clBlack) {
38 canvas->Brush->Style = bsClear;
39 }
40
42
43 inline void set_pen(TPen* p) { canvas->Pen = p; }
44 inline void set_brush(TBrush* b) { canvas->Brush = b; }
45 inline void set_color(TColor c) { canvas->Pen->Color = c; }
46 inline void set_width(unsigned int w) { _width = w; }
47 inline void set_height(unsigned int h) { _height = h; }
48 inline TPen* get_pen() { return canvas->Pen; }
49 inline unsigned int width() const { return _width; }
50 inline unsigned int height() const { return _height; }
51 inline unsigned int center_x() const { return _width * 0.5; }
52 inline unsigned int center_y() const { return _height * 0.5; }
53
54 inline void set_pen_width(int w) { canvas->Pen->Width = w; }
55
56 inline void draw_text(const T& x, const T& y, std::string text) {
57 AnsiString s = text.c_str();
58 canvas->TextOut(static_cast<int>(x), static_cast<int>(y), s);
59 }
60
61 inline void draw_pixel(const T& x, const T& y) const {
62 canvas->Pixels[static_cast<int>(x)][static_cast<int>(y)] =
63 canvas->Pen->Color;
64 }
65
66 inline void draw_pixel(const point2d<T>& point) const {
67 canvas->MoveTo(static_cast<int>(point.x), static_cast<int>(point.y));
68 canvas->LineTo(static_cast<int>(point.x + 1),
69 static_cast<int>(point.y + 1));
70 }
71
72 inline void draw_segment(const T& x1, const T& y1, const T& x2,
73 const T& y2) const {
74 canvas->MoveTo(static_cast<int>(x1), static_cast<int>(y1));
75 canvas->LineTo(static_cast<int>(x2), static_cast<int>(y2));
76 }
77
78 inline void draw_line(const T& x1, const T& y1, const T& x2,
79 const T& y2) const {
80 T dx = x2 - x1;
81 T dy = y2 - y1;
82
83 if (dx != 0.0) {
84 T m = dy / dx;
85 T c = y1 - m * x1;
86 draw_segment(0.0, c, _width, m * _width + c);
87 } else
88 draw_segment(x1, 0, x1, _height);
89 }
90
91 inline void draw_triangle(const T& x1, const T& y1, const T& x2, const T& y2,
92 const T& x3, const T& y3) const {
93 draw_segment(x1, y1, x2, y2);
94 draw_segment(x2, y2, x3, y3);
95 draw_segment(x3, y3, x1, y1);
96 }
97
98 inline void draw_quadix(const T& x1, const T& y1, const T& x2, const T& y2,
99 const T& x3, const T& y3, const T& x4,
100 const T& y4) const {
101 draw_segment(x1, y1, x2, y2);
102 draw_segment(x2, y2, x3, y3);
103 draw_segment(x3, y3, x4, y4);
104 draw_segment(x4, y4, x1, y1);
105 }
106
107 inline void draw_rectangle(const T x1, const T& y1, const T& x2,
108 const T& y2) const {
109 canvas->Rectangle(static_cast<int>(x1), static_cast<int>(y1),
110 static_cast<int>(x2), static_cast<int>(y2));
111 }
112
113 inline void draw_circle(const T x, const T& y, const T& radius) const {
114 canvas->Ellipse(static_cast<int>(x - radius), static_cast<int>(y - radius),
115 static_cast<int>(x + radius), static_cast<int>(y + radius));
116 }
117
118 inline void draw_segment(const point2d<T>& point1,
119 const point2d<T>& point2) const {
120 draw_segment(point1.x, point1.y, point2.x, point2.y);
121 }
122
123 inline void draw_line(const point2d<T>& point1,
124 const point2d<T>& point2) const {
125 draw_line(point1.x, point1.y, point2.x, point2.y);
126 }
127
128 inline void draw_triangle(const point2d<T>& point1, const point2d<T>& point2,
129 const point2d<T>& point3) const {
130 draw_triangle(point1.x, point1.y, point2.x, point2.y, point3.x, point3.y);
131 }
132
133 inline void draw_quadix(const point2d<T>& point1, const point2d<T>& point2,
134 const point2d<T>& point3,
135 const point2d<T>& point4) const {
136 draw_quadix(point1.x, point1.y, point2.x, point2.y, point3.x, point3.y,
137 point4.x, point4.y);
138 }
139
140 inline void draw_rectangle(const point2d<T>& point1,
141 const point2d<T>& point2) const {
142 draw_rectangle(point1.x, point1.y, point2.x, point2.y);
143 }
144
145 inline void draw_circle(const point2d<T>& point, const T& radius) const {
146 draw_circle(point.x, point.y, radius);
147 }
148
149 inline void draw_polyline(std::vector<point2d<T> > point_list) {
150 for (std::size_t i = 0; i < point_list.size() - 1; ++i) {
151 draw_segment(point_list[i], point_list[i + 1]);
152 }
153 }
154
155 inline void clear(TColor color) {
156 TColor TmpBrushColor = canvas->Brush->Color;
157 TBrushStyle TmpBrushStyle = canvas->Brush->Style;
158
159 canvas->Brush->Style = bsSolid;
160 canvas->Brush->Color = color;
161 canvas->FillRect(Rect(0, 0, _width, _height));
162 canvas->Brush->Color = TmpBrushColor;
163 canvas->Brush->Style = TmpBrushStyle;
164 }
165
166 inline void clear_white() { clear(clWhite); }
167 inline void clear_black() { clear(clBlack); }
168
169 inline void draw(const point2d<T>& point) { draw_pixel(point); }
170 inline void draw(const segment<T, 2>& segment) {
172 }
173 inline void draw(const line<T, 2>& line) { draw_line(line[0], line[1]); }
174 inline void draw(const triangle<T, 2>& triangle) {
176 }
177 inline void draw(const rectangle<T>& rectangle) {
179 }
180 inline void draw(const quadix<T, 2>& quadix) {
181 draw_quadix(quadix[0], quadix[1], quadix[2], quadix[3]);
182 }
183 inline void draw(const circle<T>& circle) {
185 }
186
187 inline void draw(const polygon<T, 2>& polygon) {
188 if (polygon.size() < 3) return;
189
190 std::size_t j = polygon.size() - 1;
191
192 for (std::size_t i = 0; i < polygon.size(); ++i) {
194 j = i;
195 }
196 }
197
198 inline void draw(const cubic_bezier<T, 2>& bezier,
199 const std::size_t& point_count) {
200 std::vector<point2d<T> > point_list;
201 wykobi::generate_bezier(bezier, point_count, point_list);
202 draw_polyline(point_list);
203 }
204
205 inline void draw(const quadratic_bezier<T, 2>& bezier,
206 const std::size_t& point_count) {
207 std::vector<point2d<T> > point_list;
208 wykobi::generate_bezier(bezier, point_count, point_list);
209 draw_polyline(point_list);
210 }
211
212 private:
213 TCanvas* canvas;
214 unsigned int _width;
215 unsigned int _height;
216 TColor color;
217};
218} // namespace wykobi
219
220#endif
Definition wykobi.hpp:426
T y
Definition wykobi.hpp:428
T x
Definition wykobi.hpp:428
T radius
Definition wykobi.hpp:428
Definition wykobi.hpp:493
Definition wykobi.hpp:287
Definition wykobi.hpp:74
T x
Definition wykobi.hpp:104
T y
Definition wykobi.hpp:104
Definition wykobi.hpp:383
std::size_t size() const
Definition wykobi.hpp:412
Definition wykobi.hpp:359
Definition wykobi.hpp:468
Definition wykobi.hpp:335
Definition wykobi.hpp:263
Definition wykobi.hpp:311
void draw_triangle(const T &x1, const T &y1, const T &x2, const T &y2, const T &x3, const T &y3) const
Definition wykobi_graphics_vcl.hpp:91
void draw_quadix(const T &x1, const T &y1, const T &x2, const T &y2, const T &x3, const T &y3, const T &x4, const T &y4) const
Definition wykobi_graphics_vcl.hpp:98
void draw_rectangle(const T x1, const T &y1, const T &x2, const T &y2) const
Definition wykobi_graphics_vcl.hpp:107
void draw_text(const T &x, const T &y, std::string text)
Definition wykobi_graphics_vcl.hpp:56
void draw(const point2d< T > &point)
Definition wykobi_graphics_vcl.hpp:169
void set_width(unsigned int w)
Definition wykobi_graphics_vcl.hpp:46
void set_color(TColor c)
Definition wykobi_graphics_vcl.hpp:45
void set_brush(TBrush *b)
Definition wykobi_graphics_vcl.hpp:44
~wykobi_graphics_vcl()
Definition wykobi_graphics_vcl.hpp:41
void draw_line(const T &x1, const T &y1, const T &x2, const T &y2) const
Definition wykobi_graphics_vcl.hpp:78
void draw_rectangle(const point2d< T > &point1, const point2d< T > &point2) const
Definition wykobi_graphics_vcl.hpp:140
unsigned int center_x() const
Definition wykobi_graphics_vcl.hpp:51
void draw(const segment< T, 2 > &segment)
Definition wykobi_graphics_vcl.hpp:170
void draw_pixel(const T &x, const T &y) const
Definition wykobi_graphics_vcl.hpp:61
void draw_segment(const point2d< T > &point1, const point2d< T > &point2) const
Definition wykobi_graphics_vcl.hpp:118
void draw(const quadratic_bezier< T, 2 > &bezier, const std::size_t &point_count)
Definition wykobi_graphics_vcl.hpp:205
void draw_triangle(const point2d< T > &point1, const point2d< T > &point2, const point2d< T > &point3) const
Definition wykobi_graphics_vcl.hpp:128
void set_pen_width(int w)
Definition wykobi_graphics_vcl.hpp:54
void draw_polyline(std::vector< point2d< T > > point_list)
Definition wykobi_graphics_vcl.hpp:149
TPen * get_pen()
Definition wykobi_graphics_vcl.hpp:48
void draw(const quadix< T, 2 > &quadix)
Definition wykobi_graphics_vcl.hpp:180
void draw_quadix(const point2d< T > &point1, const point2d< T > &point2, const point2d< T > &point3, const point2d< T > &point4) const
Definition wykobi_graphics_vcl.hpp:133
void draw_line(const point2d< T > &point1, const point2d< T > &point2) const
Definition wykobi_graphics_vcl.hpp:123
void draw_circle(const T x, const T &y, const T &radius) const
Definition wykobi_graphics_vcl.hpp:113
void clear_white()
Definition wykobi_graphics_vcl.hpp:166
void clear(TColor color)
Definition wykobi_graphics_vcl.hpp:155
unsigned int center_y() const
Definition wykobi_graphics_vcl.hpp:52
void draw(const cubic_bezier< T, 2 > &bezier, const std::size_t &point_count)
Definition wykobi_graphics_vcl.hpp:198
void draw(const line< T, 2 > &line)
Definition wykobi_graphics_vcl.hpp:173
void clear_black()
Definition wykobi_graphics_vcl.hpp:167
void draw_circle(const point2d< T > &point, const T &radius) const
Definition wykobi_graphics_vcl.hpp:145
void draw(const circle< T > &circle)
Definition wykobi_graphics_vcl.hpp:183
void draw(const rectangle< T > &rectangle)
Definition wykobi_graphics_vcl.hpp:177
unsigned int height() const
Definition wykobi_graphics_vcl.hpp:50
void set_pen(TPen *p)
Definition wykobi_graphics_vcl.hpp:43
void draw(const polygon< T, 2 > &polygon)
Definition wykobi_graphics_vcl.hpp:187
void set_height(unsigned int h)
Definition wykobi_graphics_vcl.hpp:47
void draw(const triangle< T, 2 > &triangle)
Definition wykobi_graphics_vcl.hpp:174
wykobi_graphics_vcl(TCanvas *c, unsigned int w, unsigned int h)
Definition wykobi_graphics_vcl.hpp:36
unsigned int width() const
Definition wykobi_graphics_vcl.hpp:49
void draw_pixel(const point2d< T > &point) const
Definition wykobi_graphics_vcl.hpp:66
void draw_segment(const T &x1, const T &y1, const T &x2, const T &y2) const
Definition wykobi_graphics_vcl.hpp:72
Definition wykobi.hpp:32
void generate_bezier(const quadratic_bezier< T, 2 > &bezier, OutputIterator out, const std::size_t &point_count=1000)