示例#1
0
void MyClass::GOST2012(){
emit set_max(0);
    QFile file(fname);
    emit sendStringFileName(fname);
    CTX = (GOST34112012Context*)(malloc(sizeof(GOST34112012Context)));
    if(sizeHash==64)
        GOST34112012Init(CTX, 512);
    if(sizeHash==32)
        GOST34112012Init(CTX, 256);

     if (file.open(QIODevice::ReadOnly) )
               {
                 while (!file.atEnd()) {
                 QByteArray line = file.read(4096);
                 GOST34112012Update(CTX, (unsigned char*)(line.data()), line.size());
               }
             }
             file.close();
             GOST34112012Final(CTX, &digest[0]);
     convert_to_hex(digest, hexdigest, sizeHash, 1);//eflag=1 (в Госте в таком виде хеш получается)// eflag=0 наоборот развернут
     QString rez = (char*)hexdigest;
    // QString rez = (char*)digest;
    //  rez   = rez.toLocal8Bit().toHex();
             GOST34112012Cleanup(CTX);

    emit sendString(rez);emit set_max(100);emit change_value(100);emit finished();emit sendStringDone("Complete");
}
示例#2
0
int	*prepare_tab(char *file, int width, int *max, int height)
{
  int	j;
  int	i;
  int	*tab;

  if ((tab = malloc(sizeof(int) * my_strlen(file))) == NULL)
    return (exit_prepare_tab(tab, NULL));
  max = set_max();
  j = 0;
  i = 0;
  while (*file++ != '\n');
  while (file[i++] != '\0' && max[0] < width && max[0] < height)
    {
      if (file[i - 1] == '.')
	tab[j] = check_lowest(tab, width, j);
      else if (file[i - 1] == 'o')
	tab[j] = 0;
      else if (file[i - 1] == '\n' || file[i - 1] == '\0')
	tab[j] = -1;
      else
	return (exit_prepare_tab(tab, max));
      if (tab[j++] > max[0])
	max = update_max(max, j - 1, tab[j - 1]);
    }
  free(tab);
  return (max);
}
int main() {

  unsigned a, b, tmp, count;
  unsigned max = 0;
  while (std::cin >> a >> b) {
    std::cout << a << " " << b << " ";
    set_max(b,a);
    
    max = 0;
    for (int i = a; i <= b; ++i) {
      tmp = i;
      count = 1;

      while (tmp != 1) {
	count++;
	if (tmp % 2 == 0)
	  tmp = tmp / 2;
	else
	  tmp = 3 * tmp + 1;
      }

      if (count > max)
	max = count;
    }

    std::cout << max << std::endl;
  }

  return 0;
}
示例#4
0
文件: variograms.cpp 项目: hpgl/hpgl
void calc_search_template_window(
    variogram_search_template_t * templ,
    search_template_window_t * window)
{
    double max = 1e10;
    double mini, maxi, minj, maxj, mink, maxk;
    mini = minj = mink = max;
    maxi = maxj = maxk = -max;

    for (int i = 0; i < 2; ++i)
        for (int j = -1; j < 3; j += 2)
            for (int k = -1; k < 3; k+=2)
            {
                vector_t DI = {0};
                vector_t DJ = {0};
                vector_t DK = {0};
                vector_t V = {0};

                vec_by_scalar(&templ->m_ellipsoid.m_direction1, templ->m_lag_separation, &DI);
                vec_by_scalar(&DI, templ->m_num_lags, &DI);
                vec_by_scalar(&DI, i, &DI);

                vec_by_scalar(&templ->m_ellipsoid.m_direction2, templ->m_ellipsoid.m_R2, &DJ);
                vec_by_scalar(&DJ, j, &DJ);

                vec_by_scalar(&templ->m_ellipsoid.m_direction3, templ->m_ellipsoid.m_R3, &DK);
                vec_by_scalar(&DK, k, &DK);

                sum_vec(&DI, &DJ, &V);
                sum_vec(&V, &DK, &V);

                set_min(&mini, V.m_data[0]);
                set_max(&maxi, V.m_data[0]);
                set_min(&minj, V.m_data[1]);
                set_max(&maxj, V.m_data[1]);
                set_min(&mink, V.m_data[2]);
                set_max(&maxk, V.m_data[2]);
            }
    window->m_min_i = mini;
    window->m_max_i = maxi;
    window->m_min_j = minj;
    window->m_max_j = maxj;
    window->m_min_k = mink;
    window->m_max_k = maxk;
}
示例#5
0
void list_slider<T>::set_items(const std::vector<T> &items)
{
	items_ = items;
	if(items.size() > 0)
	{
		set_max(items.size() - 1);
	}
	slider::set_value(0);
}
示例#6
0
void MyClass::MyCalcMD5()
{
emit set_max(0);
        QCryptographicHash hash(QCryptographicHash::Md5);
        QFile file(fname);
        if (file.open(QIODevice::ReadOnly) )
          {

            while (!file.atEnd()) {
            QByteArray line = file.read(1024);
            hash.addData(line);
          }
        }
        file.close();
        QString rez = hash.result().toHex().data();
        emit sendString(rez);emit set_max(100);emit change_value(100);
emit finished();emit sendStringDone("Complete");
}
示例#7
0
    void add( value_t x )
    {
        base_t::add( x );

        if ( x < _min )
            set_min( x );
        if ( x > _max )
            set_max( x );
    }
示例#8
0
list_slider<T>::list_slider(CVideo &video, const std::vector<T> &items) :
	slider(video),
	items_(items)
{
	set_min(0);
	set_increment(1);
	if(items.size() > 0)
	{
		set_max(items.size() - 1);
	}
	slider::set_value(0);
}
void GraphWidget::update_(uint32_t intr_sum)
{
    uint32_t i;
    /* Will ignore this */
    if (intr_sum > (1<<27))
        intr_sum = 0;

    for(i = 1; i < G_DIVISORS; ++i)
        this->divisors[i-1] = this->divisors[i];
    this->divisors[G_DIVISORS-1] = intr_sum;

    set_max();

    this->update();
}
示例#10
0
    void merge( const simple_sample_data_with_min_max_t& other )
    {
        base_t::merge( other );

        if ( other.found_min_max() )
        {
            if ( other._min < _min )
            {
                set_min( other._min );
            }
            if ( other._max > _max )
            {
                set_max( other._max );
            }
        }
    }
示例#11
0
文件: timeman.cpp 项目: hof/qm2
void time_manager_t::set(const int my_time, const int opp_time, const int my_inc, const int opp_inc, const int moves_left) {

    //determine M, the guessed amount of moves left
    int M_MAX, M_MIN;
    if (my_inc > my_time) {
        M_MAX = 1;
        M_MIN = 1;
    } else if (moves_left > 0) {
        M_MIN = MIN(2 * moves_left, time_man::M_MIN);
        M_MAX = MIN(moves_left, time_man::M_MAX);
    } else if (my_inc == 0 && my_time < time_man::LOW_TIME) {
        M_MIN = time_man::M_MIN_LOW_TIME;
        M_MAX = time_man::M_MAX_LOW_TIME;
    } else {
        M_MIN = time_man::M_MIN;
        M_MAX = time_man::M_MAX;
    }

    //set the min/max time range based on time left and M
    tot_min = my_time / M_MIN;
    tot_max = my_time / M_MAX;

    //adjustment based on opponent's time
    const int delta = my_time - opp_time;
    if (delta > 0 && tot_max < delta && my_inc >= opp_inc && opp_time > 0) {
        tot_min += (32 * delta) / 256;
        tot_max += (64 * delta) / 256;
    } else if (delta < 0 && tot_max < -delta && my_inc <= opp_inc && moves_left == 0) {
        const double factor = MAX(0.5, (1.0 * my_time) / (1.0 * opp_time + 1.0));
        tot_min *= factor;
        tot_max *= factor;
    }

    //increment bonus
    if (my_inc > 0) {
        const int min_inc_bonus = MIN(my_inc, my_time - tot_min);
        const int max_inc_bonus = MIN(my_inc, my_time - tot_max);
        tot_min += (196 * min_inc_bonus) / 256;
        tot_max += max_inc_bonus;
    }

    tot_min = MAX(0, tot_min - time_man::LAG_TIME);
    tot_max = MAX(0, tot_max - time_man::LAG_TIME);
    set_max(tot_max);
    set_min(tot_min);

}
示例#12
0
文件: flag.c 项目: aaudibert/team_ls
t_align		*max(t_file *dir, int file, t_stat *st)
{
	t_align	*max_all;

	max_all = (t_align*)malloc(sizeof(t_align));
	max_all->link = 0;
	max_all->usr = 0;
	max_all->grp = 0;
	max_all->size = 0;
	max_all->minor = 0;
	max_all->major = 0;
	while (dir != NULL)
	{
		if (file == 1 || (opt_a(dir) && st->st_mode & S_IXUSR))
			set_max(dir, max_all);
		dir = dir->next;
	}
	return (max_all);
}
示例#13
0
文件: fp_node.cpp 项目: CCJY/engine-1
void fp_node::merge(fp_node *right_node)
{
	// merges two nodes
	// w.r.t. this node is left node an in node is right node

	// adapt frequency and interval
	set_freq( get_freq() + right_node->get_freq());
	set_max( right_node->get_max() );

	// merge children
	fp_nodelist &right_childs = right_node->get_childs();

	fp_nodelist::iterator left_it = m_childs.begin();
	fp_nodelist::iterator right_it = right_childs.begin();

	while (right_it != right_childs.end()){
		if ((left_it == m_childs.end()) || (*right_it)->left_of(*(*left_it))) {
			add_child(*right_it);
			fp_nodelist::iterator tmpit = right_it;
			right_it++;
			right_childs.erase(tmpit);
		} else if ((*left_it)->contains(*(*right_it))) {
			(*left_it)->merge(*right_it); // recursive step
			fp_nodelist::iterator tmpit = right_it;
			right_it++;
			right_childs.erase(tmpit);
		} else if ((*right_it)->contains(*(*left_it))) {
			(*right_it)->merge(*left_it);
			fp_nodelist::iterator tmpit = left_it;
			left_it++;
			m_childs.erase(tmpit);
		} else {
			left_it++;
		}
	}

	// cleanup right node
	delete right_node;
}
示例#14
0
void
ui_feedback::set_maximum(int m)
{
  emit set_max(m);
  QApplication::processEvents();
}
示例#15
0
void Problem_18::run()
{
	std::vector<std::vector<short>> triangle =
	{{75},
	{95,64},
	{17,47,82},
	{18,35,87,10},
	{20,4,82,47,65},
	{19,1,23,75,3,34},
	{88,2,77,73,7,63,67},
	{99,65,4,28,6,16,70,92},
	{41,41,26,56,83,40,80,70,33},
	{41,48,72,33,47,32,37,16,94,29},
	{53,71,44,65,25,43,91,52,97,51,14},
	{70,11,33,28,77,73,17,78,39,68,17,57},
	{91,71,52,38,17,14,91,43,58,50,27,29,48},
	{63,66,4,68,89,53,67,30,73,16,69,87,40,31},
	{04,62,98,27,23,9,70,98,73,93,38,53,60,4,23}};

	u_int num = triangle.size();

	/*
	// first heuristic (chose the highest) : didn't worked, would be too easy...
	int sum = triangle[0][0];
	u_int i = 0;
	u_int j = 0;
	while(i < num-1)
	{
		if(triangle[i+1][j] > triangle[i+1][j+1])
		{
			sum += triangle[i+1][j];
			i++;
		}
		else
		{
			sum += triangle[i+1][j+1];
			i++;
			j++;
		}
	}
	*/

	std::vector<std::vector<u_int>> triangle_sol = std::vector<std::vector<u_int>>(num,std::vector<u_int>(num,0));

	triangle_sol[0][0] = triangle[0][0];
	for (u_int i = 1; i < num; ++i)
	{
		triangle_sol[i][0] = triangle_sol[i-1][0] + triangle[i][0];

		for (u_int j = 1; j < triangle[i].size(); ++j)
		{
			if (triangle_sol[i-1][j-1] > triangle_sol[i-1][j])
			{
				triangle_sol[i][j] = triangle_sol[i-1][j-1] + triangle[i][j];
			}
			else
			{
				triangle_sol[i][j] = triangle_sol[i-1][j] + triangle[i][j];
			}
		}
	}

	u_int max = 0;
	for (u_int i = 0; i < num; ++i)
	{
		set_max(max,triangle_sol[num-1][i]);
	}
	printf("%d\n", max);
}
示例#16
0
/**************************************************************************
 *
 *N  related_rows
 *
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    Return the list of related rows of table2 based upon the value of
 *    table 1's key.
 *    Supported data types - I and T<n>.
 *    Binary search supported only for data type I. (column must be sorted)
 *    Thematic index used, if present on key column.
 *    NOTE: A sequential search operation will search the entire
 *          table ...zzz...
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels  DOS Turbo C
 *E
 *************************************************************************/
linked_list_type related_rows( void *keyval1,
		       vpf_table_type table2, char *key2,
		       int sort_flag,
		       ThematicIndex *idx )
{
   linked_list_type rowlist;
   set_type rowset;
   long int rowid, i, ival, kval, n, start,end;
   row_type row = 0;
   int KEY2_;
   char cval, *tval;

   rowlist = ll_init();

   if (ossim_strcasecmp(key2,"ID")==0) {
      memcpy( &rowid, keyval1, sizeof(rowid) );
      ll_insert(&rowid,sizeof(rowid),rowlist);
      return rowlist;
   }

   KEY2_ = table_pos(key2,table2);

   if ((table2.header[KEY2_].type != 'I')&&
       (table2.header[KEY2_].type != 'T')) return rowlist;

   if ((table2.header[KEY2_].type == 'I')&&
       (table2.header[KEY2_].count != 1)) return rowlist;

   if ((table2.header[KEY2_].type == 'T')&&(sort_flag)) sort_flag = 0;

   if (idx) {
      if (idx->fp) {
	 rowset = search_thematic_index(idx,(char *)keyval1);
	 start = set_min(rowset);
	 end = set_max(rowset);
	 for (i=start;i<=end;i++)
	    if (set_member(i,rowset)) {
	       ll_insert(&i,sizeof(i),ll_last(rowlist));
	    }
	 set_nuke(&rowset);
	 return rowlist;
      }
   }

   if (!sort_flag) {   /* Sequential search */

      for (i=1;i<=table2.nrows;i++) {
	 row = get_row(i,table2);
	 if (table2.header[KEY2_].type == 'I') {
	    get_table_element(KEY2_,row,table2,&ival,&n);
	    if (memcmp(&ival,keyval1,sizeof(ival))==0)
	       ll_insert(&i,sizeof(i),ll_last(rowlist));
	 } else {
	    if (table2.header[KEY2_].count==1) {
	       get_table_element(KEY2_,row,table2,&cval,&n);
	       if (memcmp(&cval,keyval1,sizeof(ival))==0)
		  ll_insert(&i,sizeof(i),ll_last(rowlist));
	    } else {
	       tval = (char*)get_table_element(KEY2_,row,table2,NULL,&n);
	       if (strcmp(tval,(char *)keyval1)==0)
		  ll_insert(&i,sizeof(i),ll_last(rowlist));
	    }
	 }
	 free_row(row,table2);
      }

   } else {   /* Binary search */

      memcpy(&kval,keyval1,sizeof(kval));
      rowid = vpf_binary_search( kval, KEY2_, table2 );

      if (rowid > 0) {
	 ll_insert(&rowid,sizeof(rowid),ll_last(rowlist));
	 i = rowid-1L;
	 do {
	    get_row(i,table2);
	    get_table_element(KEY2_,row,table2,&ival,&n);
	    if (ival == kval)
	       ll_insert(&i,sizeof(i),ll_last(rowlist));
	    i--;
	 } while ((ival==kval)&&(i>0));
	 i = rowid+1L;
	 do {
	    get_row(i,table2);
	    get_table_element(KEY2_,row,table2,&ival,&n);
	    if (ival == kval)
	       ll_insert(&i,sizeof(i),ll_last(rowlist));
	    i++;
	 } while ((ival==kval)&&(i<=table2.nrows));
      }

   }

   return rowlist;
}
示例#17
0
文件: label.cpp 项目: zz676/godot
void Label::regenerate_word_cache() {
	
	while (word_cache) {
		
		WordCache *current=word_cache;
		word_cache=current->next;
		memdelete( current );
	}
	
	
	int width=autowrap?get_size().width:get_longest_line_width();
	Ref<Font> font = get_font("font");

	int current_word_size=0;
	int word_pos=0;
	int line_width=0;
	int space_count=0;
	int space_width=font->get_char_size(' ').width;
	line_count=1;
	total_char_cache=0;
	
	WordCache *last=NULL;
	
	for (int i=0;i<text.size()+1;i++) {
		
		CharType current=i<text.length()?text[i]:' '; //always a space at the end, so the algo works

		if (uppercase)
			current=String::char_uppercase(current);

		bool not_latin = current>=33 && (current < 65||current >90) && (current<97||current>122) && (current<48||current>57);
		bool insert_newline=false;
		int char_width;

		if (current<33) {

			if (current_word_size>0) {
				WordCache *wc = memnew( WordCache );
				if (word_cache) {
					last->next=wc;
				} else {
					word_cache=wc;
				}
				last=wc;

				wc->pixel_width=current_word_size;
				wc->char_pos=word_pos;
				wc->word_len=i-word_pos;
				wc->space_count = space_count;
				current_word_size=0;
				space_count=0;

			}


			if (current=='\n') {
				insert_newline=true;
			} else {
				total_char_cache++;
			}

			if (i<text.length() && text[i] == ' ') {
				total_char_cache--;  // do not count spaces
				if (line_width > 0 || last==NULL || last->char_pos!=WordCache::CHAR_WRAPLINE) {
					space_count++;
					line_width+=space_width;
				}else {
					space_count=0;
				}
			}


		} else {
			// latin characters
			if (current_word_size==0) {
				word_pos=i;
			}
			
			char_width=font->get_char_size(current).width;
			current_word_size+=char_width;
			line_width+=char_width;
			total_char_cache++;
			
		}

		if ((autowrap && (line_width >= width) && ((last && last->char_pos >= 0) || not_latin)) || insert_newline) {
			if (not_latin) {
				if (current_word_size>0) {
					WordCache *wc = memnew( WordCache );
					if (word_cache) {
						last->next=wc;
					} else {
						word_cache=wc;
					}
					last=wc;

					wc->pixel_width=current_word_size-char_width;
					wc->char_pos=word_pos;
					wc->word_len=i-word_pos;
					wc->space_count = space_count;
					current_word_size=char_width;
					space_count=0;
					word_pos=i;
				}
			}

			WordCache *wc = memnew( WordCache );
			if (word_cache) {
				last->next=wc;
			} else {
				word_cache=wc;
			}
			last=wc;

			wc->pixel_width=0;
			wc->char_pos=insert_newline?WordCache::CHAR_NEWLINE:WordCache::CHAR_WRAPLINE;

			line_width=current_word_size;
			line_count++;
			space_count=0;

		}
		
	}
	
	//total_char_cache -= line_count + 1; // do not count new lines (including the first one)
	
	if (!autowrap) {
		
		minsize.width=width;
		minsize.height=font->get_height()*line_count;
		set_page( line_count );
		
	} else {
	
		set_page( get_size().height / font->get_height() );
	}
	
	set_max(line_count);
	
	word_cache_dirty=false;

}
示例#18
0
/** 
 * Add distance measure
 * 
 * @param rhs BBDist to add
 * 
 * @return Updated distance
 */
  BBDist& operator+=(const BBDist &rhs) {
    set_max(0, rhs);
    set_max(1, rhs);
    calc_d();
    return *this;
  }
示例#19
0
/*************************************************************************
 *
 *N  get_selected_primitives
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    This function determines all of the selected primitive rows from
 *    the selected features.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *     view     <input> == (view_type *) view structure.
 *     themenum <input> == (int) theme number.
 *     library  <input> == (library_type *) VPF library structure.
 *     mapenv   <input> == (map_environment_type *) map environment.
 *     status  <output> == (int *) status of the function:
 *                         1 if completed, 0 if user escape.
 *     get_selected_primitives <output> == (set_type *) array of sets, each position
 *                         representing the set of primitives for the
 *                         corresponding tile in the tileref.aft table.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels   May 1991                           DOS Turbo C
 *E
 *************************************************************************/
set_type *get_selected_primitives( view_type *view,
				   int themenum,
				   library_type *library,
				   map_environment_type *mapenv,
				   int *status )
{
   int fcnum, finished, found, cov, tilecover, TILEPATH_, degree;
   int feature, prim;
   vpf_table_type tile_table;
   row_type row;
   char *ptable[] = {"","edg","fac","txt","end","cnd"};
   char *spxname[] = {"","esi","fsi","tsi","nsi","csi"};
   char *brname[] = {"","ebr","fbr","tbr","nbr","cbr"};
   set_type feature_rows, primitive_rows, tile_features;
   set_type *primitives;
   rspf_int32 prim_rownum, count, tile;
   register rspf_int32 i,j, pclass, start,end;
   char path[255], covpath[255], tiledir[255], *buf, str[255];
   fcrel_type fcrel;
   linked_list_type primlist;
   position_type p;
   vpf_relate_struct rcell;
   ThematicIndex idx;

   primitives = (set_type *)vpfmalloc((library->ntiles+1)*sizeof(set_type));
   for (i=0;i<=library->ntiles;i++) {
      primitives[i].size = 0;
      primitives[i].buf = NULL;
   }

   fcnum = view->theme[themenum].fcnum;

   feature_rows = get_selected_features( view, themenum, *library );

   /* Open the tile reference table, if present */
   sprintf(path,"%stileref\\tileref.aft",library->path);
   if (access(path,0) != 0) {
      tilecover = FALSE;
   } else {
      tile_table = vpf_open_table(path,disk,"rb",NULL);
      TILEPATH_ = table_pos("TILE_NAME",tile_table);
      tilecover = TRUE;
   }

   for (pclass=EDGE;pclass<=CONNECTED_NODE;pclass++) {

      if ((pclass != library->fc[fcnum].primclass) &&
	  (library->fc[fcnum].primclass != COMPLEX_FEATURE)) continue;

      /* Set up the feature class table relate chain.        */
      /* The feature table is fcrel.table[0].                */
      /* The primitive table is the last table in the chain: */
      /*    fcrel.table[ fcrel.nchain-1 ].                   */

      j = 0;
      for (i=0;i<strlen(library->fc[fcnum].table);i++)
	 if (library->fc[fcnum].table[i] == '\\') j = i+1;
      strcpy( str, &(library->fc[fcnum].table[j]));
      fcrel = select_feature_class_relate(fcnum, library, str,
					  ptable[pclass]);
      feature = 0;
      prim = fcrel.nchain-1;

      p = ll_previous(ll_last(fcrel.relate_list),fcrel.relate_list);
      ll_element(p,&rcell);
      degree = rcell.degree;

      /*** 'Tile' number 1 is the universe polygon for the tileref cover ***/
      for (tile = 2; tile <= library->ntiles; tile++ ) {

	 if (!set_member(tile,library->tile_set)) continue;

	 if (tilecover) {
	    row = get_row(tile,tile_table);
	    buf = (char *)get_table_element(TILEPATH_,row,tile_table,
					     NULL,&count);
	    free_row(row,tile_table);
	    strcpy(tiledir,buf);
	    rightjust(tiledir);
	    strcat(tiledir,"\\");
	    free(buf);
	 } else {
	    strcpy(tiledir,"");
	 }

	 cov = library->fc[fcnum].coverage;
	 strcpy( covpath, library->cover[cov].path );

	 finished = 1;
	 found = 0;

	 /* Open primitive table in tile */
	 sprintf(path,"%s%s%s",covpath,tiledir,ptable[pclass]);
	 if (access(path,0) != 0) continue;
	 found = 1;
	 fcrel.table[prim] = vpf_open_table(path,disk,"rb",NULL);

	 if (primitives[tile].size > 0) {
	    printf("Oops!  size = %ld\n",primitives[tile].size);
	    exit(1);
	 }
	 primitives[tile] = set_init(fcrel.table[prim].nrows+1);

	 /* Get the set of primitive rows within the map extent */

	 /* Look for spatial index file */
	 primitive_rows.size = 0;
	 if (mapenv->projection == PLATE_CARREE &&
	     mapenv->mapextent.x1 < mapenv->mapextent.x2) {
	    sprintf(path,"%s%s%s",covpath,tiledir,spxname[pclass]);
	    if ((access(path,0)==0)&&(fcrel.table[prim].nrows > 20)) {

	       primitive_rows = spatial_index_search(path,
			  mapenv->mapextent.x1,mapenv->mapextent.y1,
			  mapenv->mapextent.x2,mapenv->mapextent.y2);

	    } else {
	       /* Next best thing - bounding rectangle table */
	       sprintf(path,"%s%s%s",covpath,tiledir,brname[pclass]);
	       if (access(path,0)==0) {
		  primitive_rows = bounding_select(path,mapenv->mapextent,
						   library->dec_degrees);
	       }
	    }
	 } /* projection check */

	 if (primitive_rows.size == 0) {
	    /* Search through all the primitives */
	    primitive_rows=set_init(fcrel.table[prim].nrows+1);
	    set_on(primitive_rows);
	 }

	 tile_thematic_index_name(fcrel.table[feature], path);
	 if ( (strcmp(path,"") != 0) && (access(path,4)==0) ) {
	    /* Tile thematic index for feature table present, */
	    tile_features = read_thematic_index( path, (char *)&tile );
	 } else {
	    tile_features = set_init(fcrel.table[feature].nrows+1);
	    set_on(tile_features);
	 }

	 idx.fp = NULL;
	 i = table_pos(rcell.key2,fcrel.table[prim]);
	 if (i >= 0) {
	    if (fcrel.table[prim].header[i].tdx) {
	       sprintf(path,"%s%s",fcrel.table[prim].path,
				fcrel.table[prim].header[i].tdx);
	       if (access(path,0)==0)
		  idx = open_thematic_index(path);
	    }
	    if (fcrel.table[prim].header[i].keytype == 'U') degree = R_ONE;
	    if (fcrel.table[prim].header[i].keytype == 'N') degree = R_MANY;
	    if (fcrel.table[prim].header[i].keytype == 'P') degree = R_ONE;
	 }

	 finished = 1;

	 start = set_min(tile_features);
	 end = set_max(tile_features);

	 fseek(fcrel.table[feature].fp,
	       index_pos(start,fcrel.table[feature]),
	       SEEK_SET);

	 for (i=start;i<=end;i++) {

	    row = read_next_row(fcrel.table[feature]);

	    if (!set_member( i, feature_rows )) {
	       free_row(row,fcrel.table[feature]);
	       continue;
	    }

	    if (!set_member( i, tile_features )) {
	       free_row(row,fcrel.table[feature]);
	       continue;
	    }

	    if (degree == R_ONE) {
	       prim_rownum = fc_row_number( row, fcrel, tile );
	       primlist = NULL;
	       p = NULL;
	    } else {
	       primlist = fc_row_numbers( row, fcrel, tile, &idx );
	    }

	    free_row( row, fcrel.table[feature] );

	    if (!primlist) {
	       if ((prim_rownum<1)||
		   (prim_rownum>fcrel.table[prim].nrows))
		  continue;
	       if (set_member( prim_rownum, primitive_rows )) {
		  set_insert(prim_rownum,primitives[tile]);
	       }
	    } else {
	       p = ll_first(primlist);
	       while (!ll_end(p)) {
		  ll_element(p,&prim_rownum);
		  if ((prim_rownum<1)||
		      (prim_rownum>fcrel.table[prim].nrows))
		     continue;
		  if (set_member( prim_rownum, primitive_rows )) {
		     set_insert(prim_rownum,primitives[tile]);
		  }
		  p = ll_next(p);
	       }
	    }

	    if (kbhit()) {
	       if (getch()==27) {
		  *status = 0;
		  finished = 0;
		  break;
	       }
	    }
	 }

	 if (idx.fp) close_thematic_index(&idx);

	 vpf_close_table(&(fcrel.table[prim]));

	 set_nuke(&primitive_rows);

	 set_nuke(&tile_features);

	 if (set_empty(primitives[tile])) {
	    set_nuke(&primitives[tile]);
	    primitives[tile].size = 0;
	    primitives[tile].buf = NULL;
	 }

	 if (!finished) {
	    *status = 0;
	    break;
	 }

      }

      if (!finished) {
	 *status = 0;
	 deselect_feature_class_relate( &fcrel );
	 break;
      }

      if (found) *status = 1;

      if (kbhit()) {
	 if (getch()==27) {
	    *status = 0;
	    deselect_feature_class_relate( &fcrel );
	    break;
	 }
      }

      deselect_feature_class_relate( &fcrel );
   }

   set_nuke(&feature_rows);

   if (tilecover) {
      vpf_close_table(&tile_table);
   }

   return primitives;
}
示例#20
0
/*************************************************************************
 *
 *N  get_selected_tile_primitives
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    This function determines all of the selected primitive rows from
 *    the selected features of a given tile.
 *
 *    This function expects a feature class relationship structure that
 *    has been successfully created with select_feature_class_relate()
 *    from the feature table to the primitive.  The primitive table in
 *    the feature class relate structure must have been successfully
 *    opened for the given tile.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *     library   <input>==(library_type *) VPF library structure.
 *     fcnum     <input>==(int) feature class number of the feature table.
 *     fcrel     <input>==(fcrel_type) feature class relate structure.
 *     feature_rows <input>==(set_type) set of selected features.
 *     mapenv    <input>==(map_environment_type *) map environment.
 *     tile      <input>==(rspf_int32) tile number.
 *     tiledir   <input>==(char *) path to the tile directory.
 *     status   <output>==(int *) status of the function:
 *                         1 if completed, 0 if user escape.
 *     return   <output>==(set_type) set of primitives for the features
 *                         in the corresponding tile.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels   May 1991                           DOS Turbo C
 *E
 *************************************************************************/
set_type get_selected_tile_primitives( library_type *library,
				       int fcnum,
				       fcrel_type fcrel,
				       set_type feature_rows,
				       map_environment_type *mapenv,
				       rspf_int32 tile,
				       char *tiledir,
				       int *status )
{
   int cov, degree;
   int feature, prim;
   row_type row;
   char *spxname[] = {"","esi","fsi","tsi","nsi","csi"};
   char *brname[] = {"","ebr","fbr","tbr","nbr","cbr"};
   set_type primitive_rows, tile_features;
   set_type primitives;
   rspf_int32 prim_rownum;
   register rspf_int32 i,pclass, start,end;
   char path[255], covpath[255];
   linked_list_type primlist;
   position_type p;
   vpf_relate_struct rcell;
   ThematicIndex idx;

   feature = 0;
   prim = fcrel.nchain-1;

   /* Assume that fcrel.table[prim] has been opened */

   primitives.size = 0;
   primitives.buf = NULL;

   cov = library->fc[fcnum].coverage;
   strcpy( covpath, library->cover[cov].path );

   p = ll_previous(ll_last(fcrel.relate_list),fcrel.relate_list);
   ll_element(p,&rcell);
   degree = rcell.degree;

   for (pclass=EDGE;pclass<=CONNECTED_NODE;pclass++) {

      if ((pclass != library->fc[fcnum].primclass) &&
	  (library->fc[fcnum].primclass != COMPLEX_FEATURE)) continue;

      primitives = set_init(fcrel.table[prim].nrows+1);

      /* Get the set of primitive rows within the map extent */

      /* Look for the spatial index file to weed out primitives in the */
      /* given tile but outside of the viewing area.  If a projection  */
      /* other than plate-carree (rectangular) is on, or if the extent */
      /* crosses the meridian, the quick check is no longer valid.     */

      primitive_rows.size = 0;

      if (mapenv->projection == PLATE_CARREE &&
	  mapenv->mapextent.x1 < mapenv->mapextent.x2) {
	 sprintf(path,"%s%s%s",covpath,tiledir,spxname[pclass]);
	 /* 20 (below) is a fairly arbitrary cutoff of the number of */
	 /* primitives that make a spatial index search worth while. */
	 if ((access(path,0)==0)&&(fcrel.table[prim].nrows > 20)) {
	    primitive_rows = spatial_index_search(path,
			  mapenv->mapextent.x1,mapenv->mapextent.y1,
			  mapenv->mapextent.x2,mapenv->mapextent.y2);
	 } else {
	    /* Next best thing - bounding rectangle table */
	    sprintf(path,"%s%s%s",covpath,tiledir,brname[pclass]);
	    if ((access(path,0)==0)&&(fcrel.table[prim].nrows > 20)) {
	       primitive_rows = bounding_select(path,mapenv->mapextent,
						library->dec_degrees);
	    }
	 }
      }
      if (primitive_rows.size == 0) {
	 /* Search through all the primitives */
	 primitive_rows=set_init(fcrel.table[prim].nrows+1);
	 set_on(primitive_rows);
      }

      if (strcmp(tiledir,"") != 0) {
	 tile_thematic_index_name(fcrel.table[feature], path);
	 if ((strcmp(path,"")!=0) && (access(path,4)==0)) {
	    /* Tile thematic index for feature table present, */
	    tile_features = read_thematic_index( path, (char *)&tile );
	 } else {
	    tile_features = set_init(fcrel.table[feature].nrows+1);
	    set_on(tile_features);
	 }
      } else {
	 tile_features = set_init(fcrel.table[feature].nrows+1);
	 set_on(tile_features);
      }
      set_delete(0,tile_features);

      idx.fp = NULL;
      i = table_pos(rcell.key2,fcrel.table[prim]);
      if (i >= 0) {
	 if (fcrel.table[prim].header[i].tdx) {
	    sprintf(path,"%s%s",fcrel.table[prim].path,
				fcrel.table[prim].header[i].tdx);
	    if (access(path,0)==0)
	       idx = open_thematic_index(path);
	 }
	 if (fcrel.table[prim].header[i].keytype == 'U') degree = R_ONE;
	 if (fcrel.table[prim].header[i].keytype == 'N') degree = R_MANY;
	 if (fcrel.table[prim].header[i].keytype == 'P') degree = R_ONE;
      }

      start = set_min(tile_features);
      end = set_max(tile_features);

      /* It turns out to be MUCH faster off of a CD-ROM to */
      /* read each row and discard unwanted ones than to   */
      /* forward seek past them.  It's about the same off  */
      /* of a hard disk.				      */

      fseek(fcrel.table[feature].fp,index_pos(start,fcrel.table[feature]),
	    SEEK_SET);

      for (i=start;i<=end;i++) {

	 row = read_next_row(fcrel.table[feature]);

	 if (!set_member( i, feature_rows )) {
	    free_row(row,fcrel.table[feature]);
	    continue;
	 }
	 if (!set_member( i, tile_features )) {
	    free_row(row,fcrel.table[feature]);
	    continue;
	 }

	 if (degree == R_ONE) {
	    prim_rownum = fc_row_number( row, fcrel, tile );
	    primlist = NULL;
	    p = NULL;
	 } else {
	    primlist = fc_row_numbers( row, fcrel, tile, &idx );
	 }

	 free_row( row, fcrel.table[feature] );

	 if (!primlist) {
	    if ((prim_rownum<1)||(prim_rownum>fcrel.table[prim].nrows))
	       continue;
	    if (set_member( prim_rownum, primitive_rows )) {
	       set_insert(prim_rownum,primitives);
	    }
	 } else {
	    p = ll_first(primlist);
	    while (!ll_end(p)) {
	       ll_element(p,&prim_rownum);
	       if ((prim_rownum<1)||
		   (prim_rownum>fcrel.table[prim].nrows))
		  continue;
	       if (set_member( prim_rownum, primitive_rows )) {
		  set_insert(prim_rownum,primitives);
	       }
	       p = ll_next(p);
	    }
	 }

	 if (primlist) ll_reset(primlist);

	 if (kbhit()) {
	    if (getch()==27) {
	       *status = 0;
	       break;
	    }
	 }
      }

      set_nuke(&primitive_rows);

      set_nuke(&tile_features);

      if (idx.fp) close_thematic_index(&idx);

      *status = 1;

      if (kbhit()) {
	 if (getch()==27) {
	    *status = 0;
	    break;
	 }
      }
   }

   return primitives;
}
示例#21
0
/*************************************************************************
 *
 *N  draw_selected_features
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    This function draws the selected features from a specified feature
 *    class based upon a query (either an expression or the pre-compiled
 *    results of an expression).
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *     view     <inout>==(view_type *) view structure.
 *     themenum <input>==(int) theme number.
 *     library  <input>==(library_type *) VPF library structure.
 *     mapenv   <input>==(map_environment_type *) map environment structure.
 *     return  <output>==(int) completion status:
 *                                1 if completed successfully,
 *                                0 if an error occurred.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels   August 1991                        DOS Turbo C
 *E
 *************************************************************************/
int draw_selected_features( view_type *view,
			    int themenum,
			    library_type *library,
			    map_environment_type *mapenv )
{
   int status, fcnum, finished, cov, tilecover, TILEPATH_, prim;
   int outline, color1, color2, color3, color4;
   vpf_table_type rngtable,edgtable,fbrtable, tile_table;
   row_type row;
   char *ptable[] = {"","edg","fac","txt","end","cnd"};
   register rspf_int32 i, j, p, pclass, tile;
   int display_order[] = {FACE,EDGE,ENTITY_NODE,CONNECTED_NODE,TEXT};
   register rspf_int32 starttile, endtile, startprim, endprim;
   rspf_int32 count;
   char path[255], covpath[255], tiledir[255], *buf, str[255];
   char *drive, rngpath[255],edgpath[255],edxpath[255],fbrpath[255];
   boolean rng_rdisk,edg_rdisk,fbr_rdisk;
   set_type primitives, feature_rows;
   fcrel_type fcrel;
   window_type info;
   struct viewporttype vp;

   getviewsettings(&vp);

   fcnum = view->theme[themenum].fcnum;

   sprintf(path,"%stileref\\tileref.aft",library->path);
   if (access(path,0) != 0) {
      tilecover = FALSE;
   } else {
      tile_table = vpf_open_table(path,disk,"rb",NULL);
      TILEPATH_ = table_pos("TILE_NAME",tile_table);
      tilecover = TRUE;
   }

   feature_rows = get_selected_features( view, themenum, *library );

   for (p=0;p<5;p++) {
      pclass = display_order[p];

      if ((pclass != library->fc[fcnum].primclass) &&
	  (library->fc[fcnum].primclass != COMPLEX_FEATURE)) continue;

      if ((library->fc[fcnum].primclass == COMPLEX_FEATURE) &&
	  (!library->fc[fcnum].cprim[pclass])) continue;

      /* Set up the feature class table relate chain.        */
      /* The feature table is fcrel.table[0].                */
      /* The primitive table is the last table in the chain: */
      /*    fcrel.table[ fcrel.nchain-1 ].                   */

      j = 0;
      for (i=0;i<strlen(library->fc[fcnum].table);i++)
	 if (library->fc[fcnum].table[i] == '\\') j = i+1;
      strcpy( str, &(library->fc[fcnum].table[j]));
      fcrel = select_feature_class_relate(fcnum, library, str,
					  ptable[pclass]);
      prim = fcrel.nchain-1;

      /*** 'Tile' number 1 is the universe polygon for
	   the tileref cover ***/
      starttile = set_min(library->tile_set);
      if (starttile < 2) starttile = 2;
      endtile = set_max(library->tile_set);
      if (endtile < 2) endtile = 2;

      for (tile = starttile; tile <= endtile; tile++ ) {

	 if (!set_member(tile,library->tile_set)) continue;

	 if (tilecover) {
	    row = get_row(tile,tile_table);
	    buf = (char *)get_table_element(TILEPATH_,row,tile_table,
					     NULL,&count);
	    free_row(row,tile_table);
	    strcpy(tiledir,buf);
	    rightjust(tiledir);
	    strcat(tiledir,"\\");
	    free(buf);
	 } else {
	    strcpy(tiledir,"");
	 }

	 cov = library->fc[fcnum].coverage;
	 strcpy( covpath, library->cover[cov].path );

	 finished = TRUE;

	 sprintf(path,"%s%s%s",covpath,tiledir,ptable[pclass]);

	 if (access(path,0) != 0) continue;
	 fcrel.table[prim] = vpf_open_table(path,disk,"rb",NULL);

	 info = info_window("Searching...");

	 primitives = get_selected_tile_primitives( library,
						    fcnum, fcrel,
						    feature_rows,
						    mapenv,
						    tile, tiledir,
						    &status );
	 delete_window(&info);
	 setviewport(vp.left,vp.top,vp.right,vp.bottom,vp.clip);

	 /* Reset plate-carree parameters (changed in  */
	 /* get_selected_tile_primitives() )           */
	 if (mapenv->projection == PLATE_CARREE)
	    set_plate_carree_parameters( central_meridian(
					 mapenv->mapextent.x1,
					 mapenv->mapextent.x2),
					 0.0, 1.0 );

	 if (primitives.size < 1) {
	    vpf_close_table(&fcrel.table[prim]);
	    continue;
	 }

	 if (!status) {
	    set_nuke(&primitives);
	    vpf_close_table(&fcrel.table[prim]);
	    break;
	 }

	 if (pclass == FACE) {
	    /* Must also open RNG, EDG, and FBR for drawing faces. */
	    /* If a RAM disk is specified, copy these to it and open */
	    /* them there. */
	    rng_rdisk = FALSE;
	    edg_rdisk = FALSE;
	    fbr_rdisk = FALSE;
	    drive = getenv("TMP");
	    buf = (char *)vpfmalloc(255);

	    sprintf(path,"%s%srng",covpath,tiledir);
	    strcpy(rngpath,path);
	    if (drive && filesize(path) < available_space(drive)) {
	       sprintf(rngpath,"%s\\RNG",drive);
	       sprintf(buf,"COPY %s %s > NUL",path,rngpath);
	       system(buf);
	       rng_rdisk = TRUE;
	    }
	    rngtable = vpf_open_table(rngpath,disk,"rb",NULL);

	    sprintf(path,"%s%sedg",covpath,tiledir);
	    strcpy(edgpath,path);
            sprintf(edxpath,"%s%sedx",covpath,tiledir);
	    if (drive &&
	       (filesize(path)+filesize(edxpath))<available_space(drive)) {
	       sprintf(edgpath,"%s\\EDG",drive);
	       sprintf(buf,"COPY %s %s > NUL",path,edgpath);
	       system(buf);
	       sprintf(edxpath,"%s\\EDX",drive);
	       sprintf(buf,"COPY %s%sedx %s > NUL",covpath,tiledir,edxpath);
	       system(buf);
	       edg_rdisk = TRUE;
	    }
	    edgtable = vpf_open_table(edgpath,disk,"rb",NULL);

	    sprintf(path,"%s%sfbr",covpath,tiledir);
	    strcpy(fbrpath,path);
	    if (drive && filesize(path) < available_space(drive)) {
	       sprintf(fbrpath,"%s\\FBR",drive);
	       sprintf(buf,"COPY %s %s > NUL",path,fbrpath);
	       system(buf);
	       fbr_rdisk = TRUE;
	    }
	    fbrtable = vpf_open_table(fbrpath,disk,"rb",NULL);

	    free(buf);
	 }

	 finished = 1;

	 startprim = set_min(primitives);
	 endprim = set_max(primitives);

	 /* It turns out to be MUCH faster off of a CD-ROM to */
	 /* read each row and discard unwanted ones than to   */
	 /* forward seek past them.  It's about the same off  */
	 /* of a hard disk.				      */

	 fseek(fcrel.table[prim].fp,
	       index_pos(startprim,fcrel.table[prim]),
	       SEEK_SET);

	 for (i=startprim;i<=endprim;i++) {

	    row = read_next_row(fcrel.table[prim]);

	    if (set_member( i, primitives )) {
	       /* Draw the primitive */
	       switch (pclass) {
		  case EDGE:
		     finished = draw_edge_row(row,fcrel.table[prim]);
		     break;
		  case ENTITY_NODE:
		  case CONNECTED_NODE:
		     finished = draw_point_row(row,fcrel.table[prim]);
		     break;
		  case FACE:
		     gpgetlinecolor( &outline );
		     gpgetpattern( &color1, &color2, &color3, &color4 );
		     hidemousecursor();
		     draw_face_row( row,fcrel.table[prim],
				    rngtable, edgtable, fbrtable,
				    outline,
				    color1, color2, color3, color4 );
		     showmousecursor();
		     finished = 1;
		     if (kbhit()) {
			if (getch()==27) finished = 0;
		     }
		     break;
		  case TEXT:
		     finished = draw_text_row(row,fcrel.table[prim]);
		     break;
	       }
	    }

	    free_row(row,fcrel.table[prim]);

	    if (!finished) {
	       status = 0;
	       break;
	    }
	 }

	 if (pclass == FACE) {
	    vpf_close_table(&rngtable);
	    if (rng_rdisk) remove(rngpath);
	    vpf_close_table(&edgtable);
	    if (edg_rdisk) {
	       remove(edgpath);
	       remove(edxpath);
	    }
	    vpf_close_table(&fbrtable);
	    if (fbr_rdisk) remove(fbrpath);
	 }

	 vpf_close_table(&fcrel.table[prim]);

	 set_nuke(&primitives);

	 if (!finished) {
	    status = 0;
	    break;
	 }

      }

      if (!finished) {
	 status = 0;
	 deselect_feature_class_relate( &fcrel );
	 break;
      }

      status = 1;

      if (kbhit()) {
	 if (getch()==27) {
	    status = 0;
	    deselect_feature_class_relate( &fcrel );
	    break;
	 }
      }

      deselect_feature_class_relate(&fcrel);
   }

   if (tilecover) {
      vpf_close_table(&tile_table);
   }

   set_nuke(&feature_rows);

   return status;
}
示例#22
0
void ppupdate(int fe, int fb, int nl, int nbasins, struct band3 *elev,
	      struct band3 *basins)
{
    int i, j, ii, n;
    CELL *here;
    CELL that_basin;
    void *barrier_height;
    void *this_elev;
    void *that_elev;

    struct links *list;

    list = G_malloc((nbasins + 1) * sizeof(struct links));

    for (i = 1; i <= nbasins; i += 1) {
	list[i].next = -1;
	list[i].pp = G_malloc(bpe());
	set_max(list[i].pp);

	list[i].next_alt = -1;
	list[i].pp_alt = G_malloc(bpe());
	set_max(list[i].pp_alt);

	list[i].trace = 0;

    }

    lseek(fe, 0, SEEK_SET);
    lseek(fb, 0, SEEK_SET);

    advance_band3(fb, basins);
    advance_band3(fb, basins);

    advance_band3(fe, elev);
    advance_band3(fe, elev);

    for (i = 1; i < nl - 1; i += 1) {
	advance_band3(fb, basins);
	advance_band3(fe, elev);

	for (j = 1; j < basins->ns - 1; j += 1) {

	    /* check to see if the cell is non-null and in a basin */
	    here = (CELL *) basins->b[1] + j;
	    if (G_is_c_null_value(here) || *here < 0)
		continue;

	    ii = *here;
	    this_elev = elev->b[1] + j * bpe();

	    /* check each adjoining cell; see if we're on a boundary. */
	    for (n = 0; n < 8; n += 1) {

		switch (n) {
		case 0:
		    that_basin = *((CELL *) basins->b[0] + j + 1);
		    that_elev = elev->b[0] + (j + 1) * bpe();
		    break;
		case 1:
		    that_basin = *((CELL *) basins->b[1] + j + 1);
		    that_elev = elev->b[1] + (j + 1) * bpe();
		    break;
		case 2:
		    that_basin = *((CELL *) basins->b[2] + j + 1);
		    that_elev = elev->b[2] + (j + 1) * bpe();
		    break;
		case 3:
		    that_basin = *((CELL *) basins->b[2] + j);
		    that_elev = elev->b[2] + j * bpe();
		    break;
		case 4:
		    that_basin = *((CELL *) basins->b[2] + j - 1);
		    that_elev = elev->b[2] + (j - 1) * bpe();
		    break;
		case 5:
		    that_basin = *((CELL *) basins->b[1] + j - 1);
		    that_elev = elev->b[1] + (j - 1) * bpe();
		    break;
		case 6:
		    that_basin = *((CELL *) basins->b[0] + j - 1);
		    that_elev = elev->b[0] + (j - 1) * bpe();
		    break;
		case 7:
		    that_basin = *((CELL *) basins->b[0] + j);
		    that_elev = elev->b[0] + j * bpe();

		}		/* end switch */

		/* see if we're on a boundary */
		if (that_basin != ii) {

		    /* what is that_basin if that_elev is null ? */
		    if (is_null(that_elev)) {
			barrier_height = this_elev;
		    }
		    else {
			barrier_height = get_max(that_elev, this_elev);
		    }
		    if (get_min(barrier_height, list[ii].pp) ==
			barrier_height) {
			/* save the old list entry in case we need it to fix a loop */
			if (list[ii].next != that_basin) {
			    memcpy(list[ii].pp_alt, list[ii].pp, bpe());
			    list[ii].next_alt = list[ii].next;
			}
			/* create the new list entry */
			memcpy(list[ii].pp, barrier_height, bpe());
			list[ii].next = that_basin;
		    }
		    else if (get_min(barrier_height, list[ii].pp_alt) ==
			     barrier_height) {
			if (list[ii].next == that_basin)
			    continue;
			memcpy(list[ii].pp_alt, barrier_height, bpe());
			list[ii].next_alt = that_basin;
		    }
		}		/* end if */

	    }			/* end neighbor cells */

	}			/* end cell */

    }				/* end row */


    /* Look for pairs of basins that drain to each other */
    for (i = 1; i <= nbasins; i += 1) {
	if (list[i].next <= 0)
	    continue;

	n = list[i].next;
	if (list[n].next == i) {
	    /* we have a pair */
	    /* find out how large the elevation difference would be for a change in 
	     * each basin */
	    memcpy(that_elev, list[n].pp_alt, bpe());
	    diff(that_elev, list[n].pp);

	    memcpy(this_elev, list[i].pp_alt, bpe());
	    diff(this_elev, list[i].pp);

	    /* switch pour points in the basin where it makes the smallest change */
	    if (get_min(this_elev, that_elev) == this_elev) {
		list[i].next = list[i].next_alt;
		list[i].next_alt = n;

		this_elev = list[i].pp;
		list[i].pp = list[i].pp_alt;
		list[i].pp_alt = this_elev;
	    }
	    else {
		ii = list[n].next;
		list[n].next = list[n].next_alt;
		list[n].next_alt = ii;

		this_elev = list[n].pp;
		list[n].pp = list[n].pp_alt;
		list[n].pp_alt = this_elev;
	    }			/* end fix */

	}			/* end problem */

    }				/* end loop */

    /* backtrace drainages from the bottom and adjust pour points */
    for (i = 1; i <= nbasins; i += 1) {
	if (list[i].next == -1) {
	    list[i].trace = i;
	    backtrace(i, nbasins, list);
	}
    }

    /* fill all basins up to the elevation of their lowest bounding elevation */
    lseek(fe, 0, SEEK_SET);
    lseek(fb, 0, SEEK_SET);
    for (i = 0; i < nl; i += 1) {
	read(fe, elev->b[1], elev->sz);
	read(fb, basins->b[1], basins->sz);
	for (j = 0; j < basins->ns; j += 1) {
	    ii = *((CELL *) basins->b[1] + j);
	    if (ii <= 0)
		continue;
	    this_elev = elev->b[1] + j * bpe();
	    memcpy(this_elev, get_max(this_elev, list[ii].pp), bpe());
	}
	lseek(fe, -elev->sz, SEEK_CUR);
	write(fe, elev->b[1], elev->sz);
    }

    G_free(list);
}
示例#23
0
void
ui_feedback::reset()
{
  emit set_max(0);
  QApplication::processEvents();
}
示例#24
0
void Label::regenerate_word_cache() {
	
	while (word_cache) {
		
		WordCache *current=word_cache;
		word_cache=current->next;
		memdelete( current );
	}
	
	
	int width=autowrap?get_size().width:get_longest_line_width();
	Ref<Font> font = get_font("font");
	
	int current_word_size=0;
	int word_pos=0;
	int line_width=0;
	int last_width=0;
	line_count=1;
	total_char_cache=0;
	
	WordCache *last=NULL;
	
	for (int i=0;i<text.size()+1;i++) {
		
		CharType current=i<text.length()?text[i]:' '; //always a space at the end, so the algo works
		
		if (uppercase)
			current=String::char_uppercase(current);

		bool insert_newline=false;
		
		if (current<33) {
			
			if (current_word_size>0) {
				
				WordCache *wc = memnew( WordCache );
				if (word_cache) {
					last->next=wc;
				} else {
					word_cache=wc;
				}
				last=wc;
				
				wc->pixel_width=current_word_size;
				wc->char_pos=word_pos;
				wc->word_len=i-word_pos;
				current_word_size=0;
				
			}
			
			if (current=='\n') {
				
				insert_newline=true;
			} else {
				total_char_cache++;
			}


		} else {
			
			if (current_word_size==0) {
				if (line_width>0) // add a space before the new word if a word existed before
					line_width+=font->get_char_size(' ').width;
				word_pos=i;
			}
			
			int char_width=font->get_char_size(current).width;
			current_word_size+=char_width;
			line_width+=char_width;
			total_char_cache++;
			
		}
		
		if ((autowrap && line_width>=width && last_width<width) || insert_newline) {
			
			WordCache *wc = memnew( WordCache );
			if (word_cache) {
				last->next=wc;
			} else {
				word_cache=wc;
			}
			last=wc;
			
			wc->pixel_width=0;
			wc->char_pos=insert_newline?WordCache::CHAR_NEWLINE:WordCache::CHAR_WRAPLINE;

			line_width=current_word_size;
			line_count++;

			
		}
		
		last_width=line_width;
		
	}
		
	
	if (!autowrap) {
		
		minsize.width=width;
		minsize.height=font->get_height()*line_count;
		set_page( line_count );
		
	} else {
	
		set_page( get_size().height / font->get_height() );
	}
	
	set_max(line_count);
	
	word_cache_dirty=false;
		
}
示例#25
0
void set_values(int max, int maxi, int maxj, int min, int mini, int minj) {
  if (max > final_max)
    set_max(max, maxi, maxj);
  if (min < final_min)
    set_min(min, mini, minj);
}