OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimValueAssignImageSourceFilter.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: ossimValueAssignImageSourceFilter.cpp 15833 2009-10-29 01:41:53Z eshirschorn $
15 
17  "ossimValueAssignImageSourceFilter",
19 
21  :ossimImageSourceFilter(owner),
22  theAssignType(ossimValueAssignType_GROUP),
23  theTile(NULL)
24 {
25 }
26 
28 {
29 }
30 
32  const ossimIrect& tileRect,
33  ossim_uint32 resLevel)
34 {
36  {
37  return NULL; // This filter requires an input.
38  }
39 
40  ossimRefPtr<ossimImageData> inputTile =
41  theInputConnection->getTile(tileRect, resLevel);
42 
43  if(!isSourceEnabled() || !inputTile.valid())
44  {
45  return inputTile;
46  }
47 
48  if(!theTile.valid())
49  {
50  allocate(); // First time through...
51  }
52 
53  if (!theTile.valid()) // throw exeption...
54  {
55  return inputTile;
56  }
57 
58  // Set the origin, resize if needed of the output tile.
59  theTile->setImageRectangle(tileRect);
60 
61  if( inputTile->getDataObjectStatus() == OSSIM_NULL ||
62  inputTile->getDataObjectStatus() == OSSIM_EMPTY )
63  {
64  theTile->makeBlank();
65  return theTile;
66  }
67 
68  if(!inputTile->getBuf())
69  {
70  theTile->makeBlank();
71  }
72  else
73  {
74  theTile->loadTile(inputTile.get());
75  }
76 
77  switch(inputTile->getScalarType())
78  {
79  case OSSIM_UCHAR:
80  {
81  executeAssign(static_cast<ossim_uint8>(0),
82  theTile);
83  break;
84  }
85  case OSSIM_FLOAT:
87  {
88  executeAssign(static_cast<float>(0),
89  theTile);
90  break;
91  }
92  case OSSIM_USHORT16:
93  case OSSIM_USHORT11:
94  case OSSIM_USHORT12:
95  case OSSIM_USHORT13:
96  case OSSIM_USHORT14:
97  case OSSIM_USHORT15:
98  {
99  executeAssign(static_cast<ossim_uint16>(0),
100  theTile);
101  break;
102  }
103  case OSSIM_SSHORT16:
104  {
105  executeAssign(static_cast<ossim_sint16>(0),
106  theTile);
107  break;
108  }
109  case OSSIM_DOUBLE:
111  {
112  executeAssign(static_cast<double>(0),
113  theTile);
114  break;
115  }
116  default:
117  {
118  ossimNotify(ossimNotifyLevel_WARN) << "ossimValueAssignImageSourceFilter::getTile WARN: Scalar type = " << theTile->getScalarType()
119  << " Not supported!" << std::endl;
120  break;
121  }
122  }
123 
124  theTile->validate();
125 
126  return theTile;
127 }
128 
129 void ossimValueAssignImageSourceFilter::setInputOutputValues(const vector<double>& inputValues,
130  const vector<double>& outputValues)
131 {
132  theInputValueArray = inputValues;
133  theOutputValueArray = outputValues;
134 
135  validateArrays();
136 }
137 
139 {
140  if(theOutputValueArray.size() != theInputValueArray.size())
141  {
144 
145  vector<double> copyVector(theOutputValueArray.begin(),
146  theOutputValueArray.begin() + index);
147 
148  theOutputValueArray = copyVector;
149 
150  for(ossim_uint32 index2 = index; index < theInputValueArray.size(); ++index)
151  {
152  theOutputValueArray.push_back(theInputValueArray[index2]);
153  }
154  }
155 }
156 
158  T,
160 {
161  if(!theInputValueArray.size()) return;
162 
164  {
165  executeAssignSeparate(static_cast<T>(0), data);
166  }
167  else
168  {
169  executeAssignGroup(static_cast<T>(0), data);
170  }
171 }
172 
174  T,
176 {
177  ossim_uint32 numberOfBands = std::min((ossim_uint32)data->getNumberOfBands(),
179  ossim_uint32 maxOffset = data->getWidth()*data->getHeight();
180 
181  for(ossim_uint32 band = 0; band<numberOfBands; ++band)
182  {
183  T* buf = static_cast<T*>(data->getBuf(band));
184  T inValue = static_cast<T>(theInputValueArray[band]);
185  T outValue = static_cast<T>(theOutputValueArray[band]);
186  for(ossim_uint32 count = 0; count < maxOffset; ++count)
187  {
188  if(*buf == inValue)
189  {
190  *buf = outValue;
191  }
192  ++buf;
193  }
194  }
195 }
196 
198  T,
200 {
201  ossim_uint32 numberOfBands = std::min((ossim_uint32)data->getNumberOfBands(),
203  ossim_uint32 maxOffset = data->getWidth()*data->getHeight();
204  ossim_uint32 band = 0;
205  bool equalFlag = false;
206 
207  T** bufArray = new T*[data->getNumberOfBands()];
208  for(band = 0; band < data->getNumberOfBands(); ++band)
209  {
210  bufArray[band] = static_cast<T*>(data->getBuf(band));
211  }
212 
213  for(ossim_uint32 offset = 0; offset < maxOffset; ++offset)
214  {
215  equalFlag = true;
216 
217  for(band = 0; band<numberOfBands; ++band)
218  {
219  if(bufArray[band][offset] != theInputValueArray[band])
220  {
221  equalFlag = false;
222  }
223  }
224  if(equalFlag)
225  {
226  for(band = 0; band<numberOfBands; ++band)
227  {
228  bufArray[band][offset] = static_cast<T>(theOutputValueArray[band]);
229  }
230  }
231  }
232 
233  delete [] bufArray;
234 }
235 
237 {
238  // Base class will recapture "theInputConnection".
240 }
241 
243 {
244  theTile = NULL;
245 
247  {
249 
250  theTile = idf->create(this,
251  this);
252 
253  theTile->initialize();
254  }
255 }
256 
258  const char* prefix)const
259 {
260  ossim_uint32 index = 0;
261  for(index =0; index < theInputValueArray.size(); ++index)
262  {
263  ossimString in = ("input_band" + ossimString::toString(index));
264  ossimString out = ("output_band" + ossimString::toString(index));
265 
266  kwl.add(prefix,
267  in.c_str(),
268  theInputValueArray[index],
269  true);
270  kwl.add(prefix,
271  out.c_str(),
272  theOutputValueArray[index],
273  true);
274  }
276  {
277  kwl.add(prefix,
278  "assign_type",
279  "separate",
280  true);
281  }
282  else
283  {
284  kwl.add(prefix,
285  "assign_type",
286  "group",
287  true);
288  }
289 
290  return ossimImageSourceFilter::saveState(kwl, prefix);
291 }
292 
298  const char* prefix)
299 {
300 
301  ossimString inRegExpression = ossimString("^(") +
302  ossimString(prefix) +
303  "input_band[0-9]+)";
304  ossimString outRegExpression = ossimString("^(") +
305  ossimString(prefix) +
306  "output_band[0-9]+)";
307  ossim_uint32 numberOfInputs = kwl.getNumberOfSubstringKeys(inRegExpression);
308  ossim_uint32 numberOfOutputs = kwl.getNumberOfSubstringKeys(outRegExpression);
309  ossim_uint32 index = 0;
310  ossim_uint32 currentIndex = 0;
311 
312  theInputValueArray.clear();
313  theOutputValueArray.clear();
314 
315  while(index < numberOfInputs)
316  {
317  const char* value = kwl.find(prefix,
318  (ossimString("input_band") +
319  ossimString::toString(currentIndex)).c_str()
320  );
321  if(value)
322  {
323  theInputValueArray.push_back(ossimString(value).toDouble());
324  ++index;
325  }
326  ++currentIndex;
327  }
328  index = 0;
329  currentIndex = 0;
330  while(index < numberOfOutputs)
331  {
332  const char* value = kwl.find(prefix,
333  (ossimString("output_band") +
334  ossimString::toString(currentIndex)).c_str()
335  );
336  if(value)
337  {
338  theOutputValueArray.push_back(ossimString(value).toDouble());
339  ++index;
340  }
341  ++currentIndex;
342  }
343  validateArrays();
344 
345  const char* assignType = kwl.find(prefix, "assign_type");
346  if(assignType)
347  {
348  if(ossimString(assignType).trim().downcase() == "separate")
349  {
351  }
352  else
353  {
355  }
356  }
357  else
358  {
360  }
361 
362  return ossimImageSourceFilter::loadState(kwl, prefix);
363 }
364 
366 {
367  return theInputValueArray;
368 }
370 {
371  return theOutputValueArray;
372 }
373 
375 {
376  return theAssignType;
377 }
379 {
380  theAssignType = type;
381 }
This allows one to assign a value to a group of bands.
16 bit unsigned integer (15 bits used)
void executeAssignGroup(T, ossimRefPtr< ossimImageData > &data)
virtual ossim_uint32 getWidth() const
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
void executeAssignSeparate(T, ossimRefPtr< ossimImageData > &data)
RTTI_DEF1(ossimValueAssignImageSourceFilter, "ossimValueAssignImageSourceFilter", ossimImageSourceFilter)
virtual ossim_uint32 getNumberOfBands() const
ossim_uint32 getNumberOfSubstringKeys(const ossimString &regularExpression) const
virtual void setImageRectangle(const ossimIrect &rect)
Represents serializable keyword/value map.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=NULL)
Method to the load (recreate) the state of an object from a keyword list.
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=NULL) const
Method to save the state of an object to a keyword list.
static ossimString toString(bool aValue)
Numeric to string methods.
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
16 bit unsigned integer (14 bits used)
16 bit unsigned integer (13 bits used)
virtual void initialize()
Initialize the data buffer.
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual void loadTile(const void *src, const ossimIrect &src_rect, ossimInterleaveType il_type)
static ossimImageDataFactory * instance()
virtual ossimDataObjectStatus validate() const
ossimImageSource * theInputConnection
unsigned int ossim_uint32
32 bit normalized floating point
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
void allocate()
Called on first getTile, will initialize all data needed.
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
virtual ossimScalarType getScalarType() const
virtual void makeBlank()
Initializes data to null pixel values.
64 bit normalized floating point
16 bit unsigned integer (11 bits used)
void executeAssign(T, ossimRefPtr< ossimImageData > &data)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
void setInputOutputValues(const vector< double > &inputValues, const vector< double > &outputValues)
virtual const void * getBuf() const
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
32 bit floating point
16 bit unsigned iteger
64 bit floating point
16 bit signed integer
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
8 bit unsigned iteger
#define min(a, b)
Definition: auxiliary.h:75
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)
16 bit unsigned integer (12 bits used)