All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CompoundCurve.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/CompoundCurve.cpp
22 
23  \brief CompoundCurve is a curve that may have circular and linear segments.
24 */
25 
26 // TerraLib
27 #include "../common/STLUtils.h"
28 #include "../common/Translator.h"
29 #include "../srs/Converter.h"
30 #include "Coord2D.h"
31 #include "Envelope.h"
32 #include "Exception.h"
33 #include "CompoundCurve.h"
34 #include "Point.h"
35 #include "PointM.h"
36 #include "PointZ.h"
37 #include "PointZM.h"
38 
39 // STL
40 #include <cassert>
41 #include <memory>
42 
43 const std::string te::gm::CompoundCurve::sm_typeName("CompoundCurve");
44 
46  : Curve(t, srid, mbr)
47 {
48 }
49 
50 te::gm::CompoundCurve::CompoundCurve(std::size_t size, GeomType t, int srid, Envelope* mbr)
51  : Curve(t, srid, mbr),
52  m_curves(size)
53 {
54 }
55 
57  : Curve(rhs)
58 {
60 }
61 
63 {
64  te::common::FreeContents(m_curves);
65 }
66 
68 {
69  if(this != &rhs)
70  {
71  Curve::operator=(rhs);
72 
73  te::common::FreeContents(m_curves);
74  m_curves.clear();
75  te::common::Clone(rhs.m_curves, m_curves);
76  }
77 
78  return *this;
79 }
80 
82 {
83  return new CompoundCurve(*this);
84 }
85 
86 const std::string& te::gm::CompoundCurve::getGeometryType() const throw()
87 {
88  return sm_typeName;
89 }
90 
91 void te::gm::CompoundCurve::setSRID(int srid) throw()
92 {
93  m_srid = srid;
94 }
95 
97 {
98 #ifdef TERRALIB_MOD_SRS_ENABLED
99  if(srid == m_srid)
100  return;
101 
102  const std::size_t size = m_curves.size();
103 
104  for(std::size_t i = 0; i < size; ++i)
105  m_curves[i]->transform(srid);
106 
107  if(m_mbr)
108  computeMBR(false);
109 
110  m_srid = srid;
111 #else
112  throw Exception(TE_TR("transform method is not supported!"));
113 #endif // TERRALIB_MOD_SRS_ENABLED
114 }
115 
116 void te::gm::CompoundCurve::computeMBR(bool cascade) const throw()
117 {
118  if(m_mbr == 0)
119  m_mbr = new Envelope;
120  else
121  m_mbr->makeInvalid();
122 
123  const std::size_t nSegs = size();
124 
125  if(nSegs == 0)
126  return;
127 
128  if(cascade)
129  {
130  for(std::size_t i = 0; i < nSegs; ++i)
131  m_curves[i]->computeMBR(true);
132  }
133 
134  const Envelope* e = m_curves[0]->getMBR();
135 
136  double minx = e->m_llx;
137  double miny = e->m_lly;
138  double maxx = e->m_urx;
139  double maxy = e->m_ury;
140 
141  for(std::size_t i = 1; i < nSegs; ++i)
142  {
143  e = m_curves[i]->getMBR();
144 
145  if(minx > e->m_llx) minx = e->m_llx;
146  if(miny > e->m_lly) miny = e->m_lly;
147  if(maxx < e->m_urx) maxx = e->m_urx;
148  if(maxy < e->m_ury) maxy = e->m_ury;
149  }
150 
151  m_mbr->m_llx = minx;
152  m_mbr->m_lly = miny;
153  m_mbr->m_urx = maxx;
154  m_mbr->m_ury = maxy;
155 }
156 
157 std::size_t te::gm::CompoundCurve::getNPoints() const throw()
158 {
159  return 0;
160 }
161 
162 te::gm::Geometry* te::gm::CompoundCurve::locateBetween(const double& /*mStart*/, const double& /*mEnd*/) const throw(Exception)
163 {
164  return 0;
165 }
166 
168 {
169  return 0.0;
170 }
171 
173 {
174  assert(size() > 1);
175  return 0;
176 }
177 
179 {
180  assert(size() > 1);
181  return 0;
182 }
183 
185 {
186  assert(size() >= 2);
187  return false;
188 }
189 
191 {
192  te::common::FreeContents(m_curves);
193  m_curves.clear();
194 }
195 
197 {
198  assert(i < size());
199 
200  return m_curves[i];
201 }
202 
204 {
205  m_curves.push_back(c);
206 }
void computeMBR(bool cascade) const
It computes the minimum bounding rectangle for the compound curve.
void makeInvalid()
It will invalidated the envelope.
Definition: Envelope.h:430
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
CompoundCurve & operator=(const CompoundCurve &rhs)
Assignment operator.
Curve is an abstract class that represents 1-dimensional geometric objects stored as a sequence of co...
Definition: Curve.h:58
bool isClosed() const
It returns true if the curve is closed (startPoint = endPoint).
CompoundCurve is a curve that may have circular and linear segments.
void makeEmpty()
It clears all the segments.
A point with x and y coordinate values.
void add(Curve *c)
It adds the curve to the compound.
double m_urx
Upper right corner x-coordinate.
Definition: Envelope.h:346
virtual Curve & operator=(const Curve &rhs)
Assignment operator.
Definition: Curve.cpp:61
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:345
std::vector< Curve * > m_curves
The list of segments of the compund curve.
Point * getStartPoint() const
It returns the curve start point.
const std::string & getGeometryType() const
The name of instantiable subtype is: CompoundCurve.
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
An Envelope defines a 2D rectangular region.
Curve * getCurve(std::size_t i) const
It returns the i-th curve.
te::dt::AbstractData * clone() const
It clones the compound curve.
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
CompoundCurve is a curve that may have circular and linear segments.
Definition: CompoundCurve.h:53
void transform(int srid)
It converts the coordinate values of the compound curve to the new spatial reference system...
CompoundCurve(GeomType t, int srid=0, Envelope *mbr=0)
It initializes the compound curve with the specified spatial reference system id and envelope...
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
double getLength() const
The length of this Curve in its associated spatial reference.
Point * getEndPoint() const
It returns the curve end point.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
An exception class for the Geometry module.
std::size_t getNPoints() const
It returns the number of points (vertexes) in the compound curve.
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
Geometry * locateBetween(const double &mStart, const double &mEnd) const
It returns a derived geometry collection value according to the range of coordinate values inclusivel...
A point with z-coordinate value.
A point with a z-coordinate value and an associated measurement.
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
void setSRID(int srid)
It sets the Spatial Reference System ID of the compound curve.
An utility struct for representing 2D coordinates.
A point with an associated measure.
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
static const std::string sm_typeName
~CompoundCurve()
Virtual destructor.