BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Straight_skeleton_2/debug.h
Go to the documentation of this file.
00001 // Copyright (c) 2007 Fernando Luis Cacciola Carballal. All rights reserved.
00002 //
00003 // This file is part of CGAL (www.cgal.org); you may redistribute it under
00004 // the terms of the Q Public License version 1.0.
00005 // See the file LICENSE.QPL distributed with CGAL.
00006 //
00007 // Licensees holding a valid commercial license may use this file in
00008 // accordance with the commercial license agreement provided with the software.
00009 //
00010 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00011 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00012 //
00013 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Straight_skeleton_2/include/CGAL/Straight_skeleton_2/debug.h $
00014 // $Id: debug.h 44646 2008-07-30 12:40:57Z spion $
00015 // 
00016 // Author(s)     : Fernando Cacciola <fernando_cacciola@ciudad.com.ar>
00017 
00018 #ifndef CGAL_STRAIGHT_SKELETON_DEBUG_H
00019 #define CGAL_STRAIGHT_SKELETON_DEBUG_H 1
00020 
00021 #ifdef CGAL_USE_CORE
00022 #  include <CGAL/CORE_BigFloat.h>
00023 #endif
00024 
00025 #if    defined(CGAL_STRAIGHT_SKELETON_ENABLE_TRACE) \
00026     || defined(CGAL_POLYGON_OFFSET_ENABLE_TRACE) \
00027     || defined(CGAL_STRAIGHT_SKELETON_TRAITS_ENABLE_TRACE) \
00028     || defined(CGAL_STRAIGHT_SKELETON_ENABLE_VALIDITY_TRACE) \
00029     || defined(CGAL_STRAIGHT_SKELETON_ENABLE_INTRINSIC_TESTING)
00030 #
00031 #  define CGAL_STSKEL_TRACE_ON
00032 #
00033 #  include<string>
00034 #  include<iostream>
00035 #  include<sstream>
00036 #  include<iomanip>
00037 #  define CGAL_STSKEL_TRACE(m) \
00038      { \
00039        std::ostringstream ss ; \
00040        ss << m ; \
00041        std::string s = ss.str(); \
00042        Straight_skeleton_external_trace(s); \
00043      }
00044 
00045 template<class T>
00046 inline std::string o2str( boost::optional<T> const& o )
00047 {
00048   std::ostringstream ss ; ss << std::setprecision(19)  ;
00049   if ( o )
00050        ss << *o ;
00051   else ss << "·NONE·" ;
00052   return ss.str();
00053 }
00054 
00055 template<class T>
00056 inline std::string ptr2str( boost::intrusive_ptr<T> const& ptr )
00057 {
00058   std::ostringstream ss ; ss << std::setprecision(19)  ;
00059   if ( ptr )
00060        ss << *ptr ;
00061   else ss << "·NULL·" ;
00062   return ss.str();
00063 }
00064 
00065 template<class N>
00066 inline std::string n2str( N const& n )
00067 {
00068   std::ostringstream ss ; ss << std::setprecision(19)  ;
00069   
00070   ss << CGAL_NTS to_double(n) ;
00071   
00072   return ss.str();
00073 }
00074 
00075 
00076 #if 0 //CGAL_USE_CORE
00077 
00078 inline CORE::BigFloat to_big_float( CGAL::MP_Float const& n )
00079 {
00080   return n.to_rational<CORE::BigFloat>() ;
00081 }
00082 
00083 inline CORE::BigFloat to_big_float( CGAL::Quotient<CGAL::MP_Float> const& q )
00084 {
00085   CORE::BigFloat n = to_big_float(q.numerator  ()) ;
00086   CORE::BigFloat d = to_big_float(q.denominator()) ;
00087   if ( !d.isZeroIn())
00088        return n / d ;
00089   else return CORE::BigFloat(std::numeric_limits<double>::infinity());
00090 }
00091 
00092 template<class NT>
00093 inline CORE::BigFloat to_big_float( NT const& n )
00094 {
00095   return CORE::BigFloat( CGAL_NTS to_double(n) ) ;
00096 }
00097 
00098 
00099 inline std::string n2str( CGAL::MP_Float const& n )
00100 {
00101   std::ostringstream ss ; 
00102   ss << to_big_float(n) ;
00103   return ss.str();
00104 }
00105 
00106 inline std::string n2str( CGAL::Quotient< CGAL::MP_Float > const& n )
00107 {
00108   std::ostringstream ss ; 
00109   ss << to_big_float(n) ;
00110   return ss.str();
00111 }
00112 #else
00113 inline std::string n2str( CGAL::MP_Float const& n )
00114 {
00115   std::ostringstream ss ; ss << std::setprecision(19) ;
00116   ss << CGAL_NTS to_double(n) ;
00117   return ss.str();
00118 }
00119 
00120 inline std::string n2str( CGAL::Quotient< CGAL::MP_Float > const& n )
00121 {
00122   std::ostringstream ss ; ss << std::setprecision(19)  ;
00123   ss << CGAL_NTS to_double(n) ;
00124   return ss.str();
00125 }
00126 #endif
00127 
00128 template<class XY>
00129 inline std::string xy2str( XY const& xy )
00130 {
00131   std::ostringstream ss ; 
00132   ss << "(" << n2str(xy.x()) << "," << n2str(xy.y()) << ")" ;
00133   return ss.str();
00134 }
00135 template<class D>
00136 inline std::string dir2str( D const& d )
00137 {
00138   std::ostringstream ss ; 
00139   ss << "(" << n2str(d.dx()) << "," << n2str(d.dy()) << ")" ;
00140   return ss.str();
00141 }
00142 template<class P>
00143 inline std::string p2str( P const& p )
00144 {
00145   std::ostringstream ss ; 
00146   ss << "(" << n2str(p.x()) << "," << n2str(p.y()) << ")" ;
00147   return ss.str();
00148 }
00149 template<class OP>
00150 inline std::string op2str( OP const& op )
00151 {
00152   return op ? p2str(*op) : std::string("·NONE·");
00153 }
00154 template<class V>
00155 inline std::string v2str( V const& v )
00156 {
00157   std::ostringstream ss ; ss << std::setprecision(19)  ;
00158   ss << "V" << v.id() << " " << p2str(v.point()) << " [" << v.time() << "]" ;
00159   return ss.str();
00160 }
00161 template<class VH>
00162 inline std::string vh2str( VH const& vh )
00163 {
00164   VH null ;
00165   return vh != null ? v2str(*vh) : "NULL_VERTEX_HANDLE" ;
00166 }
00167 
00168 template<class P>
00169 inline std::string s2str( P const& s, P const& t )
00170 {
00171   std::ostringstream ss ; 
00172   ss << "{" << p2str(s) << "-" << p2str(t) << "}" ;
00173   return ss.str();
00174 }
00175 
00176 template<class S>
00177 inline std::string s2str( S const& seg ) { return s2str(seg.source(),seg.target()); }
00178 
00179 template<class E>
00180 inline std::string e2str( E const& e )
00181 {
00182   std::ostringstream ss ; ss << std::setprecision(19)  ;
00183   if ( e.is_bisector() )
00184   {
00185     ss << "B" << e.id()
00186        << "[E" << e.defining_contour_edge()->id() 
00187        << ",E" << e.opposite()->defining_contour_edge()->id() << "]"
00188        << " (/" << ( e.slope() == CGAL::ZERO ? "·" : ( e.slope() == CGAL::NEGATIVE ? "-" : "+" ) )
00189        << " " << e.opposite()->vertex()->time() << "->" << e.vertex()->time() << ")" ; 
00190   }
00191   else
00192   {
00193     ss << "E" << e.id() ;
00194   }
00195   ss << " " << s2str(e.opposite()->vertex()->point(),e.vertex()->point()) ;
00196   return ss.str();
00197 }
00198 
00199 template<class EH>
00200 inline std::string eh2str( EH const& eh )
00201 {
00202   EH null ;
00203   return eh != null ? e2str(*eh) : "NULL_HALFEDGE_HANDLE" ;
00204 }
00205 
00206 template<class BH>
00207 inline std::string newb2str( char const* name, BH const& b )
00208 {
00209   std::ostringstream ss ; 
00210   
00211   ss << "New Bisector " 
00212      << name 
00213      << " is B" << b->id()
00214      << " [E" << b->defining_contour_edge()->id() 
00215      << ",E" << b->opposite()->defining_contour_edge()->id()
00216      << "] {B" << b->prev()->id() 
00217      << "->N"  << b->prev()->vertex()->id() 
00218      << "->B" << b->id() 
00219      << "->N" << b->vertex()->id() 
00220      << "->B" << b->next()->id()
00221      << "}" ;
00222      
00223   return ss.str();
00224 }
00225 
00226 template<class VH, class Triedge>
00227 inline std::string newn2str( char const* name, VH const& v, Triedge const& aTriedge )
00228 {
00229   std::ostringstream ss ; 
00230 
00231   ss << "New Node " << name <<" is N" << v->id() << " at " << v->point()
00232      << " [E" << aTriedge.e0()->id()
00233      << ",E" << aTriedge.e1()->id()
00234      << ",E" << aTriedge.e2()->id()
00235      << "] incident halfedge: B" << v->halfedge()->id()
00236      << "  primary bisector: B" << v->primary_bisector()->id() ;
00237      
00238   return ss.str();
00239 }
00240 
00241 #endif
00242 
00243 #ifdef CGAL_STRAIGHT_SKELETON_ENABLE_TRACE
00244 #  define CGAL_STSKEL_DEBUG_CODE(code) code
00245 #  define CGAL_STSKEL_BUILDER_TRACE(l,m) if ( l <= CGAL_STRAIGHT_SKELETON_ENABLE_TRACE ) CGAL_STSKEL_TRACE(m)
00246 #  define CGAL_STSKEL_BUILDER_TRACE_IF(c,l,m) if ( (c) && l <= CGAL_STRAIGHT_SKELETON_ENABLE_TRACE ) CGAL_STSKEL_TRACE(m)
00247 #else
00248 #  define CGAL_STSKEL_DEBUG_CODE(code) 
00249 #  define CGAL_STSKEL_BUILDER_TRACE(l,m)
00250 #  define CGAL_STSKEL_BUILDER_TRACE_IF(c,l,m)
00251 #endif
00252 
00253 #ifdef CGAL_POLYGON_OFFSET_ENABLE_TRACE
00254 #  define CGAL_POLYOFFSET_DEBUG_CODE(code) code
00255 #  define CGAL_POLYOFFSET_TRACE(l,m) if ( l <= CGAL_POLYGON_OFFSET_ENABLE_TRACE ) CGAL_STSKEL_TRACE(m)
00256 #else
00257 #  define CGAL_POLYOFFSET_DEBUG_CODE(code)
00258 #  define CGAL_POLYOFFSET_TRACE(l,m)
00259 #endif
00260 
00261 #ifdef CGAL_STRAIGHT_SKELETON_TRAITS_ENABLE_TRACE
00262 bool sEnableTraitsTrace = false ;
00263 #  define CGAL_STSKEL_TRAITS_ENABLE_TRACE sEnableTraitsTrace = true ;
00264 #  define CGAL_STSKEL_TRAITS_ENABLE_TRACE_IF(cond) if ((cond)) sEnableTraitsTrace = true ;
00265 #  define CGAL_STSKEL_TRAITS_DISABLE_TRACE sEnableTraitsTrace = false;
00266 #  define CGAL_STSKEL_TRAITS_TRACE(m) \
00267      if ( sEnableTraitsTrace ) \
00268      { \
00269        std::ostringstream ss ; \
00270        ss << m ; \
00271        std::string s = ss.str(); \
00272        Straight_skeleton_traits_external_trace(s); \
00273      }
00274 #else
00275 #  define CGAL_STSKEL_TRAITS_ENABLE_TRACE
00276 #  define CGAL_STSKEL_TRAITS_ENABLE_TRACE_IF(cond)
00277 #  define CGAL_STSKEL_TRAITS_DISABLE_TRACE
00278 #  define CGAL_STSKEL_TRAITS_TRACE(m)
00279 #endif
00280 
00281 
00282 #ifdef CGAL_STRAIGHT_SKELETON_ENABLE_VALIDITY_TRACE
00283 #  define CGAL_STSKEL_VALIDITY_TRACE(m) CGAL_STSKEL_TRACE(m)
00284 #  define CGAL_STSKEL_VALIDITY_TRACE_IF(cond,m) if ( cond ) CGAL_STSKEL_VALIDITY_TRACE(m)
00285 #else
00286 #  define CGAL_STSKEL_VALIDITY_TRACE(m) 
00287 #  define CGAL_STSKEL_VALIDITY_TRACE_IF(cond,m)
00288 #endif
00289 
00290 
00291 #ifdef CGAL_STRAIGHT_SKELETON_PROFILING_ENABLED // Reserved use. DO NOT define this macro switch
00292 #  include<string>
00293 #  include<iostream>
00294 #  include<sstream>
00295 
00296 CGAL_BEGIN_NAMESPACE
00297 
00298 namespace CGAL_STRAIGHT_SKELETON_i_profiling
00299 {
00300 
00301 template<class NT> char const* kernel_type() { return typeid(NT).name() ; }
00302 
00303 template<> char const* kernel_type<double>              () { return "double" ;   }
00304 template<> char const* kernel_type<Interval_nt_advanced>() { return "Interval" ; }
00305 template<> char const* kernel_type< Quotient<MP_Float> >() { return "MP_Float" ; }
00306 template<> char const* kernel_type<CORE::Expr>          () { return "Expr" ;     }
00307 
00308 } // CGAL_STRAIGHT_SKELETON_i_profiling
00309 
00310 CGAL_END_NAMESPACE
00311 
00312 #define CGAL_STSKEL_ASSERT_PREDICATE_RESULT(expr,K,pred,error) \
00313         { \
00314           std::ostringstream predss ; \
00315           predss << CGAL_STRAIGHT_SKELETON_i_profiling::kernel_type< typename K::FT >() << " . " << pred ; \
00316           std::string preds = predss.str(); \
00317           if ( ! is_certain((expr)) ) \
00318           { \
00319             std::ostringstream errss  ; errss << error ; std::string errs = errss.str(); \
00320             register_predicate_failure(preds,errs); \
00321           } \
00322           else register_predicate_success(preds); \
00323         }
00324 
00325 #define CGAL_STSKEL_ASSERT_CONSTRUCTION_RESULT(expr,K,cons,error) \
00326         { \
00327           std::ostringstream consss ; \
00328           consss << CGAL_STRAIGHT_SKELETON_i_profiling::kernel_type< typename K::FT >() << " . " << cons ; \
00329           std::string conss = consss.str(); \
00330           if ( !(expr) ) \
00331           { \
00332             std::ostringstream errss  ; errss << error ; std::string errs = errss.str(); \
00333             register_construction_failure(conss,errs); \
00334           } \
00335           else register_construction_success(conss); \
00336         }
00337 #else
00338 
00339 #define CGAL_STSKEL_ASSERT_PREDICATE_RESULT(expr,K,pred,error)
00340 #define CGAL_STSKEL_ASSERT_CONSTRUCTION_RESULT(expr,K,cons,error)
00341 
00342 #endif
00343 
00344 #undef CGAL_STSKEL_ENABLE_TRACE
00345 
00346 #endif // CGAL_STRAIGHT_SKELETON_DEBUG_H //
00347 // EOF //
00348 
00349  
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines