GeoTessCPPExamples  2.0
GeoTessModelExtended.h
Go to the documentation of this file.
1 //- ****************************************************************************
2 //-
3 //- Copyright 2009 Sandia Corporation. Under the terms of Contract
4 //- DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
5 //- retains certain rights in this software.
6 //-
7 //- BSD Open Source License.
8 //- All rights reserved.
9 //-
10 //- Redistribution and use in source and binary forms, with or without
11 //- modification, are permitted provided that the following conditions are met:
12 //-
13 //- * Redistributions of source code must retain the above copyright notice,
14 //- this list of conditions and the following disclaimer.
15 //- * Redistributions in binary form must reproduce the above copyright
16 //- notice, this list of conditions and the following disclaimer in the
17 //- documentation and/or other materials provided with the distribution.
18 //- * Neither the name of Sandia National Laboratories nor the names of its
19 //- contributors may be used to endorse or promote products derived from
20 //- this software without specific prior written permission.
21 //-
22 //- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 //- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 //- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 //- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 //- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 //- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 //- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 //- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 //- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 //- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 //- POSSIBILITY OF SUCH DAMAGE.
33 //-
34 //- ****************************************************************************
35 
36 #ifndef GEOTESSMODELEXTENDED_H_
37 #define GEOTESSMODELEXTENDED_H_
38 
39 // **** _SYSTEM INCLUDES_ ******************************************************
40 
41 #include <iostream>
42 #include <string>
43 #include <fstream>
44 
45 // use standard library objects
46 using namespace std;
47 
48 // **** _LOCAL INCLUDES_ *******************************************************
49 
50 #include "IFStreamAscii.h"
51 #include "IFStreamBinary.h"
52 
53 #include "GeoTessModel.h"
54 
55 // **** _BEGIN GEOTESS NAMESPACE_ **********************************************
56 
57 namespace geotess {
58 
59 // **** _FORWARD REFERENCES_ ***************************************************
60 
61 
62 // **** _CLASS DEFINITION_ *****************************************************
63 
64 /**
65  * This class is an example of a class that extends GeoTessModel.
66  * It does everything a GeoTessModel can do but adds an extra
67  * data item to the model. In this example, the extra data is
68  * just a simple string called 'extraData', but in real models
69  * that extend GeoTessModel, it could be anything.
70  *
71  * <p>Classes that extend GeoTessModel should provide
72  * implementations of all the GeoTessModel constructors with
73  * the first thing that they do is call the super class
74  * constructor. This example does this.
75  * <p>In addition, classes that extend GeoTessModel must
76  * override 4 IO functions:
77  * <ul>
78  * <li>loadModelBinary(). Call super class implementation and
79  * then load derived class data.
80  * <li>writeModelBinary(). Call super class implementation and
81  * then write derived class data.
82  * <li>loadModelAscii(). Call super class implementation and
83  * then load derived class data.
84  * <li>writeModelAscii(). Call super class implementation and
85  * then write derived class data.
86  * </ul>
87  * In addition to the 4 required IO functions, derived classes
88  * may want to implement these functions:
89  * <ul>
90  * <li>~. A destructor that deletes any resources allocated by
91  * the derived class.
92  * <li>initializeData(). Perform any initialization functions.
93  * Any resources allocated by a derived class should be deleted
94  * in the destructor.
95  * </ul>
96  * Finally, the derived class can implement any other functionality
97  * that is deemed appropriate. This simple example implements
98  * functions getExtraData() and setExtraData().Any resources
99  * allocated by the derived class should be deleted in its destructor.
100  * @author sballar
101  *
102  */
103 class GeoTessModelExtended : virtual public GeoTessModel
104 {
105 private:
106 
107  /**
108  * This string is just an example that represents whatever
109  * extra data the derived class might choose to implement.
110  */
111  string extraData;
112 
113  /**
114  * Initialize the extraData.
115  */
116  void initializeData() { extraData = "default value"; };
117 
118 protected:
119 
120  /**
121  * Override GeoTessModel::loadModelAscii().
122  * Applications don't call this protected method directly.
123  * It is call from GeoTessModel.loadModel().
124  *
125  * @param input ascii stream that provides input
126  * @param inputDirectory the directory where the model file resides
127  * @param relGridFilePath the relative path from the directory where
128  * the model file resides to the directory where the grid file resides.
129  * @throws GeoTessException
130  */
131  void loadModelAscii(IFStreamAscii& input, const string& inputDirectory,
132  const string& relGridFilePath);
133 
134  /**
135  * Override GeoTessModel::loadModelBinary()
136  * Applications don't call this protected method directly.
137  * It is call from GeoTessModel.loadModel().
138  *
139  * @param input binary stream that provides input
140  * @param inputDirectory the directory where the model file resides
141  * @param relGridFilePath the relative path from the directory where
142  * the model file resides to the directory where the grid file resides.
143  * @throws GeoTessException
144  */
145  void loadModelBinary(IFStreamBinary& input, const string& inputDirectory,
146  const string& relGridFilePath);
147 
148  /**
149  * Override GeoTessModel::writeModelAscii()
150  * Applications don't call this protected method directly.
151  * It is call from GeoTessModel.writeModel().
152  *
153  * @param output the output ascii stream to which model is written.
154  * @param gridFileName
155  *
156  */
157  void writeModelAscii(IFStreamAscii& output, const string& gridFileName);
158 
159  /**
160  * Override GeoTessModel::writeModelBinary()
161  * Applications don't call this protected method directly.
162  * It is call from GeoTessModel.writeModel().
163  *
164  * @param output the output ascii stream to which model is written.
165  * @param gridFileName
166  */
167  void writeModelBinary(IFStreamBinary& output, const string& gridFileName);
168 
169 
170 public:
171 
172  /**
173  * Returns the class name.
174  */
175  static string class_name() { return "GeoTessModelExtended"; };
176 
177  /**
178  * Default constructor.
179  *
180  */
182 
183  /**
184  * Construct a new GeoTessModel object and populate it with information from
185  * the specified file.
186  *
187  * @param modelInputFile
188  * name of file containing the model.
189  * @param relativeGridPath
190  * the relative path from the directory where the model is stored
191  * to the directory where the grid is stored. Often, the model
192  * and grid are stored together in the same file in which case
193  * this parameter is ignored. Sometimes, however, the grid is
194  * stored in a separate file and only the name of the grid file
195  * (without path information) is stored in the model file. In
196  * this case, the code needs to know which directory to search
197  * for the grid file. The default is "" (empty string), which
198  * will cause the code to search for the grid file in the same
199  * directory in which the model file resides. Bottom line is that
200  * the default value is appropriate when the grid is stored in
201  * the same file as the model, or the model file is in the same
202  * directory as the model file.
203  */
204  GeoTessModelExtended(const string& modelInputFile, const string& relativeGridPath);
205 
206  /**
207  * Construct a new GeoTessModel object and populate it with information from
208  * the specified file.
209  *
210  * <p>relativeGridPath is assumed to be "" (empty string), which is appropriate
211  * when the grid information is stored in the same file as the model or when
212  * the grid is stored in a separate file located in the same directory as the
213  * model file.
214  *
215  * @param modelInputFile
216  * name of file containing the model.
217  */
218  GeoTessModelExtended(const string& modelInputFile);
219 
220  /**
221  * Default constructor.
222  *
223  * @param attributeFilter the indexes of available attributes that should
224  * be loaded into memory.
225  */
226  GeoTessModelExtended(vector<int>& attributeFilter);
227 
228  /**
229  * Construct a new GeoTessModel object and populate it with information from
230  * the specified file.
231  *
232  * @param modelInputFile
233  * name of file containing the model.
234  * @param relativeGridPath
235  * the relative path from the directory where the model is stored
236  * to the directory where the grid is stored. Often, the model
237  * and grid are stored together in the same file in which case
238  * this parameter is ignored. Sometimes, however, the grid is
239  * stored in a separate file and only the name of the grid file
240  * (without path information) is stored in the model file. In
241  * this case, the code needs to know which directory to search
242  * for the grid file. The default is "" (empty string), which
243  * will cause the code to search for the grid file in the same
244  * directory in which the model file resides. Bottom line is that
245  * the default value is appropriate when the grid is stored in
246  * the same file as the model, or the model file is in the same
247  * directory as the model file.
248  * @param attributeFilter the indexes of available attributes that should
249  * be loaded into memory.
250  */
251  GeoTessModelExtended(const string& modelInputFile, const string& relativeGridPath,
252  vector<int>& attributeFilter);
253 
254  /**
255  * Construct a new GeoTessModel object and populate it with information from
256  * the specified file.
257  *
258  * <p>relativeGridPath is assumed to be "" (empty string), which is appropriate
259  * when the grid information is stored in the same file as the model or when
260  * the grid is stored in a separate file located in the same directory as the
261  * model file.
262  *
263  * @param modelInputFile
264  * name of file containing the model.
265  * @param attributeFilter the indexes of available attributes that should
266  * be loaded into memory.
267  */
268  GeoTessModelExtended(const string& modelInputFile, vector<int>& attributeFilter);
269 
270  /**
271  * Parameterized constructor, specifying the grid and metadata for the
272  * model. The grid is constructed and the data structures are initialized
273  * based on information supplied in metadata. The data structures are not
274  * populated with any information however (all Profiles are null). The
275  * application should populate the new model's Profiles after this
276  * constructor completes.
277  *
278  * <p>
279  * Before calling this constructor, the supplied MetaData object must be
280  * populated with required information by calling the following MetaData
281  * methods:
282  * <ul>
283  * <li>setDescription()
284  * <li>setLayerNames()
285  * <li>setAttributes()
286  * <li>setDataType()
287  * <li>setLayerTessIds() (only required if grid has more than one
288  * multi-level tessellation)
289  * </ul>
290  *
291  * @param gridFileName
292  * name of file from which to load the grid.
293  * @param metaData
294  * MetaData the new GeoTessModel instantiates a reference to the
295  * supplied metaData. No copy is made.
296  * @throws GeoTessException
297  * if metadata is incomplete.
298  */
299  GeoTessModelExtended(const string& gridFileName, GeoTessMetaData* metaData);
300 
301  /**
302  * Parameterized constructor, specifying the grid and metadata for the
303  * model. The grid is constructed and the data structures are initialized
304  * based on information supplied in metadata. The data structures are not
305  * populated with any information however (all Profiles are null). The
306  * application should populate the new model's Profiles after this
307  * constructor completes.
308  *
309  * <p>
310  * Before calling this constructor, the supplied MetaData object must be
311  * populated with required information by calling the following MetaData
312  * methods:
313  * <ul>
314  * <li>setDescription()
315  * <li>setLayerNames()
316  * <li>setAttributes()
317  * <li>setDataType()
318  * <li>setLayerTessIds() (only required if grid has more than one
319  * multi-level tessellation)
320  * <li>setSoftwareVersion()
321  * <li>setGenerationDate()
322  * </ul>
323  *
324  * @param grid
325  * a pointer to the GeoTessGrid that will support this
326  * GeoTessModel. GeoTessModel assumes ownership of the
327  * supplied grid object and will delete it when it is
328  * done with it.
329  * @param metaData
330  * MetaData the new GeoTessModel instantiates a reference to the
331  * supplied metaData. No copy is made.
332  * @throws GeoTessException
333  * if metadata is incomplete.
334  */
335  GeoTessModelExtended(GeoTessGrid* grid, GeoTessMetaData* metaData);
336 
337  /**
338  * Construct a new GeoTessModelExtended by making a deep copy of an
339  * existing GeoTessModel and initializing the extra data with default
340  * values.
341  * @param baseModel pointer to an existing GeoTessModel.
342  */
343  GeoTessModelExtended(GeoTessModel* baseModel);
344 
345  /**
346  * Destructor.
347  */
348  virtual ~GeoTessModelExtended();
349 
350  /**
351  * Retrieve the extra data stored by this derived class.
352  */
353  string getExtraData();
354 
355  /**
356  * Modify the extra data stored by this derived class
357  *
358  * @param xData the new value
359  */
360  void setExtraData(const string& xData);
361 
362 };
363 
364 
365 }// end namespace geotess
366 
367 #endif /* GEOTESSMODELEXTENDED_H_ */
geotess
Definition: AK135Model.h:55
geotess::GeoTessModelExtended::initializeData
void initializeData()
Definition: GeoTessModelExtended.h:116
geotess::GeoTessModelExtended
Definition: GeoTessModelExtended.h:104
geotess::GeoTessModelExtended::extraData
string extraData
Definition: GeoTessModelExtended.h:111
geotess::GeoTessModelExtended::class_name
static string class_name()
Definition: GeoTessModelExtended.h:175