void CubitUtil::sort_and_print_ids( const char *const heading, DLIList<int> &id_list, int should_sort, int report_once, int wrap ) { // sort, if desired if ( should_sort ) { id_list.sort(); } if ( report_once ) { DLIList <int> id_list_2( id_list ); id_list_2.reset(); id_list.clean_out(); id_list.append( id_list_2.get_and_step() ); for ( int j = id_list_2.size()-1; j--; ) { if ( id_list_2.get() != id_list_2.prev() ) id_list.append( id_list_2.get() ); id_list_2.step(); } } if( wrap == -1 ) { // print out ranges int begin = id_list.get_and_step(); int end = begin; int current = -1; PRINT_INFO(" The %d %s ids are %d", id_list.size(), heading, begin); for (int i=id_list.size()-1; i > 0; i--) { current = id_list.get_and_step(); if (current == end+1) { end++; } else { if (end == begin) { PRINT_INFO(", %d", current); } else if (end == begin+1) { PRINT_INFO(", %d, %d", end, current); } else { PRINT_INFO(" to %d, %d", end, current); } begin = current; end = begin; } } if (current == begin + 1) { PRINT_INFO(", %d", current); } else if (current != begin) { PRINT_INFO(" to %d", current); } PRINT_INFO(".\n"); } else { char pre_string[67]; sprintf( pre_string, " The %d %s ids are: ", id_list.size(),heading ); CubitUtil::list_entity_ids( pre_string, id_list, wrap, ".\n", CUBIT_FALSE, CUBIT_FALSE ); } }
void CubitUtil::process_entity_ids( int method, CubitString &ret_str, const char *pre_string, DLIList<int> &id_list, int max_len, const char *post_string, int sort, int unique, int tab_len, const char *sep_string, const char* post_string_none ) { // Method: 0 - to a string // 1 - to PRINT_INFO char temp[200]; if ( id_list.size() == 0 ) { if( method ) PRINT_INFO("%s%s", pre_string, post_string_none ); else { sprintf( temp, "%s%s", pre_string, post_string_none ); ret_str = temp; } if( fp ) fprintf( fp, "%s%s", pre_string, post_string_none ); return; } // sort if( sort ) { id_list.sort(); // make unique if( unique ) { int i; DLIList <int> id_list_2( id_list ); id_list_2.reset(); id_list.clean_out(); id_list.append( id_list_2.get_and_step() ); for ( i=id_list_2.size()-1; i--; ) { if ( id_list_2.get() != id_list_2.prev() ) id_list.append( id_list_2.get() ); id_list_2.step(); } } } if( max_len < 0 ) max_len = CUBIT_INT_MAX/2; // TODO: wrap prestring, if necessary if( method ) PRINT_INFO( "%s", pre_string ); else ret_str = pre_string; if( fp ) fprintf( fp, "%s", pre_string ); // Keep track of length printed int curr_len = strlen(pre_string); int num = 0; int begin = id_list.get(); int previous = begin; int current; int comma = 0; // Is comma needed int beg_len, prev_len; int sep_len = strlen( sep_string ); // Setup the tab char* tab = new char[tab_len+1]; for( int i=0; i<tab_len; i++ ) tab[i] = ' '; tab[tab_len] = '\0'; // Loop until all the ids are printed. Use ranges if possible. while( num < id_list.size()+1 ) { current = id_list.get_and_step(); num++; // Handle last entity if( num <= id_list.size() ) { if( num==1 ) // Handle 1st time in loop continue; if( current==previous+1 ) { previous = current; continue; } } // If we are here, we are no longer tracking a range and // need to print the range or a number. if( comma ) { if( method ) PRINT_INFO("%s", sep_string ); else ret_str += sep_string; if( fp ) fprintf( fp, "%s", sep_string ); curr_len += sep_len; } if( begin==previous ) { // a single number prev_len = int_len(previous); if( curr_len+1+prev_len+sep_len > max_len ) { if( method ) { PRINT_INFO( "\n" ); PRINT_INFO( "%s%d", tab, previous ); } else { sprintf( temp, "\n%s%d", tab, previous ); ret_str += temp; } if( fp ) fprintf( fp, "\n%s%d", tab, previous ); curr_len = tab_len + prev_len; } else { if( comma ) // Don't print space before first item { if( method ) PRINT_INFO( " " ); else ret_str += " "; if( fp ) fprintf( fp, " " ); curr_len++; } if( method ) PRINT_INFO( "%d", previous ); else { sprintf( temp, "%d", previous ); ret_str += temp; } if( fp ) fprintf( fp, "%d", previous ); curr_len = curr_len + prev_len; } } else if( previous==begin+1 ) { // a range, but only 2 consecutive numbers prev_len = int_len(previous); beg_len = int_len(begin); // Print 1st if( curr_len+1+beg_len+sep_len > max_len ) { if( method ) { PRINT_INFO( "\n" ); PRINT_INFO( "%s%d%s", tab, begin, sep_string ); } else { sprintf( temp, "\n%s%d%s", tab, begin, sep_string ); ret_str += temp; } if( fp ) fprintf( fp, "\n%s%d%s", tab, begin, sep_string ); curr_len = tab_len + beg_len + sep_len; } else { if( comma ) // Don't print space before first item { if( method ) PRINT_INFO( " " ); else ret_str += " "; if( fp ) fprintf( fp, " " ); curr_len++; } if( method ) PRINT_INFO( "%d%s", begin, sep_string ); else { sprintf( temp, "%d%s", begin, sep_string ); ret_str += temp; } if( fp ) fprintf( fp, "%d%s", begin, sep_string ); curr_len = curr_len + beg_len + sep_len; } // Print 2nd if( curr_len+1+prev_len+sep_len > max_len ) { if( method ) { PRINT_INFO( "\n" ); PRINT_INFO( "%s%d", tab, previous ); } else { sprintf( temp, "\n%s%d", tab, previous ); ret_str += temp; } if( fp ) fprintf( fp, "\n%s%d", tab, previous ); curr_len = tab_len + prev_len; } else { if( method ) PRINT_INFO( " %d", previous ); else { sprintf( temp, " %d", previous ); ret_str += temp; } if( fp ) fprintf( fp, " %d", previous ); curr_len = curr_len + 1+prev_len; } } else { // a range of 3 or more consecutive numbers prev_len = int_len(previous); beg_len = int_len(begin); if( curr_len+beg_len+prev_len+5+sep_len > max_len ) { if( method ) { PRINT_INFO( "\n" ); PRINT_INFO( "%s%d to %d", tab, begin, previous ); } else { sprintf( temp, "\n%s%d to %d", tab, begin, previous ); ret_str += temp; } if( fp ) fprintf( fp, "\n%s%d to %d", tab, begin, previous ); curr_len = tab_len + beg_len+prev_len+4; } else { if( comma ) // Don't print space before first item { if( method ) PRINT_INFO( " " ); else ret_str += " "; if( fp ) fprintf( fp, " " ); curr_len++; } if( method ) PRINT_INFO( "%d to %d", begin, previous ); else { sprintf( temp, "%d to %d", begin, previous ); ret_str += temp; } if( fp ) fprintf( fp, "%d to %d", begin, previous ); curr_len = curr_len + beg_len+4+prev_len; } } begin = current; previous = current; comma = 1; } //TODO: wrap poststring, if required if (post_string) { if( method ) PRINT_INFO( "%s", post_string ); else ret_str += post_string; if( fp ) fprintf( fp, "%s", post_string ); } delete [] tab; }
CubitStatus Faceter::facet_factory(FaceterPointData *curr_faceter_data, CubitFacet *&new_facet, DLIList <FaceterPointData*> &order_list) { double angle; DLIList<CubitPoint*> loop_list; new_facet = NULL; if ( avoid_facet(curr_faceter_data, order_list) ) return CUBIT_SUCCESS; FaceterPointData *prev = curr_faceter_data->get_prev(); FaceterPointData *next = curr_faceter_data->get_next(); //create the new facet. //create a triangle from these three points. new_facet = (CubitFacet*) new FaceterFacetData((CubitPoint*)prev, (CubitPoint*)curr_faceter_data, (CubitPoint*)next); CubitVector facet_normal = new_facet->normal(); CubitVector surface_normal = thisRefFacePtr->normal_at(curr_faceter_data->coordinates()); double dot = facet_normal%surface_normal; if ( dot < 0 ) { //new need to try and do this in a different way... delete new_facet; new_facet = NULL; if ( order_list.size() < 3 ) { PRINT_DEBUG_129("Last triangle is inverted. (surface %d)\n", thisRefFacePtr->id()); return CUBIT_FAILURE; } //Try and create facets on either side of this facet. return CUBIT_FAILURE; } int debug = 1; if ( debug ) GfxDebug::draw_facet(new_facet, CUBIT_RED); //Now fix up the ordered_list. //First update the angles. prev->set_next(next); next->set_prev(prev); loop_list.clean_out(); loop_list.append(prev->get_prev()); loop_list.append(prev); loop_list.append(next); loop_list.step(); interior_angle(&loop_list, angle); prev->set_interior_angle(angle); loop_list.clean_out(); loop_list.append(prev); loop_list.append(next); loop_list.append(next->get_next()); loop_list.step(); interior_angle(&loop_list, angle); next->set_interior_angle(angle); //Now do basically a sort again. There is probably //a faster way to do this but there are also much slower //ways in worst case too. At least this has guaranteed O(nlogn). order_list.sort(FaceterPointData::sort_by_angle); CubitPoint *tmp_point = (CubitPoint*) curr_faceter_data; gridSearchPtr->remove_point(tmp_point); return CUBIT_SUCCESS; }