Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r854 - in trunk: Engine/Display Image
- Date: Fri, 20 Jan 2006 00:10:49 -0700 (MST)
Author: abe
Date: Fri Jan 20 00:10:48 2006
New Revision: 854
Modified:
trunk/Engine/Display/FileDisplay.cc
trunk/Engine/Display/FileDisplay.h
trunk/Image/NRRDFile.cc
trunk/Image/NRRDFile.h
Log:
Fixed writeNRRD.
M Image/NRRDFile.cc
M Image/NRRDFile.h
Added support for writting images using teem. Changed command line options
quite a bit. Note that if you want to output a "normal" png file you need to
use rgb8 frame buffers, not rgba8 which is the default. TGA still supported,
roughly half as fast.
M Engine/Display/FileDisplay.cc
M Engine/Display/FileDisplay.h
Modified: trunk/Engine/Display/FileDisplay.cc
==============================================================================
--- trunk/Engine/Display/FileDisplay.cc (original)
+++ trunk/Engine/Display/FileDisplay.cc Fri Jan 20 00:10:48 2006
@@ -1,15 +1,44 @@
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2005-2006
+ Scientific Computing and Imaging Institute, University of Utah
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
#include <fstream>
#include <sstream>
#include <iomanip>
#include <Engine/Display/FileDisplay.h>
#include <Core/Exceptions/IllegalArgument.h>
#include <Core/Exceptions/InternalError.h>
-#include <Core/Util/NotFinished.h>
+#include <Core/Util/Args.h>
#include <Image/NullImage.h>
#include <Image/Pixel.h>
#include <Image/SimpleImage.h>
#include <Image/TGAFile.h>
+#include <Image/NRRDFile.h>
#include <Interface/Context.h>
#include <SCIRun/Core/Thread/Time.h>
@@ -24,54 +53,122 @@
return new FileDisplay(args);
}
-FileDisplay::FileDisplay(
- const vector<string> &args )
+FileDisplay::FileDisplay(const vector<string> &args ) :
+ display_fps( false ),
+ current_frame( 0 ),
+ file_number( 0 ),
+ skip_frames( 0 ),
+ prefix( "manta_frame" ),
+ type_extension( "png" )
{
- if( args.size() != 1 )
- throw IllegalArgument( "FileDisplay", 0, args );
- baseName = args[ 0 ];
- currentFrame = 0;
+
+
/////////////////////////////////////////////////////////////////////////////
+ // Parse args.
+ for (int i=0;i<args.size();++i) {
+ if (args[i] == "-prefix") {
+ if (!getArg( i, args, prefix )) {
+ throw IllegalArgument( "FileDisplay", i, args );
+ }
+ }
+ else if (args[i] == "-type") {
+ if (!getStringArg( i, args, type_extension )) {
+ throw IllegalArgument( "FileDisplay", i, args );
+ }
+ }
+ else if (args[i] == "-offset") {
+ if (!getArg( i, args, file_number )) {
+ throw IllegalArgument( "FileDisplay", i, args );
+ }
+ }
+ else if (args[i] == "-skip") {
+ if (!getArg( i, args, skip_frames )) {
+ throw IllegalArgument( "FileDisplay", i, args );
+ }
+ }
+ else if (args[i] == "-fps") {
+ display_fps = true;
+ }
+ }
+
+
/////////////////////////////////////////////////////////////////////////////
+ // Determine which writer to use.
+ if (type_extension == "tga") {
+ writer = TGA_WRITER;
+ }
+ else {
+ writer = NRRD_WRITER;
+ }
}
-FileDisplay::~FileDisplay()
-{
+FileDisplay::~FileDisplay() {
}
-void FileDisplay::setupDisplayChannel(
- SetupContext & )
-{
+void FileDisplay::setupDisplayChannel( SetupContext & ) {
}
void FileDisplay::displayImage(
const DisplayContext &context,
const Image *image )
{
+
+ // Make sure processor 0 writes.
if(context.proc != 0)
return;
- bool stereo;
- int xres, yres;
- image->getResolution( stereo, xres, yres );
- if ( stereo ) {
- stringstream lss, rss;
- lss << baseName << "_left_" << setfill( '0' ) << setw( 5 ) <<
currentFrame << ".tga";
- rss << baseName << "_right_" << setfill( '0' ) << setw( 5 ) <<
currentFrame << ".tga";
- string left = lss.str();
- string right = rss.str();
- writeTGA( image, left, 0 );
- writeTGA( image, right, 1 );
- } else {
- stringstream ss;
- ss << baseName << "_" << setfill( '0' ) << setw( 5 ) << currentFrame <<
".tga";
- string name = ss.str();
-
- double start_time = Time::currentSeconds();
-
- writeTGA( image, name, 0 );
-
- double end_time = Time::currentSeconds();
-
- std::cout << "Frame write time: " << (end_time -
start_time)/60.0 << " minutes." << std::endl;
+ // Check to see if we should skip the frame.
+ if (!skip_frames || ((current_frame % skip_frames) == 0)) {
+
+ double start_time;
+ if (display_fps) {
+ start_time = Time::currentSeconds();
+ }
+
+ // Determine resolution.
+ bool stereo;
+ int xres, yres;
+ image->getResolution( stereo, xres, yres );
+
+ // Check for stereo.
+ if (stereo) {
+
+ stringstream lss, rss;
+
+ // Output left and right images.
+ lss << prefix << "_left_" << setfill( '0' ) << setw( 5 ) <<
file_number << "." << type_extension;
+ rss << prefix << "_right_" << setfill( '0' ) << setw( 5 ) <<
file_number << "." << type_extension;
+
+ // Send the image to the appropriate writer.
+ if (writer == TGA_WRITER) {
+ writeTGA( image, lss.str(), 0 );
+ writeTGA( image, rss.str(), 1 );
+ }
+ else {
+ writeNRRD( image, lss.str(), 0 );
+ writeNRRD( image, rss.str(), 1 );
+ }
+ } else {
+
+ // Otherwise output a single image.
+ stringstream ss;
+ ss << prefix << "_" << setfill( '0' ) << setw( 5 ) << file_number <<
"." << type_extension;
+
+ if (writer == TGA_WRITER) {
+ writeTGA( image, ss.str(), 0 );
+ }
+ else {
+ writeNRRD( image, ss.str(), 0 );
+ }
+
+ // Increment output file counter.
+ ++file_number;
+ }
+
+ if (display_fps) {
+ double end_time = Time::currentSeconds();
+ std::cerr << "FileDisplay fps: " << 1.0/(end_time-start_time) << "\n";
+ }
}
- ++currentFrame;
+
+ // Increment frame counter.
+ current_frame++;
}
Modified: trunk/Engine/Display/FileDisplay.h
==============================================================================
--- trunk/Engine/Display/FileDisplay.h (original)
+++ trunk/Engine/Display/FileDisplay.h Fri Jan 20 00:10:48 2006
@@ -2,25 +2,64 @@
#ifndef Manta_Engine_FileDisplay_h
#define Manta_Engine_FileDisplay_h
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2005-2006
+ Scientific Computing and Imaging Institute, University of Utah
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
#include <Interface/ImageDisplay.h>
#include <sgi_stl_warnings_off.h>
#include <string>
#include <vector>
#include <sgi_stl_warnings_on.h>
+// Abe Stephens
+
namespace Manta {
using namespace std;
class FileDisplay : public ImageDisplay {
public:
+ enum { TGA_WRITER, NRRD_WRITER };
+
FileDisplay(const vector<string>& args);
virtual ~FileDisplay();
virtual void setupDisplayChannel(SetupContext&);
virtual void displayImage(const DisplayContext& context,
const Image* image);
static ImageDisplay* create(const vector<string>& args);
+
protected:
- string baseName;
- int currentFrame;
+ bool display_fps;
+ int writer;
+ int current_frame;
+ int file_number;
+ int skip_frames;
+ string prefix;
+ string type_extension;
+
private:
FileDisplay(const FileDisplay&);
FileDisplay& operator=(const FileDisplay&);
Modified: trunk/Image/NRRDFile.cc
==============================================================================
--- trunk/Image/NRRDFile.cc (original)
+++ trunk/Image/NRRDFile.cc Fri Jan 20 00:10:48 2006
@@ -41,7 +41,7 @@
using namespace Manta;
using namespace SCIRun;
-extern "C" void writeNRRD( Image const *image, std::string const &file_name
) {
+extern "C" void writeNRRD( Image const *image, std::string const &file_name,
int which ) {
// Create a nrrd to save the image.
Nrrd *out_nrrd = nrrdNew();
@@ -51,33 +51,39 @@
int width, height;
image->getResolution( stereo, width, height );
- // Three dimensions for images, four dimensions for stereo images
- out_nrrd->dim = 3 + (stereo ? 1 : 0);
+ // Three dimensions for images
+ out_nrrd->dim = 3;
+
+ int pixel_width;
/////////////////////////////////////////////////////////////////////////////
// Determine the pixel type and size.
if (typeid(*image) == typeid(SimpleImage<RGB8Pixel>)) {
+ pixel_width = 3;
out_nrrd->type = nrrdTypeUChar;
out_nrrd->data =
- dynamic_cast<SimpleImage<RGB8Pixel> const *>( image )->getRaw( 0 );
+ dynamic_cast<SimpleImage<RGB8Pixel> const *>( image )->getRaw( which );
}
else if (typeid(*image) == typeid(SimpleImage<RGBA8Pixel>)) {
+ pixel_width = 4;
out_nrrd->type = nrrdTypeUChar;
out_nrrd->data =
- dynamic_cast<SimpleImage<RGBA8Pixel> const *>( image )->getRaw( 0 );
+ dynamic_cast<SimpleImage<RGBA8Pixel> const *>( image )->getRaw( which
);
}
else if (typeid(*image) == typeid(SimpleImage<RGBfloatPixel>)) {
+ pixel_width = 3;
out_nrrd->type = nrrdTypeFloat;
out_nrrd->data =
- dynamic_cast<SimpleImage<RGBfloatPixel> const *>( image )->getRaw( 0
);
+ dynamic_cast<SimpleImage<RGBfloatPixel> const *>( image )->getRaw(
which );
}
else if (typeid(*image) == typeid(SimpleImage<RGBAfloatPixel>)) {
+ pixel_width = 4;
out_nrrd->type = nrrdTypeFloat;
out_nrrd->data =
- dynamic_cast<SimpleImage<RGBAfloatPixel> const *>( image )->getRaw( 0
);
+ dynamic_cast<SimpleImage<RGBAfloatPixel> const *>( image )->getRaw(
which );
}
else {
nrrdNix( out_nrrd );
@@ -86,23 +92,31 @@
/////////////////////////////////////////////////////////////////////////////
// Specify the size of the data.
- if (stereo) {
- nrrdAxisInfoSet( out_nrrd, nrrdAxisInfoSize, 3, width, height, 2 );
- }
- else {
- nrrdAxisInfoSet( out_nrrd, nrrdAxisInfoSize, 3, width, height );
- }
+ nrrdAxisInfoSet( out_nrrd, nrrdAxisInfoSize, pixel_width, width, height );
/////////////////////////////////////////////////////////////////////////////
+ // Filp the image.
+ Nrrd *flipped = nrrdNew();
+ if (nrrdFlip( flipped, out_nrrd, 2 )) {
+ const char *reason = biffGetDone( NRRD );
+
+ nrrdNix( out_nrrd );
+ nrrdNix( flipped );
+ throw OutputError( "Could not flip nrrd image: " + string( reason ) );
+ }
+
+
/////////////////////////////////////////////////////////////////////////////
// Write the nrrd to disk.
- if (nrrdSave( file_name.c_str(), out_nrrd, 0 )) {
+ if (nrrdSave( file_name.c_str(), flipped, 0 )) {
const char *reason = biffGetDone( NRRD );
nrrdNix( out_nrrd );
+ nrrdNix( flipped );
throw OutputError( "Could not save image as nrrd: " + string( reason ) );
}
nrrdNix( out_nrrd );
+ nrrdNix( flipped );
}
extern "C" Image *readNRRD( const std::string &file_name ) {
@@ -123,7 +137,7 @@
nrrdNuke( new_nrrd );
throw InputError( "nrrd must have three dimensions" );
}
-
+
Image *image = 0;
/////////////////////////////////////////////////////////////////////////////
Modified: trunk/Image/NRRDFile.h
==============================================================================
--- trunk/Image/NRRDFile.h (original)
+++ trunk/Image/NRRDFile.h Fri Jan 20 00:10:48 2006
@@ -36,7 +36,7 @@
class Image;
- extern "C" void writeNRRD ( Image const *image, std::string const
&filename );
+ extern "C" void writeNRRD ( Image const *image, std::string const
&filename, int which = 0 );
extern "C" Image *readNRRD( const std::string &filename );
}
- [MANTA] r854 - in trunk: Engine/Display Image, abe, 01/20/2006
Archive powered by MHonArc 2.6.16.