vtf-logo

ScanConversionPolygon.h

00001 // -*- C++ -*-
00002 
00003 #if !defined(__geom_ScanConversionPolygon_h__)
00004 #define __geom_ScanConversionPolygon_h__
00005 
00006 #include "../kernel/Point.h"
00007 #include "../kernel/Line_2.h"
00008 #include "../grid/RegularGrid.h"
00009 #include "CyclicIndex.h"
00010 
00011 #include <iostream>
00012 #include <vector>
00013 #include <algorithm>
00014 
00015 #include <cassert>
00016 #include <cmath>
00017 #include <cfloat>
00018 
00019 BEGIN_NAMESPACE_GEOM
00020 
00022 
00028 template<typename T = double>
00029 class ScanConversionPolygon {
00030 public:
00031 
00032   //
00033   // Public types.
00034   //
00035 
00037   typedef T Number;
00038 
00040   typedef ads::FixedArray<2,Number> Point;
00041       
00043   typedef int SizeType;
00044 
00045 private:
00046 
00048   typedef std::vector<Point> Container;
00049 
00050 public:
00051 
00052   //
00053   // More public types.
00054   //
00055 
00057   typedef typename Container::iterator Iterator;
00058 
00060   typedef typename Container::const_iterator ConstIterator;
00061 
00062 private:
00063 
00064   //
00065   // Data
00066   //
00067 
00068   Container _vertices;
00069   
00070 public:
00071 
00072   //--------------------------------------------------------------------------
00074   // @{
00075 
00077   ScanConversionPolygon() :
00078     _vertices()
00079   {}
00080 
00082   ScanConversionPolygon(SizeType size);
00083 
00085   ScanConversionPolygon(const ScanConversionPolygon& other);
00086 
00088   ScanConversionPolygon& 
00089   operator=(const ScanConversionPolygon& other);
00090 
00092   ~ScanConversionPolygon()
00093   {}
00094 
00095   // @}
00096   //--------------------------------------------------------------------------
00098   // @{
00099 
00101   SizeType
00102   getVerticesSize() const {
00103     return SizeType(_vertices.size());
00104   }
00105 
00107   const Point& 
00108   getVertex(const int n) const { 
00109     return _vertices[n]; 
00110   }
00111 
00112   // @}
00113   //--------------------------------------------------------------------------
00115   // @{
00116 
00117   // Return the beginning of the vertices.
00118   Iterator
00119   getVerticesBeginning() {
00120     return _vertices.begin();
00121   }
00122 
00123   // Return the end of the vertices.
00124   Iterator
00125   getVerticesEnd() {
00126     return _vertices.end();
00127   }
00128 
00130   void
00131   clear() {
00132     _vertices.clear();
00133   }
00134 
00136   void
00137   insert(const Point& x) {
00138     _vertices.push_back(x);
00139   }
00140 
00141   // @}
00142   //--------------------------------------------------------------------------
00144   // @{
00145 
00147   void 
00148   orderVertices();
00149 
00151   void 
00152   removeDuplicates();
00153 
00155   int 
00156   computeBottomAndTop(Number* bottom, Number* top) const;
00157 
00159 
00163   template<typename IndexOutputIterator>
00164   void 
00165   scanConvert(IndexOutputIterator coords,
00166               const ads::FixedArray<2,int>& extents) const {
00167     ads::FixedArray<2,int> multiIndex(0);
00168     scanConvert(coords, extents, multiIndex);
00169   }
00170 
00172 
00177   template<typename IndexOutputIterator>
00178   void 
00179   scanConvert(IndexOutputIterator coords,
00180               const ads::FixedArray<3,int>& extents, 
00181               const int zCoordinate) const {
00182     ads::FixedArray<3,int> multiIndex(0);
00183     multiIndex[2] = zCoordinate;
00184     scanConvert(coords, extents, multiIndex);
00185   }
00186 
00188   void 
00189   clip(const Line_2<Number>& line);
00190 
00192 
00196   bool 
00197   isValid() const;
00198   
00199   // @}
00200   //--------------------------------------------------------------------------
00202   // @{
00203 
00205   void
00206   get(std::istream& in);
00207 
00209   void
00210   put(std::ostream& out) const;
00211 
00213   void 
00214   mathematicaPrint(std::ostream& out) const;
00215 
00216   // @}
00217 
00218 private:
00219 
00221 
00226   template<typename IndexOutputIterator, int N>
00227   void 
00228   scanConvert(IndexOutputIterator coords,
00229               const ads::FixedArray<N,int>& extents,
00230               ads::FixedArray<N,int> multiIndex) const;
00231 
00233 
00239   template<typename IndexOutputIterator, int N>
00240   void 
00241   scanConvertTriangle(IndexOutputIterator coords,
00242                       const ads::FixedArray<N,int>& extents,
00243                       ads::FixedArray<N,int> multiIndex) const;
00244 };
00245 
00246 
00248 
00249 template<typename T>
00250 inline
00251 bool 
00252 operator==(const ScanConversionPolygon<T>& a, 
00253            const ScanConversionPolygon<T>& b);
00254 
00255 
00257 
00258 template<typename T>
00259 inline
00260 bool 
00261 operator!=(const ScanConversionPolygon<T>& a, 
00262            const ScanConversionPolygon<T>& b) {
00263   return !(a == b);
00264 }
00265 
00266 
00268 
00269 template<typename T>
00270 inline
00271 std::istream& 
00272 operator>>(std::istream& in, ScanConversionPolygon<T>& x) {
00273   x.get(in);
00274   return in;
00275 }
00276 
00277 
00279 
00280 template<typename T>
00281 inline
00282 std::ostream& 
00283 operator<<(std::ostream& out, const ScanConversionPolygon<T>& x) {
00284   x.put(out);
00285   return out;
00286 }
00287 
00288 
00289 END_NAMESPACE_GEOM
00290 
00291 #define __geom_ScanConversionPolygon_ipp__
00292 #include "ScanConversionPolygon.ipp"
00293 #undef __geom_ScanConversionPolygon_ipp__
00294 
00295 #endif

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