OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimVpfAnnotationLibraryInfo.cpp
Go to the documentation of this file.
1 //*************************************************************************
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Author: Garrett Potts
8 //
9 //**************************************************************************
10 // $Id: ossimVpfAnnotationLibraryInfo.cpp 15836 2009-10-30 12:29:09Z dburken $
11 
12 #include <algorithm>
13 
18 #include <ossim/base/ossimTrace.h>
19 
20 static ossimTrace traceDebug("ossimVpfAnnotationLibraryInfo:debug");
21 
22 
24  :
25  theName(libraryName),
26  theEnabledFlag(enabledFlag),
27  theDatabase(NULL)
28 {
29 }
30 
32 {
34 }
35 
37 {
38  return theEnabledFlag;
39 }
40 
42 {
43  theEnabledFlag = flag;
44 }
45 
47 {
48  return theName;
49 }
50 
52 {
53  theName = libraryName;
54 }
55 
57 {
58  theDatabase = database;
59 }
60 
62 {
63  return theDatabase;
64 }
65 
67 {
68  ossimIrect result;
69  result.makeNan();
70 
71  for(ossim_uint32 idx = 0; idx < theCoverageLayerList.size(); ++idx)
72  {
73  ossimIrect tempRect = theCoverageLayerList[idx]->getBoundingProjectedRect();
74  if(!tempRect.hasNans())
75  {
76  if(result.hasNans())
77  {
78  result = tempRect;
79  }
80  else
81  {
82  result = result.combine(tempRect);
83  }
84  }
85  }
86 
87  return result;
88 }
89 
90 void ossimVpfAnnotationLibraryInfo::getAllFeatures(std::vector<ossimVpfAnnotationFeatureInfo*>& features)
91 {
92  if(traceDebug())
93  {
94  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimVpfAnnotationLibraryInfo::getAllFeatures DEBUG: entered..." << std::endl;
95  }
96 
97  for(ossim_uint32 idx = 0; idx < theCoverageLayerList.size(); ++idx)
98  {
99  theCoverageLayerList[idx]->getAllFeatures(features);
100  }
101 
102  if(traceDebug())
103  {
104  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimVpfAnnotationLibraryInfo::getAllFeatures DEBUG: leaving..." << std::endl;
105  }
106 }
107 
109 {
110  if(traceDebug())
111  {
112  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimVpfAnnotationLibraryInfo::transform DEBUG: entered..." << std::endl;
113  }
114 
115 
116  for(ossim_uint32 idx = 0; idx < theCoverageLayerList.size(); ++idx)
117  {
118  if(traceDebug())
119  {
120  ossimNotify(ossimNotifyLevel_DEBUG) << "transforming coverage = " << theCoverageLayerList[idx]->getName() << std::endl;
121  }
122 
123  theCoverageLayerList[idx]->transform(geom);
124  }
125 
126  if(traceDebug())
127  {
128  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimVpfAnnotationLibraryInfo::transform DEBUG: leaving..." << std::endl;
129  }
130 }
131 
133 {
134  buildLibrary( "", "");
135 }
136 
137 void ossimVpfAnnotationLibraryInfo::buildLibrary(const ossimString& coverageName, const ossimString& feature)
138 {
139  if(traceDebug())
140  {
141  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimVpfAnnotationLibraryInfo::buildLibrary DEBUG: entered..." << std::endl;
142  }
144  if(!theDatabase)
145  {
146  return;
147  }
148 
150  if(library)
151  {
152  std::vector<ossimString> coverageNames;
153  library->getCoverageNames(coverageNames);
154  for(ossim_uint32 idx = 0; idx < coverageNames.size(); ++idx)
155  {
156  ossimString s1 = coverageName;
157  ossimString s2 = coverageNames[idx];
158  s1.downcase();
159  s2.downcase();
160  if ( ! coverageName.length() || (s1 == s2) )
161  {
162  ossimVpfAnnotationCoverageInfo* coverageInfo =
164  coverageInfo->setName(coverageNames[idx]);
165  coverageInfo->setLibrary(library);
166  theCoverageLayerList.push_back(coverageInfo);
167  if(traceDebug())
168  {
169  ossimNotify(ossimNotifyLevel_DEBUG) << "coverage name = " << coverageNames[idx] << std::endl;
170  }
171  coverageInfo->buildCoverage(feature);
172  }
173  }
174  }
175  if(traceDebug())
176  {
177  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimVpfAnnotationLibraryInfo::buildLibrary DEBUG: leaving..." << std::endl;
178  }
179 }
180 
181 
183 {
184  for(ossim_uint32 idx = 0; idx < theCoverageLayerList.size(); ++idx)
185  {
186  theCoverageLayerList[idx]->drawAnnotations(tile);
187  }
188 }
189 
191 {
192  for(ossim_uint32 idx = 0; idx < theCoverageLayerList.size(); ++idx)
193  {
194  delete theCoverageLayerList[idx];
195  }
196 
197  theCoverageLayerList.clear();
198 }
199 
201  const char* prefix)const
202 {
203  ossim_uint32 idx;
204 
205  kwl.add(prefix,
206  "name",
207  theName,
208  true);
209 
210  for(idx = 0; idx < theCoverageLayerList.size(); ++idx)
211  {
212  theCoverageLayerList[idx]->saveState(kwl,
213  (ossimString(prefix) + "coverage" + ossimString::toString(idx) + ".").c_str());
214  }
215 
216  return true;
217 }
218 
220  const char* prefix)
221 {
223  theName = kwl.find(prefix, "name");
224 
226 
227  if(!library)
228  {
229  return false;
230  }
231  ossimString regExpression = ossimString("^(") + ossimString(prefix) + "coverage[0-9]+.)";
232  vector<ossimString> keys =
233  kwl.getSubstringKeyList( regExpression );
234  std::vector<int> theNumberList(keys.size());
235  int offset = (int)(ossimString(prefix)+"coverage").size();
236  int idx = 0;
237  for(idx = 0; idx < (int)theNumberList.size();++idx)
238  {
239  ossimString numberStr(keys[idx].begin() + offset,
240  keys[idx].end());
241  theNumberList[idx] = numberStr.toInt();
242  }
243  std::sort(theNumberList.begin(), theNumberList.end());
244 
245  for(idx = 0; idx < (int)keys.size(); ++idx)
246  {
247  ossimString newPrefix = ossimString(prefix);
248  newPrefix += ossimString("coverage");
249  newPrefix += ossimString::toString(theNumberList[idx]);
250  newPrefix += ossimString(".");
252  coverageInfo->setLibrary(library);
253  theCoverageLayerList.push_back(coverageInfo);
254  coverageInfo->loadState(kwl,
255  newPrefix);
256  }
257 
258  return true;
259 }
void setLibrary(ossimVpfLibrary *library)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Represents serializable keyword/value map.
const char * find(const char *key) const
static ossimString toString(bool aValue)
Numeric to string methods.
void transform(ossimImageGeometry *geom)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
void getAllFeatures(std::vector< ossimVpfAnnotationFeatureInfo *> &features)
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
bool getCoverageNames(std::vector< ossimString > &coverageNames) const
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
std::vector< ossimString > getSubstringKeyList(const ossimString &regularExpression) const
ossimVpfAnnotationLibraryInfo(const ossimString &libraryName="", bool enabledFlag=true)
void makeNan()
Definition: ossimIrect.h:329
bool hasNans() const
Definition: ossimIrect.h:337
void setDatabase(ossimVpfDatabase *database)
std::vector< ossimVpfAnnotationCoverageInfo * > theCoverageLayerList
ossimIrect combine(const ossimIrect &rect) const
Definition: ossimIrect.cpp:543
int toInt() const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
void setName(const ossimString &libraryName)
ossimVpfLibrary * getLibrary(unsigned long libraryNumber)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)