00001 /*---------------------------------------------------------------------+ 00002 | Library QgarLib, graphics analysis and recognition | 00003 | Copyright (C) 2002 Qgar Project, LORIA | 00004 | | 00005 | This library is free software; you can redistribute it and/or | 00006 | modify it under the terms of the GNU Lesser General Public | 00007 | License version 2.1, as published by the Free Software Foundation. | 00008 | | 00009 | This library is distributed in the hope that it will be useful, | 00010 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00011 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 00012 | See the GNU Lesser General Public License for more details. | 00013 | | 00014 | The GNU Lesser General Public License is included in the file | 00015 | LICENSE.LGPL, in the root directory of the Qgar packaging. See | 00016 | http://www.gnu.org/licenses/lgpl.html for the terms of the licence. | 00017 | To receive a paper copy, write to the Free Software Foundation, | 00018 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | 00019 | | 00020 | Contact Project Qgar for any information: | 00021 | LORIA - équipe Qgar | 00022 | B.P. 239, 54506 Vandoeuvre-lès-Nancy Cedex, France | 00023 | email: qgar-contact@loria.fr | 00024 | http://www.qgar.org/ | 00025 *---------------------------------------------------------------------*/ 00026 00027 00028 #ifndef __RWSEGMENTVECTOR_H_INCLUDED__ 00029 #define __RWSEGMENTVECTOR_H_INCLUDED__ 00030 00031 00032 /** 00033 * @file RWSegmentVector.H 00034 * @brief Header file of class qgar::RWSegmentVector. 00035 * 00036 * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a> 00037 * @date July 3, 2001 16:37 00038 * @since Qgar 1.0 00039 */ 00040 00041 00042 00043 // For RCS/CVS use: Do not delete 00044 /* $Id: RWSegmentVector.H,v 1.4 2005/10/14 17:05:48 masini Exp $ */ 00045 00046 00047 00048 // STD 00049 #include <vector> 00050 // QGAR 00051 #include <qgarlib/primitives.H> 00052 namespace qgar 00053 { 00054 // Avoid #include's when not necessary 00055 template <class T> class AbstractGenPointChain; 00056 } 00057 00058 00059 00060 namespace qgar 00061 { 00062 00063 00064 /*---------------------------------------------------------------------* 00065 | | 00066 | C L A S S R W T R E E | 00067 | | 00068 *---------------------------------------------------------------------*/ 00069 00070 /** 00071 * @ingroup GRAPHPROC_POLYAPPROX 00072 * 00073 * @class RWTree RWSegmentVector.H "qgarlib/RWSegmentVector.H" 00074 * 00075 * @brief Private class of class RWSegmentVector to construct a binary 00076 * tree during Rosin and West's polygonal approximation. 00077 * 00078 * @warning Class qgar::RWSegmentVector is a friend. 00079 * 00080 * @todo Find an other solution than a private class! 00081 * 00082 * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a> 00083 * @date July 3, 2001 00:02 00084 * @since Qgar 1.0 00085 */ 00086 class RWTree 00087 { 00088 00089 // ------------------------------------------------------------------- 00090 // F R I E N D S 00091 // ------------------------------------------------------------------- 00092 00093 friend class RWSegmentVector; 00094 00095 // ------------------------------------------------------------------- 00096 // P R I V A T E M E M B E R S 00097 // ------------------------------------------------------------------- 00098 private: 00099 00100 /** @name Representation of a node */ 00101 // ======================== 00102 //@{ 00103 00104 /** 00105 * @brief Index in chain of first point. 00106 */ 00107 int _firstIdx; 00108 00109 /** 00110 * @brief Index in chain of last point. 00111 */ 00112 int _lastIdx; 00113 00114 /** 00115 * @brief Left child. 00116 */ 00117 RWTree* _leftChild; 00118 00119 /** 00120 * @brief Right child. 00121 */ 00122 RWTree* _rightChild; 00123 00124 /** 00125 * @brief Significance associated to the node. 00126 */ 00127 double _significance; 00128 00129 //@} 00130 00131 00132 /** @name Constructors */ 00133 // ============ 00134 //@{ 00135 00136 /** 00137 * @brief Default constructor. 00138 */ 00139 RWTree(); 00140 00141 /** 00142 * @brief Construct from indexes and significance. 00143 * 00144 * @param fi index of first point 00145 * @param li index of last point 00146 * @param s significance (default <b>0</b>) 00147 */ 00148 RWTree(int fi, int li, double s = 0.0); 00149 00150 //@} 00151 00152 00153 /** @name Destructor */ 00154 // ========== 00155 //@{ 00156 00157 /** 00158 * @brief Non-virtual destructor. 00159 */ 00160 ~RWTree(); 00161 00162 //@} 00163 00164 00165 /** @name Access */ 00166 // ====== 00167 //@{ 00168 00169 /** 00170 * @brief Get significance. 00171 */ 00172 inline double significance() const; 00173 00174 /** 00175 * @brief Get Index of first point. 00176 */ 00177 inline int firstIdx() const; 00178 00179 /** 00180 * @brief Get Index of last point. 00181 */ 00182 inline int lastIdx() const; 00183 00184 /** 00185 * @brief Get left child. 00186 */ 00187 inline RWTree* leftChild() const; 00188 00189 /** 00190 * @brief Get right child. 00191 */ 00192 inline RWTree* rightChild() const; 00193 00194 //@} 00195 00196 00197 /** @name Transformation */ 00198 // ============== 00199 //@{ 00200 00201 /** 00202 * @brief Set significance. 00203 * 00204 * @param s a significance 00205 */ 00206 inline void setSignificance(double s); 00207 00208 /** 00209 * @brief Set index of first point. 00210 * 00211 * @param fi first point index 00212 */ 00213 inline void setFirstIdx(int fi); 00214 00215 /** 00216 * @brief Set index of last point. 00217 * 00218 * @param li last point index 00219 */ 00220 inline void setLastIdx(int li); 00221 00222 /** 00223 * @brief Set left child. 00224 * 00225 * @param ls left child 00226 */ 00227 inline void setLeftChild(RWTree* ls); 00228 00229 /** 00230 * @brief Set right child. 00231 * 00232 * @param ls right child 00233 */ 00234 inline void setRightChild(RWTree* rs); 00235 00236 //@} 00237 00238 // ------------------------------------------------------------------- 00239 }; // class RWTree 00240 00241 00242 00243 00244 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00245 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00246 // I N L I N E F U N C T I O N S I M P L E M E N T A T I O N 00247 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00248 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00249 00250 00251 // ====== 00252 // ACCESS 00253 // ====== 00254 00255 00256 // GET SIGNIFICANCE 00257 00258 inline double 00259 RWTree::significance() const 00260 { 00261 return _significance; 00262 } 00263 00264 00265 // GET INDEX OF FIRST POINT 00266 00267 inline int 00268 RWTree::firstIdx() const 00269 { 00270 return _firstIdx; 00271 } 00272 00273 00274 // GET INDEX OF LAST POINT 00275 00276 inline int 00277 RWTree::lastIdx() const 00278 { 00279 return _lastIdx; 00280 } 00281 00282 00283 // GET LEFT CHILD 00284 00285 inline RWTree* 00286 RWTree::leftChild() const 00287 { 00288 return _leftChild; 00289 } 00290 00291 00292 // GET RIGHT CHILD 00293 00294 inline RWTree* 00295 RWTree::rightChild() const 00296 { 00297 return _rightChild; 00298 } 00299 00300 00301 // ============== 00302 // TRANSFORMATION 00303 // ============== 00304 00305 00306 // SET SIGNIFICANCE 00307 00308 inline void 00309 RWTree::setSignificance(double s) 00310 { 00311 _significance = s; 00312 } 00313 00314 00315 //` SET INDEX OF FIRST POINT 00316 00317 inline void 00318 RWTree::setFirstIdx(int fi) 00319 { 00320 _firstIdx = fi; 00321 } 00322 00323 00324 // SET INDEX OF LAST POINT 00325 00326 inline void 00327 RWTree::setLastIdx(int li) 00328 { 00329 _lastIdx = li; 00330 } 00331 00332 00333 // SET LEFT CHILD 00334 00335 inline void 00336 RWTree::setLeftChild(RWTree* ls) 00337 { 00338 _leftChild = ls; 00339 } 00340 00341 00342 // SET RIGHT CHILD 00343 00344 inline void 00345 RWTree::setRightChild(RWTree* rs) 00346 { 00347 _rightChild = rs; 00348 } 00349 00350 00351 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00352 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00353 00354 00355 00356 00357 00358 00359 /*---------------------------------------------------------------------* 00360 | | 00361 | C L A S S R W S E G M E N T L I S T | 00362 | | 00363 *---------------------------------------------------------------------*/ 00364 00365 /** 00366 * @ingroup GRAPHPROC_POLYAPPROX 00367 * 00368 * @class RWSegmentVector RWSegmentVector.H "qgarlib/RWSegmentVector.H" 00369 * 00370 * @brief Recursive polygonal approximation of a chain. 00371 * 00372 * The approximation is performed using the algorithm proposed by David 00373 * Lowe and further refined by P. Rosin and G. West 00374 * [<a href="Bibliography.html#Rosin-and-West-1989">Rosin and West, 1989</a>]. 00375 * 00376 * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a> 00377 * @date July 3, 2001 16:37 00378 * @since Qgar 1.0 00379 */ 00380 class RWSegmentVector 00381 00382 : public std::vector<Segment> 00383 00384 { 00385 // ------------------------------------------------------------------- 00386 // P U B L I C M E M B E R S 00387 // ------------------------------------------------------------------- 00388 public: 00389 00390 /** @name Constructors */ 00391 // ============ 00392 //@{ 00393 00394 /** 00395 * @brief Construct a polygonal approximation of a given chain. 00396 * 00397 * @param aChain chain to approximate 00398 * @param minDeviation minimum deviation considered as good 00399 * (default <b>1.9</b>, which is an ad hoc value) 00400 */ 00401 RWSegmentVector(AbstractGenPointChain<int>& aChain, 00402 double minDeviation = 1.9); 00403 00404 //@} 00405 00406 00407 /** @name Destructor */ 00408 // ========== 00409 //@{ 00410 00411 /** 00412 * @brief Virtual destructor. 00413 */ 00414 virtual ~RWSegmentVector(); 00415 00416 //@} 00417 00418 // ------------------------------------------------------------------- 00419 // P R I V A T E M E M B E R S 00420 // ------------------------------------------------------------------- 00421 private: 00422 00423 /** @name Auxiliary data */ 00424 // ============== 00425 //@{ 00426 00427 /** 00428 * @brief Associated vector of indexes in chain. 00429 */ 00430 std::vector<int> _indexes; 00431 00432 /** 00433 * @brief Associated vector of significances. 00434 */ 00435 std::vector<double> _significance; 00436 00437 /** 00438 * @brief Root of the chain tree. 00439 */ 00440 RWTree* _root; 00441 00442 //@} 00443 00444 00445 /** @name Auxiliary functions */ 00446 // =================== 00447 //@{ 00448 00449 /** 00450 * @brief Build the tree. 00451 */ 00452 RWTree* buildTree(std::vector<Point>&, int, int, double); 00453 00454 /** 00455 * @brief Search for the best approximation in the tree. 00456 */ 00457 void searchBestApproximation(RWTree* aNode); 00458 00459 /** 00460 * @brief Add a segment when on a terminal node. 00461 */ 00462 void addSegmentIfTerminalNode(RWTree* aNode, std::vector<Point>&); 00463 00464 /** 00465 * @brief Get <b>i</b>-th significance. 00466 */ 00467 inline double significance(int i); 00468 00469 //@} 00470 00471 // ------------------------------------------------------------------- 00472 }; // Class RWSegmentVector 00473 00474 00475 00476 00477 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00478 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00479 // I N L I N E F U N C T I O N S I M P L E M E N T A T I O N 00480 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00481 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00482 00483 00484 // GET i-TH SIGNIFICANCE 00485 00486 inline double 00487 RWSegmentVector::significance(int i) 00488 { 00489 return _significance[i]; 00490 } 00491 00492 00493 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00494 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00495 00496 00497 } // namespace qgar 00498 00499 00500 #endif /* __RWSEGMENTVECTOR_H_INCLUDED__ */