• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • lib
  • marble
  • geodata
  • data
GeoDataPolygon.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2008-2009 Patrick Spendrin <ps_ml@gmx.de>
9 // Copyright 2008 Inge Wallin <inge@lysator.liu.se>
10 //
11 
12 
13 #include "GeoDataPolygon.h"
14 #include "GeoDataPolygon_p.h"
15 
16 #include "MarbleDebug.h"
17 
18 
19 namespace Marble
20 {
21 
22 GeoDataPolygon::GeoDataPolygon( TessellationFlags f )
23  : GeoDataGeometry( new GeoDataPolygonPrivate( f ) )
24 {
25 }
26 
27 GeoDataPolygon::GeoDataPolygon( const GeoDataGeometry & other )
28  : GeoDataGeometry( other )
29 {
30 }
31 
32 GeoDataPolygon::~GeoDataPolygon()
33 {
34 #ifdef DEBUG_GEODATA
35  mDebug() << "delete polygon";
36 #endif
37 }
38 
39 GeoDataPolygonPrivate* GeoDataPolygon::p()
40 {
41  return static_cast<GeoDataPolygonPrivate*>(d);
42 }
43 
44 const GeoDataPolygonPrivate* GeoDataPolygon::p() const
45 {
46  return static_cast<GeoDataPolygonPrivate*>(d);
47 }
48 
49 bool GeoDataPolygon::operator==( const GeoDataPolygon &other ) const
50 {
51  const GeoDataPolygonPrivate *d = p();
52  const GeoDataPolygonPrivate *other_d = other.p();
53 
54  if ( !GeoDataGeometry::equals(other) ||
55  tessellate() != other.tessellate() ||
56  isClosed() != other.isClosed() ||
57  d->inner.size() != other_d->inner.size() ||
58  d->outer != other_d->outer ) {
59  return false;
60  }
61 
62  QVector<GeoDataLinearRing>::const_iterator itBound = d->inner.constBegin();
63  QVector<GeoDataLinearRing>::const_iterator itEnd = d->inner.constEnd();
64  QVector<GeoDataLinearRing>::const_iterator otherItBound = other_d->inner.constBegin();
65  QVector<GeoDataLinearRing>::const_iterator otherItEnd= other_d->inner.constEnd();
66 
67  for ( ; itBound != itEnd && otherItBound != otherItEnd; ++itBound, ++otherItBound ) {
68  if ( *itBound != *itBound) {
69  return false;
70  }
71  }
72 
73  Q_ASSERT ( itBound == itEnd && otherItBound == otherItEnd );
74  return true;
75 }
76 
77 bool GeoDataPolygon::operator!=( const GeoDataPolygon &other ) const
78 {
79  return !this->operator==(other);
80 }
81 
82 bool GeoDataPolygon::isClosed() const
83 {
84  return true;
85 }
86 
87 bool GeoDataPolygon::tessellate() const
88 {
89  return p()->m_tessellationFlags.testFlag(Tessellate);
90 }
91 
92 void GeoDataPolygon::setTessellate( bool tessellate )
93 {
94  // According to the KML reference the tesselation is done along great circles
95  // for polygons in Google Earth. Our "Tesselate" flag does this.
96  // Only for pure line strings and linear rings the
97  // latitude circles are followed for subsequent points that share the same latitude.
98  GeoDataGeometry::detach();
99 
100  if ( tessellate ) {
101  p()->m_tessellationFlags |= Tessellate;
102  } else {
103  p()->m_tessellationFlags ^= Tessellate;
104  }
105 }
106 
107 TessellationFlags GeoDataPolygon::tessellationFlags() const
108 {
109  return p()->m_tessellationFlags;
110 }
111 
112 void GeoDataPolygon::setTessellationFlags( TessellationFlags f )
113 {
114  GeoDataGeometry::detach();
115  p()->m_tessellationFlags = f;
116 }
117 
118 const GeoDataLatLonAltBox& GeoDataPolygon::latLonAltBox() const
119 {
120  return p()->outer.latLonAltBox();
121 }
122 
123 GeoDataLinearRing &GeoDataPolygon::outerBoundary()
124 {
125  return (p()->outer);
126 }
127 
128 const GeoDataLinearRing &GeoDataPolygon::outerBoundary() const
129 {
130  return (p()->outer);
131 }
132 
133 void GeoDataPolygon::setOuterBoundary( const GeoDataLinearRing& boundary )
134 {
135  GeoDataGeometry::detach();
136  p()->outer = boundary;
137 }
138 
139 QVector<GeoDataLinearRing>& GeoDataPolygon::innerBoundaries()
140 {
141  return p()->inner;
142 }
143 
144 const QVector<GeoDataLinearRing>& GeoDataPolygon::innerBoundaries() const
145 {
146  return p()->inner;
147 }
148 
149 void GeoDataPolygon::appendInnerBoundary( const GeoDataLinearRing& boundary )
150 {
151  GeoDataGeometry::detach();
152  p()->inner.append( boundary );
153 }
154 
155 void GeoDataPolygon::pack( QDataStream& stream ) const
156 {
157  GeoDataObject::pack( stream );
158 
159  p()->outer.pack( stream );
160 
161  stream << p()->inner.size();
162  stream << (qint32)(p()->m_tessellationFlags);
163 
164  for( QVector<GeoDataLinearRing>::const_iterator iterator
165  = p()->inner.constBegin();
166  iterator != p()->inner.constEnd();
167  ++iterator ) {
168  mDebug() << "innerRing: size" << p()->inner.size();
169  GeoDataLinearRing linearRing = ( *iterator );
170  linearRing.pack( stream );
171  }
172 }
173 
174 void GeoDataPolygon::unpack( QDataStream& stream )
175 {
176  GeoDataGeometry::detach();
177  GeoDataObject::unpack( stream );
178 
179  p()->outer.unpack( stream );
180 
181  qint32 size;
182  qint32 tessellationFlags;
183 
184  stream >> size;
185  stream >> tessellationFlags;
186 
187  p()->m_tessellationFlags = (TessellationFlags)(tessellationFlags);
188 
189  for(qint32 i = 0; i < size; i++ ) {
190  GeoDataLinearRing linearRing;
191  linearRing.unpack( stream );
192  p()->inner.append( linearRing );
193  }
194 }
195 
196 bool GeoDataPolygon::contains( const GeoDataCoordinates &coordinates ) const
197 {
198  if ( !outerBoundary().contains( coordinates ) ) {
199  // Not inside the polygon at all
200  return false;
201  }
202 
203  foreach( const GeoDataLinearRing &ring, innerBoundaries() ) {
204  if ( ring.contains( coordinates ) ) {
205  // Inside the polygon, but in one of its holes
206  return false;
207  }
208  }
209 
210  return true;
211 }
212 
213 }
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::GeoDataLinearRing
A LinearRing that allows to store a closed, contiguous set of line segments.
Definition: GeoDataLinearRing.h:68
Marble::GeoDataPolygon::contains
virtual bool contains(const GeoDataCoordinates &coordinates) const
Returns whether the given coordinates lie within the polygon.
Definition: GeoDataPolygon.cpp:196
Marble::GeoDataLinearRing::contains
virtual bool contains(const GeoDataCoordinates &coordinates) const
Returns whether the given coordinates lie within the polygon.
Definition: GeoDataLinearRing.cpp:58
Marble::GeoDataPolygon::GeoDataPolygon
GeoDataPolygon(TessellationFlags f=Tessellate)
Creates a new Polygon.
Definition: GeoDataPolygon.cpp:22
GeoDataPolygon.h
QDataStream
Marble::GeoDataPolygon::pack
virtual void pack(QDataStream &stream) const
Serialize the Polygon to a stream.
Definition: GeoDataPolygon.cpp:155
Marble::GeoDataGeometry
A base class for all geodata features.
Definition: GeoDataGeometry.h:47
Marble::GeoDataPolygon::tessellate
bool tessellate() const
Returns whether the Polygon follows the earth's surface.
Definition: GeoDataPolygon.cpp:87
Marble::GeoDataObject::pack
virtual void pack(QDataStream &stream) const
Reimplemented from Serializable.
Definition: GeoDataObject.cpp:114
Marble::GeoDataGeometry::detach
void detach()
Definition: GeoDataGeometry.cpp:54
GeoDataPolygon_p.h
Marble::GeoDataLineString::unpack
virtual void unpack(QDataStream &stream)
Unserialize the LineString from a stream.
Definition: GeoDataLineString.cpp:662
Marble::GeoDataPolygon::setTessellate
void setTessellate(bool tessellate)
Sets the tessellation property for the Polygon.
Definition: GeoDataPolygon.cpp:92
MarbleDebug.h
Marble::GeoDataPolygonPrivate::m_tessellationFlags
TessellationFlags m_tessellationFlags
Definition: GeoDataPolygon_p.h:57
Marble::GeoDataPolygon::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Returns the smallest latLonAltBox that contains the Polygon.
Definition: GeoDataPolygon.cpp:118
Marble::GeoDataPolygon
A polygon that can have "holes".
Definition: GeoDataPolygon.h:81
Marble::GeoDataPolygonPrivate
Definition: GeoDataPolygon_p.h:21
Marble::GeoDataPolygon::outerBoundary
GeoDataLinearRing & outerBoundary()
Returns the outer boundary that is represented as a LinearRing.
Definition: GeoDataPolygon.cpp:123
Marble::GeoDataPolygon::~GeoDataPolygon
virtual ~GeoDataPolygon()
Destroys a Polygon.
Definition: GeoDataPolygon.cpp:32
Marble::GeoDataLineString::pack
virtual void pack(QDataStream &stream) const
Serialize the LineString to a stream.
Definition: GeoDataLineString.cpp:644
Marble::GeoDataPolygon::appendInnerBoundary
void appendInnerBoundary(const GeoDataLinearRing &boundary)
Appends a given LinearRing as an inner boundary of the Polygon.
Definition: GeoDataPolygon.cpp:149
Marble::GeoDataPolygon::unpack
virtual void unpack(QDataStream &stream)
Unserialize the Polygon from a stream.
Definition: GeoDataPolygon.cpp:174
Marble::GeoDataPolygon::operator!=
bool operator!=(const GeoDataPolygon &other) const
Definition: GeoDataPolygon.cpp:77
Marble::GeoDataPolygon::innerBoundaries
QVector< GeoDataLinearRing > & innerBoundaries()
Returns a set of inner boundaries which are represented as LinearRings.
Definition: GeoDataPolygon.cpp:139
QVector
Marble::GeoDataPolygon::isClosed
virtual bool isClosed() const
Returns whether a Polygon is a closed polygon.
Definition: GeoDataPolygon.cpp:82
Marble::GeoDataPolygon::operator==
bool operator==(const GeoDataPolygon &other) const
Returns true/false depending on whether this and other are/are not equal.
Definition: GeoDataPolygon.cpp:49
Marble::GeoDataObject::unpack
virtual void unpack(QDataStream &steam)
Reimplemented from Serializable.
Definition: GeoDataObject.cpp:120
Marble::GeoDataPolygonPrivate::outer
GeoDataLinearRing outer
Definition: GeoDataPolygon_p.h:52
Marble::GeoDataPolygon::tessellationFlags
TessellationFlags tessellationFlags() const
Returns the tessellation flags for a Polygon.
Definition: GeoDataPolygon.cpp:107
Marble::Tessellate
Definition: MarbleGlobal.h:32
Marble::GeoDataPolygonPrivate::inner
QVector< GeoDataLinearRing > inner
Definition: GeoDataPolygon_p.h:53
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:36
Marble::GeoDataGeometry::equals
bool equals(const GeoDataGeometry &other) const
Definition: GeoDataGeometry.cpp:146
Marble::GeoDataPolygon::setOuterBoundary
void setOuterBoundary(const GeoDataLinearRing &boundary)
Sets the given LinearRing as an outer boundary of the Polygon.
Definition: GeoDataPolygon.cpp:133
Marble::GeoDataPolygon::setTessellationFlags
void setTessellationFlags(TessellationFlags f)
Sets the given tessellation flags for a Polygon.
Definition: GeoDataPolygon.cpp:112
Marble::GeoDataLatLonAltBox
A class that defines a 3D bounding box for geographic data.
Definition: GeoDataLatLonAltBox.h:49
Marble::GeoDataLineString::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Returns the smallest latLonAltBox that contains the LineString.
Definition: GeoDataLineString.cpp:580
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal