void CubitUtil::list_entity_ids( const char *pre_string, const DLIList<CubitEntity*> &entity_list, int width, const char *post_string, int sort, int unique, int tab, const char *sep_string, const char *post_string_none ) { DLIList <int> id_list( entity_list.size() ); for ( int i=0; i<entity_list.size(); i++ ) id_list.append( entity_list.next(i)->id() ); list_entity_ids( pre_string, id_list, width, post_string, sort, unique, tab, sep_string, post_string_none ); }
CubitStatus LoopParamTool::check_selfintersecting_coincident_edges(DLIList<DLIList<CubitPoint *>*> &loops_bounding_points) { //This function checks each line segment against every other line segment //to see if they intersect or overlap. Each line will be described //by the following equations: // // Pa = P1 + ua( P2 - P1 ) // Pb = P3 + ub( P4 - P3 ) // //Setting the Pa equal to Pb and solving for ua and ub you will get two //equation. Both will have the common denominator: // // denom = ( (uv4.y() - uv3.y()) * (uv2.x() - uv1.x() ) - // (uv4.x() - uv3.x()) * (uv2.y() - uv1.y() ) ) // //And the numerators will be: // // numer_a = ( (uv4.x() - uv3.x()) * (uv1.y() - uv3.y() ) - // (uv4.y() - uv3.y()) * (uv1.x() - uv3.x() ) ) // // numer_b = ( (uv2.x() - uv1.x()) * (uv1.y() - uv3.y() ) - // (uv2.y() - uv1.y()) * (uv1.x() - uv3.x() ) ) // //ua and ub then become: // // ua = numer_a / denom // ub = numer_b / denom // //If the lines are parallel then denom will be zero. If they are //also coincedent then the numerators will also be zero. For the //segments to intersect ua and ub need to both be between 0 //and 1. int ii, jj, kk, ll; for ( ii = 0; ii < loops_bounding_points.size(); ii++ ) { DLIList<CubitPoint*>* sub_loops_bounding_points1 = loops_bounding_points.next(ii); for( jj = 0; jj < sub_loops_bounding_points1->size(); jj++ ) { CubitPoint* start_point1 = sub_loops_bounding_points1->next(jj); CubitPoint* end_point1 = NULL; if ( jj == sub_loops_bounding_points1->size()-1 ) end_point1 = sub_loops_bounding_points1->next(0); else end_point1 = sub_loops_bounding_points1->next(jj+1); CubitVector uv1 = start_point1->coordinates(); CubitVector uv2 = end_point1->coordinates(); //Start with the current loop in the list. The previous //lists have already been checked against this list. for ( kk = ii; kk < loops_bounding_points.size(); kk++ ) { DLIList<CubitPoint*>* sub_loops_bounding_points2 = loops_bounding_points.next(kk); for ( ll = 0; ll < sub_loops_bounding_points2->size(); ll++ ) { CubitPoint* start_point2 = sub_loops_bounding_points2->next(ll); CubitPoint* end_point2 = NULL; if ( ll == sub_loops_bounding_points2->size()-1 ) end_point2 = sub_loops_bounding_points2->next(0); else end_point2 = sub_loops_bounding_points2->next(ll+1); CubitVector uv3 = start_point2->coordinates(); CubitVector uv4 = end_point2->coordinates(); if ( start_point1 == end_point2 || start_point1== start_point2 || end_point1 == start_point2 || end_point1 == end_point2 ) continue; if ( (uv1 == uv3) && (uv2 == uv4) ) continue; double denom = ( (uv4.y() - uv3.y()) * (uv2.x() - uv1.x() ) - (uv4.x() - uv3.x()) * (uv2.y() - uv1.y() ) ); double numer_a = ( (uv4.x() - uv3.x()) * (uv1.y() - uv3.y() ) - (uv4.y() - uv3.y()) * (uv1.x() - uv3.x() ) ); double numer_b = ( (uv2.x() - uv1.x()) * (uv1.y() - uv3.y() ) - (uv2.y() - uv1.y()) * (uv1.x() - uv3.x() ) ); if( denom < CUBIT_RESABS && denom > -CUBIT_RESABS ) { //The lines are parallel. Check the numerators to //see if they are coincident. if( numer_a < CUBIT_RESABS && numer_a > -CUBIT_RESABS && numer_b < CUBIT_RESABS && numer_b > -CUBIT_RESABS ) { //The lines are coincident. Now see if the segments //over lap. double ua; double ub; if( (uv2.x() - uv1.x()) < CUBIT_RESABS && (uv2.x() - uv1.x()) > -CUBIT_RESABS ) { if( (uv2.y() - uv1.y() < CUBIT_RESABS && uv2.y() - uv1.y() > -CUBIT_RESABS)){ PRINT_ERROR("Can't mesh due to zero-length edge.\n"); return CUBIT_FAILURE; } ua = (uv3.y() - uv1.y() ) / ( uv2.y() - uv1.y() ); ub = (uv4.y() - uv1.y() ) / ( uv2.y() - uv1.y() ); } else { ua = (uv3.x() - uv1.x() ) / ( uv2.x() - uv1.x() ); ub = (uv4.x() - uv1.x() ) / ( uv2.x() - uv1.x() ); } if( ua > CUBIT_RESABS && ua < (1.0 - CUBIT_RESABS ) || ub > CUBIT_RESABS && ub < (1.0 - CUBIT_RESABS )) { //The segments overlap. PRINT_ERROR("Can't mesh due to coincident edges \n\n\n"); return CUBIT_FAILURE; } } } else { double ua = numer_a / denom; double ub = numer_b / denom; if( ( (ua > CUBIT_RESABS && ua < (1.0-CUBIT_RESABS)) && (ub > CUBIT_RESABS && ub < (1.0-CUBIT_RESABS))) ) { PRINT_ERROR("Can't mesh due to self intersecting edges \n\n\n"); return CUBIT_FAILURE; } } }//end of for ( ll ) }// end of for ( kk ) }//end of for ( jj ) }// end of for ( ii ) return CUBIT_SUCCESS; }
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; }
CubitStatus LoopParamTool::transform_loopspoints_to_uv( DLIList<DLIList<CubitPoint *>*> &loops_point_list) { int ii, jj; CubitStatus ret_value = CUBIT_SUCCESS; DLIList<CubitPoint *> *sub_loops_point_list; CubitPoint *point_ptr; CubitVector xyz_location, uv_location, point_coordinates; // transform the points on the best fit plane ret_value = transform_to_bestfit_plane( loops_point_list); /*printf("\n after transform to best fit plane\n"); for( ii = 0; ii < loops_point_list.size(); ii++) { sub_loops_point_list = loops_point_list.get_and_step(); for ( jj = 0; jj < sub_loops_point_list->size(); jj++) { point_ptr = sub_loops_point_list->get_and_step(); point_coordinates = point_ptr->coordinates(); printf(" %f %f %f \n",point_coordinates.x(),point_coordinates.y(),point_coordinates.z()); } }*/ //transform to u-v for ( ii = 0; ii < loops_point_list.size(); ii++) { sub_loops_point_list = loops_point_list.get_and_step(); for ( jj = 0; jj < sub_loops_point_list->size(); jj++ ) { point_ptr = sub_loops_point_list->get_and_step(); xyz_location = point_ptr->coordinates(); ret_value = transform_to_uv_local( xyz_location, uv_location ); point_ptr->set(uv_location); } } if ( check_selfintersecting_coincident_edges(loops_point_list) != CUBIT_SUCCESS ) { //PRINT_ERROR("Self interesections in parameter space found.\n"); ret_value = CUBIT_FAILURE; } else ret_value = CUBIT_SUCCESS; // if the self-intersecting and coincident edges are not there then return CUBIT_SUCCESS // else restore the points to their original positions and return CUBIT_FAILURE return ret_value; //don't do the rest for now... if ( ret_value == CUBIT_SUCCESS ) return CUBIT_SUCCESS; else { ToolData *td; for ( ii = 0; ii < loops_point_list.size(); ii++ ) { sub_loops_point_list = loops_point_list.next(ii); for ( jj = 0; jj < sub_loops_point_list->size(); jj++) { point_ptr = sub_loops_point_list->next(jj); td = point_ptr->get_TD(&TDVector::is_td_vector); TDVector *td_pos = CAST_TO(td, TDVector); CubitVector orig_xyz_location = td_pos->get_vector(); point_ptr->set(orig_xyz_location); point_coordinates = point_ptr->coordinates(); } } return CUBIT_FAILURE; } }