OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimVpfAnnotationCoverageInfo.cpp
Go to the documentation of this file.
1 //*************************************************************************
2 // Copyright (C) 2004 Intelligence Data Systems, Inc. All rights reserved.
3 //
4 // License: LGPL
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: Garrett Potts
9 //
10 //**************************************************************************
11 // $Id: ossimVpfAnnotationCoverageInfo.cpp 15833 2009-10-29 01:41:53Z eshirschorn $
12 
13 #include <vector>
14 #include <algorithm>
18 
20 {
21  for(ossim_uint32 idx = 0; idx < theFeatureInfoArray.size();++idx)
22  {
23  if(theFeatureInfoArray[idx]->getEnabledFlag())
24  {
25  return true;
26  }
27  }
28 
29  return false;
30 }
31 
32 void ossimVpfAnnotationCoverageInfo::getEnabledFeatures(std::vector<ossimVpfAnnotationFeatureInfo*>& result)
33 {
34  for(ossim_uint32 idx = 0; idx < theFeatureInfoArray.size();++idx)
35  {
36  if(theFeatureInfoArray[idx]->getEnabledFlag())
37  {
38  result.push_back(theFeatureInfoArray[idx]);
39  }
40  }
41 }
42 
43 void ossimVpfAnnotationCoverageInfo::getAllFeatures(std::vector<ossimVpfAnnotationFeatureInfo*>& result)
44 {
45  for(ossim_uint32 idx = 0; idx < theFeatureInfoArray.size();++idx)
46  {
47  result.push_back(theFeatureInfoArray[idx]);
48  }
49 }
50 
52 {
53  ossimIrect result;
54  result.makeNan();
55 
56  for(ossim_uint32 idx = 0; idx < theFeatureInfoArray.size();++idx)
57  {
58  ossimIrect tempRect = theFeatureInfoArray[idx]->getBoundingProjectedRect();
59  if(!tempRect.hasNans())
60  {
61  if(result.hasNans())
62  {
63  result = tempRect;
64  }
65  else
66  {
67  result = result.combine(tempRect);
68  }
69  }
70  }
71 
72  return result;
73 }
74 
75 
77 {
78  for(ossim_uint32 idx = 0; idx < theFeatureInfoArray.size();++idx)
79  {
80  theFeatureInfoArray[idx]->transform(geom);
81  }
82 }
83 
85 {
86  buildCoverage( "" );
87 }
88 
90 {
92  if(theLibrary)
93  {
94  ossimVpfCoverage coverage;
95 
96  if(theLibrary->getCoverage(theName, coverage))
97  {
99  if(coverage.openFeatureClassSchema(schema))
100  {
101  std::vector<ossimString> featureClassArray;
102  schema.getFeatureClasses(featureClassArray);
103  schema.closeTable();
104  for(ossim_uint32 idx = 0; idx < featureClassArray.size(); ++idx)
105  {
106  ossimString s1 = feature;
107  ossimString s2 = featureClassArray[idx];
108  s1.downcase();
109  s2.downcase();
110  if (! feature.length() || (s1 == s2) )
111  {
112  ossimVpfAnnotationFeatureInfo* featureInfo =
114  featureInfo->setName(featureClassArray[idx]);
115  featureInfo->setCoverage(coverage);
116  theFeatureInfoArray.push_back(featureInfo);
117  featureInfo->buildFeature();
118  }
119  }
120  }
121  }
122  }
123 }
124 
126 {
127  for(ossim_uint32 idx = 0; idx < theFeatureInfoArray.size();++idx)
128  {
129  if(theFeatureInfoArray[idx]->getEnabledFlag())
130  {
131  theFeatureInfoArray[idx]->drawAnnotations(tile);
132  }
133  }
134 }
135 
137 {
138  for(ossim_uint32 idx = 0; idx < theFeatureInfoArray.size();++idx)
139  {
140  theFeatureInfoArray[idx];
141  }
142 
143  theFeatureInfoArray.clear();
144 }
145 
146 
147 
149  const char* prefix)const
150 {
151  kwl.add(prefix,
152  "name",
153  theName,
154  true);
155 
156  for(ossim_uint32 idx = 0; idx < theFeatureInfoArray.size(); ++idx)
157  {
158  theFeatureInfoArray[idx]->saveState(kwl,
159  (ossimString(prefix) + "feature" +
160  ossimString::toString(idx) + ".").c_str());
161  }
162 
163  return true;
164 }
165 
167  const char* prefix)
168 {
170 
171  if(!theLibrary)
172  {
173  return false;
174  }
175 
176  theName = kwl.find(prefix, "name");
177  ossimVpfCoverage coverage;
178 
179  if(theLibrary->getCoverage(theName, coverage))
180  {
181  ossimString regExpression = ossimString("^(") + ossimString(prefix) + "feature[0-9]+.)";
182  vector<ossimString> keys =
183  kwl.getSubstringKeyList( regExpression );
184  std::vector<int> theNumberList(keys.size());
185  int offset = (int)(ossimString(prefix)+"feature").size();
186  int idx = 0;
187  for(idx = 0; idx < (int)theNumberList.size();++idx)
188  {
189  ossimString numberStr(keys[idx].begin() + offset,
190  keys[idx].end());
191  theNumberList[idx] = numberStr.toInt();
192  }
193  std::sort(theNumberList.begin(), theNumberList.end());
194 
195  for(idx=0;idx < (int)keys.size();++idx)
196  {
197  ossimString newPrefix = ossimString(prefix);
198  newPrefix += ossimString("feature");
199  newPrefix += ossimString::toString(theNumberList[idx]);
200  newPrefix += ossimString(".");
202  featureInfo->setCoverage(coverage);
203  theFeatureInfoArray.push_back(featureInfo);
204  if(!featureInfo->loadState(kwl,
205  newPrefix))
206  {
207  return false;
208  }
209  }
210  }
211  else
212  {
213  return false;
214  }
215 
216  return true;
217 }
Represents serializable keyword/value map.
const char * find(const char *key) const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
static ossimString toString(bool aValue)
Numeric to string methods.
bool openFeatureClassSchema(ossimVpfFeatureClassSchema &schema)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
yy_size_t size
std::string::size_type length() const
Definition: ossimString.h:408
unsigned int ossim_uint32
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
void getAllFeatures(std::vector< ossimVpfAnnotationFeatureInfo *> &result)
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
std::vector< ossimVpfAnnotationFeatureInfo * > theFeatureInfoArray
bool getCoverage(long coverageNumber, ossimVpfCoverage &coverage)
std::vector< ossimString > getSubstringKeyList(const ossimString &regularExpression) const
void transform(ossimImageGeometry *geom)
void setCoverage(const ossimVpfCoverage &coverage)
void getEnabledFeatures(std::vector< ossimVpfAnnotationFeatureInfo *> &result)
void makeNan()
Definition: ossimIrect.h:329
bool hasNans() const
Definition: ossimIrect.h:337
void getFeatureClasses(std::vector< ossimString > &featureClassArray) const
ossimIrect combine(const ossimIrect &rect) const
Definition: ossimIrect.cpp:543
void setName(const ossimString &name)
int toInt() const