2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-12-28 20:21:05 +00:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup freestyle
|
2019-06-16 13:37:21 +10:00
|
|
|
* \brief Class to define the representation of a triangle
|
2012-12-28 20:21:05 +00:00
|
|
|
*/
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2018-06-17 17:05:14 +02:00
|
|
|
//! inherits from class Rep
|
2008-04-30 15:41:54 +00:00
|
|
|
#include "Rep.h"
|
|
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
namespace Freestyle {
|
|
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** Base class for all lines objects */
|
2014-04-17 14:19:10 +09:00
|
|
|
class TriangleRep : public Rep {
|
2008-04-30 15:41:54 +00:00
|
|
|
public:
|
2021-06-24 15:57:33 +10:00
|
|
|
/** Line description style */
|
2012-12-28 20:21:05 +00:00
|
|
|
enum TRIANGLE_STYLE {
|
|
|
|
|
FILL,
|
|
|
|
|
LINES,
|
|
|
|
|
};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
private:
|
2012-12-28 20:21:05 +00:00
|
|
|
TRIANGLE_STYLE _Style;
|
|
|
|
|
Vec3r _vertices[3];
|
|
|
|
|
Vec3r _colors[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
public:
|
2012-12-28 20:21:05 +00:00
|
|
|
inline TriangleRep() : Rep()
|
|
|
|
|
{
|
|
|
|
|
_Style = FILL;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** Builds a triangle from 3 vertices
|
2012-12-28 20:21:05 +00:00
|
|
|
* v0
|
|
|
|
|
* first vertex
|
|
|
|
|
* v1
|
|
|
|
|
* second vertex
|
|
|
|
|
* v2
|
|
|
|
|
* third vertex
|
|
|
|
|
*/
|
|
|
|
|
inline TriangleRep(const Vec3r &v0, const Vec3r &v1, const Vec3r &v2) : Rep()
|
|
|
|
|
{
|
|
|
|
|
_vertices[0] = v0;
|
|
|
|
|
_vertices[1] = v1;
|
|
|
|
|
_vertices[2] = v2;
|
|
|
|
|
_Style = FILL;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
inline TriangleRep(const Vec3r &v0,
|
|
|
|
|
const Vec3r &c0,
|
|
|
|
|
const Vec3r &v1,
|
|
|
|
|
const Vec3r &c1,
|
|
|
|
|
const Vec3r &v2,
|
|
|
|
|
const Vec3r &c2)
|
|
|
|
|
: Rep()
|
|
|
|
|
{
|
|
|
|
|
_vertices[0] = v0;
|
|
|
|
|
_vertices[1] = v1;
|
|
|
|
|
_vertices[2] = v2;
|
|
|
|
|
_colors[0] = c0;
|
|
|
|
|
_colors[1] = c1;
|
|
|
|
|
_colors[2] = c2;
|
|
|
|
|
_Style = FILL;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
virtual ~TriangleRep()
|
|
|
|
|
{
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** accessors */
|
2012-12-28 20:21:05 +00:00
|
|
|
inline const TRIANGLE_STYLE style() const
|
|
|
|
|
{
|
|
|
|
|
return _Style;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
inline const Vec3r &vertex(int index) const
|
|
|
|
|
{
|
|
|
|
|
return _vertices[index];
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
inline const Vec3r &color(int index) const
|
|
|
|
|
{
|
|
|
|
|
return _colors[index];
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** modifiers */
|
2012-12-28 20:21:05 +00:00
|
|
|
inline void setStyle(const TRIANGLE_STYLE iStyle)
|
|
|
|
|
{
|
|
|
|
|
_Style = iStyle;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
inline void setVertex(int index, const Vec3r &iVertex)
|
|
|
|
|
{
|
|
|
|
|
_vertices[index] = iVertex;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
inline void setColor(int index, const Vec3r &iColor)
|
|
|
|
|
{
|
|
|
|
|
_colors[index] = iColor;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
inline void setVertices(const Vec3r &v0, const Vec3r &v1, const Vec3r &v2)
|
|
|
|
|
{
|
|
|
|
|
_vertices[0] = v0;
|
|
|
|
|
_vertices[1] = v1;
|
|
|
|
|
_vertices[2] = v2;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
inline void setColors(const Vec3r &c0, const Vec3r &c1, const Vec3r &c2)
|
|
|
|
|
{
|
|
|
|
|
_colors[0] = c0;
|
|
|
|
|
_colors[1] = c1;
|
|
|
|
|
_colors[2] = c2;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** Accept the corresponding visitor */
|
2012-12-28 20:21:05 +00:00
|
|
|
virtual void accept(SceneVisitor &v)
|
|
|
|
|
{
|
|
|
|
|
Rep::accept(v);
|
|
|
|
|
v.visitTriangleRep(*this);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-26 21:35:18 +10:00
|
|
|
/** Computes the triangle bounding box. */
|
2012-12-28 20:21:05 +00:00
|
|
|
virtual void ComputeBBox();
|
2008-04-30 15:41:54 +00:00
|
|
|
};
|
|
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
} /* namespace Freestyle */
|