Пример #1
0
void read_dem_header ( image<short> & dem )
{
    char file[1000];
    GDALDataset  *df;
    GDALRasterBand *bd;
    double        trans[6];
    int rows, cols;

    strcpy ( file, p.value("dem_file").c_str());
    if ( strlen(file) == 0 ) {
        fprintf(stderr,"Need to specify a dem file\n");
        exit(1);
    }

    df = (GDALDataset *) GDALOpen( file, GA_ReadOnly );
    if( df == NULL ) {
        fprintf(stderr,"Could not open dem file: %s\n", file );
        exit(1);
    }
    rows = df->GetRasterYSize();
    cols = df->GetRasterXSize();
    dem.create(rows,cols);

    if( df->GetGeoTransform( trans ) == CE_None ) {
        dem_east = trans[0];
        dem_north = trans[3];
        dem_wid = trans[1];
    } else {
        fprintf(stderr,"Dem file: %s has no geographic metadata\n", file );
        exit(1);
    }

    delete df;
}
Пример #2
0
void stateBaseWave::paint()
{
	trackDocument * doc = trackDocument::get();
	static image viewImage;//画面表示用画像
	viewImage.topdown = false;
	viewImage.create( doc->baseWave.w, doc->baseWave.h );
	pixel p( 0, 0, 0, 255 );
	for ( int x = 0; x < viewImage.width; ++x ) {
		int maxValue = doc->maxValues[x];
		for ( int y = 0; y < viewImage.height; ++y ) {
			p.r = p.g = p.b = static_cast<unsigned char>( clamp<int>( 0, double( doc->baseWave( x, y ) ) / maxValue * 255, 255 ) );
			viewImage.setInternal( x, y, p );
		}
	}
	array<int>::iterator it( doc->wave );
	pixel c( 0, 255, 255, 255 );
	pixel baseColor( 255, 0, 255, 255 );
	for ( int x = 0; x < viewImage.width && it; ++x, ++it ) {
		int y = doc->waveBias + it();
		if ( x == doc->baseIndex ) {
			viewImage.set( x, y, blend( viewImage.get( x, y ), baseColor ) );
		} else {
			viewImage.set( x, y, blend( viewImage.get( x, y ), c ) );
		}
	}
	stateDocument::paint( viewImage );
}
Пример #3
0
int main ( int argc, char **argv )
{
    int i, j, n, pid, t;
    double pix;
    double ir, ic;
    int req, task, value;
    char task_name[16];

    log_start();
    if ( argc < 2 ) {
        fprintf(stderr,"Usage: %s param_file\n", argv[0]);
        exit(1);
    }

    pe.mq = msgget ( getpid(), 0777|IPC_CREAT );

    set_defaults();
    p.read_file(argv[1]);

    GDALAllRegister();

    east1 = p.dvalue("easting_left");
    east2 = p.dvalue("easting_right");
    north1 = p.dvalue("northing_bottom");
    north2 = p.dvalue("northing_top");
    wid = p.dvalue("output_cell_size");
    pix = p.dvalue("input_cell_size");
    ir = p.dvalue("input_rows");
    ic = p.dvalue("input_columns");
    input_rows = (int)ir;
    input_cols = (int)ic;
    max_dist = 1.2 * pix * sqrt(ir*ir+ic*ic) / wid;
    max_dist_2 = max_dist/2;
    max_dist = max_dist * max_dist;
    readers = p.ivalue("readers");
    mappers = p.ivalue("mappers");
    writers = p.ivalue("writers");

    rows = int((north2 - north1) / wid);
    cols = int((east2 - east1) / wid);

    cindex = new int[cols];

    dist.create(rows,cols);
    img.create(rows,cols);

    srand(time(NULL));

    read_image_file(img);
    fill ( img, dist, 0, rows );
    //spread_dist ( img, dist );
    //if ( p.value("dist_file") != "" ) output_dist_geotiff ( dist, v );
    //if ( p.value("blob_file") != "" ) output_pcolor_geotiff ( img, dist, v );
    sort ( img_indices, img_indices+img_ct, comp_row );

    valid_img = new int[max_img_id];
    for ( i = 0; i < img_ct; i++ ) {
        j = img_indices[i];
        valid_img[j] = 0;
        if ( xy[j][0]+max_dist_2 >= 0 && xy[j][0]-max_dist_2 < rows ) {
            pe.add_task ( "image", j );
        }
    }

    read_dem_header(dem);
    pe.launch ( dem_reader );
    out.create_image(rows,cols);

    for ( i = 0; i < out.rows; i += bs ) pe.add_task ( "mapper", i );

    for ( i = 0; i < readers; i++ ) {
        pe.launch ( reader );
    }

    for ( i = 0; i < mappers; i++ ) {
        pe.launch ( mapper );
    }
    for ( i = 0; i < writers; i++ ) {
        pe.launch ( writer );
    }

    while ( pe.children > 0 ) {
        t = msgrcv ( pe.mq, &pe.msg, MSG_SIZE, 1, 0 );
        if ( t < 0 ) perror("");
        sscanf(pe.msg.s,"%d %d %s %d", &req, &pid, task_name, &value );
        switch ( req ) {
            case EXIT:
		log("exit %d",pid);
                pe.children--;
		break;
            case WAIT:
                if ( pe.ready(task_name,value) ) {
                    sprintf(pe.msg.s,"1");
                    pe.msg.t = pid;
                    //printf("Sending %d task %d\n",pid,task);
		    log("wait %d %s %d",pid,task_name,value);
                    t = msgsnd ( pe.mq, &pe.msg, MSG_SIZE, 0 );
                } else {
		    log("sleep %d %s %d",pid,task_name,value);
                    pe.enqueue ( task_name, value, pid );
                }
                break;
            case TASK:
                task = pe.fetch_task(task_name);
		log("task %d %s %d",pid,task_name,task);
                sprintf(pe.msg.s,"%d",task);
                pe.msg.t = pid;
                //printf("Sending %d task %d\n",pid,task);
                t = msgsnd ( pe.mq, &pe.msg, MSG_SIZE, 0 );
                break;
            case REPORT:
		log("complete %d %s %d",pid,task_name,value);
                pe.complete ( task_name, value );
                break;
        }
    }

    msgctl(pe.mq,IPC_RMID,NULL);

    dump_log();
    return 0;
}
Пример #4
0
/*
region<int> getDiffer( trackDocument * doc, int areaIndex, int start, int end, int time )
{
	boundaryArea & area = doc->areas[areaIndex];
	boundaryCurve & curve = area.divisions.first();
	boundaryCurveIndex index;
	index.curve = 0;
	index.size = curve.points.size;
	index.start = start;
	index.end = end;
	static array2<bool> flag;
	flag.allocate( doc->width, doc->height );
	region<int> result;
	if ( ! time ) return result;
	area.update( time - 1 );
	area.update( time );
	region<int> prevShape, nowShape;
	{
		list< point2<int> > segments;
		bool checkStart = true;
		for ( boundaryCurveIndex::iterator iti( index ); iti; ++iti ) {
			curve.segment( segments, iti(), time - 1 );
		}
		memset( flag.data, 0, sizeof( bool ) * flag.size );
		for ( list< point2<int> >::iterator itp( segments ); itp; ++itp ) {
			flag( clamp( 0, itp->x, doc->width - 1 ), clamp( 0, itp->y, doc->height - 1 ) ) = true;
		}
		prevShape.set( flag, 0, 0 );
	}
	{
		list< point2<int> > segments;
		bool checkStart = true;
		for ( boundaryCurveIndex::iterator iti( index ); iti; ++iti ) {
			curve.segment( segments, iti(), time );
		}
		memset( flag.data, 0, sizeof( bool ) * flag.size );
		for ( list< point2<int> >::iterator itp( segments ); itp; ++itp ) {
			flag( clamp( 0, itp->x, doc->width - 1 ), clamp( 0, itp->y, doc->height - 1 ) ) = true;
		}
		nowShape.set( flag, 0, 0 );
	}
	region<int> round;
	round = nowShape | prevShape;
	{
		region<int> line;
		point2<int> p1 = curve.points[start]( time - 1 );
		point2<int> p2 = curve.points[start]( time );
		line.line( p1.x, p1.y, p2.x, p2.y );
		round |= line;
	}
	{
		region<int> line;
		point2<int> p1 = curve.points[end]( time - 1 );
		point2<int> p2 = curve.points[end]( time );
		line.line( p1.x, p1.y, p2.x, p2.y );
		round |= line;
	}
	round.fill( result );
	return result;
}
*/
void stateDocument::paint()
{
	trackDocument * doc = trackDocument::get();
	trackView * view = trackView::get();
	if ( ! doc ) return;
	if ( ! view ) return;
	static image viewImage;//画面表示用画像
	viewImage.topdown = false;
	double maxValue = doc->maxValues[doc->currentViewImageIndex];
	double windowLevel = windowLevelBar->get();
	double windowSize = windowSizeBar->get();
	decimal rate = 255.0 / windowSize;
	decimal offset = windowLevel - windowSize / 2;

	imageInterface< pixelLuminance<int16> > * img = & doc->originalImages[doc->currentViewImageIndex];
	switch ( view->mode & trackView::baseImageMask ) {
	case trackView::original:
		break;
	case trackView::vertEdge: 
		img = & doc->verticalEdgeImages[doc->currentViewImageIndex]; 
		break;
	case trackView::horzEdge: 
		img = & doc->horizontalEdgeImages[doc->currentViewImageIndex]; 
		break;
	default:
		offset = 0;
		rate = 0;
		break;
	}
	viewImage.create( img->width, img->height );
	pixel p( 0, 0, 0, 255 );
	if ( rate ) {
		for ( int y = 0; y < img->height; ++y ) {
			for ( int x = 0; x < img->width; ++x ) {
				p.r = p.g = p.b = static_cast<int8>( clamp<decimal>( 0, 
					( img->getInternal( x, y ).y - offset ) * rate, 255.0 ) );
				viewImage.setInternal( x, y, p );
			}
		}
	} else {
		for ( int y = 0; y < img->height; ++y ) {
			for ( int x = 0; x < img->width; ++x ) {
				viewImage.setInternal( x, y, p );
			}
		}
	}
	//波の表示用の色
	pixel colorV( 0, 0, 255, 255 );
	pixel colorH( 0, 255, 0, 255 );
	pixel colorA( 255, 255, 0, 255 );
	pixel colorD( 255, 0, 255, 255 );
	//論文投稿用の表示
	if ( false && ( ( view->mode & trackView::baseImageMask ) == trackView::none ) ) {
		p.r = p.g = p.b = 0;
		for ( int y = 0; y < img->height; ++y ) {
			for ( int x = 0; x < img->width; ++x ) {
				viewImage.setInternal( x, y, p );
			}
		}
		for ( int t = 0; t < doc->sizeTime(); ++t ) {
			pixel c;
			if ( view->mode & trackView::vertical ) {
				for ( array< list<link> >::iterator ita( doc->verticalLinks ); ita; ++ita ) {
					for ( list<link>::iterator it( ita() ); it; ++it ) {
						c.r = c.g = c.b = clamp<int>( 0, it->reliability * 255, 255 );
						int x = it->cx * doc->wave[t] + it->bx;
						int y = it->cy * doc->wave[t] + it->by;
						viewImage.set( x, y, blendMax( viewImage.get( x, y ), c ) );
					}
				}
			}
			if ( view->mode & trackView::horizontal ) {
				for ( array< list<link> >::iterator ita( doc->horizontalLinks ); ita; ++ita ) {
					for ( list<link>::iterator it( ita() ); it; ++it ) {
						c.r = c.g = c.b = clamp<int>( 0, it->reliability * 255, 255 );
						int x = it->cx * doc->wave[t] + it->bx;
						int y = it->cy * doc->wave[t] + it->by;
						viewImage.set( x, y, blendMax( viewImage.get( x, y ), c ) );
					}
				}
			}
			if ( view->mode & trackView::ascent ) {
				for ( array< list<link> >::iterator ita( doc->ascentLinks ); ita; ++ita ) {
					for ( list<link>::iterator it( ita() ); it; ++it ) {
						c.r = c.g = c.b = clamp<int>( 0, it->reliability * 255, 255 );
						int x = it->cx * doc->wave[t] + it->bx;
						int y = it->cy * doc->wave[t] + it->by;
						viewImage.set( x, y, blendMax( viewImage.get( x, y ), c ) );
					}
				}
			}
			if ( view->mode & trackView::descent ) {
				for ( array< list<link> >::iterator ita( doc->descentLinks ); ita; ++ita ) {
					for ( list<link>::iterator it( ita() ); it; ++it ) {
						c.r = c.g = c.b = clamp<int>( 0, it->reliability * 255, 255 );
						int x = it->cx * doc->wave[t] + it->bx;
						int y = it->cy * doc->wave[t] + it->by;
						viewImage.set( x, y, blendMax( viewImage.get( x, y ), c ) );
					}
				}
			}
		}
	} else
	if ( view->mode != trackView::original ) {
/*
		if ( view->mode & trackView::vertical ) {
			checkMaximum<double> mx;
			for ( array< list<link> >::iterator ita( doc->verticalLinks ); ita; ++ita ) {
				for ( list<link>::iterator it( ita() ); it; ++it ) {
					mx( it->intensity );
				}
			}
			for ( array< list<link> >::iterator ita( doc->verticalLinks ); ita; ++ita ) {
				for ( list<link>::iterator it( ita() ); it; ++it ) {
					pixel c = colorV;
					c.a = clamp<int>( 0, c.a * it->intensity / mx(), 255 );
					int x = it->cx * doc->wave[doc->currentViewImageIndex] + it->bx;
					int y = it->cy * doc->wave[doc->currentViewImageIndex] + it->by;
					viewImage.set( x, y, blend( viewImage.get( x, y ), c ) );
				}
			}
		}
		if ( view->mode & trackView::horizontal ) {
			checkMaximum<double> mx;
			for ( array< list<link> >::iterator ita( doc->horizontalLinks ); ita; ++ita ) {
				for ( list<link>::iterator it( ita() ); it; ++it ) {
					mx( it->intensity );
				}
			}
			for ( array< list<link> >::iterator ita( doc->horizontalLinks ); ita; ++ita ) {
				for ( list<link>::iterator it( ita() ); it; ++it ) {
					pixel c = colorH;
					c.a = clamp<int>( 0, c.a * it->intensity / mx(), 255 );
					int x = it->cx * doc->wave[doc->currentViewImageIndex] + it->bx;
					int y = it->cy * doc->wave[doc->currentViewImageIndex] + it->by;
					viewImage.set( x, y, blend( viewImage.get( x, y ), c ) );
				}
			}
		}
		if ( view->mode & trackView::ascent ) {
			checkMaximum<double> mx;
			for ( array< list<link> >::iterator ita( doc->ascentLinks ); ita; ++ita ) {
				for ( list<link>::iterator it( ita() ); it; ++it ) {
					mx( it->intensity );
				}
			}
			for ( array< list<link> >::iterator ita( doc->ascentLinks ); ita; ++ita ) {
				for ( list<link>::iterator it( ita() ); it; ++it ) {
					pixel c = colorA;
					c.a = clamp<int>( 0, c.a * it->intensity / mx(), 255 );
					int x = it->cx * doc->wave[doc->currentViewImageIndex] + it->bx;
					int y = it->cy * doc->wave[doc->currentViewImageIndex] + it->by;
					viewImage.set( x, y, blend( viewImage.get( x, y ), c ) );
				}
			}
		}
		if ( view->mode & trackView::descent ) {
			checkMaximum<double> mx;
			for ( array< list<link> >::iterator ita( doc->descentLinks ); ita; ++ita ) {
				for ( list<link>::iterator it( ita() ); it; ++it ) {
					mx( it->intensity );
				}
			}
			for ( array< list<link> >::iterator ita( doc->descentLinks ); ita; ++ita ) {
				for ( list<link>::iterator it( ita() ); it; ++it ) {
					pixel c = colorD;
					c.a = clamp<int>( 0, c.a * it->intensity / mx(), 255 );
					int x = it->cx * doc->wave[doc->currentViewImageIndex] + it->bx;
					int y = it->cy * doc->wave[doc->currentViewImageIndex] + it->by;
					viewImage.set( x, y, blend( viewImage.get( x, y ), c ) );
				}
			}
		}

		*/
		if ( view->mode & trackView::vertical ) {
			for ( array< list<link> >::iterator ita( doc->verticalLinks ); ita; ++ita ) {
				for ( list<link>::iterator it( ita() ); it; ++it ) {
					pixel c = colorV;
					c.a = clamp<int>( 0, c.a * it->reliability, 255 );
					int x = it->cx * doc->wave[doc->currentViewImageIndex] + it->bx;
					int y = it->cy * doc->wave[doc->currentViewImageIndex] + it->by;
					viewImage.set( x, y, blend( viewImage.get( x, y ), c ) );
				}
			}
		}
		if ( view->mode & trackView::horizontal ) {
			for ( array< list<link> >::iterator ita( doc->horizontalLinks ); ita; ++ita ) {
				for ( list<link>::iterator it( ita() ); it; ++it ) {
					pixel c = colorH;
					c.a = clamp<int>( 0, c.a * it->reliability, 255 );
					int x = it->cx * doc->wave[doc->currentViewImageIndex] + it->bx;
					int y = it->cy * doc->wave[doc->currentViewImageIndex] + it->by;
					viewImage.set( x, y, blend( viewImage.get( x, y ), c ) );
				}
			}
		}
		if ( view->mode & trackView::ascent ) {
			for ( array< list<link> >::iterator ita( doc->ascentLinks ); ita; ++ita ) {
				for ( list<link>::iterator it( ita() ); it; ++it ) {
					pixel c = colorA;
					c.a = clamp<int>( 0, c.a * it->reliability, 255 );
					int x = it->cx * doc->wave[doc->currentViewImageIndex] + it->bx;
					int y = it->cy * doc->wave[doc->currentViewImageIndex] + it->by;
					viewImage.set( x, y, blend( viewImage.get( x, y ), c ) );
				}
			}
		}
		if ( view->mode & trackView::descent ) {
			for ( array< list<link> >::iterator ita( doc->descentLinks ); ita; ++ita ) {
				for ( list<link>::iterator it( ita() ); it; ++it ) {
					pixel c = colorD;
					c.a = clamp<int>( 0, c.a * it->reliability, 255 );
					int x = it->cx * doc->wave[doc->currentViewImageIndex] + it->bx;
					int y = it->cy * doc->wave[doc->currentViewImageIndex] + it->by;
					viewImage.set( x, y, blend( viewImage.get( x, y ), c ) );
				}
			}
		}
	}
	/*
	for ( int i = 0; i < 4; ++i ) {
		for ( array2<flicker>::iterator it( doc->flickers[i] ); it; ++it ) {
			if ( it->value < 0.25 ) continue;
			pixel c( 0, 255, 0, 255 );
			c.a = clamp<int>( 0, c.a * it->value, 128 );
			const point2<int> & pos = it->lnk.position( doc->currentViewImageIndex, doc->wave );
			int x = pos.x, y = pos.y;
			viewImage.set( x, y, blend( viewImage.get( x, y ), c ) );
		}
	}
	*/
	for ( list< boundaryArea >::iterator it( doc->areas ); it; ++it ) {
		it->update( doc->currentViewImageIndex );
	}
	list< point2<int> > points;
	pixel linecolor( 255, 255, 0, 128 );
	pixel pointcolor( 0, 255, 0, 255 );
	pixel itnitialpointcolor( 0, 0, 255, 255 );
	pixel editedpointcolor( 255, 0, 0, 255 );
	/*
	for ( list< boundaryArea >::iterator it( doc->areas ); it; ++it ) {
		boundaryArea & area = it();
		if ( ! area.enable ) continue;
		pixel areacolor( 0, 0, 0, 64 );
		for ( list< boundaryPart >::iterator ita( area.parts ); ita; ++ita ) {
			areacolor.r = rand() % 256;
			areacolor.g = rand() % 256;
			areacolor.b = rand() % 256;
			areacolor.a = 128;
			boundaryPart & part = ita();
			for ( region<int>::iterator itp( part.shapes[doc->currentViewImageIndex] ); itp; ++itp ) {
				int x = itp->x;
				int y = itp->y;
				viewImage.set( x, y, blend( viewImage.get( x, y ), areacolor ) );
			}
		}
	}
	*/
	for ( list< boundaryArea >::iterator it( doc->areas ); it; ++it ) {
		//曲線の表示
		if ( doc->show_curve )
		{
			for ( list< point2<int> >::iterator itp( it->boundaryCurves[doc->currentViewImageIndex] ); itp; ++itp ) {
				const point2<int> & p = itp();
				int x = p.x;
				int y = p.y;
				viewImage.set( x, y, blend( viewImage.get( x, y ), linecolor ) );
			}
		}
		//制御点の表示
		for ( list<boundaryPoint*>::iterator itc( it->controlPoints ); itc; ++itc ) {
			boundaryPoint & bp = *itc();
			const point2<int> & p = bp( doc->currentViewImageIndex );
			pixel c;
			switch ( bp.type( doc->currentViewImageIndex ) ) {
			case boundaryPointFrame::typeInitial: c = itnitialpointcolor; break;
			case boundaryPointFrame::typeEdited: c = editedpointcolor; break;
			case boundaryPointFrame::typeInterpolated: c = pointcolor; break;
			default: c = pointcolor; break;
			}
			for ( int y = p.y - 1; y <= p.y + 1; ++y ) {
				for ( int x = p.x - 1; x <= p.x + 1; ++x ) {
					viewImage.set( x, y, blend( viewImage.get( x, y ), c ) );
				}
			}
		}
	}
	paint( viewImage );
}