2 *  This program is free software: you can redistribute it and/or modify
 
    3 *  it under the terms of the GNU Lesser General Public License as
 
    4 *  published by the Free Software Foundation, either version 3 of the
 
    5 *  License, or  (at your option) any later version.
 
    7 *  This program is distributed in the hope that it will be useful,
 
    8 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
    9 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
   10 *  GNU General Public License for more details.
 
   12 *  You should have received a copy of the GNU General Public License
 
   13 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
   18 * @file InGeneralizedDiskOfGivenRadius.ih
 
   19 * @author Tristan Roussillon (\c tristan.roussillon@liris.cnrs.fr )
 
   20 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
 
   24 * Implementation of inline methods defined in InGeneralizedDiskOfGivenRadius.h
 
   26 * This file is part of the DGtal library.
 
   30//////////////////////////////////////////////////////////////////////////////
 
   32//////////////////////////////////////////////////////////////////////////////
 
   34///////////////////////////////////////////////////////////////////////////////
 
   35// IMPLEMENTATION of inline methods.
 
   36///////////////////////////////////////////////////////////////////////////////
 
   38///////////////////////////////////////////////////////////////////////////////
 
   41// ----------------------------------------------------------------------------
 
   42template <typename TPoint, typename TDetComputer>
 
   44DGtal::InGeneralizedDiskOfGivenRadius<TPoint, TDetComputer>::
 
   45InGeneralizedDiskOfGivenRadius(bool isPositive, 
 
   48  : myNum2(aNum2), myDen2(aDen2),
 
   49    myIsPositive( isPositive ), 
 
   54    myComputedNum2( NumberTraits<Integer>::ZERO ), 
 
   55    myComputedDen2( NumberTraits<Integer>::ZERO ), 
 
   56    myPQ0( NumberTraits<Integer>::ZERO ), 
 
   57    myPQ1( NumberTraits<Integer>::ZERO ), 
 
   58    myPQnorm( NumberTraits<Integer>::ZERO ),
 
   59    myQR0( NumberTraits<Integer>::ZERO ), 
 
   60    myQR1( NumberTraits<Integer>::ZERO ), 
 
   61    myQRnorm( NumberTraits<Integer>::ZERO ),
 
   62    myRP0( NumberTraits<Integer>::ZERO ), 
 
   63    myRP1( NumberTraits<Integer>::ZERO ), 
 
   64    myRPnorm( NumberTraits<Integer>::ZERO ),
 
   65    myArea( NumberTraits<Integer>::ZERO ),
 
   68  if (myNum2 < NumberTraits<Integer>::ZERO) 
 
   71  if (myDen2 < NumberTraits<Integer>::ZERO) 
 
   74  myDetComputer.init( myDen2, myNum2 ); 
 
   77// ----------------------------------------------------------------------------
 
   78template <typename TPoint, typename TDetComputer>
 
   81DGtal::InGeneralizedDiskOfGivenRadius<TPoint, TDetComputer>::
 
   82init ( const Point& aP, const Point& aQ )
 
   87  myPQ0 = static_cast<Integer>(myQ[0]-myP[0]); 
 
   88  myPQ1 = static_cast<Integer>(myQ[1]-myP[1]);
 
   89  myPQnorm = myPQ0*myPQ0 + myPQ1*myPQ1; 
 
   90  //myPQnorm must not be greater than the squared diameter, ie. 4 * myNum2 / myDen2
 
   91  ASSERT( lengthIsValid( myPQnorm ) ); 
 
   94// ----------------------------------------------------------------------------
 
   95template <typename TPoint, typename TDetComputer>
 
   98DGtal::InGeneralizedDiskOfGivenRadius<TPoint, TDetComputer>::
 
   99init ( const PointArray& aA )
 
  101  init( aA[0], aA[1] ); 
 
  104// ----------------------------------------------------------------------------
 
  105template <typename TPoint, typename TDetComputer>
 
  107typename DGtal::InGeneralizedDiskOfGivenRadius<TPoint, TDetComputer>::Value
 
  108DGtal::InGeneralizedDiskOfGivenRadius<TPoint, TDetComputer>::
 
  109operator() ( const Point& aR ) const
 
  113  myQR0 = static_cast<Integer>(myR[0]-myQ[0]); 
 
  114  myQR1 = static_cast<Integer>(myR[1]-myQ[1]);
 
  116  myRP0 = static_cast<Integer>(myP[0]-myR[0]); 
 
  117  myRP1 = static_cast<Integer>(myP[1]-myR[1]);
 
  119  myArea = myAreaFunctor(myPQ0, myPQ1, myQR0, myQR1);
 
  121  if (myDen2 == NumberTraits<Integer>::ZERO)
 
  122    { //comparison to an infinite radius
 
  129    { //comparison to a finite radius
 
  133          if (myArea > NumberTraits<Integer>::ZERO)
 
  135              finalizeComputation(); 
 
  136              return -myDetComputer( myComputedDen2, myComputedNum2 );
 
  139            return -NumberTraits<Value>::ONE; 
 
  143          if (myArea < NumberTraits<Integer>::ZERO)
 
  145              finalizeComputation(); 
 
  146              return myDetComputer( myComputedDen2, myComputedNum2 );
 
  149            return NumberTraits<Value>::ONE;
 
  155// ----------------------------------------------------------------------------
 
  156template <typename TPoint, typename TDetComputer>
 
  159DGtal::InGeneralizedDiskOfGivenRadius<TPoint, TDetComputer>::
 
  160finalizeComputation () const
 
  162  //squared denominator
 
  163  myComputedDen2 = 4*myArea*myArea;
 
  166  myQRnorm = myQR0*myQR0 + myQR1*myQR1; 
 
  167  //myQRnorm must not be greater than the squared diameter, ie. 4 * myNum2 / myDen2
 
  168  ASSERT( lengthIsValid( myQRnorm ) ); 
 
  170  myRPnorm = myRP0*myRP0 + myRP1*myRP1;
 
  171  //myRPnorm should be the greatest norm
 
  172  ASSERT( (myRPnorm >= myPQnorm)&&(myRPnorm >= myQRnorm) ); 
 
  174  myComputedNum2 = myPQnorm*myQRnorm*myRPnorm; 
 
  177// ----------------------------------------------------------------------------
 
  178template <typename TPoint, typename TDetComputer>
 
  181DGtal::InGeneralizedDiskOfGivenRadius<TPoint, TDetComputer>::
 
  182selfDisplay ( std::ostream & out ) const
 
  184  out << "[InGeneralizedDiskOfGivenRadius]" << std::endl;
 
  185  out << " radius: sqrt(" << myNum2 << "/" << myDen2 << ")"; 
 
  193// ----------------------------------------------------------------------------
 
  194template <typename TPoint, typename TDetComputer>
 
  197DGtal::InGeneralizedDiskOfGivenRadius<TPoint, TDetComputer>::
 
  198lengthIsValid(const Integer& aL2) const
 
  200  if (myDen2 == NumberTraits<Integer>::ZERO)
 
  203    return ( myDetComputer( 4, aL2 ) <= 0 );
 
  206// ----------------------------------------------------------------------------
 
  207template <typename TPoint, typename TDetComputer>
 
  210DGtal::InGeneralizedDiskOfGivenRadius<TPoint, TDetComputer>::
 
  213  return ( (myNum2 > NumberTraits<Integer>::ZERO) &&
 
  214           (myDen2 >= NumberTraits<Integer>::ZERO) ); 
 
  219///////////////////////////////////////////////////////////////////////////////
 
  220// Implementation of inline functions                                        //
 
  221template <typename TPoint, typename TDetComputer>
 
  224DGtal::operator<< ( std::ostream & out, 
 
  225                    const InGeneralizedDiskOfGivenRadius<TPoint, TDetComputer> & object )
 
  227  object.selfDisplay( out );
 
  232///////////////////////////////////////////////////////////////////////////////