OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimArcInfoGridWriter.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: LGPL
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: Garrett Potts
9 //
10 //*******************************************************************
11 // $Id: ossimArcInfoGridWriter.cpp 16081 2009-12-10 20:56:36Z eshirschorn $
12 
13 #include <cstring>
14 #include <cstdio>
15 #include <fstream>
16 #include <iostream>
17 
20 #include <ossim/base/ossimTrace.h>
21 #include <ossim/base/ossimEndian.h>
22 #include <ossim/base/ossimDpt.h>
27 
33 
35 
36 static const ossimTrace traceDebug("ossimArcInfoGridWriter:debug");
37 
39  "ossimArcInfoGridWriter",
41 
42 //*******************************************************************
43 // Constructor:
44 //*******************************************************************
47  theOutputTileSize(256, 4)
48 {
49 }
50 
52  const ossimFilename& filename)
53  :ossimImageFileWriter(filename, inputSource)
54 {
55 }
56 
57 //*******************************************************************
58 // Destructor
59 //*******************************************************************
61 {
62  close();
63 }
64 
66 {
67  const char* MODULE = "ossimArcInfoGridWriter::writeFile";
69  {
70  return false;
71  }
72 
76  filter->initialize();
77 
78  open();
79 
80  // make sure we have a region of interest
82  {
85  }
86  else
87  {
89  }
90 
91  if(theAreaOfInterest.hasNans()) return false;
92 
95 
96  bool result = writeBinaryAigHeader()&&
99  if(result)
100  {
101  ossimFilename indexFile=ossimFilename(theFilename+"/"+"w001001x.adf");
102  ossimFilename dataFile=ossimFilename(theFilename+"/"+"w001001.adf");
103 
104  std::ofstream indexFileStream(indexFile.c_str(),
105  ios::out|ios::binary);
106  std::ofstream dataFileStream(dataFile.c_str(),
107  ios::out|ios::binary);
108  ossimEndian endian;
109 
110  if(indexFileStream&&dataFileStream)
111  {
112  ossimAigIndexFileHeader aigIndexHeader;
113  ossimAigDataFileHeader aigDataFileHeader;
114 
115  ossimRefPtr<ossimImageData> currentTile =
117  long tileNumber = 0;
118  long totalNumberOfTiles = theInputConnection->getNumberOfTiles();
119  ossim_int32 tileOffsetShorts = 0;
120  ossim_int32 tileSizeShorts = 0;
121 
123  << "Tile height = " << theInputConnection->getTileHeight()
124  << std::endl
125  << "Tile width = " << theInputConnection->getTileWidth()
126  << std::endl;
127  ossim_int32 tileSizeInShorts = 2*(theInputConnection->getTileHeight()*
129  // Note: this is in shorts
130  //
131  aigIndexHeader.theFileSize += (4*totalNumberOfTiles);
132 
133  // Note this is in shorts
134  //
135 
136  aigDataFileHeader.theFileSize = 50+
137  (tileSizeInShorts*totalNumberOfTiles) +
138  totalNumberOfTiles;
139  aigDataFileHeader.theTileSize = tileSizeInShorts;
140 
141  aigIndexHeader.writeStream(indexFileStream);
142  aigDataFileHeader.writeStream(dataFileStream);
143 
144  if(traceDebug())
145  {
146  CLOG << "AIG INDEX HEADER = \n" << aigIndexHeader << std::endl;
147  CLOG << "AIG DATA FILE HEADER\n"
148  << "file size = " << aigDataFileHeader.theFileSize
149  << std::endl;
150  }
151 
152  while(currentTile.valid())
153  {
154  currentTile = filter->applyCast(currentTile);
155 
156  if(!currentTile->getBuf())
157  {
158  currentTile->initialize();
159  }
160 
161  tileOffsetShorts = dataFileStream.tellp()/2;
162  tileSizeShorts = 2*currentTile->getHeight()*currentTile->getWidth();
163  ossim_int16 tileSizeShorts16 = 2*currentTile->getHeight()*currentTile->getWidth();
164  if(endian.getSystemEndianType() == OSSIM_LITTLE_ENDIAN)
165  {
166  endian.swap(tileOffsetShorts);
167  endian.swap(tileSizeShorts);
168  endian.swap(tileSizeShorts16);
169  endian.swap((ossim_float32*)currentTile->getBuf(),
170  currentTile->getWidth()*
171  currentTile->getHeight());
172  }
173 
174  indexFileStream.write((char*)(&tileOffsetShorts), 4);
175  indexFileStream.write((char*)(&tileSizeShorts), 4);
176  dataFileStream.write((char*)(&tileSizeShorts16),
177  2);
178  dataFileStream.write((char*)(currentTile->getBuf()),
179  currentTile->getWidth()*currentTile->getHeight()*4);
180 
181  currentTile = theInputConnection->getNextTile();
182  ++tileNumber;
183  }
184  }
185  }
186 
187  close();
188  filter = 0;
189  return result;
190 }
191 
193  const char* prefix)const
194 {
195  return ossimImageFileWriter::saveState(kwl, prefix);
196 }
197 
199  const char* prefix)
200 {
201 
202  return ossimImageFileWriter::loadState(kwl, prefix);
203 }
204 
206 {
207  return (theFilename.isDir() && theFilename.exists());
208 }
209 
211 {
212  if(theFilename.isDir()&&
214  {
215  return true;
216  }
217  else
218  {
220  if(theFilename.isDir()&&
222  {
223  return true;
224  }
225  else
226  {
228  << "ossimArcInfoGridWriter::open(): Directory "
229  << theFilename << " doesn't exist" << std::endl;
230  }
231 
232  }
233  return false;
234 }
235 
237 {
238 }
239 
240 
242 {
243  const char* MODULE = "ossimArcInfoGridWriter::writeBinaryAigHeader";
244  ossimAigHeader aigHeader;
245 
246  ossimFilename file=ossimFilename(theFilename+"/"+"hdr.adf");
247 
248  if(isOpen())
249  {
251  {
252  case OSSIM_UCHAR:
253  case OSSIM_SSHORT16:
254  case OSSIM_USHORT11:
255  case OSSIM_USHORT12:
256  case OSSIM_USHORT13:
257  case OSSIM_USHORT14:
258  case OSSIM_USHORT15:
259  case OSSIM_USHORT16:
260 // {
261 // aigHeader.setIntCoverage();
262 // break;
263 // }
264  case OSSIM_DOUBLE:
265  case OSSIM_FLOAT:
268  {
269  aigHeader.setFloatCoverage();
270  break;
271  }
272  default:
273  {
275  << "ossimArcInfoGridWriter::writeBinaryAigHeader: "
276  << "unknown scalar type" << std::endl;
277  }
278  }
279 
280  // need to set pixel size
281  //
282 
283  // code goes here
284 
285  // now setting number of tiles per row
290 
291  std::ofstream out;
292  out.open(file.c_str(), ios::out|ios::binary);
293 
294  if(out)
295  {
296  if(traceDebug())
297  {
298  CLOG << "AIG_HEADER = \n" << aigHeader << std::endl;
299  }
300  return aigHeader.writeStream(out);
301  }
302  }
303 
304  return false;
305 }
306 
308 {
309  const char* MODULE = "ossimArcInfoGridWriter::writeBinaryAigBounds";
310  ossimAigBounds aigBounds;
311 
312 
313  // setup bounds
315  if(!bounds.hasNans())
316  {
317  aigBounds.ll_x = -.5;
318  aigBounds.ll_y = -.5;
319  aigBounds.ur_x = bounds.width()-.5;
320  aigBounds.ur_y = bounds.height()-.5;
321 
322  //
323  ossimFilename file=ossimFilename(theFilename+"/"+"dblbnd.adf");
324 
325  if(isOpen())
326  {
327  std::ofstream out;
328  out.open(file.c_str(), ios::out|ios::binary);
329 
330  if(out)
331  {
332  if(traceDebug())
333  {
334  CLOG << "AIG BOUNDS =\n" <<aigBounds << std::endl;
335  }
336  return aigBounds.writeStream(out);
337  }
338  }
339  }
340 
341  return false;
342 }
343 
345 {
346  ossimAigStatistics aigStats;
347 
348 
349  // setup bounds
352  aigStats.theMean = (aigStats.theMax-aigStats.theMin)/2.0;
353 
354  //
355  ossimFilename file=ossimFilename(theFilename+"/"+"sta.adf");
356 
357  if(isOpen())
358  {
359  std::ofstream out;
360  out.open(file.c_str(), ios::out|ios::binary);
361 
362  if(out)
363  {
364  return aigStats.writeStream(out);
365  }
366  }
367 
368  return false;
369 }
370 
372 {
373  return ossimString("aig");
374 }
16 bit unsigned integer (15 bits used)
virtual ossim_uint32 getWidth() const
#define CLOG
Definition: ossimTrace.h:23
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
virtual ossim_uint32 getTileWidth() const
Returns the default processing tile width.
ossim_uint32 tileNumber
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
float ossim_float32
bool writeStream(std::ostream &out)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
ossim_uint32 height() const
Definition: ossimIrect.h:487
virtual ossimRefPtr< ossimImageData > getNextTile(ossim_uint32 resLevel=0)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
ossimIrect theAreaOfInterest
virtual ossim_uint32 getHeight() const
16 bit unsigned integer (14 bits used)
16 bit unsigned integer (13 bits used)
Pure virtual base class for image file writers.
bool isDir() const
int theNumberOfTilesPerColumn
virtual void initialize()
Initialize the data buffer.
bool writeStream(std::ostream &out)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual ossimString getExtension() const
Returns a 3-letter extension from the image type descriptor (theOutputImageType) that can be used for...
virtual void setAreaOfInterest(const ossimIrect &areaOfInterest)
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
bool exists() const
ossimRefPtr< ossimImageSourceSequencer > theInputConnection
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
int theNumberOfTilesPerRow
32 bit normalized floating point
virtual void setOutputScalarType(ossimScalarType scalarType)
Sets the output scalar type.
bool writeStream(std::ostream &out) const
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
RTTI_DEF1(ossimArcInfoGridWriter, "ossimArcInfoGridWriter", ossimImageFileWriter)
ossim_uint32 width() const
Definition: ossimIrect.h:500
64 bit normalized floating point
16 bit unsigned integer (11 bits used)
short ossim_int16
ossim_int64 getNumberOfTilesHorizontal() const
virtual ossim_uint32 getTileHeight() const
Returns the default processing tile height.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
bool writeStream(std::ostream &out)
virtual const void * getBuf() const
virtual bool writeFile()
Write out the file.
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool hasNans() const
Definition: ossimIrect.h:337
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
const ossimIrect & getAreaOfInterest() const
std::basic_ofstream< char > ofstream
Class for char output file streams.
Definition: ossimIosFwd.h:47
void setFloatCoverage()
ossimRefPtr< ossimImageData > applyCast(ossimRefPtr< ossimImageData > input)
bool writeStream(std::ostream &out)
virtual void setTileSize(const ossimIpt &tileSize)
32 bit floating point
ossimFilename path() const
16 bit unsigned iteger
64 bit floating point
16 bit signed integer
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
ossim_int64 getNumberOfTilesVertical() const
8 bit unsigned iteger
int ossim_int32
16 bit unsigned integer (12 bits used)