27 #include <QScopedPointer> 29 #include <QStringList> 32 #include <boost/foreach.hpp> 50 Strategy::Strategy() : m_globals(), m_definition(new
PvlObject(
"Strategy")),
51 m_name(
"Strategy"), m_type(
"Counter"),
52 m_total(0), m_applyDiscarded(false), m_debug(false),
67 m_name(name), m_type(type), m_total(0),
68 m_applyDiscarded(false), m_debug(false), m_progress() {
94 m_globals(globals), m_definition(new
PvlObject(definition)),
95 m_name(
"Strategy"), m_type(
"Unknown"),
96 m_total(0), m_applyDiscarded(false), m_debug(false), m_progress() {
180 v_globals.append(myGlobals);
183 v_globals.push_back(myGlobals);
184 v_globals.append(globals);
186 return ( v_globals );
190 const PvlObject &Strategy::getDefinition()
const {
223 QString descr =
"Strategy::" +
name() +
" is running a " +
type() +
300 cout <<
"Empty apply is called...\n";
360 if ( resource->isDiscarded() ) {
362 result +=
apply(resource, globals);
367 result +=
apply(resource, globals);
426 if ( resource->isDiscarded() ) { n++; }
442 const QString &name)
const {
444 if ( resource->hasAsset(
name) ) {
445 QVariant v_asset = resource->asset(
name);
470 const QString &defValue)
const {
472 if ( keystore->exists(target) ) {
473 if ( keystore->count(target) > index ) {
474 return (keystore->value(target, index));
495 const QString &delimiter)
const {
514 const QString &replacement)
const {
516 str.replace(target, replacement, Qt::CaseInsensitive);
541 const QString &defValue)
const {
549 QString keyword = keyBase +
"Keyword";
550 if ( keys.
exists(keyword) ) {
551 idArgs.push_back(keys.
get(keyword));
552 value = keys.
get(keyBase,
"%1");
555 if ( keys.
exists(keyBase +
"Args") ) {
556 idArgs = keys.
allValues(keyBase +
"Args");
558 value = keys.
get(keyBase, defValue);
561 return (
processArgs(value, idArgs, globals, defValue));
589 const QString &defValue)
const {
591 QString result = value;
592 int i = argKeys.size();
593 BOOST_REVERSE_FOREACH ( QString arg, argKeys ) {
594 QString target(
"%"+QString::number(i));
614 BOOST_FOREACH ( QString key, keySources ) {
615 if ( source->exists(key) ) {
616 target->add(source->keyword(key));
656 QString
id = resourceA->name() +
"_" + resourceB->name();
661 if ( !keySources.isEmpty() ) {
663 BOOST_FOREACH ( QString key, keySources ) {
664 if ( resourceA->exists(key) ) {
666 keyword.
setName(keyword.name().append(keySuffix.first));
670 if ( resourceB->exists(key) ) {
672 keyword.
setName(keyword.name().append(keySuffix.second));
681 while ( rkeysA.constEnd() != pkeys) {
683 keyword.
setName(keyword.name().append(keySuffix.first));
689 pkeys = rkeysB.begin();
690 while ( rkeysB.constEnd() != pkeys) {
692 keyword.
setName(keyword.name().append(keySuffix.second));
726 QString geom(keys.
get(
"GisGeometry",
""));
729 if ( keys.
exists(
"GisGeometryRef") ) { giskey = keys.
get(
"GisGeometryRef"); }
730 if ( keys.
exists(
"GisGeometryKey") ) { giskey = keys.
get(
"GisGeometryKey"); }
732 if ( !giskey.isEmpty() ) {
733 if ( !resource->isNull(giskey) ) {
734 geom = resource->value(giskey);
737 if (
toBool(keys.
get(
"RemoveGisKeywordAfterImport",
"false")) ) {
738 resource->erase(giskey);
744 if ( !geom.isEmpty() ) {
747 if ( keys.
exists(
"GisGeometryArgs") ) {
753 QString gisType = keys.
get(
"GisType");
756 double tolerance(0.0);
760 if ( !geom.isEmpty() ) {
763 if ( geosgeom.isNull() || !geosgeom->isValid() )
return (
false);
765 npointsOrg = npoints = geosgeom->points();
769 if ( !gisTolerance.isEmpty() ) {
772 if ( 0 != simple ) geosgeom.reset(simple);
773 npoints = geosgeom->
points();
776 resource->add(geosgeom.take());
782 if ( !pointsKey.isEmpty() ) {
783 resource->add(pointsKey,
toString(npoints));
784 resource->add(pointsKey+
"Original",
toString(npointsOrg));
785 resource->add(pointsKey+
"Tolerance",
toString(tolerance));
790 cout <<
" " <<
type() <<
":" <<
name() <<
" has a geometry with " 791 << npoints <<
" points!\n";
792 if ( npoints != npointsOrg ) {
793 cout <<
" Geometry has been simplified/reduced from original " 794 << npointsOrg <<
" points.\n";
803 cout <<
" " <<
type() <<
":" <<
name() <<
" does not have a geometry!\n";
821 if ( !resource->isDiscarded() ) { v_active.append(resource); }
834 resource->activate();
900 const bool &withAssets)
const {
903 v_clone.append(
SharedResource(resource->clone(resource->name(), withAssets)));
955 QString mess =
type() +
":" +
name() +
956 "Cannot apply RTree search to bad geometry.";
965 if (
"direct" == method ) {
967 cout <<
"Using direct Geom intersects for " << v_active.size() <<
" geometries...\n";
974 if ( resource->hasValidGeometry() ) {
975 if ( geom.
intersects( *resource->geometry()) ) {
976 overlaps.append(resource);
986 cout <<
"Allocating " << v_active.size() <<
" RTree geometries.\n";
988 GEOSSTRtree *rtree = GEOSSTRtree_create(v_active.size());
990 QString mess =
"GEOS RTree allocation failed for " +
991 toString(v_active.size()) +
" geometries.";
996 cout <<
"GEOS RTree allocated " << v_active.size() <<
" geometry entries.\n";
1003 for (
int i = 0 ; i < v_active.size() ; i++ ) {
1004 if ( v_active[i]->hasValidGeometry() ) {
1005 GEOSSTRtree_insert(rtree, v_active[i]->geometry()->geometry(),
1014 cout <<
"Valid Geometries found: " << nvalid <<
" - running query...\n";
1019 GEOSSTRtree_destroy(rtree);
1023 cout <<
"Potential Intersections Found: " << overlaps.size() <<
"\n";
1038 resource->activate();
1039 n +=
apply(resource, globals);
1045 cout <<
"Total valid Intersections Found: " << n <<
"\n";
1069 rlist->append(*resource);
1120 QString p_text = text;
1122 bool status =
false;
1127 if (
toBool(p_var.
get(
"ShowProgress",
"false")) ) {
1129 if ( p_text.isEmpty() ) {
1138 if ( !p_text.isEmpty() )
m_progress->SetText(p_text);
1151 PvlObject::ConstPvlObjectIterator
object = source.
beginObject();
1152 while (
object != source.
endObject() ) {
1153 objList <<
object->name();
bool initProgress(const int &nsteps=0, const QString &text="")
Initializes strategy progress monitor if requested by user.
bool m_debug
Indicates whether to print debug messages.
int apply(ResourceList &resources)
Apply algorithm to resource list.
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 r...
QString findReplacement(const QString &target, const ResourceList &globals, const int &index=0, const QString &defValue="") const
Find keyword replacement value in globals list.
QMap< QString, PvlKeyword >::const_iterator ConstPvlFlatMapIterator
A const iterator for the underling QMap that PvlFlatMap is built on.
GisGeometry * simplify(const double &tolerance) const
Simplify complex or overdetermined geoemtry.
static void queryCallback(void *item, void *userdata)
Important GEOS query callback for class and overlap geometry.
PvlObjectIterator endObject()
Returns the index of the ending object.
QString m_type
A string containing the type of strategy.
ResourceList cloneList(const ResourceList &resources, const bool &withAssets=false) const
Create a clone of a Resource list.
int countDiscarded(const ResourceList &resources) const
Counts the number of non-active (i.e.
QString description() const
Return description for the strategy.
void setApplyToDiscarded()
Sets Resource as discarded.
virtual ~Strategy()
Destroys the Strategy object.
void setName(const QString &name)
Allow derived strategies to reset name (mostly for default constructors)
QStringList qualifiers(const QString &keyspec, const QString &delimiter="::") const
Splits the given keyspec string into a list using the given delimiter string.
ResourceList m_globals
A shared pointer to the global Resource of keywords.
bool doShowProgress() const
void setName(QString name)
Sets the keyword name.
bool intersects(const GisGeometry &target) const
Computes a new geometry from the intersection of the two geomtries.
Namespace for the standard library.
bool exists(const QString &key) const
Determines whether a given keyword exists in the PvlFlatMap.
SharedPvlObject m_definition
A shared pointer to the PvlObject that defines the strategy.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
double toDouble(const QString &string)
Global function to convert from a string to a double.
This error is for when a programmer made an API call that was illegal.
unsigned int totalProcessed() const
Accessor for the total number of resources processed.
QScopedPointer< Progress > m_progress
Progress percentage monitor.
QStringList allValues(const QString &key) const
Gets all the values associated with a keyword in the PvlFlatMap.
void setType(const QString &type)
Allow derived strategies to reset type (mostly for default constructors)
QString name() const
Accessor method to get the name of the strategy.
bool isValid() const
Determines validity of the geometry contained in this object.
Program progress reporter.
ResourceList getGlobals(SharedResource &myGlobals, const ResourceList &globals) const
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.
QString get(const QString &key, const int &index=0) const
Gets the value of a keyword in the PvlFlatMap.
bool isDebug() const
An accessor method so that inherited classes can determine whether to print debug messages for this o...
Provides a flat map of PvlKeywords.
QString type() const
Accessor method to get the type of strategy.
void deactivateList(ResourceList &resources) const
Deactivate all resources contained in the resource list.
PvlFlatMap getDefinitionMap() const
Returns the keyword definitions found in the Strategy object.
This class provides a resource of PVL keywords for Strategy classes.
#define _FILEINFO_
Macro for the filename and line number.
bool m_applyDiscarded
Indicates whether to apply strategy to discarded resources.
int applyToIntersectedGeometry(ResourceList &resources, GisGeometry &geom, const ResourceList &globals)
Identify and apply Strategy to Resources that intersect a geometry.
bool isApplyToDiscarded() const
Accessor for the apply discarded variable.
ResourceList copyList(const ResourceList &resources) const
Make a copy of the resource list that is independently managed.
A single keyword-value pair.
int points() const
Get number of points in geometry.
void setDoNotApplyToDiscarded()
Disables the general application of Strategy algorithm for all Resources regardless of state...
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...
Strategy()
Constructs default Strategy object of name "Strategy" and type "Counter".
static PvlConstraints withExcludes(const QStringList &excludes)
Static method to construct a PvlConstraints object from a list of names for the PvlObjects and PvlGro...
void activateList(ResourceList &resources) const
Activate all resources contained in the resource list.
unsigned int processed()
Increments the total number of resources processed and returns the incremented value.
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...
ResourceList activeList(ResourceList &resources) const
Get list of all active Resources only - no discarded Resources.
QString translateKeywordArgs(const QString &value, const ResourceList &globals, const QString &defValue="") const
Translates the arguments of the PVL keyword in the PVL definition object.
void resetProcessed()
Resets the total number of processed resources to zero.
bool toBool(const QString &string)
Global function to convert from a string to a boolean.
Type type() const
Returns the type (origin) of the geometry.
void propagateKeys(SharedResource &source, SharedResource &target) const
Adds the PVL definition keywords from the source to the target.
QSharedPointer< Resource > SharedResource
Defintion of a SharedResource, a shared pointer to a Resource object.
Namespace for ISIS/Bullet specific routines.
const GEOSGeometry * geometry() const
Returns the GEOSGeometry object to extend functionality.
ResourceList getGlobalDefaults() const
Accessor method to get the global defaults.
unsigned int m_total
The total number of resources processed.
QString m_name
A string containing the name of the strategy.
Encapsulation class provides support for GEOS-C API.
Contains Pvl Groups and Pvl Objects.
PvlObjectIterator beginObject()
Returns the index of the beginning object.
int countActive(const ResourceList &resources) const
Counts the number of active (i.e.
int applyToResources(ResourceList &resources, const ResourceList &globals)
Applies the strategy algorithms to the resources in the given list.
bool importGeometry(SharedResource &resource, const ResourceList &globals) const
Imports a geometry from the given resource.