From 0c26df737d50fcb39d11d3932b696eca7b8c4d43 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 19 Jul 2001 16:52:20 +0000 Subject: [PATCH] *** empty log message *** --- pandaapp/src/stitch/stitchImageProgram.cxx | 34 ++++++++- pandaapp/src/stitch/stitchImageProgram.h | 11 ++- pandaapp/src/stitchbase/stitchCommand.cxx | 44 +++++++++++- pandaapp/src/stitchbase/stitchCommand.h | 2 + pandaapp/src/stitchbase/stitchImage.cxx | 19 +++++ pandaapp/src/stitchbase/stitchImage.h | 1 + .../src/stitchbase/stitchImageOutputter.cxx | 10 +++ .../src/stitchbase/stitchImageOutputter.h | 2 + .../src/stitchbase/stitchImageRasterizer.cxx | 71 ++++++++++++++++++- .../src/stitchbase/stitchImageRasterizer.h | 36 +++++++--- pandaapp/src/stitchbase/stitchLexer.lxx | 2 + pandaapp/src/stitchbase/stitchParser.yxx | 6 ++ .../stitchviewer/stitchImageVisualizer.cxx | 17 +++++ .../src/stitchviewer/stitchImageVisualizer.h | 4 ++ 14 files changed, 240 insertions(+), 19 deletions(-) diff --git a/pandaapp/src/stitch/stitchImageProgram.cxx b/pandaapp/src/stitch/stitchImageProgram.cxx index 58dbe7d1fd..b64eb5afc8 100644 --- a/pandaapp/src/stitch/stitchImageProgram.cxx +++ b/pandaapp/src/stitch/stitchImageProgram.cxx @@ -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; } diff --git a/pandaapp/src/stitch/stitchImageProgram.h b/pandaapp/src/stitch/stitchImageProgram.h index f9e41e2c71..f4c968ee79 100644 --- a/pandaapp/src/stitch/stitchImageProgram.h +++ b/pandaapp/src/stitch/stitchImageProgram.h @@ -19,9 +19,10 @@ #ifndef STITCHIMAGEPROGRAM_H #define STITCHIMAGEPROGRAM_H -#include +#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 diff --git a/pandaapp/src/stitchbase/stitchCommand.cxx b/pandaapp/src/stitchbase/stitchCommand.cxx index 8e0354493e..705a81c495 100644 --- a/pandaapp/src/stitchbase/stitchCommand.cxx +++ b/pandaapp/src/stitchbase/stitchCommand.cxx @@ -28,8 +28,9 @@ #include "stitchFlatScreen.h" #include "stitcher.h" -#include -#include +#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() { diff --git a/pandaapp/src/stitchbase/stitchCommand.h b/pandaapp/src/stitchbase/stitchCommand.h index 5e87646104..5ec2179780 100644 --- a/pandaapp/src/stitchbase/stitchCommand.h +++ b/pandaapp/src/stitchbase/stitchCommand.h @@ -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(); diff --git a/pandaapp/src/stitchbase/stitchImage.cxx b/pandaapp/src/stitchbase/stitchImage.cxx index 66ecbf3be0..f09821c314 100644 --- a/pandaapp/src/stitchbase/stitchImage.cxx +++ b/pandaapp/src/stitchbase/stitchImage.cxx @@ -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; diff --git a/pandaapp/src/stitchbase/stitchImage.h b/pandaapp/src/stitchbase/stitchImage.h index 6cfea643ba..7592741db0 100644 --- a/pandaapp/src/stitchbase/stitchImage.h +++ b/pandaapp/src/stitchbase/stitchImage.h @@ -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; diff --git a/pandaapp/src/stitchbase/stitchImageOutputter.cxx b/pandaapp/src/stitchbase/stitchImageOutputter.cxx index d9df76b906..a8887f46f1 100644 --- a/pandaapp/src/stitchbase/stitchImageOutputter.cxx +++ b/pandaapp/src/stitchbase/stitchImageOutputter.cxx @@ -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 &) { +} diff --git a/pandaapp/src/stitchbase/stitchImageOutputter.h b/pandaapp/src/stitchbase/stitchImageOutputter.h index 633fb12185..89d590e084 100644 --- a/pandaapp/src/stitchbase/stitchImageOutputter.h +++ b/pandaapp/src/stitchbase/stitchImageOutputter.h @@ -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: diff --git a/pandaapp/src/stitchbase/stitchImageRasterizer.cxx b/pandaapp/src/stitchbase/stitchImageRasterizer.cxx index 4f109c5655..204f10d839 100644 --- a/pandaapp/src/stitchbase/stitchImageRasterizer.cxx +++ b/pandaapp/src/stitchbase/stitchImageRasterizer.cxx @@ -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) { diff --git a/pandaapp/src/stitchbase/stitchImageRasterizer.h b/pandaapp/src/stitchbase/stitchImageRasterizer.h index 0e7943575b..2a81b889dc 100644 --- a/pandaapp/src/stitchbase/stitchImageRasterizer.h +++ b/pandaapp/src/stitchbase/stitchImageRasterizer.h @@ -21,7 +21,9 @@ #include "stitchImageOutputter.h" -#include +#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 Images; - Images _input_images; - Images _output_images; - - typedef vector Stitchers; - Stitchers _stitchers; - -protected: void draw_spot(StitchImage *output, const LPoint2d pixel_center, const Colord &color, double radius); + + typedef pvector Images; + Images _input_images; + Images _output_images; + + typedef pvector Stitchers; + Stitchers _stitchers; + + typedef pset Names; + Names _output_names; + + double _filter_factor; + + int _output_xsize; + int _output_ysize; + bool _got_output_size; }; #endif diff --git a/pandaapp/src/stitchbase/stitchLexer.lxx b/pandaapp/src/stitchbase/stitchLexer.lxx index ded5b1fdad..9ce9b4f353 100644 --- a/pandaapp/src/stitchbase/stitchLexer.lxx +++ b/pandaapp/src/stitchbase/stitchLexer.lxx @@ -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) { diff --git a/pandaapp/src/stitchbase/stitchParser.yxx b/pandaapp/src/stitchbase/stitchParser.yxx index 4159b200c2..c305415521 100644 --- a/pandaapp/src/stitchbase/stitchParser.yxx +++ b/pandaapp/src/stitchbase/stitchParser.yxx @@ -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 { diff --git a/pandaapp/src/stitchviewer/stitchImageVisualizer.cxx b/pandaapp/src/stitchviewer/stitchImageVisualizer.cxx index 0991bc3e34..cd1f759c7c 100644 --- a/pandaapp/src/stitchviewer/stitchImageVisualizer.cxx +++ b/pandaapp/src/stitchviewer/stitchImageVisualizer.cxx @@ -115,6 +115,7 @@ operator = (const Image ©) { 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); } } + + + diff --git a/pandaapp/src/stitchviewer/stitchImageVisualizer.h b/pandaapp/src/stitchviewer/stitchImageVisualizer.h index fd56618d53..622b81fc0f 100644 --- a/pandaapp/src/stitchviewer/stitchImageVisualizer.h +++ b/pandaapp/src/stitchviewer/stitchImageVisualizer.h @@ -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 Images; Images _images; + LMatrix4f _eyepoint_inv; + PT(GraphicsPipe) _main_pipe; PT(GraphicsWindow) _main_win; NodeAttributes _initial_state;