1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335 | //-----------------------------------------------------------------------------
//
// File: CubitFacetEdge.hpp
//
// Purpose: optionally used with the CubitFacet class if information
// is required at the edges of facets
//
// Notes: Note that this class does not contain any private data.
// All data should be defined within the child classes inherited
// from this class. The current Cubit data class that inherits
// from CubitFacetEdge is CubitFacetEdgeData. This is done so that
// other applications using CubitFacetEdges can use their own
// edge data, but take advantage of the CGM/Cubit functionality.
// Please do not add private data to this class; instead add the
// data to the children and access through virtual functions.
//
// Do not create a CubitFacetEdge directly. For example, don't do:
// CubitFacetEdge *cfe = new CubitFacetEdge(...);
// You should instead create the appropriate child class, and
// cast it to a CubitFacetEdge for use. For example:
// CubitFacetEdge *cfe = (CubitFacetEdge *) new CubitFacetEdgeData(...);
//
//-----------------------------------------------------------------------------
#ifndef CUBITFACETEDGE_HPP
#define CUBITFACETEDGE_HPP
// Include for CubitBoolean
#include "CubitDefines.h"
#include "CubitVector.hpp"
#include "DLIList.hpp"
#include "FacetEntity.hpp"
class CubitFacet;
class CubitPoint;
class CubitBox;
class CubitFacetEdge : public FacetEntity
{
private:
protected:
CubitVector controlPoints[3];
//- bezier points on the edge
int bezierOrder;
//- bezier order
int markedFlag;
//- marked flag
IttyBit isFeature;
//- set if this edge is a feature
CubitBoolean isFlipped;
public:
CubitFacetEdge();
//- constructors
virtual ~CubitFacetEdge();
//- destructor
virtual int id() = 0;
virtual void set_id(int /*ent_id*/) {};
int is_flipped()
{
if(isFlipped)
return 1;
return 0;
}
void is_flipped ( int flipped)
{
if(flipped)
isFlipped = CUBIT_TRUE;
else
isFlipped = CUBIT_FALSE;
}
void toggle_is_flipped()
{
isFlipped = !isFlipped;
}
virtual CubitPoint *point( int index ) = 0;
//- get one of its points
virtual CubitFacet *adj_facet( int index) = 0;
//- get one of its adjacent facets
virtual int bezier_order() {return bezierOrder;};
virtual int control_points( CubitVector *ctrl_pts );
//- get the control points (return the order)
virtual CubitVector *control_points() { return controlPoints; };
virtual void control_points( CubitVector *ctrl_pts, int order );
//- set the bezier control points on the edge.
//- end points are assumed to be the first and last
//- ctrl pt so they are not passed in. Pass in order-1
//- control points (max order = 4)
virtual CubitStatus control_points( CubitFacet *facet, CubitVector *ctrl_pts );
//- return the control pons on the edge of a facet based
//- on its edge use direction
virtual void get_control_points( CubitPoint *point_ptr, CubitVector ctrl_pts[3] );
virtual void set_control_points( CubitPoint *point_ptr, CubitVector ctrl_pts[3] );
//- get and set control points oriented with respect to the
//- point_ptr (ie. point_ptr is the first control point on the edge)
//- Note: only gets and sets the middle three control points. The
//- other 2 are the edge vertices.
void set_control_points( const double *ctrl_pt_array );
virtual void set_flag( int my_flag ) {markedFlag = my_flag;};
virtual int get_flag( ) {return markedFlag;};
virtual void facets(DLIList<CubitFacet*> &facet_list ) = 0;<--- Function in derived class
virtual void edges(DLIList<CubitFacetEdge*> &edge_list ) = 0;<--- Function in derived class
virtual void points(DLIList<CubitPoint*> &point_list ) = 0;<--- Function in derived class
virtual int num_adj_facets() = 0;
void tris(DLIList<CubitFacet*> &facet_list){ facets(facet_list); }
void tris(int* /*tool_id*/,
DLIList<CubitFacet*> &facet_list){ facets(facet_list); }
//- Implement in the child class if need be.
//- Assertion will occur if not implemented in the child class
virtual void add_facet(CubitFacet * /*facet_ptr*/){ assert(0); }
virtual CubitStatus remove_facet(CubitFacet * /*facet_ptr*/) = 0;
virtual CubitPoint *start_node() = 0;
virtual CubitPoint *end_node() = 0;
virtual void flip() = 0;
virtual int number_tris() { return num_adj_facets(); }
virtual int number_faces() { return 0; }
virtual void marked (int my_flag ) { set_flag(my_flag); }
virtual int marked() { return get_flag(); }
CubitStatus evaluate_position( const CubitVector &start_position,
CubitVector *eval_point,
CubitVector *eval_tangent);
//- find closet point on non-linear edge
CubitStatus evaluate( double &t,
CubitVector *eval_point,
CubitVector *eval_tangent );
CubitStatus evaluate_single(double &t,
CubitVector *outv);
CubitStatus evaluate_single_tangent(double &t,
CubitVector *outv);
CubitStatus evaluate_2nd_derivative(double &t,
CubitVector *outv);
//- evaluate location -1 < t < 1
CubitStatus closest_point(const CubitVector &point,
CubitVector &closest_point );
//- return closest point to linear segment
CubitStatus intersect(CubitVector &aa, CubitVector &bb, // end point of segment
CubitVector &norm, // normal of the common plane
CubitVector &qq, // return the intersection point
CubitBoolean &does_intersect );
// intersect the edge with a segment. Assumes segment and edge
// are on the same plane (project to facet plane first)
void boundary_edge_points( CubitPoint * &pt0,
CubitPoint * &pt1,
int tool_id = 0);
// return oriented points on a boundary facet edge
double dist_to_edge( const CubitVector &this_point,
CubitVector &close_point,
CubitBoolean &outside_edge );
// return distance from point to an edge
CubitStatus proj_to_line( const CubitVector &this_point,
CubitVector &proj_point );
// project point to line defined by edge
CubitStatus edge_tangent( const CubitVector &point_on_edge,
CubitVector &tangent );
// compute tangent vector of edge
CubitStatus edge_curvature( const CubitVector &point_on_edge,
CubitVector &curvature,
CubitFacetEdge *closest_edge );
// compute curvature vector of edge
double length();
CubitVector position_from_fraction( double zero_to_one );
CubitVector center() { return position_from_fraction(0.5); }
// compute and return the edge length
CubitPoint* other_point( CubitPoint *point_ptr );
// return the other point on the facet edge
void get_parents(DLIList<FacetEntity *> &facet_list);<--- Function in derived class
// return the adjacent facets to edge
CubitFacet *other_facet( CubitFacet *facet_ptr );
// return the other facet at the edge
CubitFacet *other_facet_on_surf( CubitFacet *facet_ptr );
// return the other facet at the edge that has the
// same tool id
int num_adj_facets_on_surf( int tool_id );
// return number of adjacent facets with the indicated
// tool id
CubitFacet *adj_facet_on_surf( int tool_id );
// return first facet adjacent the edge with the
// indicated tool id
CubitBoolean contains( CubitPoint *point_ptr );
//- determines if point is contained in edge
void set_as_feature() { isFeature = 1; }
CubitBoolean is_feature( ){return (isFeature ? CUBIT_TRUE : CUBIT_FALSE); }
// set and get the isFeature bit
void debug_draw(int color = -1, int flush = 1, int draw_uv=0);
// debug drawing
CubitPoint *shared_point( CubitFacetEdge *edge_ptr );
// get the common point
void add_facets( );
// add this edge to its adjacent facets
CubitBox bounding_box();
// return the bounding box of the edge
static int intersect_2D_segments( double P0[2], double P1[2],
double P2[2], double P3[2],
double qq[4] );
static int intersect_intervals( double u0, double u1,
double v0, double v1,
double w[2] );
static CubitStatus order_edge_list(DLIList<CubitFacetEdge*> &edge_list,
CubitPoint *start_point,
CubitPoint *&end_point);
static CubitPoint *find_start_point_for_edge_list(DLIList<CubitFacetEdge*> edge_list);
double angle_between_facets();
inline int less_than(CubitFacetEdge*& e1, CubitFacetEdge*& e2)
{
double len1 = e1->length();
double len2 = e2->length();
if (len1 == len2) return 0;
return (len1 < len2) ? -1 : 1;
}
};
inline void CubitFacetEdge::control_points(
CubitVector *ctrl_pts, int order )
{
assert(order > 0 && order <=4);
bezierOrder = order;
for(int i=0; i<order-1; i++){
controlPoints[i] = ctrl_pts[i];
}
}
//======================================================================
// Function: get_control_points (PUBLIC)
// Description: get control points oriented with respect to the
// point_ptr (ie. point_ptr is the first control point
// on the edge)
// Note: only gets and sets the middle three control points. The
// other 2 are the edge vertices.
// Author: sjowen
// Date: 05/01
//======================================================================
inline void CubitFacetEdge::get_control_points( CubitPoint *point_ptr,
CubitVector ctrl_pts[3] )
{
DLIList<CubitPoint*> my_points;
points(my_points);
if (point_ptr == my_points.get())
{
ctrl_pts[0] = controlPoints[0];
ctrl_pts[1] = controlPoints[1];
ctrl_pts[2] = controlPoints[2];
}
else if(point_ptr == my_points.next())
{
ctrl_pts[0] = controlPoints[2];
ctrl_pts[1] = controlPoints[1];
ctrl_pts[2] = controlPoints[0];
}
else
{
assert(0); // point_ptr does not match either point
}
}
//======================================================================
// Function: set_control_points (PUBLIC)
// Description: set control points oriented with respect to the
// point_ptr (ie. point_ptr is the first control point
// on the edge)
// Note: only gets and sets the middle three control points. The
// other 2 are the edge vertices.
// Author: sjowen
// Date: 05/01
//======================================================================
inline void CubitFacetEdge::set_control_points( CubitPoint *point_ptr,
CubitVector ctrl_pts[3] )
{
DLIList<CubitPoint*> my_points;
points(my_points);
if (point_ptr == my_points.get())
{
controlPoints[0] = ctrl_pts[0];
controlPoints[1] = ctrl_pts[1];
controlPoints[2] = ctrl_pts[2];
}
else if(point_ptr == my_points.next())
{
controlPoints[0] = ctrl_pts[2];
controlPoints[1] = ctrl_pts[1];
controlPoints[2] = ctrl_pts[0];
}
else
{
assert(0); // point_ptr does not match either point
}
}
template <> struct DLIListSorter<CubitFacetEdge*>
{
bool operator()(CubitFacetEdge* a, CubitFacetEdge* b) { return a->id() < b->id(); }
};
#endif
|