OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimSlopeFilter.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // OSSIM
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 //*******************************************************************
7 // $Id: ossimSlopeFilter.cpp 23451 2015-07-27 15:42:17Z okramer $
8 
9 #include <iostream>
10 
14 
16 
17 const char* SLOPE_TYPE_KW = "slope_type";
18 
21  m_slopeType (DEGREES)
22 {
23 }
24 
26  :
27  ossimImageSourceFilter(inputSource),
28  m_slopeType (DEGREES)
29 {
30 }
31 
33 {
34  m_normals = 0;
35 }
36 
38 {
41 
42  if ( !isSourceEnabled() )
43  return theInputConnection->getTile(rect, rLevel);
44 
45  if (!m_normals.valid())
46  initialize();
47 
48  ossimRefPtr<ossimImageData> normals = m_normals->getTile(rect, rLevel);
49  if (!normals.valid())
51 
52  ossimRefPtr<ossimImageData> outputTile = new ossimImageData(this, OSSIM_FLOAT32, 1);
53  outputTile->setImageRectangle(rect);
54  outputTile->initialize();
55  ossim_float32* output_buf = outputTile->getFloatBuf();
56  ossim_float32 null_output = (ossim_float32) outputTile->getNullPix(0);
57 
58  double z, theta;
59  double null_input = normals->getNullPix(2);
60  ossim_uint32 num_pix = normals->getSizePerBand();
61  for (ossim_uint32 i=0; i<num_pix; ++i)
62  {
63  z = normals->getPix(i, 2);
64  if (z == null_input)
65  {
66  theta = null_output;
67  }
68  else
69  {
70  switch (m_slopeType)
71  {
72  case RADIANS:
73  theta = acos(z);
74  break;
75  case RATIO:
76  theta = z;
77  break;
78  case NORMALIZED:
79  theta = fabs(acos(z)/M_PI);
80  break;
81  default: // Degrees
82  theta = ossim::acosd(z);
83  };
84  }
85  output_buf[i] = theta;
86  }
87 
88  outputTile->validate();
89  return outputTile;
90 }
91 
93 {
94  if (!m_normals.valid())
97 }
98 
100 {
101  if(!property) return;
102 
103  if(property->getName() == SLOPE_TYPE_KW)
104  {
105  ossimString pts (property->valueToString());
106  pts.upcase();
107  if (pts.contains("RADIANS"))
109  else if (pts.contains("DEGREES"))
111  else if (pts.contains("RATIO"))
112  m_slopeType = RATIO;
113  else if (pts.contains("NORMALIZED"))
115  else
116  return;
117 
118  initialize();
119  }
120  else
121  {
123  }
124 }
125 
127 {
128  if(name == SLOPE_TYPE_KW)
129  {
130  ossimString propValue;
131  switch (m_slopeType)
132  {
133  case RADIANS:
134  propValue = getSlopeTypeString(RADIANS);
135  break;
136  case RATIO:
137  propValue = getSlopeTypeString(RATIO);
138  break;
139  case NORMALIZED:
140  propValue = getSlopeTypeString(NORMALIZED);
141  default:
142  propValue = getSlopeTypeString(DEGREES);
143  }
144 
145  vector<ossimString> list;
146  list.push_back(getSlopeTypeString(RADIANS));
147  list.push_back(getSlopeTypeString(DEGREES));
148  list.push_back(getSlopeTypeString(RATIO));
149  list.push_back(getSlopeTypeString(NORMALIZED));
150 
151  return new ossimStringProperty(SLOPE_TYPE_KW, propValue, false, list);
152  }
153 
155 }
156 
157 void ossimSlopeFilter::getPropertyNames(std::vector<ossimString>& propertyNames)const
158 {
160  propertyNames.push_back(SLOPE_TYPE_KW);
161 }
162 
163 bool ossimSlopeFilter::saveState(ossimKeywordlist& kwl, const char* prefix) const
164 {
166 
167  kwl.add(prefix, SLOPE_TYPE_KW, getSlopeTypeString(m_slopeType).c_str(), true);
168 
169  return true;
170 }
171 
172 bool ossimSlopeFilter::loadState(const ossimKeywordlist& kwl, const char* prefix)
173 {
175 
176  ossimString lookup = kwl.find(prefix, SLOPE_TYPE_KW);
177  if (!lookup.empty())
178  {
180  setProperty(prop);
181  }
182 
183  return true;
184 }
185 
187 {
188  if (t == RADIANS)
189  return "RADIANS";
190  if (t == DEGREES)
191  return "DEGREES";
192  if (t == RATIO)
193  return "RATIO";
194  if (t == NORMALIZED)
195  return "NORMALIZED";
196  return "";
197 }
198 
200 {
201  return ossimString("Slope Filter, Computes the change in pixel value in x, Y direction as a "
202  "slope quantity. Assumes that the input source represents elevation in meters.");
203 }
204 
206 {
207  return ossimString("Slope Filter");
208 }
209 
virtual void valueToString(ossimString &valueResult) const =0
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
static ossimString getSlopeTypeString(SlopeType t)
virtual void setProperty(ossimRefPtr< ossimProperty > property)
static ossimString upcase(const ossimString &aString)
Definition: ossimString.cpp:34
virtual ~ossimSlopeFilter()
virtual void setImageRectangle(const ossimIrect &rect)
Filter class for computing the slope image of the input image connection.
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
float ossim_float32
double acosd(double x)
Definition: ossimCommon.h:264
ossimRefPtr< ossimImageToPlaneNormalFilter > m_normals
virtual ossim_float64 getPix(const ossimIpt &position, ossim_uint32 band=0) const
Will return the pixel at location position.
32 bit floating point
virtual void initialize()
Initialize the data buffer.
SlopeType
Specifies how the slope quantity is represented.
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tile_rect, ossim_uint32 rLevel=0)
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
#define M_PI
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual ossimDataObjectStatus validate() const
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=NULL) const
Method to save the state of an object to a keyword list.
virtual ossim_uint32 getSizePerBand() const
Returns the number of pixels in a single band in a tile.
ossimImageSource * theInputConnection
unsigned int ossim_uint32
virtual const ossim_float64 * getNullPix() const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
virtual ossimString getLongName() const
virtual const ossim_float32 * getFloatBuf() const
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual void initialize()
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=NULL)
Method to the load (recreate) the state of an object from a keyword list.
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
bool empty() const
Definition: ossimString.h:411
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
const char * SLOPE_TYPE_KW
const ossimString & getName() const
virtual ossimString getShortName() const
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)