Branch data Line data Source code
1 : : //- Class: CurveFacetEvalTool
2 : : //- Description: The CurveFacetEvalTool is a tool to perform generic geometric
3 : : //- operations on a set of facets.
4 : : //- Assumptions: All of the facets are connected topologically correct.
5 : : //-
6 : : //- Owner: Steve J. Owen
7 : : //- Checked by:
8 : :
9 : : #include "CubitVector.hpp"
10 : : #include "CubitPoint.hpp"
11 : : #include "CubitFacet.hpp"
12 : : #include "CubitFacetEdge.hpp"
13 : : #include "CubitFacetEdgeData.hpp"
14 : : #include "CubitBox.hpp"
15 : : #include "DLIList.hpp"
16 : : #include "CurveFacetEvalTool.hpp"
17 : : #include "FacetEvalTool.hpp"
18 : : #include "GeometryDefines.h"
19 : : #include "CastTo.hpp"
20 : : #include "GfxDebug.hpp"
21 : : #include "CubitFileIOWrapper.hpp"
22 : : #include "Cholla.h"
23 : : #include "FacetDataUtil.hpp"
24 : :
25 : : //===========================================================================
26 : : //Function Name: initialize
27 : : //
28 : : //Member Type: PUBLIC
29 : : //Description: initialize a CurveFacetEvalTool - uses end locations of the curve
30 : : // (does geometric comparisons to match facet points)
31 : : //===========================================================================
32 : 0 : CubitStatus CurveFacetEvalTool::initialize(
33 : : FacetEvalTool *surf_eval_tool, // the adjacent surface facet eval tool
34 : : CubitVector &start, CubitVector &end, // begin and end vertex
35 : : CubitSense orientation_wrt_surface ) // direction wrt the surface
36 : : {
37 : : // static int counter = 0;
38 : 0 : output_id = -1;
39 : 0 : myBBox = NULL;
40 : :
41 : 0 : surfFacetEvalTool = surf_eval_tool;
42 : :
43 : : CubitStatus stat = get_segments_from_loops( surfFacetEvalTool->loops(), start, end,
44 : 0 : myEdgeList, myPointList, orientation_wrt_surface );
45 [ # # ]: 0 : goodCurveData = (stat == CUBIT_SUCCESS) ? CUBIT_TRUE : CUBIT_FALSE;
46 [ # # ]: 0 : if( !goodCurveData )
47 : : {
48 [ # # ][ # # ]: 0 : PRINT_ERROR( "Unable to initialize Curve Evaluation Tool for Faceted Geometry.\n" );
49 : 0 : return CUBIT_FAILURE;
50 : : }
51 : :
52 : 0 : interpOrder = surfFacetEvalTool->interp_order();
53 : 0 : curvSense = find_curv_sense( start );
54 : 0 : bounding_box();
55 : 0 : return CUBIT_SUCCESS;
56 : : }
57 : :
58 : 0 : CubitStatus CurveFacetEvalTool::initialize(
59 : : FacetEvalTool *surf_eval_tool, // the adjacent surface facet eval tool
60 : : CubitVector &start, // begin vertex
61 : : std::vector<CubitVector> &positions )
62 : : {
63 : : // static int counter = 0;
64 : 0 : output_id = -1;
65 : 0 : myBBox = NULL;
66 : :
67 : 0 : surfFacetEvalTool = surf_eval_tool;
68 : :
69 : : CubitStatus stat = get_segments_from_positions( positions, start,
70 : 0 : myEdgeList, myPointList );
71 : :
72 [ # # ]: 0 : goodCurveData = (stat == CUBIT_SUCCESS) ? CUBIT_TRUE : CUBIT_FALSE;
73 [ # # ]: 0 : if( !goodCurveData )
74 : : {
75 [ # # ][ # # ]: 0 : PRINT_ERROR( "Unable to initialize Curve Evaluation Tool for Faceted Geometry.\n" );
76 : 0 : return CUBIT_FAILURE;
77 : : }
78 : :
79 : 0 : interpOrder = surfFacetEvalTool->interp_order();
80 : 0 : curvSense = find_curv_sense( start );
81 : 0 : bounding_box();
82 : 0 : return CUBIT_SUCCESS;
83 : : }
84 : :
85 : : //===========================================================================
86 : : //Function Name: initialize
87 : : //
88 : : //Member Type: PUBLIC
89 : : //Description: initialize a CurveFacetEvalTool - uses end point pointers of the curve
90 : : //===========================================================================
91 : 0 : CubitStatus CurveFacetEvalTool::initialize(
92 : : FacetEvalTool *surf_eval_tool, // the adjacent surface facet eval tool
93 : : CubitPoint *start_pt, CubitPoint *end_pt, // begin and end points
94 : : CubitSense orientation_wrt_surf ) // direction wrt the surface
95 : : {
96 : : // static int counter = 0;
97 : 0 : output_id = -1;
98 : :
99 : 0 : myBBox = NULL;
100 : 0 : surfFacetEvalTool = surf_eval_tool;
101 : : CubitStatus stat = get_segments_from_loops( surfFacetEvalTool->loops(),
102 : : start_pt, end_pt,
103 : : myEdgeList, myPointList,
104 : 0 : orientation_wrt_surf );
105 [ # # ]: 0 : goodCurveData = (stat == CUBIT_SUCCESS) ? CUBIT_TRUE : CUBIT_FALSE;
106 [ # # ]: 0 : if( !goodCurveData )
107 : : {
108 [ # # ][ # # ]: 0 : PRINT_ERROR( "Unable to initialize Curve Evaluation Tool for Faceted Geometry.\n" );
109 : 0 : return CUBIT_FAILURE;
110 : : }
111 : 0 : interpOrder = surfFacetEvalTool->interp_order();
112 : 0 : curvSense = find_curv_sense( start_pt );
113 : 0 : bounding_box();
114 : 0 : return CUBIT_SUCCESS;
115 : : }
116 : :
117 : : //===========================================================================
118 : : //Function Name: CurveFacetEvalTool
119 : : //
120 : : //Member Type: PUBLIC
121 : : //Description: initialize a CurveFacetEvalTool - uses an existing set of
122 : : // ordered facet edges to define curve
123 : : //===========================================================================
124 : 594 : CubitStatus CurveFacetEvalTool::initialize(
125 : : DLIList<CubitFacetEdge*> &edge_list, // the ordered facet edges on this curve
126 : : DLIList<CubitPoint*> &point_list, FacetEvalTool* surf_eval) // the ordered points on this curve
127 : : {
128 : : // static int counter = 0;
129 : 594 : output_id = -1;
130 : 594 : myBBox = NULL;
131 : 594 : curvSense = CUBIT_FORWARD;
132 : 594 : surfFacetEvalTool = surf_eval;
133 : 594 : myEdgeList = edge_list;
134 : 594 : myPointList = point_list;
135 : 594 : set_length();
136 : :
137 : 594 : CubitStatus status = fix_point_edge_order();
138 : :
139 [ - + ]: 594 : if( CUBIT_SUCCESS != status )
140 : 0 : return status;
141 : :
142 : 594 : interpOrder = 0;
143 [ + - ]: 594 : if(surf_eval)
144 : 594 : interpOrder = surf_eval->interp_order();
145 : 594 : bounding_box();
146 : 594 : goodCurveData = CUBIT_TRUE;
147 : 594 : return CUBIT_SUCCESS;
148 : : }
149 : :
150 [ + - ]: 1716 : CurveFacetEvalTool::CurveFacetEvalTool()
151 : : {
152 : : static int counter = 0;
153 : 858 : toolID = counter++;
154 : 858 : myBBox = NULL;
155 : 858 : goodCurveData = CUBIT_TRUE;
156 : :
157 : 858 : }
158 : : //===========================================================================
159 : : //Function Name: ~CurveFacetEvalTool
160 : : //
161 : : //Member Type: PUBLIC
162 : : //Description: destructor
163 : : //===========================================================================
164 [ # # ]: 0 : CurveFacetEvalTool::~CurveFacetEvalTool()
165 : : {
166 [ # # ][ # # ]: 0 : if ( myBBox ) delete myBBox;
[ # # ]
167 [ # # ]: 0 : destroy_facets();
168 : 0 : }
169 : :
170 : : //===========================================================================
171 : : //Function Name: get_segments_from_loops
172 : : //
173 : : //Member Type: PRIVATE
174 : : //Description: extract the facet edges from the loops list that are
175 : : // used for the current curve. Uses CubitVectors at curve
176 : : // ends to determine curve -- has to do geometric comaprisons
177 : : // so it may be less reliable than the overloaded function
178 : : // assumption: the sense (orientation) of the RefFace is the same as that of
179 : : // the facets and the facetedge loop list
180 : : //===========================================================================
181 : 0 : CubitStatus CurveFacetEvalTool::get_segments_from_loops(
182 : : DLIList<DLIList<CubitFacetEdge*>*> *facet_loop_list, // lists of boundary edges
183 : : CubitVector &start, CubitVector &end, // begin and end vertex
184 : : DLIList<CubitFacetEdge*> &edge_list, // return the edges used for this curve
185 : : DLIList<CubitPoint*> &point_list, // return the points used for this curve
186 : : CubitSense orientation_wrt_surf )
187 : : {
188 : 0 : CubitStatus stat = CUBIT_SUCCESS;
189 : : int ii, jj;
190 : 0 : int mydebug = 0;
191 : :
192 : 0 : CubitBoolean done = CUBIT_FALSE;
193 : : DLIList<CubitFacetEdge*> *facet_loop;
194 : 0 : CubitFacetEdge *edge, *startedge = NULL;
195 : : CubitPoint *pt0, *pt1;
196 [ # # ][ # # ]: 0 : CubitVector loc_pt0, loc_pt1;
197 : : double edge_length;
198 : :
199 : 0 : facetLength = 0.0e0;
200 : :
201 [ # # ]: 0 : int tool_id = surfFacetEvalTool->tool_id();
202 : : //loop over the "loops"
203 [ # # ][ # # ]: 0 : for (ii=0; ii<facet_loop_list->size() && !done && stat == CUBIT_SUCCESS; ii++) {
[ # # ][ # # ]
[ # # ]
204 : : //get the next facet loop
205 [ # # ]: 0 : facet_loop = facet_loop_list->get_and_step();
206 : :
207 : : // now loop over the edges in that loop
208 [ # # ][ # # ]: 0 : for (jj=0; jj<facet_loop->size() && !done; jj++) {
[ # # ][ # # ]
209 : : //get the start edge... we will
210 : : //traverse the list forwards, if the surface is oriented forward
211 : : //otherwise, traverse it backwards
212 : : startedge =
213 [ # # ]: 0 : (orientation_wrt_surf == CUBIT_FORWARD) ? facet_loop->get_and_step() :
214 [ # # ][ # # ]: 0 : facet_loop->get_and_back();
215 : :
216 [ # # ][ # # ]: 0 : if (startedge->get_flag() == 0) {
217 [ # # ]: 0 : if (orientation_wrt_surf == CUBIT_FORWARD) {
218 [ # # ]: 0 : startedge->boundary_edge_points( pt0, pt1, tool_id );
219 : : }
220 : : else {
221 [ # # ]: 0 : startedge->boundary_edge_points( pt1, pt0, tool_id );
222 : : }
223 [ # # ][ # # ]: 0 : loc_pt0 = pt0->coordinates();
224 [ # # ][ # # ]: 0 : loc_pt1 = pt1->coordinates();
225 [ # # ][ # # ]: 0 : if (loc_pt0.within_tolerance( start, GEOMETRY_RESABS )) {
226 [ # # ]: 0 : startedge->set_flag( 1 );
227 : 0 : edge = startedge;
228 [ # # ][ # # ]: 0 : if (mydebug) draw_edge( edge, CUBIT_GREEN_INDEX );
229 [ # # ]: 0 : while (!done) {
230 [ # # ]: 0 : edge_list.append( edge );
231 [ # # ]: 0 : point_list.append( pt0 );
232 [ # # ]: 0 : edge_length = loc_pt0.distance_between( loc_pt1 );
233 : 0 : facetLength += edge_length;
234 : : //if the other end of the edge is at the begginning of the
235 : : //loop, then we're done.
236 [ # # ][ # # ]: 0 : if (loc_pt1.within_tolerance( end, GEOMETRY_RESABS )) {
237 : 0 : done = CUBIT_TRUE;
238 [ # # ]: 0 : point_list.append( pt1 );
239 : : }
240 : : else {//otherwise...
241 [ # # ]: 0 : if (orientation_wrt_surf == CUBIT_FORWARD) {
242 [ # # ]: 0 : edge = facet_loop->get_and_step();
243 [ # # ]: 0 : edge->boundary_edge_points( pt0, pt1, tool_id );
244 : : }
245 : : else {
246 [ # # ]: 0 : edge = facet_loop->get_and_back();
247 [ # # ]: 0 : edge->boundary_edge_points( pt1, pt0, tool_id );
248 : : }
249 [ # # ][ # # ]: 0 : loc_pt0 = pt0->coordinates();
250 [ # # ][ # # ]: 0 : loc_pt1 = pt1->coordinates();
251 [ # # ][ # # ]: 0 : if (mydebug) draw_edge( edge, CUBIT_BLUE_INDEX );
252 : : //if we got back to the startedge without the
253 : : // other end of an edge getting to the start vertex,
254 : : // we have a problem....
255 [ # # ]: 0 : if (edge == startedge)
256 : : {
257 : 0 : stat = CUBIT_FAILURE; // this shouldn't happen
258 : 0 : done = CUBIT_TRUE;
259 : : }//end edge == startedge
260 : : }//end else not within tolerance
261 : : }//end while not done
262 : : }//end if within tolerance
263 : : }//end if not marked
264 : : }//end loop over edges in facet loop
265 : : }//end loop over facet loops
266 [ # # ]: 0 : if(done!=CUBIT_TRUE)
267 : : {
268 [ # # ][ # # ]: 0 : PRINT_ERROR("Can't define curve representation in mesh-based geometry\n");
[ # # ][ # # ]
269 : 0 : stat = CUBIT_FAILURE;
270 : : }
271 : 0 : return stat;
272 : :
273 : : }
274 : :
275 : : //===========================================================================
276 : : //Function Name: get_segments_from_loops
277 : : //
278 : : //Member Type: PRIVATE
279 : : //Description: extract the facet edges from the loops list that are
280 : : // used for the current curve. Uses the CubitPoints at
281 : : // the ends of the curve to determine curve
282 : : // assumption: the sense (orientation) of the RefFace is the same as that of
283 : : // the facets and the facetedge loop list
284 : : //===========================================================================
285 : 0 : CubitStatus CurveFacetEvalTool::get_segments_from_loops(
286 : : DLIList<DLIList<CubitFacetEdge*>*> *facet_loop_list, // lists of boundary edges
287 : : CubitPoint *start_pt, CubitPoint *end_pt, // begin and end point
288 : : DLIList<CubitFacetEdge*> &edge_list, // return the edges used for this curve
289 : : DLIList<CubitPoint*> &point_list, // return the points used for this curve
290 : : CubitSense orientation_wrt_surf )
291 : : {
292 : 0 : CubitStatus stat = CUBIT_SUCCESS;
293 : : int ii, jj;
294 [ # # ][ # # ]: 0 : int mydebug = DEBUG_FLAG(181);
295 : 0 : CubitBoolean done = CUBIT_FALSE;
296 : : DLIList<CubitFacetEdge*> *facet_loop;
297 : 0 : CubitFacetEdge *edge, *startedge = NULL;
298 : : CubitPoint *pt0, *pt1;
299 [ # # ][ # # ]: 0 : CubitVector loc_pt0, loc_pt1;
300 : : double edge_length;
301 [ # # ]: 0 : DLIList<CubitFacetEdge*> temp_edge_list;
302 [ # # ][ # # ]: 0 : DLIList<CubitPoint*> temp_point_list;
303 : :
304 [ # # ]: 0 : if (mydebug)
305 : : {
306 [ # # ]: 0 : GfxDebug::draw_point( start_pt->x(),
307 [ # # ]: 0 : start_pt->y(),
308 [ # # ]: 0 : start_pt->z(),
309 [ # # ]: 0 : CUBIT_RED_INDEX );
310 [ # # ]: 0 : GfxDebug::draw_point( end_pt->x(),
311 [ # # ]: 0 : end_pt->y(),
312 [ # # ]: 0 : end_pt->z(),
313 [ # # ]: 0 : CUBIT_GREEN_INDEX );
314 [ # # ]: 0 : GfxDebug::flush();
315 : : }
316 : :
317 [ # # ]: 0 : int tool_id = surfFacetEvalTool->tool_id();
318 : : //loop over the list of facet loops
319 [ # # ][ # # ]: 0 : for (ii=0; ii<facet_loop_list->size() && !done && stat == CUBIT_SUCCESS; ii++) {
[ # # ][ # # ]
[ # # ]
320 : : //get the next facet loop
321 [ # # ]: 0 : facet_loop = facet_loop_list->get_and_step();
322 : : //now loop over the edges in that facet loop
323 [ # # ][ # # ]: 0 : for (jj=0; jj<facet_loop->size() && !done; jj++) {
[ # # ][ # # ]
324 : : //get the start edge... we will
325 : : //traverse the list forwards, if the surface is oriented forward
326 : : //otherwise, traverse it backwards
327 : : startedge =
328 [ # # ]: 0 : (orientation_wrt_surf == CUBIT_FORWARD) ? facet_loop->get_and_step() :
329 [ # # ][ # # ]: 0 : facet_loop->get_and_back();
330 : : //if startedge isn't marked
331 [ # # ][ # # ]: 0 : if (startedge->get_flag() == 0) {
332 : : //get the points from the start edge in the appropriate order
333 [ # # ]: 0 : if (orientation_wrt_surf == CUBIT_FORWARD) {
334 [ # # ]: 0 : startedge->boundary_edge_points( pt0, pt1, tool_id );
335 : : }
336 : : else {
337 [ # # ]: 0 : startedge->boundary_edge_points( pt1, pt0, tool_id );
338 : : }
339 : : //convert to CubitVector
340 [ # # ][ # # ]: 0 : loc_pt0 = pt0->coordinates();
341 [ # # ][ # # ]: 0 : loc_pt1 = pt1->coordinates();
342 : : //if the first point on the edge is the start_pt... otherwise step
343 [ # # ]: 0 : if (pt0 == start_pt) {
344 : : //mark the startedge
345 : 0 : CubitFacetEdge* marked_edge = NULL;
346 : 0 : edge = startedge;
347 [ # # ][ # # ]: 0 : if (mydebug) draw_edge( edge, CUBIT_GREEN_INDEX );//draw the start edge
348 : : //loop until we have reached an end or no more choices
349 [ # # ]: 0 : while (!done) {
350 : : //if the first point is at the start, we are either
351 : : // just starting, or we have looped back onto the
352 : : // start point. The latter _may_ be ok. In case
353 : : // the latter is the case, clean out the temporary
354 : : // lists and (re)initialize the length. Also, unmark
355 : : // the edge that we marked the last time we started,
356 : : // if we previously marked an edge.
357 [ # # ]: 0 : if (pt0 == start_pt){
358 [ # # ]: 0 : temp_point_list.clean_out();
359 [ # # ]: 0 : temp_edge_list.clean_out();
360 : 0 : facetLength = 0.0;
361 [ # # ]: 0 : if(marked_edge)
362 [ # # ]: 0 : marked_edge->set_flag(0);
363 : 0 : marked_edge=edge;
364 [ # # ]: 0 : edge->set_flag(1);
365 : : }
366 : : //add the current edge to the edge list
367 [ # # ]: 0 : temp_edge_list.append( edge );
368 : : //add the current start point to the point list
369 [ # # ]: 0 : temp_point_list.append( pt0 );
370 : : //measure the edge... essentially
371 [ # # ]: 0 : edge_length = loc_pt0.distance_between( loc_pt1 );
372 : : //keep a running tally of the curve length
373 : 0 : facetLength += edge_length;
374 : :
375 : : //if the second point is at the end, we're done
376 [ # # ]: 0 : if (pt1 == end_pt ) {
377 : 0 : done = CUBIT_TRUE;
378 [ # # ]: 0 : temp_point_list.append( pt1 );
379 : : }
380 : : //otherwise, we need to step forward
381 : : else {
382 [ # # ]: 0 : if (orientation_wrt_surf == CUBIT_FORWARD) {
383 [ # # ]: 0 : edge = facet_loop->get_and_step();
384 [ # # ]: 0 : edge->boundary_edge_points( pt0, pt1, tool_id );
385 : : }
386 : : else {
387 [ # # ]: 0 : edge = facet_loop->get_and_back();
388 [ # # ]: 0 : edge->boundary_edge_points( pt1, pt0, tool_id );
389 : : }
390 : : //convert point to CubitVector, as above
391 [ # # ][ # # ]: 0 : loc_pt0 = pt0->coordinates();
392 [ # # ][ # # ]: 0 : loc_pt1 = pt1->coordinates();
393 [ # # ][ # # ]: 0 : if (mydebug) draw_edge( edge, CUBIT_BLUE_INDEX );
394 [ # # ]: 0 : if (edge == startedge)
395 : : {
396 : 0 : stat = CUBIT_FAILURE; // this shouldn't happen
397 : 0 : done = CUBIT_TRUE;
398 : : }
399 : : }//end else (ie, if not pt1==end_pt)
400 : : }//end while !done
401 : : }//end if pt0 == start_pt
402 : : }//end if start edge isn't marked
403 : : }//end loop over edges in the loop
404 : : }//end loop over facet loops
405 : :
406 : : //now put the temporary list entries onto the end of the list we return.
407 [ # # ]: 0 : point_list += temp_point_list;
408 [ # # ]: 0 : edge_list += temp_edge_list;
409 : :
410 [ # # ][ # # ]: 0 : if(done!=CUBIT_TRUE || stat == CUBIT_FAILURE)
411 : : {
412 : 0 : stat = CUBIT_FAILURE;
413 [ # # ][ # # ]: 0 : PRINT_WARNING("Can't define curve representation in mesh-based geometry\n");
[ # # ][ # # ]
414 [ # # ][ # # ]: 0 : PRINT_INFO(" Hint: Try importing as a free mesh and examining nodes and attached\n");
[ # # ][ # # ]
415 [ # # ][ # # ]: 0 : PRINT_INFO(" elements near the following locations:\n");
[ # # ][ # # ]
416 [ # # ][ # # ]: 0 : PRINT_INFO(" Start curve = %f %f %f\n", start_pt->x(), start_pt->y(), start_pt->z());
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
417 [ # # ][ # # ]: 0 : PRINT_INFO(" End curve = %f %f %f\n", end_pt->x(), end_pt->y(), end_pt->z());
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
418 [ # # ]: 0 : if (mydebug)
419 : : {
420 [ # # ]: 0 : surfFacetEvalTool->debug_draw_facets( CUBIT_YELLOW_INDEX );
421 : : int i, j;
422 [ # # ][ # # ]: 0 : for (i=0; i<facet_loop_list->size(); i++)
423 : : {
424 [ # # ]: 0 : DLIList<CubitFacetEdge*> *my_facet_loop = facet_loop_list->get_and_step();
425 [ # # ][ # # ]: 0 : for (j=0; j<my_facet_loop->size(); j++)
426 : : {
427 [ # # ][ # # ]: 0 : draw_edge( my_facet_loop->get_and_step(), CUBIT_RED_INDEX );
428 : : }
429 : : }
430 [ # # ]: 0 : GfxDebug::mouse_xforms();
431 : : }
432 : : }
433 [ # # ]: 0 : return stat;
434 : : }
435 : :
436 : : //===========================================================================
437 : : //Function Name: get_segments_from_positions
438 : : //
439 : : //Member Type: PRIVATE
440 : : //Description: extract the facet edges from the facets of the parent surface.
441 : : // This function is used exclusively for hardlines.
442 : : //===========================================================================
443 : 0 : CubitStatus CurveFacetEvalTool::get_segments_from_positions(
444 : : std::vector<CubitVector> &positions, // postions of points on curve
445 : : CubitVector &start, // begin point
446 : : DLIList<CubitFacetEdge*> &edge_list, // return the edges used for this curve
447 : : DLIList<CubitPoint*> &point_list ) // return the points used for this curve
448 : : {
449 [ # # ]: 0 : DLIList<CubitPoint*> surface_pts;
450 [ # # ]: 0 : surfFacetEvalTool->get_points( surface_pts );
451 : :
452 : 0 : facetLength = 0;
453 : :
454 : 0 : double smallest_dist = CUBIT_DBL_MAX;
455 : 0 : CubitPoint *start_pt = NULL;
456 : : //find the closest point to 'start'
457 [ # # ][ # # ]: 0 : for( int k=surface_pts.size(); k--; )
458 : : {
459 [ # # ][ # # ]: 0 : double tmp_dist = surface_pts.get()->coordinates().distance_between_squared( start );
[ # # ]
460 : :
461 [ # # ]: 0 : if( tmp_dist < smallest_dist )
462 : : {
463 : 0 : smallest_dist = tmp_dist;
464 [ # # ]: 0 : start_pt = surface_pts.get();
465 : : }
466 [ # # ]: 0 : surface_pts.get_and_step();
467 : : }
468 : :
469 [ # # ]: 0 : myPointList.append( start_pt );
470 : :
471 : 0 : CubitPoint *current_pt = start_pt;
472 : 0 : CubitPoint *next_pt = NULL;
473 [ # # ][ # # ]: 0 : for (size_t k = 1; k < positions.size(); k++ )
474 : : {
475 [ # # ][ # # ]: 0 : CubitVector current_pos = positions[k];
476 : :
477 : : //find the CubitPoint attached to this point via an edge
478 : 0 : double smallest_dist = CUBIT_DBL_MAX;
479 : : CubitFacetEdge *next_edge;
480 : :
481 [ # # ]: 0 : DLIList<CubitFacetEdge*> adj_edges;
482 [ # # ]: 0 : current_pt->edges( adj_edges );
483 : :
484 [ # # ][ # # ]: 0 : for( int m=adj_edges.size(); m--; )
485 : : {
486 [ # # ]: 0 : CubitFacetEdge *tmp_edge = adj_edges.get_and_step();
487 [ # # ]: 0 : CubitPoint *other_pt = tmp_edge->other_point( current_pt );
488 : :
489 [ # # ][ # # ]: 0 : double tmp_dist = current_pos.distance_between_squared( other_pt->coordinates() );
490 [ # # ]: 0 : if( tmp_dist < smallest_dist )
491 : : {
492 : 0 : smallest_dist = tmp_dist;
493 : 0 : next_pt = other_pt;
494 : 0 : next_edge = tmp_edge;
495 : : }
496 : : }
497 : :
498 : 0 : current_pt = next_pt;
499 : :
500 [ # # ]: 0 : facetLength += next_edge->length();
501 : :
502 [ # # ]: 0 : myEdgeList.append( next_edge );
503 [ # # ]: 0 : myPointList.append( current_pt );
504 [ # # ]: 0 : }
505 : :
506 [ # # ][ # # ]: 0 : if ((size_t)myPointList.size() != positions.size() ||
[ # # ][ # # ]
[ # # ]
507 [ # # ][ # # ]: 0 : (size_t)myEdgeList.size() != positions.size() - 1 )
508 : 0 : return CUBIT_FAILURE;
509 : :
510 [ # # ]: 0 : return CUBIT_SUCCESS;
511 : : }
512 : :
513 : : //===========================================================================
514 : : //Function Name: find_curv_sense
515 : : //
516 : : //Member Type: PRIVATE
517 : : //Description: Determines 'curvSense' depending on the CubitFacetEdges
518 : : // in 'myEdgeList' Assumption is that all edges
519 : : // are oriented the same in the curve
520 : : //===========================================================================
521 : 0 : CubitSense CurveFacetEvalTool::find_curv_sense( CubitPoint *start_pt )
522 : : {
523 : 0 : myEdgeList.reset();
524 : 0 : CubitFacetEdge *edge_ptr = myEdgeList.get();
525 : 0 : CubitPoint *pt0 = edge_ptr->point(0);
526 : 0 : CubitPoint *pt1 = edge_ptr->point(1);
527 : : CubitSense sense;
528 : :
529 [ # # ]: 0 : if (start_pt == pt0)
530 : : {
531 : 0 : sense = CUBIT_FORWARD;
532 : : }
533 [ # # ]: 0 : else if (start_pt == pt1)
534 : : {
535 : 0 : sense = CUBIT_REVERSED;
536 : : }
537 : : else
538 : : {
539 : 0 : sense = CUBIT_UNKNOWN;
540 : : }
541 : 0 : return sense;
542 : : }
543 : :
544 : : //===========================================================================
545 : : //Function Name: find_curv_sense
546 : : //
547 : : //Member Type: PRIVATE
548 : : //Description: Determines 'curvSense' depending on the CubitFacetEdges
549 : : // in 'myEdgeList' Assumption is that all edges
550 : : // are oriented the same in the curve
551 : : //===========================================================================
552 : :
553 : 0 : CubitSense CurveFacetEvalTool::find_curv_sense( CubitVector &start )
554 : : {
555 [ # # ]: 0 : myEdgeList.reset();
556 [ # # ]: 0 : CubitFacetEdge* temp_edge = myEdgeList.get();
557 : :
558 [ # # ]: 0 : CubitVector temp_vector = temp_edge->point(1)->coordinates() -
559 [ # # ][ # # ]: 0 : temp_edge->point(0)->coordinates();
[ # # ][ # # ]
560 : :
561 [ # # ]: 0 : double tol = temp_vector.length() / 100.0;
562 : : //if point(0) of first edge in list == start, it is CUBIT_FORWARD
563 [ # # ][ # # ]: 0 : if(start.within_tolerance(temp_edge->point(0)->coordinates(), tol ) )
[ # # ][ # # ]
564 : 0 : return CUBIT_FORWARD;
565 : : //if point(1) of first edge in list == start, it is CUBIT_REVERSED
566 [ # # ][ # # ]: 0 : else if(start.within_tolerance(temp_edge->point(1)->coordinates(), tol ) )
[ # # ][ # # ]
567 : 0 : return CUBIT_REVERSED;
568 : : else
569 : 0 : return CUBIT_UNKNOWN;
570 : : }
571 : :
572 : : //===========================================================================
573 : : //Function Name: bounding_box
574 : : //
575 : : //Member Type: PUBLIC
576 : : //Description: Calculates the bounding box of the curve.
577 : : //===========================================================================
578 : 1397 : CubitBox CurveFacetEvalTool::bounding_box()
579 : : {
580 [ + + ]: 1397 : if ( !myBBox )
581 : : {
582 : : int ii;
583 : : CubitPoint *point_ptr;
584 : : double x, y, z;
585 : 858 : double x_min = CUBIT_DBL_MAX, x_max = -CUBIT_DBL_MAX;
586 : 858 : double y_min = CUBIT_DBL_MAX, y_max = -CUBIT_DBL_MAX;
587 : 858 : double z_min = CUBIT_DBL_MAX, z_max = -CUBIT_DBL_MAX;
588 [ + - ][ + + ]: 2728 : for ( ii = myPointList.size(); ii > 0; ii-- )
589 : : {
590 [ + - ]: 1870 : point_ptr = myPointList.get_and_step();
591 [ + - ]: 1870 : x = point_ptr->x();
592 [ + - ]: 1870 : y = point_ptr->y();
593 [ + - ]: 1870 : z = point_ptr->z();
594 [ + + ]: 1870 : if ( x < x_min )
595 : 979 : x_min = x;
596 [ + + ]: 1870 : if ( y < y_min )
597 : 1045 : y_min = y;
598 [ + + ]: 1870 : if ( z < z_min )
599 : 1067 : z_min = z;
600 [ + + ]: 1870 : if ( x > x_max )
601 : 1067 : x_max = x;
602 [ + + ]: 1870 : if ( y > y_max )
603 : 1001 : y_max = y;
604 [ + + ]: 1870 : if ( z > z_max )
605 : 968 : z_max = z;
606 : : }
607 [ + - ]: 858 : CubitVector min_v(x_min, y_min, z_min );
608 [ + - ]: 858 : CubitVector max_v(x_max, y_max, z_max );
609 [ + - ][ + - ]: 858 : myBBox = new CubitBox( min_v, max_v );
610 : : }
611 : 1397 : return *(myBBox);
612 : : }
613 : :
614 : : //===========================================================================
615 : : //Function Name: position_from_fraction
616 : : //
617 : : //Member Type: PUBLIC
618 : : //Description: evaluates the location a fraction of the way along the curve
619 : : // based on the sum of the lengths of the facet edges on this curve
620 : : //===========================================================================
621 : 10802 : CubitStatus CurveFacetEvalTool::position_from_fraction(
622 : : double fraction, // between 0 and 1
623 : : CubitVector &location_on_curve )
624 : : {
625 : 10802 : CubitStatus status = CUBIT_SUCCESS;
626 : 10802 : CubitBoolean done = CUBIT_FALSE;
627 : : double length, curlength, targetlength, lastlength;
628 : 10802 : CubitFacetEdge *edge = NULL;
629 : 10802 : CubitPoint *pt0=NULL, *pt1=NULL;
630 [ + - ][ + - ]: 10802 : CubitVector loc_pt0, loc_pt1;
631 [ + - ]: 10802 : CubitVector eval_location;
632 [ + - ]: 10802 : myEdgeList.reset();
633 : :
634 [ + - ]: 10802 : myPointList.reset();
635 [ + - ]: 10802 : pt0 = myPointList.get();
636 [ + + ]: 10802 : if (fraction <= 0.0) {
637 [ + - ]: 3542 : edge = myEdgeList.get_and_step();
638 [ + - ][ + - ]: 3542 : location_on_curve = pt0->coordinates();
639 : 3542 : return status;
640 : : }
641 : 7260 : curlength = lastlength = 0.0e0;
642 : 7260 : targetlength = fraction * facetLength;
643 [ + - ][ - + ]: 7260 : assert(myEdgeList.size() > 0);
644 : 7260 : int ii = 0;
645 [ + - ][ + + ]: 14520 : for ( ; ii<myEdgeList.size() && !done; ii++) {
[ + - ][ + + ]
646 [ + - ]: 7260 : edge = myEdgeList.get_and_step();
647 [ + - ][ + - ]: 7260 : loc_pt0 = edge->point( 0 )->coordinates();
[ + - ]
648 [ + - ][ + - ]: 7260 : loc_pt1 = edge->point( 1 )->coordinates();
[ + - ]
649 [ + - ]: 7260 : length = loc_pt0.distance_between( loc_pt1 );
650 : 7260 : curlength += length;
651 [ + - ][ + - ]: 7260 : if ( edge->point(0) == pt0 ){
652 [ + - ]: 7260 : pt1 = edge->point(1);
653 : : }
654 : : else{
655 [ # # ]: 0 : pt1 = edge->point(0);
656 : : }
657 [ + - ]: 7260 : if (targetlength <= curlength) {
658 : 7260 : done = CUBIT_TRUE;
659 : :
660 [ + - ][ + - ]: 7260 : loc_pt0 = pt0->coordinates();
661 [ + - ][ + - ]: 7260 : loc_pt1 = pt1->coordinates();
662 : 7260 : double local_fraction = (targetlength - lastlength) / length;
663 [ + - ][ + - ]: 7260 : eval_location = loc_pt0 + local_fraction * (loc_pt1 - loc_pt0);
[ + - ][ + - ]
664 [ - + ][ # # ]: 7260 : if (interpOrder == 0 || !surfFacetEvalTool) {
665 [ + - ]: 7260 : location_on_curve = eval_location;
666 : : }
667 : : else {
668 : : // evaluate Bezier edge
669 : 0 : int index0 = 0;
670 : 0 : int index1 = 1;
671 [ # # ][ # # ]: 0 : if ( pt1 == edge->point(0) ) {
672 : : //switching the indices causes evaluate_bezier_edge to compute the
673 : : //wrong location, so I'm removing the switch (mbrewer)
674 : : //index0 = 1;
675 : : //index1 = 0;
676 : 0 : local_fraction = 1. - local_fraction;
677 : : }
678 : : status = evaluate_bezier_edge(edge,index0,index1,local_fraction,
679 [ # # ]: 7260 : location_on_curve,0);
680 : : }
681 : : }
682 : : else {
683 : 0 : lastlength = curlength;
684 : : }
685 [ + - ][ + - ]: 7260 : if ( edge->point(0) == pt0 )
686 [ + - ]: 7260 : pt0 = edge->point(1);
687 : : else
688 [ # # ]: 0 : pt0 = edge->point(0);
689 : : }
690 : :
691 [ - + ]: 7260 : if (!done) {
692 [ # # ]: 0 : if(pt1 == NULL){
693 [ # # ][ # # ]: 0 : PRINT_ERROR("Opposite point not found while evaluating a curve.\n");
[ # # ][ # # ]
694 [ # # ]: 0 : location_on_curve.set(0.0,0.0,0.0);
695 : 0 : return CUBIT_FAILURE;
696 : : }
697 [ # # ][ # # ]: 0 : location_on_curve = pt1->coordinates();
698 : : }
699 : 10802 : return status;
700 : : }
701 : :
702 : : //===========================================================================
703 : : //Function Name: evaluate_bezier_edge
704 : : //
705 : : //Member Type: PRIVATE
706 : : //Description: evaluates a fractional length onto a Bezier edge
707 : : //===========================================================================
708 : 0 : CubitStatus CurveFacetEvalTool::evaluate_bezier_edge(CubitFacetEdge *edge,
709 : : int index0,
710 : : int index1,
711 : : double fraction,
712 : : CubitVector &location_on_curve,
713 : : double* tangent)
714 : : {
715 : : CubitStatus status;
716 : : int numEdge, numVert, numLocs;
717 : : int edgeVert[2];
718 : : //int order;
719 : : double vert[6], edgeCtrlPts[9], location[3];
720 : : CubitVector *edge_ctrl_pts;
721 : : double scaled_parameter;
722 : :
723 : 0 : numEdge = 1;
724 : 0 : numVert = 2;
725 : 0 : numLocs = 1;
726 : 0 : edgeVert[0] = 0; edgeVert[1] = 1;
727 [ # # ][ # # ]: 0 : vert[0] = edge->point(index0)->x();
728 [ # # ][ # # ]: 0 : vert[1] = edge->point(index0)->y();
729 [ # # ][ # # ]: 0 : vert[2] = edge->point(index0)->z();
730 [ # # ][ # # ]: 0 : vert[3] = edge->point(index1)->x();
731 [ # # ][ # # ]: 0 : vert[4] = edge->point(index1)->y();
732 [ # # ][ # # ]: 0 : vert[5] = edge->point(index1)->z();
733 : :
734 [ # # ]: 0 : edge_ctrl_pts = edge->control_points();
735 [ # # ]: 0 : edgeCtrlPts[0] = edge_ctrl_pts[0].x();
736 [ # # ]: 0 : edgeCtrlPts[1] = edge_ctrl_pts[0].y();
737 [ # # ]: 0 : edgeCtrlPts[2] = edge_ctrl_pts[0].z();
738 [ # # ]: 0 : edgeCtrlPts[3] = edge_ctrl_pts[1].x();
739 [ # # ]: 0 : edgeCtrlPts[4] = edge_ctrl_pts[1].y();
740 [ # # ]: 0 : edgeCtrlPts[5] = edge_ctrl_pts[1].z();
741 [ # # ]: 0 : edgeCtrlPts[6] = edge_ctrl_pts[2].x();
742 [ # # ]: 0 : edgeCtrlPts[7] = edge_ctrl_pts[2].y();
743 [ # # ]: 0 : edgeCtrlPts[8] = edge_ctrl_pts[2].z();
744 : :
745 : : //evalBezierEdge takes a parameter in the range of -1 to 1.
746 : : // evalBezierEdge calls functions which convert back to
747 : : // a range of 0 to 1,
748 : : // but we must convert to -1 to 1, before sending it.
749 : 0 : scaled_parameter = (2.0 * fraction) - 1.0;
750 : :
751 : : // static function in Cholla.cpp
752 : : evalBezierEdge(numEdge,numVert,edgeVert,vert,edgeCtrlPts,numLocs,
753 [ # # ]: 0 : &scaled_parameter, location,tangent);
754 : :
755 [ # # ]: 0 : location_on_curve.x(location[0]);
756 [ # # ]: 0 : location_on_curve.y(location[1]);
757 [ # # ]: 0 : location_on_curve.z(location[2]);
758 : :
759 : 0 : status = CUBIT_SUCCESS;
760 : :
761 : 0 : return status;
762 : : }
763 : :
764 : : //===========================================================================
765 : : //Function Name: u_from_arc_length
766 : : //
767 : : //Member Type: PUBLIC
768 : : //Description: see notes in FacetCurve::u_from_arc_length
769 : : //===========================================================================
770 : 264 : double CurveFacetEvalTool::u_from_arc_length ( double root_param,
771 : : double arc_length )
772 : : {
773 [ - + ]: 264 : if( facetLength == 0 )
774 : 0 : return 0;
775 : :
776 : 264 : double u = root_param + arc_length / facetLength;
777 : :
778 : 264 : return u;
779 : :
780 : : }
781 : :
782 : : //===========================================================================
783 : : //Function Name: length_from_u
784 : : //
785 : : //Member Type: PUBLIC
786 : : //Description: return length along curve from u parameter
787 : : //===========================================================================
788 : 0 : double CurveFacetEvalTool::length_from_u ( double root_param,
789 : : double end_param )
790 : : {
791 : 0 : double length = (end_param - root_param) * facetLength;
792 : :
793 : 0 : return length;
794 : : }
795 : :
796 : : //===========================================================================
797 : : //Function Name: closest_point
798 : : //
799 : : //Member Type: PUBLIC
800 : : //Description: Finds the closest point from the vector (this_point) to the
801 : : // set of facets that lies on the set of facets. If the point
802 : : // lies outside this set, the closest point will be on the plane
803 : : // of the closest facet. The closest_point is set to be that point.
804 : : //===========================================================================
805 : 3740 : CubitStatus CurveFacetEvalTool::closest_point(CubitVector &this_point,
806 : : CubitVector &closest_point,
807 : : CubitVector *tangent_ptr,
808 : : CubitVector *curvature_ptr,
809 : : double *param )
810 : : {
811 : 3740 : CubitStatus stat = CUBIT_SUCCESS;
812 : : // int outside;
813 : 3740 : int mydebug = 0;
814 [ - + ]: 3740 : if (mydebug)
815 : : {
816 [ # # ]: 0 : draw_location(this_point, CUBIT_RED_INDEX);
817 : : }
818 : : /*
819 : : if (surfFacetEvalTool == NULL)
820 : : {
821 : : stat = project_to_linear_facet_edge( this_point, closest_point,
822 : : tangent_ptr, curvature_ptr,
823 : : param, &outside );
824 : : }
825 : : else
826 : : {
827 : : stat = project_to_facet_edge( this_point, closest_point,
828 : : tangent_ptr, curvature_ptr, param, &outside );
829 : : }
830 : : */
831 : : int i;
832 [ + - ][ + - ]: 3740 : CubitVector test_pt_v, closest_pt_v, pt0_v, pt1_v;
[ + - ][ + - ]
833 : : double distance2, closest_distance2; // distance squared
834 : 3740 : CubitFacetEdge *edge, *best_edge = NULL;
835 : :
836 [ + - ]: 3740 : myEdgeList.reset();
837 : 3740 : closest_distance2 = CUBIT_DBL_MAX;
838 [ + - ][ + + ]: 7029 : for ( i = myEdgeList.size(); i > 0; i-- ) {
839 [ + - ]: 3740 : edge = myEdgeList.get_and_step();
840 [ + - ][ + - ]: 3740 : pt0_v = edge->point(0)->coordinates();
[ + - ]
841 [ + - ][ + - ]: 3740 : pt1_v = edge->point(1)->coordinates();
[ + - ]
842 [ + - ]: 3740 : test_pt_v = FacetDataUtil::squared_distance_to_segment(this_point,
843 [ + - ]: 3740 : pt0_v,pt1_v,distance2);
844 [ + - ]: 3740 : if ( distance2 < closest_distance2 ) {
845 : 3740 : closest_distance2 = distance2;
846 [ + - ]: 3740 : closest_pt_v = test_pt_v;
847 : 3740 : best_edge = edge;
848 [ + + ]: 3740 : if ( distance2 < GEOMETRY_RESABS*GEOMETRY_RESABS ) break;
849 : : }
850 : : }
851 : :
852 : :
853 [ - + ]: 3740 : if (mydebug)
854 : : {
855 [ # # ]: 0 : myEdgeList.reset();
856 [ # # ][ # # ]: 0 : for ( i = myEdgeList.size(); i > 0; i-- ) {
857 [ # # ]: 0 : edge = myEdgeList.get_and_step();
858 [ # # ][ # # ]: 0 : pt0_v = edge->point(0)->coordinates();
[ # # ]
859 [ # # ][ # # ]: 0 : pt1_v = edge->point(1)->coordinates();
[ # # ]
860 [ # # ]: 0 : GfxDebug::draw_point(pt0_v, CUBIT_GREEN_INDEX );
861 [ # # ]: 0 : GfxDebug::draw_point(pt1_v, CUBIT_RED_INDEX );
862 [ # # ]: 0 : GfxDebug::flush();
863 : : }
864 : : }
865 : :
866 [ + - ]: 3740 : if ( interpOrder == 0 ) {
867 [ + - ]: 3740 : closest_point = closest_pt_v;
868 [ + + ]: 3740 : if (tangent_ptr) {
869 [ + - ]: 330 : CubitVector tangent;
870 [ + - ][ - + ]: 330 : if (best_edge->edge_tangent( closest_point, tangent ) != CUBIT_SUCCESS) {
871 : 0 : return CUBIT_FAILURE;
872 : : }
873 [ - + ]: 330 : if (curvSense == CUBIT_REVERSED)
874 [ # # ][ # # ]: 0 : tangent = -tangent;
875 [ + - ]: 330 : *tangent_ptr = tangent;
876 : : }
877 : : // evaluate the curvature if required
878 [ - + ]: 3740 : if (curvature_ptr)
879 : : {
880 [ # # ][ # # ]: 0 : if( myEdgeList.size() == 1 )
881 [ # # ]: 0 : (*curvature_ptr).set( 0, 0, 0);
882 : : else
883 : : {
884 [ # # ]: 0 : CubitVector curvature;
885 [ # # ]: 0 : myEdgeList.move_to( best_edge );
886 [ # # ]: 0 : int index = myEdgeList.get_index();
887 : :
888 : : //"best_edge" could be last or first on curve
889 : 0 : CubitFacetEdge* prev_edge = NULL;
890 [ # # ]: 0 : myEdgeList.back();
891 [ # # ][ # # ]: 0 : if( (index - 1) == myEdgeList.get_index() )
892 [ # # ]: 0 : prev_edge = myEdgeList.get();
893 : :
894 : 0 : CubitFacetEdge* next_edge = NULL;
895 [ # # ]: 0 : myEdgeList.step(2);
896 [ # # ][ # # ]: 0 : if( (index + 1) == myEdgeList.get_index() )
897 [ # # ]: 0 : next_edge = myEdgeList.get();
898 : :
899 : :
900 : : CubitFacetEdge *closest_edge;
901 : : //determine which adjacent edge is closest to "best_point"
902 [ # # ][ # # ]: 0 : if( prev_edge && next_edge )
903 : : {
904 [ # # ]: 0 : CubitVector tmp_vec;
905 : : double prev_dist, next_dist;
906 [ # # ][ # # ]: 0 : tmp_vec = (prev_edge->point(0)->coordinates() +
[ # # ][ # # ]
907 [ # # ][ # # ]: 0 : prev_edge->point(1)->coordinates() ) / 2;
[ # # ]
908 [ # # ]: 0 : prev_dist = closest_point.distance_between( tmp_vec );
909 : :
910 [ # # ][ # # ]: 0 : tmp_vec = (next_edge->point(0)->coordinates() +
[ # # ][ # # ]
911 [ # # ][ # # ]: 0 : next_edge->point(1)->coordinates() ) / 2;
[ # # ]
912 [ # # ]: 0 : next_dist = closest_point.distance_between( tmp_vec );
913 : :
914 [ # # ]: 0 : if( prev_dist < next_dist )
915 : 0 : closest_edge = prev_edge;
916 : : else
917 : 0 : closest_edge = next_edge;
918 : : }
919 [ # # ]: 0 : else if( prev_edge )
920 : 0 : closest_edge = prev_edge;
921 : : else
922 : 0 : closest_edge = next_edge;
923 : :
924 [ # # ][ # # ]: 0 : if (best_edge->edge_curvature( closest_point, curvature, closest_edge ) != CUBIT_SUCCESS) {
925 : 0 : return CUBIT_FAILURE;
926 : : }
927 [ # # ]: 0 : if (curvSense == CUBIT_REVERSED)
928 [ # # ][ # # ]: 0 : curvature = -curvature;
929 [ # # ]: 3740 : *curvature_ptr = curvature;
930 : : }
931 : : }
932 [ # # ]: 0 : } else if ( interpOrder == 4 ) {
933 : : double t_value;
934 : : double tangent[3];
935 : : stat = project_to_bezier_edge(best_edge,this_point,
936 [ # # ]: 0 : closest_point,tangent,&t_value);
937 [ # # ]: 0 : if(curvSense == CUBIT_REVERSED){
938 : 0 : tangent[0]= -tangent[0];
939 : 0 : tangent[1]= -tangent[1];
940 : 0 : tangent[2]= -tangent[2];
941 : : }
942 : :
943 [ # # ]: 0 : if ( tangent_ptr ) {
944 [ # # ]: 0 : tangent_ptr->x(tangent[0]);
945 [ # # ]: 0 : tangent_ptr->y(tangent[1]);
946 [ # # ]: 0 : tangent_ptr->z(tangent[2]);
947 : : }
948 : :
949 [ # # ]: 0 : if ( curvature_ptr ) {
950 : : // The idea here is to get the planes normal to two points on the curve
951 : : // on either side of the closest_point, and also to get the plane through
952 : : // these three points. The point of intersection of these three planes
953 : : // should be a good approximation of the center of curvature, from which
954 : : // the curvature vector is readily found.
955 : : // tan1 and tan2 are the normals to the two planes for the endpoints;
956 : : // norm3 is the normal for the plane through the three points.
957 [ # # ][ # # ]: 0 : CubitVector tan1, tan2, point_1, point_2;
[ # # ][ # # ]
958 : 0 : CubitVector *tan1_ptr = &tan1;
959 : 0 : CubitVector *tan2_ptr = &tan2;
960 : : // CubitVector *point_1_ptr = &point_1;
961 : 0 : CubitVector *point_2_ptr = &point_2;
962 : 0 : t_value -= 0.01;
963 [ # # ]: 0 : best_edge->evaluate_single_tangent(t_value,tan1_ptr);
964 : 0 : t_value += 0.02;
965 [ # # ]: 0 : best_edge->evaluate_single(t_value,tan2_ptr);
966 [ # # ]: 0 : best_edge->evaluate_single_tangent(t_value,point_2_ptr);
967 [ # # ]: 0 : tan1.normalize();
968 [ # # ]: 0 : tan2.normalize();
969 : : // Get the plane through the point and normal to the tangent for the two
970 : : // points at the end.
971 : : // Get the plane for the three points.
972 [ # # ]: 0 : CubitVector arm1 = point_1 - closest_point;
973 [ # # ]: 0 : CubitVector arm2 = point_2 - closest_point;
974 [ # # ]: 0 : CubitVector norm3 = arm1*arm2;
975 [ # # ]: 0 : norm3.normalize();
976 : : double denominator;
977 : :
978 [ # # ][ # # ]: 0 : denominator = tan1 % ( tan2 * norm3 );
979 : :
980 [ # # ]: 0 : if ( fabs(denominator) < GEOMETRY_RESABS ) { // planes are parallel;
981 : : // curvature is infinite
982 [ # # ]: 0 : curvature_ptr->x(CUBIT_DBL_MAX);
983 [ # # ]: 0 : curvature_ptr->y(CUBIT_DBL_MAX);
984 [ # # ]: 0 : curvature_ptr->z(CUBIT_DBL_MAX);
985 : :
986 : : } else {
987 [ # # ]: 0 : CubitVector IntersectionPoint;
988 [ # # ][ # # ]: 0 : IntersectionPoint = ( (point_1%tan1)*(norm3*tan2) +
[ # # ][ # # ]
989 [ # # ][ # # ]: 0 : (closest_point%norm3)*(tan2*tan1) +
[ # # ][ # # ]
990 [ # # ][ # # ]: 0 : (point_2%tan2)*(tan1*norm3) )/denominator;
[ # # ][ # # ]
[ # # ]
991 : :
992 [ # # ][ # # ]: 0 : curvature_ptr->x(closest_point.x() - IntersectionPoint.x());
[ # # ]
993 [ # # ][ # # ]: 0 : curvature_ptr->y(closest_point.y() - IntersectionPoint.y());
[ # # ]
994 [ # # ][ # # ]: 0 : curvature_ptr->z(closest_point.z() - IntersectionPoint.z());
[ # # ]
995 : :
996 : : }
997 : :
998 : : }
999 : : } else {
1000 [ # # ][ # # ]: 0 : PRINT_ERROR("Error: Only curves or order 0 or 4 are supported.\n");
[ # # ][ # # ]
1001 : 0 : return CUBIT_FAILURE;
1002 : : }
1003 : :
1004 : :
1005 : :
1006 [ + + ]: 3740 : if (param)
1007 : : {
1008 [ + - ][ + - ]: 3410 : *param = u_on_facet_edge( best_edge, closest_point );
1009 : : }
1010 : :
1011 [ - + ]: 3740 : if (mydebug)
1012 : : {
1013 [ # # ]: 0 : draw_location(closest_point, CUBIT_GREEN_INDEX);
1014 : : }
1015 : 3740 : return stat;
1016 : :
1017 : : }
1018 : :
1019 : : //===========================================================================
1020 : : //Function Name: project_to_bezier_edge
1021 : : //
1022 : : //Member Type: PRIVATE
1023 : : //Description: projects a point onto a Bezier edge
1024 : : //===========================================================================
1025 : 0 : CubitStatus CurveFacetEvalTool::project_to_bezier_edge(CubitFacetEdge *edge,
1026 : : CubitVector &point, CubitVector &projected_point,
1027 : : double *tangent, double *tval)
1028 : : {
1029 : : CubitStatus stat;
1030 : : int numEdge, numVert, edgeVert[2], numLocs;
1031 : : double vert[6], edgeCtrlPts[9], xyz[3], xyzOnEdge[3];
1032 : : CubitVector *edge_ctrl_pts;
1033 : :
1034 : 0 : stat = CUBIT_SUCCESS;
1035 : :
1036 : 0 : numEdge = 1;
1037 : 0 : numVert = 2;
1038 : 0 : numLocs = 1;
1039 : 0 : edgeVert[0] = 0; edgeVert[1] = 1;
1040 [ # # ][ # # ]: 0 : vert[0] = edge->point(0)->x();
1041 [ # # ][ # # ]: 0 : vert[1] = edge->point(0)->y();
1042 [ # # ][ # # ]: 0 : vert[2] = edge->point(0)->z();
1043 [ # # ][ # # ]: 0 : vert[3] = edge->point(1)->x();
1044 [ # # ][ # # ]: 0 : vert[4] = edge->point(1)->y();
1045 [ # # ][ # # ]: 0 : vert[5] = edge->point(1)->z();
1046 : :
1047 [ # # ]: 0 : edge_ctrl_pts = edge->control_points();
1048 [ # # ]: 0 : edgeCtrlPts[0] = edge_ctrl_pts[0].x();
1049 [ # # ]: 0 : edgeCtrlPts[1] = edge_ctrl_pts[0].y();
1050 [ # # ]: 0 : edgeCtrlPts[2] = edge_ctrl_pts[0].z();
1051 [ # # ]: 0 : edgeCtrlPts[3] = edge_ctrl_pts[1].x();
1052 [ # # ]: 0 : edgeCtrlPts[4] = edge_ctrl_pts[1].y();
1053 [ # # ]: 0 : edgeCtrlPts[5] = edge_ctrl_pts[1].z();
1054 [ # # ]: 0 : edgeCtrlPts[6] = edge_ctrl_pts[2].x();
1055 [ # # ]: 0 : edgeCtrlPts[7] = edge_ctrl_pts[2].y();
1056 [ # # ]: 0 : edgeCtrlPts[8] = edge_ctrl_pts[2].z();
1057 [ # # ]: 0 : xyz[0] = point.x();
1058 [ # # ]: 0 : xyz[1] = point.y();
1059 [ # # ]: 0 : xyz[2] = point.z();
1060 : : projToBezierEdge( numEdge,numVert,edgeVert,vert,edgeCtrlPts,
1061 [ # # ]: 0 : numLocs,xyz,xyzOnEdge,tangent,tval );
1062 : :
1063 [ # # ]: 0 : projected_point.x(xyzOnEdge[0]);
1064 [ # # ]: 0 : projected_point.y(xyzOnEdge[1]);
1065 [ # # ]: 0 : projected_point.z(xyzOnEdge[2]);
1066 : :
1067 : 0 : return stat;
1068 : : }
1069 : : /*
1070 : : //===========================================================================
1071 : : //Function Name: project_to_facet_edge
1072 : : //
1073 : : //Member Type: PRIVATE
1074 : : //Description: project the point to the facets defining this curve
1075 : : //===========================================================================
1076 : : CubitStatus CurveFacetEvalTool::project_to_facet_edge(CubitVector &this_point,
1077 : : CubitVector &closest_point,
1078 : : CubitVector *tangent_ptr,
1079 : : CubitVector *curvature_ptr,
1080 : : double *param,
1081 : : int *outside )
1082 : : {
1083 : : int trim = 0;
1084 : : int ncheck, ii, nincr=0;
1085 : : static int calls=0;
1086 : : static int nncheck=0;
1087 : : static int ntol=0;
1088 : : static int mydebug=0;
1089 : : CubitBoolean outside_facet, best_outside_facet;
1090 : : CubitVector boxmin, boxmax, p0, p1;
1091 : : CubitVector close_point, best_point, best_areacoord;
1092 : : CubitFacetEdge *best_edge, *edge;
1093 : : CubitFacet *best_facet, *facet;
1094 : :
1095 : : double tol = surfFacetEvalTool->compare_tol();
1096 : : double facet_tol = 1.0e-3 * surfFacetEvalTool->compare_tol();
1097 : : double mindist = 0.0e0;
1098 : : CubitVector pt_on_edge;
1099 : : CubitBoolean done = CUBIT_FALSE;
1100 : : while(!done) {
1101 : :
1102 : : // define a bounding box around the point
1103 : :
1104 : : CubitVector ptmin( this_point.x() - tol,
1105 : : this_point.y() - tol,
1106 : : this_point.z() - tol );
1107 : :
1108 : : CubitVector ptmax( this_point.x() + tol,
1109 : : this_point.y() + tol,
1110 : : this_point.z() + tol );
1111 : :
1112 : : mindist = CUBIT_DBL_MAX;
1113 : : ncheck = 0;
1114 : : best_outside_facet = CUBIT_TRUE;
1115 : : myEdgeList.reset();
1116 : : for ( ii = myEdgeList.size(); ii > 0 && !done; ii-- ) {
1117 : : edge = myEdgeList.get_and_step();
1118 : : p0 = edge->point( 0 )->coordinates();
1119 : : p1 = edge->point( 1 )->coordinates();
1120 : :
1121 : : // Try to trivially reject this facet with a bounding box test
1122 : :
1123 : : boxmin.x( CUBIT_MIN( p0.x(), p1.x() ) );
1124 : : boxmax.x( CUBIT_MAX( p0.x(), p1.x() ) );
1125 : : if (ptmax.x() < boxmin.x() ||
1126 : : ptmin.x() > boxmax.x()) {
1127 : : continue;
1128 : : }
1129 : : boxmin.y( CUBIT_MIN( p0.y(), p1.y() ) );
1130 : : boxmax.y( CUBIT_MAX( p0.y(), p1.y() ) );
1131 : : if (ptmax.y() < boxmin.y() ||
1132 : : ptmin.y() > boxmax.y()) {
1133 : : continue;
1134 : : }
1135 : : boxmin.z( CUBIT_MIN( p0.z(), p1.z() ) );
1136 : : boxmax.z( CUBIT_MAX( p0.z(), p1.z() ) );
1137 : : if (ptmax.z() < boxmin.z() ||
1138 : : ptmin.z() > boxmax.z()) {
1139 : : continue;
1140 : : }
1141 : :
1142 : : // Only facets that pass the bounding box test will get past here!
1143 : :
1144 : : // Project point to plane of the facet and determine its area coordinates
1145 : :
1146 : : ncheck++;
1147 : : CubitVector pt_on_plane;
1148 : : double dist_to_plane;
1149 : : facet = edge->adj_facet( 0 );
1150 : : if (!facet) {
1151 : : facet = edge->adj_facet( 1 );
1152 : : }
1153 : : project_to_edge_line( edge, this_point, pt_on_plane, dist_to_plane );
1154 : : CubitVector areacoord;
1155 : : pt_on_edge = pt_on_plane;
1156 : : surfFacetEvalTool->facet_area_coordinate( facet, pt_on_plane, areacoord );
1157 : :
1158 : : // If sign of areacoords are all positive then its inside the triangle
1159 : : // and we are done - go interpolate the point. (use an absolute
1160 : : // tolerance since the coordinates arenormalized)
1161 : :
1162 : : if (areacoord.x() > -GEOMETRY_RESABS &&
1163 : : areacoord.y() > -GEOMETRY_RESABS &&
1164 : : areacoord.z() > -GEOMETRY_RESABS) {
1165 : : if (interpOrder == 0 && dist_to_plane < facet_tol) {
1166 : : outside_facet = CUBIT_FALSE;
1167 : : close_point = this_point;
1168 : : }
1169 : : else {
1170 : : if (surfFacetEvalTool->eval_facet( facet, this_point, areacoord,
1171 : : close_point, outside_facet )
1172 : : != CUBIT_SUCCESS) {
1173 : : return CUBIT_FAILURE;
1174 : : }
1175 : : }
1176 : : }
1177 : :
1178 : : // otherwise find the closest vertex or edge to the projected point
1179 : :
1180 : : else if (areacoord.x() < GEOMETRY_RESABS)
1181 : : {
1182 : : outside_facet = CUBIT_TRUE;
1183 : : if (areacoord.y() < GEOMETRY_RESABS)
1184 : : {
1185 : : if (surfFacetEvalTool->eval_point( facet, 2, close_point )
1186 : : != CUBIT_SUCCESS) {
1187 : : return CUBIT_FAILURE;
1188 : : }
1189 : : }
1190 : : else if(areacoord.z() < GEOMETRY_RESABS)
1191 : : {
1192 : : if (surfFacetEvalTool->eval_point( facet, 1, close_point )
1193 : : != CUBIT_SUCCESS) {
1194 : : return CUBIT_FAILURE;
1195 : : }
1196 : : }
1197 : : else
1198 : : {
1199 : : if (surfFacetEvalTool->project_to_facetedge( facet, 1, 2, this_point, pt_on_plane,
1200 : : close_point, outside_facet ) !=CUBIT_SUCCESS) {
1201 : : return CUBIT_FAILURE;
1202 : : }
1203 : : }
1204 : : }
1205 : : else if (areacoord.y() < GEOMETRY_RESABS)
1206 : : {
1207 : : outside_facet = CUBIT_TRUE;
1208 : : if (areacoord.z() < GEOMETRY_RESABS)
1209 : : {
1210 : : if (surfFacetEvalTool->eval_point( facet, 0, close_point )
1211 : : != CUBIT_SUCCESS) {
1212 : : return CUBIT_FAILURE;
1213 : : }
1214 : : }
1215 : : else
1216 : : {
1217 : : if (surfFacetEvalTool->project_to_facetedge( facet, 2, 0, this_point, pt_on_plane,
1218 : : close_point, outside_facet ) !=CUBIT_SUCCESS) {
1219 : : return CUBIT_FAILURE;
1220 : : }
1221 : : }
1222 : : }
1223 : : else
1224 : : {
1225 : : outside_facet = CUBIT_TRUE;
1226 : : if (surfFacetEvalTool->project_to_facetedge( facet, 0, 1, this_point, pt_on_plane,
1227 : : close_point, outside_facet ) !=CUBIT_SUCCESS) {
1228 : : return CUBIT_FAILURE;
1229 : : }
1230 : : }
1231 : :
1232 : : // keep track of the minimum distance
1233 : :
1234 : : double dist = sqrt(sqr(close_point.x() - this_point.x()) +
1235 : : sqr(close_point.y() - this_point.y()) +
1236 : : sqr(close_point.z() - this_point.z()));
1237 : : if (dist < mindist) {
1238 : : if ((best_outside_facet == CUBIT_FALSE && outside_facet == CUBIT_TRUE)) {
1239 : : //int x=1;
1240 : : }
1241 : : else {
1242 : : mindist = dist;
1243 : : best_point = close_point;
1244 : : best_edge = edge;
1245 : : best_facet = facet;
1246 : : best_areacoord = areacoord;
1247 : : best_outside_facet = outside_facet;
1248 : :
1249 : : if (dist < facet_tol) {
1250 : : done = CUBIT_TRUE;
1251 : : }
1252 : : }
1253 : : }
1254 : : }
1255 : :
1256 : : // We are done if we found at least one triangle. Otherwise
1257 : : // increase the tolerance and try again
1258 : :
1259 : : nincr++;
1260 : : if (ncheck > 0) {
1261 : : if (best_outside_facet && nincr < 10) {
1262 : : tol *= 2.0;
1263 : : ntol++;
1264 : : }
1265 : : else {
1266 : : done = CUBIT_TRUE;
1267 : : }
1268 : : }
1269 : : else {
1270 : : tol *= 2.0e0;
1271 : : ntol++;
1272 : : }
1273 : : }
1274 : :
1275 : :
1276 : : //If area coords are still negative...we are still not on a "best_facet"
1277 : : //Find closest point to "best_edge" and use this point for area coordinates
1278 : : if (best_areacoord.x() <= -GEOMETRY_RESABS ||
1279 : : best_areacoord.y() <= -GEOMETRY_RESABS ||
1280 : : best_areacoord.z() <= -GEOMETRY_RESABS)
1281 : : {
1282 : : surfFacetEvalTool->facet_area_coordinate( best_facet, best_point, best_areacoord );
1283 : : }
1284 : :
1285 : :
1286 : : // if the closest point is outside of a facet, then evaluate the point
1287 : : // on the facet using its area coordinates (otherwise it would be
1288 : : // trimmed to an edge or point)
1289 : : if ( !trim && best_outside_facet && interpOrder != 4) {
1290 : : if (surfFacetEvalTool->eval_facet( best_facet, this_point, best_areacoord,
1291 : : best_point, best_outside_facet )
1292 : : != CUBIT_SUCCESS) {
1293 : : return CUBIT_FAILURE;
1294 : : }
1295 : :
1296 : : // see if its really outside (it could just be on an edge where the
1297 : : // curvature is convex)
1298 : :
1299 : : best_outside_facet = surfFacetEvalTool->is_outside( best_facet, best_areacoord );
1300 : : }
1301 : :
1302 : : // evaluate the tangent if required
1303 : :
1304 : : CubitVector tangent_vec;
1305 : : if (tangent_ptr || curvature_ptr) {
1306 : : CubitVector facet_tangent = best_edge->point(1)->coordinates() -
1307 : : best_edge->point(0)->coordinates();
1308 : : if (curvSense == CUBIT_REVERSED)
1309 : : facet_tangent = -facet_tangent;
1310 : : facet_tangent.normalize();
1311 : : if (surfFacetEvalTool->interp_order() == 0)
1312 : : {
1313 : : tangent_vec = facet_tangent;
1314 : : }
1315 : : else
1316 : : {
1317 : : CubitVector normal;
1318 : : if (surfFacetEvalTool->eval_facet_normal( best_facet, best_areacoord, normal )
1319 : : != CUBIT_SUCCESS) {
1320 : : return CUBIT_FAILURE;
1321 : : }
1322 : : tangent_vec = normal * (facet_tangent * normal);
1323 : : }
1324 : : }
1325 : :
1326 : : if( tangent_ptr )
1327 : : *tangent_ptr = tangent_vec;
1328 : :
1329 : : if (curvature_ptr) {
1330 : : //get adjacent facet edges to "best_edge"
1331 : : myEdgeList.move_to( best_edge );
1332 : : int index = myEdgeList.get_index();
1333 : :
1334 : : //"best_edge" could be last or first on curve
1335 : : CubitFacetEdge* prev_edge = NULL;
1336 : : myEdgeList.back();
1337 : : if( (index - 1) == myEdgeList.get_index() )
1338 : : prev_edge = myEdgeList.get();
1339 : :
1340 : : CubitFacetEdge* next_edge = NULL;
1341 : : myEdgeList.step(2);
1342 : : if( (index + 1) == myEdgeList.get_index() )
1343 : : next_edge = myEdgeList.get();
1344 : :
1345 : : //now get 1 facet on each adj. edge
1346 : : CubitFacet *prev_facet = NULL;
1347 : : if( prev_edge )
1348 : : {
1349 : : prev_facet = prev_edge->adj_facet( 0 );
1350 : : if (!prev_facet)
1351 : : prev_facet = prev_edge->adj_facet( 1 );
1352 : : }
1353 : :
1354 : : CubitFacet *next_facet = NULL;
1355 : : if( next_edge )
1356 : : {
1357 : : next_facet = next_edge->adj_facet( 0 );
1358 : : if (!next_facet)
1359 : : next_facet = next_edge->adj_facet( 1 );
1360 : : }
1361 : :
1362 : : //get tangent at midpoint of prev_edge
1363 : : CubitVector prev_tangent_vec;
1364 : : if( prev_edge )
1365 : : {
1366 : : CubitVector facet_tangent = prev_edge->point(1)->coordinates() -
1367 : : prev_edge->point(0)->coordinates();
1368 : : if (curvSense == CUBIT_REVERSED)
1369 : : facet_tangent = -facet_tangent;
1370 : : facet_tangent.normalize();
1371 : :
1372 : : if (surfFacetEvalTool->interp_order() == 0)
1373 : : prev_tangent_vec = facet_tangent;
1374 : : else
1375 : : {
1376 : : CubitVector prev_mid_point;
1377 : : prev_mid_point = (prev_edge->point(0)->coordinates() +
1378 : : prev_edge->point(1)->coordinates() ) / 2;
1379 : :
1380 : : CubitVector areacoord;
1381 : : surfFacetEvalTool->facet_area_coordinate( prev_facet, prev_mid_point, areacoord );
1382 : : CubitVector normal;
1383 : : if (surfFacetEvalTool->eval_facet_normal( prev_facet, areacoord, normal )
1384 : : != CUBIT_SUCCESS)
1385 : : {
1386 : : return CUBIT_FAILURE;
1387 : : }
1388 : : prev_tangent_vec = normal * (facet_tangent * normal);
1389 : : }
1390 : : }
1391 : :
1392 : : //get tangent at midpoint of next_edge
1393 : : CubitVector next_tangent_vec;
1394 : : if( next_edge )
1395 : : {
1396 : : CubitVector facet_tangent = next_edge->point(1)->coordinates() -
1397 : : next_edge->point(0)->coordinates();
1398 : : if (curvSense == CUBIT_REVERSED)
1399 : : facet_tangent = -facet_tangent;
1400 : : facet_tangent.normalize();
1401 : :
1402 : : if (surfFacetEvalTool->interp_order() == 0)
1403 : : next_tangent_vec = facet_tangent;
1404 : : else
1405 : : {
1406 : : CubitVector next_mid_point;
1407 : : next_mid_point = (next_edge->point(0)->coordinates() +
1408 : : next_edge->point(1)->coordinates() ) / 2;
1409 : :
1410 : : CubitVector areacoord;
1411 : : surfFacetEvalTool->facet_area_coordinate( next_facet, next_mid_point, areacoord );
1412 : : CubitVector normal;
1413 : : if (surfFacetEvalTool->eval_facet_normal( next_facet, areacoord, normal )
1414 : : != CUBIT_SUCCESS)
1415 : : {
1416 : : return CUBIT_FAILURE;
1417 : : }
1418 : : next_tangent_vec = normal * (facet_tangent * normal);
1419 : : }
1420 : : }
1421 : :
1422 : : //decide how to weight the tangents
1423 : : double prev_weight, next_weight;
1424 : : if( !prev_edge )
1425 : : {
1426 : : prev_weight = 0;
1427 : : next_weight = 2;
1428 : : }
1429 : : else if( !next_edge )
1430 : : {
1431 : : prev_weight = 2;
1432 : : next_weight = 0;
1433 : : }
1434 : : else
1435 : : {
1436 : : double dist1 = best_edge->point(0)->coordinates().distance_between(
1437 : : best_edge->point(1)->coordinates() );
1438 : : double dist2 = best_edge->point(0)->coordinates().distance_between(
1439 : : best_point);
1440 : : next_weight = dist2/dist1;
1441 : : next_weight *= 2;
1442 : : prev_weight = 2-next_weight;
1443 : : }
1444 : :
1445 : : *curvature_ptr = (prev_weight*( tangent_vec - prev_tangent_vec ) +
1446 : : next_weight*( next_tangent_vec - tangent_vec ) );
1447 : : }
1448 : :
1449 : : closest_point = best_point;
1450 : :
1451 : : *outside = best_outside_facet;
1452 : :
1453 : : if (mydebug) {
1454 : : nncheck+= ncheck;
1455 : : calls++;
1456 : : if (calls%100==0){
1457 : : char message[100];
1458 : : sprintf(message,"calls = %d, ckecks = %d, ntol = %d\n",calls,nncheck,ntol);
1459 : : PRINT_INFO(message);
1460 : : }
1461 : : }
1462 : :
1463 : : // determine the parameter on the curve
1464 : :
1465 : : if (param)
1466 : : {
1467 : : *param = u_on_facet_edge( best_edge, closest_point );
1468 : : }
1469 : :
1470 : : return CUBIT_SUCCESS;
1471 : : }
1472 : :
1473 : : //===========================================================================
1474 : : //Function Name: project_to_edge_line
1475 : : //
1476 : : //Member Type: PRIVATE
1477 : : //Description: compute the area coordinate on the linear facet edge
1478 : : //===========================================================================
1479 : : CubitStatus CurveFacetEvalTool::project_to_edge_line( CubitFacetEdge *edge,
1480 : : CubitVector &this_point,
1481 : : CubitVector &pt_on_edge,
1482 : : double &dist_to_edge )
1483 : : {
1484 : : CubitVector p0 = edge->point(0)->coordinates();
1485 : : CubitVector p1 = edge->point(1)->coordinates();
1486 : : CubitVector v0 = p1 - p0;
1487 : : CubitVector v1 = this_point - p0;
1488 : : double h = v1.normalize();
1489 : : v0.normalize();
1490 : : double costheta = v0 % v1;
1491 : : double l = h * costheta;
1492 : : dist_to_edge = sqrt( fabs((h*h) - (l*l)) );
1493 : : pt_on_edge = p0 + l*v0;
1494 : :
1495 : : return CUBIT_SUCCESS;
1496 : : }
1497 : :
1498 : : //===========================================================================
1499 : : //Function Name: project_to_linear_facet_edge
1500 : : //
1501 : : //Member Type: PRIVATE
1502 : : //Description: project the point to the facets defining this curve.
1503 : : // Note: this function assumes a piecewise linear representation
1504 : : // of the curve. Does not rely on an adjacent surface
1505 : : // eval tool to project the point
1506 : : //===========================================================================
1507 : : CubitStatus CurveFacetEvalTool::project_to_linear_facet_edge(CubitVector &this_point,
1508 : : CubitVector &closest_point,
1509 : : CubitVector *tangent_ptr,
1510 : : CubitVector *curvature_ptr,
1511 : : double *param,
1512 : : int *outside )
1513 : : {
1514 : : int trim = 0;
1515 : : int ncheck, ii, nincr=0;
1516 : : static int ntol=0;
1517 : : CubitBoolean outside_facet, best_outside_facet;
1518 : : CubitVector boxmin, boxmax, p0, p1;
1519 : : CubitVector close_point, best_point;
1520 : : CubitFacetEdge *best_edge, *edge;
1521 : :
1522 : : // so we don't evaluate an edge more than once - mark the edges
1523 : : // as we evaluate them. Put the evaluated edges on a used_edge_list
1524 : : // so we clear the marks off when we are done. Note: this assumes
1525 : : // theat marks are initially cleared.
1526 : :
1527 : : DLIList<CubitFacetEdge *>used_edge_list;
1528 : : for(ii=0; ii<myEdgeList.size(); ii++)
1529 : : myEdgeList.get_and_step()->set_flag(0);
1530 : : CubitBoolean eval_all = CUBIT_FALSE;
1531 : :
1532 : : double tol = facetLength * 1.0e-3;
1533 : : double facet_tol = facetLength * GEOMETRY_RESABS;
1534 : : double mindist = CUBIT_DBL_MAX;
1535 : : double dist = 0.0e0;
1536 : : CubitBoolean done = CUBIT_FALSE;
1537 : : while(!done) {
1538 : :
1539 : : // define a bounding box around the point
1540 : :
1541 : : CubitVector ptmin( this_point.x() - tol,
1542 : : this_point.y() - tol,
1543 : : this_point.z() - tol );
1544 : :
1545 : : CubitVector ptmax( this_point.x() + tol,
1546 : : this_point.y() + tol,
1547 : : this_point.z() + tol );
1548 : :
1549 : : ncheck = 0;
1550 : : best_outside_facet = CUBIT_TRUE;
1551 : : myEdgeList.reset();
1552 : : for ( ii = myEdgeList.size(); ii > 0 && !done; ii-- )
1553 : : {
1554 : : edge = myEdgeList.get_and_step();
1555 : :
1556 : : // if( (edge->get_flag() == 1) )
1557 : : // continue;
1558 : :
1559 : : p0 = edge->point( 0 )->coordinates();
1560 : : p1 = edge->point( 1 )->coordinates();
1561 : :
1562 : : // Try to trivially reject this facet with a bounding box test
1563 : :
1564 : : if (!eval_all)
1565 : : {
1566 : : boxmin.x( CUBIT_MIN( p0.x(), p1.x() ) );
1567 : : boxmax.x( CUBIT_MAX( p0.x(), p1.x() ) );
1568 : : if (ptmax.x() < boxmin.x() ||
1569 : : ptmin.x() > boxmax.x()) {
1570 : : continue;
1571 : : }
1572 : : boxmin.y( CUBIT_MIN( p0.y(), p1.y() ) );
1573 : : boxmax.y( CUBIT_MAX( p0.y(), p1.y() ) );
1574 : : if (ptmax.y() < boxmin.y() ||
1575 : : ptmin.y() > boxmax.y()) {
1576 : : continue;
1577 : : }
1578 : : boxmax.z( CUBIT_MAX( p0.z(), p1.z() ) );
1579 : : if (ptmax.z() < boxmin.z() ||
1580 : : ptmin.z() > boxmax.z()) {
1581 : : continue;
1582 : : }
1583 : : }
1584 : :
1585 : : // Only edges that pass the bounding box test will get past here!
1586 : :
1587 : : // find distance to this edge
1588 : : dist = edge->dist_to_edge( this_point, close_point, outside_facet );
1589 : :
1590 : : if (dist <= mindist) {
1591 : : if ((best_outside_facet == CUBIT_FALSE && outside_facet == CUBIT_TRUE)) {
1592 : : //int x=1;
1593 : : }
1594 : : else {
1595 : : mindist = dist;
1596 : : best_point = close_point;
1597 : : best_edge = edge;
1598 : : best_outside_facet = outside_facet;
1599 : :
1600 : : if (dist < facet_tol) {
1601 : : done = CUBIT_TRUE;
1602 : : }
1603 : : }
1604 : : }
1605 : : ncheck++;
1606 : : // edge->set_flag(1);
1607 : : // used_edge_list.append(edge);
1608 : : }
1609 : :
1610 : : // We are done if we found at least one edge. Otherwise
1611 : : // increase the tolerance and try again
1612 : :
1613 : : nincr++;
1614 : : if (ncheck > 0) {
1615 : : done = CUBIT_TRUE;
1616 : : if (best_outside_facet && nincr < 10) {
1617 : : done = CUBIT_FALSE;
1618 : : }
1619 : : }
1620 : :
1621 : : if (!done)
1622 : : {
1623 : : if (nincr < 10)
1624 : : {
1625 : : tol *= 2.0e0;
1626 : : ntol++;
1627 : : }
1628 : : else {
1629 : : eval_all = CUBIT_TRUE;
1630 : : }
1631 : : }
1632 : : }
1633 : :
1634 : : assert(best_edge != NULL);
1635 : :
1636 : : // if the closest point is outside of a facet, then evaluate the point
1637 : : // on the facet using its area coordinates (otherwise it would be
1638 : : // trimmed to an edge or point)
1639 : :
1640 : :
1641 : : if ( !trim && best_outside_facet) {
1642 : : // if (best_edge->proj_to_line( this_point, best_point )!= CUBIT_SUCCESS) {
1643 : : if (best_edge->closest_point( this_point, best_point )!= CUBIT_SUCCESS) {
1644 : : return CUBIT_FAILURE;
1645 : : }
1646 : : }
1647 : :
1648 : :
1649 : : // evaluate the tangent if required
1650 : :
1651 : : if (tangent_ptr) {
1652 : : //get 2 adjacent edges
1653 : : CubitVector tangent;
1654 : : if (best_edge->edge_tangent( best_point, tangent )
1655 : : != CUBIT_SUCCESS) {
1656 : : return CUBIT_FAILURE;
1657 : : }
1658 : : if (curvSense == CUBIT_REVERSED)
1659 : : tangent = -tangent;
1660 : : *tangent_ptr = tangent;
1661 : : }
1662 : :
1663 : : // evaluate the curvature if required
1664 : : if (curvature_ptr) {
1665 : : CubitVector curvature;
1666 : : myEdgeList.move_to( best_edge );
1667 : : int index = myEdgeList.get_index();
1668 : :
1669 : : //"best_edge" could be last or first on curve
1670 : : CubitFacetEdge* prev_edge = NULL;
1671 : : myEdgeList.back();
1672 : : if( (index - 1) == myEdgeList.get_index() )
1673 : : prev_edge = myEdgeList.get();
1674 : :
1675 : : CubitFacetEdge* next_edge = NULL;
1676 : : myEdgeList.step(2);
1677 : : if( (index + 1) == myEdgeList.get_index() )
1678 : : next_edge = myEdgeList.get();
1679 : :
1680 : :
1681 : : CubitFacetEdge *closest_edge;
1682 : : //determine which adjacent edge is closest to "best_point"
1683 : : if( prev_edge && next_edge )
1684 : : {
1685 : : CubitVector tmp_vec;
1686 : : double prev_dist, next_dist;
1687 : : tmp_vec = (prev_edge->point(0)->coordinates() +
1688 : : prev_edge->point(1)->coordinates() ) / 2;
1689 : : prev_dist = best_point.distance_between( tmp_vec );
1690 : :
1691 : : tmp_vec = (next_edge->point(0)->coordinates() +
1692 : : next_edge->point(1)->coordinates() ) / 2;
1693 : : next_dist = best_point.distance_between( tmp_vec );
1694 : :
1695 : : if( prev_dist < next_dist )
1696 : : closest_edge = prev_edge;
1697 : : else
1698 : : closest_edge = next_edge;
1699 : : }
1700 : : else if( prev_edge )
1701 : : closest_edge = prev_edge;
1702 : : else
1703 : : closest_edge = next_edge;
1704 : :
1705 : : if (best_edge->edge_curvature( best_point, curvature, closest_edge ) != CUBIT_SUCCESS) {
1706 : : return CUBIT_FAILURE;
1707 : : }
1708 : : if (curvSense == CUBIT_REVERSED)
1709 : : curvature = -curvature;
1710 : : *curvature_ptr = curvature;
1711 : : }
1712 : :
1713 : : closest_point = best_point;
1714 : : *outside = best_outside_facet;
1715 : :
1716 : : if (param)
1717 : : {
1718 : : *param = u_on_facet_edge( best_edge, closest_point );
1719 : : }
1720 : :
1721 : : // clear the marks from the used edges
1722 : :
1723 : : for (ii=0; ii<used_edge_list.size(); ii++)
1724 : : {
1725 : : edge = used_edge_list.get_and_step();
1726 : : edge->set_flag( 0 );
1727 : : }
1728 : :
1729 : :
1730 : : return CUBIT_SUCCESS;
1731 : : }
1732 : :
1733 : : */
1734 : : //===========================================================================
1735 : : //Function Name: u_on_facet_edge
1736 : : //
1737 : : //Member Type: PRIVATE
1738 : : //Description: return the u param on the facet curve given a point on the
1739 : : // curve and the facet edge it is on
1740 : : //===========================================================================
1741 : 3410 : double CurveFacetEvalTool::u_on_facet_edge( CubitFacetEdge *edge_at_pt,
1742 : : CubitVector pt )
1743 : : {
1744 : : int ii;
1745 : 3410 : double cum_len = 0.0;
1746 : 3410 : CubitBoolean done = CUBIT_FALSE;
1747 : 3410 : myEdgeList.reset();
1748 [ + + ][ + - ]: 6820 : for (ii=0; ii<myEdgeList.size() && !done; ii++) {
[ + + ]
1749 : 3410 : CubitFacetEdge *edge = myEdgeList.get_and_step();
1750 [ - + ]: 3410 : if (edge != edge_at_pt)
1751 : : {
1752 : 0 : cum_len += edge->length();
1753 : : }
1754 : : else
1755 : : {
1756 [ + - ]: 3410 : CubitVector pt0;
1757 [ - + ]: 3410 : if (curvSense == CUBIT_REVERSED)
1758 : : {
1759 [ # # ][ # # ]: 0 : pt0 = edge->point( 1 )->coordinates();
[ # # ]
1760 : : }
1761 : : else
1762 : : {
1763 [ + - ][ + - ]: 3410 : pt0 = edge->point( 0 )->coordinates();
[ + - ]
1764 : : }
1765 [ + - ]: 3410 : cum_len += pt.distance_between( pt0 );
1766 : 3410 : done = CUBIT_TRUE;
1767 : : }
1768 : : }
1769 [ - + ]: 3410 : if (!done)
1770 : : {
1771 [ # # ][ # # ]: 0 : PRINT_DEBUG_122( "Error in CurveFacetEvalTool::u_on_facet_edge" );
[ # # ]
1772 : : }
1773 : 3410 : double u = cum_len / facetLength;
1774 : 3410 : return u;
1775 : : }
1776 : :
1777 : : //===========================================================================
1778 : : //Function Name: destroy_facets
1779 : : //
1780 : : //Member Type: PRIVATE
1781 : : //Description: Deletes the points and facets.
1782 : : //===========================================================================
1783 : 0 : void CurveFacetEvalTool::destroy_facets()
1784 : : {
1785 : :
1786 : 0 : }
1787 : :
1788 : :
1789 : : //===========================================================================
1790 : : //Function Name: draw_edges
1791 : : //
1792 : : //Member Type: PRIVATE
1793 : : //Description: draw the facet edges
1794 : : //===========================================================================
1795 : 0 : void CurveFacetEvalTool::draw_edges(int color)
1796 : : {
1797 : : int ii;
1798 [ # # ]: 0 : if ( color == -1 )
1799 : 0 : color = CUBIT_BLUE_INDEX;
1800 [ # # ]: 0 : for ( ii = myEdgeList.size(); ii > 0; ii-- )
1801 : : {
1802 : 0 : CubitFacetEdge *edge = myEdgeList.get_and_step();
1803 : 0 : CubitPoint *begin_point = edge->point(0);
1804 : 0 : CubitPoint *end_point = edge->point(1);
1805 : 0 : GfxDebug::draw_line(begin_point->x(),
1806 : 0 : begin_point->y(),
1807 : 0 : begin_point->z(),
1808 : 0 : end_point->x(),
1809 : 0 : end_point->y(),
1810 : 0 : end_point->z(),
1811 : 0 : color);
1812 : : }
1813 : 0 : GfxDebug::flush();
1814 : 0 : }
1815 : :
1816 : : //===========================================================================
1817 : : //Function Name: draw_edge
1818 : : //
1819 : : //Member Type: PRIVATE
1820 : : //Description: draw the facet edge
1821 : : //===========================================================================
1822 : 0 : void CurveFacetEvalTool::draw_edge(CubitFacetEdge *edge, int color)
1823 : : {
1824 : :
1825 : 0 : CubitPoint *begin_point = edge->point(0);
1826 : 0 : CubitPoint *end_point = edge->point(1);
1827 : 0 : GfxDebug::draw_line(begin_point->x(),
1828 : 0 : begin_point->y(),
1829 : 0 : begin_point->z(),
1830 : 0 : end_point->x(),
1831 : 0 : end_point->y(),
1832 : 0 : end_point->z(),
1833 : 0 : color);
1834 : :
1835 : 0 : GfxDebug::flush();
1836 : 0 : }
1837 : :
1838 : : //===========================================================================
1839 : : //Function Name: draw_line
1840 : : //
1841 : : //Member Type: PRIVATE
1842 : : //===========================================================================
1843 : 0 : void CurveFacetEvalTool::draw_line(CubitVector &begin, CubitVector &end, int color)
1844 : : {
1845 : 0 : GfxDebug::draw_line(begin.x(), begin.y(), begin.z(),
1846 : 0 : end.x(), end.y(), end.z(), color);
1847 : 0 : GfxDebug::flush();
1848 : 0 : }
1849 : :
1850 : : //===========================================================================
1851 : : //Function Name: draw_location
1852 : : //
1853 : : //Member Type: PRIVATE
1854 : : //===========================================================================
1855 : 0 : void CurveFacetEvalTool::draw_location(CubitVector &loc, int color )
1856 : : {
1857 [ # # ]: 0 : if ( color == -1 )
1858 : 0 : color = CUBIT_YELLOW_INDEX;
1859 : 0 : GfxDebug::draw_point(loc, color);
1860 : 0 : GfxDebug::flush();
1861 : 0 : }
1862 : :
1863 : : //===========================================================================
1864 : : //Function Name: set_length
1865 : : //
1866 : : //Member Type: PRIVATE
1867 : : //Description: compute the length of the facets in this curve
1868 : : // assumption: facet edges have been set up
1869 : : //===========================================================================
1870 : 594 : void CurveFacetEvalTool::set_length()
1871 : : {
1872 : : int ii;
1873 : : CubitFacetEdge *cf_edge;
1874 : :
1875 : 594 : facetLength = 0.0e0;
1876 : :
1877 [ + + ]: 1342 : for (ii=0; ii<myEdgeList.size(); ii++)
1878 : : {
1879 : 748 : cf_edge = myEdgeList.get_and_step();
1880 : 748 : facetLength += cf_edge->length();
1881 : : }
1882 : :
1883 : 594 : }
1884 : :
1885 : : //===========================================================================
1886 : : //Function Name: save
1887 : : //
1888 : : //Member Type: PUBLIC
1889 : : //Description: save the curve facet eval tool to a cubit file
1890 : : // Assumption: contained edge facets have been previuosly saved. This function
1891 : : // saves only the edge facet ids.
1892 : : //===========================================================================
1893 : 462 : CubitStatus CurveFacetEvalTool::save(
1894 : : FILE *fp )
1895 : : {
1896 [ + - ]: 462 : NCubitFile::CIOWrapper cio(fp);
1897 : : typedef NCubitFile::UnsignedInt32 int32;
1898 : :
1899 : : // write out "interpOrder"
1900 [ + - ]: 462 : cio.Write(reinterpret_cast<int32*>(&interpOrder), 1);
1901 : :
1902 : : // write the associated facet eval tool id. If there is none then write -1
1903 : 462 : int surf_tool_id = -1;
1904 [ + - ]: 462 : if (surfFacetEvalTool != NULL)
1905 [ + - ]: 462 : surf_tool_id = surfFacetEvalTool->get_output_id();
1906 [ + - ]: 462 : cio.Write(reinterpret_cast<int32*>(&surf_tool_id), 1);
1907 : :
1908 : : // convert "curvSense" in an int
1909 : : int sense;
1910 [ - + ]: 462 : if( curvSense == CUBIT_UNKNOWN )
1911 : 0 : sense = -1;
1912 : : else
1913 [ - + ]: 462 : sense = (curvSense == CUBIT_REVERSED) ? 1 : 0;
1914 : :
1915 : : // write "curveSense" and "goodCurveData"
1916 [ + - ]: 462 : cio.Write(reinterpret_cast<int32*>(&sense), 1);
1917 [ + - ]: 462 : int32 is_good = goodCurveData ? 1 : 0;
1918 [ + - ]: 462 : cio.Write(&is_good, 1);
1919 : :
1920 : : // write "facetLength"
1921 [ + - ]: 462 : cio.Write( &facetLength, 1 );
1922 : :
1923 : : // write ids of facet edges in "myEdgeList"
1924 : : int ii;
1925 : : CubitFacetEdge *edge_ptr;
1926 [ + - ]: 462 : int nedges = myEdgeList.size();
1927 [ + - ][ + - ]: 462 : int32* edge_id = new int32 [nedges];
1928 [ + - ]: 462 : myEdgeList.reset();
1929 [ + + ]: 1078 : for (ii=0; ii<nedges; ii++)
1930 : : {
1931 [ + - ]: 616 : edge_ptr = myEdgeList.get_and_step();
1932 [ + - ]: 616 : edge_id[ii] = edge_ptr->id();
1933 : : }
1934 [ + - ]: 462 : cio.Write(reinterpret_cast<int32*>(&nedges), 1);
1935 [ + - ]: 462 : if (nedges > 0)
1936 : : {
1937 [ + - ]: 462 : cio.Write(edge_id, nedges);
1938 : : }
1939 [ + - ]: 462 : delete [] edge_id;
1940 : :
1941 : : // write ids of points in "myPointList"
1942 : : CubitPoint *point_ptr;
1943 [ + - ]: 462 : int npoints = myPointList.size();
1944 [ + - ][ + - ]: 462 : int32* point_id = new int32 [npoints];
1945 [ + - ]: 462 : myPointList.reset();
1946 [ + + ]: 1540 : for (ii=0; ii<npoints; ii++)
1947 : : {
1948 [ + - ]: 1078 : point_ptr = myPointList.get_and_step();
1949 [ + - ]: 1078 : point_id[ii] = point_ptr->id();
1950 : : }
1951 [ + - ]: 462 : cio.Write(reinterpret_cast<int32*>(&npoints), 1);
1952 [ + - ]: 462 : if (npoints > 0)
1953 : : {
1954 [ + - ]: 462 : cio.Write(point_id, npoints);
1955 : : }
1956 [ + - ]: 462 : delete [] point_id;
1957 : :
1958 [ + - ]: 462 : return CUBIT_SUCCESS;
1959 : : }
1960 : :
1961 : : //===========================================================================
1962 : : //Function Name: restore
1963 : : //Member Type: PUBLIC
1964 : : //Description: restore curve eval tool from a CUB file
1965 : : //author: sjowen
1966 : : //Date:1/28/2003
1967 : : //===========================================================================
1968 : 264 : CubitStatus CurveFacetEvalTool::restore(FILE *fp,
1969 : : unsigned int endian,
1970 : : int num_edges,
1971 : : int num_points,
1972 : : CubitFacetEdge **edges,
1973 : : CubitPoint **points,
1974 : : int num_fets,
1975 : : FacetEvalTool **fet_array)
1976 : : {
1977 [ + - ]: 264 : NCubitFile::CIOWrapper cio(endian, fp);
1978 : : typedef NCubitFile::UnsignedInt32 int32;
1979 : :
1980 : : // read stuff about this eval tool
1981 : :
1982 : : int ii;
1983 : : int int_data[4];
1984 [ + - ]: 264 : cio.Read(reinterpret_cast<int32*>(int_data), 4);
1985 : 264 : interpOrder = int_data[0];
1986 : 264 : int surf_tool_id = int_data[1];
1987 : :
1988 [ - + ]: 264 : if (int_data[2] == -1 )
1989 : 0 : curvSense = CUBIT_UNKNOWN;
1990 : : else
1991 [ - + ]: 264 : curvSense= int_data[2] ? CUBIT_REVERSED : CUBIT_FORWARD;
1992 : :
1993 [ - + ]: 264 : goodCurveData = (int_data[3]==0) ? CUBIT_FALSE : CUBIT_TRUE;
1994 : :
1995 [ + - ]: 264 : if( surf_tool_id != -1 )
1996 : 264 : surfFacetEvalTool = fet_array[ surf_tool_id ];
1997 : : else
1998 : 0 : surfFacetEvalTool = NULL;
1999 : :
2000 [ + - ]: 264 : cio.Read(&facetLength, 1);
2001 : :
2002 : : // read the edges
2003 : :
2004 : : int nedges;
2005 [ + - ]: 264 : cio.Read(reinterpret_cast<int32*>(&nedges), 1);
2006 [ + - ]: 264 : if (nedges > 0)
2007 : : {
2008 [ + - ][ + - ]: 264 : int32* edge_id = new int32 [nedges];
2009 [ + - ]: 264 : cio.Read(edge_id, nedges);
2010 : : int id;
2011 [ + + ]: 528 : for (ii=0; ii<nedges; ii++)
2012 : : {
2013 : 264 : id = edge_id[ii];
2014 [ + - ][ - + ]: 264 : if (id <0 || id >= num_edges)
2015 : : {
2016 [ # # ]: 0 : delete [] edge_id;
2017 : 0 : return CUBIT_FAILURE;
2018 : : }
2019 [ + - ]: 264 : myEdgeList.append(edges[id]);
2020 : : }
2021 [ + - ]: 264 : delete [] edge_id;
2022 : : }
2023 : :
2024 : : // read the points
2025 : :
2026 : : int npoints;
2027 [ + - ]: 264 : cio.Read(reinterpret_cast<int32*>(&npoints), 1);
2028 : : int id;
2029 [ + - ]: 264 : if (npoints > 0)
2030 : : {
2031 [ + - ][ + - ]: 264 : int32* point_id = new int32 [npoints];
2032 [ + - ]: 264 : cio.Read(point_id, npoints);
2033 [ + + ]: 792 : for (ii=0; ii<npoints; ii++)
2034 : : {
2035 : 528 : id = point_id[ii];
2036 [ + - ][ - + ]: 528 : if (id <0 || id >= num_points)
2037 : : {
2038 [ # # ]: 0 : delete [] point_id;
2039 : 0 : return CUBIT_FAILURE;
2040 : : }
2041 [ + - ]: 528 : myPointList.append(points[id]);
2042 : : }
2043 [ + - ]: 264 : delete [] point_id;
2044 : : }
2045 : :
2046 [ + - ][ + - ]: 264 : bounding_box();
2047 : :
2048 [ + - ]: 264 : return CUBIT_SUCCESS;
2049 : : }
2050 : :
2051 : 594 : CubitStatus CurveFacetEvalTool::fix_point_edge_order()
2052 : : {
2053 : : CubitFacetEdge* this_edge;
2054 : : CubitFacetEdge* next_edge;
2055 : : CubitPoint *this_pt1;
2056 : : CubitPoint *next_pt0, *next_pt1;
2057 : :
2058 [ - + ]: 594 : if( myEdgeList.size() == 0 )
2059 : 0 : return CUBIT_FAILURE;
2060 : :
2061 : 594 : this_edge = myEdgeList.get_and_step();
2062 : : int ii;
2063 [ + + ]: 748 : for( ii = myEdgeList.size() - 1; ii > 0; ii-- )
2064 : : {
2065 [ + - ]: 154 : if( 0 != this_edge->num_adj_facets() )
2066 : 154 : continue;
2067 : :
2068 : 0 : next_edge = myEdgeList.get_and_step();
2069 : :
2070 : 0 : this_pt1 = this_edge->point( 1 );
2071 : 0 : next_pt0 = next_edge->point( 0 );
2072 : 0 : next_pt1 = next_edge->point( 1 );
2073 : :
2074 [ # # ][ # # ]: 0 : if( this_pt1 != next_pt0 &&
2075 : : this_pt1 != next_pt1 )
2076 : : {
2077 : : //Swap direction of edge. (mod. 3-7-06) Now calling flip instead
2078 : : // of doing the flip manually. The flip function also tracks
2079 : : // the orientation so that we can remember the original orientation
2080 : : // of the edge.
2081 : 0 : this_edge->flip();
2082 : :
2083 : : }
2084 : :
2085 : 0 : this_edge = next_edge;
2086 : : }
2087 : : //Handle last edge
2088 : 594 : next_edge = myEdgeList.prev(2);
2089 [ - + ]: 594 : if( 0 == this_edge->num_adj_facets() )
2090 : : {
2091 : 0 : CubitPoint* this_pt0 = this_edge->point( 0 );
2092 : 0 : next_pt0 = next_edge->point( 0 );
2093 : 0 : next_pt1 = next_edge->point( 1 );
2094 : :
2095 [ # # ][ # # ]: 0 : if( this_pt0 != next_pt0 &&
2096 : : this_pt0 != next_pt1 )
2097 : : {
2098 : : //Swap direction of edge.(mod. 3-7-06) Now calling flip instead
2099 : : // of doing the flip manually. The flip function also tracks
2100 : : // the orientation so that we can remember the original orientation
2101 : : // of the edge.
2102 : 0 : this_edge->flip();
2103 : :
2104 : : }
2105 : : }
2106 : :
2107 : 594 : return CUBIT_SUCCESS;
2108 : : }
2109 : : //===========================================================================
2110 : : //Function Name: debug_draw_facet_edges
2111 : : //
2112 : : //Member Type: PUBLIC
2113 : : //Descriptoin: draw the facet edges for debug
2114 : : //===========================================================================
2115 : 0 : void CurveFacetEvalTool::debug_draw_facet_edges( int color )
2116 : : {
2117 : 0 : draw_edges(color);
2118 : 0 : }
2119 : :
2120 : 0 : CubitBoolean CurveFacetEvalTool::replace_point( CubitPoint *del_pnt, CubitPoint *keep_pnt )
2121 : : {
2122 : : CubitPoint *point_ptr;
2123 : 0 : int npoints = myPointList.size();
2124 : 0 : myPointList.reset();
2125 : 0 : CubitBoolean istat = CUBIT_FALSE;
2126 : : int i;
2127 [ # # ]: 0 : for ( i = 0; i < npoints; i++ )
2128 : : {
2129 : 0 : point_ptr = myPointList.get();
2130 : :
2131 [ # # ]: 0 : if( point_ptr == del_pnt )
2132 : : {
2133 : 0 : myPointList.remove();
2134 : 0 : myPointList.insert( keep_pnt );
2135 : 0 : istat = CUBIT_TRUE;
2136 : : }
2137 : 0 : myPointList.step();
2138 : : }
2139 : :
2140 : 0 : return istat;
2141 : : }
2142 : :
2143 : :
2144 : 0 : CubitBoolean CurveFacetEvalTool::replace_facets( DLIList< CubitFacetEdge *> &curv_edges )
2145 : : {
2146 : :
2147 : : // replace edges
2148 [ # # ]: 0 : this->myEdgeList = curv_edges;
2149 : :
2150 : : // replace points
2151 [ # # ]: 0 : DLIList<CubitPoint *> point_list;
2152 : : int i;
2153 : : // insert start point of every facet_edge
2154 [ # # ]: 0 : curv_edges.reset();
2155 [ # # ][ # # ]: 0 : for( i = 0; i < curv_edges.size(); i++ )
2156 : : {
2157 [ # # ][ # # ]: 0 : point_list.append( CAST_TO( curv_edges.get_and_step(), CubitFacetEdge )->point(0) );
[ # # ]
2158 : : }
2159 : : // insert end point of last facet_edge
2160 [ # # ][ # # ]: 0 : curv_edges.step( curv_edges.size() - 1 );
2161 [ # # ][ # # ]: 0 : point_list.append( CAST_TO( curv_edges.get(), CubitFacetEdge )->point(1) );
[ # # ]
2162 [ # # ]: 0 : this->myPointList = point_list;
2163 : :
2164 [ # # ]: 0 : return CUBIT_TRUE;
2165 : : }
2166 : :
2167 : :
2168 : 0 : void CurveFacetEvalTool::remove_facets( DLIList<CubitFacetEdge*> &facet_edges)
2169 : : {
2170 : 0 : facet_edges = myEdgeList;
2171 : 0 : myEdgeList.clean_out();
2172 : 0 : myPointList.clean_out();
2173 [ + - ][ + - ]: 6540 : }
|