OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimImageDataFactory.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Author: Garrett Potts
8 // Contributor: David A. Horner (DAH) - http://dave.thehorners.com
9 //
10 //*************************************************************************
11 // $Id: ossimImageDataFactory.cpp 22135 2013-02-02 16:27:24Z dburken $
12 
24 #include <ossim/base/ossimCommon.h>
25 #include <ossim/base/ossimNotify.h>
26 #include <ossim/base/ossimTrace.h>
28 
29 // Static trace for debugging
30 static ossimTrace traceDebug("ossimImageDataFactory:debug");
31 
35 {
36  theInstance = 0;
37 }
38 
40 {
41  if(theInstance)
42  {
43  //delete theInstance;
44  theInstance = 0;
45  }
46 }
47 
49 {
50  theInstanceMutex.lock();
51  if(!theInstance)
52  {
54  }
55  theInstanceMutex.unlock();
56  return theInstance;
57 }
58 
60  ossimSource* owner,
61  ossimScalarType scalar,
62  ossim_uint32 bands)const
63 {
64  ossimIpt tileSize;
65  ossim::defaultTileSize(tileSize);
66  ossim_uint32 width = tileSize.x;
67  ossim_uint32 height = tileSize.y;
68 
69  // do some bounds checking and initialize to a default
70  bands = (bands>0)?bands:1;
71  scalar = scalar != OSSIM_SCALAR_UNKNOWN?scalar:OSSIM_UINT8;
72 
73  if (traceDebug())
74  {
76  << "ossimImageDataFactory::create DEBUG:"
77  << "\nCaller: "
78  << (owner ? owner->getClassName().c_str() : "unknown")
79  << "\nbands: " << bands
80  << "\nwidth: " << width
81  << "\nheight: " << height
82  << "\nScalar type: "
84  << std::endl;
85  }
86 
87  ossimRefPtr<ossimImageData> result = 0;
88  switch(scalar)
89  {
90  case OSSIM_UINT8:
91  {
92  result = new ossimU8ImageData(owner, bands, width, height);
93  break;
94  }
95  case OSSIM_USHORT11:
96  {
97  result = new ossimU11ImageData(owner, bands, width, height);
98  break;
99  }
100  case OSSIM_USHORT12:
101  {
102  result = new ossimU12ImageData(owner, bands, width, height);
103  break;
104  }
105  case OSSIM_USHORT13:
106  {
107  result = new ossimU13ImageData(owner, bands, width, height);
108  break;
109  }
110  case OSSIM_USHORT14:
111  {
112  result = new ossimU14ImageData(owner, bands, width, height);
113  break;
114  }
115  case OSSIM_USHORT15:
116  {
117  result = new ossimU15ImageData(owner, bands, width, height);
118  break;
119  }
120  case OSSIM_UINT16:
121  {
122  result = new ossimU16ImageData(owner, bands, width, height);
123  break;
124  }
125  case OSSIM_SINT16:
126  {
127  result = new ossimS16ImageData(owner, bands, width, height);
128  break;
129  }
130  default:
131  {
132  // create a generic image data implementation.
133  result = new ossimImageData(owner, scalar, bands, width, height);
134 
135  // Set the scalar type for stretching.
136  ossimImageSource* inputSource = dynamic_cast<ossimImageSource*>(owner);
137  if( inputSource )
138  {
139  for(ossim_uint32 band = 0; band < bands; ++band)
140  {
141  result->setMinPix(inputSource->getMinPixelValue(band), band);
142  result->setMaxPix(inputSource->getMaxPixelValue(band), band);
143  result->setNullPix(inputSource->getNullPixelValue(band), band);
144  }
145  }
146  break;
147  }
148  }
149 
150  return result;
151 }
152 
154  ossimSource* owner,
155  ossimScalarType scalar,
156  ossim_uint32 bands,
157  ossim_uint32 width,
158  ossim_uint32 height)const
159 {
160  ossimIpt tileSize;
161  ossim::defaultTileSize(tileSize);
162  // do some bounds checking and initialize to a default
163  bands = bands > 0?bands:1;
164  width = width > 0?width:tileSize.x;
165  height = height > 0?height:tileSize.y;
166  scalar = scalar != OSSIM_SCALAR_UNKNOWN?scalar:OSSIM_UINT8;
167 
168  if (traceDebug())
169  {
171  << "ossimImageDataFactory::create DEBUG:"
172  << "\nCaller: "
173  << (owner ? owner->getClassName().c_str() : "unknown")
174  << "\nbands: " << bands
175  << "\nwidth: " << width
176  << "\nheight: " << height
177  << "\nScalar type: "
179  << std::endl;
180  }
181 
182  ossimRefPtr<ossimImageData> result = 0;
183  switch(scalar)
184  {
185  case OSSIM_UINT8:
186  {
187  result = new ossimU8ImageData(owner, bands, width, height);
188  break;
189  }
190  case OSSIM_USHORT11:
191  {
192  result = new ossimU11ImageData(owner, bands, width, height);
193  break;
194  }
195  case OSSIM_USHORT12:
196  {
197  result = new ossimU12ImageData(owner, bands, width, height);
198  break;
199  }
200  case OSSIM_USHORT13:
201  {
202  result = new ossimU13ImageData(owner, bands, width, height);
203  break;
204  }
205  case OSSIM_USHORT14:
206  {
207  result = new ossimU14ImageData(owner, bands, width, height);
208  break;
209  }
210  case OSSIM_USHORT15:
211  {
212  result = new ossimU15ImageData(owner, bands, width, height);
213  break;
214  }
215  case OSSIM_UINT16:
216  {
217  result = new ossimU16ImageData(owner, bands, width, height);
218  break;
219  }
220  case OSSIM_SINT16:
221  {
222  result = new ossimS16ImageData(owner, bands, width, height);
223  break;
224  }
225  default:
226  {
227  // create a generic image data implementation.
228  result = new ossimImageData(owner, scalar, bands, width, height);
229  break;
230  }
231  }
232 
233  return result;
234 }
235 
237  ossimSource* owner,
238  ossim_uint32 bands,
239  ossimImageSource* inputSource)const
240 {
241  ossimRefPtr<ossimImageData> result = 0;
242 
243  if(inputSource)
244  {
245  ossimScalarType scalar = inputSource->getOutputScalarType();
246  ossim_uint32 width = inputSource->getTileWidth();
247  ossim_uint32 height = inputSource->getTileHeight();
248 
249  result = create(owner, scalar, bands, width, height);
250  if ( result.valid() )
251  {
252  for(ossim_uint32 band = 0; band < bands; ++band)
253  {
254  result->setMinPix(inputSource->getMinPixelValue(band), band);
255  result->setMaxPix(inputSource->getMaxPixelValue(band), band);
256  result->setNullPix(inputSource->getNullPixelValue(band), band);
257  }
258  }
259  }
260  else
261  {
263  << "ossimImageDataFactory::create ERROR:"
264  << "\nNULL input source!" << std::endl;
265  }
266 
267  return result;
268 }
269 
270 
272  ossimSource* owner,
273  ossimImageSource* inputSource)const
274 {
275  ossimRefPtr<ossimImageData> result = 0;
276 
277  if(inputSource)
278  {
279  ossimScalarType scalar = inputSource->getOutputScalarType();
280  ossim_uint32 bands = inputSource->getNumberOfOutputBands();
281  ossim_uint32 width = inputSource->getTileWidth();
282  ossim_uint32 height = inputSource->getTileHeight();
283 
284  result = create(owner, scalar, bands, width, height);
285  if ( result.valid() )
286  {
287  for(ossim_uint32 band = 0; band < bands; ++band)
288  {
289  result->setMinPix(inputSource->getMinPixelValue(band), band);
290  result->setMaxPix(inputSource->getMaxPixelValue(band), band);
291  result->setNullPix(inputSource->getNullPixelValue(band), band);
292  }
293  }
294  }
295  else
296  {
298  << "ossimImageDataFactory::create ERROR:"
299  << "\nNULL input source!" << std::endl;
300  }
301 
302  return result;
303 }
16 bit unsigned integer (15 bits used)
16 bit unsigned integer
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
bool valid() const
Definition: ossimRefPtr.h:75
virtual ossimString getEntryString(ossim_int32 entry_number) const
virtual ossim_uint32 getTileHeight() const
Returns the default processing tile height.
OSSIM_DLL void defaultTileSize(ossimIpt &tileSize)
16 bit signed integer
16 bit unsigned integer (14 bits used)
virtual ossimString getClassName() const
Definition: ossimObject.cpp:64
16 bit unsigned integer (13 bits used)
virtual ossim_uint32 getTileWidth() const
Returns the default processing tile width.
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
static ossimScalarTypeLut * instance()
Returns the static instance of an ossimScalarTypeLut object.
virtual void setNullPix(ossim_float64 null_pix)
static ossimImageDataFactory * instance()
static std::mutex theInstanceMutex
unsigned int ossim_uint32
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
ossimScalarType
static ossimImageDataFactory * theInstance
16 bit unsigned integer (11 bits used)
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
virtual void setMaxPix(ossim_float64 max_pix)
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
ossim_int32 y
Definition: ossimIpt.h:142
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
ossim_int32 x
Definition: ossimIpt.h:141
8 bit unsigned integer
virtual void setMinPix(ossim_float64 min_pix)
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
16 bit unsigned integer (12 bits used)