File: TaggedLineString.cpp

package info (click to toggle)
geos 3.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 10,060 kB
  • ctags: 8,674
  • sloc: cpp: 64,513; xml: 23,384; sh: 8,965; ruby: 1,295; makefile: 1,124; python: 824; ansic: 289
file content (267 lines) | stat: -rw-r--r-- 5,824 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/**********************************************************************
 * $Id: TaggedLineString.cpp 1820 2006-09-06 16:54:23Z mloskot $
 *
 * GEOS - Geometry Engine Open Source
 * http://geos.refractions.net
 *
 * Copyright (C) 2006 Refractions Research Inc.
 *
 * This is free software; you can redistribute and/or modify it under
 * the terms of the GNU Lesser General Licence as published
 * by the Free Software Foundation. 
 * See the COPYING file for more information.
 *
 **********************************************************************
 *
 * Last port: simplify/TaggedLineString.java rev. 1.2 (JTS-1.7.1)
 *
 **********************************************************************/

#include <geos/simplify/TaggedLineString.h>
#include <geos/simplify/TaggedLineSegment.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/geom/LineString.h>
#include <geos/geom/Geometry.h> // for auto_ptr destructor 
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/CoordinateSequenceFactory.h>

#include <cassert>
#include <memory>

#ifndef GEOS_DEBUG
#define GEOS_DEBUG 0
#endif

#ifdef GEOS_DEBUG
#include <iostream>
#endif

using namespace geos::geom;
using namespace std;

namespace geos {
namespace simplify { // geos::simplify

/*public*/
TaggedLineString::TaggedLineString(const geom::LineString* nParentLine,
			size_t nMinimumSize)
	:
	parentLine(nParentLine),
	minimumSize(nMinimumSize)
{
	init();
}

/*public*/
TaggedLineString::~TaggedLineString()
{
#if GEOS_DEBUG
	cerr << "TaggedLineString[" << this << "] destructor"
	     << endl;
#endif

	for (size_t i=0, n=segs.size(); i<n; i++)
		delete segs[i];

	for (size_t i=0, n=resultSegs.size(); i<n; i++)
		delete resultSegs[i];
}

/*private*/
void
TaggedLineString::init()
{
	assert(parentLine);
	const CoordinateSequence* pts = parentLine->getCoordinatesRO();

#if GEOS_DEBUG
	cerr << "TaggedLineString[" << this << "] pts.size() " << pts->size()
	     << endl;
#endif

	segs.reserve(pts->size()-1);

	for (size_t i=0, n=pts->size()-1; i<n; i++)
	{
		TaggedLineSegment* seg = new TaggedLineSegment(
				pts->getAt(i),
				pts->getAt(i+1),
				parentLine, i);

		segs.push_back(seg);
	}

#if GEOS_DEBUG
	cerr << "TaggedLineString[" << this << "] segs.size " << segs.size()
	    << endl;
	cerr << "TaggedLineString[" << this << "] resultSegs.size " << resultSegs.size()
	    << endl;
#endif
}

/*public*/
size_t
TaggedLineString::getMinimumSize() const
{
	return minimumSize;
}

/*public*/
const geom::LineString* 
TaggedLineString::getParent() const
{
	return parentLine;
}

/*public*/
const CoordinateSequence*
TaggedLineString::getParentCoordinates() const
{
	assert(parentLine);
	return parentLine->getCoordinatesRO();
}

/*public*/
CoordinateSequence::AutoPtr
TaggedLineString::getResultCoordinates() const
{

#if GEOS_DEBUG
	cerr << __FUNCTION__ << " resultSegs.size: "
	     << resultSegs.size() << endl;
#endif

	CoordVectPtr pts = extractCoordinates(resultSegs);

#if GEOS_DEBUG
	cerr << __FUNCTION__ << " extracted Coords.size: "
	     << pts->size() << endl;
#endif


	CoordVect* v = pts.release();
	return CoordinateSequence::AutoPtr(parentLine->getFactory()->getCoordinateSequenceFactory()->create(v));

}

/*private static*/
TaggedLineString::CoordVectPtr
TaggedLineString::extractCoordinates(
		const std::vector<TaggedLineSegment*>& segs)
{
	CoordVectPtr pts(new CoordVect());

#if GEOS_DEBUG
	cerr << __FUNCTION__ << " segs.size: " << segs.size() << endl;
#endif

	size_t i=0, size=segs.size();

	assert(size);

	for (; i<size; i++)
	{
		TaggedLineSegment* seg = segs[i];
		assert(seg);
		pts->push_back(seg->p0);
	}

	// add last point
	pts->push_back(segs[size-1]->p1);

	return pts;
}

/*public*/
size_t
TaggedLineString::getResultSize() const
{
	unsigned resultSegsSize = resultSegs.size();
	return resultSegsSize == 0 ? 0 : resultSegsSize + 1;
}

/*public*/
TaggedLineSegment*
TaggedLineString::getSegment(size_t i) 
{
	return segs[i];
}

/*public*/
const TaggedLineSegment*
TaggedLineString::getSegment(size_t i) const
{
	return segs[i];
}

/*public*/
vector<TaggedLineSegment*>&
TaggedLineString::getSegments()
{
	assert(0);
	return segs;
}

/*public*/
const vector<TaggedLineSegment*>&
TaggedLineString::getSegments() const
{
	return segs;
}

/*public*/
auto_ptr<Geometry>
TaggedLineString::asLineString() const
{
	return parentLine->getFactory()->createLineString(
			getResultCoordinates());
}

/*public*/
auto_ptr<Geometry>
TaggedLineString::asLinearRing() const
{
	return parentLine->getFactory()->createLinearRing(
			getResultCoordinates());
}

/*public*/
void
TaggedLineString::addToResult(auto_ptr<TaggedLineSegment> seg)
{
#if GEOS_DEBUG
	cerr << "TaggedLineString[" << this << "] adding "
	     << " seg " << seg.get() << " to result"
	     << endl;
#endif
	resultSegs.push_back(seg.release());
#if GEOS_DEBUG
	cerr << "TaggedLineString[" << this << "] adding "
	     << " seg " << seg.get() << " to result"
	     << endl;
#endif
}

} // namespace geos::simplify
} // namespace geos

/**********************************************************************
 * $Log$
 * Revision 1.5  2006/06/12 11:29:24  strk
 * unsigned int => size_t
 *
 * Revision 1.4  2006/04/13 21:52:35  strk
 * Many debugging lines and assertions added. Fixed bug in TaggedLineString class.
 *
 * Revision 1.3  2006/04/13 09:21:46  mloskot
 * Removed definition of copy ctor and assignment operator for TaggedLineString class.
 * According to following rule: Declaring, but not defining, private copy operations has
 * the effect of "turning off" copying for the class.
 *
 * Revision 1.2  2006/04/12 15:20:37  strk
 * LineSegmentIndex class
 *
 * Revision 1.1  2006/04/12 14:22:12  strk
 * Initial implementation of TaggedLineSegment and TaggedLineString classes
 *
 **********************************************************************/