From 490a726ec052ff438d42bf0449b3ead6605a1059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Mon, 20 Jan 2020 10:42:46 +0100 Subject: [PATCH] Clean file IO code in Stream_support (no real changes) --- Stream_support/include/CGAL/IO/3MF/read_3mf.h | 218 ++++--- .../include/CGAL/IO/3MF/write_3mf.h | 261 +++++---- .../CGAL/IO/OBJ/File_writer_wavefront.h | 77 +-- .../include/CGAL/IO/OBJ/OBJ_reader.h | 36 +- Stream_support/include/CGAL/IO/OFF.h | 91 +-- .../include/CGAL/IO/OI/File_writer_inventor.h | 72 ++- .../include/CGAL/IO/PLY/PLY_reader.h | 543 +++++++++--------- .../include/CGAL/IO/PLY/PLY_writer.h | 266 +++++---- .../include/CGAL/IO/STL/STL_reader.h | 15 +- .../include/CGAL/IO/STL/STL_writer.h | 30 +- .../include/CGAL/IO/VRML/File_writer_VRML_2.h | 89 ++- .../include/CGAL/IO/VRML/VRML_1_ostream.h | 38 +- .../include/CGAL/IO/VRML/VRML_2_ostream.h | 299 +++++----- .../include/CGAL/IO/VTK/write_vtk.h | 16 +- Stream_support/include/CGAL/IO/WKT.h | 259 +++++---- .../include/CGAL/IO/WKT/traits_linestring.h | 25 +- .../CGAL/IO/WKT/traits_multilinestring.h | 25 +- .../include/CGAL/IO/WKT/traits_multipoint.h | 25 +- .../include/CGAL/IO/WKT/traits_multipolygon.h | 23 +- .../include/CGAL/IO/WKT/traits_point.h | 80 +-- .../include/CGAL/IO/WKT/traits_point_3.h | 101 ++-- .../include/CGAL/IO/WKT/traits_polygon.h | 46 +- 22 files changed, 1409 insertions(+), 1226 deletions(-) diff --git a/Stream_support/include/CGAL/IO/3MF/read_3mf.h b/Stream_support/include/CGAL/IO/3MF/read_3mf.h index ac1b48459a8..7c1dae4b040 100644 --- a/Stream_support/include/CGAL/IO/3MF/read_3mf.h +++ b/Stream_support/include/CGAL/IO/3MF/read_3mf.h @@ -11,30 +11,35 @@ #ifndef CGAL_IO_READ_3MF_H #define CGAL_IO_READ_3MF_H -#include -#include -#include -#include -#include + #include #include -#include -namespace CGAL{ -namespace transform_nmr_internal{ +#include + +#include +#include +#include +#include +#include + +namespace CGAL { +namespace transform_nmr_internal { + NMR::MODELTRANSFORM initMatrix() { NMR::MODELTRANSFORM mMatrix; int i, j; - for (i = 0; i < 4; i++) { - for (j = 0; j < 3; j++) { + for(i = 0; i < 4; i++) { + for(j = 0; j < 3; j++) { mMatrix.m_fFields[j][i] = (i == j) ? 1.0f : 0.0f; } } return mMatrix; } -}//end transform_nmr_internal + +} // namespace transform_nmr_internal template::Kernel Kernel; + HRESULT hResult; DWORD nNeededChars; std::vector pBuffer; // Retrieve Mesh Name Length hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, NULL, 0, &nNeededChars); - if (hResult != LIB3MF_OK) + if(hResult != LIB3MF_OK) { std::cerr<<"Error during name extraction."; return false; } // Retrieve Mesh Name - if (nNeededChars > 0) { + if(nNeededChars > 0) + { pBuffer.resize(nNeededChars + 1); hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, &pBuffer[0], nNeededChars + 1, NULL); pBuffer[nNeededChars] = 0; @@ -74,17 +82,20 @@ bool extract_soups (NMR::PLib3MFModelMeshObject *pMeshObject, name = std::string(&pBuffer[0]); } else + { name = std::string("Unknown Mesh"); + } typename Kernel::Aff_transformation_3 t( transform.m_fFields[0][0], transform.m_fFields[0][1], transform.m_fFields[0][2], transform.m_fFields[0][3], - transform.m_fFields[1][0], transform.m_fFields[1][1], transform.m_fFields[1][2], transform.m_fFields[1][3], - transform.m_fFields[2][0], transform.m_fFields[2][1], transform.m_fFields[2][2], transform.m_fFields[2][3] + transform.m_fFields[1][0], transform.m_fFields[1][1], transform.m_fFields[1][2], transform.m_fFields[1][3], + transform.m_fFields[2][0], transform.m_fFields[2][1], transform.m_fFields[2][2], transform.m_fFields[2][3] ); NMR::PLib3MFPropertyHandler * pPropertyHandler; hResult = NMR::lib3mf_meshobject_createpropertyhandler(pMeshObject, &pPropertyHandler); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { DWORD nErrorMessage; LPCSTR pszErrorMessage; std::cerr << "could not create property handler: " << std::hex << hResult << std::endl; @@ -103,6 +114,7 @@ bool extract_soups (NMR::PLib3MFModelMeshObject *pMeshObject, pVertex.m_fPosition[2]); points[vid] = t.transform(p); } + for(DWORD pid = 0; pid < triangles.size(); ++pid) { NMR::MODELMESHTRIANGLE pTriangle; @@ -117,6 +129,7 @@ bool extract_soups (NMR::PLib3MFModelMeshObject *pMeshObject, colors[pid]=CGAL::Color(mColor.m_Red, mColor.m_Green, mColor.m_Blue, mColor.m_Alpha); } + return true; } @@ -128,7 +141,8 @@ bool extract_polylines (NMR::PLib3MFModelMeshObject *pMeshObject, PointRange& points, PolygonRange&, ColorRange& colors, - std::string& name) { + std::string& name) +{ typedef typename PointRange::value_type Point_3; HRESULT hResult; @@ -136,7 +150,7 @@ bool extract_polylines (NMR::PLib3MFModelMeshObject *pMeshObject, std::vector pBuffer; // Retrieve Mesh Name Length hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, NULL, 0, &nNeededChars); - if (hResult != LIB3MF_OK) + if(hResult != LIB3MF_OK) { points.resize(0); std::cerr<<"Error during name extraction."; @@ -144,7 +158,8 @@ bool extract_polylines (NMR::PLib3MFModelMeshObject *pMeshObject, } // Retrieve Mesh Name - if (nNeededChars > 0) { + if(nNeededChars > 0) + { pBuffer.resize(nNeededChars + 1); hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, &pBuffer[0], nNeededChars + 1, NULL); pBuffer[nNeededChars] = 0; @@ -164,7 +179,8 @@ bool extract_polylines (NMR::PLib3MFModelMeshObject *pMeshObject, NMR::PLib3MFPropertyHandler * pPropertyHandler; hResult = NMR::lib3mf_meshobject_createpropertyhandler(pMeshObject, &pPropertyHandler); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { DWORD nErrorMessage; LPCSTR pszErrorMessage; std::cerr << "could not create property handler: " << std::hex << hResult << std::endl; @@ -188,8 +204,8 @@ bool extract_polylines (NMR::PLib3MFModelMeshObject *pMeshObject, NMR::MODELMESH_TRIANGLECOLOR_SRGB pColor; NMR::lib3mf_propertyhandler_getcolor(pPropertyHandler, 0, &pColor);//get color of the dummy triangle NMR::MODELMESHCOLOR_SRGB mColor = pColor.m_Colors[0]; - colors[0]=CGAL::Color(mColor.m_Red, mColor.m_Green, - mColor.m_Blue, mColor.m_Alpha); + colors[0] = CGAL::Color(mColor.m_Red, mColor.m_Green, + mColor.m_Blue, mColor.m_Alpha); return true; } @@ -201,15 +217,17 @@ bool extract_point_clouds (NMR::PLib3MFModelMeshObject *pMeshObject, PointRange& points, PolygonRange&, ColorRange& colors, - std::string& name) { + std::string& name) +{ typedef typename PointRange::value_type Point_3; HRESULT hResult; DWORD nNeededChars; std::vector pBuffer; + // Retrieve Mesh Name Length hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, NULL, 0, &nNeededChars); - if (hResult != LIB3MF_OK) + if(hResult != LIB3MF_OK) { std::cerr<<"Error during name extraction."; points.resize(0); @@ -217,7 +235,8 @@ bool extract_point_clouds (NMR::PLib3MFModelMeshObject *pMeshObject, } // Retrieve Mesh Name - if (nNeededChars > 0) { + if(nNeededChars > 0) + { pBuffer.resize(nNeededChars + 1); hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, &pBuffer[0], nNeededChars + 1, NULL); pBuffer[nNeededChars] = 0; @@ -229,14 +248,15 @@ bool extract_point_clouds (NMR::PLib3MFModelMeshObject *pMeshObject, } name = std::string(&pBuffer[0]); } - else{ + else + { points.resize(0); return false; } NMR::PLib3MFPropertyHandler * pPropertyHandler; hResult = NMR::lib3mf_meshobject_createpropertyhandler(pMeshObject, &pPropertyHandler); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) { DWORD nErrorMessage; LPCSTR pszErrorMessage; std::cerr << "could not create property handler: " << std::hex << hResult << std::endl; @@ -276,32 +296,34 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points, PointRange&, PolygonRange&, ColorRange&, - std::string&)> func - ) + std::string&)> func) { DWORD nInterfaceVersionMajor, nInterfaceVersionMinor, nInterfaceVersionMicro, nbVertices, nbPolygons; HRESULT hResult; NMR::PLib3MFModel * pModel; NMR::PLib3MFModelReader * pReader; + // Extract Extension of filename std::string sReaderName("3mf"); hResult = NMR::lib3mf_getinterfaceversion(&nInterfaceVersionMajor, &nInterfaceVersionMinor, &nInterfaceVersionMicro); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { std::cerr << "could not get 3MF Library version: " << std::hex << hResult << std::endl; return -1; } // Create Model Instance hResult = NMR::lib3mf_createmodel(&pModel); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) { std::cerr << "could not create model: " << std::hex << hResult << std::endl; return -1; } // Create Model Reader hResult = NMR::lib3mf_model_queryreader(pModel, sReaderName.c_str(), &pReader); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { std::cerr << "could not create model reader: " << std::hex << hResult << std::endl; NMR::lib3mf_release(pModel); return -1; @@ -309,7 +331,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points, // Import Model from File hResult = NMR::lib3mf_reader_readfromfileutf8(pReader, file_name.c_str()); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { std::cerr << "could not parse file: " << std::hex << hResult << std::endl; NMR::lib3mf_release(pReader); NMR::lib3mf_release(pModel); @@ -325,13 +348,16 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points, NMR::PLib3MFModelResourceIterator * pResourceIterator; hResult = NMR::lib3mf_model_getobjects(pModel, &pResourceIterator); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { std::cerr << "could not get object: " << std::hex << hResult << std::endl; NMR::lib3mf_release(pModel); return -1; } + hResult = NMR::lib3mf_resourceiterator_movenext(pResourceIterator, &pbHasNext); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { std::cerr << "could not get next object: " << std::hex << hResult << std::endl; NMR::lib3mf_release(pResourceIterator); NMR::lib3mf_release(pModel); @@ -350,7 +376,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points, // get current resource hResult = NMR::lib3mf_resourceiterator_getcurrent(pResourceIterator, &pResource); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { std::cerr << "could not get resource: " << std::hex << hResult << std::endl; NMR::lib3mf_release(pResourceIterator); NMR::lib3mf_release(pModel); @@ -359,68 +386,79 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points, // get resource ID hResult = NMR::lib3mf_resource_getresourceid(pResource, &ResourceID); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { std::cerr << "could not get resource id: " << std::hex << hResult << std::endl; NMR::lib3mf_release(pResource); NMR::lib3mf_release(pResourceIterator); NMR::lib3mf_release(pModel); return -1; } + // Query mesh interface BOOL bIsMeshObject; hResult = NMR::lib3mf_object_ismeshobject(pResource, &bIsMeshObject); - if (hResult == LIB3MF_OK) + if(hResult == LIB3MF_OK) { - if(bIsMeshObject) { + if(bIsMeshObject) + { //skip it. Only get it through the components and buildItems. } - else { + else + { BOOL bIsComponentsObject; hResult = NMR::lib3mf_object_iscomponentsobject(pResource, &bIsComponentsObject); - if ((hResult == LIB3MF_OK) && (bIsComponentsObject)) { + if((hResult == LIB3MF_OK) && (bIsComponentsObject)) { pComponentsObject = (NMR::PLib3MFModelComponentsObject*)pResource; DWORD nComponentCount; hResult = NMR::lib3mf_componentsobject_getcomponentcount(pComponentsObject, &nComponentCount); - if (hResult != LIB3MF_OK) + if(hResult != LIB3MF_OK) return -1; //for each component DWORD nIndex; - for (nIndex = 0; nIndex < nComponentCount; ++nIndex) { + for(nIndex = 0; nIndex < nComponentCount; ++nIndex) { NMR::PLib3MFModelResource * compResource; NMR::PLib3MFModelComponent * pComponent; hResult = NMR::lib3mf_componentsobject_getcomponent(pComponentsObject, nIndex, &pComponent); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) return -1; - } hResult = NMR::lib3mf_component_getobjectresource(pComponent, &compResource); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { NMR::lib3mf_release(pComponent); return -1; } + hResult = NMR::lib3mf_object_ismeshobject(compResource, &bIsMeshObject); - if (hResult == LIB3MF_OK) + if(hResult == LIB3MF_OK) { - if(bIsMeshObject) { + if(bIsMeshObject) + { BOOL bHasTransform; NMR::MODELTRANSFORM Transform; hResult = NMR::lib3mf_component_hastransform(pComponent, &bHasTransform); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { NMR::lib3mf_release(pComponent); return -1; } - if (bHasTransform) { + if(bHasTransform) + { // Retrieve Transform hResult = NMR::lib3mf_component_gettransform(pComponent, &Transform); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { NMR::lib3mf_release(pComponent); return -1; } } - else { + else + { Transform = transform_nmr_internal::initMatrix(); } + pMeshObject = compResource; NMR::lib3mf_meshobject_getvertexcount(pMeshObject, &nbVertices); NMR::lib3mf_meshobject_gettrianglecount(pMeshObject, &nbPolygons); @@ -429,7 +467,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points, ColorRange colors(nbPolygons); std::string name; - if(func(pMeshObject, Transform, points, triangles, colors, name)){ + if(func(pMeshObject, Transform, points, triangles, colors, name)) + { all_points.push_back(points); all_polygons.push_back(triangles); all_colors.push_back(colors); @@ -442,16 +481,17 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points, } } } + // free instances NMR::lib3mf_release(pResource); hResult = NMR::lib3mf_resourceiterator_movenext(pResourceIterator, &pbHasNext); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { std::cerr << "could not get next object: " << std::hex << hResult << std::endl; return -1; } } - /******************************************************** **** Iterate Build items To Find Transformed Meshes **** ********************************************************/ @@ -459,7 +499,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points, // Iterate through all the Build items NMR::PLib3MFModelBuildItemIterator * pBuildItemIterator; hResult = NMR::lib3mf_model_getbuilditems(pModel, &pBuildItemIterator); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { std::cout << "could not get build items: " << std::hex << hResult << std::endl; NMR::lib3mf_release(pBuildItemIterator); NMR::lib3mf_release(pModel); @@ -467,20 +508,23 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points, } hResult = NMR::lib3mf_builditemiterator_movenext(pBuildItemIterator, &pbHasNext); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { std::cout << "could not get next build item: " << std::hex << hResult << std::endl; NMR::lib3mf_release(pBuildItemIterator); NMR::lib3mf_release(pModel); return -1; } - while (pbHasNext) { + while (pbHasNext) + { NMR::PLib3MFModelMeshObject * pMeshObject; NMR::MODELTRANSFORM Transform; NMR::PLib3MFModelBuildItem * pBuildItem; // Retrieve Build Item hResult = NMR::lib3mf_builditemiterator_getcurrent(pBuildItemIterator, &pBuildItem); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { std::cout << "could not get build item: " << std::hex << hResult << std::endl; NMR::lib3mf_release(pBuildItemIterator); NMR::lib3mf_release(pModel); @@ -490,7 +534,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points, // Retrieve Resource NMR::PLib3MFModelObjectResource * pObjectResource; hResult = NMR::lib3mf_builditem_getobjectresource(pBuildItem, &pObjectResource); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { std::cout << "could not get build item resource: " << std::hex << hResult << std::endl; NMR::lib3mf_release(pBuildItem); NMR::lib3mf_release(pBuildItemIterator); @@ -500,9 +545,10 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points, BOOL bIsMeshObject; hResult = NMR::lib3mf_object_ismeshobject(pObjectResource, &bIsMeshObject); - if (hResult == LIB3MF_OK) + if(hResult == LIB3MF_OK) { - if(bIsMeshObject) { + if(bIsMeshObject) + { pMeshObject = pObjectResource; NMR::lib3mf_meshobject_getvertexcount(pMeshObject, &nbVertices); NMR::lib3mf_meshobject_gettrianglecount(pMeshObject, &nbPolygons); @@ -511,11 +557,11 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points, ColorRange colors(nbPolygons); std::string name; - // Check Object Transform BOOL bHasTransform; hResult = NMR::lib3mf_builditem_hasobjecttransform(pBuildItem, &bHasTransform); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { NMR::lib3mf_release(pBuildItem); NMR::lib3mf_release(pBuildItemIterator); NMR::lib3mf_release(pModel); @@ -523,10 +569,11 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points, return -1; } - if (bHasTransform) { + if(bHasTransform) + { // Retrieve Transform hResult = NMR::lib3mf_builditem_getobjecttransform(pBuildItem, &Transform); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) { NMR::lib3mf_release(pBuildItem); NMR::lib3mf_release(pBuildItemIterator); NMR::lib3mf_release(pModel); @@ -534,7 +581,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points, return -1; } } - else { + else + { Transform = transform_nmr_internal::initMatrix(); } @@ -546,6 +594,7 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points, } } } + // Release Object Resource ID NMR::lib3mf_release(pObjectResource); // Release Build Item @@ -553,11 +602,13 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points, // Move to next Item hResult = NMR::lib3mf_builditemiterator_movenext(pBuildItemIterator, &pbHasNext); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { std::cerr << "could not get next build item: " << std::hex << hResult << std::endl; return -1; } } + // Release Build Item Iterator NMR::lib3mf_release(pBuildItemIterator); return all_points.size(); @@ -592,57 +643,54 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points, */ template int read_triangle_soups_from_3mf(const std::string& file_name, PointRanges& all_points, - PolygonRanges& all_polygons, ColorRanges& all_colors, - std::vector& names - ) + PolygonRanges& all_polygons, ColorRanges& all_colors, + std::vector& names) { typedef typename PointRanges::value_type PointRange; typedef typename PolygonRanges::value_type PolygonRange; typedef typename ColorRanges::value_type ColorRange; return read_from_3mf - (file_name, all_points, all_polygons, - all_colors, names, extract_soups); + (file_name, all_points, all_polygons, all_colors, names, + extract_soups); } - template int read_polylines_from_3mf(const std::string& file_name, PointRanges& all_points, ColorRanges& all_colors, - std::vector& names - ) + std::vector& names) { typedef typename PointRanges::value_type PointRange; typedef std::vector Polygon; typedef std::vector PolygonRange; typedef std::vector ColorRange; + std::vector all_polygons; return read_from_3mf, - std::vector, PointRange, PolygonRange, ColorRange> - (file_name, all_points, all_polygons, all_colors, names, - extract_polylines); + std::vector, PointRange, PolygonRange, ColorRange> + (file_name, all_points, all_polygons, all_colors, names, + extract_polylines); } - template int read_point_clouds_from_3mf(const std::string& file_name, PointRanges& all_points, ColorRanges& all_colors, - std::vector& names - ) + std::vector& names) { typedef typename PointRanges::value_type PointRange; typedef std::vector Polygon; typedef std::vector PolygonRange; typedef std::vector ColorRange; + std::vector all_polygons; return read_from_3mf, std::vector, PointRange, PolygonRange, ColorRange> (file_name, all_points, all_polygons, all_colors, names, extract_point_clouds); } -}//end CGAL + +} // namespace CGAL #endif // CGAL_IO_READ_3MF_H - diff --git a/Stream_support/include/CGAL/IO/3MF/write_3mf.h b/Stream_support/include/CGAL/IO/3MF/write_3mf.h index f6c2a73689e..49cdb583796 100644 --- a/Stream_support/include/CGAL/IO/3MF/write_3mf.h +++ b/Stream_support/include/CGAL/IO/3MF/write_3mf.h @@ -11,16 +11,19 @@ #ifndef CGAL_IO_WRITE_3MF_H #define CGAL_IO_WRITE_3MF_H -#include -#include -#include +#include #include #include -namespace CGAL{ -namespace tmf_internal{ +#include +#include +#include + +namespace CGAL { +namespace tmf_internal { + // Utility functions to create vertices and triangles NMR::MODELMESHVERTEX fnCreateVertex(float x, float y, float z) { @@ -30,6 +33,7 @@ NMR::MODELMESHVERTEX fnCreateVertex(float x, float y, float z) result.m_fPosition[2] = z; return result; } + NMR::MODELMESHTRIANGLE fnCreateTriangle(int v0, int v1, int v2) { NMR::MODELMESHTRIANGLE result; @@ -38,6 +42,7 @@ NMR::MODELMESHTRIANGLE fnCreateTriangle(int v0, int v1, int v2) result.m_nIndices[2] = v2; return result; } + NMR::MODELMESHCOLOR_SRGB fnCreateColor(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255) { @@ -47,10 +52,9 @@ NMR::MODELMESHCOLOR_SRGB fnCreateColor(unsigned char red, unsigned char green, result.m_Blue = blue; result.m_Alpha = alpha; return result; - - } -} //end internal + +} // namespace tmf_internal bool add_build_item(NMR::PLib3MFModel * pModel, NMR::PLib3MFModelMeshObject* pMeshObject) @@ -58,19 +62,21 @@ bool add_build_item(NMR::PLib3MFModel * pModel, HRESULT hResult; DWORD nErrorMessage; LPCSTR pszErrorMessage; + // Add Build Item for Mesh NMR::PLib3MFModelBuildItem * pBuildItem; hResult = NMR::lib3mf_model_addbuilditem(pModel, pMeshObject, NULL, &pBuildItem); - if (hResult != LIB3MF_OK) { - std::cerr << "could not create build item: " - << std::hex << hResult << std::endl; + + if(hResult != LIB3MF_OK) + { + std::cerr << "could not create build item: " << std::hex << hResult << std::endl; NMR::lib3mf_getlasterror(pModel, &nErrorMessage, &pszErrorMessage); - std::cerr << "error #" << std::hex << nErrorMessage - << ": " << pszErrorMessage << std::endl; + std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; NMR::lib3mf_release(pMeshObject); NMR::lib3mf_release(pModel); return false; } + // Release BuildItem and Mesh NMR::lib3mf_release(pMeshObject); NMR::lib3mf_release(pBuildItem); @@ -83,78 +89,76 @@ bool export_model_to_file(const std::string& file_name, HRESULT hResult; DWORD nErrorMessage; LPCSTR pszErrorMessage; + // Output mesh as 3MF // Create Model Writer for 3MF NMR::PLib3MFModelWriter * p3MFWriter; hResult = NMR::lib3mf_model_querywriter(pModel, "3mf", &p3MFWriter); - if (hResult != LIB3MF_OK) { - std::cerr << "could not create model reader: " - << std::hex << hResult << std::endl; + + if(hResult != LIB3MF_OK) + { + std::cerr << "could not create model reader: " << std::hex << hResult << std::endl; NMR::lib3mf_getlasterror(pModel, &nErrorMessage, &pszErrorMessage); - std::cerr << "error #" << std::hex << nErrorMessage - << ": " << pszErrorMessage << std::endl; + std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; NMR::lib3mf_release(pModel); return false; } + // Export Model into File hResult = NMR::lib3mf_writer_writetofileutf8(p3MFWriter, file_name.c_str()); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) { std::cerr << "could not write file: " << std::hex << hResult << std::endl; NMR::lib3mf_getlasterror(p3MFWriter, &nErrorMessage, &pszErrorMessage); - std::cerr << "error #" << std::hex << nErrorMessage << ": " - << pszErrorMessage << std::endl; + std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; NMR::lib3mf_release(pModel); NMR::lib3mf_release(p3MFWriter); return false; } - + // Release Model Writer NMR::lib3mf_release(p3MFWriter); return true; } template -bool write_mesh_to_model( const PointRange& points, - const PolygonRange& polygons, - const ColorRange& colors, - const std::string& name, - NMR::PLib3MFModelMeshObject** pMeshObject, - NMR::PLib3MFModel * pModel - ) +bool write_mesh_to_model(const PointRange& points, + const PolygonRange& polygons, + const ColorRange& colors, + const std::string& name, + NMR::PLib3MFModelMeshObject** pMeshObject, + NMR::PLib3MFModel * pModel) { DWORD nErrorMessage; LPCSTR pszErrorMessage; HRESULT hResult; + // Create mesh structure std::vector pVertices; std::vector pTriangles; + // Create Mesh Object hResult = NMR::lib3mf_model_addmeshobject(pModel, pMeshObject); - if (hResult != LIB3MF_OK) { - std::cerr << "could not add mesh object: " << std::hex - << hResult << std::endl; + if(hResult != LIB3MF_OK) + { + std::cerr << "could not add mesh object: " << std::hex << hResult << std::endl; NMR::lib3mf_getlasterror(pModel, &nErrorMessage, &pszErrorMessage); - std::cerr << "error #" << std::hex << nErrorMessage << ": " - << pszErrorMessage << std::endl; + std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; NMR::lib3mf_release(pModel); return false; } - for( auto point : points) - { + + for(const auto& point : points) pVertices.push_back(tmf_internal::fnCreateVertex(point.x(), point.y(), point.z())); - } - - for( auto triangle : polygons) - { + + for(const auto& triangle : polygons) pTriangles.push_back(tmf_internal::fnCreateTriangle(triangle[0], triangle[1], triangle[2])); - } - + hResult = NMR::lib3mf_meshobject_setgeometry(*pMeshObject, pVertices.data(), - pVertices.size(), pTriangles.data(), - pTriangles.size()); - if (hResult != LIB3MF_OK) { - std::cerr << "could not set mesh geometry: " - << std::hex << hResult << std::endl; + pVertices.size(), pTriangles.data(), + pTriangles.size()); + if(hResult != LIB3MF_OK) + { + std::cerr << "could not set mesh geometry: " << std::hex << hResult << std::endl; NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; @@ -162,16 +166,18 @@ bool write_mesh_to_model( const PointRange& points, NMR::lib3mf_release(pModel); return false; } + // Create color entries NMR::PLib3MFPropertyHandler * pPropertyHandler; hResult = NMR::lib3mf_meshobject_createpropertyhandler(*pMeshObject, &pPropertyHandler); - if (hResult != LIB3MF_OK) { - std::cerr << "could not create property handler: " << std::hex << hResult << std::endl; - NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); - std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; - NMR::lib3mf_release(*pMeshObject); - NMR::lib3mf_release(pModel); - return false; + if(hResult != LIB3MF_OK) + { + std::cerr << "could not create property handler: " << std::hex << hResult << std::endl; + NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); + std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; + NMR::lib3mf_release(*pMeshObject); + NMR::lib3mf_release(pModel); + return false; } // define colors @@ -188,7 +194,8 @@ bool write_mesh_to_model( const PointRange& points, // make sure to define a default property NMR::PLib3MFDefaultPropertyHandler * pDefaultPropertyHandler; hResult = NMR::lib3mf_object_createdefaultpropertyhandler(*pMeshObject, &pDefaultPropertyHandler); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { std::cerr<< "could not create default property handler: " << std::hex << hResult << std::endl; NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); std::cerr<< "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; @@ -196,16 +203,17 @@ bool write_mesh_to_model( const PointRange& points, NMR::lib3mf_release(pModel); return false; } + NMR::MODELMESHCOLOR_SRGB default_color = tmf_internal::fnCreateColor(0,0,0,0); - NMR::lib3mf_defaultpropertyhandler_setcolor(pDefaultPropertyHandler, - &default_color); + NMR::lib3mf_defaultpropertyhandler_setcolor(pDefaultPropertyHandler, &default_color); // release default property handler NMR::lib3mf_release(pDefaultPropertyHandler); // Set name hResult = NMR::lib3mf_object_setnameutf8(*pMeshObject, name.c_str()); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { std::cerr << "could not set object name: " << std::hex << hResult << std::endl; NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; @@ -224,41 +232,41 @@ bool write_points(const PointRange& points, const Color& color, const std::string& name, NMR::PLib3MFModelMeshObject** pMeshObject, - NMR::PLib3MFModel * pModel - ) + NMR::PLib3MFModel * pModel) { DWORD nErrorMessage; LPCSTR pszErrorMessage; HRESULT hResult; + // Create mesh structure std::vector pVertices; + // Create Mesh Object hResult = NMR::lib3mf_model_addmeshobject(pModel, pMeshObject); - if (hResult != LIB3MF_OK) { - std::cerr << "could not add mesh object: " << std::hex - << hResult << std::endl; + if(hResult != LIB3MF_OK) + { + std::cerr << "could not add mesh object: " << std::hex << hResult << std::endl; NMR::lib3mf_getlasterror(pModel, &nErrorMessage, &pszErrorMessage); - std::cerr << "error #" << std::hex << nErrorMessage << ": " - << pszErrorMessage << std::endl; + std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; NMR::lib3mf_release(pModel); return false; } + //add 3 demmy vertices to be sure to have a valid triangle and accept point sets with less than 3 vertices. for(int i = 0; i< 3; ++i) pVertices.push_back(tmf_internal::fnCreateVertex(0,0,0)); - for( auto point : points) - { + + for(const auto& point : points) pVertices.push_back(tmf_internal::fnCreateVertex(point.x(), point.y(), point.z())); - } + NMR::MODELMESHTRIANGLE dummy_triangle = tmf_internal::fnCreateTriangle(0,1,2); //add a triangle to avoid lib error. hResult = NMR::lib3mf_meshobject_setgeometry(*pMeshObject, pVertices.data(), - pVertices.size(), &dummy_triangle, 1); - if (hResult != LIB3MF_OK) { - std::cerr << "could not set mesh geometry: " - << std::hex << hResult << std::endl; + pVertices.size(), &dummy_triangle, 1); + if(hResult != LIB3MF_OK) + { + std::cerr << "could not set mesh geometry: " << std::hex << hResult << std::endl; NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); - std::cerr << "error #" << std::hex << nErrorMessage - << ": " << pszErrorMessage << std::endl; + std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; NMR::lib3mf_release(*pMeshObject); NMR::lib3mf_release(pModel); return false; @@ -267,27 +275,29 @@ bool write_points(const PointRange& points, // Create color entries NMR::PLib3MFPropertyHandler * pPropertyHandler; hResult = NMR::lib3mf_meshobject_createpropertyhandler(*pMeshObject, &pPropertyHandler); - if (hResult != LIB3MF_OK) { - std::cerr << "could not create property handler: " << std::hex << hResult << std::endl; - NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); - std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; - NMR::lib3mf_release(*pMeshObject); - NMR::lib3mf_release(pModel); - return false; + if(hResult != LIB3MF_OK) + { + std::cerr << "could not create property handler: " << std::hex << hResult << std::endl; + NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); + std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; + NMR::lib3mf_release(*pMeshObject); + NMR::lib3mf_release(pModel); + return false; } // define colors - NMR::MODELMESHCOLOR_SRGB sColor = tmf_internal::fnCreateColor (color.red(), - color.green(), - color.blue(), - color.alpha()); - // One-colored Triangles - NMR::lib3mf_propertyhandler_setsinglecolor(pPropertyHandler, 0, &sColor); + NMR::MODELMESHCOLOR_SRGB sColor = tmf_internal::fnCreateColor (color.red(), + color.green(), + color.blue(), + color.alpha()); + // One-colored Triangles + NMR::lib3mf_propertyhandler_setsinglecolor(pPropertyHandler, 0, &sColor); // make sure to define a default property NMR::PLib3MFDefaultPropertyHandler * pDefaultPropertyHandler; hResult = NMR::lib3mf_object_createdefaultpropertyhandler(*pMeshObject, &pDefaultPropertyHandler); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { std::cerr<< "could not create default property handler: " << std::hex << hResult << std::endl; NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); std::cerr<< "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; @@ -295,6 +305,7 @@ bool write_points(const PointRange& points, NMR::lib3mf_release(pModel); return false; } + NMR::MODELMESHCOLOR_SRGB default_color = tmf_internal::fnCreateColor(0,0,0,0); NMR::lib3mf_defaultpropertyhandler_setcolor(pDefaultPropertyHandler, &default_color); @@ -304,7 +315,8 @@ bool write_points(const PointRange& points, // Set name hResult = NMR::lib3mf_object_setnameutf8(*pMeshObject, name.c_str()); - if (hResult != LIB3MF_OK) { + if(hResult != LIB3MF_OK) + { std::cerr << "could not set object name: " << std::hex << hResult << std::endl; NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; @@ -312,6 +324,7 @@ bool write_points(const PointRange& points, NMR::lib3mf_release(pModel); return false; } + return add_build_item(pModel, *pMeshObject); } @@ -320,8 +333,7 @@ bool write_point_cloud_to_model(const PointRange& points, const Color& color, const std::string& name, NMR::PLib3MFModelMeshObject** pMeshObject, - NMR::PLib3MFModel * pModel - ) + NMR::PLib3MFModel * pModel) { std::string pc_name = name; pc_name.append("_cgal_pc"); @@ -333,8 +345,7 @@ bool write_polyline_to_model(const PointRange& points, const Color& color, const std::string& name, NMR::PLib3MFModelMeshObject** pMeshObject, - NMR::PLib3MFModel * pModel - ) + NMR::PLib3MFModel * pModel) { std::string pc_name = name; pc_name.append("_cgal_pl"); @@ -362,33 +373,36 @@ bool write_polyline_to_model(const PointRange& points, */ template bool write_triangle_soups_to_3mf(const std::string& file_name, - const PointRanges& all_points, - const PolygonRanges& all_polygons, - const std::vector& names) + const PointRanges& all_points, + const PolygonRanges& all_polygons, + const std::vector& names) { - HRESULT hResult; - - // Create Model Instance + // Create Model Instance NMR::PLib3MFModel * pModel; - hResult = NMR::lib3mf_createmodel(&pModel); - if (hResult != LIB3MF_OK) { + HRESULT hResult = NMR::lib3mf_createmodel(&pModel); + if(hResult != LIB3MF_OK) + { std::cerr << "could not create model: " << std::hex << hResult << std::endl; return false; } - for(std::size_t id = 0; id < all_points.size(); ++id) + + for(std::size_t id = 0; id < all_points.size(); ++id) { NMR::PLib3MFModelMeshObject* pMeshObject; std::string name; - if(names.size() > id - && ! names[id].empty()) + if(names.size() > id && ! names[id].empty()) { name=names[id]; } else + { name = std::string(""); + } + std::vector colors(all_polygons[id].size()); - write_mesh_to_model(all_points[id], all_polygons[id], colors, name, &pMeshObject, pModel); + write_mesh_to_model(all_points[id], all_polygons[id], colors, name, &pMeshObject, pModel); } + return export_model_to_file(file_name, pModel); } @@ -412,46 +426,53 @@ bool write_triangle_meshes_to_3mf(const std::string& file_name, const TriangleMeshRange& tms, const std::vector& names) { - typedef typename TriangleMeshRange::value_type Mesh; + typedef typename TriangleMeshRange::value_type Mesh; typedef typename boost::property_map::type VPMap; - typedef typename boost::property_traits::value_type Point_3; + typedef typename boost::property_traits::value_type Point_3; - typedef std::vector Polygon; - typedef std::vector PolygonRange; + typedef boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef boost::graph_traits::face_descriptor face_descriptor; - typedef std::vector PointRange; + typedef std::vector Polygon; + typedef std::vector PolygonRange; + typedef std::vector PointRange; std::vector all_points; std::vector all_polygons; - - for(auto tm : tms) + for(const auto& tm : tms) { PointRange points; + points.reserve(num_vertices(tm)); PolygonRange triangles; + triangles.reserve(num_faces(tm)); + VPMap vpm = get(boost::vertex_point, tm); - std::unordered_map::vertex_descriptor, - std::size_t> vertex_id_map; + std::unordered_map::vertex_descriptor, std::size_t> vertex_id_map; + std::size_t i = 0; - for(auto v : vertices(tm)) + for(vertex_descriptor v : vertices(tm)) { points.push_back(get(vpm, v)); vertex_id_map[v] = i++; } + all_points.push_back(points); - for(auto f : faces(tm)) + for(face_descriptor f : faces(tm)) { Polygon triangle; - for(auto vert : CGAL::vertices_around_face(halfedge(f, tm), tm)) - { + for(vertex_descriptor vert : CGAL::vertices_around_face(halfedge(f, tm), tm)) triangle.push_back(vertex_id_map[vert]); - } + triangles.push_back(triangle); } + all_polygons.push_back(triangles); } return write_triangle_soups_to_3mf(file_name, all_points, all_polygons, names); } -}//end CGAL + +} // namespace CGAL + #endif // CGAL_IO_WRITE_3MF_H diff --git a/Stream_support/include/CGAL/IO/OBJ/File_writer_wavefront.h b/Stream_support/include/CGAL/IO/OBJ/File_writer_wavefront.h index 0bb1595eb87..15c45afba4f 100644 --- a/Stream_support/include/CGAL/IO/OBJ/File_writer_wavefront.h +++ b/Stream_support/include/CGAL/IO/OBJ/File_writer_wavefront.h @@ -1,57 +1,70 @@ -// Copyright (c) 1997 +// Copyright (c) 1997 // Utrecht University (The Netherlands), // ETH Zurich (Switzerland), // INRIA Sophia-Antipolis (France), // Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. +// and Tel-Aviv University (Israel). All rights reserved. // // This file is part of CGAL (www.cgal.org); // // $URL$ // $Id$ // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// +// // // Author(s) : Lutz Kettner #ifndef CGAL_IO_OBJ_FILE_WRITER_WAVEFRONT_H -#define CGAL_IO_OBJ_FILE_WRITER_WAVEFRONT_H 1 +#define CGAL_IO_OBJ_FILE_WRITER_WAVEFRONT_H #include + #include #include namespace CGAL { -class CGAL_EXPORT File_writer_wavefront { - std::ostream* m_out; - std::size_t m_facets; +class File_writer_wavefront +{ + std::ostream* m_out; + std::size_t m_facets; + public: - std::ostream& out() const { return *m_out; } - void write_header( std::ostream& out, - std::size_t vertices, - std::size_t halfedges, - std::size_t facets); - void write_footer() const { - out() << "\n# End of Wavefront obj format #" << std::endl; - } - void write_vertex( const double& x, const double& y, const double& z) { - out() << "v " << x << ' ' << y << ' ' << z << '\n'; - } - void write_facet_header() { - out() << "\n# " << m_facets << " facets\n"; - out() << "# ------------------------------------------\n\n"; - } - void write_facet_begin( std::size_t) { out() << "f "; } - void write_facet_vertex_index( std::size_t idx) { out() << ' ' << idx+1; } - void write_facet_end() { out() << '\n'; } + std::ostream& out() const { return *m_out; } + void write_header(std::ostream& out, + std::size_t vertices, + std::size_t halfedges, + std::size_t facets) + { + m_out = &o; + m_facets = facets; + + // Print header. + out() << "# file written from a CGAL tool in Wavefront obj format\n"; + out() << "# " << vertices << " vertices\n"; + out() << "# " << halfedges << " halfedges\n"; + out() << "# " << facets << " facets\n\n"; + + out() << "\n# " << vertices << " vertices\n"; + out() << "# ------------------------------------------\n\n"; + } + + void write_footer() const { out() << "\n# End of Wavefront obj format #" << std::endl; } + + void write_vertex(const double& x, const double& y, const double& z) { + out() << "v " << x << ' ' << y << ' ' << z << '\n'; + } + + void write_facet_header() + { + out() << "\n# " << m_facets << " facets\n"; + out() << "# ------------------------------------------\n\n"; + } + void write_facet_begin(std::size_t) { out() << "f "; } + void write_facet_vertex_index(std::size_t idx) { out() << ' ' << idx+1; } + void write_facet_end() { out() << '\n'; } }; -} //namespace CGAL +} // namespace CGAL -#ifdef CGAL_HEADER_ONLY -#include -#endif // CGAL_HEADER_ONLY - -#endif // CGAL_IO_OBJ_FILE_WRITER_WAVEFRONT_H // -// EOF // +#endif // CGAL_IO_OBJ_FILE_WRITER_WAVEFRONT_H diff --git a/Stream_support/include/CGAL/IO/OBJ/OBJ_reader.h b/Stream_support/include/CGAL/IO/OBJ/OBJ_reader.h index c494e883da2..bf06610a2a4 100644 --- a/Stream_support/include/CGAL/IO/OBJ/OBJ_reader.h +++ b/Stream_support/include/CGAL/IO/OBJ/OBJ_reader.h @@ -16,34 +16,37 @@ #include #include - namespace CGAL { -//Points_3 a RandomAccessContainer of Point_3, -//Faces a RandomAccessContainer of RandomAccessContainer of std::size_t +// Points_3 a RandomAccessContainer of Point_3, +// Faces a RandomAccessContainer of RandomAccessContainer of std::size_t template -bool -read_OBJ( std::istream& input, - Points_3 &points, - Faces &faces) +bool read_OBJ(std::istream& input, + Points_3 &points, + Faces &faces) { - typedef typename Points_3::value_type Point_3; + typedef typename Points_3::value_type Point_3; + int mini(1), maxi(-INT_MAX); Point_3 p; std::string line; - while(getline(input, line)) { - if(line[0] == 'v' && line[1] == ' ') { + + while(getline(input, line)) + { + if(line[0] == 'v' && line[1] == ' ') + { std::istringstream iss(line.substr(1)); iss >> p; if(!iss) return false; points.push_back(p); } - else if(line[0] == 'f') { + else if(line[0] == 'f') + { std::istringstream iss(line.substr(1)); int i; - faces.push_back( std::vector() ); + faces.push_back(std::vector()); while(iss >> i) { if(i < 1) @@ -52,13 +55,15 @@ read_OBJ( std::istream& input, if(i maxi) maxi = i-1; } iss.ignore(256, ' '); } + if(!iss.good() && !iss.eof()) return false; } @@ -68,10 +73,13 @@ read_OBJ( std::istream& input, continue; } } - if(maxi > points.size() || mini < -static_cast(points.size())){ + + if(maxi > points.size() || mini < -static_cast(points.size())) + { std::cerr<<"a face index is invalid "< -bool -read_OFF( std::istream& in, - std::vector< Point_3 >& points, - std::vector< Polygon_3 >& polygons, - bool /* verbose */ = false) +bool read_OFF(std::istream& in, + std::vector< Point_3 >& points, + std::vector< Polygon_3 >& polygons, + bool /* verbose */ = false) { CGAL::File_scanner_OFF scanner(in); points.resize(scanner.size_of_vertices()); polygons.resize(scanner.size_of_facets()); - for (std::size_t i = 0; i < scanner.size_of_vertices(); ++i) { + for(std::size_t i = 0; i < scanner.size_of_vertices(); ++i) + { double x, y, z, w; scanner.scan_vertex( x, y, z, w); CGAL_assertion(w!=0); @@ -45,19 +45,20 @@ read_OFF( std::istream& in, if(!in) return false; - for (std::size_t i = 0; i < scanner.size_of_facets(); ++i) { + for(std::size_t i = 0; i < scanner.size_of_facets(); ++i) + { std::size_t no; scanner.scan_facet( no, i); IO::internal::resize(polygons[i], no); - for(std::size_t j = 0; j < no; ++j) { + for(std::size_t j = 0; j < no; ++j) + { std::size_t id; scanner.scan_facet_vertex_index(id, i); - if(id < scanner.size_of_vertices()) { + if(id < scanner.size_of_vertices()) polygons[i][j] = id; - } else { + else return false; - } } } @@ -65,13 +66,12 @@ read_OFF( std::istream& in, } template -bool -read_OFF( std::istream& in, - std::vector< Point_3 >& points, - std::vector< Polygon_3 >& polygons, - std::vector& fcolors, - std::vector& vcolors, - bool /* verbose */ = false) +bool read_OFF(std::istream& in, + std::vector< Point_3 >& points, + std::vector< Polygon_3 >& polygons, + std::vector& fcolors, + std::vector& vcolors, + bool /* verbose */ = false) { CGAL::File_scanner_OFF scanner(in); @@ -81,16 +81,20 @@ read_OFF( std::istream& in, if(scanner.has_colors()) vcolors.resize(scanner.size_of_vertices()); - for (std::size_t i = 0; i < scanner.size_of_vertices(); ++i) { + for(std::size_t i = 0; i < scanner.size_of_vertices(); ++i) + { double x, y, z, w; scanner.scan_vertex( x, y, z, w); CGAL_assertion(w!=0); IO::internal::fill_point( x/w, y/w, z/w, points[i] ); - if(scanner.has_colors()) { + if(scanner.has_colors()) + { unsigned char r=0, g=0, b=0; scanner.scan_color( r, g, b); vcolors[i] = Color_rgb(r,g,b); - } else { + } + else + { scanner.skip_to_next_vertex(i); } @@ -99,7 +103,7 @@ read_OFF( std::istream& in, } bool has_fcolors = false; - for (std::size_t i = 0; i < scanner.size_of_facets(); ++i) + for(std::size_t i = 0; i < scanner.size_of_facets(); ++i) { std::size_t no; scanner.scan_facet( no, i); @@ -108,30 +112,33 @@ read_OFF( std::istream& in, return false; IO::internal::resize(polygons[i], no); - for(std::size_t j = 0; j < no; ++j) { + for(std::size_t j = 0; j < no; ++j) + { std::size_t id; scanner.scan_facet_vertex_index(id, i); - if(id < scanner.size_of_vertices()) { + if(id < scanner.size_of_vertices()) polygons[i][j] = id; - } else { + else return false; - } } - if(i==0) + if(i == 0) { std::string col; std::getline(in, col); std::istringstream iss(col); char ci =' '; - if(iss >> ci) { + if(iss >> ci) + { has_fcolors = true; fcolors.resize(scanner.size_of_facets()); std::istringstream iss2(col); fcolors[i] = scanner.get_color_from_line(iss2); } - } else if(has_fcolors) { + } + else if(has_fcolors) + { unsigned char r=0, g=0, b=0; scanner.scan_color(r,g,b); fcolors[i] = Color_rgb(r,g,b); @@ -142,37 +149,33 @@ read_OFF( std::istream& in, } template -bool -write_OFF(std::ostream& out, - std::vector< Point_3 >& points, - std::vector< Polygon_3 >& polygons) +bool write_OFF(std::ostream& out, + std::vector< Point_3 >& points, + std::vector< Polygon_3 >& polygons) { CGAL::File_writer_OFF writer; - writer.write_header(out, - points.size(), - 0, - polygons.size()); - for(std::size_t i = 0, end = points.size(); - i < end; ++i) + writer.write_header(out, points.size(), 0, polygons.size()); + + for(std::size_t i = 0, end = points.size(); i < end; ++i) { const Point_3& p = points[i]; writer.write_vertex( p.x(), p.y(), p.z() ); } + writer.write_facet_header(); - for(std::size_t i = 0, end = polygons.size(); - i < end; ++i) + for(std::size_t i=0, end=polygons.size(); i + #include #include namespace CGAL { -class CGAL_EXPORT File_writer_inventor { - std::ostream* m_out; - std::size_t m_facets; +class CGAL_EXPORT File_writer_inventor +{ + std::ostream* m_out; + std::size_t m_facets; + public: - File_writer_inventor() {} - std::ostream& out() const { return *m_out; } - void write_header( std::ostream& o, - std::size_t vertices, - std::size_t halfedges, - std::size_t facets); - void write_footer() const; - void write_vertex( const double& x, const double& y, const double& z) { - out() << " " << x << ' ' << y << ' ' << z << ',' <<'\n'; - } - void write_facet_header() const; - void write_facet_begin( std::size_t) { out() << " "; } - void write_facet_vertex_index( std::size_t idx) { out() << idx << ',';} - void write_facet_end() { out() << "-1,\n"; } + File_writer_inventor() {} + std::ostream& out() const { return *m_out; } + + void write_header(std::ostream& o, + std::size_t vertices, + std::size_t halfedges, + std::size_t facets) + { + m_out = &o; + m_facets = facets; + + out() << "# " << vertices << " vertices\n"; + out() << "# " << halfedges << " halfedges\n"; + out() << "# " << facets << " facets\n\n"; + out() << "Separator {\n" + " Coordinate3 {\n" + " point [" << std::endl; + } + + void write_footer() const + { + out() << " ] #coordIndex\n" + " } #IndexedFaceSet\n" + "} #Separator" << std::endl; + } + + void write_vertex( const double& x, const double& y, const double& z) { + out() << " " << x << ' ' << y << ' ' << z << ',' <<'\n'; + } + + void write_facet_header() const + { + out() << " ] #point\n" + " } #Coordinate3\n" + " # " << m_facets << " facets\n" + " IndexedFaceSet {\n" + " coordIndex [\n"; + } + + void write_facet_begin( std::size_t) { out() << " "; } + void write_facet_vertex_index( std::size_t idx) { out() << idx << ','; } + void write_facet_end() { out() << "-1,\n"; } }; } //namespace CGAL -#ifdef CGAL_HEADER_ONLY -#include -#endif // CGAL_HEADER_ONLY - -#endif // CGAL_IO_FILE_WRITER_INVENTOR_H // -// EOF // +#endif // CGAL_IO_FILE_WRITER_INVENTOR_H diff --git a/Stream_support/include/CGAL/IO/PLY/PLY_reader.h b/Stream_support/include/CGAL/IO/PLY/PLY_reader.h index b57e5596602..40c6a7f5643 100644 --- a/Stream_support/include/CGAL/IO/PLY/PLY_reader.h +++ b/Stream_support/include/CGAL/IO/PLY/PLY_reader.h @@ -13,327 +13,324 @@ #include -namespace CGAL{ +namespace CGAL { +namespace internal { - namespace internal - { - template - bool - read_PLY_faces (std::istream& in, +template +bool read_PLY_faces(std::istream& in, internal::PLY::PLY_element& element, std::vector< Polygon_3 >& polygons, std::vector< Color_rgb >& fcolors, const char* vertex_indices_tag) +{ + bool has_colors = false; + std::string rtag = "r", gtag = "g", btag = "b"; + + if((element.has_property("red") || element.has_property("r")) && + (element.has_property("green") || element.has_property("g")) && + (element.has_property("blue") || element.has_property("b"))) + { + has_colors = true; + if(element.has_property("red")) + rtag = "red"; gtag = "green"; btag = "blue"; + } + + for(std::size_t j = 0; j < element.number_of_items(); ++ j) + { + for(std::size_t k = 0; k < element.number_of_properties(); ++ k) + { + internal::PLY::PLY_read_number* property = element.property(k); + property->get(in); + + if(in.fail()) + return false; + } + + std::tuple, boost::uint8_t, boost::uint8_t, boost::uint8_t> new_face; + + if(has_colors) + { + PLY::process_properties(element, new_face, + std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_face), + PLY_property >(vertex_indices_tag)), + std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_face), + PLY_property(rtag.c_str())), + std::make_pair(CGAL::make_nth_of_tuple_property_map<2>(new_face), + PLY_property(gtag.c_str())), + std::make_pair(CGAL::make_nth_of_tuple_property_map<3>(new_face), + PLY_property(btag.c_str()))); + + fcolors.push_back(Color_rgb(get<1>(new_face), get<2>(new_face), get<3>(new_face))); + } + else + { + PLY::process_properties(element, new_face, + std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_face), + PLY_property >(vertex_indices_tag))); + } + + polygons.push_back(Polygon_3(get<0>(new_face).size())); + for(std::size_t i = 0; i < get<0>(new_face).size(); ++ i) + polygons.back()[i] = std::size_t(get<0>(new_face)[i]); + } + + return true; +} + +} // namespace internal + +template +bool +read_PLY(std::istream& in, + std::vector< Point_3 >& points, + std::vector< Polygon_3 >& polygons, + bool /* verbose */ = false) +{ + if(!in) + { + std::cerr << "Error: cannot open file" << std::endl; + return false; + } + + internal::PLY::PLY_reader reader; + + if(!(reader.init(in))) + { + in.setstate(std::ios::failbit); + return false; + } + + for(std::size_t i = 0; i < reader.number_of_elements(); ++ i) + { + internal::PLY::PLY_element& element = reader.element(i); + + if(element.name() == "vertex" || element.name() == "vertices") + { + for(std::size_t j = 0; j < element.number_of_items(); ++ j) + { + for(std::size_t k = 0; k < element.number_of_properties(); ++ k) + { + internal::PLY::PLY_read_number* property = element.property(k); + property->get(in); + + if(in.fail()) + return false; + } + + Point_3 new_vertex; + + internal::PLY::process_properties(element, new_vertex, + make_ply_point_reader(CGAL::Identity_property_map())); + + points.push_back(get<0>(new_vertex)); + } + } + else if(element.name() == "face" || element.name() == "faces") + { + std::vector dummy; + + if(element.has_property >("vertex_indices")) + internal::read_PLY_faces(in, element, polygons, dummy, "vertex_indices"); + else if(element.has_property >("vertex_indices")) + internal::read_PLY_faces(in, element, polygons, dummy, "vertex_indices"); + else if(element.has_property >("vertex_index")) + internal::read_PLY_faces(in, element, polygons, dummy, "vertex_index"); + else if(element.has_property >("vertex_index")) + internal::read_PLY_faces(in, element, polygons, dummy, "vertex_index"); + else + { + std::cerr << "Error: can't find vertex indices in PLY input" << std::endl; + return false; + } + } + else // Read other elements and ignore + { + for(std::size_t j = 0; j < element.number_of_items(); ++ j) + { + for(std::size_t k = 0; k < element.number_of_properties(); ++ k) + { + internal::PLY::PLY_read_number* property = element.property(k); + property->get(in); + + if(in.fail()) + return false; + } + } + } + } + + return !in.bad(); +} + +template +bool read_PLY(std::istream& in, + std::vector< Point_3 >& points, + std::vector< Polygon_3 >& polygons, + std::vector >& hedges, + std::vector& fcolors, + std::vector& vcolors, + std::vector >& huvs, + bool /* verbose */ = false) +{ + if(!in) + { + std::cerr << "Error: cannot open file" << std::endl; + return false; + } + internal::PLY::PLY_reader reader; + + if(!(reader.init(in))) + { + in.setstate(std::ios::failbit); + return false; + } + for(std::size_t i = 0; i < reader.number_of_elements(); ++ i) + { + internal::PLY::PLY_element& element = reader.element(i); + + if(element.name() == "vertex" || element.name() == "vertices") { bool has_colors = false; std::string rtag = "r", gtag = "g", btag = "b"; - if ((element.has_property("red") || element.has_property("r")) && - (element.has_property("green") || element.has_property("g")) && - (element.has_property("blue") || element.has_property("b"))) + if((element.has_property("red") || element.has_property("r")) && + (element.has_property("green") || element.has_property("g")) && + (element.has_property("blue") || element.has_property("b"))) { has_colors = true; - if (element.has_property("red")) + if(element.has_property("red")) { rtag = "red"; gtag = "green"; btag = "blue"; } } - - for (std::size_t j = 0; j < element.number_of_items(); ++ j) + + for(std::size_t j = 0; j < element.number_of_items(); ++ j) { - for (std::size_t k = 0; k < element.number_of_properties(); ++ k) + for(std::size_t k = 0; k < element.number_of_properties(); ++ k) { internal::PLY::PLY_read_number* property = element.property(k); - property->get (in); + property->get(in); - if (in.fail()) + if(in.fail()) return false; } - std::tuple, boost::uint8_t, boost::uint8_t, boost::uint8_t> new_face; + std::tuple new_vertex; - if (has_colors) + if(has_colors) { - PLY::process_properties (element, new_face, - std::make_pair (CGAL::make_nth_of_tuple_property_map<0>(new_face), - PLY_property >(vertex_indices_tag)), - std::make_pair (CGAL::make_nth_of_tuple_property_map<1>(new_face), - PLY_property(rtag.c_str())), - std::make_pair (CGAL::make_nth_of_tuple_property_map<2>(new_face), - PLY_property(gtag.c_str())), - std::make_pair (CGAL::make_nth_of_tuple_property_map<3>(new_face), - PLY_property(btag.c_str()))); + internal::PLY::process_properties(element, new_vertex, + make_ply_point_reader(CGAL::make_nth_of_tuple_property_map<0>(new_vertex)), + std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_vertex), + PLY_property(rtag.c_str())), + std::make_pair(CGAL::make_nth_of_tuple_property_map<2>(new_vertex), + PLY_property(gtag.c_str())), + std::make_pair(CGAL::make_nth_of_tuple_property_map<3>(new_vertex), + PLY_property(btag.c_str()))); - fcolors.push_back (Color_rgb (get<1>(new_face), get<2>(new_face), get<3>(new_face))); + vcolors.push_back(Color_rgb(get<1>(new_vertex), get<2>(new_vertex), get<3>(new_vertex))); } else - PLY::process_properties (element, new_face, - std::make_pair (CGAL::make_nth_of_tuple_property_map<0>(new_face), - PLY_property >(vertex_indices_tag))); + internal::PLY::process_properties(element, new_vertex, + make_ply_point_reader(CGAL::make_nth_of_tuple_property_map<0>(new_vertex))); - polygons.push_back (Polygon_3(get<0>(new_face).size())); - for (std::size_t i = 0; i < get<0>(new_face).size(); ++ i) - polygons.back()[i] = std::size_t(get<0>(new_face)[i]); + points.push_back(get<0>(new_vertex)); } - - return true; } - - } - - - template - bool - read_PLY( std::istream& in, - std::vector< Point_3 >& points, - std::vector< Polygon_3 >& polygons, - bool /* verbose */ = false) - { - if(!in) + else if(element.name() == "face" || element.name() == "faces") { - std::cerr << "Error: cannot open file" << std::endl; - return false; - } - - internal::PLY::PLY_reader reader; - - if (!(reader.init (in))) - { - in.setstate(std::ios::failbit); - return false; - } - - for (std::size_t i = 0; i < reader.number_of_elements(); ++ i) - { - internal::PLY::PLY_element& element = reader.element(i); - - if (element.name() == "vertex" || element.name() == "vertices") + if(element.has_property >("vertex_indices")) + internal::read_PLY_faces(in, element, polygons, fcolors, "vertex_indices"); + else if(element.has_property >("vertex_indices")) + internal::read_PLY_faces(in, element, polygons, fcolors, "vertex_indices"); + else if(element.has_property >("vertex_index")) + internal::read_PLY_faces(in, element, polygons, fcolors, "vertex_index"); + else if(element.has_property >("vertex_index")) + internal::read_PLY_faces(in, element, polygons, fcolors, "vertex_index"); + else { - for (std::size_t j = 0; j < element.number_of_items(); ++ j) + std::cerr << "Error: can't find vertex indices in PLY input" << std::endl; + return false; + } + } + else if(element.name() == "halfedge" ) + { + bool has_uv = false; + std::string stag = "source", ttag = "target", utag = "u", vtag = "v"; + if( element.has_property("source") && + element.has_property("target") && + element.has_property("u") && + element.has_property("v")) + { + has_uv = true; + } + cpp11::tuple new_hedge; + for(std::size_t j = 0; j < element.number_of_items(); ++ j) + { + for(std::size_t k = 0; k < element.number_of_properties(); ++ k) { - for (std::size_t k = 0; k < element.number_of_properties(); ++ k) - { - internal::PLY::PLY_read_number* property = element.property(k); - property->get (in); + internal::PLY::PLY_read_number* property = element.property(k); + property->get(in); - if (in.fail()) - return false; - } - - Point_3 new_vertex; - - internal::PLY::process_properties (element, new_vertex, - make_ply_point_reader (CGAL::Identity_property_map())); - - points.push_back (get<0>(new_vertex)); + if(in.eof()) + return false; } - } - else if (element.name() == "face" || element.name() == "faces") - { - std::vector dummy; - if (element.has_property > ("vertex_indices")) - internal::read_PLY_faces (in, element, polygons, dummy, "vertex_indices"); - else if (element.has_property > ("vertex_indices")) - internal::read_PLY_faces (in, element, polygons, dummy, "vertex_indices"); - else if (element.has_property > ("vertex_index")) - internal::read_PLY_faces (in, element, polygons, dummy, "vertex_index"); - else if (element.has_property > ("vertex_index")) - internal::read_PLY_faces (in, element, polygons, dummy, "vertex_index"); + if(has_uv) + { + internal::PLY::process_properties(element, new_hedge, + std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_hedge), + PLY_property(stag.c_str())), + std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_hedge), + PLY_property(ttag.c_str())), + std::make_pair(CGAL::make_nth_of_tuple_property_map<2>(new_hedge), + PLY_property(utag.c_str())), + std::make_pair(CGAL::make_nth_of_tuple_property_map<3>(new_hedge), + PLY_property(vtag.c_str()))); + hedges.push_back(std::make_pair(get<0>(new_hedge), get<1>(new_hedge))); + huvs.push_back(std::make_pair(get<2>(new_hedge), get<3>(new_hedge))); + } else { - std::cerr << "Error: can't find vertex indices in PLY input" << std::endl; - return false; - } - } - else // Read other elements and ignore - { - for (std::size_t j = 0; j < element.number_of_items(); ++ j) - { - for (std::size_t k = 0; k < element.number_of_properties(); ++ k) - { - internal::PLY::PLY_read_number* property = element.property(k); - property->get (in); - - if (in.fail()) - return false; - } + internal::PLY::process_properties(element, new_hedge, + std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_hedge), + PLY_property(stag.c_str())), + std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_hedge), + PLY_property(ttag.c_str())) + ); } } } - - return !in.bad(); - } - - template - bool - read_PLY( std::istream& in, - std::vector< Point_3 >& points, - std::vector< Polygon_3 >& polygons, - std::vector >& hedges, - std::vector& fcolors, - std::vector& vcolors, - std::vector >& huvs, - bool /* verbose */ = false) - { - if(!in) + else // Read other elements and ignore { - std::cerr << "Error: cannot open file" << std::endl; - return false; - } - internal::PLY::PLY_reader reader; - - if (!(reader.init (in))) - { - in.setstate(std::ios::failbit); - return false; - } - for (std::size_t i = 0; i < reader.number_of_elements(); ++ i) - { - internal::PLY::PLY_element& element = reader.element(i); - - if (element.name() == "vertex" || element.name() == "vertices") + for(std::size_t j = 0; j < element.number_of_items(); ++ j) { - bool has_colors = false; - std::string rtag = "r", gtag = "g", btag = "b"; - if ((element.has_property("red") || element.has_property("r")) && - (element.has_property("green") || element.has_property("g")) && - (element.has_property("blue") || element.has_property("b"))) + for(std::size_t k = 0; k < element.number_of_properties(); ++ k) { - has_colors = true; - if (element.has_property("red")) - { - rtag = "red"; gtag = "green"; btag = "blue"; - } - } - - for (std::size_t j = 0; j < element.number_of_items(); ++ j) - { - for (std::size_t k = 0; k < element.number_of_properties(); ++ k) - { - internal::PLY::PLY_read_number* property = element.property(k); - property->get (in); - - if (in.fail()) - return false; - } - - std::tuple new_vertex; - - if (has_colors) - { - internal::PLY::process_properties (element, new_vertex, - make_ply_point_reader (CGAL::make_nth_of_tuple_property_map<0>(new_vertex)), - std::make_pair (CGAL::make_nth_of_tuple_property_map<1>(new_vertex), - PLY_property(rtag.c_str())), - std::make_pair (CGAL::make_nth_of_tuple_property_map<2>(new_vertex), - PLY_property(gtag.c_str())), - std::make_pair (CGAL::make_nth_of_tuple_property_map<3>(new_vertex), - PLY_property(btag.c_str()))); - - vcolors.push_back (Color_rgb (get<1>(new_vertex), get<2>(new_vertex), get<3>(new_vertex))); - } - else - internal::PLY::process_properties (element, new_vertex, - make_ply_point_reader (CGAL::make_nth_of_tuple_property_map<0>(new_vertex))); - - points.push_back (get<0>(new_vertex)); - } - } - else if (element.name() == "face" || element.name() == "faces") - { - if (element.has_property > ("vertex_indices")) - internal::read_PLY_faces (in, element, polygons, fcolors, "vertex_indices"); - else if (element.has_property > ("vertex_indices")) - internal::read_PLY_faces (in, element, polygons, fcolors, "vertex_indices"); - else if (element.has_property > ("vertex_index")) - internal::read_PLY_faces (in, element, polygons, fcolors, "vertex_index"); - else if (element.has_property > ("vertex_index")) - internal::read_PLY_faces (in, element, polygons, fcolors, "vertex_index"); - else - { - std::cerr << "Error: can't find vertex indices in PLY input" << std::endl; - return false; - } - } - else if(element.name() == "halfedge" ) - { - bool has_uv = false; - std::string stag = "source", ttag = "target", utag = "u", vtag = "v"; - if ( element.has_property("source") && - element.has_property("target") && - element.has_property("u") && - element.has_property("v")) - { - has_uv = true; - } - cpp11::tuple new_hedge; - for (std::size_t j = 0; j < element.number_of_items(); ++ j) - { - for (std::size_t k = 0; k < element.number_of_properties(); ++ k) - { - internal::PLY::PLY_read_number* property = element.property(k); - property->get (in); - - if (in.eof()) - return false; - } - - if (has_uv) - { - internal::PLY::process_properties (element, new_hedge, - std::make_pair (CGAL::make_nth_of_tuple_property_map<0>(new_hedge), - PLY_property(stag.c_str())), - std::make_pair (CGAL::make_nth_of_tuple_property_map<1>(new_hedge), - PLY_property(ttag.c_str())), - std::make_pair (CGAL::make_nth_of_tuple_property_map<2>(new_hedge), - PLY_property(utag.c_str())), - std::make_pair (CGAL::make_nth_of_tuple_property_map<3>(new_hedge), - PLY_property(vtag.c_str()))); - hedges.push_back (std::make_pair(get<0>(new_hedge), get<1>(new_hedge))); - huvs.push_back (std::make_pair(get<2>(new_hedge), get<3>(new_hedge))); - } - else - internal::PLY::process_properties (element, new_hedge, - std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_hedge), - PLY_property(stag.c_str())), - std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_hedge), - PLY_property(ttag.c_str())) - ); - } - } - else // Read other elements and ignore - { - for (std::size_t j = 0; j < element.number_of_items(); ++ j) - { - for (std::size_t k = 0; k < element.number_of_properties(); ++ k) - { - internal::PLY::PLY_read_number* property = element.property(k); - property->get (in); - if (in.fail()) - return false; - } + internal::PLY::PLY_read_number* property = element.property(k); + property->get(in); + if(in.fail()) + return false; } } } - return !in.bad(); } + return !in.bad(); +} + +template +bool read_PLY(std::istream& in, + std::vector< Point_3 >& points, + std::vector< Polygon_3 >& polygons, + std::vector& fcolors, + std::vector& vcolors, + bool /* verbose */ = false) +{ + std::vector > dummy_pui; + std::vector > dummy_pf; + + return read_PLY(in, points, polygons, dummy_pui, fcolors, vcolors, dummy_pf); +} - template - bool - read_PLY( std::istream& in, - std::vector< Point_3 >& points, - std::vector< Polygon_3 >& polygons, - std::vector& fcolors, - std::vector& vcolors, - bool /* verbose */ = false) - { - std::vector > dummy_pui; - std::vector > dummy_pf; - return read_PLY(in, points, polygons, - dummy_pui, - fcolors, vcolors, - dummy_pf); - } } // namespace CGAL #endif // CGAL_IO_PLY_PLY_READER_H diff --git a/Stream_support/include/CGAL/IO/PLY/PLY_writer.h b/Stream_support/include/CGAL/IO/PLY/PLY_writer.h index 0d68bef4b85..2e4edbbb761 100644 --- a/Stream_support/include/CGAL/IO/PLY/PLY_writer.h +++ b/Stream_support/include/CGAL/IO/PLY/PLY_writer.h @@ -13,148 +13,144 @@ #include -namespace CGAL{ +namespace CGAL { - template - bool - write_PLY(std::ostream& out, - const std::vector< Point_3 >& points, - const std::vector< Polygon_3 >& polygons, - bool /* verbose */ = false) +template +bool write_PLY(std::ostream& out, + const std::vector< Point_3 >& points, + const std::vector< Polygon_3 >& polygons, + bool /* verbose */ = false) +{ + if(!out) { - - if(!out) - { - std::cerr << "Error: cannot open file" << std::endl; - return false; - } - - // Write header - out << "ply" << std::endl - << ((get_mode(out) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl - << "comment Generated by the CGAL library" << std::endl - << "element vertex " << points.size() << std::endl; - - internal::PLY::output_property_header (out, - make_ply_point_writer (CGAL::Identity_property_map())); - - out << "element face " << polygons.size() << std::endl; - - internal::PLY::output_property_header (out, - std::make_pair (CGAL::Identity_property_map(), - PLY_property >("vertex_indices"))); - - out << "end_header" << std::endl; - - for (std::size_t i = 0; i < points.size(); ++ i) - internal::PLY::output_properties (out, points.begin() + i, - make_ply_point_writer (CGAL::Identity_property_map())); - - for (std::size_t i = 0; i < polygons.size(); ++ i) - internal::PLY::output_properties (out, polygons.begin() + i, - std::make_pair (CGAL::Identity_property_map(), - PLY_property >("vertex_indices"))); - - return out.good(); + std::cerr << "Error: cannot open file" << std::endl; + return false; } - template - bool - write_PLY(std::ostream& out, - const SurfaceMesh& mesh, - bool /* verbose */ = false) + // Write header + out << "ply" << std::endl + << ((get_mode(out) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl + << "comment Generated by the CGAL library" << std::endl + << "element vertex " << points.size() << std::endl; + + internal::PLY::output_property_header(out, make_ply_point_writer (CGAL::Identity_property_map())); + + out << "element face " << polygons.size() << std::endl; + + internal::PLY::output_property_header(out, std::make_pair(CGAL::Identity_property_map(), + PLY_property >("vertex_indices"))); + + out << "end_header" << std::endl; + + for (std::size_t i = 0; i < points.size(); ++ i) + internal::PLY::output_properties(out, points.begin() + i, + make_ply_point_writer (CGAL::Identity_property_map())); + + for (std::size_t i = 0; i < polygons.size(); ++ i) + internal::PLY::output_properties(out, polygons.begin() + i, + std::make_pair(CGAL::Identity_property_map(), + PLY_property >("vertex_indices"))); + + return out.good(); +} + +template +bool write_PLY(std::ostream& out, + const SurfaceMesh& mesh, + bool /* verbose */ = false) +{ + typedef typename boost::graph_traits::face_descriptor face_descriptor; + typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::property_map::type::value_type Point_3; + typedef typename SurfaceMesh::template Property_map > UV_map; + + UV_map h_uv; + bool has_texture; + boost::tie(h_uv, has_texture) = mesh.template property_map >("h:uv"); + + if(!out) { - typedef typename boost::graph_traits::face_descriptor face_descriptor; - typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - typedef typename boost::property_map::type::value_type Point_3; - typedef typename SurfaceMesh::template Property_map > UV_map; - UV_map h_uv; - bool has_texture; - boost::tie(h_uv, has_texture) = mesh.template property_map >("h:uv"); - if(!out) - { - std::cerr << "Error: cannot open file" << std::endl; - return false; - } - - // Write header - out << "ply" << std::endl - << ((get_mode(out) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl - << "comment Generated by the CGAL library" << std::endl - << "element vertex " << num_vertices(mesh) << std::endl; - - internal::PLY::output_property_header (out, - make_ply_point_writer (CGAL::Identity_property_map())); - - out << "element face " << num_faces(mesh) << std::endl; - - internal::PLY::output_property_header (out, - std::make_pair (CGAL::Identity_property_map >(), - PLY_property >("vertex_indices"))); - - if(has_texture) - { - out << "element halfedge " << num_halfedges(mesh) << std::endl; - - internal::PLY::output_property_header (out, - std::make_pair (CGAL::Identity_property_map(), - PLY_property("source"))); - - internal::PLY::output_property_header (out, - std::make_pair (CGAL::Identity_property_map(), - PLY_property("target"))); - internal::PLY::output_property_header (out, - std::make_tuple (h_uv, - PLY_property("u"), - PLY_property("v"))); - } - out << "end_header" << std::endl; - - for(vertex_descriptor vd : vertices(mesh)) - { - Point_3 p = get(get(CGAL::vertex_point, mesh), vd); - internal::PLY::output_properties (out, &p, - make_ply_point_writer (CGAL::Identity_property_map())); - } - - - std::vector polygon; - for(face_descriptor fd : faces(mesh)) - { - polygon.clear(); - for(halfedge_descriptor hd : halfedges_around_face(halfedge(fd, mesh), mesh)) - polygon.push_back (get(get(boost::vertex_index, mesh), target(hd,mesh))); - - internal::PLY::output_properties (out, &polygon, - std::make_pair (CGAL::Identity_property_map >(), - PLY_property >("vertex_indices"))); - } - - if(has_texture) - { - for(halfedge_descriptor hd : halfedges(mesh)) - { - typedef std::tuple Super_tuple; - Super_tuple t = - std::make_tuple(source(hd, mesh),target(hd, mesh), - h_uv[hd].first, - h_uv[hd].second); - - internal::PLY::output_properties (out, &t, - std::make_pair (Nth_of_tuple_property_map<0,Super_tuple>(), - PLY_property("source")), - std::make_pair (Nth_of_tuple_property_map<1,Super_tuple>(), - PLY_property("target")), - std::make_pair (Nth_of_tuple_property_map<2,Super_tuple>(), - PLY_property("u")), - std::make_pair (Nth_of_tuple_property_map<3,Super_tuple>(), - PLY_property("v"))); - } - } - return out.good(); + std::cerr << "Error: cannot open file" << std::endl; + return false; } + // Write header + out << "ply" << std::endl + << ((get_mode(out) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl + << "comment Generated by the CGAL library" << std::endl + << "element vertex " << num_vertices(mesh) << std::endl; + + internal::PLY::output_property_header(out, + make_ply_point_writer (CGAL::Identity_property_map())); + + out << "element face " << num_faces(mesh) << std::endl; + + internal::PLY::output_property_header(out, + std::make_pair(CGAL::Identity_property_map >(), + PLY_property >("vertex_indices"))); + + if(has_texture) + { + out << "element halfedge " << num_halfedges(mesh) << std::endl; + + internal::PLY::output_property_header(out, + std::make_pair(CGAL::Identity_property_map(), + PLY_property("source"))); + + internal::PLY::output_property_header(out, + std::make_pair(CGAL::Identity_property_map(), + PLY_property("target"))); + internal::PLY::output_property_header(out, + std::make_tuple (h_uv, + PLY_property("u"), + PLY_property("v"))); + } + out << "end_header" << std::endl; + + for(vertex_descriptor vd : vertices(mesh)) + { + Point_3 p = get(get(CGAL::vertex_point, mesh), vd); + internal::PLY::output_properties(out, &p, + make_ply_point_writer (CGAL::Identity_property_map())); + } + + std::vector polygon; + for(face_descriptor fd : faces(mesh)) + { + polygon.clear(); + for(halfedge_descriptor hd : halfedges_around_face(halfedge(fd, mesh), mesh)) + polygon.push_back(get(get(boost::vertex_index, mesh), target(hd,mesh))); + + internal::PLY::output_properties(out, &polygon, + std::make_pair(CGAL::Identity_property_map >(), + PLY_property >("vertex_indices"))); + } + + if(has_texture) + { + for(halfedge_descriptor hd : halfedges(mesh)) + { + typedef std::tuple Super_tuple; + Super_tuple t = std::make_tuple(source(hd, mesh),target(hd, mesh), + h_uv[hd].first, + h_uv[hd].second); + + internal::PLY::output_properties(out, &t, + std::make_pair(Nth_of_tuple_property_map<0,Super_tuple>(), + PLY_property("source")), + std::make_pair(Nth_of_tuple_property_map<1,Super_tuple>(), + PLY_property("target")), + std::make_pair(Nth_of_tuple_property_map<2,Super_tuple>(), + PLY_property("u")), + std::make_pair(Nth_of_tuple_property_map<3,Super_tuple>(), + PLY_property("v"))); + } + } + + return out.good(); +} + } // namespace CGAL #endif // CGAL_IO_PLY_PLY_WRITER_H diff --git a/Stream_support/include/CGAL/IO/STL/STL_reader.h b/Stream_support/include/CGAL/IO/STL/STL_reader.h index 947c927491e..9a74f1b5afd 100644 --- a/Stream_support/include/CGAL/IO/STL/STL_reader.h +++ b/Stream_support/include/CGAL/IO/STL/STL_reader.h @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include @@ -40,7 +40,7 @@ bool read_ASCII_facet(std::istream& input, std::string s; std::string vertex("vertex"), - endfacet("endfacet"); + endfacet("endfacet"); int count = 0; double x,y,z; @@ -133,9 +133,8 @@ bool parse_ASCII_STL(std::istream& input, if(s == solid) { if(in_solid) - { break; - } + in_solid = true; } if(s == facet) @@ -149,12 +148,14 @@ bool parse_ASCII_STL(std::istream& input, } } - if(in_solid){ + if(in_solid) + { if(verbose) std::cerr << "Error while parsing ASCII file" << std::endl; return false; } + return true; } @@ -331,9 +332,7 @@ bool read_STL(std::istream& input, return true; // empty file // If the first word is not 'solid', the file must be binary - if(s != "solid" - || (word[5] !='\n' - && word[5] != ' ')) + if(s != "solid" || (word[5] !='\n' && word[5] != ' ')) { if(parse_binary_STL(input, points, facets, verbose)) { diff --git a/Stream_support/include/CGAL/IO/STL/STL_writer.h b/Stream_support/include/CGAL/IO/STL/STL_writer.h index c1df2bebe30..c60ec20f8d6 100644 --- a/Stream_support/include/CGAL/IO/STL/STL_writer.h +++ b/Stream_support/include/CGAL/IO/STL/STL_writer.h @@ -16,21 +16,17 @@ #include - - -namespace CGAL{ +namespace CGAL { template -std::ostream& -write_STL(const PointRange& points, - const TriangleRange& facets, - std::ostream& out) +std::ostream& write_STL(const PointRange& points, + const TriangleRange& facets, + std::ostream& out) { typedef typename PointRange::value_type Point; typedef typename CGAL::Kernel_traits::Kernel K; typedef typename K::Vector_3 Vector_3; - if (get_mode(out) == IO::BINARY) { out << "FileType: Binary "; @@ -43,14 +39,12 @@ write_STL(const PointRange& points, const Point& q = points[face[1]]; const Point& r = points[face[2]]; - Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0): - unit_normal(p,q,r); + Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0) : unit_normal(p,q,r); - const float coords[12]={ - static_cast(n.x()), static_cast(n.y()), static_cast(n.z()), - static_cast(p.x()), static_cast(p.y()), static_cast(p.z()), - static_cast(q.x()), static_cast(q.y()), static_cast(q.z()), - static_cast(r.x()), static_cast(r.y()), static_cast(r.z()) }; + const float coords[12] = { static_cast(n.x()), static_cast(n.y()), static_cast(n.z()), + static_cast(p.x()), static_cast(p.y()), static_cast(p.z()), + static_cast(q.x()), static_cast(q.y()), static_cast(q.z()), + static_cast(r.x()), static_cast(r.y()), static_cast(r.z()) }; for (int i=0; i<12; ++i) out.write(reinterpret_cast(&coords[i]), sizeof(coords[i])); @@ -66,8 +60,7 @@ write_STL(const PointRange& points, const Point& q = points[face[1]]; const Point& r = points[face[2]]; - Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0): - unit_normal(p,q,r); + Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0) : unit_normal(p,q,r); out << "facet normal " << n << "\nouter loop\n"; out << "vertex " << p << "\n"; out << "vertex " << q << "\n"; @@ -76,9 +69,10 @@ write_STL(const PointRange& points, } out << "endsolid\n"; } + return out; } -} // end of namespace CGAL +} // namespace CGAL #endif // CGAL_IO_STL_STL_WRITER_H diff --git a/Stream_support/include/CGAL/IO/VRML/File_writer_VRML_2.h b/Stream_support/include/CGAL/IO/VRML/File_writer_VRML_2.h index 16224cb0dd5..904e7760ce8 100644 --- a/Stream_support/include/CGAL/IO/VRML/File_writer_VRML_2.h +++ b/Stream_support/include/CGAL/IO/VRML/File_writer_VRML_2.h @@ -1,16 +1,16 @@ -// Copyright (c) 1997 +// Copyright (c) 1997 // Utrecht University (The Netherlands), // ETH Zurich (Switzerland), // INRIA Sophia-Antipolis (France), // Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. +// and Tel-Aviv University (Israel). All rights reserved. // // This file is part of CGAL (www.cgal.org) // // $URL$ // $Id$ // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// +// // // Author(s) : Lutz Kettner @@ -18,39 +18,70 @@ #define CGAL_IO_FILE_WRITER_VRML_2_H 1 #include + #include #include namespace CGAL { -class CGAL_EXPORT File_writer_VRML_2 { - std::ostream* m_out; - std::size_t m_facets; +class File_writer_VRML_2 +{ + std::ostream* m_out; + std::size_t m_facets; public: - File_writer_VRML_2() {} - std::ostream& out() const { return *m_out; } - void write_header( std::ostream& o, - std::size_t vertices, - std::size_t halfedges, - std::size_t facets); - void write_footer() const; - void write_vertex( const double& x, const double& y, const double& z) { - out() << " " - << x << ' ' << y << ' ' << z << ',' << '\n'; - } - void write_facet_header() const; - void write_facet_begin( std::size_t) { - out() << " "; - } - void write_facet_vertex_index( std::size_t idx) { out() << idx << ',';} - void write_facet_end() { out() << "-1,\n"; } + File_writer_VRML_2() {} + std::ostream& out() const { return *m_out; } + void write_header( std::ostream& o, + std::size_t vertices, + std::size_t halfedges, + std::size_t facets) + { + m_out = &o; + m_facets = facets; + + out() << " #-- Begin of Polyhedron_3\n"; + out() << " # " << vertices << " vertices\n"; + out() << " # " << halfedges << " halfedges\n"; + out() << " # " << facets << " facets\n"; + out() << " Group {\n" + " children [\n" + " Shape {\n" + " appearance Appearance { material " + "USE Material }\n" + " geometry IndexedFaceSet {\n" + " convex FALSE\n" + " solid FALSE\n" + " coord Coordinate {\n" + " point [" << std::endl; + } + + void write_footer() const + { + out() << " ] #coordIndex\n" + " } #geometry\n" + " } #Shape\n" + " ] #children\n" + " } #Group" << std::endl; + } + + void write_vertex( const double& x, const double& y, const double& z) { + out() << " " + << x << ' ' << y << ' ' << z << ',' << '\n'; + } + void write_facet_header() const + { + out() << " ] #point\n" + " } #coord Coordinate\n" + " coordIndex [" << std::endl; + } + + void write_facet_begin( std::size_t) { + out() << " "; + } + void write_facet_vertex_index( std::size_t idx) { out() << idx << ',';} + void write_facet_end() { out() << "-1,\n"; } }; -} //namespace CGAL - -#ifdef CGAL_HEADER_ONLY -#include -#endif // CGAL_HEADER_ONLY +} // namespace CGAL #endif // CGAL_IO_FILE_WRITER_VRML_2_H // -// EOF // diff --git a/Stream_support/include/CGAL/IO/VRML/VRML_1_ostream.h b/Stream_support/include/CGAL/IO/VRML/VRML_1_ostream.h index ecbb29ffb71..ba761207f9f 100644 --- a/Stream_support/include/CGAL/IO/VRML/VRML_1_ostream.h +++ b/Stream_support/include/CGAL/IO/VRML/VRML_1_ostream.h @@ -1,16 +1,16 @@ -// Copyright (c) 1997 +// Copyright (c) 1997 // Utrecht University (The Netherlands), // ETH Zurich (Switzerland), // INRIA Sophia-Antipolis (France), // Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. +// and Tel-Aviv University (Israel). All rights reserved. // // This file is part of CGAL (www.cgal.org); // // $URL$ // $Id$ // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// +// // Author(s) : Andreas Fabri // Lutz Kettner // Herve Bronnimann @@ -20,6 +20,7 @@ #define CGAL_IO_VRML_VRML_1_OSTREAM_H #include + #include // Declare the common base class for OpenInventor and VRML 1.0 format. @@ -32,22 +33,23 @@ namespace CGAL { -class VRML_1_ostream : public Inventor_ostream_base { +class VRML_1_ostream : public Inventor_ostream_base +{ public: - VRML_1_ostream() {} - VRML_1_ostream(std::ostream& o) : Inventor_ostream_base(o) { - header(); - } - void open(std::ostream& o) { - Inventor_ostream_base::open(o); - header(); - } + VRML_1_ostream() {} + VRML_1_ostream(std::ostream& o) : Inventor_ostream_base(o) { header(); } + void open(std::ostream& o) { + Inventor_ostream_base::open(o); + header(); + } + private: - void header() { - os() << "#VRML V1.0 ascii" << std::endl; - os() << "# File written with the help of the CGAL Library" - << std::endl; - } + void header() + { + os() << "#VRML V1.0 ascii" << std::endl; + os() << "# File written with the help of the CGAL Library" + << std::endl; + } }; } //namespace CGAL @@ -86,11 +88,13 @@ operator<<(VRML_1_ostream& os, << CGAL::to_double(t[3].y()) << " " << CGAL::to_double(t[3].z()) << " ]" << "\n } #Coordinate3" ; + os.os() << "\n IndexedFaceSet {" << Indent << "coordIndex [ 0,1,2,-1, 1,3,2,-1,\n" << Indent << " 0,2,3,-1, 0,3,1,-1 ]\n" << "\n } #IndexedFaceSet" << "\n } #Separator\n"; + return os; } diff --git a/Stream_support/include/CGAL/IO/VRML/VRML_2_ostream.h b/Stream_support/include/CGAL/IO/VRML/VRML_2_ostream.h index 091d113e4e4..8bf9295b657 100644 --- a/Stream_support/include/CGAL/IO/VRML/VRML_2_ostream.h +++ b/Stream_support/include/CGAL/IO/VRML/VRML_2_ostream.h @@ -1,9 +1,9 @@ -// Copyright (c) 1997 +// Copyright (c) 1997 // Utrecht University (The Netherlands), // ETH Zurich (Switzerland), // INRIA Sophia-Antipolis (France), // Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. +// and Tel-Aviv University (Israel). All rights reserved. // // This file is part of CGAL (www.cgal.org); // @@ -24,76 +24,80 @@ namespace CGAL { -class VRML_2_ostream { +class VRML_2_ostream +{ public: - VRML_2_ostream() : m_os(0) {} - VRML_2_ostream(std::ostream& o) : m_os(&o) { header();} - ~VRML_2_ostream() { close(); } - void open(std::ostream& o) { m_os = &o; header(); } - void close() { - if ( m_os) - footer(); - m_os = 0; - } - explicit operator bool () { - return m_os && !m_os->fail(); - } - std::ostream& os() { - // The behaviour if m_os == 0 could be changed to return - // cerr or a file handle to /dev/null. The latter one would - // mimick the behaviour that one can still use a stream with - // an invalid stream, but without producing any output. - CGAL_assertion( m_os != 0 ); - return *m_os; - } + VRML_2_ostream() : m_os(0) {} + VRML_2_ostream(std::ostream& o) : m_os(&o) { header(); } + ~VRML_2_ostream() { close(); } + void open(std::ostream& o) { m_os = &o; header(); } + void close() + { + if ( m_os) + footer(); + m_os = 0; + } + + explicit operator bool () { return m_os && !m_os->fail(); } + + std::ostream& os() + { + // The behaviour if m_os == 0 could be changed to return + // cerr or a file handle to /dev/null. The latter one would + // mimick the behaviour that one can still use a stream with + // an invalid stream, but without producing any output. + CGAL_assertion( m_os != 0 ); + return *m_os; + } + private: - void header() { - os() << "#VRML V2.0 utf8\n" - "# File written with the help of the CGAL Library\n" - "#-- Begin of file header\n" - "Group {\n" - " children [\n" - " Shape {\n" - " appearance DEF A1 Appearance {\n" - " material Material {\n" - " diffuseColor .6 .5 .9\n" - " }\n }\n" - " appearance\n" - " Appearance {\n" - " material DEF Material Material {}\n" - " }\n" - " geometry nullptr\n" - " }\n" - " #-- End of file header" << std::endl; - } - void footer() { - os() << " #-- Begin of file footer\n" - " ]\n" - "}\n" - "#-- End of file footer" << std::endl; - } - std::ostream* m_os; + void header() + { + os() << "#VRML V2.0 utf8\n" + "# File written with the help of the CGAL Library\n" + "#-- Begin of file header\n" + "Group {\n" + " children [\n" + " Shape {\n" + " appearance DEF A1 Appearance {\n" + " material Material {\n" + " diffuseColor .6 .5 .9\n" + " }\n }\n" + " appearance\n" + " Appearance {\n" + " material DEF Material Material {}\n" + " }\n" + " geometry nullptr\n" + " }\n" + " #-- End of file header" << std::endl; + } + + void footer() + { + os() << " #-- Begin of file footer\n" + " ]\n" + "}\n" + "#-- End of file footer" << std::endl; + } + + std::ostream* m_os; }; -inline -VRML_2_ostream& -operator<<(VRML_2_ostream& os, - const char* s) +inline VRML_2_ostream& operator<<(VRML_2_ostream& os, + const char* s) { os.os() << s; return os; } -inline -VRML_2_ostream& -operator<<(VRML_2_ostream& os, - const double& d) +inline VRML_2_ostream& operator<<(VRML_2_ostream& os, + const double& d) { os.os() << d; return os; } -} //namespace CGAL +} // namespace CGAL #endif // CGAL_IO_VRML_2_OSTREAM_H @@ -109,42 +113,43 @@ operator<<(VRML_2_ostream& os, const Tetrahedron_3 &t) { const char *Indent = " "; - os << " Group {\n" - " children [\n" - " Shape {\n" - " appearance\n" - " Appearance {\n" - " material USE Material\n" - " } #Appearance\n" - " geometry\n" - " IndexedFaceSet {\n" - " coord Coordinate {\n" - " point [ \n" - << Indent << " " - << CGAL::to_double(t[0].x()) << " " - << CGAL::to_double(t[0].y()) << " " - << CGAL::to_double(t[0].z()) << " ,\n" - << Indent << " " - << CGAL::to_double(t[1].x()) << " " - << CGAL::to_double(t[1].y()) << " " - << CGAL::to_double(t[1].z()) << " ,\n" - << Indent << " " - << CGAL::to_double(t[2].x()) << " " - << CGAL::to_double(t[2].y()) << " " - << CGAL::to_double(t[2].z()) << " ,\n" - << Indent << " " - << CGAL::to_double(t[3].x()) << " " - << CGAL::to_double(t[3].y()) << " " - << CGAL::to_double(t[3].z()) << - "\n ]\n" - " }\n" - " solid FALSE\n" - << Indent << "coordIndex [ 0,1,2,-1, 1,3,2,-1,\n" - << Indent << " 0,2,3,-1, 0,3,1,-1 ]\n" - " } #IndexedFaceSet\n" - " } #Shape\n" - " ] #children\n" - " } #Group\n"; + os << " Group {\n" + " children [\n" + " Shape {\n" + " appearance\n" + " Appearance {\n" + " material USE Material\n" + " } #Appearance\n" + " geometry\n" + " IndexedFaceSet {\n" + " coord Coordinate {\n" + " point [ \n" + << Indent << " " + << CGAL::to_double(t[0].x()) << " " + << CGAL::to_double(t[0].y()) << " " + << CGAL::to_double(t[0].z()) << " ,\n" + << Indent << " " + << CGAL::to_double(t[1].x()) << " " + << CGAL::to_double(t[1].y()) << " " + << CGAL::to_double(t[1].z()) << " ,\n" + << Indent << " " + << CGAL::to_double(t[2].x()) << " " + << CGAL::to_double(t[2].y()) << " " + << CGAL::to_double(t[2].z()) << " ,\n" + << Indent << " " + << CGAL::to_double(t[3].x()) << " " + << CGAL::to_double(t[3].y()) << " " + << CGAL::to_double(t[3].z()) << + "\n ]\n" + " }\n" + " solid FALSE\n" + << Indent << "coordIndex [ 0,1,2,-1, 1,3,2,-1,\n" + << Indent << " 0,2,3,-1, 0,3,1,-1 ]\n" + " } #IndexedFaceSet\n" + " } #Shape\n" + " ] #children\n" + " } #Group\n"; + return os; } @@ -165,16 +170,15 @@ operator<<(VRML_2_ostream& os, const Point_3 &p) { const char *Indent = " "; - os << " Group {\n" - " children [\n" - " Shape {\n" - " appearance USE A1\n" - " geometry\n" - " PointSet {\n" - " coord Coordinate {\n" - " point [ "; - os << CGAL::to_double(p.x()) << " " << CGAL::to_double(p.y()) - << " " << CGAL::to_double(p.z()) << " ]\n"; + os << " Group {\n" + " children [\n" + " Shape {\n" + " appearance USE A1\n" + " geometry\n" + " PointSet {\n" + " coord Coordinate {\n" + " point [ "; + os << CGAL::to_double(p.x()) << " " << CGAL::to_double(p.y()) << " " << CGAL::to_double(p.z()) << " ]\n"; os << Indent << "}\n"; os << Indent << "} # PointSet\n"; os << " } #Shape\n" @@ -188,8 +192,6 @@ operator<<(VRML_2_ostream& os, #endif // CGAL_IO_VRML_2_POINT_3 #endif // CGAL_POINT_3_H - - #ifdef CGAL_TRIANGLE_3_H #ifndef CGAL_IO_VRML_2_TRIANGLE_3 #define CGAL_IO_VRML_2_TRIANGLE_3 @@ -202,37 +204,34 @@ operator<<(VRML_2_ostream& os, const Triangle_3 &t) { const char *Indent = " "; - os << " Group {\n" - " children [\n" - " Shape {\n" - " appearance USE A1\n" - " geometry\n" - " IndexedLineSet {\n" - " coord Coordinate {\n" - " point [ \n"; + os << " Group {\n" + " children [\n" + " Shape {\n" + " appearance USE A1\n" + " geometry\n" + " IndexedLineSet {\n" + " coord Coordinate {\n" + " point [ \n"; os << Indent ; - os << CGAL::to_double(t[0].x()) << " " << CGAL::to_double(t[0].y()) - << " " << CGAL::to_double(t[0].z()) << ",\n"; + os << CGAL::to_double(t[0].x()) << " " << CGAL::to_double(t[0].y()) << " " << CGAL::to_double(t[0].z()) << ",\n"; os << Indent; - os << CGAL::to_double(t[1].x()) << " " << CGAL::to_double(t[1].y()) - << " " << CGAL::to_double(t[1].z()) << ",\n"; + os << CGAL::to_double(t[1].x()) << " " << CGAL::to_double(t[1].y()) << " " << CGAL::to_double(t[1].z()) << ",\n"; os << Indent; - os << CGAL::to_double(t[2].x()) << " " << CGAL::to_double(t[2].y()) - << " " << CGAL::to_double(t[2].z()) << " ]\n"; + os << CGAL::to_double(t[2].x()) << " " << CGAL::to_double(t[2].y()) << " " << CGAL::to_double(t[2].z()) << " ]\n"; os << Indent << "}\n" << Indent << "coordIndex [ 0 1, 1 2, 2 0 -1 ]\n"; os << Indent << "} # IndexedLineSet\n"; os << " } #Shape\n" " ] #children\n" " } #Group\n"; + return os; } -} //namespace CGAL +} // namespace CGAL #endif // CGAL_IO_VRML_2_TRIANGLE_3 #endif // CGAL_TRIANGLE_3_H - #ifdef CGAL_SEGMENT_3_H #ifndef CGAL_IO_VRML_2_SEGMENT_3 #define CGAL_IO_VRML_2_SEGMENT_3 @@ -245,20 +244,20 @@ operator<<(VRML_2_ostream& os, const Segment_3 &s) { const char *Indent = " "; - os << " Group {\n" - " children [\n" - " Shape {\n" - " appearance USE A1\n" - " geometry\n" - " IndexedLineSet {\n" - " coord Coordinate {\n" - " point [ \n"; - os << Indent << CGAL::to_double(s.source().x()); - os << " " << CGAL::to_double(s.source().y()) + os << " Group {\n" + " children [\n" + " Shape {\n" + " appearance USE A1\n" + " geometry\n" + " IndexedLineSet {\n" + " coord Coordinate {\n" + " point [ \n"; + os << Indent << CGAL::to_double(s.source().x()) + << " " << CGAL::to_double(s.source().y()) << " " << CGAL::to_double(s.source().z()) << ",\n"; os << Indent; os << CGAL::to_double(s.target().x()) - << " " << CGAL::to_double(s.target().y()) + << " " << CGAL::to_double(s.target().y()) << " " << CGAL::to_double(s.target().z()) << " ]\n"; os << Indent << "}\n" << Indent << "coordIndex [ 0 1 -1 ]\n"; os << Indent << "} # IndexedLineSet\n"; @@ -285,23 +284,23 @@ VRML_2_ostream& operator<<(VRML_2_ostream& os, const Sphere_3 &s) { - os << " Group {\n" - " children [\n" - " Transform {\n" - " translation "; - os << CGAL::to_double(s.center().x()) << " " - << CGAL::to_double(s.center().y()) << " " - << CGAL::to_double(s.center().z()) << "\n"; - os << " children Shape {\n" - " appearance USE A1\n" - " geometry\n" - " Sphere { " - "radius "; - os << std::sqrt(CGAL::to_double(s.squared_radius())) <<" }\n"; - os << " } #children Shape\n" - " } # Transform\n" - " ] #children\n" - " } #Group\n"; + os << " Group {\n" + " children [\n" + " Transform {\n" + " translation "; + os << CGAL::to_double(s.center().x()) << " " + << CGAL::to_double(s.center().y()) << " " + << CGAL::to_double(s.center().z()) << "\n"; + os << " children Shape {\n" + " appearance USE A1\n" + " geometry\n" + " Sphere { " + "radius "; + os << std::sqrt(CGAL::to_double(s.squared_radius())) <<" }\n"; + os << " } #children Shape\n" + " } # Transform\n" + " ] #children\n" + " } #Group\n"; return os; } diff --git a/Stream_support/include/CGAL/IO/VTK/write_vtk.h b/Stream_support/include/CGAL/IO/VTK/write_vtk.h index 8c72c994077..4adeaae958c 100644 --- a/Stream_support/include/CGAL/IO/VTK/write_vtk.h +++ b/Stream_support/include/CGAL/IO/VTK/write_vtk.h @@ -1,12 +1,12 @@ // Copyright (c) 2018 -// GeometryFactory( France) All rights reserved. +// GeometryFactory (France) All rights reserved. // // This file is part of CGAL (www.cgal.org) // // $URL$ // $Id$ // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// +// // // Author(s) : Stephane Tayeb @@ -17,15 +17,15 @@ #include #include -template -void -write_vector(std::ostream& os, - const std::vector& vect) + +template +void write_vector(std::ostream& os, + const std::vector& vect) { const char* buffer = reinterpret_cast(&(vect[0])); std::size_t size = vect.size()*sizeof(FT); - + os.write(reinterpret_cast(&size), sizeof(std::size_t)); // number of bytes encoded os.write(buffer, vect.size()*sizeof(FT)); // encoded data } -#endif +#endif diff --git a/Stream_support/include/CGAL/IO/WKT.h b/Stream_support/include/CGAL/IO/WKT.h index 2b6f66fc8cf..d8e708602b9 100644 --- a/Stream_support/include/CGAL/IO/WKT.h +++ b/Stream_support/include/CGAL/IO/WKT.h @@ -14,19 +14,13 @@ #ifndef CGAL_IO_WKT_H #define CGAL_IO_WKT_H + #include #include #include #include #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) -#include -#include -#include - - -#include -#include #include #include @@ -36,68 +30,74 @@ #include #include +#include +#include -namespace CGAL{ +#include +#include +#include +namespace CGAL { namespace internal { - template - void pop_back_if_equal_to_front(CGAL::Polygon_2& poly) - { - typename CGAL::Polygon_2::iterator it = poly.end(); - --it; - if( (*poly.begin()) == *it){ - poly.erase(it); - } - } - - template - void pop_back_if_equal_to_front(CGAL::Polygon_with_holes_2& pwh) - { - pop_back_if_equal_to_front(pwh.outer_boundary()); - for(auto i = pwh.holes_begin(); i!= pwh.holes_end(); ++i){ - pop_back_if_equal_to_front(*i); - } - } +template +void pop_back_if_equal_to_front(CGAL::Polygon_2& poly) +{ + typename CGAL::Polygon_2::iterator it = poly.end(); + --it; + if((*poly.begin()) == *it) + poly.erase(it); } - + +template +void pop_back_if_equal_to_front(CGAL::Polygon_with_holes_2& pwh) +{ + pop_back_if_equal_to_front(pwh.outer_boundary()); + for(auto i = pwh.holes_begin(); i!= pwh.holes_end(); ++i) + pop_back_if_equal_to_front(*i); +} + +} // namespace internal + template -bool -read_point_WKT( std::istream& in, - Point& point) +bool read_point_WKT(std::istream& in, + Point& point) { if(!in) { std::cerr << "Error: cannot open file" << std::endl; return false; } - + std::string line; while(std::getline(in, line)) { std::istringstream iss(line); std::string type; iss >> type; - - if(type.substr(0, 5).compare("POINT")==0) + + if(type.substr(0, 5).compare("POINT") == 0) { - try{ - boost::geometry::read_wkt(line, point); - } catch(...) + try { - std::cerr<<"error."< -bool -read_multi_point_WKT( std::istream& in, - MultiPoint& mp) +bool read_multi_point_WKT(std::istream& in, + MultiPoint& mp) { if(!in) { @@ -111,13 +111,13 @@ read_multi_point_WKT( std::istream& in, std::istringstream iss(line); std::string type; iss >> type; - - if(type.substr(0, 10).compare("MULTIPOINT")==0) + + if(type.substr(0, 10).compare("MULTIPOINT") == 0) { try{ boost::geometry::read_wkt(line, gc); } catch(...){ - std::cerr<<"error."< -bool -read_linestring_WKT( std::istream& in, - LineString& polyline) +bool read_linestring_WKT(std::istream& in, + LineString& polyline) { if(!in) { @@ -144,13 +142,13 @@ read_linestring_WKT( std::istream& in, std::istringstream iss(line); std::string type; iss >> type; - - if(type.substr(0, 10).compare("LINESTRING")==0) + + if(type.substr(0, 10).compare("LINESTRING") == 0) { try{ boost::geometry::read_wkt(line, gc); } catch(...){ - std::cerr<<"error."< -bool -read_multi_linestring_WKT( std::istream& in, - MultiLineString& mls) +bool read_multi_linestring_WKT(std::istream& in, + MultiLineString& mls) { if(!in) { std::cerr << "Error: cannot open file" << std::endl; return false; } - typedef typename MultiLineString::value_type PointRange; + + typedef typename MultiLineString::value_type PointRange; typedef internal::Geometry_container LineString; - + std::vector pr_range; internal::Geometry_container, boost::geometry::multi_linestring_tag> gc(pr_range); std::string line; @@ -180,52 +178,58 @@ read_multi_linestring_WKT( std::istream& in, std::istringstream iss(line); std::string type; iss >> type; - - if(type.substr(0, 15).compare("MULTILINESTRING")==0) + + if(type.substr(0, 15).compare("MULTILINESTRING") == 0) { - try{ + try + { boost::geometry::read_wkt(line, gc); - } catch(...){ - std::cerr<<"error."< -bool -read_polygon_WKT( std::istream& in, - Polygon& polygon - ) +bool read_polygon_WKT(std::istream& in, + Polygon& polygon) { if(!in) { std::cerr << "Error: cannot open file" << std::endl; return false; } - + std::string line; while(std::getline(in, line)) { std::istringstream iss(line); std::string type; iss >> type; - - if(type.substr(0, 7).compare("POLYGON")==0) + + if(type.substr(0, 7).compare("POLYGON") == 0) { - try { + try + { boost::geometry::read_wkt(line, polygon); - } catch( ...){ + } + catch( ...) + { in.setstate(std::ios::failbit); return false; }; + internal::pop_back_if_equal_to_front(polygon); break; } @@ -234,16 +238,15 @@ read_polygon_WKT( std::istream& in, } template -bool -read_multi_polygon_WKT( std::istream& in, - MultiPolygon& polygons - ) +bool read_multi_polygon_WKT(std::istream& in, + MultiPolygon& polygons) { if(!in) { std::cerr << "Error: cannot open file" << std::endl; return false; } + internal::Geometry_container gc(polygons); std::string line; while(std::getline(in, line)) @@ -251,21 +254,22 @@ read_multi_polygon_WKT( std::istream& in, std::istringstream iss(line); std::string type; iss >> type; - - if(type.substr(0, 12).compare("MULTIPOLYGON")==0) + + if(type.substr(0, 12).compare("MULTIPOLYGON") == 0) { - try { + try + { boost::geometry::read_wkt(line, gc); - } catch( ...){ + } + catch( ...) + { in.setstate(std::ios::failbit); return false; }; - for( typename - internal::Geometry_container::iterator it - = gc.begin(); it != gc.end(); ++it) - { + + for(typename internal::Geometry_container::iterator it = gc.begin(); it != gc.end(); ++it) internal::pop_back_if_equal_to_front(*it); - } + break; } } @@ -273,56 +277,51 @@ read_multi_polygon_WKT( std::istream& in, } template -std::ostream& -write_point_WKT( std::ostream& out, - const Point& point - ) +std::ostream& write_point_WKT(std::ostream& out, + const Point& point) { if(!out) { std::cerr << "Error: cannot open file" << std::endl; return out; } - out< -std::ostream& -write_polygon_WKT( std::ostream& out, - const Polygon& poly - ) +std::ostream& write_polygon_WKT(std::ostream& out, + const Polygon& poly) { if(!out) { std::cerr << "Error: cannot open file" << std::endl; return out; } - out< -std::ostream& -write_linestring_WKT( std::ostream& out, - LineString ls - ) +std::ostream& write_linestring_WKT(std::ostream& out, + LineString ls) { if(!out) { std::cerr << "Error: cannot open file" << std::endl; return out; } + internal::Geometry_container gc(ls); - out< -std::ostream& -write_multi_point_WKT( std::ostream& out, - MultiPoint& mp - ) +std::ostream& write_multi_point_WKT(std::ostream& out, + MultiPoint& mp) { if(!out) { @@ -330,64 +329,65 @@ write_multi_point_WKT( std::ostream& out, return out; } internal::Geometry_container gc(mp); - out< -std::ostream& -write_multi_polygon_WKT( std::ostream& out, - MultiPolygon& polygons - ) +std::ostream& write_multi_polygon_WKT(std::ostream& out, + MultiPolygon& polygons) { if(!out) { std::cerr << "Error: cannot open file" << std::endl; return out; } + internal::Geometry_container gc(polygons); - out< -std::ostream& -write_multi_linestring_WKT( std::ostream& out, - MultiLineString& mls - ) +std::ostream& write_multi_linestring_WKT(std::ostream& out, + MultiLineString& mls) { if(!out) { std::cerr << "Error: cannot open file" << std::endl; return out; } - typedef typename MultiLineString::value_type PointRange; + + typedef typename MultiLineString::value_type PointRange; typedef internal::Geometry_container LineString; + std::vector pr_range; for(PointRange& pr : mls) { LineString ls(pr); pr_range.push_back(ls); } + internal::Geometry_container, boost::geometry::multi_linestring_tag> gc(pr_range); - out< -std::istream& -read_WKT( std::istream& input, - MultiPoint& points, - MultiLineString& polylines, - MultiPolygon& polygons) +std::istream& read_WKT(std::istream& input, + MultiPoint& points, + MultiLineString& polylines, + MultiPolygon& polygons) { do { typedef typename MultiPoint::value_type Point; typedef typename MultiLineString::value_type LineString; typedef typename MultiPolygon::value_type Polygon; + std::string line; std::streampos input_pos = input.tellg(); std::getline(input, line); @@ -395,13 +395,16 @@ read_WKT( std::istream& input, std::string t; std::string type=""; iss >> t; + for(std::size_t pos=0; pos < t.length(); ++pos) { - char c=t[pos]; - if(c=='(') + char c = t[pos]; + if(c == '(') break; + type.push_back(c); } + input.seekg(input_pos); if(type == "POINT") { @@ -427,24 +430,26 @@ read_WKT( std::istream& input, MultiPoint mp; CGAL::read_multi_point_WKT(input, mp); for(const Point& point : mp) - points.push_back(point); + points.push_back(point); } else if(type == "MULTILINESTRING") { MultiLineString mls; CGAL::read_multi_linestring_WKT(input, mls); for(const LineString& ls : mls) - polylines.push_back(ls); + polylines.push_back(ls); } else if(type == "MULTIPOLYGON") { MultiPolygon mp; CGAL::read_multi_polygon_WKT(input, mp); for(const Polygon& poly : mp) - polygons.push_back(poly); + polygons.push_back(poly); } - }while(input.good() && !input.eof()); - return input; + } + while(input.good() && !input.eof()); + + return input; } }//end CGAL #endif diff --git a/Stream_support/include/CGAL/IO/WKT/traits_linestring.h b/Stream_support/include/CGAL/IO/WKT/traits_linestring.h index 70148a37c8c..f16904cdb45 100644 --- a/Stream_support/include/CGAL/IO/WKT/traits_linestring.h +++ b/Stream_support/include/CGAL/IO/WKT/traits_linestring.h @@ -14,20 +14,27 @@ #ifndef CGAL_IO_WKT_TRAITS_LINESTRING_H #define CGAL_IO_WKT_TRAITS_LINESTRING_H + #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) + #include + #include #include +namespace boost { +namespace geometry { +namespace traits { +template< typename R> +struct tag > +{ + typedef linestring_tag type; +}; -namespace boost{ -namespace geometry{ -namespace traits{ -template< typename R> struct tag > -{ typedef linestring_tag type; }; +} // namespace traits +} // namespace geometry +} // namespace boost -}}} //end namespaces - -#endif -#endif // TRAITS_LINESTRING_H +#endif // BOOST VERSION CHECKS +#endif // CGAL_IO_WKT_TRAITS_LINESTRING_H diff --git a/Stream_support/include/CGAL/IO/WKT/traits_multilinestring.h b/Stream_support/include/CGAL/IO/WKT/traits_multilinestring.h index cc92f662d85..87d3527fbaf 100644 --- a/Stream_support/include/CGAL/IO/WKT/traits_multilinestring.h +++ b/Stream_support/include/CGAL/IO/WKT/traits_multilinestring.h @@ -14,21 +14,28 @@ #ifndef CGAL_IO_WKT_TRAITS_MULTILINESTRING_H #define CGAL_IO_WKT_TRAITS_MULTILINESTRING_H + #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) + #include + #include #include -namespace boost{ -namespace geometry{ -namespace traits{ +namespace boost { +namespace geometry { +namespace traits { + // WKT traits for MultiLinestring template< typename R > struct tag > -{ typedef multi_linestring_tag type; }; +{ + typedef multi_linestring_tag type; +}; -}//end traits -}//end geometry -}//end boost -#endif // TRAITS_MULTILINESTRING_H -#endif +} // namespace traits +} // namespace geometry +} // namespace boost + +#endif // BOOST VERSION CHECKS +#endif // CGAL_IO_WKT_TRAITS_MULTILINESTRING_H diff --git a/Stream_support/include/CGAL/IO/WKT/traits_multipoint.h b/Stream_support/include/CGAL/IO/WKT/traits_multipoint.h index edbbb3944bb..ac465fdbd42 100644 --- a/Stream_support/include/CGAL/IO/WKT/traits_multipoint.h +++ b/Stream_support/include/CGAL/IO/WKT/traits_multipoint.h @@ -14,21 +14,28 @@ #ifndef CGAL_IO_WKT_TRAITS_MULTIPOINT_H #define CGAL_IO_WKT_TRAITS_MULTIPOINT_H + #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) + #include + #include #include -namespace boost{ -namespace geometry{ -namespace traits{ +namespace boost { +namespace geometry { +namespace traits { + // WKT traits for MultiPoint template< typename R > struct tag > -{ typedef multi_point_tag type; }; +{ + typedef multi_point_tag type; +}; -}//end traits -}//end geometry -}//end boost -#endif // TRAITS_MULTIPOINT_H -#endif +} // namespace traits +} // namespace geometry +} // namespace boost + +#endif // BOOST VERSION CHECKS +#endif // CGAL_IO_WKT_TRAITS_MULTIPOINT_H diff --git a/Stream_support/include/CGAL/IO/WKT/traits_multipolygon.h b/Stream_support/include/CGAL/IO/WKT/traits_multipolygon.h index 09a935680d4..ab9211492a0 100644 --- a/Stream_support/include/CGAL/IO/WKT/traits_multipolygon.h +++ b/Stream_support/include/CGAL/IO/WKT/traits_multipolygon.h @@ -14,24 +14,29 @@ #ifndef CGAL_IO_WKT_TRAITS_MULTIPOLYGON_H #define CGAL_IO_WKT_TRAITS_MULTIPOLYGON_H + #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) + #include + #include #include +namespace boost { +namespace geometry { +namespace traits { -namespace boost{ -namespace geometry{ -namespace traits{ // WKT traits for MultiPolygon template< typename R > struct tag > -{ typedef multi_polygon_tag type; }; +{ + typedef multi_polygon_tag type; +}; -}//end traits -}//end geometry -}//end boost +} // namespace traits +} // namespace geometry +} // namespace boost -#endif -#endif +#endif // BOOST VERSION CHECKS +#endif // CGAL_IO_WKT_TRAITS_MULTIPOLYGON_H diff --git a/Stream_support/include/CGAL/IO/WKT/traits_point.h b/Stream_support/include/CGAL/IO/WKT/traits_point.h index 3fae251b35d..788b0f6a7e2 100644 --- a/Stream_support/include/CGAL/IO/WKT/traits_point.h +++ b/Stream_support/include/CGAL/IO/WKT/traits_point.h @@ -14,58 +14,60 @@ #ifndef CGAL_IO_WKT_TRAITS_POINT_H #define CGAL_IO_WKT_TRAITS_POINT_H + #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) + #include #include + #include #include -namespace boost{ -namespace geometry{ -namespace traits{ +namespace boost { +namespace geometry { +namespace traits { //WKT traits for Points -template< typename K > struct tag > -{ typedef point_tag type; }; - -template< typename K > struct coordinate_type > -{ typedef double type; }; - -template< typename K > struct coordinate_system > -{ typedef cs::cartesian type; }; - -template< typename K > struct dimension > : boost::mpl::int_<2> {}; - template< typename K > -struct access , 0> +struct tag > { - static double get(CGAL::Point_2 const& p) - { - return CGAL::to_double(p.x()); - } - - static void set(CGAL::Point_2 & p, typename K::FT c) - { - p = CGAL::Point_2 (c, p.y()); - } - + typedef point_tag type; }; template< typename K > -struct access , 1> +struct coordinate_type > { - static double get(CGAL::Point_2 const& p) - { - return CGAL::to_double(p.y()); - } - - static void set(CGAL::Point_2 & p, typename K::FT c) - { - p = CGAL::Point_2 (p.x(), c); - } - + typedef double type; }; -}}}//end namespaces -#endif -#endif +template< typename K > +struct coordinate_system > +{ + typedef cs::cartesian type; +}; + +template< typename K > +struct dimension > + : boost::mpl::int_<2> +{}; + +template< typename K > +struct access, 0> +{ + static double get(const CGAL::Point_2& p) { return CGAL::to_double(p.x()); } + static void set(CGAL::Point_2& p, typename K::FT c) { p = CGAL::Point_2(c, p.y()); } +}; + +template< typename K > +struct access, 1> +{ + static double get(const CGAL::Point_2& p) { return CGAL::to_double(p.y()); } + static void set(CGAL::Point_2& p, typename K::FT c) { p = CGAL::Point_2(p.x(), c); } +}; + +} // namespace traits +} // namespace geometry +} // namespace boost + +#endif // BOOST VERSION CHECKS +#endif // CGAL_IO_WKT_TRAITS_POINT_H diff --git a/Stream_support/include/CGAL/IO/WKT/traits_point_3.h b/Stream_support/include/CGAL/IO/WKT/traits_point_3.h index 5b27dbf8aeb..9aaa8b852d3 100644 --- a/Stream_support/include/CGAL/IO/WKT/traits_point_3.h +++ b/Stream_support/include/CGAL/IO/WKT/traits_point_3.h @@ -14,72 +14,67 @@ #ifndef CGAL_IO_WKT_TRAITS_POINT_3_H #define CGAL_IO_WKT_TRAITS_POINT_3_H + #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) + #include #include + #include #include -namespace boost{ -namespace geometry{ -namespace traits{ +namespace boost { +namespace geometry { +namespace traits { //WKT traits for Points -template< typename K > struct tag > -{ typedef point_tag type; }; - -template< typename K > struct coordinate_type > -{ typedef typename K::FT type; }; - -template< typename K > struct coordinate_system > -{ typedef cs::cartesian type; }; - -template< typename K > struct dimension > : boost::mpl::int_<3> {}; - template< typename K > -struct access , 0> +struct tag > { - static double get(CGAL::Point_3 const& p) - { - return CGAL::to_double(p.x()); - } - - static void set(CGAL::Point_3 & p, typename K::FT c) - { - p = CGAL::Point_3 (c, p.y(), p.z()); - } - + typedef point_tag type; }; template< typename K > -struct access , 1> +struct coordinate_type > { - static double get(CGAL::Point_3 const& p) - { - return CGAL::to_double(p.y()); - } - - static void set(CGAL::Point_3 & p, typename K::FT c) - { - p = CGAL::Point_3 (p.x(), c, p.z()); - } - -}; -template< typename K > -struct access , 2> -{ - static double get(CGAL::Point_3 const& p) - { - return CGAL::to_double(p.z()); - } - - static void set(CGAL::Point_3 & p, typename K::FT c) - { - p = CGAL::Point_3 (p.x(), p.y(), c); - } - + typedef typename K::FT type; }; -}}}//end namespaces -#endif -#endif +template< typename K > +struct coordinate_system > +{ + typedef cs::cartesian type; +}; + +template< typename K > +struct dimension > + : boost::mpl::int_<3> +{}; + +template< typename K > +struct access, 0> +{ + static double get(const CGAL::Point_3& p) { return CGAL::to_double(p.x()); } + static void set(CGAL::Point_3& p, typename K::FT c) { p = CGAL::Point_3 (c, p.y(), p.z()); } +}; + +template< typename K > +struct access, 1> +{ + static double get(const CGAL::Point_3& p) { return CGAL::to_double(p.y()); } + static void set(CGAL::Point_3& p, typename K::FT c) { p = CGAL::Point_3 (p.x(), c, p.z()); } +}; + +template< typename K > +struct access, 2> +{ + static double get(const CGAL::Point_3& p) { return CGAL::to_double(p.z()); } + static void set(CGAL::Point_3& p, typename K::FT c) { p = CGAL::Point_3 (p.x(), p.y(), c); } +}; + +} // namespace traits +} // namespace geometry +} // namespace boost + +#endif // BOOST VERSION CHECKS +#endif // CGAL_IO_WKT_TRAITS_POINT_3_H diff --git a/Stream_support/include/CGAL/IO/WKT/traits_polygon.h b/Stream_support/include/CGAL/IO/WKT/traits_polygon.h index 3fa6bae4aff..bbc8bbd204f 100644 --- a/Stream_support/include/CGAL/IO/WKT/traits_polygon.h +++ b/Stream_support/include/CGAL/IO/WKT/traits_polygon.h @@ -14,35 +14,50 @@ #ifndef CGAL_IO_WKT_TRAITS_POLYGON_H #define CGAL_IO_WKT_TRAITS_POLYGON_H + #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) + #include #include #include + #include #include -namespace boost{ -namespace geometry{ -namespace traits{ +namespace boost { +namespace geometry { +namespace traits { + // WKT traits for Polygon -template< typename K > struct tag > -{ typedef ring_tag type; }; +template< typename K > +struct tag > +{ + typedef ring_tag type; +}; template< typename K > struct tag > -{ typedef polygon_tag type; }; +{ + typedef polygon_tag type; +}; template< typename K > struct ring_const_type > -{ typedef const CGAL::Polygon_2& type; }; +{ + typedef const CGAL::Polygon_2& type; +}; template< typename K > struct ring_mutable_type > -{ typedef CGAL::Polygon_2& type; }; +{ + typedef CGAL::Polygon_2& type; +}; template< typename K > struct interior_const_type > -{ typedef const typename CGAL::Polygon_with_holes_2::Holes_container& type; }; +{ + typedef const typename CGAL::Polygon_with_holes_2::Holes_container& type; +}; template< typename K > struct interior_mutable_type > @@ -55,7 +70,7 @@ struct exterior_ring > { return (p.outer_boundary()); } - static CGAL::Polygon_2 const& get(CGAL::Polygon_with_holes_2 const& p) + static const CGAL::Polygon_2& get(const CGAL::Polygon_with_holes_2& p) { return (p.outer_boundary()); } @@ -73,8 +88,9 @@ struct interior_rings > return p.holes(); } }; -}//end traits -}//end geometry + +} // namespace traits +} // namespace geometry //extra specialization template< typename K > @@ -83,7 +99,7 @@ struct range_value > typedef typename CGAL::Polygon_2::Point_2 type; }; -}//end boost +} // namespace boost -#endif -#endif +#endif // BOOST VERSION CHECKS +#endif // CGAL_IO_WKT_TRAITS_POLYGON_H