VR-Forces 4.8 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtTextureAtlasIndexParser.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2019 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvCore/vrvCore.h>
15 
16 #include <boost/unordered_map.hpp>
17 #include <boost/thread.hpp>
18 #include <string>
19 
20 namespace makVrv
21 {
24  {
25  public:
28  struct AtlasResult
29  {
30  std::string annotation;
31  float uOffset;
32  float vOffset;
33  };
34 
38 
41  std::string myText;
42  float myValue;
43  StringOrFloatAttrib(const std::string& name) : myText(name), myValue(0) { ; }
44  StringOrFloatAttrib(const std::string& name, float value) : myText(name), myValue(value) { ; }
45  };
48  typedef std::pair<std::string, StringOrFloatAttrib> AttrValuePair;
49 
53  typedef std::vector<AttrValuePair> AttrValuePairVec;
54 
56  virtual ~DtTextureAtlasIndexParser();
57 
61  bool parseAtlasIfNecessary(const std::string& inputFile);
62 
65  bool retrieveTextureAtlasUV(const std::string& annotation,
66  const AttrValuePairVec& searchStringPairs,
67  float& u, float& v);
68 
71  bool retrieveTextureAtlasUV(const AttrValuePairVec & categoryValuePairs,
72  std::vector<AtlasResult>& results);
73 
75  bool hasSeen(const std::string& fileName);
76 
78  void setCurrentFile(const std::string& fileName);
79 
81  const std::string& currentFile() const;
82 
85  void setDefaultUV(float u, float v);
86 
88  void defaultUV(float& u, float& v);
89 
93  void setDefaultAttribute(const std::string& annotation);
94 
97  const std::string& defaultAttribute() const;
98 
102  void setDefaultValue(const std::string& value);
103 
106  const std::string& defaultValue() const;
107 
109  DtDe& de() { return myDe; }
110 
111  protected:
112 
115 
116  protected:
117  // valueUVMap["texture"] => { ("COLOUR", "Red"), .. ("U", "0.3"), ("V", "0.2") }
118  typedef boost::unordered_multimap<std::string, AttrValuePairVec > AnnotVecMap;
119  typedef boost::unordered_multimap<std::string, AttrValuePairVec >::iterator AnnotVecMapItr;
120 
121  // valueUVMap = FileMap["$(DATA)/objects/buoys/pillarBuoy.dtxc"]
122  typedef boost::unordered_map<std::string, AnnotVecMap> FileMap;
123  typedef boost::unordered_map<std::string, AnnotVecMap>::iterator FileMapItr;
124 
125  // For categories
126  typedef std::set<std::string> AttributeSet;
127  // Annotation -> categories ex. ( "COLOUR", "COLPAT", ... )
128  typedef boost::unordered_map<std::string, AttributeSet> AnnotAttrMap;
129  typedef boost::unordered_map<std::string, AnnotAttrMap> AttrMap;
130 
131  // map[file][annotation] = { ("COLOUR", "Red"), .. ("U", "0.3"), ("V", "0.2") }
133 
134  // map[file][annotation1] = { COLOUR, COLPAT, CATSPM }
135  // map[file][annotation2] = { CATSPM, TOPSHP }
137 
138  std::string myCurrentAtlasIndex;
139 
140  // If we can't find anything, provide a global default
141  float myDefaultU;
142  float myDefaultV;
143 
144  // If we can't find our pair, look for DEFAULT, default
145  std::string myDefaultAnnotation;
146  std::string myDefaultValue;
147 
148  boost::mutex myDataMutex;
150  };
151 
154  return lhs.myText == rhs.myText;
155  }
156 
157 
161  {
162 
163  public:
165  static DtTextureAtlasIndexParserCreator& instance( DtDe& de );
166 
168  static void registerInstance( DtDe& de, DtTextureAtlasIndexParserCreator* anInstance );
169 
171  virtual DtTextureAtlasIndexParser* create(DtDe& de);
172  };
173 
174 }
Virtual base class.
Definition: DtVirtualBaseClass.h:22
StringOrFloatAttrib(const std::string &name)
Definition: DtTextureAtlasIndexParser.h:43
boost::unordered_multimap< std::string, AttrValuePairVec > AnnotVecMap
Definition: DtTextureAtlasIndexParser.h:118
float vOffset
Definition: DtTextureAtlasIndexParser.h:32
boost::unordered_map< std::string, AnnotVecMap >::iterator FileMapItr
Definition: DtTextureAtlasIndexParser.h:123
std::string myDefaultAnnotation
Definition: DtTextureAtlasIndexParser.h:145
2 dimensional vector
boost::unordered_map< std::string, AnnotAttrMap > AttrMap
Definition: DtTextureAtlasIndexParser.h:129
Results for setting UV offsets ex.
Definition: DtTextureAtlasIndexParser.h:28
std::string myText
Definition: DtTextureAtlasIndexParser.h:41
Definition: DtTextureAtlasIndexParser.h:23
std::vector< AttrValuePair > AttrValuePairVec
Typedef for a vector of S-57 attribute/value pairs and a UV coord ex.
Definition: DtTextureAtlasIndexParser.h:53
std::string annotation
Definition: DtTextureAtlasIndexParser.h:30
std::set< std::string > AttributeSet
Definition: DtTextureAtlasIndexParser.h:126
std::string myCurrentAtlasIndex
Definition: DtTextureAtlasIndexParser.h:138
float uOffset
Definition: DtTextureAtlasIndexParser.h:31
StringOrFloatAttrib(const std::string &name, float value)
Definition: DtTextureAtlasIndexParser.h:44
Contains makVrv::DtVirtualBaseClass class.
#define DT_DLL_VRVCORE
Definition: vrvCore.h:20
struct for capturing the floating point value to avoid parsing constantly.
Definition: DtTextureAtlasIndexParser.h:40
FileMap myFileAttrValueUVMap
Definition: DtTextureAtlasIndexParser.h:132
boost::unordered_map< std::string, AnnotVecMap > FileMap
Definition: DtTextureAtlasIndexParser.h:122
DtTextureAtlasIndexParser creator.
Definition: DtTextureAtlasIndexParser.h:160
AttrMap myAttributeOnlyMap
Definition: DtTextureAtlasIndexParser.h:136
boost::unordered_multimap< std::string, AttrValuePairVec >::iterator AnnotVecMapItr
Definition: DtTextureAtlasIndexParser.h:119
float myDefaultU
Definition: DtTextureAtlasIndexParser.h:141
DtDe & myDe
Definition: DtTextureAtlasIndexParser.h:149
boost::unordered_map< std::string, AttributeSet > AnnotAttrMap
Definition: DtTextureAtlasIndexParser.h:128
boost::mutex myDataMutex
Definition: DtTextureAtlasIndexParser.h:148
bool operator==(const DtTextureAtlasIndexParser::StringOrFloatAttrib &lhs, const DtTextureAtlasIndexParser::StringOrFloatAttrib &rhs)
needed for search comparison code
Definition: DtTextureAtlasIndexParser.h:153
DtDe & de()
Retrieve the display engine.
Definition: DtTextureAtlasIndexParser.h:109
The DtDe is the core component of any VR-Vantage application.
Definition: DtDe.h:69
std::pair< std::string, StringOrFloatAttrib > AttrValuePair
Typedef for S-57 attribute/value pairs valuePair = (&quot;COLOUR&quot;, &quot;Red&quot;) = ( attribute, value )
Definition: DtTextureAtlasIndexParser.h:48
float myDefaultV
Definition: DtTextureAtlasIndexParser.h:142
std::string myDefaultValue
Definition: DtTextureAtlasIndexParser.h:146
float myValue
Definition: DtTextureAtlasIndexParser.h:42
Contains DLL export macros.

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)