Isis Developer Reference
|
Strategy - Supports algorithm development. More...
#include <Strategy.h>
Public Member Functions | |
Strategy () | |
Constructs default Strategy object of name "Strategy" and type "Counter". | |
Strategy (const PvlObject &definition, const ResourceList &globals) | |
Constructs Strategy object from the given definition pvl and shared resource globals. | |
virtual | ~Strategy () |
Destroys the Strategy object. | |
QString | name () const |
Accessor method to get the name of the strategy. | |
QString | type () const |
Accessor method to get the type of strategy. | |
QString | description () const |
Return description for the strategy. | |
int | apply (ResourceList &resources) |
Apply algorithm to resource list. | |
int | apply (SharedResource &resource) |
Apply algorithm to Resource. | |
virtual int | apply (ResourceList &resources, const ResourceList &globals) |
Apply strategy algorithms to list of Resources. | |
virtual int | apply (SharedResource &resource, const ResourceList &globals) |
This method applies the strategy algorithms to the data stored in the given shared resource. | |
unsigned int | totalProcessed () const |
Accessor for the total number of resources processed. | |
Protected Types | |
typedef QSharedPointer< PvlObject > | SharedPvlObject |
Definition for a SharedPvlObject, a shared pointer to a PvlObject. | |
Protected Member Functions | |
Strategy (const QString &name, const QString &type) | |
Constructs a Strategy object from the given name, type, and shared resource globals. | |
void | setName (const QString &name) |
Allow derived strategies to reset name (mostly for default constructors) | |
void | setType (const QString &type) |
Allow derived strategies to reset type (mostly for default constructors) | |
ResourceList | getGlobalDefaults () const |
Accessor method to get the global defaults. | |
ResourceList | getGlobals (SharedResource &myGlobals, const ResourceList &globals) const |
const PvlObject & | getDefinition () const |
PvlFlatMap | getDefinitionMap () const |
Returns the keyword definitions found in the Strategy object. | |
void | setApplyToDiscarded () |
Sets Resource as discarded. | |
bool | isApplyToDiscarded () const |
Accessor for the apply discarded variable. | |
void | setDoNotApplyToDiscarded () |
Disables the general application of Strategy algorithm for all Resources regardless of state. | |
int | applyToResources (ResourceList &resources, const ResourceList &globals) |
Applies the strategy algorithms to the resources in the given list. | |
unsigned int | processed () |
Increments the total number of resources processed and returns the incremented value. | |
void | resetProcessed () |
Resets the total number of processed resources to zero. | |
int | countActive (const ResourceList &resources) const |
Counts the number of active (i.e. | |
int | countDiscarded (const ResourceList &resources) const |
Counts the number of non-active (i.e. | |
ResourceList | assetResourceList (const SharedResource &resource, const QString &name) const |
Searches the given resource for an asset with the given name and converts it to a ResourceList, if possible. | |
QString | findReplacement (const QString &target, const ResourceList &globals, const int &index=0, const QString &defValue="") const |
Find keyword replacement value in globals list. | |
QStringList | qualifiers (const QString &keyspec, const QString &delimiter="::") const |
Splits the given keyspec string into a list using the given delimiter string. | |
QString | scanAndReplace (const QString &input, const QString &target, const QString &replacement) const |
Performs a case insensitive scan of the input string for a substring matching the target string and replaces the target substring with the replacement string. | |
QString | translateKeywordArgs (const QString &value, const ResourceList &globals, const QString &defValue="") const |
Translates the arguments of the PVL keyword in the PVL definition object. | |
QString | processArgs (const QString &value, const QStringList &argKeys, const ResourceList &globals, const QString &defValue="") const |
Processes the given string value using the given argument list, resource and default resource. | |
void | propagateKeys (SharedResource &source, SharedResource &target) const |
Adds the PVL definition keywords from the source to the target. | |
SharedResource | composite (SharedResource &resourceA, SharedResource &resourceB, const QPair< QString, QString > &keySuffix=qMakePair(QString("A"), QString("B"))) const |
Create a composite Resource from a pair by merging keywords. | |
bool | importGeometry (SharedResource &resource, const ResourceList &globals) const |
Imports a geometry from the given resource. | |
ResourceList | activeList (ResourceList &resources) const |
Get list of all active Resources only - no discarded Resources. | |
void | activateList (ResourceList &resources) const |
Activate all resources contained in the resource list. | |
void | deactivateList (ResourceList &resources) const |
Deactivate all resources contained in the resource list. | |
ResourceList | copyList (const ResourceList &resources) const |
Make a copy of the resource list that is independently managed. | |
ResourceList | cloneList (const ResourceList &resources, const bool &withAssets=false) const |
Create a clone of a Resource list. | |
int | applyToIntersectedGeometry (ResourceList &resources, GisGeometry &geom, const ResourceList &globals) |
Identify and apply Strategy to Resources that intersect a geometry. | |
bool | isDebug () const |
An accessor method so that inherited classes can determine whether to print debug messages for this object. | |
bool | doShowProgress () const |
bool | initProgress (const int &nsteps=0, const QString &text="") |
Initializes strategy progress monitor if requested by user. | |
QStringList | getObjectList (const PvlObject &object) const |
template<class STRATEGYLIST , class STRATEGYFACTORY > | |
STRATEGYLIST | LoadMinerStrategies (const QString &minerName, const ResourceList &globals) const |
Static Protected Member Functions | |
static void | queryCallback (void *item, void *userdata) |
Important GEOS query callback for class and overlap geometry. | |
Strategy - Supports algorithm development.
This base class provides a framework to develop strategic planning tools used to process and/or rank ISIS resources.
The ISIS resource can be cubes, PVLs (e.g., PDS/EDRs, etc), CSV files or virtually any other resource type simply by adding support in the Resources type class.
This default implementation is simply a LessThan function for real data types
The Users may provide values for the following influential keywords in the Pvl Stategy configuration:
|
protected |
Definition for a SharedPvlObject, a shared pointer to a PvlObject.
Isis::Strategy::Strategy | ( | ) |
Constructs default Strategy object of name "Strategy" and type "Counter".
Debug and apply discarded are set to false.
Isis::Strategy::Strategy | ( | const PvlObject & | definition, |
const ResourceList & | globals ) |
Constructs Strategy object from the given definition pvl and shared resource globals.
Strategy name, strategy type, debug, and apply discarded values are read from the pvl. If not found in the PVL, debug and apply discarded are set to false.
Example PVL:
definition | A PVL that defines the strategy. |
globals | A shared pointer to a global Resource of keywords. |
References getDefinitionMap(), initProgress(), and Isis::toBool().
|
virtual |
Destroys the Strategy object.
|
protected |
Constructs a Strategy object from the given name, type, and shared resource globals.
Debug and apply discarded are set to false.
name | A string containing the strategy name. |
type | A string containing the strategy type. |
|
protected |
Activate all resources contained in the resource list.
resources | A list of resources to activate. |
|
protected |
Get list of all active Resources only - no discarded Resources.
resources | A list of resources to check. |
Referenced by applyToIntersectedGeometry().
int Isis::Strategy::apply | ( | ResourceList & | resources | ) |
Apply algorithm to resource list.
This method is used to initiate the Strategy algorithm implemented by deriving Strategy for a list of Resources.
resources | List of resources to be processed by the Strategy algorithm |
References apply(), and getGlobalDefaults().
Referenced by apply(), apply(), applyToIntersectedGeometry(), and applyToResources().
|
virtual |
Apply strategy algorithms to list of Resources.
This method iterates once through all Resources contained in the list. Resources that have been discarded are filtered out unless users/strategies opt to process all resources.
By making the actual iteration of Resources a separate method, this allows other strategies to derive this virtual return to give them a change to do something meaninful prior to processing the Resource list, but retain behavior in counts and calls to the Resource applicator.
resources | A list of resources to which the strategy will be applied. |
References applyToResources().
int Isis::Strategy::apply | ( | SharedResource & | resource | ) |
|
virtual |
This method applies the strategy algorithms to the data stored in the given shared resource.
resource | A resource to which the strategy will be applied. |
References isDebug().
|
protected |
Identify and apply Strategy to Resources that intersect a geometry.
This method applies the Strategy::apply(SharedResource &) method for all Resources whose geometry intersect the given geometry. This method uses a very efficient RTree implementation in GEOS to determine geometries that intersect each others envelope (a minimal boundary for a geometry). There is a significant performance increase (up to 30% or more) achieved by using this method over direct intersection and operation techniques.
However, since this is typically done once, it is not advantageous to create an index and then search it doing essentially the same operation as the evaluation of the RTree. Therefore a direct intersection loop is available and applied by default. The use of the RTree method can be selected by a user preferenced keyword. Set GisMethod = Indexed. The default is GisMethod = Direct.
This method only acts upon active Resources, so be sure to provide the appropriate state of Resources in the list provided.
It will discard all Resources prior to call the GEOS intersection query. When a Resources is identified to intersect, it makes in active again prior to calling the Strategy::apply(SharedResource &) method. Note that the implementation of the apply(SharedResource &) should further check for false postives as the envelope used in the RTree method may not be as accurate as is required for a robust intersection of GIS geometries.
resources | A list of resources to which the strategy will be applied. |
geom | A reference to the GIS geometry to be intersected. |
globals | Global parameter pool for keyword translation |
IException::Programmer | "Cannot apply RTree search to bad geometry." |
References _FILEINFO_, activeList(), apply(), deactivateList(), Isis::GisGeometry::geometry(), Isis::PvlFlatMap::get(), getDefinitionMap(), initProgress(), Isis::GisGeometry::intersects(), isDebug(), Isis::GisGeometry::isValid(), name(), processed(), Isis::IException::Programmer, queryCallback(), Isis::toString(), and type().
|
protected |
Applies the strategy algorithms to the resources in the given list.
resources | A list of resources to which the strategy will be applied. |
globals | A list of global resources. |
References apply(), countActive(), initProgress(), isApplyToDiscarded(), and processed().
Referenced by apply().
|
protected |
Searches the given resource for an asset with the given name and converts it to a ResourceList, if possible.
resource | The resource to be searched |
name | The name of the asset being searched for |
References name().
|
protected |
Create a clone of a Resource list.
This method creates a clone of the resources where an independent copy of the Resource data is created from its parent. Assets are optional created as well, but can be retained if desired. Any shared components are simply copied as well and can be individually managed if desired.
This creates new data for all copies the parent for each resource. All Resources are set to an active state upon cloning.
resources | List of resources to clone |
withAssets | If true, assets are retained, otherwise they are deleted from the cloned Resource. |
|
protected |
Create a composite Resource from a pair by merging keywords.
This method will create a composite Resource from two resources my merging the keywords from both resources. Users can provide a list of keywords they would like to merge by providing the PropogateKeywords Strategy keyword in the definition section. If not provided or empty, all keywords in each Resource is propagated.
Keywords from each resource are distinguished by appending a suffix to the name of each keyword propagated. For example, the default suffix for resourceA is "A" and resourceB is "B". If the keyword named "Emission" exists in both resourceA and resourceB then two keywords wind up in the composite resource as "EmissionA" and "EmissionB".
The name of the composite resource is the name of resourceA and resourceB separated by an "_".
resourceA | First resource |
resourceB | Second resource |
keySuffix | String pair specifying the suffix to append to the keywords originating from each Resource Defaults: ("A", "B") |
References Isis::PvlFlatMap::allValues(), composite(), getDefinitionMap(), Isis::PvlKeyword::name(), and Isis::PvlKeyword::setName().
Referenced by composite().
|
protected |
Make a copy of the resource list that is independently managed.
This method creates a copy of the resources but provides independent management of its status from its parent. All Resource data, name, keywords, assets and geometry, are copied to the new Resource list created. Its current status is also copied.
This allows the same data for all copies to be shared but the active/discard status to be managed in each copy independently of the parent for each resource.
This is really useful for strategies such as AssetSideBar.
resources | Input list of Resources to copy |
|
protected |
Counts the number of active (i.e.
not discarded) resources in the given list.
resources | A list of resources to count. |
References countDiscarded().
Referenced by applyToResources().
|
protected |
Counts the number of non-active (i.e.
discarded) resources in the given list.
resources | A list of resources to count. |
Referenced by countActive().
|
protected |
Deactivate all resources contained in the resource list.
resources | A list of resources to discard. |
Referenced by applyToIntersectedGeometry().
QString Isis::Strategy::description | ( | ) | const |
Return description for the strategy.
If a Description keyword exists in the PvlObject definition of the strategy, this is returned to the caller. If it doesn't exist, it will provide a simple description made up of its name and type.
|
protected |
Referenced by initProgress(), and processed().
|
protected |
Find keyword replacement value in globals list.
globals | ResourceList A list of resources to be searched. |
target | QString The keyword of the target resource. |
index | int The index of the last resource in the list with keyword == target. |
defValue | QString The value to return in the event the resource is not found. |
Referenced by processArgs().
|
protected |
Referenced by LoadMinerStrategies().
|
protected |
Returns the keyword definitions found in the Strategy object.
References getObjectList(), and Isis::PvlConstraints::withExcludes().
Referenced by applyToIntersectedGeometry(), composite(), importGeometry(), initProgress(), propagateKeys(), Strategy(), and translateKeywordArgs().
|
protected |
|
protected |
myGlobals | Additional source for keyword translation |
globals | Pre-exiting global pool to add myGlobals |
Referenced by importGeometry().
|
protected |
Referenced by getDefinitionMap().
|
protected |
Imports a geometry from the given resource.
By default, this method searches the definition PVL object for a GisGeometry keyword. If the PVL contains either the GisGeometryRef or the GisGeometryKey keywords, then the value is used to search the resource's flat map for the geometry. Then, if the RemoveGisKeywordAfterImport keyword is set to true in the PVL, the resource erases the keyword from the flat map.
If a geometry is found, the PVL is searched for a GisGeometryArgs keyword and the arguments are processed, if they exist. Next, the GisType is read from the PVL. The geometry and type are used to construct a GIS geometry and add it to the resource.
resource | A shared pointer to the resource from which the geometry will be imported. |
globals | The resource list to be searched. |
References Isis::PvlFlatMap::allValues(), Isis::PvlFlatMap::exists(), Isis::PvlFlatMap::get(), getDefinitionMap(), getGlobals(), isDebug(), name(), Isis::GisGeometry::points(), processArgs(), Isis::GisGeometry::simplify(), Isis::toBool(), Isis::toDouble(), Isis::toString(), translateKeywordArgs(), Isis::GisGeometry::type(), and type().
|
protected |
Initializes strategy progress monitor if requested by user.
This method will set up progress monitoring for the user if the "ShowProgress" keyword exists and is set to "True" in any strategy Pvl configuration.
The processed() method will apply status checking to measure progress. For consistency purposes, the resetProcessed() method is always called which resets the internal resource process count to 0.
Strategy implementors must initialize using this method if they rederive apply(ResourceList &resources) or they do not call applyToResources(ResourceList &resources) or appyToIntersectedGeoemtry(ResourceList &resources).
nsteps | Number of steps to set for progress |
text | Optional text to set progress message to |
References doShowProgress(), getDefinitionMap(), name(), resetProcessed(), Isis::toBool(), and type().
Referenced by applyToIntersectedGeometry(), applyToResources(), and Strategy().
|
protected |
Accessor for the apply discarded variable.
Referenced by applyToResources().
|
protected |
An accessor method so that inherited classes can determine whether to print debug messages for this object.
Referenced by apply(), applyToIntersectedGeometry(), and importGeometry().
|
inlineprotected |
References getDefinition(), and translateKeywordArgs().
QString Isis::Strategy::name | ( | ) | const |
Accessor method to get the name of the strategy.
Referenced by applyToIntersectedGeometry(), assetResourceList(), description(), importGeometry(), initProgress(), and setName().
|
protected |
Processes the given string value using the given argument list, resource and default resource.
For each argument in the given list, the target string "%i" (where i is the argument number) is replaced with the resource's keyword value corresponding to the argument. If this value doesn't exist, then the default resource's keyword value is used. If both fail, then the target string is replaced with "NULL"
value | A keyword value to modified using the given argument list and resources. |
argKeys | A list of string arguments representing the resource values to be found in the resource's PVL flat map. |
globals | A list of resources that will be searched. |
defValue | A pointer to the default resource whose PVL flat map will be searched for the arguments if they are not found in the main resource PVL flat map. |
References findReplacement(), and scanAndReplace().
Referenced by importGeometry(), and translateKeywordArgs().
|
protected |
Increments the total number of resources processed and returns the incremented value.
References doShowProgress().
Referenced by applyToIntersectedGeometry(), and applyToResources().
|
protected |
Adds the PVL definition keywords from the source to the target.
This creates a PVL flat map from the definition pvl. All of the keywords in the map that are also in the source resource are added to the target resource.
source | A reference to the resource to be copied from. |
target | A reference to the resource to be added to. |
References Isis::PvlFlatMap::allValues(), and getDefinitionMap().
|
protected |
Splits the given keyspec string into a list using the given delimiter string.
keyspec | The string to be split. |
delimiter | A string containing the characters used to specify the boundary by which to split the string. |
|
staticprotected |
Important GEOS query callback for class and overlap geometry.
This method accumulates the resources that are determined to potentially overlap the resource geometry provided in the GEOS query.
This implementation may not be portable or safe. It most certainly is not threadable. (I am open for suggestions on how to do this better...)
item | Resource to add to overlap list |
userdata | ResourceList to contain overlapping geoemetries |
Referenced by applyToIntersectedGeometry().
|
protected |
Resets the total number of processed resources to zero.
Referenced by initProgress().
|
protected |
Performs a case insensitive scan of the input string for a substring matching the target string and replaces the target substring with the replacement string.
input | The input string to be modified. |
target | The string pattern to find in the input string. |
replacement | The string pattern that will replace the target string pattern. |
Referenced by processArgs().
|
protected |
Sets Resource as discarded.
This mutator tells the object to not apply strategy algorithms to discarded resources.
|
protected |
Disables the general application of Strategy algorithm for all Resources regardless of state.
|
protected |
Allow derived strategies to reset name (mostly for default constructors)
A | string containing the new name of the strategy. |
References name().
|
protected |
Allow derived strategies to reset type (mostly for default constructors)
A | string containing the new type of the strategy. |
References type().
unsigned int Isis::Strategy::totalProcessed | ( | ) | const |
Accessor for the total number of resources processed.
|
protected |
Translates the arguments of the PVL keyword in the PVL definition object.
This method uses the keyBase string to get the keyword value and populate the argument replacement list. The keyword value is then modified by passing it to processArgs() along with using the argument list, resource, and default resource pointers.
If a keyword does not exist, the string provided by defValue is returned. The empty string is returned in the event that defValue is not given an argument.
keyBase | A string containing the base of the keyword name. |
globals | A list of resources that will be searched. |
defValue | The default value to return if the keyBase does not exist |
References Isis::PvlFlatMap::allValues(), Isis::PvlFlatMap::exists(), Isis::PvlFlatMap::get(), getDefinitionMap(), and processArgs().
Referenced by importGeometry(), and LoadMinerStrategies().
QString Isis::Strategy::type | ( | ) | const |
Accessor method to get the type of strategy.
Referenced by applyToIntersectedGeometry(), description(), importGeometry(), initProgress(), and setType().