本文整理汇总了C++中array2d::init方法的典型用法代码示例。如果您正苦于以下问题:C++ array2d::init方法的具体用法?C++ array2d::init怎么用?C++ array2d::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类array2d
的用法示例。
在下文中一共展示了array2d::init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: d8_flow_directions
void d8_flow_directions(
const array2d<T> &elevations,
array2d<U> &flowdirs
){
ProgressBar progress;
diagnostic("Setting up the flow directions matrix...");
flowdirs.copyprops(elevations);
flowdirs.init(NO_FLOW);
flowdirs.no_data=d8_NO_DATA;
diagnostic("succeeded.\n");
diagnostic("%%Calculating D8 flow directions...\n");
progress.start( elevations.width()*elevations.height() );
#pragma omp parallel for
for(int x=0;x<elevations.width();x++){
progress.update( x*elevations.height() );
for(int y=0;y<elevations.height();y++)
if(elevations(x,y)==elevations.no_data)
flowdirs(x,y)=flowdirs.no_data;
else
flowdirs(x,y)=d8_FlowDir(elevations,x,y);
}
diagnostic_arg(SUCCEEDED_IN,progress.stop());
}
示例2: d8_upslope_cells
void d8_upslope_cells(
int x0, int y0, int x1, int y1,
const array2d<T> &flowdirs,array2d<U> &upslope_cells
){
diagnostic("Setting up the upslope_cells matrix...");
upslope_cells.copyprops(flowdirs);
upslope_cells.init(d8_NO_DATA);
upslope_cells.no_data=d8_NO_DATA;
diagnostic("succeeded.\n");
ProgressBar progress;
std::queue<grid_cell> expansion;
if(x0>x1){
std::swap(x0,x1);
std::swap(y0,y1);
}
//Modified Bresenham Line-Drawing Algorithm
int deltax=x1-x0;
int deltay=y1-y0;
float error=0;
float deltaerr=(float)deltay/(float)deltax;
if (deltaerr<0)
deltaerr=-deltaerr;
diagnostic_arg("Line slope is %f\n",deltaerr);
int y=y0;
for(int x=x0;x<=x1;x++){
expansion.push(grid_cell(x,y));
upslope_cells(x,y)=2;
error+=deltaerr;
if (error>=0.5) {
expansion.push(grid_cell(x+1,y));
upslope_cells(x+1,y)=2;
y+=sgn(deltay);
error-=1;
}
}
progress.start(flowdirs.data_cells);
long int ccount=0;
while(expansion.size()>0){
grid_cell c=expansion.front();
expansion.pop();
progress.update(ccount++);
for(int n=1;n<=8;n++)
if(!flowdirs.in_grid(c.x+dx[n],c.y+dy[n]))
continue;
else if(flowdirs(c.x+dx[n],c.y+dy[n])==NO_FLOW)
continue;
else if(flowdirs(c.x+dx[n],c.y+dy[n])==flowdirs.no_data)
continue;
else if(upslope_cells(c.x+dx[n],c.y+dy[n])==upslope_cells.no_data && n==inverse_flow[flowdirs(c.x+dx[n],c.y+dy[n])]){
expansion.push(grid_cell(c.x+dx[n],c.y+dy[n]));
upslope_cells(c.x+dx[n],c.y+dy[n])=1;
}
}
diagnostic_arg(SUCCEEDED_IN,progress.stop());
diagnostic_arg("Found %ld up-slope cells.\n",ccount);
}
示例3: d8_upslope_area
void d8_upslope_area(const array2d<T> &flowdirs, array2d<U> &area){
char_2d dependency;
std::queue<grid_cell> sources;
ProgressBar progress;
diagnostic("\n###D8 Upslope Area\n");
diagnostic_arg(
"The sources queue will require at most approximately %ldMB of RAM.\n",
flowdirs.width()*flowdirs.height()*((long)sizeof(grid_cell))/1024/1024
);
diagnostic("Resizing dependency matrix...");
dependency.copyprops(flowdirs);
diagnostic("succeeded.\n");
diagnostic("Setting up the area matrix...");
area.copyprops(flowdirs);
area.init(0);
area.no_data=d8_NO_DATA;
diagnostic("succeeded.\n");
diagnostic("%%Calculating dependency matrix & setting no_data cells...\n");
progress.start( flowdirs.width()*flowdirs.height() );
#pragma omp parallel for
for(int x=0;x<flowdirs.width();x++){
progress.update( x*flowdirs.height() );
for(int y=0;y<flowdirs.height();y++){
dependency(x,y)=0;
if(flowdirs(x,y)==flowdirs.no_data){
area(x,y)=area.no_data;
continue;
}
for(int n=1;n<=8;n++)
if(!flowdirs.in_grid(x+dx[n],y+dy[n]))
continue;
else if(flowdirs(x+dx[n],y+dy[n])==NO_FLOW)
continue;
else if(flowdirs(x+dx[n],y+dy[n])==flowdirs.no_data)
continue;
else if(n==inverse_flow[(int)flowdirs(x+dx[n],y+dy[n])])
++dependency(x,y);
}
}
diagnostic_arg(SUCCEEDED_IN,progress.stop());
diagnostic("%%Locating source cells...\n");
progress.start( flowdirs.width()*flowdirs.height() );
for(int x=0;x<flowdirs.width();x++){
progress.update( x*flowdirs.height() );
for(int y=0;y<flowdirs.height();y++)
if(flowdirs(x,y)==flowdirs.no_data)
continue;
else if(dependency(x,y)==0)
sources.push(grid_cell(x,y));
}
diagnostic_arg(SUCCEEDED_IN,progress.stop());
diagnostic("%%Calculating up-slope areas...\n");
progress.start(flowdirs.data_cells);
long int ccount=0;
while(sources.size()>0){
grid_cell c=sources.front();
sources.pop();
ccount++;
progress.update(ccount);
area(c.x,c.y)+=1;
if(flowdirs(c.x,c.y)==NO_FLOW)
continue;
int nx=c.x+dx[(int)flowdirs(c.x,c.y)];
int ny=c.y+dy[(int)flowdirs(c.x,c.y)];
if(flowdirs.in_grid(nx,ny) && area(nx,ny)!=area.no_data){
area(nx,ny)+=area(c.x,c.y);
if((--dependency(nx,ny))==0)
sources.push(grid_cell(nx,ny));
}
}
diagnostic_arg(SUCCEEDED_IN,progress.stop());
}