Skip to content

Commit

Permalink
Implemented phosolve.py
Browse files Browse the repository at this point in the history
Phosolve runs the standard cycle of solving. Currently it can't ready the project but that will have to be a future addition.

Also have bug fixes for:
Alpha blending is now possible.
Iteration increment error was fixed by moving the code to a spot that didn't immediately depend on it (race condition).
  • Loading branch information
Zack Moratto committed May 19, 2010
1 parent bf20908 commit 23b4082
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 34 deletions.
9 changes: 5 additions & 4 deletions src/asp/PhotometryTK/phodrg2plate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void do_creation( Options const& opt ) {
RemoteProjectFile remote_ptk( opt.ptk_url );

// Load up DRG
DiskImageView<PixelMask<PixelGray<uint8> > > drg_image( opt.drg_file );
DiskImageView<PixelGrayA<uint8> > drg_image( opt.drg_file );
GeoReference georef;
read_georeference( georef, opt.drg_file );

Expand All @@ -61,25 +61,26 @@ void do_creation( Options const& opt ) {
VW_PIXEL_GRAYA,
VW_CHANNEL_UINT8 ) );
PlateCarreePlateManager< PixelGrayA<uint8> > drg_manager( drg_plate );
drg_manager.insert( mask_to_alpha( drg_image ), opt.drg_file,
drg_manager.insert( drg_image, opt.drg_file,
cam_id+1, georef, false,
TerminalProgressCallback( "photometrytk",
"\tProcessing" ) );
}

/*
{ // Create Reflectance ( at the moment it's just white )
boost::shared_ptr<PlateFile> ref_plate =
boost::shared_ptr<PlateFile>( new PlateFile( "pf://index/Reflectance.plate",
"equi", "", 256, "tif",
VW_PIXEL_GRAYA,
VW_CHANNEL_FLOAT32 ) );
PlateCarreePlateManager< PixelGrayA<float32> > ref_manager( ref_plate );
ref_manager.insert( mask_to_alpha(copy_mask(ConstantView<PixelGray<float32> >(1.0, drg_image.cols(), drg_image.rows() ), drg_image)),
ref_manager.insert( mask_to_alpha(copy_mask(ConstantView<PixelGray<float32> >(1.0, drg_image.cols(), drg_image.rows() ), alpha_to_mask(drg_image))),
opt.drg_file, cam_id+1, georef, false,
TerminalProgressCallback( "photometrytk",
"\tProcessing" ) );
}

*/

}

Expand Down
51 changes: 25 additions & 26 deletions src/asp/PhotometryTK/phoitalbedo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ using namespace std;
struct Options {
// Input
std::string ptk_url;
int level;

// For spawning multiple jobs
int job_id, num_jobs;
Expand Down Expand Up @@ -65,7 +66,7 @@ void initial_albedo( Options const& opt, ProjectMeta const& ptk_meta,
h_tile_records =
drg_plate->search_by_location( workunit.min().x()/8,
workunit.min().y()/8,
drg_plate->num_levels()-4,
opt.level - 3,
0, max_tid, true );
if ( h_tile_records.empty() )
continue;
Expand All @@ -74,8 +75,7 @@ void initial_albedo( Options const& opt, ProjectMeta const& ptk_meta,
for ( int iy = workunit.min().y(); iy < workunit.max().y(); iy++ ) {
// Polling for DRG Tiles
std::list<TileHeader> tile_records =
drg_plate->search_by_location( ix, iy,
drg_plate->num_levels()-1,
drg_plate->search_by_location( ix, iy, opt.level,
0, max_tid, true );

// No Tiles? No Problem!
Expand All @@ -84,18 +84,16 @@ void initial_albedo( Options const& opt, ProjectMeta const& ptk_meta,

// Feeding accumulator
BOOST_FOREACH( const TileHeader& tile, tile_records ) {
drg_plate->read( image_temp, ix, iy,
drg_plate->num_levels()-1,
drg_plate->read( image_temp, ix, iy, opt.level,
tile.transaction_id(), true );

accum(image_temp, exposure_ts[tile.transaction_id()-1]);
}
image_temp = accum.result();

// Write result
albedo_plate->write_update(image_temp,ix,iy,
drg_plate->num_levels()-1,
transaction_id);
albedo_plate->write_update(image_temp, ix, iy,
opt.level, transaction_id);

} // end for iy
} // end for ix
Expand Down Expand Up @@ -138,8 +136,7 @@ void update_albedo( Options const& opt, ProjectMeta const& ptk_meta,
h_tile_records =
drg_plate->search_by_location( workunit.min().x()/8,
workunit.min().y()/8,
drg_plate->num_levels()-4,
0, max_tid, true );
opt.level - 3, 0, max_tid, true );
if ( h_tile_records.empty() )
continue;

Expand All @@ -148,8 +145,7 @@ void update_albedo( Options const& opt, ProjectMeta const& ptk_meta,

// Polling for DRG Tiles
std::list<TileHeader> tile_records =
drg_plate->search_by_location( ix, iy,
drg_plate->num_levels()-1,
drg_plate->search_by_location( ix, iy, opt.level,
0, max_tid, true );

// No Tiles? No Problem!
Expand All @@ -158,13 +154,11 @@ void update_albedo( Options const& opt, ProjectMeta const& ptk_meta,

// Polling for current albedo
albedo_plate->read( current_albedo, ix, iy,
drg_plate->num_levels()-1,
-1, true );
opt.level, -1, true );

// Feeding accumulator
BOOST_FOREACH( const TileHeader& tile, tile_records ) {
drg_plate->read( image_temp, ix, iy,
drg_plate->num_levels()-1,
drg_plate->read( image_temp, ix, iy, opt.level,
tile.transaction_id(), true );

accum(image_temp, current_albedo,
Expand All @@ -173,10 +167,9 @@ void update_albedo( Options const& opt, ProjectMeta const& ptk_meta,
image_temp = accum.result();

// Write result
albedo_plate->write_update(image_temp+current_albedo,ix,iy,
drg_plate->num_levels()-1,
transaction_id);

select_channel(current_albedo,0) += select_channel(image_temp,0);
albedo_plate->write_update(current_albedo, ix, iy,
opt.level, transaction_id);
} // end for iy
} // end for ix
} // end foreach
Expand All @@ -193,6 +186,7 @@ void update_albedo( Options const& opt, ProjectMeta const& ptk_meta,
void handle_arguments( int argc, char *argv[], Options& opt ) {
po::options_description general_options("");
general_options.add_options()
("level,l", po::value<int>(&opt.level)->default_value(-1), "Default is to process at lowest level.")
("job_id,j", po::value<int>(&opt.job_id)->default_value(0), "")
("num_jobs,n", po::value<int>(&opt.num_jobs)->default_value(1), "")
("help,h", "Display this help message");
Expand Down Expand Up @@ -256,10 +250,14 @@ int main( int argc, char *argv[] ) {
VW_PIXEL_GRAYA,
VW_CHANNEL_FLOAT32 ) );

// Setting up working level
if ( opt.level < 0 )
opt.level = drg_plate->num_levels() - 1;

// Diving up jobs and deciding work units
std::list<BBox2i> workunits;
{
int region_size = pow(2.0,drg_plate->num_levels()-1);
int region_size = pow(2.0,opt.level);
BBox2i full_region(0,region_size/4,region_size,region_size/2);
std::list<BBox2i> all_workunits = bbox_tiles(full_region,8,8);
int count = 0;
Expand All @@ -278,7 +276,12 @@ int main( int argc, char *argv[] ) {
CameraMeta current_cam;
remote_ptk->ReadCameraMeta( i, current_cam );
exposure_t[i] = current_cam.exposure_t();
std::cout << "exposure[" << i << "] = " << exposure_t[i] << "\n";
}

// Double check for an iteration error
if ( albedo_plate->num_levels() == 0 ) {
project_info.set_current_iteration(0);
remote_ptk->UpdateIteration(0);
}

// Determine if we're updating or initializing
Expand All @@ -294,10 +297,6 @@ int main( int argc, char *argv[] ) {
albedo_plate, reflect_plate, workunits, exposure_t );
}

// Increment iterations
if ( opt.job_id == 0 )
remote_ptk->UpdateIteration(project_info.current_iteration()+1);

} catch ( const ArgumentErr& e ) {
vw_out() << e.what() << std::endl;
return 1;
Expand Down
9 changes: 7 additions & 2 deletions src/asp/PhotometryTK/phoittime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,13 @@ void update_exposure( Options& opt ) {

// Updating current time exposure
}
if ( !opt.dry_run )
if ( !opt.dry_run ) {
remote_ptk.WriteCameraMeta(j, cam_info);

// Increment iterations
if ( opt.job_id == 0 )
remote_ptk.UpdateIteration(project_info.current_iteration()+1);
}
std::cout << "Camera[" << j << "] updated exposure time: "
<< cam_info.exposure_t() << "\n";

Expand Down Expand Up @@ -141,7 +146,7 @@ void handle_arguments( int argc, char *argv[], Options& opt ) {
}

std::ostringstream usage;
usage << "Usage: " << argv[0] << " [programmer hasn't filled this out]\n";
usage << "Usage: " << argv[0] << " <ptk-url>\n";
opt.dry_run = vm.count("dry-run");

if ( vm.count("help") )
Expand Down
43 changes: 41 additions & 2 deletions src/asp/PhotometryTK/phosolve.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/env python

import os, optparse, multiprocessing, sys;
from multiprocessing import Pool

def job_func(cmd):
os.system(cmd);
return cmd;

class Usage(Exception):
def __init__(self,msg):
Expand All @@ -9,8 +14,14 @@ def __init__(self,msg):
def main():
try:
try:
usage = "phosolve.py [--help] not-sure-yet "
usage = "phosolve.py [--help][--threads N][--level N] ptk-url "
parser = optparse.OptionParser(usage=usage);
parser.set_defaults(threads=10)
parser.set_defaults(level=-1)
parser.add_option("-t", "--threads", dest="threads",
help="Number of threads to use.",type="int")
parser.add_option("-l", "--level", dest="level",
help="Lowest level to process at.",type="int")

(options, args) = parser.parse_args()

Expand All @@ -19,7 +30,35 @@ def main():
except optparse.OptionError, msg:
raise Usage(msg)

return 0
pool = Pool(processes=options.threads)

for iteration in range(100):
# Perform Albedo
albedo_cmd = []
for i in range(2*options.threads):
cmd = "phoitalbedo "
if ( options.level > 0 ):
cmd = cmd + "-l "+str(options.level)+" "
cmd = cmd + "-j "+str(i)+" -n "+str(2*options.threads)+" "+args[0]
albedo_cmd.append( cmd )
results = [pool.apply_async(job_func, (cmd,)) for cmd in albedo_cmd]
for result in results:
result.get()

# Mipmap up the levels
os.system("mipmap pf://index/Albedo.plate")

# Update the Time Estimate
time_cmd = []
for i in range(options.threads):
cmd = "phoittime "
if ( options.level > 0 ):
cmd = cmd + "-l "+str(options.level-2)+" "
cmd = cmd + "-j "+str(i)+" -n "+str(options.threads)+" "+args[0]
time_cmd.append(cmd)
results = [pool.apply_async(job_func, (cmd,)) for cmd in time_cmd]
for result in results:
result.get()

except Usage, err:
print >>sys.stderr, err.msg
Expand Down

0 comments on commit 23b4082

Please sign in to comment.