DGtal  1.5.beta
LibBoard::GouraudTriangle Struct Reference

A triangle with shaded filling according to colors given for each vertex. More...

#include <Board/Shapes.h>

Inheritance diagram for LibBoard::GouraudTriangle:
[legend]

Public Member Functions

 GouraudTriangle (const Point &p0, const DGtal::Color &color0, const Point &p1, const DGtal::Color &color1, const Point &p2, const DGtal::Color &color2, int subdivisions, int depth=-1)
 
 GouraudTriangle (const Point &p0, float brightness0, const Point &p1, float brightness1, const Point &p2, float brightness2, const DGtal::Color &fillColor, int subdivisions, int depth=-1)
 
const std::string & name () const
 
Point center () const
 
GouraudTrianglerotate (double angle, const Point &center)
 
GouraudTriangle rotated (double angle, const Point &center) const
 
GouraudTrianglerotate (double angle)
 
GouraudTriangle rotated (double angle) const
 
GouraudTriangle translated (double dx, double dy) const
 
GouraudTriangle scaled (double sx, double sy) const
 
GouraudTriangle scaled (double s) const
 
void scaleAll (double s)
 
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
 
GouraudTriangleclone () 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)
 
Polylineoperator<< (const Point &p)
 
Pointoperator[] (const unsigned int n)
 
Polyline rotated (double angle, const Point &center) const
 
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
 
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
 

Protected Attributes

DGtal::Color _color0
 
DGtal::Color _color1
 
DGtal::Color _color2
 
int _subdivisions
 
- 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
 

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
 

Detailed Description

A triangle with shaded filling according to colors given for each vertex.

The GouraudTriangle structure.

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

Constructor & Destructor Documentation

◆ GouraudTriangle() [1/2]

LibBoard::GouraudTriangle::GouraudTriangle ( const Point p0,
const DGtal::Color color0,
const Point p1,
const DGtal::Color color1,
const Point p2,
const DGtal::Color color2,
int  subdivisions,
int  depth = -1 
)

Definition at line 2094 of file Shapes.cpp.

2099  : Polyline( std::vector<Point>(), true, DGtal::Color::None, DGtal::Color::None,
2100  0.0f, SolidStyle, ButtCap, MiterJoin, depthValue ),
2101  _color0( color0 ), _color1( color1 ), _color2( color2 ), _subdivisions( subdivisions ) {
2102  _path << p0;
2103  _path << p1;
2104  _path << p2;
2105 
2106  Shape::_fillColor.red( ( color0.red() + color1.red() + color2.red() ) / 3 );
2107  Shape::_fillColor.green( ( color0.green() + color1.green() + color2.green() ) / 3 );
2108  Shape::_fillColor.blue( ( color0.blue() + color1.blue() + color2.blue() ) / 3 );
2109 }
static const Color None
Definition: Color.h:412
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
void blue(const unsigned char aBlueValue)
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)
DGtal::Color _fillColor
Definition: Board/Shapes.h:297

References LibBoard::Shape::_fillColor, LibBoard::Polyline::_path, DGtal::Color::blue(), DGtal::Color::green(), and DGtal::Color::red().

Referenced by clone(), flushPostscript(), flushSVG(), rotated(), scaled(), and translated().

◆ GouraudTriangle() [2/2]

LibBoard::GouraudTriangle::GouraudTriangle ( const Point p0,
float  brightness0,
const Point p1,
float  brightness1,
const Point p2,
float  brightness2,
const DGtal::Color fillColor,
int  subdivisions,
int  depth = -1 
)

Definition at line 2111 of file Shapes.cpp.

2117  : Polyline( std::vector<Point>(), true, DGtal::Color::None, DGtal::Color::None,
2118  0.0f, SolidStyle, ButtCap, MiterJoin, depthValue ),
2119  _color0( fill ), _color1( fill ), _color2( fill ), _subdivisions( subdivisions )
2120 {
2121  _path << p0;
2122  _path << p1;
2123  _path << p2;
2124  _color0.red( static_cast<unsigned char>( std::min( 255.0f, _color0.red() * brightness0 ) ) );
2125  _color0.green( static_cast<unsigned char>( std::min( 255.0f, _color0.green() * brightness0 ) ) );
2126  _color0.blue( static_cast<unsigned char>( std::min( 255.0f, _color0.blue() * brightness0 ) ) );
2127  _color1.red( static_cast<unsigned char>( std::min( 255.0f, _color1.red() * brightness1 ) ) );
2128  _color1.green( static_cast<unsigned char>( std::min( 255.0f, _color1.green() * brightness1 ) ) );
2129  _color1.blue( static_cast<unsigned char>( std::min( 255.0f, _color1.blue() * brightness1 ) ) );
2130  _color2.red( static_cast<unsigned char>( std::min( 255.0f, _color2.red() * brightness2 ) ) );
2131  _color2.green( static_cast<unsigned char>( std::min( 255.0f, _color2.green() * brightness2 ) ) );
2132  _color2.blue( static_cast<unsigned char>( std::min( 255.0f, _color2.blue() * brightness2 ) ) );
2133 
2134  Shape::_fillColor.red( ( _color0.red() + _color1.red() + _color2.red() ) / 3 );
2136  Shape::_fillColor.blue( ( _color0.blue() + _color1.blue() + _color2.blue() ) / 3 );
2137 }

References _color0, _color1, _color2, LibBoard::Shape::_fillColor, LibBoard::Polyline::_path, DGtal::Color::blue(), DGtal::Color::green(), and DGtal::Color::red().

Member Function Documentation

◆ center()

Point LibBoard::GouraudTriangle::center ( ) const
virtual

Returns the gravity center of the shape.

Returns
The center of the shape.

Reimplemented from LibBoard::Polyline.

Definition at line 2140 of file Shapes.cpp.

2140  {
2141  return ( _path[0] + _path[1] + _path[2] ) / 3.0;
2142 }

References LibBoard::Polyline::_path.

Referenced by rotate(), and rotated().

◆ clone()

GouraudTriangle * LibBoard::GouraudTriangle::clone ( ) const
virtual

Return a copy of the shape.

Returns
copye of the shape.

Reimplemented from LibBoard::Polyline.

Definition at line 2194 of file Shapes.cpp.

2194  {
2195  return new GouraudTriangle(*this);
2196 }
GouraudTriangle(const Point &p0, const DGtal::Color &color0, const Point &p1, const DGtal::Color &color1, const Point &p2, const DGtal::Color &color2, int subdivisions, int depth=-1)
Definition: Shapes.cpp:2094

References GouraudTriangle().

◆ flushCairo()

void LibBoard::GouraudTriangle::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 2299 of file Shapes.cpp.

2301 {
2302 }

◆ flushFIG()

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

Sends the Triangle to a FIG file format stream.

Warning! Because shading would generally require more colors in the colormap than allowed by the FIG file format, rendering a Gouraud triangle in an XFig file is the same as rendering a simple triangle whose filling color is the average of the vertex colors.

Parameters
streamoutput stream
transformtransform
colormapcolormap

Reimplemented from LibBoard::Polyline.

Definition at line 2228 of file Shapes.cpp.

2231 {
2232 
2233  DGtal::Color c( static_cast<unsigned char>((_color0.red() + _color1.red() + _color2.red() )/3.0),
2234  static_cast<unsigned char>((_color0.green() + _color1.green() + _color2.green())/3.0),
2235  static_cast<unsigned char>((_color0.blue() + _color1.blue() + _color2.blue())/3.0 ));
2236  Polyline( _path, DGtal::Color::None, c, 0.0f ).flushFIG( stream, transform, colormap );
2237 
2238  // if ( ! _subdivisions ) {
2239  // Polyline::flushFIG( stream, transform, colormap );
2240  // return;
2241  // }
2242 // TODO : Handle extended colormap through clustering...
2243 // const Point & p0 = _points[0];
2244 // const Point & p1 = _points[1];
2245 // const Point & p2 = _points[2];
2246 // Point p01( 0.5*(p0.x+p1.x), 0.5*(p0.y+p1.y) );
2247 // DGtal::Color c01( (_color0.red() + _color1.red())/2,
2248 // (_color0.green() + _color1.green())/2,
2249 // (_color0.blue() + _color1.blue())/2 );
2250 // Point p12( 0.5*(p1.x+p2.x), 0.5*(p1.y+p2.y) );
2251 // DGtal::Color c12( (_color1.red() + _color2.red())/2,
2252 // (_color1.green() + _color2.green())/2,
2253 // (_color1.blue() + _color2.blue())/2 );
2254 // Point p20( 0.5*(p2.x+p0.x), 0.5*(p2.y+p0.y) );
2255 // DGtal::Color c20( (_color2.red() + _color0.red())/2,
2256 // (_color2.green() + _color0.green())/2,
2257 // (_color2.blue() + _color0.blue())/2 );
2258 // GouraudTriangle( p0, _color0, p20, c20, p01, c01, _subdivisions - 1, _depth ).flushFIG( stream, transform, colormap );
2259 // GouraudTriangle( p1, _color1, p01, c01, p12, c12, _subdivisions - 1, _depth ).flushFIG( stream, transform, colormap );
2260 // GouraudTriangle( p2, _color2, p20, c20, p12, c12, _subdivisions - 1, _depth ).flushFIG( stream, transform, colormap );
2261 // GouraudTriangle( p01, c01, p12, c12, p20, c20, _subdivisions - 1, _depth ).flushFIG( stream, transform, colormap );
2262 }
Structure representing an RGB triple with alpha component.
Definition: Color.h:68

References _color0, _color1, _color2, LibBoard::Polyline::_path, DGtal::Color::blue(), DGtal::Color::green(), DGtal::Color::None, LibBoard::Polyline::Polyline(), and DGtal::Color::red().

◆ flushPostscript()

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

Sends the triangle to a Postscript document.

Parameters
streamoutput stream
transformtransform

Reimplemented from LibBoard::Polyline.

Definition at line 2199 of file Shapes.cpp.

2201 {
2202  if ( ! _subdivisions ) {
2203  Polyline::flushPostscript( stream, transform );
2204  return;
2205  }
2206  const Point & p0 = _path[0];
2207  const Point & p1 = _path[1];
2208  const Point & p2 = _path[2];
2209  Point p01( 0.5*(p0.x+p1.x), 0.5*(p0.y+p1.y) );
2210  DGtal::Color c01( (_color0.red() + _color1.red())/2,
2211  (_color0.green() + _color1.green())/2,
2212  (_color0.blue() + _color1.blue())/2 );
2213  Point p12( 0.5*(p1.x+p2.x), 0.5*(p1.y+p2.y) );
2214  DGtal::Color c12( (_color1.red() + _color2.red())/2,
2215  (_color1.green() + _color2.green())/2,
2216  (_color1.blue() + _color2.blue())/2 );
2217  Point p20( 0.5*(p2.x+p0.x), 0.5*(p2.y+p0.y) );
2218  DGtal::Color c20( (_color2.red() + _color0.red())/2,
2219  (_color2.green() + _color0.green())/2,
2220  (_color2.blue() + _color0.blue())/2 );
2221  GouraudTriangle( p0, _color0, p20, c20, p01, c01, _subdivisions - 1, _depth ).flushPostscript( stream, transform );
2222  GouraudTriangle( p1, _color1, p01, c01, p12, c12, _subdivisions - 1, _depth ).flushPostscript( stream, transform );
2223  GouraudTriangle( p2, _color2, p20, c20, p12, c12, _subdivisions - 1, _depth ).flushPostscript( stream, transform );
2224  GouraudTriangle( p01, c01, p12, c12, p20, c20, _subdivisions - 1, _depth ).flushPostscript( stream, transform );
2225 }
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Shapes.cpp:1736
MyPointD Point
Definition: testClone2.cpp:383

References _color0, _color1, _color2, LibBoard::Shape::_depth, LibBoard::Polyline::_path, _subdivisions, DGtal::Color::blue(), LibBoard::Polyline::flushPostscript(), GouraudTriangle(), DGtal::Color::green(), DGtal::Color::red(), LibBoard::Point::x, and LibBoard::Point::y.

◆ flushSVG()

void LibBoard::GouraudTriangle::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 2265 of file Shapes.cpp.

2267 {
2268  if ( ! _subdivisions ) {
2269  Polyline::flushSVG( stream, transform );
2270  return;
2271  }
2272  const Point & p0 = _path[0];
2273  const Point & p1 = _path[1];
2274  const Point & p2 = _path[2];
2275  Point p01( 0.5*(p0.x+p1.x), 0.5*(p0.y+p1.y) );
2276  DGtal::Color c01( (_color0.red() + _color1.red())/2,
2277  (_color0.green() + _color1.green())/2,
2278  (_color0.blue() + _color1.blue())/2 );
2279  Point p12( 0.5*(p1.x+p2.x), 0.5*(p1.y+p2.y) );
2280  DGtal::Color c12( (_color1.red() + _color2.red())/2,
2281  (_color1.green() + _color2.green())/2,
2282  (_color1.blue() + _color2.blue())/2 );
2283  Point p20( 0.5*(p2.x+p0.x), 0.5*(p2.y+p0.y) );
2284  DGtal::Color c20( (_color2.red() + _color0.red())/2,
2285  (_color2.green() + _color0.green())/2,
2286  (_color2.blue() + _color0.blue())/2 );
2287  GouraudTriangle( p0, _color0, p20, c20, p01, c01,
2288  _subdivisions - 1, _depth ).flushSVG( stream, transform );
2289  GouraudTriangle( p1, _color1, p01, c01, p12, c12,
2290  _subdivisions - 1, _depth ).flushSVG( stream, transform );
2291  GouraudTriangle( p2, _color2, p20, c20, p12, c12,
2292  _subdivisions - 1, _depth ).flushSVG( stream, transform );
2293  GouraudTriangle( p01, c01, p12, c12, p20, c20,
2294  _subdivisions - 1, _depth ).flushSVG( stream, transform );
2295 }
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:1792

References _color0, _color1, _color2, LibBoard::Shape::_depth, LibBoard::Polyline::_path, _subdivisions, DGtal::Color::blue(), LibBoard::Polyline::flushSVG(), GouraudTriangle(), DGtal::Color::green(), DGtal::Color::red(), LibBoard::Point::x, and LibBoard::Point::y.

◆ flushTikZ()

void LibBoard::GouraudTriangle::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 2306 of file Shapes.cpp.

2308 {
2309  // FIXME: unimplemented
2310  stream << "% FIXME: GouraudTriangle::flushTikZ unimplemented" << std::endl;
2311 }

◆ name()

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

Returns the generic name of the shape (e.g., Circle, Rectangle, etc.)

Returns
object name

Reimplemented from LibBoard::Polyline.

Definition at line 2089 of file Shapes.cpp.

2090 {
2091  return _name;
2092 }
static const std::string _name

References _name.

◆ rotate() [1/2]

GouraudTriangle & LibBoard::GouraudTriangle::rotate ( double  angle)
virtual

Rotate the shape around its center.

Parameters
angleThe rotation angle in radian.
Returns
A reference to the shape itself.

Reimplemented from LibBoard::Polyline.

Definition at line 2158 of file Shapes.cpp.

2159 {
2160  return GouraudTriangle::rotate( angle, center() );
2161 }
Point center() const
Definition: Shapes.cpp:2140
GouraudTriangle & rotate(double angle, const Point &center)
Definition: Shapes.cpp:2145

References center(), and rotate().

◆ rotate() [2/2]

GouraudTriangle & LibBoard::GouraudTriangle::rotate ( double  angle,
const Point center 
)
virtual

Rotate the shape around a given center of rotation.

Parameters
angleThe rotation angle in radian.
centerThe center of rotation.
Returns
A reference to the shape itself.

Reimplemented from LibBoard::Polyline.

Definition at line 2145 of file Shapes.cpp.

2146 {
2147  _path.rotate( angle, rotCenter );
2148  return *this;
2149 }
Path & rotate(double angle, const Point &center)
Definition: Path.cpp:43

References LibBoard::Polyline::_path, and LibBoard::Path::rotate().

Referenced by rotate().

◆ rotated() [1/2]

GouraudTriangle LibBoard::GouraudTriangle::rotated ( double  angle) const

Definition at line 2164 of file Shapes.cpp.

2165 {
2166  return GouraudTriangle(*this).rotate( angle, center() );
2167 }

References center(), and GouraudTriangle().

◆ rotated() [2/2]

GouraudTriangle LibBoard::GouraudTriangle::rotated ( double  angle,
const Point center 
) const

Definition at line 2152 of file Shapes.cpp.

2153 {
2154  return GouraudTriangle(*this).rotate( angle, rotCenter );
2155 }

References GouraudTriangle().

◆ scaleAll()

void LibBoard::GouraudTriangle::scaleAll ( double  s)
virtual

Scales all the values (positions, dimensions, etc.) associated with the shape.

Parameters
sThe scaling factor.

Reimplemented from LibBoard::Polyline.

Definition at line 2188 of file Shapes.cpp.

2189 {
2190  _path.scaleAll( s );
2191 }
void scaleAll(double s)
Definition: Path.cpp:143

References LibBoard::Polyline::_path, and LibBoard::Path::scaleAll().

◆ scaled() [1/2]

GouraudTriangle LibBoard::GouraudTriangle::scaled ( double  s) const

Definition at line 2182 of file Shapes.cpp.

2183 {
2184  return static_cast<GouraudTriangle &>( GouraudTriangle(*this).scale( s, s ) );
2185 }

References GouraudTriangle().

◆ scaled() [2/2]

GouraudTriangle LibBoard::GouraudTriangle::scaled ( double  sx,
double  sy 
) const

Returns a scaled copy of the triangle.

Parameters
sxScale factor along the x axis.
syScale factor along the y axis.
Returns
A scaled copy of the arrow.

Definition at line 2176 of file Shapes.cpp.

2177 {
2178  return static_cast<GouraudTriangle &>( GouraudTriangle(*this).scale( sx, sy ) );
2179 }

References GouraudTriangle().

◆ translated()

GouraudTriangle LibBoard::GouraudTriangle::translated ( double  dx,
double  dy 
) const

Returns a translated copy of the triangle.

Parameters
dxThe shift along the x axis.
dyThe shift along the y axis.
Returns
A translated copy of the line.

Definition at line 2170 of file Shapes.cpp.

2171 {
2172  return static_cast<GouraudTriangle &>( GouraudTriangle(*this).translate( dx, dy ) );
2173 }

References GouraudTriangle().

Field Documentation

◆ _color0

DGtal::Color LibBoard::GouraudTriangle::_color0
protected

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

Referenced by flushFIG(), flushPostscript(), flushSVG(), and GouraudTriangle().

◆ _color1

DGtal::Color LibBoard::GouraudTriangle::_color1
protected

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

Referenced by flushFIG(), flushPostscript(), flushSVG(), and GouraudTriangle().

◆ _color2

DGtal::Color LibBoard::GouraudTriangle::_color2
protected

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

Referenced by flushFIG(), flushPostscript(), flushSVG(), and GouraudTriangle().

◆ _name

const std::string LibBoard::GouraudTriangle::_name
staticprivate

The generic name of the shape.

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

Referenced by name().

◆ _subdivisions

int LibBoard::GouraudTriangle::_subdivisions
protected

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

Referenced by flushPostscript(), and flushSVG().


The documentation for this struct was generated from the following files: