25 static ossimTrace traceDebug(
"ossimPixelFlipper:debug");
36 static const char TARGET_LOWER_LIMIT_PROP_NAME[] =
"target_range_lower_limit";
37 static const char TARGET_UPPER_LIMIT_PROP_NAME[] =
"target_range_upper_limit";
39 #ifdef OSSIM_ID_ENABLED 40 static const char OSSIM_ID[] =
"$Id: ossimPixelFlipper.cpp 21631 2012-09-06 18:10:55Z dburken $";
45 theTargetValueLo(0.0),
46 theTargetValueHi(0.0),
47 theReplacementValue(1.0),
51 theClampingMode(DISABLED),
57 <<
"ossimPixelFlipper::ossimPixelFlipper entered...\n";
58 #ifdef OSSIM_ID_ENABLED 60 <<
"OSSIM_ID: " << OSSIM_ID <<
"\n";
92 std::lock_guard<std::recursive_mutex> scopeLock(
theMutex);
148 <<
"ossimPixelFlipper::getTile Unsupported scalar type!" << endl;
174 T **buf =
new T *[bands];
175 for (band = 0; band < bands; ++band)
176 buf[band] = static_cast<T *>(inputTile->
getBuf(band));
185 bool is_outside_aoi =
false;
186 bool needsTesting =
false;
190 is_outside_aoi =
true;
200 if ((!ulFlag) && (!urFlag) && (!lrFlag) && (!llFlag))
201 is_outside_aoi =
true;
203 needsTesting = !(ulFlag && urFlag && lrFlag && llFlag);
214 bool can_replace, found_candidate;
217 for (pixel_loc.
y = ul.
y; pixel_loc.
y <= lr.
y; ++pixel_loc.
y)
219 for (pixel_loc.
x = ul.
x; pixel_loc.
x <= lr.
x; ++pixel_loc.
x)
224 bool is_inside =
true;
233 for (band = 0; band < bands; ++band)
234 buf[band][i] = replacement;
249 for (band = 0; band < bands; ++band)
252 buf[band][i] = clampLo;
254 buf[band][i] = clampHi;
263 found_candidate =
false;
264 for (band = 0; (band < bands) && !(can_replace && found_candidate); ++band)
268 found_candidate =
true;
272 if (can_replace && found_candidate)
276 for (band = 0; band < bands; ++band)
279 buf[band][i] = clampLo;
281 buf[band][i] = clampHi;
290 for (band = 0; (band < bands) && can_replace; ++band)
299 for (band = 0; band < bands; ++band)
302 buf[band][i] = clampLo;
304 buf[band][i] = clampHi;
320 for (band = 0; band < bands; ++band)
322 if ((buf[band][i] >= targetLo) && (buf[band][i] <= targetHi))
332 found_candidate =
false;
333 for (band = 0; (band < bands) && !(can_replace && found_candidate); ++band)
336 if ((buf[band][i] < targetLo) || (buf[band][i] > targetHi))
339 found_candidate =
true;
341 if (can_replace && found_candidate)
345 for (band = 0; band < bands; ++band)
347 if ((buf[band][i] >= targetLo) && (buf[band][i] <= targetHi))
358 found_candidate =
false;
359 for (band = 0; (band < bands) && !(can_replace && found_candidate); ++band)
362 if ((buf[band][i] < targetLo) || (buf[band][i] > targetHi))
365 found_candidate =
true;
367 if (can_replace && found_candidate)
371 for (band = 0; band < bands; ++band)
381 for (band = 0; (band < bands) && can_replace; ++band)
384 if ((buf[band][i] < targetLo) || (buf[band][i] > targetHi))
390 for (band = 0; band < bands; ++band)
400 for (band = 0; (band < bands) && !can_replace; ++band)
403 if ((buf[band][i] >= targetLo) && (buf[band][i] <= targetHi))
409 for (band = 0; band < bands; ++band)
436 if (!inputTile->
getBuf() ||
503 else if (!(ulWithin ||
521 for (
y = 0;
y < h; ++
y)
524 for (
x = 0;
x < w; ++
x)
545 if (inputImage.
valid())
547 bool needDupFlag =
false;
573 std::lock_guard<std::recursive_mutex> scopeLock(
theMutex);
591 for (idx = 0; idx < rlevels; ++idx)
593 std::vector<ossimIpt> validVertices;
685 const char *lookupReturn;
752 const char *prefix)
const 787 std::lock_guard<std::recursive_mutex> scopeLock(
theMutex);
800 std::lock_guard<std::recursive_mutex> scopeLock(
theMutex);
808 std::lock_guard<std::recursive_mutex> scopeLock(
theMutex);
811 if (
inRange(replacement_value))
819 std::lock_guard<std::recursive_mutex> scopeLock(
theMutex);
848 std::lock_guard<std::recursive_mutex> scopeLock(
theMutex);
854 std::lock_guard<std::recursive_mutex> scopeLock(
theMutex);
858 if (mode ==
"REPLACE_BAND_IF_TARGET")
862 else if (mode ==
"REPLACE_BAND_IF_PARTIAL_TARGET")
866 else if (mode ==
"REPLACE_ALL_BANDS_IF_PARTIAL_TARGET")
870 else if (mode ==
"REPLACE_ONLY_FULL_TARGETS")
874 else if (mode ==
"REPLACE_ALL_BANDS_IF_ANY_TARGET")
881 <<
"ossimPixelFlipper::setReplacementMode warning:\n" 882 <<
"Invalid mode: " << modeString
891 std::lock_guard<std::recursive_mutex> scopeLock(
theMutex);
903 else if (mode ==
"bounding_rect")
907 else if (mode ==
"valid_vertices")
914 <<
"ossimPixelFlipper::setClipMode warning:\n" 915 <<
"Invalid mode: " << modeString
942 return ossimString(
"REPLACE_BAND_IF_PARTIAL_TARGET");
944 return ossimString(
"REPLACE_ALL_BANDS_IF_PARTIAL_TARGET");
948 return ossimString(
"REPLACE_ALL_BANDS_IF_ANY_TARGET");
974 out <<
"ossimPixelFlipper::print:" 990 std::lock_guard<std::recursive_mutex> scopeLock(
theMutex);
1008 if (name == TARGET_UPPER_LIMIT_PROP_NAME)
1040 vector<ossimString> constraintList(5);
1041 constraintList[0] =
"REPLACE_BAND_IF_TARGET";
1042 constraintList[1] =
"REPLACE_BAND_IF_PARTIAL_TARGET";
1043 constraintList[2] =
"REPLACE_ALL_BANDS_IF_PARTIAL_TARGET";
1044 constraintList[3] =
"REPLACE_ONLY_FULL_TARGETS";
1045 constraintList[4] =
"REPLACE_ALL_BANDS_IF_ANY_TARGET";
1057 vector<ossimString> constraintList(3);
1058 constraintList[0] =
"none";
1059 constraintList[1] =
"bounding_rect";
1060 constraintList[2] =
"valid_vertices";
1099 if (name == TARGET_LOWER_LIMIT_PROP_NAME)
1103 if (name == TARGET_UPPER_LIMIT_PROP_NAME)
1134 std::vector<ossimString> &propertyNames)
const 1137 propertyNames.push_back(TARGET_LOWER_LIMIT_PROP_NAME);
1138 propertyNames.push_back(TARGET_UPPER_LIMIT_PROP_NAME);
1170 if ((value == NULL_PIX) || ((value >= MIN_PIX) && (value <= MAX_PIX)))
1176 <<
"\nossimPixelFlipper::inRange WARNING:" 1177 <<
"\nvalue \"" << value
1178 <<
"\" is out of range!" 1179 <<
"\nInput source null = " << NULL_PIX
1180 <<
"\nInput source min = " << MIN_PIX
1181 <<
"\nInput source max = " << MAX_PIX
16 bit unsigned integer (15 bits used)
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
virtual ossim_uint32 getWidth() const
virtual bool isSourceEnabled() const
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
virtual void setDescription(const ossimString &description)
ossimString before(const ossimString &str, std::string::size_type pos=0) const
METHOD: before(str, pos) Returns string beginning at pos and ending one before the token str If strin...
ossim_float64 theReplacementValue
When target values are defined, this is the value the pixel will assume if the pixel falls within the...
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
static ossimString upcase(const ossimString &aString)
virtual ossim_uint32 getNumberOfBands() const
void setClipMode(const ossimString &modeString)
Clipping here refers to bounding rect or valid polygon (spacial) clipping, where all pixels outside t...
ReplacementMode
Target Replacement Mode:
virtual void setImageRectangle(const ossimIrect &rect)
virtual ~ossimPixelFlipper()
destructor
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
Represents serializable keyword/value map.
ossimPixelFlipper(ossimObject *owner=NULL)
default constructor
ClipMode theClipMode
Border Clip mode.
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
const char * find(const char *key) const
ReplacementMode theReplacementMode
See documentation for ReplacementMode enum above.
std::recursive_mutex theMutex
For lock and unlock.
double nan()
Method to return ieee floating point double precision NAN.
This code was derived from https://gist.github.com/mshockwave.
ossim_float64 theTargetValueLo
The value range to replace.
static const char PF_REPLACEMENT_MODE_KW[]
static ossimString toString(bool aValue)
Numeric to string methods.
static const char PF_CLAMP_VALUE_KW[]
const ossimIpt & ul() const
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
16 bit unsigned integer (14 bits used)
16 bit unsigned integer (13 bits used)
virtual ossim_uint32 getNumberOfDecimationLevels() const
Will return the number of resolution levels.
static const char PF_TARGET_RANGE_KW[]
bool intersects(const ossimIrect &rect) const
unsigned short ossim_uint16
const ossimIpt & ll() const
ossimPixelFlipper::ReplacementMode getReplacementMode() const
void setClampValue(ossim_float64 clamp_value, bool is_high_clamp_value=true)
virtual void initialize()
Initializes the state of the object from theInputConnection.
static const char PF_CLAMP_VALUE_LO_KW[]
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
void setReplacementMode(ossimPixelFlipper::ReplacementMode mode)
virtual ossimObject * dup() const
ossim_float64 getReplacementValue() const
virtual void initialize()
bool completely_within(const ossimIrect &rect) const
ClampingMode
When either a lo and/or hi clamp value is set, the clamping mode will be enabled accordingly and over...
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual void loadTile(const void *src, const ossimIrect &src_rect, ossimInterleaveType il_type)
ossim_float64 theTargetValueHi
void allocateClipTileBuffer(ossimRefPtr< ossimImageData > inputImage)
void flipPixels(T dummy, ossimImageData *inpuTile, ossim_uint32 resLevel)
This object can be used outside of an image chain for offline processing of existing tile...
virtual ossimDataObjectStatus validate() const
signed short ossim_sint16
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
static const char PF_CLAMP_VALUE_HI_KW[]
virtual void getValidImageVertices(std::vector< ossimIpt > &validVertices, ossimVertexOrdering ordering=OSSIM_CLOCKWISE_ORDER, ossim_uint32 resLevel=0) const
ordering specifies how the vertices should be arranged.
ossimImageSource * theInputConnection
unsigned int ossim_uint32
32 bit normalized floating point
ossim_float64 toFloat64() const
ClipMode getClipMode() const
virtual ossimIrect getImageRectangle() 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 ossim_float64 getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
ossimString getClipModeString() const
void setClampValues(ossim_float64 clamp_value_lo, ossim_float64 clamp_value_hi)
const ossimIpt & lr() const
virtual void enableSource()
static ossimString downcase(const ossimString &aString)
virtual ossimString getShortName() const
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tile_rect, ossim_uint32 resLevel=0)
ClampingMode theClampingMode
ossim_float64 theClampValueHi
ossimIrect clipToRect(const ossimIrect &rect) const
static const char * ENABLED_KW
void setNull(ossim_uint32 offset)
const ossimIpt & ur() const
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 setTargetRange(ossim_float64 target_min, ossim_float64 target_max)
Instead of a single value for a target, this method allows for specifying a range of values to flip t...
void setReplacementValue(ossim_float64 replacement_value)
ossimString getReplacementModeString() const
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
void setTargetValue(ossim_float64 target_value)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
bool isPointWithin(const ossimDpt &point) const
Class to scan pixels and flip target dn value to a replacement dn value.
virtual const void * getBuf() const
virtual std::ostream & print(std::ostream &out) const
Outputs theErrorStatus as an ossimErrorCode and an ossimString.
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
void clipTile(T dummy, ossimImageData *inpuTile, ossim_uint32 resLevel)
virtual void setDataObjectStatus(ossimDataObjectStatus status) const
Full list found in ossimConstants.h.
ossim_float64 theClampValueLo
The range of desired pixel values.
static const char PF_REPLACEMENT_VALUE_KW[]
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
ossimRefPtr< ossimImageData > theClipTileBuffer
#define RTTI_DEF1(cls, name, b1)
static const char PF_CLIP_MODE_KW[]
ossimString after(const ossimString &str, std::string::size_type pos=0) const
METHOD: after(str, pos) Returns string immediately after the token str.
unsigned char ossim_uint8
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
virtual ossim_float64 getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::vector< ossimIrect > theBoundingRects
bool inRange(ossim_float64 value) const
Verifies pixel is in range.
std::basic_ostream< char > ostream
Base class for char output streams.
void setCacheRefreshBit()
std::vector< ossimPolygon > theValidVertices
static const char PF_TARGET_VALUE_KW[]
const ossimString & getName() const
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)
16 bit unsigned integer (12 bits used)
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.