CVR-Lib last update 20 Sep 2009

cvrPointList.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1998
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  *
00006  * This file is part of the Computer Vision and Robotics Library (CVR-Lib)
00007  *
00008  * The CVR-Lib is free software; you can redistribute it and/or
00009  * modify it under the terms of the BSD License.
00010  *
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright notice,
00017  *    this list of conditions and the following disclaimer.
00018  *
00019  * 2. Redistributions in binary form must reproduce the above copyright notice,
00020  *    this list of conditions and the following disclaimer in the documentation
00021  *    and/or other materials provided with the distribution.
00022  *
00023  * 3. Neither the name of the authors nor the names of its contributors may be
00024  *    used to endorse or promote products derived from this software without
00025  *    specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00037  * POSSIBILITY OF SUCH DAMAGE.
00038  */
00039 
00040 
00041 /**
00042  * \file   cvrPointList.h
00043  *         Defines a class for lists of points
00044  * \author Suat Akyol
00045  * \date   28.06.2000
00046  *
00047  * $Id: cvrPointList.h,v 1.10 2005/06/08 12:00:44 doerfler Exp $
00048  */
00049 
00050 #ifndef _CVR_POINT_LIST_H_
00051 #define _CVR_POINT_LIST_H_
00052 
00053 #include "cvrObject.h"
00054 #include "cvrIoObject.h"
00055 #include "cvrTypes.h"
00056 #include "cvrPoint.h"
00057 #include "cvrRectangle.h"
00058 #include "cvrException.h"
00059 #include "cvrVector.h"
00060 #include "cvrList.h"
00061 
00062 #include <iostream>
00063 
00064 namespace cvr {
00065   /**
00066    * Template class to store a list of points.
00067    *
00068    * The %cvr::pointList class allows the storage of a list of points<T>.
00069    * The elements of the pointList can be accessed through iterators.
00070    *
00071    * There are several inherited classes which have an additional
00072    * semantical meaning.
00073    *
00074    * @see borderPoints, areaPoints, ioPoints, polygonPoints
00075    *
00076    * Example:
00077    *
00078    * \code
00079    * cvr::pointList pts;  // a list of points with integer coodinates
00080    *
00081    * // create 10 points
00082    * for (int i=0;i<10;++i) {
00083    *   pts.push_back(point(i,i));
00084    * }
00085    *
00086    * // iterate on the list of points to add 1 to x and 2 to y:
00087    * cvr::pointList::iterator it;
00088    * for (it=pts.begin();it!=pts.end();++pts) {
00089    *   (*pts).add(point(1,2));
00090    * }
00091    * \endcode
00092    *
00093    * @ingroup gAggregate
00094    *
00095    * This class usually is just a wrapper for the
00096    * cvr::smallObjectList<point<T>>, but it depends on the size you
00097    * set while compiling the library for the cvr::list to be a
00098    * std::list or a cvr::smallObjectList.
00099    */
00100   template<class T>
00101   class pointList : public ioObject, public list< point<T> > {
00102   public:
00103 
00104     /**
00105      * Iterator type (allows read and write operations).
00106      *
00107      * The use of the iterator classes is similar to the iterators of
00108      * the STL (Standard Template Library). See cvr::pointList::begin()
00109      * for an example
00110      */
00111     typedef typename list< point<T> >::iterator iterator;
00112 
00113     /**
00114      * Const iterator type (allows read-only operations).
00115      *
00116      * The use of the iterator classes is similar to the iterators of
00117      * the STL (Standard Template Library). See cvr::pointList::begin()
00118      * for an example.
00119      */
00120     typedef typename list< point<T> >::const_iterator const_iterator;
00121 
00122     /**
00123      * Reference type (allows read and write operations)
00124      * The use of the reference classes is similar to the references of
00125      * the STL (Standard Template Library).
00126      */
00127     typedef typename list< point<T> >::reference reference;
00128 
00129     /**
00130      * Const_reference type (allows read-only operations)
00131      * The use of the reference classes is similar to the references of
00132      * the STL (Standard Template Library).
00133      */
00134     typedef typename list< point<T> >::const_reference const_reference;
00135 
00136     /**
00137      * Default constructor creates an empty pointList;
00138      */
00139     pointList();
00140 
00141     /**
00142      * Create this pointList as a copy of another pointList
00143      * @param other the pointList to be copied.
00144      */
00145     pointList(const pointList<T>& other);
00146 
00147     /**
00148      * Create this pointList as a copy of a list< point<T> > of point<T>
00149      * @param other the pointList to be copied.
00150      */
00151     pointList(const list< point<T> >& other);
00152 
00153     /**
00154      * Destructor
00155      */
00156     virtual ~pointList();
00157 
00158     /**
00159      * Returns the number of elements of the pointList
00160      */
00161 //     int size() const;
00162 
00163     /**
00164      * Compares the size of this list with the size of the other point list
00165      * and returns true if this list has fewer points than the other one.
00166      */
00167     bool operator<(const pointList<T>& other) const;
00168 
00169     /**
00170      * Compares the size of this list with the size of the other point list
00171      * and returns true if this list has more points than the other one.
00172      */
00173     bool operator>(const pointList<T>& other) const;
00174 
00175     /**
00176      * Returns first element as a const_iterator.
00177      * Note that you can not change the values of the pointList
00178      * elements when you use a const_iterator. See also begin()
00179      */
00180 //     const_iterator begin() const;
00181 
00182     /**
00183      * Returns an iterator pointing to the first element of the pointList
00184      * The use of the interators is similar to the iterators of the
00185      * Standard Template Library (STL).
00186      * If you need to iterate on all elements of the pointList, you can
00187      * use following code:
00188      * \code
00189      * cvr::pointList<int> myPL;               // an empty pointList
00190      * cvr::pointList<int>::iterator it;       // an iterator
00191      *
00192      * // Fill pointList with some arbitrary points
00193      * for (int i=0; i<10; i++) {
00194      *   myPL.push_back(cvr::point(0,i));
00195      * }
00196      *
00197      * // Swap x and y for all points in list
00198      * for (it=myPL.begin();it!=myPL.end();it++) {
00199      *   int temp;
00200      *   temp = (*it).x;
00201      *   (*it).x = (*it).y;
00202      *   (*it).y = temp;
00203      * }
00204      * \endcode
00205      */
00206 //     iterator begin();
00207 
00208     /**
00209      * Returns last element as a const iterator.
00210      * For an example see begin()
00211      */
00212 //     const_iterator end() const;
00213 
00214     /**
00215      * Returns last element as an iterator
00216      * For an example see begin()
00217      */
00218 //     iterator end();
00219 
00220     /**
00221      * Deletes all points from list and leaves empty pointList.
00222      */
00223 //     void clear();
00224 
00225     /**
00226      * Erases point, which is denoted by it. Returns iterator to next element.
00227      */
00228 //     iterator erase(const iterator& it);
00229 
00230     /**
00231      * Erases points between first and last. Returns iterator to next element.
00232      */
00233 //     iterator erase(const iterator& first, const iterator& last);
00234 
00235     /**
00236      * Inserts point before position denoted by it.
00237      * returns iterator to inserted element.
00238      *
00239      * \b WARNING: This is not the same as default list behaviour
00240      * which returns an iterator pointing after the last inserted
00241      * element!
00242      */
00243 //     iterator insert(const iterator& it, const point<T>& thePoint);
00244 
00245     /**
00246      * Inserts points before position denoted by it.
00247      * Returns iterator to first element of inserted elements.
00248      *
00249      * \b WARNING: This is not the same as default list behaviour
00250      * which returns an iterator pointing after the last inserted
00251      * element!
00252      */
00253 //     iterator insert(const iterator& it,
00254 //                     const int n,
00255 //                     const point<T>& thePoint);
00256 
00257     /**
00258      * Inserts the elements from first to last, before position denoted by it.
00259      * Returns iterator to first element of inserted elements.
00260      *
00261      * \b WARNING: This is not the same as default list behaviour
00262      * which returns an iterator pointing after the last inserted
00263      * element!
00264      */
00265 //     iterator insert(const iterator& it,
00266 //                     const_iterator first,
00267 //                     const_iterator last);
00268 
00269     /**
00270      * Transfer all elements in the second list into this one.
00271      * At the end of the operation, the second list will be empty
00272      */
00273 //     void splice(const iterator& pos,
00274 //                 pointList<T>& other);
00275 
00276     /**
00277      * Inserts element at begin of pointList
00278      */
00279 //     void push_front(const point<T>& thePoint);
00280 
00281     /**
00282      * Removes element at begin of pointList
00283      */
00284 //     void pop_front();
00285 
00286     /**
00287      * Inserts element at end of pointList
00288      */
00289 //     void push_back(const point<T>& thePoint);
00290 
00291     /**
00292      * Removes element at end of pointList
00293      */
00294 //     void pop_back();
00295 
00296     /**
00297      * Returns a reference to the first element
00298      */
00299 //     reference front();
00300 
00301     /**
00302      * Returns a const reference to the first element
00303      */
00304 //     const_reference front() const;
00305 
00306     /**
00307      * Returns a reference to the last element
00308      */
00309 //     reference back();
00310 
00311     /**
00312      * Returns a const reference to the last element
00313      */
00314 //     const_reference back() const;
00315 
00316     /**
00317      * Copy function.
00318      * copy the contents of \a other in this %object.
00319      * @param other the source pointList to be copied.
00320      */
00321     pointList<T>& copy(const pointList<T>& other);
00322 
00323     /**
00324      * Assigment operator (alias for copy(other)).
00325      * @param other the pointList to be copied
00326      * @return a reference to the actual pointList
00327      */
00328     pointList<T>& operator=(const pointList<T>& other);
00329 
00330     /**
00331      * Returns the name of this type.
00332      */
00333     virtual const std::string& name() const;
00334 
00335     /**
00336      * Create a clone of this pointList
00337      * @return a pointer to a copy of this pointList
00338      */
00339     virtual ioObject* clone() const;
00340 
00341     /**
00342      * Create a new instance of pointList
00343      * @return a pointer to a copy of this pointList
00344      */
00345     virtual ioObject* newInstance() const;
00346 
00347     /**
00348      * Sort the points int the pointList in ascending order first of
00349      * y, and than of x.
00350      */
00351 //     inline void sort();
00352 
00353     /**
00354      * Sort the pointList according to the compare function \a comp,
00355      * which must return a bool and take two point<T> as
00356      * arguments. See std::less() for an example.
00357      */
00358 //     template <class Compare>
00359 //     inline void sort(Compare comp);
00360 
00361     /**
00362      * @name Conversion Methods
00363      */
00364     //@{
00365 
00366     /**
00367      * Copy the elements of the other standard list of point<T> in this
00368      * %object
00369      * @param other the source pointList to be copied.
00370      */
00371     pointList<T>& castFrom(const list< point<T> >& other);
00372 
00373     /**
00374      * Copy the \a other point-list by casting each of its elements
00375      * @param other The point list to be casted
00376      */
00377     template<class U>
00378     inline pointList<T>& castFrom(const pointList<U>& other);
00379 
00380     /**
00381      * Cast the given vector of points into a list, where the
00382      * first element in the vector will be the first element
00383      * in the list.
00384      * @param other the vector of points with the points
00385      * @return a reference to this instance
00386      */
00387     template<class U>
00388     inline pointList<T>& castFrom(const vector< point<U> >& other);
00389 
00390     /**
00391      * Cast the given vector of points into a list, where the
00392      * first element in the vector will be the first element
00393      * in the list.
00394      */
00395     template<class U>
00396     inline pointList<T>& castFrom(const vector< point<U> >& other) const;
00397 
00398     /**
00399      * Cast this list of points into a cvr::vector, which can be
00400      * accessed in a faster way than the list.
00401      */
00402     template<class U>
00403     inline void castTo(vector< point<U> >& other) const;
00404 
00405     //@}
00406 
00407     /**
00408      * Compare this pointList with other
00409      * @param other the other pointList to be compared with
00410      * @return true if both pointLists have the same elements and same size
00411      */
00412     bool equals(const pointList<T>& other) const;
00413 
00414     /**
00415      * Compare this pointList with other
00416      * @param other the other pointList to be compared with
00417      * @return true if both pointLists have the same elements and same size
00418      */
00419     bool operator==(const pointList<T>& other) const;
00420 
00421     /**
00422      * Returns true if the list is empty
00423      */
00424 //     bool empty() const;
00425 
00426     /**
00427      * Returns the last set or calculated boundary.
00428      *
00429      * The boundary is the smallest rectangle that contains all the
00430      * points in the list.  Note that the boundary must be set by the
00431      * user, or the user must explicitly specify that it must be
00432      * updated (see cvr::pointList<T>::updateBoundary).  It will NOT
00433      * be updated automatically
00434      */
00435     inline const rectangle<T>& getBoundary() const;
00436 
00437     /**
00438      * Set the boundary of the points.
00439      *
00440      * The boundary is the smallest rectangle that contains all the
00441      * points in the list.  Note that the boundary must be set by the
00442      * user using this method, or the user must explicitly specify
00443      * that it must be updated (see cvr::pointList<T>::updateBoundary).
00444      * It will \b NOT be updated automatically with each point you insert or
00445      * delete.
00446      */
00447     inline void setBoundary(const rectangle<T>& r);
00448 
00449     /**
00450      * Calculate the boundary box.
00451      *
00452      * The boundary is the smallest rectangle that contains all the
00453      * points in the list.  Note that the boundary must be set by the
00454      * user, or the user must explicitly specify that it must be
00455      * calculated.
00456      *
00457      * This member computes the boundary, but it does not set the compute
00458      * one into the internal boundary attribute.  See also updateBoundary().
00459      *
00460      * @return a the calculated boundary
00461      */
00462     const rectangle<T> computeBoundary() const;
00463 
00464      /**
00465      * Calculate and update the boundary box.
00466      *
00467      * The boundary is the smallest rectangle that contains all the
00468      * points in the list.  Note that the boundary must be set by the
00469      * user, or the user must explicitly specify that it must be
00470      * calculated.
00471      *
00472      * This member computes the boundary AND set the internal boundary
00473      * attribute.  See also computeBoundary().
00474      *
00475      * @return a reference to the calculated boundary
00476      */
00477     const rectangle<T>& updateBoundary();
00478 
00479     /**
00480      * Write the point list in the given ioHandler
00481      */
00482     virtual bool write(ioHandler& handler,const bool complete = true) const;
00483 
00484     /**
00485      * Read the point list from the given ioHandler
00486      */
00487     virtual bool read(ioHandler& handler,const bool complete = true);
00488 
00489   protected:
00490     /**
00491      * This pointList class is implemented with a list< point<T> > instance
00492      */
00493 //     list< point<T> > thePointList_;
00494 
00495     /**
00496      * Boundary is the smallest rectangle which includes all the points
00497      * in the list
00498      */
00499     rectangle<T> boundary_;
00500   };
00501 
00502   /**
00503    * Read the vector from the given ioHandler.  The complete flag indicates
00504    * if the enclosing begin and end should be also be readed
00505    *
00506    * @ingroup gStorable
00507    */
00508   template<class T>
00509   bool read(ioHandler& handler,pointList<T>& plst,const bool complete=true);
00510 
00511   /**
00512    * Write the vector in the given ioHandler.  The complete flag indicates
00513    * if the enclosing begin and end should be also be written or not
00514    *
00515    * @ingroup gStorable
00516    */
00517   template<class T>
00518   bool write(ioHandler& handler, const pointList<T>& plst,
00519              const bool complete=true);
00520 
00521   /**
00522    * ipointList is a list of points with integer coordinates
00523    */
00524   typedef pointList<int> ipointList;
00525 
00526 } // namespace cvr
00527 
00528 namespace std {
00529 
00530   template<class T>
00531   std::ostream& operator<<(std::ostream& s,const cvr::pointList<T>& pts);
00532 }
00533 
00534 #include "cvrPointList_inline.h"
00535 
00536 #endif
00537 

Generated on Sun Sep 20 22:08:00 2009 for CVR-Lib by Doxygen 1.5.8