DGtal  1.1.0
Public Member Functions | Static Private Attributes
LibBoard::QuadraticBezierCurve Struct Reference

A quadratic Bezier curve having 3 control points. NB. It is also a parabola arc. More...

#include <Board/Shapes.h>

Inheritance diagram for LibBoard::QuadraticBezierCurve:
[legend]
Collaboration diagram for LibBoard::QuadraticBezierCurve:
[legend]

Public Member Functions

 QuadraticBezierCurve (double x1, double y1, double x2, double y2, double x3, double y3, DGtal::Color pen, DGtal::Color fill, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depthValue=-1)
 
void flushPostscript (std::ostream &stream, const TransformEPS &transform) const
 
void flushFIG (std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
 
void flushSVG (std::ostream &stream, const TransformSVG &transform) const
 
void flushCairo (cairo_t *cr, const TransformCairo &transform) const
 
void flushTikZ (std::ostream &stream, const TransformTikZ &transform) const
 
const std::string & name () const
 
- Public Member Functions inherited from LibBoard::Triangle
 Triangle (const Point &p1, const Point &p2, const Point &p3, DGtal::Color pen, DGtal::Color fill, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depthValue=-1)
 
 Triangle (const double x1, const double y1, const double x2, const double y2, const double x3, const double y3, DGtal::Color pen, DGtal::Color fill, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depthValue=-1)
 
Triangle rotated (double angle) const
 
Triangle translated (double dx, double dy) const
 
Triangle scaled (double sx, double sy) const
 
Triangle scaled (double s) const
 
Triangleclone () const
 
- Public Member Functions inherited from LibBoard::Polyline
 Polyline (const std::vector< Point > &points, bool closed, DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, const LineStyle lineStyle=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
 
 Polyline (const Path &path, DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, const LineStyle lineStyle=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
 
 Polyline (bool closed, DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, const LineStyle lineStyle=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
 
Point center () const
 
Polylineoperator<< (const Point &p)
 
Pointoperator[] (const unsigned int n)
 
Polylinerotate (double angle, const Point &center)
 
Polyline rotated (double angle, const Point &center) const
 
Polylinerotate (double angle)
 
Polyline rotated (double angle) const
 
Polylinetranslate (double dx, double dy)
 
Polyline translated (double dx, double dy) const
 
Shapescale (double sx, double sy)
 
Shapescale (double s)
 
Polyline scaled (double sx, double sy) const
 
Polyline scaled (double s) const
 
void scaleAll (double s)
 
Rect boundingBox () const
 
- Public Member Functions inherited from LibBoard::Shape
 Shape (DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, LineStyle style, const LineCap cap, const LineJoin join, int depth)
 
virtual ~Shape ()
 
bool filled () const
 
ShaperotateDeg (double angle, const Point &center)
 
ShaperotateDeg (double angle)
 
Rect bbox ()
 
Shapeoperator-- ()
 
Shapeoperator++ ()
 
int depth () const
 
virtual void depth (int)
 
virtual void shiftDepth (int shift)
 
const DGtal::ColorpenColor () const
 
const DGtal::ColorfillColor () const
 

Static Private Attributes

static const std::string _name
 

Additional Inherited Members

- Public Types inherited from LibBoard::Shape
enum  LineCap { ButtCap = 0, RoundCap, SquareCap }
 
enum  LineJoin { MiterJoin = 0, RoundJoin, BevelJoin }
 
enum  LineStyle {
  SolidStyle = 0, DashStyle, DotStyle, DashDotStyle,
  DashDotDotStyle, DashDotDotDotStyle
}
 
- Protected Member Functions inherited from LibBoard::Shape
std::string svgProperties (const TransformSVG &transform) const
 
std::string postscriptProperties () const
 
void setCairoDashStyle (cairo_t *cr, LineStyle type) const
 
std::string tikzProperties (const TransformTikZ &transform) const
 
- Protected Attributes inherited from LibBoard::Polyline
Path _path
 
- Protected Attributes inherited from LibBoard::Shape
int _depth
 
DGtal::Color _penColor
 
DGtal::Color _fillColor
 
double _lineWidth
 
LineStyle _lineStyle
 
LineCap _lineCap
 
LineJoin _lineJoin
 

Detailed Description

A quadratic Bezier curve having 3 control points. NB. It is also a parabola arc.

Definition at line 1160 of file Board/Shapes.h.

Constructor & Destructor Documentation

◆ QuadraticBezierCurve()

LibBoard::QuadraticBezierCurve::QuadraticBezierCurve ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3,
DGtal::Color  pen,
DGtal::Color  fill,
double  lineWidth,
const LineStyle  style = SolidStyle,
const LineCap  cap = ButtCap,
const LineJoin  join = MiterJoin,
int  depthValue = -1 
)
inline

Constructs a curve.

Parameters
x1First coordinate of the start point.
y1Second coordinate of the start point.
x2First coordinate of the middle point.
y2Second coordinate of the middle point.
x3First coordinate of the end point.
y3Second coordinate of the end point.
penColor of the curve.
fillColor of the interior.
lineWidthThe line thickness.
styleCurve style
capCurve cap
joinCurve join
depthValueThe depth of the line.

Definition at line 1179 of file Board/Shapes.h.

1187  : Triangle(x1, y1, x2, y2, x3, y3, pen, fill, lineWidth, style, cap, join, depthValue) {}

Member Function Documentation

◆ flushCairo()

void LibBoard::QuadraticBezierCurve::flushCairo ( cairo_t *  cr,
const TransformCairo transform 
) const
virtual

Writes the cairo code of the shape in a cairo drawing context according to a transform.

Parameters
crThe cairo drawing context.
transformA 2D transform to be applied.

Reimplemented from LibBoard::Polyline.

Definition at line 2448 of file Shapes.cpp.

2450 {
2451  double x1, y1, x2, y2, x3, y3, x4, y4; //coordinates of the control points
2452  _path[ 0 ].get(x1, y1);
2453  _path[ 1 ].get(x3, y3);
2454  _path[ 2 ].get(x4, y4);
2455  //we compute the two middle control points of a cubic Bezier curve
2456  //from the three control points of the quadratic Bezier curve
2457  x2 = x1 + 2/3.0*(x3-x1);
2458  y2 = y1 + 2/3.0*(y3-y1);
2459  x3 = x2 + 1/3.0*(x4-x1);
2460  y3 = y2 + 1/3.0*(y4-y1);
2461 
2462  cairo_save (cr);
2463 
2464  cairo_set_source_rgba (cr, _fillColor.red()/255.0, _fillColor.green()/255.0, _fillColor.blue()/255.0, 1.);
2465 
2466  cairo_move_to( cr, transform.mapX( x1 ), transform.mapY( y1 ) );
2467  cairo_curve_to( cr, transform.mapX( x2 ), transform.mapY( y2 ),
2468  transform.mapX( x3 ), transform.mapY( y3 ),
2469  transform.mapX( x4 ), transform.mapY( y4 ) );
2470 
2471  if ( filled() )
2472  {
2473  if ( _penColor != DGtal::Color::None )
2474  cairo_fill_preserve (cr);
2475  else
2476  cairo_fill (cr);
2477  }
2478 
2479  if ( _penColor != DGtal::Color::None )
2480  {
2481  cairo_set_source_rgba (cr, _penColor.red()/255.0, _penColor.green()/255.0, _penColor.blue()/255.0, 1.);
2482 
2483  cairo_set_line_width (cr, _lineWidth);
2484  cairo_set_line_cap (cr, cairoLineCap[_lineCap]);
2485  cairo_set_line_join (cr, cairoLineJoin[_lineJoin]);
2487 
2488  cairo_stroke (cr);
2489  }
2490 
2491  cairo_restore (cr);
2492 }

References LibBoard::Shape::_fillColor, LibBoard::Shape::_lineCap, LibBoard::Shape::_lineJoin, LibBoard::Shape::_lineStyle, LibBoard::Shape::_lineWidth, LibBoard::Polyline::_path, LibBoard::Shape::_penColor, DGtal::Color::blue(), LibBoard::Shape::filled(), DGtal::Color::green(), DGtal::Color::None, DGtal::Color::red(), and LibBoard::Shape::setCairoDashStyle().

◆ flushFIG()

void LibBoard::QuadraticBezierCurve::flushFIG ( std::ostream &  stream,
const TransformFIG transform,
std::map< DGtal::Color, int > &  colormap 
) const
virtual

Writes the FIG code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.
colormapA colormap.

Reimplemented from LibBoard::Polyline.

Definition at line 2416 of file Shapes.cpp.

2419 {
2420  stream << "#FIXME: quadratic Bezier curve unimplemented" << std::endl;
2421  Triangle::flushFIG(stream, transform, colormap);
2422 }

References LibBoard::Polyline::flushFIG().

◆ flushPostscript()

void LibBoard::QuadraticBezierCurve::flushPostscript ( std::ostream &  stream,
const TransformEPS transform 
) const
virtual

Writes the EPS code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Reimplemented from LibBoard::Polyline.

Definition at line 2366 of file Shapes.cpp.

2368 {
2369  double x1, y1, x2, y2, x3, y3, x4, y4; //coordinates of the control points
2370  _path[ 0 ].get(x1, y1);
2371  _path[ 1 ].get(x3, y3);
2372  _path[ 2 ].get(x4, y4);
2373  //we compute the two middle control points of a cubic Bezier curve
2374  //from the three control points of the quadratic Bezier curve
2375  x2 = x1 + 2/3.0*(x3-x1);
2376  y2 = y1 + 2/3.0*(y3-y1);
2377  x3 = x2 + 1/3.0*(x4-x1);
2378  y3 = y2 + 1/3.0*(y4-y1);
2379 
2380  stream << std::endl << "% Bezier curve" << std::endl;
2381  if ( _fillColor != DGtal::Color::None ) {
2382  stream << "n "
2383  << transform.mapX( x1 ) << " "
2384  << transform.mapY( y1 ) << " "
2385  << "m "
2386  << transform.mapX( x2 ) << " "
2387  << transform.mapY( y2 ) << " "
2388  << transform.mapX( x3 ) << " "
2389  << transform.mapY( y3 ) << " "
2390  << transform.mapX( x4 ) << " "
2391  << transform.mapY( y4 ) << " "
2392  << "curveto ";
2393  _fillColor.flushPostscript( stream );
2394  stream << " " << postscriptProperties();
2395  stream << " fill" << std::endl;
2396  }
2397  if ( _penColor != DGtal::Color::None ) {
2398  stream << " " << postscriptProperties() << " ";
2399  stream << "n "
2400  << transform.mapX( x1 ) << " "
2401  << transform.mapY( y1 ) << " "
2402  << "m "
2403  << transform.mapX( x2 ) << " "
2404  << transform.mapY( y2 ) << " "
2405  << transform.mapX( x3 ) << " "
2406  << transform.mapY( y3 ) << " "
2407  << transform.mapX( x4 ) << " "
2408  << transform.mapY( y4 ) << " "
2409  << "curveto ";
2410  _penColor.flushPostscript( stream );
2411  stream << " stroke" << std::endl;
2412  }
2413 }

References LibBoard::Shape::_fillColor, LibBoard::Polyline::_path, LibBoard::Shape::_penColor, DGtal::Color::flushPostscript(), DGtal::Color::None, and LibBoard::Shape::postscriptProperties().

◆ flushSVG()

void LibBoard::QuadraticBezierCurve::flushSVG ( std::ostream &  stream,
const TransformSVG transform 
) const
virtual

Writes the SVG code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Reimplemented from LibBoard::Polyline.

Definition at line 2425 of file Shapes.cpp.

2427 {
2428  double x1, y1, x2, y2, x3, y3; //coordinates of the control points
2429  _path[ 0 ].get(x1, y1);
2430  _path[ 1 ].get(x2, y2);
2431  _path[ 2 ].get(x3, y3);
2432 
2433  stream << "<path ";
2434  stream << svgProperties( transform ) << " ";
2435  //first point
2436  stream << "d='M " << transform.mapX( x1 );
2437  stream << "," << transform.mapY( y1 );
2438  //arc
2439  stream << " Q " << transform.mapX( x2 ) << "," << transform.mapY( y2 );
2440  //last point
2441  stream << " " << transform.mapX( x3 );
2442  stream << "," << transform.mapY( y3 );
2443  stream << "' />";
2444 }

References LibBoard::Polyline::_path, and LibBoard::Shape::svgProperties().

◆ flushTikZ()

void LibBoard::QuadraticBezierCurve::flushTikZ ( std::ostream &  stream,
const TransformTikZ transform 
) const
virtual

Writes the TikZ code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Reimplemented from LibBoard::Polyline.

Definition at line 2496 of file Shapes.cpp.

2498 {
2499  double x1, y1, x2, y2, x3, y3, x4, y4; //coordinates of the control points
2500  _path[ 0 ].get(x1, y1);
2501  _path[ 1 ].get(x3, y3);
2502  _path[ 2 ].get(x4, y4);
2503  //we compute the two middle control points of a cubic Bezier curve
2504  //from the three control points of the quadratic Bezier curve
2505  x2 = x1 + 2/3.0*(x3-x1);
2506  y2 = y1 + 2/3.0*(y3-y1);
2507  x3 = x2 + 1/3.0*(x4-x1);
2508  y3 = y2 + 1/3.0*(y4-y1);
2509 
2510  stream << "\\draw[" << tikzProperties(transform) << "] ("
2511  << transform.mapX( x1 ) << ',' << transform.mapY( y1 )
2512  << ") .. controls ("
2513  << transform.mapX( x2 ) << ',' << transform.mapY( y2 )
2514  << ") and ("
2515  << transform.mapX( x3 ) << ',' << transform.mapY( y3 )
2516  << ") .. ("
2517  << transform.mapX( x4 ) << ',' << transform.mapY( y4 )
2518  << ");" << std::endl;
2519 }

References LibBoard::Polyline::_path, and LibBoard::Shape::tikzProperties().

◆ name()

const std::string & LibBoard::QuadraticBezierCurve::name ( ) const
virtual

Returns the name of the shape (QuadraticBezierCurve)

Returns
object name

Reimplemented from LibBoard::Triangle.

Definition at line 2360 of file Shapes.cpp.

2361 {
2362  return _name;
2363 }

References _name.

Field Documentation

◆ _name

const std::string LibBoard::QuadraticBezierCurve::_name
staticprivate

name of the shape.

Definition at line 1215 of file Board/Shapes.h.

Referenced by name().


The documentation for this struct was generated from the following files:
LibBoard::Triangle::Triangle
Triangle(const Point &p1, const Point &p2, const Point &p3, DGtal::Color pen, DGtal::Color fill, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depthValue=-1)
Definition: Board/Shapes.h:1087
LibBoard::Shape::filled
bool filled() const
Definition: Board/Shapes.h:111
LibBoard::Shape::_lineCap
LineCap _lineCap
Definition: Board/Shapes.h:300
LibBoard::Shape::_fillColor
DGtal::Color _fillColor
Definition: Board/Shapes.h:297
LibBoard::Shape::postscriptProperties
std::string postscriptProperties() const
Definition: Shapes.cpp:140
DGtal::Color::flushPostscript
void flushPostscript(std::ostream &) const
Definition: Color.cpp:124
LibBoard::Polyline::flushFIG
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Definition: Shapes.cpp:1760
DGtal::Color::red
void red(const unsigned char aRedValue)
LibBoard::Shape::svgProperties
std::string svgProperties(const TransformSVG &transform) const
Definition: Shapes.cpp:109
LibBoard::Shape::setCairoDashStyle
void setCairoDashStyle(cairo_t *cr, LineStyle type) const
Definition: Shapes.cpp:153
LibBoard::Shape::_lineWidth
double _lineWidth
Definition: Board/Shapes.h:298
LibBoard::Shape::_lineStyle
LineStyle _lineStyle
Definition: Board/Shapes.h:299
DGtal::Color::green
void green(const unsigned char aGreenValue)
DGtal::Color::blue
void blue(const unsigned char aBlueValue)
LibBoard::QuadraticBezierCurve::_name
static const std::string _name
Definition: Board/Shapes.h:1215
LibBoard::Shape::_lineJoin
LineJoin _lineJoin
Definition: Board/Shapes.h:301
DGtal::Color::None
static const Color None
Definition: Color.h:396
LibBoard::Polyline::_path
Path _path
Definition: Board/Shapes.h:905
LibBoard::Shape::_penColor
DGtal::Color _penColor
Definition: Board/Shapes.h:296
LibBoard::Shape::tikzProperties
std::string tikzProperties(const TransformTikZ &transform) const
Definition: Shapes.cpp:177