ValidDataOperator 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSGTERRAIN_VALIDDATAOPERATOR
  14. #define OSGTERRAIN_VALIDDATAOPERATOR 1
  15. #include <osg/Referenced>
  16. #include <osg/Vec2>
  17. #include <osg/Vec3>
  18. #include <osg/Vec4>
  19. #include <osgTerrain/Export>
  20. namespace osgTerrain {
  21. struct ValidDataOperator : public osg::Referenced
  22. {
  23. virtual bool operator() (float /*value*/) const { return true; }
  24. virtual bool operator() (const osg::Vec2& value) const { return operator()(value.x()) && operator()(value.y()) ; }
  25. virtual bool operator() (const osg::Vec3& value) const { return operator()(value.x()) && operator()(value.y()) && operator()(value.z()); }
  26. virtual bool operator() (const osg::Vec4& value) const { return operator()(value.x()) && operator()(value.y()) && operator()(value.z()) && operator()(value.w()); }
  27. };
  28. struct ValidRange : public ValidDataOperator
  29. {
  30. ValidRange(float minValue, float maxValue):
  31. _minValue(minValue),
  32. _maxValue(maxValue) {}
  33. void setRange(float minValue, float maxValue)
  34. {
  35. _minValue = minValue;
  36. _maxValue = maxValue;
  37. }
  38. void setMinValue(float minValue) { _minValue = minValue; }
  39. float getMinValue() const { return _minValue; }
  40. void setMaxValue(float maxValue) { _maxValue = maxValue; }
  41. float getMaxValue() const { return _maxValue; }
  42. virtual bool operator() (float value) const { return value>=_minValue && value<=_maxValue; }
  43. float _minValue, _maxValue;
  44. };
  45. struct NoDataValue : public ValidDataOperator
  46. {
  47. NoDataValue(float value):
  48. _value(value) {}
  49. void setNoDataValue(float value) { _value = value; }
  50. float getValue() const { return _value; }
  51. virtual bool operator() (float value) const { return value!=_value; }
  52. float _value;
  53. };
  54. }
  55. #endif