CubitStatus Faceter::get_curve_facets( RefEdge* curve, DLIList<CubitPoint*>& segments ) const { //const double COS_ANGLE_TOL = 0.965925826289068312213715; // cos(15) const double COS_ANGLE_TOL = 0.984807753012208020315654; // cos(10) //const double COS_ANGLE_TOL = 0.996194698091745545198705; // cos(5) GMem curve_graphics; const double dist_tol = GEOMETRY_RESABS; const double dist_tol_sqr = dist_tol*dist_tol; Curve* curve_ptr = curve->get_curve_ptr(); curve_ptr->get_geometry_query_engine()->get_graphics( curve_ptr, &curve_graphics ); GPoint* gp = curve_graphics.point_list(); CubitPoint* last = (CubitPoint*) new FaceterPointData( gp->x, gp->y, gp->z ); ((FaceterPointData*)last)->owner(dynamic_cast<RefEntity*>(curve)); CubitVector lastv = last->coordinates(); segments.append( last ); GPoint* end = gp + curve_graphics.pointListCount - 1; for( gp++; gp < end; gp++ ) { CubitVector pos( gp->x, gp->y, gp->z ); CubitVector step1 = (pos - lastv); double len1 = step1.length(); if( len1 < dist_tol ) continue; GPoint* np = gp + 1; CubitVector next( np->x, np->y, np->z ); CubitVector step2 = next - pos; double len2 = step2.length(); if( len2 < dist_tol ) continue; double cosine = (step1 % step2) / (len1 * len2); if( cosine > COS_ANGLE_TOL ) continue; last = new FaceterPointData( pos ); ((FaceterPointData*)last)->owner(dynamic_cast<RefEntity*>(curve)); segments.append( last ); lastv = last->coordinates(); } CubitVector last_pos( gp->x, gp->y, gp->z ); segments.last(); while( (last_pos - (segments.get()->coordinates())).length_squared() < dist_tol_sqr ) { delete segments.pop(); segments.last(); } CubitPoint *tmp_point = (CubitPoint*) new FaceterPointData( last_pos ); segments.append( tmp_point ); ((FaceterPointData*)tmp_point)->owner( dynamic_cast<RefEntity*>(curve) ); // Now check if the segment list is reversed wrt the curve direction. segments.reset(); double u1, u2; if( segments.size() > 2 ) { u1 = curve->u_from_position( (segments.next(1)->coordinates()) ); u2 = curve->u_from_position( (segments.next(2)->coordinates()) ); } else { u1 = curve->u_from_position( (segments.get()->coordinates() ) ); u2 = curve->u_from_position( (segments.next()->coordinates()) ); } if( (u2 < u1) && (curve->start_param() <= curve->end_param()) ) segments.reverse(); //Make sure we don't have duplicate points. int jj; CubitVector curr, prev; for ( jj = segments.size(); jj > 0; jj-- ) { prev = segments.prev()->coordinates(); curr = segments.get_and_step()->coordinates(); if ( prev.about_equal(curr) ) { PRINT_DEBUG_129("Points on curve %d within tolerance...\n", curve->id()); segments.back(); delete segments.remove(); } } return CUBIT_SUCCESS; }