*** empty log message ***

This commit is contained in:
David Rose 2001-07-19 16:52:20 +00:00
parent a1a9d91b42
commit 0c26df737d
14 changed files with 240 additions and 19 deletions

View File

@ -46,6 +46,19 @@ StitchImageProgram() {
"results.",
&StitchImageProgram::dispatch_double, NULL, &_filter_factor);
add_option
("n", "name", 0,
"Generates only the named output image. This may be repeated to "
"generate multiple images in one run. If omitted, all output images "
"in the file are generated.",
&StitchImageProgram::dispatch_output_name);
add_option
("s", "xsize,ysize", 0,
"Generates the output image(s) at the specified size, rather than the "
"size specified within the .st file.",
&StitchImageProgram::dispatch_int_pair, &_got_output_size, &_output_size);
_filter_factor = 1.0;
}
@ -56,9 +69,24 @@ StitchImageProgram() {
////////////////////////////////////////////////////////////////////
void StitchImageProgram::
run() {
StitchImageRasterizer outputter;
outputter._filter_factor = _filter_factor;
_command_file.process(outputter);
if (_got_output_size) {
_outputter.set_output_size(_output_size[0], _output_size[1]);
}
_outputter.set_filter_factor(_filter_factor);
_command_file.process(_outputter);
}
////////////////////////////////////////////////////////////////////
// Function: StitchImageProgram::dispatch_output_name
// Access: Protected, Static
// Description: Dispatch function for an output image name.
////////////////////////////////////////////////////////////////////
bool StitchImageProgram::
dispatch_output_name(ProgramBase *self, const string &opt,
const string &arg, void *) {
StitchImageProgram *prog = (StitchImageProgram *)self;
prog->_outputter.add_output_name(arg);
return true;
}

View File

@ -19,9 +19,10 @@
#ifndef STITCHIMAGEPROGRAM_H
#define STITCHIMAGEPROGRAM_H
#include <pandatoolbase.h>
#include "pandaappbase.h"
#include "stitchCommandReader.h"
#include "stitchImageRasterizer.h"
////////////////////////////////////////////////////////////////////
// Class : StitchImageProgram
@ -35,8 +36,16 @@ public:
void run();
protected:
static bool dispatch_output_name(ProgramBase *self, const string &opt,
const string &arg, void *);
private:
double _filter_factor;
bool _got_output_size;
int _output_size[2];
StitchImageRasterizer _outputter;
};
#endif

View File

@ -28,8 +28,9 @@
#include "stitchFlatScreen.h"
#include "stitcher.h"
#include <indent.h>
#include <pnmImage.h>
#include "compose_matrix.h"
#include "indent.h"
#include "pnmImage.h"
ostream &
operator << (ostream &out, StitchCommand::Command c) {
@ -54,6 +55,10 @@ operator << (ostream &out, StitchCommand::Command c) {
return out << "output_image";
break;
case StitchCommand::C_eyepoint:
return out << "eyepoint";
break;
case StitchCommand::C_perspective:
return out << "perspective";
break;
@ -357,6 +362,9 @@ process(StitchImageOutputter &outputter, Stitcher *stitcher,
StitchImage *image = create_image();
outputter.add_output_image(image);
} else if (_command == C_eyepoint) {
set_eyepoint(outputter);
} else if (_command == C_stitch) {
Stitcher *new_stitcher = new Stitcher;
Commands::const_iterator ci;
@ -712,6 +720,38 @@ create_image() {
return image;
}
////////////////////////////////////////////////////////////////////
// Function: StitchCommand::set_eyepoint
// Access: Protected
// Description: Sets the eyepoint on the outputter according to the
// eyepoint entry in the command file.
////////////////////////////////////////////////////////////////////
void StitchCommand::
set_eyepoint(StitchImageOutputter &outputter) {
LVecBase3d hpr(0.0, 0.0, 0.0);
LPoint3d pos(0.0, 0.0, 0.0);
Commands::const_iterator ci;
for (ci = _nested.begin(); ci != _nested.end(); ++ci) {
switch ((*ci)->_command) {
case C_hpr:
hpr = (*ci)->get_point3d();
break;
case C_pos:
pos = (*ci)->get_point3d();
break;
default:
break;
}
}
LMatrix4d mat;
compose_matrix(mat, LVecBase3d(1.0, 1.0, 1.0), hpr, pos);
outputter.set_eyepoint(mat);
}
PT(StitchScreen) StitchCommand::
create_screen() {

View File

@ -41,6 +41,7 @@ public:
C_lens,
C_input_image,
C_output_image,
C_eyepoint,
C_perspective,
C_fisheye,
C_cylindrical,
@ -123,6 +124,7 @@ private:
LVecBase2d find_parameter(Command command, const LVecBase2d &dflt);
StitchImage *create_image();
void set_eyepoint(StitchImageOutputter &outputter);
PT(StitchScreen) create_screen();

View File

@ -329,6 +329,25 @@ get_size_pixels() const {
return _size_pixels;
}
////////////////////////////////////////////////////////////////////
// Function: StitchImage::set_size_pixels
// Access: Public
// Description: Redefines the image to be the indicated size in
// pixels, without changing its size in mm.
//
// This may only be called before open_output_file() has
// been called.
////////////////////////////////////////////////////////////////////
void StitchImage::
set_size_pixels(const LVecBase2d &size_pixels) {
assert(_data == (PNMImage *)NULL);
_size_pixels = size_pixels;
_orig_size_pixels = _size_pixels;
_pixels_per_mm.set((_size_pixels[0] - 1.0) / _size_mm[0],
(_size_pixels[1] - 1.0) / _size_mm[1]);
}
LVecBase2d StitchImage::
get_size_mm() const {
return _size_mm;

View File

@ -84,6 +84,7 @@ public:
double get_grid_alpha(int xv, int yv);
const LVecBase2d &get_size_pixels() const;
void set_size_pixels(const LVecBase2d &size_pixels);
LVecBase2d get_size_mm() const;
LVector3d extrude(const LPoint2d &point_uv) const;

View File

@ -50,3 +50,13 @@ void StitchImageOutputter::
add_screen(StitchScreen *screen) {
_screen->add_screen(screen);
}
////////////////////////////////////////////////////////////////////
// Function: StitchImageOutputter::set_eyepoint
// Access: Public, Virtual
// Description: Sets the eye point to the indicated coordinate frame,
// if it makes sense to this kind of outputter.
////////////////////////////////////////////////////////////////////
void StitchImageOutputter::
set_eyepoint(const LMatrix4d &) {
}

View File

@ -53,6 +53,8 @@ public:
virtual void add_stitcher(Stitcher *stitcher)=0;
void add_screen(StitchScreen *screen);
virtual void set_eyepoint(const LMatrix4d &mat);
virtual void execute()=0;
protected:

View File

@ -26,6 +26,7 @@
StitchImageRasterizer::
StitchImageRasterizer() {
_filter_factor = 1.0;
_got_output_size = false;
}
@ -36,8 +37,16 @@ add_input_image(StitchImage *image) {
void StitchImageRasterizer::
add_output_image(StitchImage *image) {
image->set_output_scale_factor(_filter_factor);
_output_images.push_back(image);
if (has_output_name(image->get_name())) {
if (_got_output_size) {
image->set_size_pixels(LPoint2d(_output_xsize, _output_ysize));
}
image->set_output_scale_factor(_filter_factor);
_output_images.push_back(image);
} else {
cerr << "Ignoring output image " << image->get_name() << "\n";
}
}
void StitchImageRasterizer::
@ -90,6 +99,64 @@ execute() {
}
}
////////////////////////////////////////////////////////////////////
// Function: StitchImageRasterizer::add_output_name
// Access: Public
// Description: Adds the indicated name to the set of output image
// names that will be generated. If no names are added,
// all output images will be generated.
////////////////////////////////////////////////////////////////////
void StitchImageRasterizer::
add_output_name(const string &name) {
_output_names.insert(name);
}
////////////////////////////////////////////////////////////////////
// Function: StitchImageRasterizer::has_output_name
// Access: Public
// Description: Returns true if the indicated output image name is
// one that should be generated. This will be true if
// this name has been added via add_output_name(), or if
// no names at all have been added.
////////////////////////////////////////////////////////////////////
bool StitchImageRasterizer::
has_output_name(const string &name) const {
if (_output_names.empty()) {
// If no names have been added, all names are good.
return true;
}
// Otherwise, the name is good only if it is on the list.
return (_output_names.count(name) != 0);
}
////////////////////////////////////////////////////////////////////
// Function: StitchImageRasterizer::set_filter_factor
// Access: Public
// Description: Sets the factor by which the output images will be
// scaled internally in each dimension while generating
// them. They will be reduced again to their original
// size for writing the images out. This provides a
// simple kind of pixel filtering.
////////////////////////////////////////////////////////////////////
void StitchImageRasterizer::
set_filter_factor(double filter_factor) {
_filter_factor = filter_factor;
}
////////////////////////////////////////////////////////////////////
// Function: StitchImageRasterizer::set_output_size
// Access: Public
// Description: Overrides the image size each output image specifies
// with the indicated size.
////////////////////////////////////////////////////////////////////
void StitchImageRasterizer::
set_output_size(int xsize, int ysize) {
_output_xsize = xsize;
_output_ysize = ysize;
_got_output_size = true;
}
void StitchImageRasterizer::
draw_points(StitchImage *output, StitchImage *input,
const Colord &color, double radius) {

View File

@ -21,7 +21,9 @@
#include "stitchImageOutputter.h"
#include <luse.h>
#include "pvector.h"
#include "pset.h"
#include "luse.h"
class Stitcher;
class StitchImage;
@ -36,26 +38,38 @@ public:
virtual void execute();
double _filter_factor;
void add_output_name(const string &name);
bool has_output_name(const string &name) const;
protected:
void set_filter_factor(double filter_factor);
void set_output_size(int xsize, int ysize);
private:
void draw_points(StitchImage *output, StitchImage *input,
const Colord &color, double radius);
void draw_points(StitchImage *output, Stitcher *input,
const Colord &color, double radius);
void draw_image(StitchImage *output, StitchImage *input);
typedef vector<StitchImage *> Images;
Images _input_images;
Images _output_images;
typedef vector<Stitcher *> Stitchers;
Stitchers _stitchers;
protected:
void draw_spot(StitchImage *output,
const LPoint2d pixel_center, const Colord &color,
double radius);
typedef pvector<StitchImage *> Images;
Images _input_images;
Images _output_images;
typedef pvector<Stitcher *> Stitchers;
Stitchers _stitchers;
typedef pset<string> Names;
Names _output_names;
double _filter_factor;
int _output_xsize;
int _output_ysize;
bool _got_output_size;
};
#endif

View File

@ -321,6 +321,8 @@ NUMERIC ([+-]?(([0-9]+[.]?)|([0-9]*[.][0-9]+))([eE][+-]?[0-9]+)?)
return KW_INPUT_IMAGE;
} else if (cmp_nocase_uh(str, "output_image") == 0) {
return KW_OUTPUT_IMAGE;
} else if (cmp_nocase_uh(str, "eyepoint") == 0) {
return KW_EYEPOINT;
} else if (cmp_nocase_uh(str, "perspective") == 0) {
return KW_PERSPECTIVE;
} else if (cmp_nocase_uh(str, "fisheye") == 0) {

View File

@ -37,6 +37,7 @@ stitch_init_parser(istream &in, const string &filename,
%token KW_LENS
%token KW_INPUT_IMAGE
%token KW_OUTPUT_IMAGE
%token KW_EYEPOINT
%token KW_PERSPECTIVE
%token KW_FISHEYE
%token KW_CYLINDRICAL
@ -141,6 +142,11 @@ group_command:
{
$$ = new StitchCommand(parent, StitchCommand::C_output_image);
$$->set_name($2);
}
| KW_EYEPOINT optional_name
{
$$ = new StitchCommand(parent, StitchCommand::C_eyepoint);
$$->set_name($2);
}
| KW_STITCH optional_name
{

View File

@ -115,6 +115,7 @@ operator = (const Image &copy) {
StitchImageVisualizer::
StitchImageVisualizer() :
_eyepoint_inv(LMatrix4f::ident_mat()),
_event_handler(EventQueue::get_global_event_queue())
{
_event_handler.add_hook("q", static_handle_event);
@ -140,6 +141,17 @@ void StitchImageVisualizer::
add_stitcher(Stitcher *) {
}
////////////////////////////////////////////////////////////////////
// Function: StitchImageVisualizer::set_eyepoint
// Access: Public, Virtual
// Description: Sets the eye point to the indicated coordinate frame,
// if it makes sense to this kind of outputter.
////////////////////////////////////////////////////////////////////
void StitchImageVisualizer::
set_eyepoint(const LMatrix4d &mat) {
_eyepoint_inv.invert_from(LCAST(float, mat));
}
void StitchImageVisualizer::
execute() {
setup();
@ -215,6 +227,7 @@ setup() {
// Create a trackball to handle the mouse input.
_trackball = new Trackball("trackball");
_trackball->set_mat(_eyepoint_inv);
new DataRelation(_mak, _trackball);
@ -376,5 +389,9 @@ handle_event(CPT(Event) event) {
} else if (name == "z") {
_trackball->reset();
_trackball->set_mat(_eyepoint_inv);
}
}

View File

@ -44,6 +44,8 @@ public:
virtual void add_output_image(StitchImage *image);
virtual void add_stitcher(Stitcher *stitcher);
virtual void set_eyepoint(const LMatrix4d &mat);
virtual void execute();
protected:
@ -78,6 +80,8 @@ protected:
typedef vector<Image> Images;
Images _images;
LMatrix4f _eyepoint_inv;
PT(GraphicsPipe) _main_pipe;
PT(GraphicsWindow) _main_win;
NodeAttributes _initial_state;