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