Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

_QGAR_GenQgarSegment.TCC

Go to the documentation of this file.
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 /**
00029  * @file   _QGAR_GenQgarSegment.TCC
00030  * @brief  Implementation of function members
00031  *         of class qgar::GenQgarSegment.
00032  *
00033  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gérald Masini">Gérald Masini</a>
00034  * @date   December 15, 2004  14:14
00035  * @since  Qgar 2.2
00036  */
00037 
00038 
00039 
00040 // STL
00041 #include <cmath>
00042 #include <iostream>
00043 // QGAR
00044 #include <qgarlib/ISerializable.H>
00045 #include <qgarlib/math.H>
00046 
00047 
00048 
00049 namespace qgar
00050 {
00051 
00052 
00053 // -------------------------------------------------------------------
00054 // C O N S T R U C T O R S
00055 // -------------------------------------------------------------------
00056 
00057 
00058 // DEFAULT CONSTRUCTOR
00059 
00060 template <class T>
00061 GenQgarSegment<T>::GenQgarSegment(int aThickness,
00062                                   QGEcolor aColor,
00063                                   QGEoutline anOutline)
00064 
00065   : AbstractGenQgarPrimitive<T>(aThickness, aColor, anOutline),
00066     _geomStructure(0, 0, 0, 0)
00067 
00068 {
00069   // VOID
00070 }
00071 
00072 
00073 // COPY-CONSTRUCTOR
00074 
00075 template <class T>
00076 GenQgarSegment<T>::GenQgarSegment(const GenQgarSegment<T>& aQSeg)
00077 
00078   : AbstractGenQgarPrimitive<T>(aQSeg._thickness,
00079                                 aQSeg._color,
00080                                 aQSeg._outline),
00081     _geomStructure(aQSeg._geomStructure)
00082 
00083 {
00084   // VOID
00085 }
00086 
00087 
00088 // INITIALIZE FROM A GEOMETRICAL SEGMENT
00089 
00090 template <class T>
00091 GenQgarSegment<T>::GenQgarSegment(const GenSegment<T>& aSeg,
00092                                   int aThickness,
00093                                   QGEcolor aColor,
00094                                   QGEoutline anOutline)
00095 
00096   : AbstractGenQgarPrimitive<T>(aThickness, aColor, anOutline),
00097     _geomStructure(aSeg)
00098 
00099 {
00100   // VOID
00101 }
00102 
00103 
00104 // INITIALIZE FROM SOURCE AND TARGET POINTS
00105 
00106 template <class T>
00107 GenQgarSegment<T>::GenQgarSegment(const GenPoint<T>& aSource,
00108                                   const GenPoint<T>& aTarget,
00109                                   int aThickness,
00110                                   QGEcolor aColor,
00111                                   QGEoutline anOutline)
00112 
00113   : AbstractGenQgarPrimitive<T>(aThickness, aColor, anOutline),
00114     _geomStructure(aSource, aTarget)
00115 
00116 {
00117   // VOID
00118 }
00119 
00120 
00121 // INITIALIZE FROM COORDINATES
00122 
00123 template <class T>
00124 GenQgarSegment<T>::GenQgarSegment(T aXSource,
00125                                   T aYSource,
00126                                   T aXTarget,
00127                                   T aYTarget,
00128                                   int aThickness,
00129                                   QGEcolor aColor,
00130                                   QGEoutline anOutline)
00131 
00132   : AbstractGenQgarPrimitive<T>(aThickness, aColor, anOutline),
00133     _geomStructure(aXSource, aYSource, aXTarget, aYTarget)
00134 
00135 {
00136   // VOID
00137 }
00138 
00139 
00140 // -------------------------------------------------------------------
00141 // D E S T R U C T O R 
00142 // -------------------------------------------------------------------
00143 
00144 
00145 template <class T>
00146 GenQgarSegment<T>::~GenQgarSegment()
00147 {
00148   // VOID
00149 }
00150 
00151 
00152 // -------------------------------------------------------------------
00153 // ACCESS TO GEOMETRICAL FEATURES
00154 // -------------------------------------------------------------------
00155 
00156 
00157 // GET LENGTH OF THE SEGMENT
00158 
00159 template <class T>
00160 inline double
00161 GenQgarSegment<T>::length() const
00162 {
00163   return _geomStructure.length();
00164 }
00165 
00166 
00167 // GET SQUARED LENGTH OF THE SEGMENT
00168 
00169 template <class T>
00170 inline double
00171 GenQgarSegment<T>::sqr_length() const
00172 {
00173   return _geomStructure.sqr_length();
00174 }
00175 
00176 
00177 // SIGNED DISTANCE BETWEEN (0,0) AND ITS PERPENDICULAR
00178 // PROJECTION ONTO THE LINE SUPPORTING THE SEGMENT
00179 // Precomputed
00180 // WARNING: This value is negative if the line supporting the
00181 // segment intersects the Y axis at a negative value
00182 
00183 template <class T>
00184 inline double
00185 GenQgarSegment<T>::rho() const
00186 {
00187   return _geomStructure.rho();
00188 }
00189 
00190 
00191 // ANGLE BETWEEN THE X AXIS AND THE SEGMENT, IN [0, 2PI[ RADIANS
00192 // Precomputed
00193 
00194 template <class T>
00195 inline double
00196 GenQgarSegment<T>::theta() const
00197 {
00198   return _geomStructure.theta();
00199 }
00200 
00201 
00202 // SAME AS PREVIOUS
00203 
00204 template <class T>
00205 inline double
00206 GenQgarSegment<T>::angle() const
00207 {
00208   return _geomStructure.angle();
00209 }
00210 
00211 
00212 // ANGLE BETWEEN THE X AXIS AND THE SEGMENT, IN [0, 360[ DEGREES
00213 
00214 template <class T>
00215 inline double
00216 GenQgarSegment<T>::thetaDegrees() const
00217 {
00218   return _geomStructure.thetaDegrees();
00219 }
00220 
00221 
00222 // SAME AS PREVIOUS
00223 
00224 template <class T>
00225 inline double
00226 GenQgarSegment<T>::angleDegrees() const
00227 {
00228   return _geomStructure.angleDegrees();
00229 }
00230 
00231 
00232 // ANGLE BETWEEN THE X AXIS AND THE SEGMENT, IN [0, PI[ RADIANS
00233 
00234 template <class T>
00235 inline double
00236 GenQgarSegment<T>::slope() const
00237 {
00238   return _geomStructure.slope();
00239 }
00240 
00241 
00242 // ANGLE BETWEEN THE X AXIS AND THE SEGMENT, IN [0, 180[ DEGREES
00243 
00244 template <class T>
00245 inline double
00246 GenQgarSegment<T>::slopeDegrees() const
00247 {
00248   return _geomStructure.slopeDegrees();
00249 }
00250 
00251   
00252 // -------------------------------------------------------------------
00253 // G E O M E T R I C A L   P R E D I C A T E S
00254 // -------------------------------------------------------------------
00255 
00256 
00257 // DOES THE GIVEN POINT APPROXIMATELY BELONGS
00258 // TO THE CURRENT QGAR SEGMENT?
00259 
00260 template <class T>
00261 inline bool
00262 GenQgarSegment<T>::contains(const GenPoint<T>& c, double aDist)
00263 {
00264   return _geomStructure.contains(c, aDist);
00265 }
00266 
00267 
00268 // -------------------------------------------------------------------
00269 // O P E R A T O R S 
00270 // -------------------------------------------------------------------
00271 
00272 
00273 // ASSIGNMENT
00274 
00275 template <class T>
00276 GenQgarSegment<T>&
00277 GenQgarSegment<T>::operator=(const GenQgarSegment<T>& aQSeg)
00278 {
00279   // Are left hand side and right hand side different objects?
00280   if (this != &aQSeg)
00281     {
00282       AbstractGenQgarPrimitive<T>::operator=(aQSeg);
00283       _geomStructure = aQSeg._geomStructure;
00284     }
00285   return *this;
00286 }
00287 
00288 
00289 // EQUALITY
00290 
00291 template <class T>
00292 inline bool
00293 GenQgarSegment<T>::operator==(const GenQgarSegment<T>& aQSeg) const
00294 {
00295   return this->_geomStructure == aQSeg._geomStructure;
00296 }
00297 
00298 
00299 // INEQUALITY
00300 
00301 template <class T>
00302 inline bool
00303 GenQgarSegment<T>::operator!=(const GenQgarSegment<T>& aQSeg) const
00304 {
00305   return this->_geomStructure != aQSeg._geomStructure;
00306 }
00307 
00308 
00309   
00310 // -------------------------------------------------------------------
00311 // F U N C T I O N A L   O P E R A T O R S 
00312 // -------------------------------------------------------------------
00313 
00314 
00315 // EQUALITY OF COORDINATES ONLY
00316 
00317 template <class T>
00318 inline bool
00319 GenQgarSegment<T>::eq(const GenQgarSegment<T>& aQSeg) const
00320 {
00321   return (this->_geomStructure).eq(aQSeg._geomStructure);
00322 }
00323 
00324 
00325 // EQUALITY OF COORDINATES AND ALL FEATURES
00326 
00327 template <class T>
00328 bool
00329 GenQgarSegment<T>::equal(const GenQgarSegment<T>& aQSeg) const
00330 {
00331   return
00332     (this->_geomStructure).eq(aQSeg._geomStructure)
00333     && ((this->_thickness) == (aQSeg._thickness))
00334     && ((this->_color)     == (aQSeg._color))
00335     && ((this->_outline)   == (aQSeg._outline));
00336 }
00337 
00338 
00339 // INEQUALITY OF COORDINATES ONLY
00340 
00341 template <class T>
00342 inline bool
00343 GenQgarSegment<T>::notEq(const GenQgarSegment<T>& aQSeg) const
00344 {
00345   return (this->_geomStructure).notEq(aQSeg._geomStructure);
00346 }
00347 
00348 
00349 // INEQUALITY OF COORDINATES OR ALL FEATURES
00350 
00351 template <class T>
00352 bool
00353 GenQgarSegment<T>::notEqual(const GenQgarSegment<T>& aQSeg) const
00354 {
00355   return
00356     (this->_geomStructure).notEq(aQSeg._geomStructure)
00357     || ((this->_thickness) != (aQSeg._thickness))
00358     || ((this->_color)     != (aQSeg._color))
00359     || ((this->_outline)   != (aQSeg._outline));
00360 }
00361 
00362 
00363 // -------------------------------------------------------------------
00364 // S E R I A L I Z A T I O N / D E S E R I A L I Z A T I O N
00365 // -------------------------------------------------------------------
00366 
00367 
00368 template <class T>
00369 std::istream& 
00370 GenQgarSegment<T>::read(std::istream& anInStream)
00371 {
00372   qgReadObjName(anInStream, "QgarSegment");
00373 
00374   // Geometrical structure
00375 
00376   qgReadObjData(anInStream, _geomStructure);
00377 
00378   // Attributes
00379 
00380   qgReadObjData(anInStream, this->_thickness);
00381 
00382   int color;
00383   qgReadObjData(anInStream, color);
00384   this->_color = static_cast<QGEcolor>(color);
00385 
00386   int outline;
00387   qgReadObjData(anInStream, outline);
00388   this->_outline = static_cast<QGEoutline>(outline);
00389 
00390   return anInStream;
00391 }
00392 
00393 
00394 template <class T>
00395 std::ostream& 
00396 GenQgarSegment<T>::write(std::ostream& anOutStream) const
00397 {
00398   anOutStream << "QgarSegment("
00399               << this->_geomStructure
00400               << ")("
00401               << this->_thickness
00402               << ")("
00403               << this->_color
00404               << ")("
00405               << this->_outline
00406               << ')';
00407   return anOutStream;  
00408 }
00409 
00410 
00411 // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
00412 // V                                                                 V
00413 // V            IMPLEMENTATION OF PURE VIRTUAL FUNCTIONS             V
00414 // V            INHERITED FROM AbstractGenQgarPrimitive              V
00415 // V                                                                 V
00416 // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
00417 
00418 
00419 // -------------------------------------------------------------------
00420 // C O P Y
00421 // -------------------------------------------------------------------
00422 
00423 
00424 // GET A COPY OF THE STRUCTURE IMPLEMENTING
00425 // THE GEOMETRICAL ASPECT OF A QGAR SEGMENT
00426 
00427 template <class T>
00428 GenQgarSegment<T>*
00429 GenQgarSegment<T>::clone() const
00430 {
00431   return new GenQgarSegment<T>(*this);
00432 }
00433 
00434 
00435 // -------------------------------------------------------------------
00436 // ACCESS TO GEOMETRICAL FEATURES
00437 // -------------------------------------------------------------------
00438 
00439 
00440 // GET THE STRUCTURE IMPLEMENTING
00441 // THE GEOMETRICAL ASPECT OF A QGAR SEGMENT
00442 
00443 template <class T>
00444 inline const GenSegment<T>&
00445 GenQgarSegment<T>::accessGeomStructure() const
00446 {
00447   return _geomStructure;
00448 }
00449 
00450 
00451 // -------------------------------------------------------------------
00452 // NON-PROTECTED ACCESS TO THE GEOMETRICAL ASPECT
00453 // -------------------------------------------------------------------
00454 
00455 
00456 // RETURN THE GEOMETRICAL ASPECT, THAT MAY THEN BE MODIFIED
00457 // USING APPROPRIATE TRANSFORMATION FUNCTION MEMBERS
00458 
00459 template <class T>
00460 inline AbstractGenPrimitive<T>&
00461 GenQgarSegment<T>::getGeomStructure()
00462 {
00463   return _geomStructure;
00464 }
00465 
00466 
00467 // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
00468 // V                                                                 V
00469 // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
00470 
00471 
00472 } // namespace qgar