| 1 |
// |
| 2 |
// AutoCoast: Automatic Coastline scenery generator for Flight Simulator |
| 3 |
// |
| 4 |
// Copyright (c) 2004, Takuya Murakami. All rights reserved. |
| 5 |
// |
| 6 |
// Redistribution and use in source and binary forms, with or without |
| 7 |
// modification, are permitted provided that the following conditions |
| 8 |
// are met: |
| 9 |
// |
| 10 |
// 1. Redistributions of source code must retain the above copyright |
| 11 |
// notice, this list of conditions and the following disclaimer. |
| 12 |
// |
| 13 |
// 2. Redistributions in binary form must reproduce the above copyright |
| 14 |
// notice, this list of conditions and the following disclaimer in the |
| 15 |
// documentation and/or other materials provided with the distribution. |
| 16 |
// |
| 17 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 |
// ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR |
| 21 |
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 22 |
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 23 |
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 24 |
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 25 |
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 26 |
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 27 |
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 |
|
| 29 |
/* |
| 30 |
* GSHHS: Global Self-consistent Hierarchical High-resolution Shorelines |
| 31 |
* handling library |
| 32 |
*/ |
| 33 |
|
| 34 |
#ifndef _GSHHS_HPP |
| 35 |
#define _GSHHS_HPP |
| 36 |
|
| 37 |
#include <stdio.h> |
| 38 |
#include <vector> |
| 39 |
|
| 40 |
using namespace std; |
| 41 |
|
| 42 |
#include "gpc.hpp" |
| 43 |
#include "bbox.hpp" |
| 44 |
|
| 45 |
// |
| 46 |
// GSHHS data header |
| 47 |
// |
| 48 |
struct GSHHS_Header { |
| 49 |
int id; // Polygon ID |
| 50 |
int num; // number of vertices |
| 51 |
int level; // 1:land, 2:water, 3:water in land, 4:land in water in land |
| 52 |
int xmin, xmax; // Range (east-west: micro-degree) |
| 53 |
int ymin, ymax; // Range (south-north) |
| 54 |
int area; // Area size (1/10km^2) |
| 55 |
int version; // Version |
| 56 |
short greenwich; // Greenwich flag |
| 57 |
short source; // 0 = CIA WDB II, 1 = WVS |
| 58 |
}; |
| 59 |
|
| 60 |
// |
| 61 |
// GSHHS polygon class |
| 62 |
// |
| 63 |
class GVertexList : public GpcVertexList { |
| 64 |
private: |
| 65 |
GSHHS_Header header; |
| 66 |
BoundingBox bbox; |
| 67 |
|
| 68 |
public: |
| 69 |
GVertexList(); |
| 70 |
~GVertexList(); |
| 71 |
|
| 72 |
bool readHeader(FILE *fp); |
| 73 |
bool readData(FILE *fp, bool skip=false, bool isWestHemisphere=false); |
| 74 |
|
| 75 |
void printHeader(void); |
| 76 |
|
| 77 |
inline int id(void) { return header.id; } |
| 78 |
inline int level(void) { return header.level; } |
| 79 |
|
| 80 |
inline gpc_vertex_list *getvlist(void) { return vlist; } |
| 81 |
|
| 82 |
bool inBound(BoundingBox &c); |
| 83 |
bool inBoundVertices(BoundingBox &clip); |
| 84 |
}; |
| 85 |
|
| 86 |
// |
| 87 |
// GSHHS polygon set class (for each level) |
| 88 |
// |
| 89 |
class GPolygon : public GpcPolygon { |
| 90 |
private: |
| 91 |
// vector<GVertexList*> vlists; |
| 92 |
|
| 93 |
public: |
| 94 |
GPolygon(void); |
| 95 |
~GPolygon(); |
| 96 |
|
| 97 |
int LoadFromGshhsBinary(const char *fname, int level, BoundingBox &bbox, int skipid); |
| 98 |
int SaveGpcFile(const char *fname); |
| 99 |
}; |
| 100 |
|
| 101 |
#endif |
| 102 |
|