All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PolyhedralSurface.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/geometry/PolyhedralSurface.cpp
22 
23  \brief PolyhedralSurface is a contiguous collection of polygons, which share common boundary segments.
24 */
25 
26 // TerraLib
27 #include "../common/Exception.h"
28 #include "../common/STLUtils.h"
29 #include "Envelope.h"
30 #include "MultiPolygon.h"
31 #include "Polygon.h"
32 #include "PolyhedralSurface.h"
33 
34 const std::string te::gm::PolyhedralSurface::sm_typeName("PolyhedralSurface");
35 
36 te::gm::PolyhedralSurface::PolyhedralSurface(std::size_t nPolygons, GeomType t, int srid, Envelope* mbr)
37  : Surface(t, srid, mbr),
38  m_polygons(nPolygons)
39 {
40 }
41 
43  : Surface(rhs)
44 {
46 }
47 
49 {
50  te::common::FreeContents(m_polygons);
51 }
52 
54 {
55  if(this != &rhs)
56  {
57  Surface::operator=(rhs);
58  te::common::FreeContents(m_polygons);
59  m_polygons.clear();
60  te::common::Clone(rhs.m_polygons, m_polygons);
61  }
62 
63  return *this;
64 }
65 
67 {
68  return new PolyhedralSurface(*this);
69 }
70 
72 {
73  if(size < m_polygons.size())
74  {
75  std::size_t oldSize = m_polygons.size();
76  for(std::size_t i = size; i < oldSize; ++i)
77  delete m_polygons[i];
78  }
79 
80  m_polygons.resize(size);
81 }
82 
84 {
85  assert(i < m_polygons.size());
86  return m_polygons[i];
87 }
88 
90 {
91  assert((i < m_polygons.size()) && (m_polygons[i] == 0));
92  delete m_polygons[i];
93  m_polygons[i] = p;
94 }
95 
97 {
98  return 0;
99 }
100 
102 {
103  return 0.0;
104 }
105 
106 const std::string& te::gm::PolyhedralSurface::getGeometryType() const throw()
107 {
108  return sm_typeName;
109 }
110 
112 {
113  std::size_t n = m_polygons.size();
114 
115  for(std::size_t i = 0; i < n; ++i)
116  m_polygons[i]->setSRID(srid);
117 
118  m_srid = srid;
119 }
120 
122 {
123  if (srid == m_srid)
124  return;
125 
126  std::size_t n = m_polygons.size();
127 
128  for(std::size_t i = 0; i < n; ++i)
129  m_polygons[i]->transform(srid);
130 
131  if(m_mbr)
132  computeMBR(false);
133 
134  m_srid = srid;
135 }
136 
137 void te::gm::PolyhedralSurface::computeMBR(bool cascade) const throw()
138 {
139  if(m_mbr == 0)
140  m_mbr = new Envelope;
141  else
142  m_mbr->makeInvalid();
143 
144  std::size_t nPols = m_polygons.size();
145 
146  if(nPols == 0)
147  return;
148 
149  if(cascade)
150  m_polygons[0]->computeMBR(true);
151 
152  *m_mbr = *(m_polygons[0]->getMBR());
153 
154  for(std::size_t i = 1; i < nPols; ++i)
155  {
156  if(cascade)
157  m_polygons[i]->computeMBR(true);
158 
159  m_mbr->Union(*(m_polygons[i]->getMBR()));
160  }
161 }
162 
163 std::size_t te::gm::PolyhedralSurface::getNPoints() const throw()
164 {
165  std::size_t n = m_polygons.size();
166 
167  std::size_t sum = 0;
168 
169  for(std::size_t i = 0; i < n; ++i)
170  sum += m_polygons[i]->getNPoints();
171 
172  return sum;
173 }
174 
PolyhedralSurface is a contiguous collection of polygons, which share common boundary segments...
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
PolyhedralSurface(std::size_t nPolygons, GeomType t, int srid=0, Envelope *mbr=0)
It initializes the Geometry with the specified spatial reference system id and envelope.
virtual ~PolyhedralSurface()
Virtual destructor.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
virtual const std::string & getGeometryType() const
The name of the geometry subtype for PolyhedralSurface is: PolyhedralSurface.
Polygon * getPatchN(std::size_t i) const
It returns a polygon in this surface, the order is arbitrary.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
MultiPolygon * getBoundingPolygons(const Polygon *p) const
It returns the collection of polygons in this surface that bounds the given polygon &quot;p&quot; for any polyg...
std::size_t getNPoints() const
it returns the number of points (vertexes) in the geometry.
void Clone(const std::vector< T * > &src, std::vector< T * > &dst)
This function can be applied to a vector of pointers.
Definition: STLUtils.h:237
virtual Surface & operator=(const Surface &rhs)
Assignment operator.
Definition: Surface.cpp:39
virtual te::dt::AbstractData * clone() const
It clones the linestring.
MultiPolygon is a MultiSurface whose elements are Polygons.
Definition: MultiPolygon.h:50
static const std::string sm_typeName
Geometry type name for PolyhedralSurface.
void setPatchN(std::size_t i, Polygon *p)
It sets the informed position polygon to the new one.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
void transform(int srid)
It will transform the coordinates of the Geometry to the new one.
void setNumPatches(std::size_t size)
It sets the number of including polygons.
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
PolyhedralSurface is a contiguous collection of polygons, which share common boundary segments...
virtual PolyhedralSurface & operator=(const PolyhedralSurface &rhs)
Assignment operator.
MultiPolygon is a MultiSurface whose elements are Polygons.
An Envelope defines a 2D rectangular region.
double getPerimeter() const
It returns the length of the boundary for the surface.
std::vector< Polygon * > m_polygons
An array with the polygon list.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
Surface is an abstract class that represents a 2-dimensional geometric objects.
Definition: Surface.h:54
void makeInvalid()
It will invalidated the envelope.
Definition: Envelope.h:430
void setSRID(int srid)
It sets the Spatial Reference System ID of the Geometry and all its parts if it is a GeometryCollecti...
void computeMBR(bool cascade) const
It computes the minimum bounding rectangle for the Geometry.