Commit 1e98540b authored by hrchilds's avatar hrchilds

Update from January 6, 2004

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@154 18c085ea-50e0-402c-830e-de6fd14e8384
parent b2bdcc12
......@@ -6,7 +6,7 @@
#include <vtkBMPWriter.h>
#include <vtkJPEGWriter.h>
#include <vtkTIFFWriter.h>
#include <vtkHankTIFFWriter.h>
#include <vtkPostScriptWriter.h>
#include <vtkPPMWriter.h>
#include <vtkRGBWriter.h>
......@@ -69,6 +69,11 @@ avtImageFileWriter::avtImageFileWriter()
//
// Kathleen Bonnell, Thu Nov 6 07:44:38 PST 2003
// Added compression arg, used with TIFF writer.
//
// Hank Childs, Mon Jan 5 21:26:34 PST 2004
// Use vtkHankTIFFWriter, which does not exhibit strangeness like
// vtkTIFFWriter does on the SGIs using CC.
//
// ****************************************************************************
void
......@@ -105,8 +110,8 @@ avtImageFileWriter::Write(ImageFileFormat format, const char *filename,
break;
case TIFF:
default:
writer = vtkTIFFWriter::New();
((vtkTIFFWriter*)writer)->SetCompression(compression);
writer = vtkHankTIFFWriter::New();
((vtkHankTIFFWriter*)writer)->SetCompression(compression);
break;
}
......
template<class T>
class AutoArray
{
public:
AutoArray(int _size=1000, int _ainc=1000, bool _strict=false)
{ size = _size;
ainc = _ainc;
maxidx = -1;
strictSize = _strict;
dataRetrieved = false;
dummy = 0.0;
if (size <= 0)
size = 1000;
if (ainc <= 0)
ainc = 1000;
data = (T*) malloc(size * sizeof(T));
};
~AutoArray()
{
if (!dataRetrieved)
{
if (data != 0)
free(data);
}
};
int GetSize() const
{
if (dataRetrieved)
return size;
return -1;
};
T* GetData()
{
if (dataRetrieved)
return 0;
dataRetrieved = true;
if (strictSize || (maxidx+1 < size/2))
{
data = (T*) realloc((void*)data, (maxidx+1) * sizeof(T));
size = maxidx+1;
}
return data;
};
T& operator[](int idx)
{
if (dataRetrieved)
return dummy;
// check if we need to resize
if (idx >= size)
{
int newSize = size;
while (idx >= newSize)
newSize += ainc;
// do the resize
size = newSize;
data = (T*) realloc((void*)data, size * sizeof(T));
}
if (idx > maxidx)
maxidx = idx;
return data[idx];
}
private:
T* data;
int size;
int ainc;
int maxidx;
float dummy;
bool strictSize;
bool dataRetrieved;
};
This diff is collapsed.
......@@ -58,9 +58,7 @@ class avtSAMRAIFileFormat : public avtSTMDFileFormat
vtkDataArray *GetVar(int, const char *);
vtkDataArray *GetVectorVar(int, const char *);
avtMaterial *GetMaterial(int, const char *);
#if 0
avtSpecies *GetSpecies(int, const char *);
#endif
void *GetAuxiliaryData(const char *var, int,
const char *type, void *args,
......@@ -158,6 +156,13 @@ class avtSAMRAIFileFormat : public avtSTMDFileFormat
map<string, matinfo_t*> mat_names_matinfo;
map<string, map<string, matinfo_t*> > mat_var_names_matinfo;
bool has_specs;
int num_spec_vars;
string *spec_var_names;
int *nmatspec;
map<string, string*> mat_specs;
map<string, map<string, matinfo_t*> > mat_specs_matinfo;
var_extents_t **var_extents;
patch_extents_t *patch_extents;
patch_map_t *patch_map;
......@@ -221,13 +226,19 @@ class avtSAMRAIFileFormat : public avtSTMDFileFormat
void ReadParentPointerArray(hid_t &h5_file);
void ReadMaterialInfo(hid_t &h5_file);
float *ReadMaterialVolumeFractions(int, string);
void ConvertVolumeFractionFields(std::vector<int> matIds, float **vfracs,
float *ReadMatSpecFractions(int, string, string="");
void ConvertVolumeFractionFields(vector<int> matIds, float **vfracs,
int ncells, int* &matfield, int &mixlen, int* &mix_mat,
int* &mix_next, int* &mix_zone, float* &mix_vf);
char DebugMixedMaterials(int ncells, int* &matfield, int* &mix_next,
int* &mix_mat, float* &mix_vf, int* &mix_zone);
void ReadSpeciesInfo(hid_t &h5_file);
void ConvertMassFractionFields(vector<int> matIds,
vector<float**> sfracs, int ncells, avtMaterial *mat,
int* &speclist, int &nspecies_mf, float* &species_mf,
int* &mixList);
void BuildDomainAuxiliaryInfo();
void ReadMetaDataFile();
......
......@@ -200,6 +200,9 @@
# Brad Whitlock, Tue Oct 28 17:00:24 PST 2003
# I added vtkTimeSliderActor.
#
# Hank Childs, Mon Jan 5 21:19:56 PST 2004
# Added vtkHankTIFFWriter.
#
##############################################################################
##
......@@ -227,6 +230,7 @@ SRC=InitVTK.C \
vtkDebugStream.C \
vtkDisjointCubesFacelistFilter.C \
vtkHankAxisActor2D.C \
vtkHankTIFFWriter.C \
vtkKatAxisActor.C \
vtkKatCubeAxesActor.C \
vtkLineoutFilter.C \
......
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkHankTIFFWriter.cxx,v $
Language: C++
Date: $Date: 2003/10/08 13:46:13 $
Version: $Revision: 1.30 $
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkHankTIFFWriter.h"
#include "vtkObjectFactory.h"
#include "vtkImageData.h"
#include "vtkPointData.h"
#include "vtkErrorCode.h"
#include <tiffio.h>
vtkCxxRevisionMacro(vtkHankTIFFWriter, "$Revision: 1.30 $");
vtkStandardNewMacro(vtkHankTIFFWriter);
//----------------------------------------------------------------------------
vtkHankTIFFWriter::vtkHankTIFFWriter()
{
this->TIFFPtr = 0;
this->Compression = vtkHankTIFFWriter::PackBits;
};
class vtkHankTIFFWriterIO
{
public:
// Writing file no reading
static tsize_t TIFFRead(thandle_t, tdata_t, tsize_t) { return 0; }
// Write data
static tsize_t TIFFWrite(thandle_t fd, tdata_t buf, tsize_t size)
{
ofstream *out = reinterpret_cast<ofstream *>(fd);
out->write(static_cast<char *>(buf), size);
return out->fail() ? static_cast<tsize_t>(0) : size;
}
static toff_t TIFFSeek(thandle_t fd, toff_t off, int whence)
{
ofstream *out = reinterpret_cast<ofstream *>(fd);
switch (whence)
{
case SEEK_SET:
out->seekp(off, ios::beg);
break;
case SEEK_END:
out->seekp(off, ios::end);
break;
case SEEK_CUR:
out->seekp(off, ios::cur);
break;
default:
return out->tellp();
}
return out->tellp();
}
// File will be closed by the superclass
static int TIFFClose(thandle_t) { return 1; }
static toff_t TIFFSize(thandle_t fd)
{
ofstream *out = reinterpret_cast<ofstream *>(fd);
out->seekp(0, ios::end);
return out->tellp();
}
static int TIFFMapFile(thandle_t, tdata_t*, toff_t*) { return (0); }
static void TIFFUnmapFile(thandle_t, tdata_t, toff_t) {}
};
//----------------------------------------------------------------------------
void vtkHankTIFFWriter::WriteFileHeader(ofstream *file, vtkImageData *data)
{
int dims[3];
int width, height;
data->GetDimensions(dims);
int scomponents = data->GetNumberOfScalarComponents();
int stype = data->GetScalarType();
double resolution = -1;
uint32 rowsperstrip = (uint32) -1;
int min0, min1, max0, max1, min2, max2;
int bps;
switch (stype)
{
case VTK_CHAR:
case VTK_UNSIGNED_CHAR:
bps = 8;
break;
case VTK_SHORT:
case VTK_UNSIGNED_SHORT:
bps = 16;
break;
default:
vtkErrorMacro(<< "Unsupported data type: " << data->GetScalarTypeAsString());
this->SetErrorCode(vtkErrorCode::FileFormatError);
return;
}
int predictor = 0;
// Find the length of the rows to write.
data->GetWholeExtent(min0, max0, min1, max1, min2, max2);
width = (max0 - min0 + 1);
height = (max1 - min1 + 1);
TIFF* tif = TIFFClientOpen(this->GetFileName(), "w",
(thandle_t) file,
vtkHankTIFFWriterIO::TIFFRead, vtkHankTIFFWriterIO::TIFFWrite,
vtkHankTIFFWriterIO::TIFFSeek,
vtkHankTIFFWriterIO::TIFFClose, vtkHankTIFFWriterIO::TIFFSize,
vtkHankTIFFWriterIO::TIFFMapFile, vtkHankTIFFWriterIO::TIFFUnmapFile);
if ( !tif )
{
this->TIFFPtr = 0;
return;
}
this->TIFFPtr = tif;
uint32 w = width;
uint32 h = height;
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, w);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, h);
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, scomponents);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps); // Fix for stype
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
if ( scomponents > 3 )
{
// if number of scalar components is greater than 3, that means we assume
// there is alpha.
uint16 extra_samples = scomponents-3;
uint16 *sample_info = new uint16[scomponents-3];
sample_info[0]=EXTRASAMPLE_ASSOCALPHA;
int cc;
for ( cc = 1; cc < scomponents-3; cc ++ )
{
sample_info[cc] = EXTRASAMPLE_UNSPECIFIED;
}
TIFFSetField(tif,TIFFTAG_EXTRASAMPLES,extra_samples,
sample_info);
delete [] sample_info;
}
int compression = COMPRESSION_PACKBITS;
switch ( this->Compression )
{
case vtkHankTIFFWriter::PackBits: compression = COMPRESSION_PACKBITS; break;
case vtkHankTIFFWriter::JPEG: compression = COMPRESSION_JPEG; break;
case vtkHankTIFFWriter::Deflate: compression = COMPRESSION_DEFLATE; break;
case vtkHankTIFFWriter::LZW: compression = COMPRESSION_LZW; break;
default: compression = COMPRESSION_NONE;
}
//compression = COMPRESSION_JPEG;
TIFFSetField(tif, TIFFTAG_COMPRESSION, compression); // Fix for compression
uint16 photometric = PHOTOMETRIC_RGB;
if ( compression == COMPRESSION_JPEG )
{
TIFFSetField(tif, TIFFTAG_JPEGQUALITY, 75); // Parameter
TIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);
photometric = PHOTOMETRIC_YCBCR;
}
else if ( compression == COMPRESSION_LZW )
{
predictor = 2;
TIFFSetField(tif, TIFFTAG_PREDICTOR, predictor);
vtkErrorMacro("LZW compression is patented outside US so it is disabled");
}
else if ( compression == COMPRESSION_DEFLATE )
{
predictor = 2;
TIFFSetField(tif, TIFFTAG_PREDICTOR, predictor);
}
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photometric); // Fix for scomponents
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP,
TIFFDefaultStripSize(tif, rowsperstrip));
if (resolution > 0) {
TIFFSetField(tif, TIFFTAG_XRESOLUTION, resolution);
TIFFSetField(tif, TIFFTAG_YRESOLUTION, resolution);
TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
}
}
//----------------------------------------------------------------------------
void vtkHankTIFFWriter::WriteFile(ofstream *, vtkImageData *data,
int extent[6])
{
int idx1, idx2;
int rowLength; // in bytes
void *ptr;
// Make sure we actually have data.
if ( !data->GetPointData()->GetScalars())
{
vtkErrorMacro(<< "Could not get data from input.");
return;
}
TIFF* tif = reinterpret_cast<TIFF*>(this->TIFFPtr);
if ( !tif )
{
vtkErrorMacro("Problem writting trailer.");
this->SetErrorCode(vtkErrorCode::FileFormatError);
return;
}
// take into consideration the scalar type
switch (data->GetScalarType())
{
case VTK_UNSIGNED_CHAR:
rowLength = sizeof(unsigned char);
break;
case VTK_UNSIGNED_SHORT:
rowLength = sizeof(unsigned short);
default:
vtkErrorMacro("TIFFWriter only accepts unsigned char scalars!");
return;
}
rowLength *= data->GetNumberOfScalarComponents();
rowLength *= (extent[1] - extent[0] + 1);
int row = 0;
for (idx2 = extent[4]; idx2 <= extent[5]; ++idx2)
{
for (idx1 = extent[3]; idx1 >= extent[2]; idx1--)
{
ptr = data->GetScalarPointer(extent[0], idx1, idx2);
if ( TIFFWriteScanline(tif, static_cast<unsigned char*>(ptr), row, 0) < 0)
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
break;
}
row ++;
}
}
}
//----------------------------------------------------------------------------
void vtkHankTIFFWriter::WriteFileTrailer(ofstream *, vtkImageData *)
{
TIFF* tif = reinterpret_cast<TIFF*>(this->TIFFPtr);
if ( !tif )
{
vtkErrorMacro("Problem writting trailer.");
this->SetErrorCode(vtkErrorCode::FileFormatError);
}
TIFFClose(tif);
this->TIFFPtr = 0;
}
//----------------------------------------------------------------------------
void vtkHankTIFFWriter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Compression: ";
if ( this->Compression == vtkHankTIFFWriter::PackBits )
{
os << "Pack Bits\n";
}
else if ( this->Compression == vtkHankTIFFWriter::JPEG )
{
os << "JPEG\n";
}
else if ( this->Compression == vtkHankTIFFWriter::Deflate )
{
os << "Deflate\n";
}
else if ( this->Compression == vtkHankTIFFWriter::LZW )
{
os << "LZW\n";
}
else //if ( this->Compression == vtkHankTIFFWriter::NoCompression )
{
os << "No Compression\n";
}
}
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkHankTIFFWriter.h,v $
Language: C++
Date: $Date: 2003/10/08 13:46:13 $
Version: $Revision: 1.23 $
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkHankTIFFWriter - write out image data as a TIFF file
// .SECTION Description
// vtkHankTIFFWriter writes image data as a TIFF data file. Data can be written
// uncompressed or compressed. Several forms of compression are supported
// including packed bits, JPEG, deflation, and LZW. (Note: LZW compression
// is currently under patent in the US and is disabled until the patent
// expires. However, the mechanism for supporting this compression is available
// for those with a valid license or to whom the patent does not apply.)
#ifndef __vtkHankTIFFWriter_h
#define __vtkHankTIFFWriter_h
#include "vtkImageWriter.h"
class VTK_IO_EXPORT vtkHankTIFFWriter : public vtkImageWriter
{
public:
static vtkHankTIFFWriter *New();
vtkTypeRevisionMacro(vtkHankTIFFWriter,vtkImageWriter);
virtual void PrintSelf(ostream& os, vtkIndent indent);
//BTX
enum { // Compression types
NoCompression,
PackBits,
JPEG,
Deflate,
LZW
};
//ETX
// Description:
// Set compression type. Sinze LZW compression is patented outside US, the
// additional work steps have to be taken in order to use that compression.
vtkSetClampMacro(Compression, int, NoCompression, LZW);
vtkGetMacro(Compression, int);
void SetCompressionToNoCompression() { this->SetCompression(NoCompression); }
void SetCompressionToPackBits() { this->SetCompression(PackBits); }
void SetCompressionToJPEG() { this->SetCompression(JPEG); }
void SetCompressionToDeflate() { this->SetCompression(Deflate); }
void SetCompressionToLZW() { this->SetCompression(LZW); }
protected:
vtkHankTIFFWriter();
~vtkHankTIFFWriter() {}
virtual void WriteFile(ofstream *file, vtkImageData *data, int ext[6]);
virtual void WriteFileHeader(ofstream *, vtkImageData *);
virtual void WriteFileTrailer(ofstream *, vtkImageData *);
void* TIFFPtr;
int Compression;
private:
vtkHankTIFFWriter(const vtkHankTIFFWriter&); // Not implemented.
void operator=(const vtkHankTIFFWriter&); // Not implemented.
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment