2012-12-28 20:21:05 +00:00
|
|
|
/*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup freestyle
|
|
|
|
|
* \brief Class to build a Node Tree designed to be displayed from a set of strokes structure.
|
2012-12-28 20:21:05 +00:00
|
|
|
*/
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2010-04-07 23:28:29 +00:00
|
|
|
#include "StrokeTesselator.h"
|
2020-04-21 12:39:12 +02:00
|
|
|
#include "StrokeAdvancedIterators.h"
|
2012-12-28 20:21:05 +00:00
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
#include "../scene_graph/NodeGroup.h"
|
|
|
|
|
#include "../scene_graph/NodeShape.h"
|
2020-04-21 12:39:12 +02:00
|
|
|
#include "../scene_graph/OrientedLineRep.h"
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
namespace Freestyle {
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
LineRep *StrokeTesselator::Tesselate(Stroke *iStroke)
|
2008-04-30 15:41:54 +00:00
|
|
|
{
|
2020-11-06 17:49:09 +01:00
|
|
|
if (nullptr == iStroke) {
|
|
|
|
|
return nullptr;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2013-03-11 06:56:51 +00:00
|
|
|
LineRep *line;
|
2012-12-28 20:21:05 +00:00
|
|
|
line = new OrientedLineRep();
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2013-03-11 06:56:51 +00:00
|
|
|
Stroke::vertex_iterator v, vend;
|
2012-12-28 20:21:05 +00:00
|
|
|
if (2 == iStroke->vertices_size()) {
|
|
|
|
|
line->setStyle(LineRep::LINES);
|
|
|
|
|
v = iStroke->vertices_begin();
|
|
|
|
|
StrokeVertex *svA = (*v);
|
|
|
|
|
v++;
|
|
|
|
|
StrokeVertex *svB = (*v);
|
|
|
|
|
Vec3r A((*svA)[0], (*svA)[1], 0);
|
|
|
|
|
Vec3r B((*svB)[0], (*svB)[1], 0);
|
|
|
|
|
line->AddVertex(A);
|
|
|
|
|
line->AddVertex(B);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (_overloadFrsMaterial) {
|
2014-04-15 19:21:29 +10:00
|
|
|
line->setFrsMaterial(_FrsMaterial);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
line->setStyle(LineRep::LINE_STRIP);
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
for (v = iStroke->vertices_begin(), vend = iStroke->vertices_end(); v != vend; v++) {
|
|
|
|
|
StrokeVertex *sv = (*v);
|
|
|
|
|
Vec3r V((*sv)[0], (*sv)[1], 0);
|
|
|
|
|
line->AddVertex(V);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
line->setId(iStroke->getId());
|
|
|
|
|
line->ComputeBBox();
|
|
|
|
|
|
|
|
|
|
return line;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class StrokeVertexIterator>
|
2012-12-28 20:21:05 +00:00
|
|
|
NodeGroup *StrokeTesselator::Tesselate(StrokeVertexIterator begin, StrokeVertexIterator end)
|
2008-04-30 15:41:54 +00:00
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
NodeGroup *group = new NodeGroup;
|
|
|
|
|
NodeShape *tshape = new NodeShape;
|
|
|
|
|
group->AddChild(tshape);
|
2019-04-30 17:50:57 +10:00
|
|
|
// tshape->material().setDiffuse(0.0f, 0.0f, 0.0f, 1.0f);
|
2012-12-28 20:21:05 +00:00
|
|
|
tshape->setFrsMaterial(_FrsMaterial);
|
|
|
|
|
|
|
|
|
|
for (StrokeVertexIterator c = begin, cend = end; c != cend; c++) {
|
|
|
|
|
tshape->AddRep(Tesselate((*c)));
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
return group;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
2013-04-09 00:46:49 +00:00
|
|
|
|
|
|
|
|
} /* namespace Freestyle */
|