vtf-logo

StateBase.h

00001 // -*- C++ -*-
00002 
00003 #if !defined(__cpt_StateBase_h__)
00004 #define __cpt_StateBase_h__
00005 
00006 // Local
00007 #include "Grid.h"
00008 #include "BRep.h"
00009 
00010 #include "../geom/mesh/iss/distance.h"
00011 
00012 #include <iostream>
00013 
00014 #include <cmath>
00015 
00016 BEGIN_NAMESPACE_CPT
00017 
00019 
00022 template<int N, typename T = double>
00023 class StateBase {
00024   //
00025   // Protected types.
00026   //
00027 
00028 protected:
00029 
00031   typedef T Number;
00033   typedef ads::FixedArray<N,Number> Point;
00035   typedef ads::FixedArray<N,int> IndexedFace;
00037   typedef ads::FixedArray<N,int> Index;
00039   typedef ads::IndexRange<N,int> Range;
00041   typedef geom::BBox<N,Number> BBox;
00043   typedef geom::RegularGrid<N,T> Lattice;
00045   typedef Grid<N,T> Grid;
00047   typedef BRep<N,T> BRep;
00048 
00049   //
00050   // Member data.
00051   //
00052 
00053 protected:
00054 
00056   bool _hasBRepBeenSet;
00058   bool _hasCptBeenComputed;
00060 
00061   BBox _domain;
00063   Number _maximumDistance;
00065   Lattice _lattice;
00067   std::vector<Grid> _grids;
00069   BRep _brep;
00070 
00071   //
00072   // Not implemented.
00073   //
00074 
00075 private:
00076 
00078   StateBase(const StateBase&);
00079 
00081   StateBase&
00082   operator=(const StateBase&);
00083 
00084   // CONTINUE: Modified to compile with gcc 3.3.  It cannot use insertGrid
00085   // in the derived class when it is protected here.
00086   //protected:
00087 public:
00088 
00089   //-------------------------------------------------------------------------
00091 
00092 
00094   StateBase() :
00095     _hasBRepBeenSet(false),
00096     _hasCptBeenComputed(false),
00097     _domain(),
00098     _maximumDistance(-1),
00099     _lattice(),
00100     _grids(),
00101     _brep()
00102   {}
00103 
00105   ~StateBase()
00106   {}
00107 
00109   //-------------------------------------------------------------------------
00111 
00112 
00114   int
00115   getNumberOfGrids() const {
00116     return int(_grids.size());
00117   }
00118 
00120   bool
00121   hasBRepBeenSet() const {
00122     return _hasBRepBeenSet;
00123   }
00124 
00126   const BBox&
00127   getDomain() const {
00128     return _domain;
00129   }
00130 
00132   Number
00133   getMaximumDistance() const {
00134     return _maximumDistance;
00135   }
00136 
00138   //-------------------------------------------------------------------------
00140 
00141 
00142   // CONTINUE: The max distance should be specified on a per level basis.
00144 
00158   void 
00159   setParameters(const BBox& domain, Number maximumDistance);
00160 
00162 
00165   void 
00166   setParameters(const Number* domain, const Number maximumDistance) {
00167     setParameters(BBox(domain), maximumDistance);
00168   }
00169 
00171 
00176   void 
00177   setParameters(const Number maximumDistance) {
00178     // The point at infinity.
00179     const Point Infinity(std::numeric_limits<Number>::max());
00180     // Call setParameters() with all of space as the domain.
00181     setParameters(BBox(-Infinity, Infinity), maximumDistance);
00182   }
00183 
00184   // CONTINUE Make sure setLattice is called before adding grids.
00185   // CONTINUE enable multiple levels.  Add documentation.
00187 
00191   void 
00192   setLattice(const Index& extents, const BBox& domain);
00193 
00195 
00198   void 
00199   setLattice(const int* extents, const Number* domain) {
00200     setLattice(Index(extents), BBox(domain));
00201   }
00202 
00204 
00228   template<bool A1, bool A2, bool A3, bool A4>
00229   void 
00230   insertGrid(ads::Array<N,Number,A1>* distance,
00231              ads::Array<N,Point,A2>* gradientOfDistance,
00232              ads::Array<N,Point,A3>* closestPoint,
00233              ads::Array<N,int,A4>* closestFace);
00234 
00236 
00244   void 
00245   insertGrid(const int* indexLowerBounds,
00246              const int* indexUpperBounds,
00247              Number* distance,
00248              Number* gradientOfDistance,
00249              Number* closestPoint,
00250              int* closestFace);
00251 
00253 
00257   void
00258   clearGrids() {
00259     _grids.clear();
00260   }
00261 
00263 
00279   std::pair<int,int>
00280   computeClosestPointTransformUsingBBox();
00281 
00283 
00300   std::pair<int,int>
00301   computeClosestPointTransformUsingBruteForce();
00302 
00304 
00320   std::pair<int,int>
00321   computeClosestPointTransformUsingTree();
00322 
00324 
00340   std::pair<int,int>
00341   computeClosestPointTransformUnsignedUsingBBox();
00342 
00344 
00361   std::pair<int,int>
00362   computeClosestPointTransformUnsignedUsingBruteForce();
00363 
00365 
00374   void
00375   floodFillAtBoundary(Number farAway);
00376 
00378 
00394   void
00395   floodFillDetermineSign(Number farAway);
00396 
00398 
00402   void
00403   floodFillUnsigned(Number farAway);
00404 
00406 
00413   bool 
00414   areGridsValid();
00415 
00417 
00424   bool 
00425   areGridsValidUnsigned();
00426 
00428 
00439   void 
00440   setBRepWithNoClipping(int verticesSize,
00441                         const void* vertices,
00442                         int facesSize,
00443                         const void* faces);
00444 
00446 
00458   void 
00459   setBRep(int verticesSize,
00460           const void* vertices,
00461           int facesSize,
00462           const void* faces);
00463 
00465   //-------------------------------------------------------------------------
00467 
00468 
00470   void 
00471   displayInformation(std::ostream& out) const;
00472 
00474   //-------------------------------------------------------------------------
00476 
00477 
00478 protected:
00479 
00481   void
00482   initializeGrids() {
00483     for (int n = 0; n != getNumberOfGrids(); ++n) {
00484       _grids[n].initialize();
00485     }
00486   }
00487 
00489 
00490 };
00491 
00492 END_NAMESPACE_CPT
00493 
00494 #define __cpt_StateBase_ipp__
00495 #include "StateBase.ipp"
00496 #undef __cpt_StateBase_ipp__
00497 
00498 #endif

Generated on Fri Aug 24 12:55:43 2007 for Closest Point Transform by  doxygen 1.4.7