Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
Contour.h
Go to the documentation of this file.
1#pragma once
2
3#include <ktm/global.h>
4#include <math/Types.h>
5#include <misc/gen/TVector.h>
6
7namespace sf
8{
9
19
29
34{
35 // Default Constructor.
37
38 // Copy Constructor.
40 {
41 Assign(cd);
42 }
43
44 // Arc constructor using angles in radials.
45 TContourItem(const Vector2D& center, double radius, double start, double stop);
46 // Arc constructor using three vectors and a radius.
47 TContourItem(const Vector2D& center, double radius, const Vector2D& start, const Vector2D& stop);
48 // Arc constructor using two vectors and a radius.
49 TContourItem(double radius, const Vector2D& start, const Vector2D& stop);
50 // Arc center 2 point constructor.
51 TContourItem(const Vector2D& center, const Vector2D& start, const Vector2D& stop);
52 // Arc 3P constructor.
53 TContourItem(const Vector2D& p1, const Vector2D& p2, const Vector2D& p3, bool);
54 // Adds a line of zero length. Start and stop are the same.
55 TContourItem(const Vector2D& center);
56 // Assignment operator.
57 TContourItem& operator=(const TContourItem& cd);
58 // Arc assignment.
59 TContourItem& Assign(const TContourItem& cd);
60 // Arc assignment using radials.
61 TContourItem& Assign(const Vector2D& center, double radius, double start, double stop);
62 // Arc assignment.
63 TContourItem& Assign(const Vector2D& center, double radius, const Vector2D& start, const Vector2D& stop);
64 // Arc assignment.
65 TContourItem& Assign(double radius, const Vector2D& start, const Vector2D& stop);
66 // Arc center 2 point assignment.
67 TContourItem& Assign(const Vector2D& center, const Vector2D& start, const Vector2D& stop);
68 // Arc 3P assignment.
69 TContourItem& Assign(const Vector2D& p1, const Vector2D& p2, const Vector2D& p3, bool);
70 // Assign Stop and Start value determined by type of content.
71 // Does not change the radius.
72 void SetStart(const Vector2D& v);
73 void SetStop(const Vector2D& v);
74 // Sets the center of the arc.
75 void SetCenter(const Vector2D& v);
76 // Sets the mid-vector of the contour item.
77 void SetMid(const Vector2D& v);
78 // Sets the radius of the arc.
79 // When offset_center is true the center is changed to accommodate the radius.
80 void SetRadius(double radius, bool offset_center);
81 // Point assignment arc with radius zero.
82 TContourItem& Assign(Vector2D center);
83 // Resets the structure
84 void Clear();
85 // Resets the structure and sets the tag.
86 void Clear(int tag);
87 // Tells if the angle from start to stop is used clockwise.
88 bool IsClockWise() const;
89 // Returns the length of the arc described between start and stop angles.
90 double GetArcLength() const;
91 // Returns the angle of rotation from the start angle.
92 // Positive values are counter clock wise negative are clock wise.
93 double GetRotationAngle() const;
94 // Returns true if the angle passed is part of the arc.
95 bool IsAngle(double angle) const;
96 // Returns the mid-point on the arc.
97 Vector2D GetMid() const;
98 // Returns the smallest rectangle to contains this item.
99 Rectangle2D GetExtend() const;
100 // Makes of an array of center start and stop values.
101 // All values of EContourItemPoint apply here.
102 Vector2D GetPoint(int i) const;
103 // Sets a point value.
104 // All values of EContourItemPoint apply here.
105 void SetPoint(int i, Vector2D v);
106 // Returns the of the point when using the GetPoint function.
107 static const char* GetPointName(int i);
108 // Determines the type of data.
110 // The center point of the arc.
111 Vector2D Center;
112 // Start point.
113 Vector2D Start;
114 // End point.
115 Vector2D Stop;
116 // Radius of an arc in radials.
117 double Radius;
118 // Start angle of an arc in radials.
120 // Stop angle of an arc in radials.
121 double StopAngle;
122 // Field used for selection in a contour or other stuf. Is zero by default.
123 int Tag;
124};
125
127{
128 Clear();
129}
130
131inline TContourItem::TContourItem(const Vector2D& center, double radius, double start, double stop)
132{
133 Tag = 0;
134 Assign(center, radius, start, stop);
135}
136
137inline TContourItem::TContourItem(const Vector2D& center, double radius, const Vector2D& start, const Vector2D& stop)
138{
139 Tag = 0;
140 Assign(center, radius, start, stop);
141}
142
143inline TContourItem::TContourItem(double radius, const Vector2D& start, const Vector2D& stop)
144{
145 Tag = 0;
146 Assign(radius, start, stop);
147}
148
149inline TContourItem::TContourItem(const Vector2D& center, const Vector2D& start, const Vector2D& stop)
150{
151 Tag = 0;
152 Assign(center, start, stop);
153}
154
155inline TContourItem::TContourItem(const Vector2D& p1, const Vector2D& p2, const Vector2D& p3, bool dum)
156{
157 Tag = 0;
158 Assign(p1, p2, p3, dum);
159}
160
161inline TContourItem::TContourItem(const Vector2D& center)
162{
163 Tag = 0;
164 Assign(center);
165}
166
168{
169 memcpy(this, &cd, sizeof(*this));
170 return *this;
171}
172
174{
175 memset(this, 0, sizeof(*this));
176}
177
178inline void TContourItem::Clear(int tag)
179{
180 memset(this, 0, sizeof(*this));
181 Tag = tag;
182}
183
185{
186 return Assign(cd);
187}
188
190{
191 // Default constructor.
193 {
194 Clear();
195 }
196
197 // Puts all data members in their initial state.
198 void Clear();
199 // Returns true when the index is less than zero.
200 bool IsEmpty();
201 // Return distance value from start on the contour.
202 double Distance;
203 // Returns length value.
204 double Length;
205 // Return angle value at of the contour at the designated point.
206 double Angle;
207 // Point on the contour.
208 Vector2D Point;
209 // Contour segment index. Is less than zero when data is invalid.
210 int Index;
211};
212
213//
215{
216 Distance = 0.0;
217 Length = 0.0;
218 Angle = 0.0;
219 Point.assign(0.0, 0.0);
220 Index = -1;
221}
222
223//
225{
226 // When the index is smaller than zero the instance contains no valid data.
227 return Index <= 0;
228}
229
230class _KTM_CLASS TContour : public TVector<TContourItem>
231{
232 public:
233 // Calculate second point for instance at 'index'.
234 bool Connect(unsigned index, int mode);
235 // Returns information on the point at a distance from the contours start.
236 // Passed negative value is converted to a positive one.
237 // Angle returned is the normal on the surface.
238 bool GetInfo(double distance, TContourInfo& info) const;
239 // Returns total length of contour.
240 double GetLength() const;
241 // Returns the length of a range of items.
242 // Notice that add indexes are the line segments between the arcs.
243 double GetLength(unsigned from, unsigned to) const;
244 // Gets intersection information of vector line specified by passed
245 // contour info. Returns true when an intersection was found on the contour.
246 // The fields in the 'intersect' structure holds all information about
247 // the intersection.
248 // Angle = angle at intersection from normal.
249 // Point = point of intersection.
250 // Index = index of intersected segment.
251 // Distance = distance from start on the contour.
252 // Length = Distance between the info points and found intersection point.
254 const TContourInfo& info,// Input information
255 TContourInfo& intersect// Output intersection information.
256 ) const;
257 // Returns the smallest rectangle to contains all items.
258 Rectangle2D GetExtend() const;
259};
260
270 const Vector2D& surf_point,// Point on the contour.
271 double surf_angle,// Angle of the point on the contour.
272 double rot_angle,// Angle of rotation.
273 Matrix44& surface// Returned matrix.
274);
275
288 const Vector2D& surf_point,// Point on the contour.
289 double surf_angle,// Angle of the point on the contour.
290 double rotangle,// Angle of rotation.
291 double anglexz,// Local angle on the surface in the XZ-plane.
292 double angleyz,// Local angle on the surface in the YZ-plane.
293 double anglexy,// Local angle on the surface in the XY-plane.
294 Matrix44& surface// Returned matrix.
295);
296
297}// namespace sf
Definition Contour.h:231
bool Connect(unsigned index, int mode)
bool GetInfo(double distance, TContourInfo &info) const
double GetLength(unsigned from, unsigned to) const
Rectangle2D GetExtend() const
bool GetIntersection(const TContourInfo &info, TContourInfo &intersect) const
double GetLength() const
Counted vector having additional methods and operators for ease of usage. This template class extends...
Definition TVector.h:20
#define _KTM_CLASS
Definition ktm/global.h:35
#define _KTM_FUNC
Definition ktm/global.h:34
Definition Application.h:10
EContourItemType
Definition Contour.h:11
@ citARC
Definition Contour.h:15
@ citPOINT
Definition Contour.h:17
@ citNONE
Definition Contour.h:13
bool _KTM_FUNC GetSurfaceMatrix(const Vector2D &surf_point, double surf_angle, double rot_angle, Matrix44 &surface)
Gets the matrix of the surface of the contour info of a rotation symmetrical object.
EContourItemPoint
Definition Contour.h:21
@ cipSTOP
Definition Contour.h:25
@ cipNONE
Definition Contour.h:22
@ cipSTART
Definition Contour.h:24
@ cipMID
Definition Contour.h:26
@ cipCENTER
Definition Contour.h:23
@ cipLAST_ENTRY
Definition Contour.h:27
Definition Contour.h:190
Vector2D Point
Definition Contour.h:208
double Distance
Definition Contour.h:202
void Clear()
Definition Contour.h:214
TContourInfo()
Definition Contour.h:192
double Angle
Definition Contour.h:206
int Index
Definition Contour.h:210
double Length
Definition Contour.h:204
bool IsEmpty()
Definition Contour.h:224
Container for a single data segment.
Definition Contour.h:34
TContourItem & Assign(const TContourItem &cd)
Definition Contour.h:167
double GetArcLength() const
void Clear()
Definition Contour.h:173
double Radius
Definition Contour.h:117
int Tag
Definition Contour.h:123
double GetRotationAngle() const
TContourItem & Assign(double radius, const Vector2D &start, const Vector2D &stop)
Vector2D GetMid() const
void SetPoint(int i, Vector2D v)
bool IsClockWise() const
Vector2D Stop
Definition Contour.h:115
void SetMid(const Vector2D &v)
double StopAngle
Definition Contour.h:121
EContourItemType Type
Definition Contour.h:109
double StartAngle
Definition Contour.h:119
TContourItem & Assign(const Vector2D &center, double radius, const Vector2D &start, const Vector2D &stop)
TContourItem & Assign(Vector2D center)
TContourItem & operator=(const TContourItem &cd)
Definition Contour.h:184
TContourItem()
Definition Contour.h:126
Vector2D GetPoint(int i) const
TContourItem(const TContourItem &cd)
Definition Contour.h:39
TContourItem & Assign(const Vector2D &center, double radius, double start, double stop)
void SetStart(const Vector2D &v)
bool IsAngle(double angle) const
static const char * GetPointName(int i)
void SetRadius(double radius, bool offset_center)
Rectangle2D GetExtend() const
void SetStop(const Vector2D &v)
TContourItem & Assign(const Vector2D &center, const Vector2D &start, const Vector2D &stop)
Vector2D Center
Definition Contour.h:111
Vector2D Start
Definition Contour.h:113
void SetCenter(const Vector2D &v)
TContourItem & Assign(const Vector2D &p1, const Vector2D &p2, const Vector2D &p3, bool)