From ac827088151dbe46e516532faf38ba83f073f6fa Mon Sep 17 00:00:00 2001 From: Fernando Cacciola Date: Tue, 8 Apr 2008 19:33:11 +0000 Subject: [PATCH] General compilation fixes for VC++ --- .../Straight_skeleton_2/StraightSkeleton.cpp | 295 ++++++++---------- .../Straight_skeleton_2/StraightSkeleton.h | 34 +- .../include/CGAL/Create_straight_skeleton_2.h | 8 +- .../include/CGAL/IO/Dxf_stream.h | 34 +- .../include/CGAL/IO/Dxf_writer.h | 3 +- .../Straight_skeleton_cons_ftC2.h | 18 +- 6 files changed, 187 insertions(+), 205 deletions(-) diff --git a/Straight_skeleton_2/dll/Straight_skeleton_2/StraightSkeleton.cpp b/Straight_skeleton_2/dll/Straight_skeleton_2/StraightSkeleton.cpp index e8b854bf901..6498d53cbf5 100644 --- a/Straight_skeleton_2/dll/Straight_skeleton_2/StraightSkeleton.cpp +++ b/Straight_skeleton_2/dll/Straight_skeleton_2/StraightSkeleton.cpp @@ -38,43 +38,43 @@ struct Visitor { ++ mCurr ; if ( Progress ) - Progress(mCurr,mTotal); + Progress(mCurr,mTotal); } void on_edge_event_created( Vertex_const_handle const& lnode - , Vertex_const_handle const& rnode - ) const {} + , Vertex_const_handle const& rnode + ) const {} void on_split_event_created( Vertex_const_handle const& node ) const {} void on_pseudo_split_event_created( Vertex_const_handle const& lnode - , Vertex_const_handle const& rnode - ) const {} + , Vertex_const_handle const& rnode + ) const {} void on_initialization_finished() const {} void on_propagation_started() const {} void on_anihiliation_event_processed ( Vertex_const_handle const& node0 - , Vertex_const_handle const& node1 - ) const {} + , Vertex_const_handle const& node1 + ) const {} void on_edge_event_processed( Vertex_const_handle const& lseed - , Vertex_const_handle const& rseed - , Vertex_const_handle const& node - ) const {} + , Vertex_const_handle const& rseed + , Vertex_const_handle const& node + ) const {} void on_split_event_processed( Vertex_const_handle const& seed - , Vertex_const_handle const& node0 - , Vertex_const_handle const& node1 - ) const {} + , Vertex_const_handle const& node0 + , Vertex_const_handle const& node1 + ) const {} void on_pseudo_split_event_processed( Vertex_const_handle const& lseed - , Vertex_const_handle const& rseed - , Vertex_const_handle const& node0 - , Vertex_const_handle const& node1 - ) const {} + , Vertex_const_handle const& rseed + , Vertex_const_handle const& node0 + , Vertex_const_handle const& node1 + ) const {} void on_vertex_processed( Vertex_const_handle const& node ) const { @@ -82,7 +82,7 @@ struct Visitor { ++ mCurr ; if ( Progress ) - Progress(mCurr,mTotal); + Progress(mCurr,mTotal); } } @@ -119,79 +119,80 @@ typedef CGAL::Bbox_2 Bbox_2; extern "C" { -void STRAIGHT_SKELETON_API StraightSkeletonFree(int* numFace_i, double* xf, double* yf) -{ - delete [] xf; - delete [] yf; - delete [] numFace_i; -} - -int STRAIGHT_SKELETON_API StraightSkeleton( int np - , int* np_i - , double* xp - , double* yp - , int& numFaces - , int& numVertices - , int*& numFace_i - , double*& xf - , double*& yf - , int dumpEPS - , ProgressCallback progress - ) -{ - int result = 0 ; - - numFace_i = NULL ; - xf = yf = NULL ; - - try + void __declspec (dllexport) StraightSkeletonFree(int* numFace_i, double* xf, double* yf) { - double scale = 1.0; + delete [] xf; + delete [] yf; + delete [] numFace_i; + } - SsBuilderTraits traits ; - Visitor visitor(progress) ; - SsBuilder ssb(traits,visitor) ; + int __declspec (dllexport) StraightSkeleton( int np + , int* np_i + , double* xp + , double* yp + , int& numFaces + , int& numVertices + , int*& numFace_i + , double*& xf + , double*& yf + , int dumpEPS + , ProgressCallback progress + ) + { + int result = 0 ; - Bbox_2 bbox; - - int currentPoint = 0; - for(int i = 0; i < np; i++) + numFace_i = NULL ; + xf = yf = NULL ; + + try { - std::vector points(np_i[i]); - for(int j=0; j < np_i[i]; j++) + double scale = 1.0; + + SsBuilderTraits traits ; + Visitor visitor(progress) ; + SsBuilder ssb(traits,visitor) ; + + Bbox_2 bbox; + + int currentPoint = 0; + for(int i = 0; i < np; i++) { - Point_2 p(xp[currentPoint], yp[currentPoint]); - if(currentPoint == 0) - bbox = p.bbox() ; - else bbox = bbox + p.bbox(); + int s = np_i[i]; + std::vector points(s); + for(int j=0; j < s; j++) + { + Point_2 p(xp[currentPoint], yp[currentPoint]); + if(currentPoint == 0) + bbox = p.bbox() ; + else bbox = bbox + p.bbox(); - points[j] = p; - ++currentPoint; - } + points[j] = p; + ++currentPoint; + } - if( ! CGAL::is_simple_2(points.begin(),points.end())) - { - std::cerr << "Polygon " << i << " is not simple" << std::endl; - return 0; - } + if( ! CGAL::is_simple_2(points.begin(),points.end())) + { + std::cerr << "Polygon " << i << " is not simple" << std::endl; + return 0; + } - if( CGAL::orientation_2(points.begin(),points.end()) != ( i == 0 ? CGAL::COUNTERCLOCKWISE - : CGAL::CLOCKWISE - ) - ) - ssb.enter_contour(points.rbegin(),points.rend()); - else ssb.enter_contour(points.begin(),points.end()); - } + if( CGAL::orientation_2(points.begin(),points.end()) != ( i == 0 ? CGAL::COUNTERCLOCKWISE + : CGAL::CLOCKWISE + ) + ) + ssb.enter_contour(points.rbegin(),points.rend()); + else ssb.enter_contour(points.begin(),points.end()); + } - visitor.set_total(currentPoint*2); + visitor.set_total(currentPoint*2); - // Construct the skeleton - boost::shared_ptr ss = ssb.construct_skeleton(); + // Construct the skeleton + boost::shared_ptr ss = ssb.construct_skeleton(); - // Proceed only if the skeleton was correctly constructed. - if ( ss ) - { + // Proceed only if the skeleton was correctly constructed. + if ( ss ) + { // We first count the points numFaces= (int)ss->size_of_faces(); numFace_i = new int[numFaces]; @@ -200,21 +201,21 @@ int STRAIGHT_SKELETON_API StraightSkeleton( int np int currentFace = 0; for(Face_iterator fit = ss->faces_begin(); fit != ss->faces_end(); ++fit) { - int count = 0; + int count = 0; Halfedge_handle h = fit->halfedge(); - Halfedge_handle done; - done = h; - do + Halfedge_handle done; + done = h; + do { - count++; + count++; h = h->next(); - } while(h != done); - numVertices += count; + } while(h != done); + numVertices += count; - numFace_i[currentFace] = count; - ++currentFace; + numFace_i[currentFace] = count; + ++currentFace; } - + // Allocate the x and y array and traverse the faces again xf = new double[numVertices]; yf = new double[numVertices]; @@ -223,97 +224,75 @@ int STRAIGHT_SKELETON_API StraightSkeleton( int np for(Face_iterator fit = ss->faces_begin(); fit != ss->faces_end(); ++fit) { - Halfedge_handle h = fit->halfedge(); - Halfedge_handle done; - done = h; - do + Halfedge_handle h = fit->halfedge(); + Halfedge_handle done; + done = h; + do { - xf[currentVertex] = h->vertex()->point().x(); - yf[currentVertex] = h->vertex()->point().y(); + xf[currentVertex] = h->vertex()->point().x(); + yf[currentVertex] = h->vertex()->point().y(); ++currentVertex; h = h->next(); - } + } while(h != done); } -int vi = 0 ; -for ( int fi = 0 ; fi < numFaces ; ++ fi ) -{ - double firstx = xf[vi] ; - double firsty = yf[vi]; - - double lastx ; - double lasty ; - - for ( int fvi = 0 ; fvi < numFace_i[fi] ; ++ fvi ) - { - lastx = xf[vi]; - lasty = yf[vi]; - ++ vi ; - } - - std::cout << "face " << fi << " edge: (" << firstx << "," << firsty << ")->(" << lastx << "," << lasty << ")\n" ; - - //Face_handle fh = *(ss->faces_begin()+fi); - -} if(dumpEPS) { scale = 1000 / (bbox.xmax() - bbox.xmin()) ; - std::ofstream dump("dump.eps"); - dump << "%!PS-Adobe-2.0 EPSF-2.0\n%%BoundingBox:" << scale* bbox.xmin()-1 << " " << scale* bbox.ymin()-1 << " " << scale*bbox.xmax()+1 << " " << scale*bbox.ymax()+1 << std::endl; - dump << "%%EndComments\n" - "gsave\n" - "1.0 setlinewidth\n" - "/cont { 0 0 0 setrgbcolor } bind def\n" - "/cont_w { 0.1 setlinewidth } bind def\n" - "/skel { 1 0 0 setrgbcolor } bind def\n" - "/skel_w { 1.0 setlinewidth } bind def\n" - "% stroke - x1 y1 x2 y2 E\n" - "/E {newpath moveto lineto stroke} bind def\n" << std::endl; + std::ofstream dump("dump.eps"); + dump << "%!PS-Adobe-2.0 EPSF-2.0\n%%BoundingBox:" << scale* bbox.xmin()-1 << " " << scale* bbox.ymin()-1 << " " << scale*bbox.xmax()+1 << " " << scale*bbox.ymax()+1 << std::endl; + dump << "%%EndComments\n" + "gsave\n" + "1.0 setlinewidth\n" + "/cont { 0 0 0 setrgbcolor } bind def\n" + "/cont_w { 0.1 setlinewidth } bind def\n" + "/skel { 1 0 0 setrgbcolor } bind def\n" + "/skel_w { 1.0 setlinewidth } bind def\n" + "% stroke - x1 y1 x2 y2 E\n" + "/E {newpath moveto lineto stroke} bind def\n" << std::endl; - for(Face_iterator fit = ss->faces_begin(); fit != ss->faces_end(); ++fit) + for(Face_iterator fit = ss->faces_begin(); fit != ss->faces_end(); ++fit) { - Halfedge_handle h = fit->halfedge(); - Halfedge_handle done; - done = h; - do + Halfedge_handle h = fit->halfedge(); + Halfedge_handle done; + done = h; + do { - if(h->is_bisector()) - dump << "skel\n"; - else dump << "cont\n"; - - dump << scale* h->vertex()->point().x() << " " << scale*h->vertex()->point().y() << " " - << scale*h->opposite()->vertex()->point().x() << " " + if(h->is_bisector()) + dump << "skel\n"; + else dump << "cont\n"; + + dump << scale* h->vertex()->point().x() << " " << scale*h->vertex()->point().y() << " " + << scale*h->opposite()->vertex()->point().x() << " " << scale*h->opposite()->vertex()->point().y() << " E\n"; - h = h->next(); - } + h = h->next(); + } while(h != done); - } + } - dump << "grestore\nshowpage" << std::endl; + dump << "grestore\nshowpage" << std::endl; - dump.close(); + dump.close(); } - result = 1 ; + } + } + catch ( std::exception const& e ) + { + std::cerr << "Exception thrown: " << e.what() << std::endl ; + StraightSkeletonFree(numFace_i,xf,yf); + } + catch ( ... ) + { + std::cerr << "Unknown exception thrown." << std::endl ; + StraightSkeletonFree(numFace_i,xf,yf); } - } - catch ( std::exception const& e ) - { - std::cerr << "Exception thrown: " << e.what() << std::endl ; - StraightSkeletonFree(numFace_i,xf,yf); - } - catch ( ... ) - { - std::cerr << "Unknown exception thrown." << std::endl ; - StraightSkeletonFree(numFace_i,xf,yf); - } - return result ; -} + return result ; + } } // extern "C" diff --git a/Straight_skeleton_2/dll/Straight_skeleton_2/StraightSkeleton.h b/Straight_skeleton_2/dll/Straight_skeleton_2/StraightSkeleton.h index 05179ce52f9..a93bc940c81 100644 --- a/Straight_skeleton_2/dll/Straight_skeleton_2/StraightSkeleton.h +++ b/Straight_skeleton_2/dll/Straight_skeleton_2/StraightSkeleton.h @@ -1,12 +1,6 @@ -#ifndef STRAIGHT_SKELETON_H +#ifndef STRAIGHT_SKELETON_H #define STRAIGHT_SKELETON_H -#ifdef STRAIGHTSKELETONDLL_EXPORTS -# define STRAIGHT_SKELETON_API __declspec (dllexport) -#else -# define STRAIGHT_SKELETON_API __declspec (dllimport) -#endif - /*! \file StraightSkeleton.h \brief Functions for computing the straight skeleton of a simple polygon with holes. @@ -46,18 +40,18 @@ typedef void (__stdcall *ProgressCallback) ( int aCurr, int aTotal ) ; extern "C" { -int STRAIGHT_SKELETON_API StraightSkeleton( int np - , int* np_i - , double* xp - , double* yp - , int& numFaces - , int& numVertices - , int*& numFace_i - , double*& xf - , double*& yf - , int dumpEPS - , ProgressCallback progress - ); +int __declspec (dllexport) StraightSkeleton( int np + , int* np_i + , double* xp + , double* yp + , int& numFaces + , int& numVertices + , int*& numFace_i + , double*& xf + , double*& yf + , int dumpEPS + , ProgressCallback progress + ); /** @@ -67,7 +61,7 @@ int STRAIGHT_SKELETON_API StraightSkeleton( int np * @param yf is a reference parameter. After the call it holds NULL. */ -void STRAIGHT_SKELETON_API StraightSkeletonFree(int* numFace_i, double* xf, double* yf ); +void __declspec (dllexport) StraightSkeletonFree(int* numFace_i, double* xf, double* yf ); } // extern "C" diff --git a/Straight_skeleton_2/include/CGAL/Create_straight_skeleton_2.h b/Straight_skeleton_2/include/CGAL/Create_straight_skeleton_2.h index 3895624b504..6cad5983051 100644 --- a/Straight_skeleton_2/include/CGAL/Create_straight_skeleton_2.h +++ b/Straight_skeleton_2/include/CGAL/Create_straight_skeleton_2.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 Fernando Luis Cacciola Carballal. All rights reserved. +// Copyright (c) 2006 Fernando Luis Cacciola Carballal. All rights reserved. // // This file is part of CGAL (www.cgal.org); you may redistribute it under // the terms of the Q Public License version 1.0. @@ -43,6 +43,12 @@ template inline typename Polygon_2::Vertex_const_iterator vertices_end( Polygon_2 const& aPoly ) { return aPoly.vertices_end() ; } +template +inline typename Poly::const_iterator vertices_begin ( boost::shared_ptr const& aPoly ) { return aPoly->begin() ; } + +template +inline typename Poly::const_iterator vertices_end ( boost::shared_ptr const& aPoly ) { return aPoly->end() ; } + } template diff --git a/Straight_skeleton_2/include/CGAL/IO/Dxf_stream.h b/Straight_skeleton_2/include/CGAL/IO/Dxf_stream.h index 4e915950842..dc6fc56b3a8 100644 --- a/Straight_skeleton_2/include/CGAL/IO/Dxf_stream.h +++ b/Straight_skeleton_2/include/CGAL/IO/Dxf_stream.h @@ -30,7 +30,7 @@ #include #include -#include +#include CGAL_BEGIN_NAMESPACE @@ -38,7 +38,7 @@ class Dxf_layer { public: - Dxf_layer( string aStr ) : mStr(aStr) {} + Dxf_layer( std::string aStr ) : mStr(aStr) {} std::string str() const { return mStr ; } @@ -55,15 +55,15 @@ public: typedef Kernel_ Kernel; // Define the kernel objects. - typedef typename Kernel::FT NT; - typedef typename Kernel::Point_2 Point; - typedef typename Kernel::Segment_2 Segment; - typedef typename Kernel::Ray_2 Ray; - typedef typename Kernel::Line_2 Line; - typedef typename Kernel::Triangle_2 Triangle; - typedef typename Kernel::Iso_rectangle_2 Iso_rectangle; - typedef typename Kernel::Circle_2 Circle; - typedef CGAL::Polygon_2 Polygon; + typedef typename Kernel::FT NT; + typedef typename Kernel::Point_2 Point_2; + typedef typename Kernel::Segment_2 Segment_2; + typedef typename Kernel::Ray_2 Ray_2; + typedef typename Kernel::Line_2 Line_2; + typedef typename Kernel::Triangle_2 Triangle_2; + typedef typename Kernel::Iso_rectangle_2 Iso_rectangle_2; + typedef Polygon_2 Polygon_2; + typedef typename Kernel::Circle_2 Circle_2; protected: @@ -106,7 +106,7 @@ public: * Constructor. * \param filename The name of the output FIG file. */ - Dxf_stream ( ostream& out ) + Dxf_stream ( std::ostream& out ) : mWriter (out) ,mDefaultDxfColor (255) @@ -152,7 +152,7 @@ public: /*! * Set the current layer. */ - void set_layer ( string aLayer ) { mLayer = aLayer ; } + void set_layer ( std::string aLayer ) { mLayer = aLayer ; } /*! * Set the current color. @@ -196,7 +196,7 @@ public: /*! * Write a 2D segment. */ - void write_segment_2 (const Segment& seg) + void write_segment_2 (const Segment_2& seg) { mWriter.add_segment_2( seg.source(), seg.target(), mLayer, mDxfColor ) ; } @@ -249,7 +249,7 @@ public: /*! * Write a 2D (closed) polygon. */ - void write_polygon (const Polygon& pgn) + void write_polygon (const Polygon_2& pgn) { mWriter.add_polyline_2( pgn.begin(), pgn.end(), true, mLayer, mDxfColor ) ; } @@ -283,7 +283,7 @@ public: /*! * Write a line segment. */ - Dxf_stream& operator<< (const Segment& seg) + Dxf_stream& operator<< (const Segment_2& seg) { write_segment_2 (seg); return (*this); @@ -292,7 +292,7 @@ public: /*! * Write a polygon. */ - Dxf_stream& operator<< (const Polygon& pgn) + Dxf_stream& operator<< (const Polygon_2& pgn) { write_polygon_2 (pgn); return (*this); diff --git a/Straight_skeleton_2/include/CGAL/IO/Dxf_writer.h b/Straight_skeleton_2/include/CGAL/IO/Dxf_writer.h index 16d4ee8740d..e0278da4b4c 100644 --- a/Straight_skeleton_2/include/CGAL/IO/Dxf_writer.h +++ b/Straight_skeleton_2/include/CGAL/IO/Dxf_writer.h @@ -25,6 +25,7 @@ #define CGAL_IO_DXF_WRITER_H #include +#include #include #include #include @@ -121,7 +122,7 @@ public: while ( lCurrVertex != aVerticesEnd ) { - XY_Iterator lNextVertex = ( lCurrVertex == lLastVertex ? lFirstVertex : successor(lCurrVertex) ) ; + XY_Iterator lNextVertex = ( lCurrVertex == lLastVertex ? lFirstVertex : CGAL::successor(lCurrVertex) ) ; add_segment_2 ( *lCurrVertex, *lNextVertex, aLayer, aColor ) ; diff --git a/Straight_skeleton_2/include/CGAL/constructions/Straight_skeleton_cons_ftC2.h b/Straight_skeleton_2/include/CGAL/constructions/Straight_skeleton_cons_ftC2.h index 15edee544e7..0acd720fed7 100644 --- a/Straight_skeleton_2/include/CGAL/constructions/Straight_skeleton_cons_ftC2.h +++ b/Straight_skeleton_2/include/CGAL/constructions/Straight_skeleton_cons_ftC2.h @@ -49,7 +49,8 @@ inline CORE::BigFloat MP_Float_to_BigFloat( MP_Float const& b ) d += d_exp * CORE::BigFloat(b.of_exp(i)); } - return d * CORE::BigFloat::exp2(exp * log_limb); + // The cast is necessary for SunPro. + return d * CORE::BigFloat::exp2(static_cast(exp * log_limb)); } #endif @@ -63,7 +64,7 @@ inline MP_Float inexact_sqrt( MP_Float const& n ) { CGAL_precondition(n > 0); -#ifdef CGAL_USE_CORE +#ifdef CGAL_USE_CORE CORE::BigFloat nn = MP_Float_to_BigFloat(n); CORE::BigFloat s = CORE::sqrt(nn); @@ -89,13 +90,15 @@ inline Quotient inexact_sqrt( Quotient const& q ) return Quotient(CGAL_SS_i::inexact_sqrt(q.numerator()*q.denominator()), q.denominator() ); } -inline Lazy_exact_nt inexact_sqrt( Lazy_exact_nt const& n ) +template +inline Lazy_exact_nt inexact_sqrt( Lazy_exact_nt const& n ) { -#ifdef CGAL_USE_CORE + +#ifdef CGAL_USE_CORE CORE::BigFloat nn = CGAL::to_double(n) ; CORE::BigFloat s = CORE::sqrt(nn); - return Lazy_exact_nt(s.doubleValue()); + return Lazy_exact_nt(s.doubleValue()); #else @@ -108,12 +111,11 @@ inline Lazy_exact_nt inexact_sqrt( Lazy_exact_nt const& n ) double s = CGAL_NTS sqrt(nn); - return Lazy_exact_nt(s); + return Lazy_exact_nt(s); + #endif } - - // Given an oriented 2D straight line segment 'e', computes the normalized coefficients (a,b,c) of the // supporting line. // POSTCONDITION: [a,b] is the leftward normal _unit_ (a�+b�=1) vector.