vtf-logo

Polygon.h

00001 // -*- C++ -*-
00002 //----------------------------------------------------------------------
00003 //
00004 //                            Sean Mauch
00005 //                (C) 1999-2005 All Rights Reserved
00006 //
00007 //----------------------------------------------------------------------
00008 // CONTINUE: Is this used?
00009 
00010 #if !defined(__geom_Polygon_h__)
00011 #define __geom_Polygon_h__
00012 
00013 #include "../kernel/Point.h"
00014 #include "../kernel/Line_2.h"
00015 #include "../grid/RegularGrid.h"
00016 #include "CyclicIndex.h"
00017 
00018 #include <iostream>
00019 #include <vector>
00020 #include <algorithm>
00021 
00022 #include <cassert>
00023 #include <cmath>
00024 #include <cfloat>
00025 
00026 BEGIN_NAMESPACE_GEOM
00027 
00029 
00035 template<typename T = double>
00036 class Polygon {
00037 public:
00038 
00039   //
00040   // Public types
00041   //
00042 
00044   typedef ads::FixedArray<2,T> Point;
00045       
00047   typedef std::vector<Point> Container;
00048 
00050   typedef typename Container::terator Iterator;
00051 
00053   typedef typename Container::const_iterator ConstIterator;
00054 
00056   typedef int SizeType;
00057 
00058 private:
00059 
00060   //
00061   // Data
00062   //
00063 
00064   Container _vertices;
00065   
00066 public:
00067 
00068   //--------------------------------------------------------------------------
00070   // @{
00071 
00073   Polygon()
00074   {}
00075 
00077   Polygon(SizeType size);
00078 
00080   Polygon(const Polygon& other);
00081 
00083   Polygon& 
00084   operator=(const Polygon& other);
00085 
00087   ~Polygon()
00088   {}
00089 
00090   // @}
00091   //--------------------------------------------------------------------------
00093   // @{
00094 
00096   const Container& 
00097   getVertices() const { 
00098     return _vertices; 
00099   }
00100 
00101   // @}
00102   //--------------------------------------------------------------------------
00104   // @{
00105 
00106   // CONTINUE
00107 #if 0
00109   Container& 
00110   vertices() { 
00111     return _vertices; 
00112   }
00113 #endif
00114 
00115   // @}
00116   //--------------------------------------------------------------------------
00118   // @{
00119 
00121   void 
00122   orderVertices();
00123 
00125   void 
00126   removeDuplicates();
00127 
00129   int 
00130   computeBottomAndTop(T* bottom, T* top) const;
00131 
00133 
00137   template<typename MultiIndexType, typename MultiSizeType>
00138   void 
00139   scan_convert(std::vector<MultiIndexType>& indices_vector,
00140                 MultiSizeType extents) const
00141   {
00142     MultiIndexType multi_index;
00143     scan_convert(indices_vector, extents, multi_index);
00144   }
00145 
00147 
00152   template<typename MultiIndexType, typename MultiSizeType>
00153   void 
00154   scan_convert(std::vector<MultiIndexType>& indices_vector,
00155                 MultiSizeType extents, int z_coord) const
00156   {
00157     MultiIndexType multi_index;
00158     multi_index[2] = z_coord;
00159     scan_convert(indices_vector, extents, multi_index);
00160   }
00161 
00163   void 
00164   clip(const Line_2<T>& ln);
00165 
00167 
00171   bool 
00172   is_valid() const;
00173   
00174   // @}
00175   //--------------------------------------------------------------------------
00177   // @{
00178 
00180   void
00181   get(std::istream& in);
00182 
00184   void
00185   put(std::ostream& out) const;
00186 
00188   void 
00189   mathematica_print() const;
00190 
00191   // @}
00192 
00193 private:
00194 
00196 
00201   template<typename MultiIndexType, typename MultiSizeType>
00202   void 
00203   scan_convert(std::vector<MultiIndexType>& cs, 
00204                 MultiSizeType extents,
00205                 MultiIndexType multi_index) const;
00206 
00208 
00214   template<typename MultiIndexType, typename MultiSizeType>
00215   void 
00216   scan_convert_triangle(std::vector<MultiIndexType>& cs, 
00217                          MultiSizeType extents,
00218                          MultiIndexType multi_index) const;
00219 };
00220 
00222 
00223 template<typename T>
00224 bool 
00225 operator==(const Polygon<T>& a, const Polygon<T>& b);
00226 
00228 
00229 template<typename T>
00230 bool 
00231 operator!=(const Polygon<T>& a, const Polygon<T>& b)
00232 {
00233   return !(a == b);
00234 }
00235 
00237 
00238 template<typename T>
00239 inline
00240 std::istream& 
00241 operator>>(std::istream& in, Polygon<T>& poly)
00242 {
00243   poly.get(in);
00244   return in;
00245 }
00246 
00248 
00249 template<typename T>
00250 inline
00251 std::ostream& 
00252 operator<<(std::ostream& out, const Polygon<T>& poly)
00253 {
00254   poly.put(out);
00255   return out;
00256 }
00257 
00258 END_NAMESPACE_GEOM
00259 
00260 #define __geom_Polygon_ipp__
00261 #include "Polygon.ipp"
00262 #undef __geom_Polygon_ipp__
00263 
00264 #endif
00265 

Generated on Fri Aug 24 12:55:56 2007 for Computational Geometry Package by  doxygen 1.4.7