OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimImageGaussianFilter.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // License: LGPL
3 //
4 // See LICENSE.txt file in the top level directory for more details.
5 // class ossimImageGaussianFilter : tile source
6 //*******************************************************************
7 // $Id: ossimImageGaussianFilter.cpp 21631 2012-09-06 18:10:55Z dburken $
8 
13 #include <cmath>
14 
15 RTTI_DEF1(ossimImageGaussianFilter, "ossimImageGaussianFilter", ossimImageSourceFilter);
16 
20 static const char* PROPERTYNAME_GAUSSSTD = "GaussStd";
21 static const char* PROPERTYNAME_STRICTNODATA = "StrictNoData";
22 
25  theGaussStd(0.5),
26  theStrictNoData(true)
27 {
28  // ingredients:
29  // 2x ConvolutionFilter1D
32 
33  theHF->setIsHorizontal(true);
34  theVF->setIsHorizontal(false);
35  updateKernels();
36 
39 
40  //tie them up
42 }
43 
45 {
46  if(theHF.valid())
47  {
48  theHF->disconnect();
49  theHF = 0;
50  }
51  if(theVF.valid())
52  {
53  theVF->disconnect();
54  theVF = 0;
55  }
56 }
57 
59 {
60  if(!property) return;
61 
62  if (property->getName() == PROPERTYNAME_GAUSSSTD) {
64  property.get());
65  if(sProperty)
66  {
67  setGaussStd(sProperty->asFloat64());
68  }
69  } else if (property->getName() == PROPERTYNAME_STRICTNODATA) {
71  property.get());
72  if(booleanProperty)
73  {
74  setStrictNoData(booleanProperty->getBoolean());
75  }
76  } else {
78  }
79 }
80 
82 {
83  if (name == PROPERTYNAME_GAUSSSTD) {
85  property->setCacheRefreshBit();
86  return property;
87  } else if (name == PROPERTYNAME_STRICTNODATA) {
89  property->setCacheRefreshBit();
90  return property;
91  }
93 }
94 
95 void ossimImageGaussianFilter::getPropertyNames(std::vector<ossimString>& propertyNames)const
96 {
98  propertyNames.push_back(PROPERTYNAME_GAUSSSTD);
99  propertyNames.push_back(PROPERTYNAME_STRICTNODATA);
100 }
101 
103  const char* prefix)const
104 {
105  kwl.add(prefix,
106  PROPERTYNAME_GAUSSSTD,
107  theGaussStd,
108  true);
109  kwl.add(prefix,
110  PROPERTYNAME_STRICTNODATA,
111  isStrictNoData()?"true":"false", //use string instead of boolean
112  true);
113 
114  return ossimImageSourceFilter::saveState(kwl, prefix);
115 }
116 
117 
119  const char* prefix)
120 {
121  const char* gs = kwl.find(prefix, PROPERTYNAME_GAUSSSTD);
122  if(gs)
123  {
124  setGaussStd(ossimString(gs).toDouble());
125  } else {
126  cerr<<"ossimImageGaussianFilter : warning no "<< PROPERTYNAME_GAUSSSTD<<" in loadState"<<endl;
127  }
128  const char* sn = kwl.find(prefix, PROPERTYNAME_STRICTNODATA);
129  if(sn)
130  {
131  setStrictNoData(ossimString(sn).toBool());
132  } else {
133  cerr<<"ossimConvolutionFilter1D : warning no "<<PROPERTYNAME_STRICTNODATA<<" in state"<<endl;
134  }
135  return ossimImageSourceFilter::loadState(kwl, prefix);
136 }
137 
139 {
140  theGaussStd = v;
141  updateKernels();
142 }
143 
145 {
146  theStrictNoData = aStrict;
147  theHF->setStrictNoData(aStrict);
148  theVF->setStrictNoData(aStrict);
149 }
150 
151 void
153 {
156 }
157 
160 {
161  if(isSourceEnabled())
162  {
163  return theVF->getTile(tileRect, resLevel);
164  }
166  {
167  return theInputConnection->getTile(tileRect, resLevel);
168  }
169 
170  return 0;
171 }
172 
173 void
175 {
176  theHF->initialize();
177  theVF->initialize();
178 }
179 
180 void
182 {
184  if(getInput())
185  {
188  }
189  else
190  {
191  theHF->disconnectMyInput(0, false, false);
193  }
194 }
195 
196 void
198 {
200  if(getInput())
201  {
204  }
205  else
206  {
207  theHF->disconnectMyInput(0, false, false);
209  }
210 }
211 void
213 {
214  //update kernels based on GaussStd value :2.5 sigma on each side
215  // symetric kernel
216  static const ossim_float64 sigmaN = 2.5;
217  ossim_float64 sig22 = getGaussStd()*getGaussStd()*2.0;
218 
219  ossim_uint32 halfw = (ossim_uint32)(std::floor(getGaussStd() * sigmaN + 0.5));
220  ossim_uint32 supsize = 2*halfw + 1;
221 
222  //fill with sym. gaussian (unnormalized)
223  vector<ossim_float64> newk(supsize);
224  ossim_float64 sum=1.0;
225  ossim_float64 v;
226  newk[halfw] = 1.0;
227  for(ossim_int32 i=(ossim_int32)halfw; i>0 ;--i) //reverse for summing
228  {
229  newk[halfw + i] = newk[halfw - i] = v = std::exp(-i*i/sig22);
230  sum += 2.0 * v;
231  }
232 
233  //normalize
234  ossim_float64 invsum=1.0/sum;
235  for(ossim_uint32 i=0; i<supsize ;++i)
236  {
237  newk[i] *= invsum;
238  }
239 
240  //send to 1d conv filters
241  theHF->setKernel(newk);
242  theVF->setKernel(newk);
243  theHF->setCenterOffset(halfw);
244  theVF->setCenterOffset(halfw);
245 }
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual ossimRefPtr< ossimConnectableObject > disconnectMyInput(ossim_int32 inputIndex, bool disconnectOutputFlag=true, bool createEventFlag=true)
Will disconnect the object at the given input index and generate a connection event.
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual void connectInputEvent(ossimConnectionEvent &event)
virtual void disconnect(ossimConnectableObject *object=0)
Will disconnect the object passed in.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
RTTI_DEF1(ossimImageGaussianFilter, "ossimImageGaussianFilter", ossimImageSourceFilter)
ossim_float64 getGaussStd() const
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
static ossimString toString(bool aValue)
Numeric to string methods.
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
virtual void setKernel(const std::vector< ossim_float64 > &aKernel)
virtual void disconnectInputEvent(ossimConnectionEvent &event)
void initializeProcesses()
protected methods
virtual void setStrictNoData(bool aStrict)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
ossimConnectableObject * getInput(ossim_uint32 index=0)
returns the object at the specified index.
double ossim_float64
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
ossim_float64 theGaussStd
parameters
virtual void disconnectInputEvent(ossimConnectionEvent &event)
class for symmetric Gaussian filtering implemented as two separable horizontal/vertical gaussian filt...
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
ossimImageSource * theInputConnection
unsigned int ossim_uint32
#define PTR_CAST(T, p)
Definition: ossimRtti.h:321
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
class for vertical or horizontal convolution
void setGaussStd(const ossim_float64 &v)
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual void setIsHorizontal(bool aIsHz)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
virtual void connectInputEvent(ossimConnectionEvent &event)
ossimRefPtr< ossimConvolutionFilter1D > theHF
subprocesses
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual void initialize()
inherited methods
virtual ossim_float64 asFloat64() const
virtual void setCenterOffset(ossim_int32 aCenterOffset)
ossimRefPtr< ossimConvolutionFilter1D > theVF
const ossimString & getName() const
int ossim_int32
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)