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