CoordinateSequence.h

00001 /**********************************************************************
00002  * $Id: CoordinateSequence.h 1958 2007-01-09 15:08:22Z strk $
00003  *
00004  * GEOS - Geometry Engine Open Source
00005  * http://geos.refractions.net
00006  *
00007  * Copyright (C) 2006 Refractions Research Inc.
00008  *
00009  * This is free software; you can redistribute and/or modify it under
00010  * the terms of the GNU Lesser General Public Licence as published
00011  * by the Free Software Foundation. 
00012  * See the COPYING file for more information.
00013  *
00014  **********************************************************************/
00015 
00016 #ifndef GEOS_GEOM_COORDINATESEQUENCE_H
00017 #define GEOS_GEOM_COORDINATESEQUENCE_H
00018 
00019 #include <geos/platform.h>
00020 #include <geos/inline.h>
00021 
00022 #include <geos/geom/Coordinate.h> // for applyCoordinateFilter
00023 
00024 #include <vector>
00025 #include <iosfwd> // ostream
00026 #include <memory> // for auto_ptr typedef
00027 
00028 // Forward declarations
00029 namespace geos {
00030         namespace geom { 
00031                 class Envelope;
00032                 class CoordinateFilter;
00033                 class Coordinate;
00034         }
00035 }
00036 
00037 
00038 namespace geos {
00039 namespace geom { // geos::geom
00040 
00060 class CoordinateSequence {
00061 
00062 protected:
00063 
00064         CoordinateSequence() {}
00065 
00066         CoordinateSequence(const CoordinateSequence&) {}
00067 
00068 public:
00069 
00070         typedef std::auto_ptr<CoordinateSequence> AutoPtr;
00071 
00072         friend std::ostream& operator<< (std::ostream& os,
00073                 const CoordinateSequence& cs);
00074 
00075         friend bool operator== (
00076                 const CoordinateSequence& seq1,
00077                 const CoordinateSequence& seq2);
00078 
00079         friend bool operator!= (
00080                 const CoordinateSequence& seq1,
00081                 const CoordinateSequence& seq2);
00082 
00083         virtual ~CoordinateSequence() {}
00084 
00088         virtual CoordinateSequence *clone() const=0;
00089 
00096         //virtual const Coordinate& getCoordinate(int i) const=0;
00097         virtual const Coordinate& getAt(size_t i) const=0;
00098 
00100         const Coordinate& back() const {
00101                 return getAt(size()-1);
00102         }
00103 
00105         const Coordinate& front() const {
00106                 return getAt(0);
00107         }
00108 
00109         const Coordinate& operator[] (size_t i) const {
00110                 return getAt(i);
00111         }
00112 
00116         virtual void getAt(size_t i, Coordinate& c) const=0;
00117 
00122         //virtual int size() const=0;
00123         virtual size_t getSize() const=0;
00124 
00125         size_t size() const { return getSize(); }
00126 
00145         virtual const std::vector<Coordinate>* toVector() const=0;
00146 
00154         void add(const std::vector<Coordinate>* vc, bool allowRepeated);
00155 
00156         /* This is here for backward compatibility.. */
00157         //void add(CoordinateSequence *cl,bool allowRepeated,bool direction);
00158 
00171         void add(const CoordinateSequence *cl, bool allowRepeated,
00172                         bool direction);
00173 
00181         virtual void add(const Coordinate& c, bool allowRepeated);
00182 
00184         virtual bool isEmpty() const=0;
00185 
00187         virtual void add(const Coordinate& c)=0;
00188 
00189         // Get number of coordinates
00190         //virtual int getSize() const=0;
00191 
00193         //virtual       const Coordinate& getAt(size_t pos) const=0;
00194 
00196         virtual void setAt(const Coordinate& c, size_t pos)=0;
00197 
00199         virtual void deleteAt(size_t pos)=0;
00200 
00202         virtual std::string toString() const=0;
00203 
00205         virtual void setPoints(const std::vector<Coordinate> &v)=0;
00206         
00208         bool hasRepeatedPoints() const;
00209 
00211         const Coordinate* minCoordinate() const;
00212 
00213 
00220         static CoordinateSequence* removeRepeatedPoints(
00221                         const CoordinateSequence *cl);
00222 
00224         //
00227         virtual CoordinateSequence& removeRepeatedPoints()=0;
00228 
00233         static bool hasRepeatedPoints(const CoordinateSequence *cl);
00234 
00239         static CoordinateSequence* atLeastNCoordinatesOrNothing(size_t n,
00240                         CoordinateSequence *c);
00241 
00247         static const Coordinate* minCoordinate(CoordinateSequence *cl);
00248 
00250         //
00254         static int indexOf(const Coordinate *coordinate,
00255                         const CoordinateSequence *cl);
00256 
00262         static bool equals(const CoordinateSequence *cl1,
00263                         const CoordinateSequence *cl2);
00264 
00266         static void scroll(CoordinateSequence *cl, const Coordinate *firstCoordinate);
00267 
00269         static void reverse(CoordinateSequence *cl);
00270 
00272         enum { X,Y,Z,M };
00273 
00280         virtual size_t getDimension() const=0;
00281 
00292         virtual double getOrdinate(size_t index, size_t ordinateIndex) const=0;
00293 
00300         virtual double getX(size_t index) const { return getOrdinate(index, X); }
00301 
00308         virtual double getY(size_t index) const { return getOrdinate(index, Y); }
00309 
00310 
00319         virtual void setOrdinate(size_t index, size_t ordinateIndex, double value)=0;
00320 
00328         virtual void expandEnvelope(Envelope &env) const;
00329 
00330         virtual void apply_rw(const CoordinateFilter *filter)=0; //Abstract
00331         virtual void apply_ro(CoordinateFilter *filter) const=0; //Abstract
00332 
00341         template <class T>
00342         void applyCoordinateFilter(T& f) 
00343         {
00344                 Coordinate c;
00345                 for(size_t i=0, n=size(); i<n; ++i)
00346                 {
00347                         getAt(i, c);
00348                         f.filter(c);
00349                         setAt(c, i);
00350                 }
00351         }
00352 
00353 };
00354 
00355 std::ostream& operator<< (std::ostream& os, const CoordinateSequence& cs);
00356 
00357 bool operator== (const CoordinateSequence& s1, const CoordinateSequence& s2);
00358 
00359 bool operator!= (const CoordinateSequence& s1, const CoordinateSequence& s2);
00360 
00361 } // namespace geos::geom
00362 } // namespace geos
00363 
00364 //#ifdef GEOS_INLINE
00365 //# include "geos/geom/CoordinateSequence.inl"
00366 //#endif
00367 
00368 #endif // ndef GEOS_GEOM_COORDINATESEQUENCE_H
00369 
00370 /**********************************************************************
00371  * $Log$
00372  * Revision 1.12  2006/06/12 16:51:23  strk
00373  * Added equality and inequality operators and tests
00374  *
00375  * Revision 1.11  2006/06/12 16:36:22  strk
00376  * indentation, notes about things to be fixed.
00377  *
00378  * Revision 1.10  2006/06/12 15:06:30  strk
00379  * Added default ctor and copy ctor (protected)
00380  *
00381  * Revision 1.9  2006/06/12 10:10:39  strk
00382  * Fixed getGeometryN() to take size_t rather then int, changed unsigned int parameters to size_t.
00383  *
00384  * Revision 1.8  2006/05/04 08:42:12  strk
00385  * Added note about the CoordinateSequence::toVector() method.
00386  *
00387  * Revision 1.7  2006/05/03 19:47:27  strk
00388  * added operator<< for CoordinateSequence
00389  *
00390  * Revision 1.6  2006/05/03 08:58:34  strk
00391  * added new non-static CoordinateSequence::removeRepeatedPoints() mutator.
00392  *
00393  * Revision 1.5  2006/04/11 11:55:22  strk
00394  * Added CoordinateSequence::AutoPtr typedef
00395  *
00396  * Revision 1.4  2006/04/04 09:53:45  strk
00397  * Fixed applyCoordinateFilter() templated function body
00398  *
00399  * Revision 1.3  2006/03/24 09:52:41  strk
00400  * USE_INLINE => GEOS_INLINE
00401  *
00402  * Revision 1.2  2006/03/20 17:27:03  strk
00403  * Bug #72 - Missing <vector> header
00404  *
00405  * Revision 1.1  2006/03/09 16:46:49  strk
00406  * geos::geom namespace definition, first pass at headers split
00407  *
00408  **********************************************************************/

Generated on Fri Mar 27 04:52:38 2009 for GEOS by  doxygen 1.5.4