void Faceter::max_min_edge_ratio( DLIList <DLIList <CubitPoint*>*> &boundary_point_loops, double &ratio, double &cell_size) { double max_edge_length = CUBIT_DBL_MIN; double min_edge_length = CUBIT_DBL_MAX; double sum = 0.0; int total_count = 0; DLIList<CubitPoint*> *loopPtr; CubitPoint *node1, *node2; CubitVector edge; for (int i = boundary_point_loops.size(); i > 0; i--) { loopPtr = boundary_point_loops.get_and_step(); node2 = loopPtr->prev(); for (int j = loopPtr->size(); j > 0; j--) { node1 = node2; node2 = loopPtr->get_and_step(); CubitVector p1 = node1->coordinates(); CubitVector p2 = node2->coordinates(); edge = p2-p1; double edge_length = edge.length_squared(); if (edge_length > max_edge_length) max_edge_length = edge_length; if (edge_length < min_edge_length) min_edge_length = edge_length; total_count++; sum += edge_length; } } if (min_edge_length > CUBIT_RESABS) { ratio = sqrt(max_edge_length/min_edge_length); } else { ratio = sqrt(max_edge_length); } if ( total_count > 0 && sum > 0 ) cell_size = sqrt(sum/total_count); else cell_size = 0.0; }
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; }