OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimSrcRecord.cpp
Go to the documentation of this file.
1 //*************************************************************************************************
2 // OSSIM -- Open Source Software Image Map
3 //
4 // LICENSE: See top level LICENSE.txt file.
5 // AUTHOR: Oscar Kramer
6 //
7 // CLASS DESCRIPTION:
10 //*************************************************************************************************
11 // $Id$
12 
15 #include <ossim/base/ossimNotify.h>
16 
17 //*************************************************************************************************
18 // Default constructor
19 //*************************************************************************************************
21 : m_entryIndex(-1),
22  m_weight(0.0),
23  m_isVectorData(false),
24  m_isRgbData(false)
25 {}
26 
27 //*************************************************************************************************
28 // Constructs given an in-memory KWL and entry index.
29 //*************************************************************************************************
31 : m_entryIndex(-1),
32  m_weight(0.0),
33  m_isVectorData(false),
34  m_isRgbData(false)
35 {
36  prefix_str += ossimString::toString(index) + ".";
37  const char* prefix = prefix_str.chars();
38 
39  loadState(src_kwl, prefix);
40 }
41 
42 //*************************************************************************************************
43 // METHOD
44 //*************************************************************************************************
45 bool ossimSrcRecord::loadState(const ossimKeywordlist& kwl, const char* prefix)
46 {
47  // Read image filename entry (required):
48  m_rgbFilenames.clear();
49  m_rgbHistogramPaths.clear();
50  m_rgbHistogramOps.clear();
51  m_rgbOverviewPaths.clear();
52  ossimString lookup = kwl.find(prefix, "r");
53  if (!lookup.empty())
54  {
55  m_filename = lookup;
56  m_isRgbData = true;
57  m_rgbFilenames.push_back(lookup);
58 
59  lookup = kwl.find(prefix, "r.hist");
60  m_rgbHistogramPaths.push_back(lookup.downcase());
61 
62  lookup = kwl.find(prefix, "r.hist-op");
63  m_rgbHistogramOps.push_back(lookup.downcase());
64 
65  lookup = kwl.find(prefix, "r.ovr");
66  m_rgbOverviewPaths.push_back(lookup);
67 
68  lookup = kwl.find(prefix, "g");
69  m_rgbFilenames.push_back(lookup);
70 
71  lookup = kwl.find(prefix, "g.hist");
72  m_rgbHistogramPaths.push_back(lookup.downcase());
73 
74  lookup = kwl.find(prefix, "g.ovr");
75  m_rgbOverviewPaths.push_back(lookup);
76 
77  lookup = kwl.find(prefix, "g.hist-op");
78  m_rgbHistogramOps.push_back(lookup.downcase());
79 
80  lookup = kwl.find(prefix, "b");
81  m_rgbFilenames.push_back(lookup);
82 
83  lookup = kwl.find(prefix, "b.hist");
84  m_rgbHistogramPaths.push_back(lookup.downcase());
85 
86  lookup = kwl.find(prefix, "b.hist-op");
87  m_rgbHistogramOps.push_back(lookup.downcase());
88 
89  lookup = kwl.find(prefix, "b.ovr");
90  m_rgbOverviewPaths.push_back(lookup);
91 
92  return true;
93  }
94 
95  lookup = kwl.find(prefix, "file");
96  if (!lookup.empty())
97  {
98  m_filename = lookup;
100  }
101  else
102  {
103  m_filename.clear();
104  return false;
105  }
106 
107  // Read image entry index:
108  lookup = kwl.find(prefix, "entry");
109  if (!lookup.empty())
110  {
111  m_entryIndex = lookup.toInt32();
113  }
114  else
115  {
116  m_entryIndex = -1;
117  }
118 
119  // Establish supplementary directory containing overview:
120  lookup = kwl.find(prefix, "ovr");
121  if (!lookup.empty())
122  {
123  setOverview(ossimFilename(lookup));
124  }
125  else
126  {
128  }
129  lookup = kwl.find(prefix, "geom");
130  if (!lookup.empty())
131  {
132  setGeom(ossimFilename(lookup));
133  }
134  else
135  {
136  m_geomPath.clear();
137  }
138 
139  lookup = kwl.find(prefix, "mask");
140  if (!lookup.empty())
141  {
142  m_maskPath = ossimFilename(lookup);
143  }
144  else
145  {
146  m_maskPath.clear();
147  }
148 
149  // Histogram operation for this image:
150  lookup = kwl.find(prefix, "hist");
151  if (!lookup.empty())
152  {
153  m_histogramPath = lookup.downcase();
154  }
155  else
156  {
158  }
159 
160  // Histogram operation for this image:
161  lookup = kwl.find(prefix, "hist-op");
162  if (!lookup.empty())
163  {
164  m_histogramOp = lookup.downcase();
165  }
166  else
167  {
169  }
170 
171  // Newer more generic spec of supp dir since more than just ovrs may reside there:
172  lookup = kwl.find(prefix, "support");
173  if (!lookup.empty())
174  {
175  setSupportDir(lookup);
176  }
177  else
178  {
180  }
181 
182  // Establish selected bands:
183  lookup = kwl.find(prefix, "rgb");
184  if (!lookup.empty())
185  {
186  m_bandList.clear();
187 
188  //---
189  // Multiple bands delimited by comma:
190  //
191  // NOTE: Keyword list ONE based.
192  // ossimBandSelector list ZERO based.
193  //---
194  std::vector<ossimString> bandsStr = lookup.split(",");
195  for (ossim_uint32 i = 0; i < bandsStr.size(); i++)
196  {
197  int band = bandsStr[i].toInt32() - 1;
198  if (band >= 0) m_bandList.push_back((ossim_uint32) band);
199  }
200  }
201  else
202  {
203  m_bandList.clear();
204  }
205 
206  lookup = kwl.find(prefix, "opacity");
207  if (!lookup.empty())
208  m_weight = lookup.toDouble();
209 
210  // Look for vector data info:
211  m_isVectorData = false;
212  ossimString vector_prefix (prefix);
213  vector_prefix += "vector.";
214  ossimKeywordlist vectorKwl;
215 
216 #define DIRECT_KW_MAPPING false
217  if (DIRECT_KW_MAPPING)
218  {
219  // This method of stuffing the attributes KWL is presented here as an example of the way we
220  // should do it:
221  m_attributesKwl.add(kwl, vector_prefix.chars());
222  }
223  else
224  {
225  // Need to translate SRC keywords to KWs expected by OSSIM:
226  lookup = kwl.find(vector_prefix, "line.color");
227  if (!lookup.empty())
228  vectorKwl.add(ossimKeywordNames::PEN_COLOR_KW, lookup);
229  lookup = kwl.find(vector_prefix, "line.width");
230  if (!lookup.empty())
231  vectorKwl.add(ossimKeywordNames::THICKNESS_KW, lookup);
232  lookup = kwl.find(vector_prefix, "fill.color");
233  if (!lookup.empty())
234  {
235  vectorKwl.add(ossimKeywordNames::FILL_FLAG_KW, true);
236  vectorKwl.add(ossimKeywordNames::BRUSH_COLOR_KW, lookup);
237  }
238  lookup = kwl.find(vector_prefix, "query");
239  if (!lookup.empty())
240  vectorKwl.add(ossimKeywordNames::QUERY_KW, lookup);
241  }
242 
243  if (vectorKwl.getSize())
244  {
245  m_isVectorData = true;
246  m_attributesKwl.add(0, vectorKwl);
247  }
248 
249  // Read keywords associated with special pixel remapping (pixel flipping, clamping, and
250  // clipping):
251  lookup = kwl.find(prefix, "replacement_mode");
252  if (!lookup.empty())
254  lookup = kwl.find(prefix, "clamp.min");
255  if (!lookup.empty())
257  lookup = kwl.find(prefix, "clamp.max");
258  if (!lookup.empty())
260  lookup = kwl.find(prefix, "clip.min");
261  if (!lookup.empty())
263  lookup = kwl.find(prefix, "clip.max");
264  if (!lookup.empty())
266 
267  return true;
268 }
269 
270 //*************************************************************************************************
271 // Sets supplementary data files dir. If the OVR and/or hist dirs are undefined, they are also
272 // set to this path.
273 //*************************************************************************************************
275 {
276  m_supportDir = f;
277  m_attributesKwl.add("supplementary_directory", f.c_str());
278  // if (m_overviewPath.empty())
279  // setOverview(m_supportDir);
280  if (m_histogramPath.empty())
282  if (m_maskPath.empty())
284  // if(m_geomPath.empty())
285  // m_geomPath = m_supportDir;
286 }
287 
288 //*************************************************************************************************
289 // METHOD
290 //*************************************************************************************************
292 {
293  m_filename = f;
295 }
296 
297 //*************************************************************************************************
298 // METHOD
299 //*************************************************************************************************
301 {
302  m_entryIndex = i;
304 }
305 
306 //*************************************************************************************************
307 // METHOD
308 //*************************************************************************************************
310 {
311  m_overviewPath = f;
313 }
314 //*************************************************************************************************
315 // METHOD
316 //*************************************************************************************************
318 {
319  m_geomPath = f;
321 }
322 
void clear()
Erases the entire container.
Definition: ossimString.h:432
static const char * OVERVIEW_FILE_KW
bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Initializes record from an in-memory KWL and prefix.
void setOverview(const ossimFilename &f)
ossimSrcRecord()
Class used for parsing the command line *.src files.
static const char * BRUSH_COLOR_KW
Represents serializable keyword/value map.
const char * find(const char *key) const
std::vector< ossimString > m_rgbOverviewPaths
static ossimString toString(bool aValue)
Numeric to string methods.
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
ossimFilename m_supportDir
ossimFilename m_overviewPath
The following data members are usually just a copy of m_supportDir, but are provided in order to supp...
ossimFilename m_maskPath
ossim_int32 toInt32() const
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
ossimKeywordlist m_attributesKwl
std::vector< ossimString > m_rgbHistogramPaths
void setEntryIndex(ossim_int32 i)
#define DIRECT_KW_MAPPING
void setFilename(const ossimFilename &f)
static const char * QUERY_KW
unsigned int ossim_uint32
static const char * FILL_FLAG_KW
const char * chars() const
For backward compatibility.
Definition: ossimString.h:77
double toDouble() const
ossimString m_histogramOp
std::vector< ossim_uint32 > m_bandList
std::vector< ossimString > m_rgbHistogramOps
static const char * GEOM_FILE_KW
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
ossimFilename m_histogramPath
ossimFilename m_filename
void setSupportDir(const ossimFilename &f)
Sets supplementary data files dir.
static const char * ENTRY_KW
PixelFlipParams m_pixelFlipParams
bool m_isVectorData
The following data members allow users to render vector data.
ossim_uint32 getSize() const
ossimFilename m_geomPath
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool empty() const
Definition: ossimString.h:411
std::vector< ossimString > m_rgbFilenames
static const char * PEN_COLOR_KW
ossim_int32 m_entryIndex
void setGeom(const ossimFilename &f)
static const char * FILENAME_KW
static const char * THICKNESS_KW
int ossim_int32