29#include "SectionTrack.h"
32#include "common/NarrowCast.h"
33#include "common/Interval.h"
34#include "spat/Position.h"
35#include "spat/VectorBundle.h"
36#include "spat/VectorBundle2.h"
37#include "spat/Frame.h"
56 mode_default = mode_none,
73 dclspc TrackPainter(
const TrackPainter& ) =
default;
74 dclspc TrackPainter( TrackPainter&& ) =
default;
78 dclspc
virtual ~TrackPainter() =
default;
80 TrackPainter& operator=(
const TrackPainter& ) =
default;
81 TrackPainter& operator=( TrackPainter&& ) =
default;
83 inline TrackPainter& operator()(
const SectionTrack& track ){
85 Paint( track, *track.GetSection() );
96 return m_CountSegmentsLastPaint;
126 int m_CountSegmentsLastPaint = 0;
132 class SectionPainter :
public TrackPainter{
134 dclspc SectionPainter()
noexcept;
135 dclspc SectionPainter(
int mode,
common::Interval<Length> segmentLimits = {epsilon__length,plausible_maximum_length},
Length e = epsilon__length );
140 virtual void AddTriangle(
unsigned int i0,
unsigned int i1,
unsigned int i2 ) = 0;
149 template<
typename Po
intType_>
150 class BufferedPainter_Base :
public SectionPainter{
152 using PointType = PointType_;
154 BufferedPainter_Base( std::vector<PointType>& points,
155 std::vector<int>& indices,
156 int mode = TrackPainter::Mode::mode_default,
158 Length e = epsilon__length )
159 : SectionPainter {mode,segmentLimits,e},
172 void AddTriangle(
unsigned int i0,
unsigned int i1,
unsigned int i2 )
override{
173 m_Indices.push_back( m_IndexOffset + i0 );
174 m_Indices.push_back( m_IndexOffset + i1 );
175 m_Indices.push_back( m_IndexOffset + i2 );
178 std::vector<PointType>& m_Points;
180 std::vector<int>& m_Indices;
185 template<
typename Po
intType>
186 class BufferedPainter :
public BufferedPainter_Base<PointType>{
188 BufferedPainter( std::vector<PointType>& points,
189 std::vector<int>& indices,
190 int mode = TrackPainter::Mode::mode_default,
192 Length e = epsilon__length )
193 : BufferedPainter_Base<PointType>{points,indices,mode,segmentLimits,e}
202 class BufferedPainter<
spat::
Position<Length>> :
public BufferedPainter_Base<spat::Position<Length>>{
204 BufferedPainter( std::vector<PointType>& points,
205 std::vector<int>& indices,
206 int mode = TrackPainter::Mode::mode_default,
208 Length e = epsilon__length )
209 : BufferedPainter_Base<PointType>{points,indices,mode,segmentLimits,e}
215 m_Points.push_back( rFrame.
P + pt.
p.x * rFrame.
N + pt.
p.y * rFrame.
B );
220 class BufferedPainter<
std::pair<spat::VectorBundle<Length,One>,spat::Position2D<One>>> :
public BufferedPainter_Base<std::pair<spat::VectorBundle<Length,One>,spat::Position2D<One>>>{
222 BufferedPainter( std::vector<PointType>& points,
223 std::vector<int>& indices,
224 int mode = TrackPainter::Mode::mode_default,
226 Length e = epsilon__length )
227 : BufferedPainter_Base<PointType>{points,indices,mode,segmentLimits,e}
233 m_Points.push_back( {{ rFrame.
P + pt.
p.x * rFrame.
N + pt.
p.y * rFrame.
B,
234 pt.
n.dx * rFrame.
N + pt.
n.dy * rFrame.
B },
240 class BufferedPainter<
std::pair<spat::VectorBundle2<Length,One>,spat::Position2D<One>>> :
public BufferedPainter_Base<std::pair<spat::VectorBundle2<Length,One>,spat::Position2D<One>>>{
242 BufferedPainter( std::vector<PointType>& points,
243 std::vector<int>& indices,
244 int mode = TrackPainter::Mode::mode_default,
246 Length e = epsilon__length )
247 : BufferedPainter_Base<PointType>{points,indices,mode,segmentLimits,e}
253 m_Points.push_back( {{ rFrame.
P + pt.
p.x * rFrame.
N + pt.
p.y * rFrame.
B,
255 pt.
n.dx * rFrame.
N + pt.
n.dy * rFrame.
B },
Value type, dependend from dimensions.
Definition DimensionedValues.h:233
void StartPaint(const spat::Frame< Length, One > &rFrame, Length offset, const Section §ion) override
Gets called once on rendering startup before all PaintSegment() calls.
Definition TrackPainter.h:167
void dclspc StartPaint(const spat::Frame< Length, One > &rFrame, Length offset, const Section §ion) override
Gets called once on rendering startup before all PaintSegment() calls.
void dclspc PaintSegment(const spat::Frame< Length, One > &rFrame, Length segmentLength, const Section §ion) override
This gets called once per segment to paint a segment of the track.
Base class for painting tracks as a series of short straight pieces.
Definition TrackPainter.h:44
dclspc Length Paint(const TrackBuilder &track, const Section §ion, Length offset=0_m)
Paints the track.
int GetMode() const noexcept
Definition TrackPainter.h:90
virtual void PaintSegment(const spat::Frame< Length, One > &rFrame, Length segmentLength, const Section &)=0
This gets called once per segment to paint a segment of the track.
int GetCountSegments() const noexcept
Definition TrackPainter.h:95
virtual void EndPaint(const spat::Frame< Length, One > &)
Gets called once on rendering end after all PaintSegment() calls.
Definition TrackPainter.h:120
Mode
Definition TrackPainter.h:46
@ mode_startFrame
Paints the track around it's start frame. The first segment will start at {0,0,0} with it's tangent h...
Definition TrackPainter.h:55
@ mode_leftHandedFaces
Produces triangles according to the left hand rule. Default it is the right hand rule.
Definition TrackPainter.h:48
@ mode_SegmentLength
Checks each segment at its starting point. The default.
Definition TrackPainter.h:50
@ mode_constantSegmentLength
Uses segmentLimits.Far() as segment length.
Definition TrackPainter.h:49
@ mode_ignoreCuvesTorsion
Ignores the curves torsion (but not the track's twist) for segment calculations.
Definition TrackPainter.h:53
@ mode_checkedSegmentLength
Checks the end point of the segment, shrinks if necessary. Use it if the curvature changes much insid...
Definition TrackPainter.h:51
@ mode_localFrame
Paints the track in it's local frame of reference. To get global coordinates, the tracks's transforma...
Definition TrackPainter.h:54
@ mode_totallycheckedSegmentLength
Checks every point of the segment with respect to the segmentLimits.Near() grid. Use it if sudden cur...
Definition TrackPainter.h:52
virtual void StartPaint(const spat::Frame< Length, One > &, Length, const Section &)
Gets called once on rendering startup before all PaintSegment() calls.
Definition TrackPainter.h:112
Namespace of common utility classes and methods.
Definition Helpers.h:43
Target narrow_cast(Source v)
Safe cast for casting numeric values.
Definition NarrowCast.h:60
Value< Dimension< 0, 0, 0 > > One
Dimensionless value.
Definition DimensionedValues.h:319
Value< Dimension< 1, 0, 0 > > Length
Length.
Definition DimensionedValues.h:324
constexpr Real _m(Length l) noexcept
Dimensionated Values conversion functions.
Definition DimensionedValues.h:1210
The namespace provides classes and methods for spatial computations.
Definition Box.h:32
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
An interval describes the area between two numbers. It is understood to contain the near one and exlu...
Definition Interval.h:42
Type selection for class Value.
Definition DimensionedValues.h:224
A Frame ("TNBFrame") describes a location in 3d space and an orientation using a right handed coordin...
Definition Frame.h:52
Vector< ValtypeT > B
Binormal axis or z-axis.
Definition Frame.h:56
Position< Valtype > P
Point in 3D space.
Definition Frame.h:53
Vector< ValtypeT > N
Normal axis or y-axis.
Definition Frame.h:55
Vector< ValtypeT > T
Tangential axis or x-axis.
Definition Frame.h:54
Implements a 2D - position in cartesian coordinates.
Definition Position2D.h:45
Implements a 3D - position in cartesian coordinates.
Definition Position.h:46
Point structure used to describe a section.
Definition Section.h:82
spat::Position2D< Length > p
Position of profile point.
Definition Section.h:83
spat::Vector2D< One > n
Normal of profile point.
Definition Section.h:84
A profile of a track.
Definition Section.h:45
Interface for making and shaping tracks.
Definition Track.h:831