OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimVpfAnnotationSource.cpp
Go to the documentation of this file.
1 #include <algorithm>
2 
11 
12 static ossimTrace traceDebug("ossimVpfAnnotationSource:debug");
13 
16 {
17  if(!m_geometry)
18  {
20  }
21  ossimMapProjection* mapProj = dynamic_cast<ossimMapProjection*>(m_geometry->getProjection());
22 
23  if(mapProj)
24  {
25  mapProj->setMetersPerPixel(ossimDpt(30, 30));
26  }
27 }
28 
30 {
31  close();
32 }
33 
35 {
36  if(traceDebug())
37  {
38  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimVpfAnnotationSource::open DEBUG: entering..." << std::endl;
39  }
40  bool result = false;
41 
42  if(file.file().downcase() == "dht")
43  {
44  if(openDatabase(file))
45  {
46  vector<ossimString> libraryNames = theDatabase.getLibraryNames();
47  if(traceDebug())
48  {
49  ossimNotify(ossimNotifyLevel_DEBUG) << "Library names list size = " << libraryNames.size() << std::endl;
50  }
51 
52  for(int idx = 0; idx < (int)libraryNames.size();++idx)
53  {
55  info->setName(libraryNames[idx]);
56  theLibraryInfo.push_back(info);
57  info->setDatabase(&theDatabase);
58  if(traceDebug())
59  {
60  ossimNotify(ossimNotifyLevel_DEBUG) << "loading library " << libraryNames[idx] << std::endl;
61  }
62  info->buildLibrary();
64  }
66  result = true;
67  }
68  }
69  if(traceDebug())
70  {
71  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimVpfAnnotationSource::open DEBUG: leaving..." << std::endl;
72  }
73  return result;
74 }
75 
77 {
79  for(int idx = 0; idx < (int)theLibraryInfo.size(); ++idx)
80  {
81  delete theLibraryInfo[idx];
82  }
83 
84  theLibraryInfo.clear();
85 }
86 
88 {
89  return theFilename;
90 }
91 
93 {
94  if(traceDebug())
95  {
96  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimVpfAnnotationSource::transformObjects DEBUG: entered..." << std::endl;
97  }
98  ossimImageGeometry* tempGeom = geom;
99 
100  if(!tempGeom)
101  {
102  tempGeom = m_geometry.get();
103  }
104 
105  if(!tempGeom) return;
106  for(int idx = 0; idx < (int)theLibraryInfo.size(); ++idx)
107  {
108  theLibraryInfo[idx]->transform(tempGeom);
109  }
111  if(traceDebug())
112  {
113  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimVpfAnnotationSource::transformObjects DEBUG: leaving..." << std::endl;
114  }
115 }
116 
118 
119 {
120  ossimIrect result;
121  result.makeNan();
122  for(int i = 0; i < (int)theLibraryInfo.size();++i)
123  {
124  ossimIrect tempRect = theLibraryInfo[i]->getBoundingProjectedRect();
125  if(!tempRect.hasNans())
126  {
127  if(result.hasNans())
128  {
129  result = tempRect;
130  }
131  else
132  {
133  result = result.combine(tempRect);
134  }
135  }
136  }
137 
138  theRectangle = result;
139 }
140 
141 
143 {
144  for(int idx = 0; idx < (int)theLibraryInfo.size();++idx)
145  {
146  delete theLibraryInfo[idx];
147  }
148 
149  theLibraryInfo.clear();
150 }
151 
152 void ossimVpfAnnotationSource::getAllFeatures(std::vector<ossimVpfAnnotationFeatureInfo*>& features)
153 {
154  features = theFeatureList;
155 }
156 
157 void ossimVpfAnnotationSource::setAllFeatures(const std::vector<ossimVpfAnnotationFeatureInfo*>& features)
158 {
159  theFeatureList = features;
160 
162 
163 }
164 
165 
167 {
169  if(theImage->getImageData().valid())
170  {
171  for(ossim_uint32 idx = 0; idx < theFeatureList.size();++idx)
172  {
173  if(theFeatureList[idx]->getEnabledFlag())
174  {
175  theFeatureList[idx]->drawAnnotations(theImage.get());
176  }
177  }
178  }
179 }
180 
182 {
185  theFeatureList.clear();
186  if(theDatabase.isOpened())
187  {
189  }
190 
191  theFilename = file;
192  return theDatabase.openDatabase(file);
193 }
194 
195 
197  const char* prefix)const
198 {
199  kwl.add(prefix,
201  theFilename,
202  true);
203  for(ossim_uint32 idx = 0; idx < theLibraryInfo.size(); ++idx)
204  {
205  theLibraryInfo[idx]->saveState(kwl,
206  (ossimString(prefix) + "library" + ossimString::toString(idx) + ".").c_str());
207  }
208  return true;
209 }
210 
212  const char* prefix)
213 {
214  bool result = false;
216  const char* filename = kwl.find(prefix, ossimKeywordNames::FILENAME_KW);
217  if(filename)
218  {
219  if(openDatabase(filename))
220  {
221  int idx = 0;
222  ossimString regExpression = ossimString("^(") + ossimString(prefix) + "library[0-9]+.)";
223  vector<ossimString> keys =
224  kwl.getSubstringKeyList( regExpression );
225  std::vector<int> theNumberList(keys.size());
226  int offset = (int)(ossimString(prefix)+"library").size();
227 
228  for(idx = 0; idx < (int)theNumberList.size();++idx)
229  {
230  ossimString numberStr(keys[idx].begin() + offset,
231  keys[idx].end());
232  theNumberList[idx] = numberStr.toInt();
233  }
234  std::sort(theNumberList.begin(), theNumberList.end());
235 
236  for(idx=0;idx < (int)keys.size();++idx)
237  {
238  ossimString newPrefix = ossimString(prefix);
239  newPrefix += ossimString("library");
240  newPrefix += ossimString::toString(theNumberList[idx]);
241  newPrefix += ossimString(".");
242 
244  theLibraryInfo.push_back(info);
245  info->setDatabase(&theDatabase);
246  info->loadState(kwl,
247  newPrefix);
249  }
251  result = true;
252  }
253  }
254 
255  return result;
256 }
257 
259 {
260  return open(theFilename);
261 }
262 
264 {
265  return (theDatabase.isOpened());
266 }
std::vector< ossimVpfAnnotationLibraryInfo * > theLibraryInfo
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
virtual void setAllFeatures(const std::vector< ossimVpfAnnotationFeatureInfo *> &features)
static ossimString toString(bool aValue)
Numeric to string methods.
virtual void transformObjects(ossimImageGeometry *geom=0)
virtual bool openDatabase(const ossimFilename &filename)
ossimRefPtr< ossimImageGeometry > m_geometry
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=NULL) const
Saves the current state of this object.
virtual void getAllFeatures(std::vector< ossimVpfAnnotationFeatureInfo *> &features)
bool openDatabase(const ossimFilename &file)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=NULL)
Method to the load (recreate) the state of an object from a keyword list.
virtual void setMetersPerPixel(const ossimDpt &gsd)
void getAllFeatures(std::vector< ossimVpfAnnotationFeatureInfo *> &features)
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
yy_size_t size
ossimRefPtr< ossimImageData > getImageData()
Will return the image data.
unsigned int ossim_uint32
vector< ossimString > getLibraryNames() const
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
virtual ossimFilename getFilename() const
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
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
void makeNan()
Definition: ossimIrect.h:329
ossimRefPtr< ossimRgbImage > theImage
virtual void drawAnnotations(ossimRefPtr< ossimImageData > tile)
bool hasNans() const
Definition: ossimIrect.h:337
ossimFilename file() const
void setDatabase(ossimVpfDatabase *database)
void setCurrentImageData(ossimRefPtr< ossimImageData > &imageData)
Allows you to change the image data that this RgbImage object operates on.
static const char * FILENAME_KW
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)
std::vector< ossimVpfAnnotationFeatureInfo * > theFeatureList
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)