Clean file IO code in Stream_support (no real changes)

This commit is contained in:
Mael Rouxel-Labbé 2020-01-20 10:42:46 +01:00
parent e317c689aa
commit 490a726ec0
22 changed files with 1409 additions and 1226 deletions

View File

@ -11,17 +11,21 @@
#ifndef CGAL_IO_READ_3MF_H #ifndef CGAL_IO_READ_3MF_H
#define CGAL_IO_READ_3MF_H #define CGAL_IO_READ_3MF_H
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <CGAL/IO/Color.h> #include <CGAL/IO/Color.h>
#include <CGAL/Kernel_traits.h> #include <CGAL/Kernel_traits.h>
#include <Model/COM/NMR_DLLInterfaces.h>
namespace CGAL{
#include <Model/COM/NMR_DLLInterfaces.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
namespace CGAL {
namespace transform_nmr_internal { namespace transform_nmr_internal {
NMR::MODELTRANSFORM initMatrix() NMR::MODELTRANSFORM initMatrix()
{ {
NMR::MODELTRANSFORM mMatrix; NMR::MODELTRANSFORM mMatrix;
@ -34,7 +38,8 @@ NMR::MODELTRANSFORM initMatrix()
return mMatrix; return mMatrix;
} }
}//end transform_nmr_internal
} // namespace transform_nmr_internal
template<typename PointRange, template<typename PointRange,
typename PolygonRange, typename PolygonRange,
@ -44,10 +49,12 @@ bool extract_soups (NMR::PLib3MFModelMeshObject *pMeshObject,
PointRange& points, PointRange& points,
PolygonRange& triangles, PolygonRange& triangles,
ColorRange& colors, ColorRange& colors,
std::string& name) { std::string& name)
{
typedef typename PointRange::value_type Point_3; typedef typename PointRange::value_type Point_3;
typedef typename PolygonRange::value_type Polygon; typedef typename PolygonRange::value_type Polygon;
typedef typename Kernel_traits<Point_3>::Kernel Kernel; typedef typename Kernel_traits<Point_3>::Kernel Kernel;
HRESULT hResult; HRESULT hResult;
DWORD nNeededChars; DWORD nNeededChars;
std::vector<char> pBuffer; std::vector<char> pBuffer;
@ -61,7 +68,8 @@ bool extract_soups (NMR::PLib3MFModelMeshObject *pMeshObject,
} }
// Retrieve Mesh Name // Retrieve Mesh Name
if (nNeededChars > 0) { if(nNeededChars > 0)
{
pBuffer.resize(nNeededChars + 1); pBuffer.resize(nNeededChars + 1);
hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, &pBuffer[0], nNeededChars + 1, NULL); hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, &pBuffer[0], nNeededChars + 1, NULL);
pBuffer[nNeededChars] = 0; pBuffer[nNeededChars] = 0;
@ -74,7 +82,9 @@ bool extract_soups (NMR::PLib3MFModelMeshObject *pMeshObject,
name = std::string(&pBuffer[0]); name = std::string(&pBuffer[0]);
} }
else else
{
name = std::string("Unknown Mesh"); name = std::string("Unknown Mesh");
}
typename Kernel::Aff_transformation_3 t( 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[0][0], transform.m_fFields[0][1], transform.m_fFields[0][2], transform.m_fFields[0][3],
@ -84,7 +94,8 @@ bool extract_soups (NMR::PLib3MFModelMeshObject *pMeshObject,
NMR::PLib3MFPropertyHandler * pPropertyHandler; NMR::PLib3MFPropertyHandler * pPropertyHandler;
hResult = NMR::lib3mf_meshobject_createpropertyhandler(pMeshObject, &pPropertyHandler); hResult = NMR::lib3mf_meshobject_createpropertyhandler(pMeshObject, &pPropertyHandler);
if (hResult != LIB3MF_OK) { if(hResult != LIB3MF_OK)
{
DWORD nErrorMessage; DWORD nErrorMessage;
LPCSTR pszErrorMessage; LPCSTR pszErrorMessage;
std::cerr << "could not create property handler: " << std::hex << hResult << std::endl; 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]); pVertex.m_fPosition[2]);
points[vid] = t.transform(p); points[vid] = t.transform(p);
} }
for(DWORD pid = 0; pid < triangles.size(); ++pid) for(DWORD pid = 0; pid < triangles.size(); ++pid)
{ {
NMR::MODELMESHTRIANGLE pTriangle; NMR::MODELMESHTRIANGLE pTriangle;
@ -117,6 +129,7 @@ bool extract_soups (NMR::PLib3MFModelMeshObject *pMeshObject,
colors[pid]=CGAL::Color(mColor.m_Red, mColor.m_Green, colors[pid]=CGAL::Color(mColor.m_Red, mColor.m_Green,
mColor.m_Blue, mColor.m_Alpha); mColor.m_Blue, mColor.m_Alpha);
} }
return true; return true;
} }
@ -128,7 +141,8 @@ bool extract_polylines (NMR::PLib3MFModelMeshObject *pMeshObject,
PointRange& points, PointRange& points,
PolygonRange&, PolygonRange&,
ColorRange& colors, ColorRange& colors,
std::string& name) { std::string& name)
{
typedef typename PointRange::value_type Point_3; typedef typename PointRange::value_type Point_3;
HRESULT hResult; HRESULT hResult;
@ -144,7 +158,8 @@ bool extract_polylines (NMR::PLib3MFModelMeshObject *pMeshObject,
} }
// Retrieve Mesh Name // Retrieve Mesh Name
if (nNeededChars > 0) { if(nNeededChars > 0)
{
pBuffer.resize(nNeededChars + 1); pBuffer.resize(nNeededChars + 1);
hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, &pBuffer[0], nNeededChars + 1, NULL); hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, &pBuffer[0], nNeededChars + 1, NULL);
pBuffer[nNeededChars] = 0; pBuffer[nNeededChars] = 0;
@ -164,7 +179,8 @@ bool extract_polylines (NMR::PLib3MFModelMeshObject *pMeshObject,
NMR::PLib3MFPropertyHandler * pPropertyHandler; NMR::PLib3MFPropertyHandler * pPropertyHandler;
hResult = NMR::lib3mf_meshobject_createpropertyhandler(pMeshObject, &pPropertyHandler); hResult = NMR::lib3mf_meshobject_createpropertyhandler(pMeshObject, &pPropertyHandler);
if (hResult != LIB3MF_OK) { if(hResult != LIB3MF_OK)
{
DWORD nErrorMessage; DWORD nErrorMessage;
LPCSTR pszErrorMessage; LPCSTR pszErrorMessage;
std::cerr << "could not create property handler: " << std::hex << hResult << std::endl; std::cerr << "could not create property handler: " << std::hex << hResult << std::endl;
@ -201,12 +217,14 @@ bool extract_point_clouds (NMR::PLib3MFModelMeshObject *pMeshObject,
PointRange& points, PointRange& points,
PolygonRange&, PolygonRange&,
ColorRange& colors, ColorRange& colors,
std::string& name) { std::string& name)
{
typedef typename PointRange::value_type Point_3; typedef typename PointRange::value_type Point_3;
HRESULT hResult; HRESULT hResult;
DWORD nNeededChars; DWORD nNeededChars;
std::vector<char> pBuffer; std::vector<char> pBuffer;
// Retrieve Mesh Name Length // Retrieve Mesh Name Length
hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, NULL, 0, &nNeededChars); hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, NULL, 0, &nNeededChars);
if(hResult != LIB3MF_OK) if(hResult != LIB3MF_OK)
@ -217,7 +235,8 @@ bool extract_point_clouds (NMR::PLib3MFModelMeshObject *pMeshObject,
} }
// Retrieve Mesh Name // Retrieve Mesh Name
if (nNeededChars > 0) { if(nNeededChars > 0)
{
pBuffer.resize(nNeededChars + 1); pBuffer.resize(nNeededChars + 1);
hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, &pBuffer[0], nNeededChars + 1, NULL); hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, &pBuffer[0], nNeededChars + 1, NULL);
pBuffer[nNeededChars] = 0; pBuffer[nNeededChars] = 0;
@ -229,7 +248,8 @@ bool extract_point_clouds (NMR::PLib3MFModelMeshObject *pMeshObject,
} }
name = std::string(&pBuffer[0]); name = std::string(&pBuffer[0]);
} }
else{ else
{
points.resize(0); points.resize(0);
return false; return false;
} }
@ -276,18 +296,19 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
PointRange&, PointRange&,
PolygonRange&, PolygonRange&,
ColorRange&, ColorRange&,
std::string&)> func std::string&)> func)
)
{ {
DWORD nInterfaceVersionMajor, nInterfaceVersionMinor, nInterfaceVersionMicro, nbVertices, nbPolygons; DWORD nInterfaceVersionMajor, nInterfaceVersionMinor, nInterfaceVersionMicro, nbVertices, nbPolygons;
HRESULT hResult; HRESULT hResult;
NMR::PLib3MFModel * pModel; NMR::PLib3MFModel * pModel;
NMR::PLib3MFModelReader * pReader; NMR::PLib3MFModelReader * pReader;
// Extract Extension of filename // Extract Extension of filename
std::string sReaderName("3mf"); std::string sReaderName("3mf");
hResult = NMR::lib3mf_getinterfaceversion(&nInterfaceVersionMajor, &nInterfaceVersionMinor, &nInterfaceVersionMicro); 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; std::cerr << "could not get 3MF Library version: " << std::hex << hResult << std::endl;
return -1; return -1;
} }
@ -301,7 +322,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
// Create Model Reader // Create Model Reader
hResult = NMR::lib3mf_model_queryreader(pModel, sReaderName.c_str(), &pReader); 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; std::cerr << "could not create model reader: " << std::hex << hResult << std::endl;
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
return -1; return -1;
@ -309,7 +331,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
// Import Model from File // Import Model from File
hResult = NMR::lib3mf_reader_readfromfileutf8(pReader, file_name.c_str()); 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; std::cerr << "could not parse file: " << std::hex << hResult << std::endl;
NMR::lib3mf_release(pReader); NMR::lib3mf_release(pReader);
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
@ -325,13 +348,16 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
NMR::PLib3MFModelResourceIterator * pResourceIterator; NMR::PLib3MFModelResourceIterator * pResourceIterator;
hResult = NMR::lib3mf_model_getobjects(pModel, &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; std::cerr << "could not get object: " << std::hex << hResult << std::endl;
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
return -1; return -1;
} }
hResult = NMR::lib3mf_resourceiterator_movenext(pResourceIterator, &pbHasNext); 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; std::cerr << "could not get next object: " << std::hex << hResult << std::endl;
NMR::lib3mf_release(pResourceIterator); NMR::lib3mf_release(pResourceIterator);
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
@ -350,7 +376,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
// get current resource // get current resource
hResult = NMR::lib3mf_resourceiterator_getcurrent(pResourceIterator, &pResource); 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; std::cerr << "could not get resource: " << std::hex << hResult << std::endl;
NMR::lib3mf_release(pResourceIterator); NMR::lib3mf_release(pResourceIterator);
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
@ -359,22 +386,26 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
// get resource ID // get resource ID
hResult = NMR::lib3mf_resource_getresourceid(pResource, &ResourceID); 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; std::cerr << "could not get resource id: " << std::hex << hResult << std::endl;
NMR::lib3mf_release(pResource); NMR::lib3mf_release(pResource);
NMR::lib3mf_release(pResourceIterator); NMR::lib3mf_release(pResourceIterator);
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
return -1; return -1;
} }
// Query mesh interface // Query mesh interface
BOOL bIsMeshObject; BOOL bIsMeshObject;
hResult = NMR::lib3mf_object_ismeshobject(pResource, &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. //skip it. Only get it through the components and buildItems.
} }
else { else
{
BOOL bIsComponentsObject; BOOL bIsComponentsObject;
hResult = NMR::lib3mf_object_iscomponentsobject(pResource, &bIsComponentsObject); hResult = NMR::lib3mf_object_iscomponentsobject(pResource, &bIsComponentsObject);
if((hResult == LIB3MF_OK) && (bIsComponentsObject)) { if((hResult == LIB3MF_OK) && (bIsComponentsObject)) {
@ -389,38 +420,45 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
NMR::PLib3MFModelResource * compResource; NMR::PLib3MFModelResource * compResource;
NMR::PLib3MFModelComponent * pComponent; NMR::PLib3MFModelComponent * pComponent;
hResult = NMR::lib3mf_componentsobject_getcomponent(pComponentsObject, nIndex, &pComponent); hResult = NMR::lib3mf_componentsobject_getcomponent(pComponentsObject, nIndex, &pComponent);
if (hResult != LIB3MF_OK) { if(hResult != LIB3MF_OK)
return -1; return -1;
}
hResult = NMR::lib3mf_component_getobjectresource(pComponent, &compResource); hResult = NMR::lib3mf_component_getobjectresource(pComponent, &compResource);
if (hResult != LIB3MF_OK) { if(hResult != LIB3MF_OK)
{
NMR::lib3mf_release(pComponent); NMR::lib3mf_release(pComponent);
return -1; return -1;
} }
hResult = NMR::lib3mf_object_ismeshobject(compResource, &bIsMeshObject); hResult = NMR::lib3mf_object_ismeshobject(compResource, &bIsMeshObject);
if(hResult == LIB3MF_OK) if(hResult == LIB3MF_OK)
{ {
if(bIsMeshObject) { if(bIsMeshObject)
{
BOOL bHasTransform; BOOL bHasTransform;
NMR::MODELTRANSFORM Transform; NMR::MODELTRANSFORM Transform;
hResult = NMR::lib3mf_component_hastransform(pComponent, &bHasTransform); hResult = NMR::lib3mf_component_hastransform(pComponent, &bHasTransform);
if (hResult != LIB3MF_OK) { if(hResult != LIB3MF_OK)
{
NMR::lib3mf_release(pComponent); NMR::lib3mf_release(pComponent);
return -1; return -1;
} }
if (bHasTransform) { if(bHasTransform)
{
// Retrieve Transform // Retrieve Transform
hResult = NMR::lib3mf_component_gettransform(pComponent, &Transform); hResult = NMR::lib3mf_component_gettransform(pComponent, &Transform);
if (hResult != LIB3MF_OK) { if(hResult != LIB3MF_OK)
{
NMR::lib3mf_release(pComponent); NMR::lib3mf_release(pComponent);
return -1; return -1;
} }
} }
else { else
{
Transform = transform_nmr_internal::initMatrix(); Transform = transform_nmr_internal::initMatrix();
} }
pMeshObject = compResource; pMeshObject = compResource;
NMR::lib3mf_meshobject_getvertexcount(pMeshObject, &nbVertices); NMR::lib3mf_meshobject_getvertexcount(pMeshObject, &nbVertices);
NMR::lib3mf_meshobject_gettrianglecount(pMeshObject, &nbPolygons); 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); ColorRange colors(nbPolygons);
std::string name; 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_points.push_back(points);
all_polygons.push_back(triangles); all_polygons.push_back(triangles);
all_colors.push_back(colors); all_colors.push_back(colors);
@ -442,16 +481,17 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
} }
} }
} }
// free instances // free instances
NMR::lib3mf_release(pResource); NMR::lib3mf_release(pResource);
hResult = NMR::lib3mf_resourceiterator_movenext(pResourceIterator, &pbHasNext); 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; std::cerr << "could not get next object: " << std::hex << hResult << std::endl;
return -1; return -1;
} }
} }
/******************************************************** /********************************************************
**** Iterate Build items To Find Transformed Meshes **** **** 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 // Iterate through all the Build items
NMR::PLib3MFModelBuildItemIterator * pBuildItemIterator; NMR::PLib3MFModelBuildItemIterator * pBuildItemIterator;
hResult = NMR::lib3mf_model_getbuilditems(pModel, &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; std::cout << "could not get build items: " << std::hex << hResult << std::endl;
NMR::lib3mf_release(pBuildItemIterator); NMR::lib3mf_release(pBuildItemIterator);
NMR::lib3mf_release(pModel); 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); 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; std::cout << "could not get next build item: " << std::hex << hResult << std::endl;
NMR::lib3mf_release(pBuildItemIterator); NMR::lib3mf_release(pBuildItemIterator);
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
return -1; return -1;
} }
while (pbHasNext) { while (pbHasNext)
{
NMR::PLib3MFModelMeshObject * pMeshObject; NMR::PLib3MFModelMeshObject * pMeshObject;
NMR::MODELTRANSFORM Transform; NMR::MODELTRANSFORM Transform;
NMR::PLib3MFModelBuildItem * pBuildItem; NMR::PLib3MFModelBuildItem * pBuildItem;
// Retrieve Build Item // Retrieve Build Item
hResult = NMR::lib3mf_builditemiterator_getcurrent(pBuildItemIterator, &pBuildItem); 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; std::cout << "could not get build item: " << std::hex << hResult << std::endl;
NMR::lib3mf_release(pBuildItemIterator); NMR::lib3mf_release(pBuildItemIterator);
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
@ -490,7 +534,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
// Retrieve Resource // Retrieve Resource
NMR::PLib3MFModelObjectResource * pObjectResource; NMR::PLib3MFModelObjectResource * pObjectResource;
hResult = NMR::lib3mf_builditem_getobjectresource(pBuildItem, &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; std::cout << "could not get build item resource: " << std::hex << hResult << std::endl;
NMR::lib3mf_release(pBuildItem); NMR::lib3mf_release(pBuildItem);
NMR::lib3mf_release(pBuildItemIterator); NMR::lib3mf_release(pBuildItemIterator);
@ -502,7 +547,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
hResult = NMR::lib3mf_object_ismeshobject(pObjectResource, &bIsMeshObject); hResult = NMR::lib3mf_object_ismeshobject(pObjectResource, &bIsMeshObject);
if(hResult == LIB3MF_OK) if(hResult == LIB3MF_OK)
{ {
if(bIsMeshObject) { if(bIsMeshObject)
{
pMeshObject = pObjectResource; pMeshObject = pObjectResource;
NMR::lib3mf_meshobject_getvertexcount(pMeshObject, &nbVertices); NMR::lib3mf_meshobject_getvertexcount(pMeshObject, &nbVertices);
NMR::lib3mf_meshobject_gettrianglecount(pMeshObject, &nbPolygons); 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); ColorRange colors(nbPolygons);
std::string name; std::string name;
// Check Object Transform // Check Object Transform
BOOL bHasTransform; BOOL bHasTransform;
hResult = NMR::lib3mf_builditem_hasobjecttransform(pBuildItem, &bHasTransform); hResult = NMR::lib3mf_builditem_hasobjecttransform(pBuildItem, &bHasTransform);
if (hResult != LIB3MF_OK) { if(hResult != LIB3MF_OK)
{
NMR::lib3mf_release(pBuildItem); NMR::lib3mf_release(pBuildItem);
NMR::lib3mf_release(pBuildItemIterator); NMR::lib3mf_release(pBuildItemIterator);
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
@ -523,7 +569,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
return -1; return -1;
} }
if (bHasTransform) { if(bHasTransform)
{
// Retrieve Transform // Retrieve Transform
hResult = NMR::lib3mf_builditem_getobjecttransform(pBuildItem, &Transform); hResult = NMR::lib3mf_builditem_getobjecttransform(pBuildItem, &Transform);
if(hResult != LIB3MF_OK) { if(hResult != LIB3MF_OK) {
@ -534,7 +581,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
return -1; return -1;
} }
} }
else { else
{
Transform = transform_nmr_internal::initMatrix(); 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 // Release Object Resource ID
NMR::lib3mf_release(pObjectResource); NMR::lib3mf_release(pObjectResource);
// Release Build Item // Release Build Item
@ -553,11 +602,13 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
// Move to next Item // Move to next Item
hResult = NMR::lib3mf_builditemiterator_movenext(pBuildItemIterator, &pbHasNext); 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; std::cerr << "could not get next build item: " << std::hex << hResult << std::endl;
return -1; return -1;
} }
} }
// Release Build Item Iterator // Release Build Item Iterator
NMR::lib3mf_release(pBuildItemIterator); NMR::lib3mf_release(pBuildItemIterator);
return all_points.size(); return all_points.size();
@ -593,30 +644,28 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
template<typename PointRanges, typename PolygonRanges, typename ColorRanges> template<typename PointRanges, typename PolygonRanges, typename ColorRanges>
int read_triangle_soups_from_3mf(const std::string& file_name, PointRanges& all_points, int read_triangle_soups_from_3mf(const std::string& file_name, PointRanges& all_points,
PolygonRanges& all_polygons, ColorRanges& all_colors, PolygonRanges& all_polygons, ColorRanges& all_colors,
std::vector<std::string>& names std::vector<std::string>& names)
)
{ {
typedef typename PointRanges::value_type PointRange; typedef typename PointRanges::value_type PointRange;
typedef typename PolygonRanges::value_type PolygonRange; typedef typename PolygonRanges::value_type PolygonRange;
typedef typename ColorRanges::value_type ColorRange; typedef typename ColorRanges::value_type ColorRange;
return read_from_3mf<PointRanges,PolygonRanges,ColorRanges, return read_from_3mf<PointRanges,PolygonRanges,ColorRanges,
PointRange, PolygonRange, ColorRange> PointRange, PolygonRange, ColorRange>
(file_name, all_points, all_polygons, (file_name, all_points, all_polygons, all_colors, names,
all_colors, names, extract_soups<PointRange, PolygonRange, ColorRange>); extract_soups<PointRange, PolygonRange, ColorRange>);
} }
template<typename PointRanges, typename ColorRanges> template<typename PointRanges, typename ColorRanges>
int read_polylines_from_3mf(const std::string& file_name, int read_polylines_from_3mf(const std::string& file_name,
PointRanges& all_points, PointRanges& all_points,
ColorRanges& all_colors, ColorRanges& all_colors,
std::vector<std::string>& names std::vector<std::string>& names)
)
{ {
typedef typename PointRanges::value_type PointRange; typedef typename PointRanges::value_type PointRange;
typedef std::vector<std::size_t> Polygon; typedef std::vector<std::size_t> Polygon;
typedef std::vector<Polygon> PolygonRange; typedef std::vector<Polygon> PolygonRange;
typedef std::vector<CGAL::Color> ColorRange; typedef std::vector<CGAL::Color> ColorRange;
std::vector<PolygonRange> all_polygons; std::vector<PolygonRange> all_polygons;
return read_from_3mf<PointRanges,std::vector<PolygonRange>, return read_from_3mf<PointRanges,std::vector<PolygonRange>,
std::vector<ColorRange>, PointRange, PolygonRange, ColorRange> std::vector<ColorRange>, PointRange, PolygonRange, ColorRange>
@ -624,25 +673,24 @@ int read_polylines_from_3mf(const std::string& file_name,
extract_polylines<PointRange, PolygonRange, ColorRange>); extract_polylines<PointRange, PolygonRange, ColorRange>);
} }
template<typename PointRanges, typename ColorRanges> template<typename PointRanges, typename ColorRanges>
int read_point_clouds_from_3mf(const std::string& file_name, int read_point_clouds_from_3mf(const std::string& file_name,
PointRanges& all_points, PointRanges& all_points,
ColorRanges& all_colors, ColorRanges& all_colors,
std::vector<std::string>& names std::vector<std::string>& names)
)
{ {
typedef typename PointRanges::value_type PointRange; typedef typename PointRanges::value_type PointRange;
typedef std::vector<std::size_t> Polygon; typedef std::vector<std::size_t> Polygon;
typedef std::vector<Polygon> PolygonRange; typedef std::vector<Polygon> PolygonRange;
typedef std::vector<CGAL::Color> ColorRange; typedef std::vector<CGAL::Color> ColorRange;
std::vector<PolygonRange> all_polygons; std::vector<PolygonRange> all_polygons;
return read_from_3mf<PointRanges,std::vector<PolygonRange>, return read_from_3mf<PointRanges,std::vector<PolygonRange>,
std::vector<ColorRange>, PointRange, PolygonRange, ColorRange> std::vector<ColorRange>, PointRange, PolygonRange, ColorRange>
(file_name, all_points, all_polygons, all_colors, names, (file_name, all_points, all_polygons, all_colors, names,
extract_point_clouds<PointRange, PolygonRange, ColorRange>); extract_point_clouds<PointRange, PolygonRange, ColorRange>);
} }
}//end CGAL
} // namespace CGAL
#endif // CGAL_IO_READ_3MF_H #endif // CGAL_IO_READ_3MF_H

View File

@ -11,16 +11,19 @@
#ifndef CGAL_IO_WRITE_3MF_H #ifndef CGAL_IO_WRITE_3MF_H
#define CGAL_IO_WRITE_3MF_H #define CGAL_IO_WRITE_3MF_H
#include <iostream>
#include <vector>
#include <string>
#include <CGAL/boost/graph/iterator.h>
#include <CGAL/IO/Color.h> #include <CGAL/IO/Color.h>
#include <Model/COM/NMR_DLLInterfaces.h> #include <Model/COM/NMR_DLLInterfaces.h>
#include <iostream>
#include <vector>
#include <string>
namespace CGAL { namespace CGAL {
namespace tmf_internal { namespace tmf_internal {
// Utility functions to create vertices and triangles // Utility functions to create vertices and triangles
NMR::MODELMESHVERTEX fnCreateVertex(float x, float y, float z) 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; result.m_fPosition[2] = z;
return result; return result;
} }
NMR::MODELMESHTRIANGLE fnCreateTriangle(int v0, int v1, int v2) NMR::MODELMESHTRIANGLE fnCreateTriangle(int v0, int v1, int v2)
{ {
NMR::MODELMESHTRIANGLE result; NMR::MODELMESHTRIANGLE result;
@ -38,6 +42,7 @@ NMR::MODELMESHTRIANGLE fnCreateTriangle(int v0, int v1, int v2)
result.m_nIndices[2] = v2; result.m_nIndices[2] = v2;
return result; return result;
} }
NMR::MODELMESHCOLOR_SRGB fnCreateColor(unsigned char red, unsigned char green, NMR::MODELMESHCOLOR_SRGB fnCreateColor(unsigned char red, unsigned char green,
unsigned char blue, unsigned char alpha=255) 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_Blue = blue;
result.m_Alpha = alpha; result.m_Alpha = alpha;
return result; return result;
} }
} //end internal
} // namespace tmf_internal
bool add_build_item(NMR::PLib3MFModel * pModel, bool add_build_item(NMR::PLib3MFModel * pModel,
NMR::PLib3MFModelMeshObject* pMeshObject) NMR::PLib3MFModelMeshObject* pMeshObject)
@ -58,19 +62,21 @@ bool add_build_item(NMR::PLib3MFModel * pModel,
HRESULT hResult; HRESULT hResult;
DWORD nErrorMessage; DWORD nErrorMessage;
LPCSTR pszErrorMessage; LPCSTR pszErrorMessage;
// Add Build Item for Mesh // Add Build Item for Mesh
NMR::PLib3MFModelBuildItem * pBuildItem; NMR::PLib3MFModelBuildItem * pBuildItem;
hResult = NMR::lib3mf_model_addbuilditem(pModel, pMeshObject, NULL, &pBuildItem); hResult = NMR::lib3mf_model_addbuilditem(pModel, pMeshObject, NULL, &pBuildItem);
if (hResult != LIB3MF_OK) {
std::cerr << "could not create build item: " if(hResult != LIB3MF_OK)
<< std::hex << hResult << std::endl; {
std::cerr << "could not create build item: " << std::hex << hResult << std::endl;
NMR::lib3mf_getlasterror(pModel, &nErrorMessage, &pszErrorMessage); NMR::lib3mf_getlasterror(pModel, &nErrorMessage, &pszErrorMessage);
std::cerr << "error #" << std::hex << nErrorMessage std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
<< ": " << pszErrorMessage << std::endl;
NMR::lib3mf_release(pMeshObject); NMR::lib3mf_release(pMeshObject);
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
return false; return false;
} }
// Release BuildItem and Mesh // Release BuildItem and Mesh
NMR::lib3mf_release(pMeshObject); NMR::lib3mf_release(pMeshObject);
NMR::lib3mf_release(pBuildItem); NMR::lib3mf_release(pBuildItem);
@ -83,26 +89,27 @@ bool export_model_to_file(const std::string& file_name,
HRESULT hResult; HRESULT hResult;
DWORD nErrorMessage; DWORD nErrorMessage;
LPCSTR pszErrorMessage; LPCSTR pszErrorMessage;
// Output mesh as 3MF // Output mesh as 3MF
// Create Model Writer for 3MF // Create Model Writer for 3MF
NMR::PLib3MFModelWriter * p3MFWriter; NMR::PLib3MFModelWriter * p3MFWriter;
hResult = NMR::lib3mf_model_querywriter(pModel, "3mf", &p3MFWriter); hResult = NMR::lib3mf_model_querywriter(pModel, "3mf", &p3MFWriter);
if (hResult != LIB3MF_OK) {
std::cerr << "could not create model reader: " if(hResult != LIB3MF_OK)
<< std::hex << hResult << std::endl; {
std::cerr << "could not create model reader: " << std::hex << hResult << std::endl;
NMR::lib3mf_getlasterror(pModel, &nErrorMessage, &pszErrorMessage); NMR::lib3mf_getlasterror(pModel, &nErrorMessage, &pszErrorMessage);
std::cerr << "error #" << std::hex << nErrorMessage std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
<< ": " << pszErrorMessage << std::endl;
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
return false; return false;
} }
// Export Model into File // Export Model into File
hResult = NMR::lib3mf_writer_writetofileutf8(p3MFWriter, file_name.c_str()); 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; std::cerr << "could not write file: " << std::hex << hResult << std::endl;
NMR::lib3mf_getlasterror(p3MFWriter, &nErrorMessage, &pszErrorMessage); NMR::lib3mf_getlasterror(p3MFWriter, &nErrorMessage, &pszErrorMessage);
std::cerr << "error #" << std::hex << nErrorMessage << ": " std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
<< pszErrorMessage << std::endl;
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
NMR::lib3mf_release(p3MFWriter); NMR::lib3mf_release(p3MFWriter);
return false; return false;
@ -119,42 +126,39 @@ bool write_mesh_to_model( const PointRange& points,
const ColorRange& colors, const ColorRange& colors,
const std::string& name, const std::string& name,
NMR::PLib3MFModelMeshObject** pMeshObject, NMR::PLib3MFModelMeshObject** pMeshObject,
NMR::PLib3MFModel * pModel NMR::PLib3MFModel * pModel)
)
{ {
DWORD nErrorMessage; DWORD nErrorMessage;
LPCSTR pszErrorMessage; LPCSTR pszErrorMessage;
HRESULT hResult; HRESULT hResult;
// Create mesh structure // Create mesh structure
std::vector<NMR::MODELMESHVERTEX> pVertices; std::vector<NMR::MODELMESHVERTEX> pVertices;
std::vector<NMR::MODELMESHTRIANGLE> pTriangles; std::vector<NMR::MODELMESHTRIANGLE> pTriangles;
// Create Mesh Object // Create Mesh Object
hResult = NMR::lib3mf_model_addmeshobject(pModel, pMeshObject); hResult = NMR::lib3mf_model_addmeshobject(pModel, pMeshObject);
if (hResult != LIB3MF_OK) { if(hResult != LIB3MF_OK)
std::cerr << "could not add mesh object: " << std::hex {
<< hResult << std::endl; std::cerr << "could not add mesh object: " << std::hex << hResult << std::endl;
NMR::lib3mf_getlasterror(pModel, &nErrorMessage, &pszErrorMessage); NMR::lib3mf_getlasterror(pModel, &nErrorMessage, &pszErrorMessage);
std::cerr << "error #" << std::hex << nErrorMessage << ": " std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
<< pszErrorMessage << std::endl;
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
return false; return false;
} }
for( auto point : points)
{
pVertices.push_back(tmf_internal::fnCreateVertex(point.x(), point.y(), point.z()));
}
for( auto triangle : polygons) for(const auto& point : points)
{ pVertices.push_back(tmf_internal::fnCreateVertex(point.x(), point.y(), point.z()));
for(const auto& triangle : polygons)
pTriangles.push_back(tmf_internal::fnCreateTriangle(triangle[0], triangle[1], triangle[2])); pTriangles.push_back(tmf_internal::fnCreateTriangle(triangle[0], triangle[1], triangle[2]));
}
hResult = NMR::lib3mf_meshobject_setgeometry(*pMeshObject, pVertices.data(), hResult = NMR::lib3mf_meshobject_setgeometry(*pMeshObject, pVertices.data(),
pVertices.size(), pTriangles.data(), pVertices.size(), pTriangles.data(),
pTriangles.size()); pTriangles.size());
if (hResult != LIB3MF_OK) { if(hResult != LIB3MF_OK)
std::cerr << "could not set mesh geometry: " {
<< std::hex << hResult << std::endl; std::cerr << "could not set mesh geometry: " << std::hex << hResult << std::endl;
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
std::cerr << "error #" << std::hex << nErrorMessage std::cerr << "error #" << std::hex << nErrorMessage
<< ": " << pszErrorMessage << std::endl; << ": " << pszErrorMessage << std::endl;
@ -162,10 +166,12 @@ bool write_mesh_to_model( const PointRange& points,
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
return false; return false;
} }
// Create color entries // Create color entries
NMR::PLib3MFPropertyHandler * pPropertyHandler; NMR::PLib3MFPropertyHandler * pPropertyHandler;
hResult = NMR::lib3mf_meshobject_createpropertyhandler(*pMeshObject, &pPropertyHandler); hResult = NMR::lib3mf_meshobject_createpropertyhandler(*pMeshObject, &pPropertyHandler);
if (hResult != LIB3MF_OK) { if(hResult != LIB3MF_OK)
{
std::cerr << "could not create property handler: " << std::hex << hResult << std::endl; std::cerr << "could not create property handler: " << std::hex << hResult << std::endl;
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
@ -188,7 +194,8 @@ bool write_mesh_to_model( const PointRange& points,
// make sure to define a default property // make sure to define a default property
NMR::PLib3MFDefaultPropertyHandler * pDefaultPropertyHandler; NMR::PLib3MFDefaultPropertyHandler * pDefaultPropertyHandler;
hResult = NMR::lib3mf_object_createdefaultpropertyhandler(*pMeshObject, &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; std::cerr<< "could not create default property handler: " << std::hex << hResult << std::endl;
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
std::cerr<< "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; 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); NMR::lib3mf_release(pModel);
return false; return false;
} }
NMR::MODELMESHCOLOR_SRGB default_color = tmf_internal::fnCreateColor(0,0,0,0); NMR::MODELMESHCOLOR_SRGB default_color = tmf_internal::fnCreateColor(0,0,0,0);
NMR::lib3mf_defaultpropertyhandler_setcolor(pDefaultPropertyHandler, NMR::lib3mf_defaultpropertyhandler_setcolor(pDefaultPropertyHandler, &default_color);
&default_color);
// release default property handler // release default property handler
NMR::lib3mf_release(pDefaultPropertyHandler); NMR::lib3mf_release(pDefaultPropertyHandler);
// Set name // Set name
hResult = NMR::lib3mf_object_setnameutf8(*pMeshObject, name.c_str()); 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; std::cerr << "could not set object name: " << std::hex << hResult << std::endl;
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
@ -224,41 +232,41 @@ bool write_points(const PointRange& points,
const Color& color, const Color& color,
const std::string& name, const std::string& name,
NMR::PLib3MFModelMeshObject** pMeshObject, NMR::PLib3MFModelMeshObject** pMeshObject,
NMR::PLib3MFModel * pModel NMR::PLib3MFModel * pModel)
)
{ {
DWORD nErrorMessage; DWORD nErrorMessage;
LPCSTR pszErrorMessage; LPCSTR pszErrorMessage;
HRESULT hResult; HRESULT hResult;
// Create mesh structure // Create mesh structure
std::vector<NMR::MODELMESHVERTEX> pVertices; std::vector<NMR::MODELMESHVERTEX> pVertices;
// Create Mesh Object // Create Mesh Object
hResult = NMR::lib3mf_model_addmeshobject(pModel, pMeshObject); hResult = NMR::lib3mf_model_addmeshobject(pModel, pMeshObject);
if (hResult != LIB3MF_OK) { if(hResult != LIB3MF_OK)
std::cerr << "could not add mesh object: " << std::hex {
<< hResult << std::endl; std::cerr << "could not add mesh object: " << std::hex << hResult << std::endl;
NMR::lib3mf_getlasterror(pModel, &nErrorMessage, &pszErrorMessage); NMR::lib3mf_getlasterror(pModel, &nErrorMessage, &pszErrorMessage);
std::cerr << "error #" << std::hex << nErrorMessage << ": " std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
<< pszErrorMessage << std::endl;
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
return false; return false;
} }
//add 3 demmy vertices to be sure to have a valid triangle and accept point sets with less than 3 vertices. //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) for(int i = 0; i< 3; ++i)
pVertices.push_back(tmf_internal::fnCreateVertex(0,0,0)); 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())); 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. 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(), hResult = NMR::lib3mf_meshobject_setgeometry(*pMeshObject, pVertices.data(),
pVertices.size(), &dummy_triangle, 1); pVertices.size(), &dummy_triangle, 1);
if (hResult != LIB3MF_OK) { if(hResult != LIB3MF_OK)
std::cerr << "could not set mesh geometry: " {
<< std::hex << hResult << std::endl; std::cerr << "could not set mesh geometry: " << std::hex << hResult << std::endl;
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
std::cerr << "error #" << std::hex << nErrorMessage std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
<< ": " << pszErrorMessage << std::endl;
NMR::lib3mf_release(*pMeshObject); NMR::lib3mf_release(*pMeshObject);
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
return false; return false;
@ -267,7 +275,8 @@ bool write_points(const PointRange& points,
// Create color entries // Create color entries
NMR::PLib3MFPropertyHandler * pPropertyHandler; NMR::PLib3MFPropertyHandler * pPropertyHandler;
hResult = NMR::lib3mf_meshobject_createpropertyhandler(*pMeshObject, &pPropertyHandler); hResult = NMR::lib3mf_meshobject_createpropertyhandler(*pMeshObject, &pPropertyHandler);
if (hResult != LIB3MF_OK) { if(hResult != LIB3MF_OK)
{
std::cerr << "could not create property handler: " << std::hex << hResult << std::endl; std::cerr << "could not create property handler: " << std::hex << hResult << std::endl;
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
@ -287,7 +296,8 @@ bool write_points(const PointRange& points,
// make sure to define a default property // make sure to define a default property
NMR::PLib3MFDefaultPropertyHandler * pDefaultPropertyHandler; NMR::PLib3MFDefaultPropertyHandler * pDefaultPropertyHandler;
hResult = NMR::lib3mf_object_createdefaultpropertyhandler(*pMeshObject, &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; std::cerr<< "could not create default property handler: " << std::hex << hResult << std::endl;
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
std::cerr<< "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; std::cerr<< "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
@ -295,6 +305,7 @@ bool write_points(const PointRange& points,
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
return false; return false;
} }
NMR::MODELMESHCOLOR_SRGB default_color = tmf_internal::fnCreateColor(0,0,0,0); NMR::MODELMESHCOLOR_SRGB default_color = tmf_internal::fnCreateColor(0,0,0,0);
NMR::lib3mf_defaultpropertyhandler_setcolor(pDefaultPropertyHandler, NMR::lib3mf_defaultpropertyhandler_setcolor(pDefaultPropertyHandler,
&default_color); &default_color);
@ -304,7 +315,8 @@ bool write_points(const PointRange& points,
// Set name // Set name
hResult = NMR::lib3mf_object_setnameutf8(*pMeshObject, name.c_str()); 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; std::cerr << "could not set object name: " << std::hex << hResult << std::endl;
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage); NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl; std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
@ -312,6 +324,7 @@ bool write_points(const PointRange& points,
NMR::lib3mf_release(pModel); NMR::lib3mf_release(pModel);
return false; return false;
} }
return add_build_item(pModel, *pMeshObject); return add_build_item(pModel, *pMeshObject);
} }
@ -320,8 +333,7 @@ bool write_point_cloud_to_model(const PointRange& points,
const Color& color, const Color& color,
const std::string& name, const std::string& name,
NMR::PLib3MFModelMeshObject** pMeshObject, NMR::PLib3MFModelMeshObject** pMeshObject,
NMR::PLib3MFModel * pModel NMR::PLib3MFModel * pModel)
)
{ {
std::string pc_name = name; std::string pc_name = name;
pc_name.append("_cgal_pc"); pc_name.append("_cgal_pc");
@ -333,8 +345,7 @@ bool write_polyline_to_model(const PointRange& points,
const Color& color, const Color& color,
const std::string& name, const std::string& name,
NMR::PLib3MFModelMeshObject** pMeshObject, NMR::PLib3MFModelMeshObject** pMeshObject,
NMR::PLib3MFModel * pModel NMR::PLib3MFModel * pModel)
)
{ {
std::string pc_name = name; std::string pc_name = name;
pc_name.append("_cgal_pl"); pc_name.append("_cgal_pl");
@ -366,29 +377,32 @@ bool write_triangle_soups_to_3mf(const std::string& file_name,
const PolygonRanges& all_polygons, const PolygonRanges& all_polygons,
const std::vector<std::string>& names) const std::vector<std::string>& names)
{ {
HRESULT hResult;
// Create Model Instance // Create Model Instance
NMR::PLib3MFModel * pModel; NMR::PLib3MFModel * pModel;
hResult = NMR::lib3mf_createmodel(&pModel); HRESULT hResult = NMR::lib3mf_createmodel(&pModel);
if (hResult != LIB3MF_OK) { if(hResult != LIB3MF_OK)
{
std::cerr << "could not create model: " << std::hex << hResult << std::endl; std::cerr << "could not create model: " << std::hex << hResult << std::endl;
return false; 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; NMR::PLib3MFModelMeshObject* pMeshObject;
std::string name; std::string name;
if(names.size() > id if(names.size() > id && ! names[id].empty())
&& ! names[id].empty())
{ {
name=names[id]; name=names[id];
} }
else else
{
name = std::string(""); name = std::string("");
}
std::vector<CGAL::Color> colors(all_polygons[id].size()); std::vector<CGAL::Color> 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); return export_model_to_file(file_name, pModel);
} }
@ -416,42 +430,49 @@ bool write_triangle_meshes_to_3mf(const std::string& file_name,
typedef typename boost::property_map<Mesh, boost::vertex_point_t>::type VPMap; typedef typename boost::property_map<Mesh, boost::vertex_point_t>::type VPMap;
typedef typename boost::property_traits<VPMap>::value_type Point_3; typedef typename boost::property_traits<VPMap>::value_type Point_3;
typedef boost::graph_traits<Mesh>::vertex_descriptor vertex_descriptor;
typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor;
typedef std::vector<std::size_t> Polygon; typedef std::vector<std::size_t> Polygon;
typedef std::vector<Polygon> PolygonRange; typedef std::vector<Polygon> PolygonRange;
typedef std::vector<Point_3> PointRange; typedef std::vector<Point_3> PointRange;
std::vector<PointRange> all_points; std::vector<PointRange> all_points;
std::vector<PolygonRange> all_polygons; std::vector<PolygonRange> all_polygons;
for(const auto& tm : tms)
for(auto tm : tms)
{ {
PointRange points; PointRange points;
points.reserve(num_vertices(tm));
PolygonRange triangles; PolygonRange triangles;
triangles.reserve(num_faces(tm));
VPMap vpm = get(boost::vertex_point, tm); VPMap vpm = get(boost::vertex_point, tm);
std::unordered_map<typename boost::graph_traits<Mesh>::vertex_descriptor, std::unordered_map<typename boost::graph_traits<Mesh>::vertex_descriptor, std::size_t> vertex_id_map;
std::size_t> vertex_id_map;
std::size_t i = 0; std::size_t i = 0;
for(auto v : vertices(tm)) for(vertex_descriptor v : vertices(tm))
{ {
points.push_back(get(vpm, v)); points.push_back(get(vpm, v));
vertex_id_map[v] = i++; vertex_id_map[v] = i++;
} }
all_points.push_back(points); all_points.push_back(points);
for(auto f : faces(tm)) for(face_descriptor f : faces(tm))
{ {
Polygon triangle; 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]); triangle.push_back(vertex_id_map[vert]);
}
triangles.push_back(triangle); triangles.push_back(triangle);
} }
all_polygons.push_back(triangles); all_polygons.push_back(triangles);
} }
return write_triangle_soups_to_3mf(file_name, all_points, all_polygons, names); return write_triangle_soups_to_3mf(file_name, all_points, all_polygons, names);
} }
}//end CGAL
} // namespace CGAL
#endif // CGAL_IO_WRITE_3MF_H #endif // CGAL_IO_WRITE_3MF_H

View File

@ -15,30 +15,48 @@
// Author(s) : Lutz Kettner <kettner@mpi-sb.mpg.de> // Author(s) : Lutz Kettner <kettner@mpi-sb.mpg.de>
#ifndef CGAL_IO_OBJ_FILE_WRITER_WAVEFRONT_H #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 <CGAL/IO/binary_file_io.h> #include <CGAL/IO/binary_file_io.h>
#include <iostream> #include <iostream>
#include <cstddef> #include <cstddef>
namespace CGAL { namespace CGAL {
class CGAL_EXPORT File_writer_wavefront { class File_writer_wavefront
{
std::ostream* m_out; std::ostream* m_out;
std::size_t m_facets; std::size_t m_facets;
public: public:
std::ostream& out() const { return *m_out; } std::ostream& out() const { return *m_out; }
void write_header(std::ostream& out, void write_header(std::ostream& out,
std::size_t vertices, std::size_t vertices,
std::size_t halfedges, std::size_t halfedges,
std::size_t facets); std::size_t facets)
void write_footer() const { {
out() << "\n# End of Wavefront obj format #" << std::endl; 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) { void write_vertex(const double& x, const double& y, const double& z) {
out() << "v " << x << ' ' << y << ' ' << z << '\n'; out() << "v " << x << ' ' << y << ' ' << z << '\n';
} }
void write_facet_header() {
void write_facet_header()
{
out() << "\n# " << m_facets << " facets\n"; out() << "\n# " << m_facets << " facets\n";
out() << "# ------------------------------------------\n\n"; out() << "# ------------------------------------------\n\n";
} }
@ -49,9 +67,4 @@ public:
} // namespace CGAL } // namespace CGAL
#ifdef CGAL_HEADER_ONLY #endif // CGAL_IO_OBJ_FILE_WRITER_WAVEFRONT_H
#include <CGAL/IO/OBJ/File_writer_wavefront_impl.h>
#endif // CGAL_HEADER_ONLY
#endif // CGAL_IO_OBJ_FILE_WRITER_WAVEFRONT_H //
// EOF //

View File

@ -16,31 +16,34 @@
#include <vector> #include <vector>
#include <limits> #include <limits>
namespace CGAL { namespace CGAL {
// Points_3 a RandomAccessContainer of Point_3, // Points_3 a RandomAccessContainer of Point_3,
// Faces a RandomAccessContainer of RandomAccessContainer of std::size_t // Faces a RandomAccessContainer of RandomAccessContainer of std::size_t
template <class Points_3, class Faces> template <class Points_3, class Faces>
bool bool read_OBJ(std::istream& input,
read_OBJ( std::istream& input,
Points_3 &points, Points_3 &points,
Faces &faces) Faces &faces)
{ {
typedef typename Points_3::value_type Point_3; typedef typename Points_3::value_type Point_3;
int mini(1), int mini(1),
maxi(-INT_MAX); maxi(-INT_MAX);
Point_3 p; Point_3 p;
std::string line; 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)); std::istringstream iss(line.substr(1));
iss >> p; iss >> p;
if(!iss) if(!iss)
return false; return false;
points.push_back(p); points.push_back(p);
} }
else if(line[0] == 'f') { else if(line[0] == 'f')
{
std::istringstream iss(line.substr(1)); std::istringstream iss(line.substr(1));
int i; int i;
faces.push_back(std::vector<std::size_t>()); faces.push_back(std::vector<std::size_t>());
@ -52,13 +55,15 @@ read_OBJ( std::istream& input,
if(i<mini) if(i<mini)
mini=i; mini=i;
} }
else { else
{
faces.back().push_back(i-1); faces.back().push_back(i-1);
if(i-1 > maxi) if(i-1 > maxi)
maxi = i-1; maxi = i-1;
} }
iss.ignore(256, ' '); iss.ignore(256, ' ');
} }
if(!iss.good() && !iss.eof()) if(!iss.good() && !iss.eof())
return false; return false;
} }
@ -68,10 +73,13 @@ read_OBJ( std::istream& input,
continue; continue;
} }
} }
if(maxi > points.size() || mini < -static_cast<int>(points.size())){
if(maxi > points.size() || mini < -static_cast<int>(points.size()))
{
std::cerr<<"a face index is invalid "<<std::endl; std::cerr<<"a face index is invalid "<<std::endl;
return false; return false;
} }
return true; return true;
} }

View File

@ -24,8 +24,7 @@
namespace CGAL { namespace CGAL {
template <class Point_3, class Polygon_3> template <class Point_3, class Polygon_3>
bool bool read_OFF(std::istream& in,
read_OFF( std::istream& in,
std::vector< Point_3 >& points, std::vector< Point_3 >& points,
std::vector< Polygon_3 >& polygons, std::vector< Polygon_3 >& polygons,
bool /* verbose */ = false) bool /* verbose */ = false)
@ -34,7 +33,8 @@ read_OFF( std::istream& in,
points.resize(scanner.size_of_vertices()); points.resize(scanner.size_of_vertices());
polygons.resize(scanner.size_of_facets()); 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; double x, y, z, w;
scanner.scan_vertex( x, y, z, w); scanner.scan_vertex( x, y, z, w);
CGAL_assertion(w!=0); CGAL_assertion(w!=0);
@ -45,28 +45,28 @@ read_OFF( std::istream& in,
if(!in) if(!in)
return false; 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; std::size_t no;
scanner.scan_facet( no, i); scanner.scan_facet( no, i);
IO::internal::resize(polygons[i], no); 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; std::size_t id;
scanner.scan_facet_vertex_index(id, i); scanner.scan_facet_vertex_index(id, i);
if(id < scanner.size_of_vertices()) { if(id < scanner.size_of_vertices())
polygons[i][j] = id; polygons[i][j] = id;
} else { else
return false; return false;
} }
} }
}
return in.good(); return in.good();
} }
template <class Point_3, class Polygon_3, class Color_rgb > template <class Point_3, class Polygon_3, class Color_rgb >
bool bool read_OFF(std::istream& in,
read_OFF( std::istream& in,
std::vector< Point_3 >& points, std::vector< Point_3 >& points,
std::vector< Polygon_3 >& polygons, std::vector< Polygon_3 >& polygons,
std::vector<Color_rgb>& fcolors, std::vector<Color_rgb>& fcolors,
@ -81,16 +81,20 @@ read_OFF( std::istream& in,
if(scanner.has_colors()) if(scanner.has_colors())
vcolors.resize(scanner.size_of_vertices()); 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; double x, y, z, w;
scanner.scan_vertex( x, y, z, w); scanner.scan_vertex( x, y, z, w);
CGAL_assertion(w!=0); CGAL_assertion(w!=0);
IO::internal::fill_point( x/w, y/w, z/w, points[i] ); 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; unsigned char r=0, g=0, b=0;
scanner.scan_color( r, g, b); scanner.scan_color( r, g, b);
vcolors[i] = Color_rgb(r,g,b); vcolors[i] = Color_rgb(r,g,b);
} else { }
else
{
scanner.skip_to_next_vertex(i); scanner.skip_to_next_vertex(i);
} }
@ -108,15 +112,15 @@ read_OFF( std::istream& in,
return false; return false;
IO::internal::resize(polygons[i], no); 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; std::size_t id;
scanner.scan_facet_vertex_index(id, i); scanner.scan_facet_vertex_index(id, i);
if(id < scanner.size_of_vertices()) { if(id < scanner.size_of_vertices())
polygons[i][j] = id; polygons[i][j] = id;
} else { else
return false; return false;
} }
}
if(i == 0) if(i == 0)
{ {
@ -125,13 +129,16 @@ read_OFF( std::istream& in,
std::istringstream iss(col); std::istringstream iss(col);
char ci =' '; char ci =' ';
if(iss >> ci) { if(iss >> ci)
{
has_fcolors = true; has_fcolors = true;
fcolors.resize(scanner.size_of_facets()); fcolors.resize(scanner.size_of_facets());
std::istringstream iss2(col); std::istringstream iss2(col);
fcolors[i] = scanner.get_color_from_line(iss2); fcolors[i] = scanner.get_color_from_line(iss2);
} }
} else if(has_fcolors) { }
else if(has_fcolors)
{
unsigned char r=0, g=0, b=0; unsigned char r=0, g=0, b=0;
scanner.scan_color(r,g,b); scanner.scan_color(r,g,b);
fcolors[i] = Color_rgb(r,g,b); fcolors[i] = Color_rgb(r,g,b);
@ -142,37 +149,33 @@ read_OFF( std::istream& in,
} }
template <class Point_3, class Polygon_3> template <class Point_3, class Polygon_3>
bool bool write_OFF(std::ostream& out,
write_OFF(std::ostream& out,
std::vector< Point_3 >& points, std::vector< Point_3 >& points,
std::vector< Polygon_3 >& polygons) std::vector< Polygon_3 >& polygons)
{ {
CGAL::File_writer_OFF writer; CGAL::File_writer_OFF writer;
writer.write_header(out, writer.write_header(out, points.size(), 0, polygons.size());
points.size(),
0, for(std::size_t i = 0, end = points.size(); i < end; ++i)
polygons.size());
for(std::size_t i = 0, end = points.size();
i < end; ++i)
{ {
const Point_3& p = points[i]; const Point_3& p = points[i];
writer.write_vertex( p.x(), p.y(), p.z() ); writer.write_vertex( p.x(), p.y(), p.z() );
} }
writer.write_facet_header(); writer.write_facet_header();
for(std::size_t i = 0, end = polygons.size(); for(std::size_t i=0, end=polygons.size(); i<end; ++i)
i < end; ++i)
{ {
Polygon_3& polygon = polygons[i]; Polygon_3& polygon = polygons[i];
const std::size_t size = polygon.size(); const std::size_t size = polygon.size();
writer.write_facet_begin(size); writer.write_facet_begin(size);
for(std::size_t j = 0; j < size; ++j) { for(std::size_t j=0; j<size; ++j)
writer.write_facet_vertex_index(polygon[j]); writer.write_facet_vertex_index(polygon[j]);
}
writer.write_facet_end(); writer.write_facet_end();
} }
writer.write_footer(); writer.write_footer();
return (bool) out; return out.good();
} }
} // namespace CGAL } // namespace CGAL

View File

@ -18,26 +18,57 @@
#define CGAL_IO_FILE_WRITER_INVENTOR_H 1 #define CGAL_IO_FILE_WRITER_INVENTOR_H 1
#include <CGAL/basic.h> #include <CGAL/basic.h>
#include <iostream> #include <iostream>
#include <cstddef> #include <cstddef>
namespace CGAL { namespace CGAL {
class CGAL_EXPORT File_writer_inventor { class CGAL_EXPORT File_writer_inventor
{
std::ostream* m_out; std::ostream* m_out;
std::size_t m_facets; std::size_t m_facets;
public: public:
File_writer_inventor() {} File_writer_inventor() {}
std::ostream& out() const { return *m_out; } std::ostream& out() const { return *m_out; }
void write_header(std::ostream& o, void write_header(std::ostream& o,
std::size_t vertices, std::size_t vertices,
std::size_t halfedges, std::size_t halfedges,
std::size_t facets); std::size_t facets)
void write_footer() const; {
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) { void write_vertex( const double& x, const double& y, const double& z) {
out() << " " << x << ' ' << y << ' ' << z << ',' <<'\n'; out() << " " << x << ' ' << y << ' ' << z << ',' <<'\n';
} }
void write_facet_header() const;
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_begin( std::size_t) { out() << " "; }
void write_facet_vertex_index( std::size_t idx) { out() << idx << ','; } void write_facet_vertex_index( std::size_t idx) { out() << idx << ','; }
void write_facet_end() { out() << "-1,\n"; } void write_facet_end() { out() << "-1,\n"; }
@ -45,9 +76,4 @@ public:
} //namespace CGAL } //namespace CGAL
#ifdef CGAL_HEADER_ONLY #endif // CGAL_IO_FILE_WRITER_INVENTOR_H
#include <CGAL/IO/File_writer_inventor_impl.h>
#endif // CGAL_HEADER_ONLY
#endif // CGAL_IO_FILE_WRITER_INVENTOR_H //
// EOF //

View File

@ -14,12 +14,10 @@
#include <CGAL/IO/PLY.h> #include <CGAL/IO/PLY.h>
namespace CGAL { namespace CGAL {
namespace internal {
namespace internal
{
template <typename Integer, class Polygon_3, class Color_rgb> template <typename Integer, class Polygon_3, class Color_rgb>
bool bool read_PLY_faces(std::istream& in,
read_PLY_faces (std::istream& in,
internal::PLY::PLY_element& element, internal::PLY::PLY_element& element,
std::vector< Polygon_3 >& polygons, std::vector< Polygon_3 >& polygons,
std::vector< Color_rgb >& fcolors, std::vector< Color_rgb >& fcolors,
@ -27,16 +25,15 @@ namespace CGAL{
{ {
bool has_colors = false; bool has_colors = false;
std::string rtag = "r", gtag = "g", btag = "b"; std::string rtag = "r", gtag = "g", btag = "b";
if((element.has_property<boost::uint8_t>("red") || element.has_property<boost::uint8_t>("r")) && if((element.has_property<boost::uint8_t>("red") || element.has_property<boost::uint8_t>("r")) &&
(element.has_property<boost::uint8_t>("green") || element.has_property<boost::uint8_t>("g")) && (element.has_property<boost::uint8_t>("green") || element.has_property<boost::uint8_t>("g")) &&
(element.has_property<boost::uint8_t>("blue") || element.has_property<boost::uint8_t>("b"))) (element.has_property<boost::uint8_t>("blue") || element.has_property<boost::uint8_t>("b")))
{ {
has_colors = true; has_colors = true;
if(element.has_property<boost::uint8_t>("red")) if(element.has_property<boost::uint8_t>("red"))
{
rtag = "red"; gtag = "green"; btag = "blue"; 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)
{ {
@ -66,9 +63,11 @@ namespace CGAL{
fcolors.push_back(Color_rgb(get<1>(new_face), get<2>(new_face), get<3>(new_face))); fcolors.push_back(Color_rgb(get<1>(new_face), get<2>(new_face), get<3>(new_face)));
} }
else else
{
PLY::process_properties(element, new_face, PLY::process_properties(element, new_face,
std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_face), std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_face),
PLY_property<std::vector<Integer> >(vertex_indices_tag))); PLY_property<std::vector<Integer> >(vertex_indices_tag)));
}
polygons.push_back(Polygon_3(get<0>(new_face).size())); polygons.push_back(Polygon_3(get<0>(new_face).size()));
for(std::size_t i = 0; i < get<0>(new_face).size(); ++ i) for(std::size_t i = 0; i < get<0>(new_face).size(); ++ i)
@ -78,8 +77,7 @@ namespace CGAL{
return true; return true;
} }
} } // namespace internal
template <class Point_3, class Polygon_3> template <class Point_3, class Polygon_3>
bool bool
@ -165,8 +163,7 @@ namespace CGAL{
} }
template <class Point_3, class Polygon_3, class Color_rgb> template <class Point_3, class Polygon_3, class Color_rgb>
bool bool read_PLY(std::istream& in,
read_PLY( std::istream& in,
std::vector< Point_3 >& points, std::vector< Point_3 >& points,
std::vector< Polygon_3 >& polygons, std::vector< Polygon_3 >& polygons,
std::vector<std::pair<unsigned int, unsigned int> >& hedges, std::vector<std::pair<unsigned int, unsigned int> >& hedges,
@ -293,6 +290,7 @@ namespace CGAL{
huvs.push_back(std::make_pair(get<2>(new_hedge), get<3>(new_hedge))); huvs.push_back(std::make_pair(get<2>(new_hedge), get<3>(new_hedge)));
} }
else else
{
internal::PLY::process_properties(element, new_hedge, internal::PLY::process_properties(element, new_hedge,
std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_hedge), std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_hedge),
PLY_property<unsigned int>(stag.c_str())), PLY_property<unsigned int>(stag.c_str())),
@ -301,6 +299,7 @@ namespace CGAL{
); );
} }
} }
}
else // Read other elements and ignore else // Read other elements and ignore
{ {
for(std::size_t j = 0; j < element.number_of_items(); ++ j) for(std::size_t j = 0; j < element.number_of_items(); ++ j)
@ -319,8 +318,7 @@ namespace CGAL{
} }
template <class Point_3, class Polygon_3, class Color_rgb> template <class Point_3, class Polygon_3, class Color_rgb>
bool bool read_PLY(std::istream& in,
read_PLY( std::istream& in,
std::vector< Point_3 >& points, std::vector< Point_3 >& points,
std::vector< Polygon_3 >& polygons, std::vector< Polygon_3 >& polygons,
std::vector<Color_rgb>& fcolors, std::vector<Color_rgb>& fcolors,
@ -329,11 +327,10 @@ namespace CGAL{
{ {
std::vector<std::pair<unsigned int, unsigned int> > dummy_pui; std::vector<std::pair<unsigned int, unsigned int> > dummy_pui;
std::vector<std::pair<float, float> > dummy_pf; std::vector<std::pair<float, float> > dummy_pf;
return read_PLY<Point_3, Polygon_3, Color_rgb>(in, points, polygons,
dummy_pui, return read_PLY<Point_3, Polygon_3, Color_rgb>(in, points, polygons, dummy_pui, fcolors, vcolors, dummy_pf);
fcolors, vcolors,
dummy_pf);
} }
} // namespace CGAL } // namespace CGAL
#endif // CGAL_IO_PLY_PLY_READER_H #endif // CGAL_IO_PLY_PLY_READER_H

View File

@ -16,13 +16,11 @@
namespace CGAL { namespace CGAL {
template <class Point_3, class Polygon_3> template <class Point_3, class Polygon_3>
bool bool write_PLY(std::ostream& out,
write_PLY(std::ostream& out,
const std::vector< Point_3 >& points, const std::vector< Point_3 >& points,
const std::vector< Polygon_3 >& polygons, const std::vector< Polygon_3 >& polygons,
bool /* verbose */ = false) bool /* verbose */ = false)
{ {
if(!out) if(!out)
{ {
std::cerr << "Error: cannot open file" << std::endl; std::cerr << "Error: cannot open file" << std::endl;
@ -35,13 +33,11 @@ namespace CGAL{
<< "comment Generated by the CGAL library" << std::endl << "comment Generated by the CGAL library" << std::endl
<< "element vertex " << points.size() << std::endl; << "element vertex " << points.size() << std::endl;
internal::PLY::output_property_header (out, internal::PLY::output_property_header(out, make_ply_point_writer (CGAL::Identity_property_map<Point_3>()));
make_ply_point_writer (CGAL::Identity_property_map<Point_3>()));
out << "element face " << polygons.size() << std::endl; out << "element face " << polygons.size() << std::endl;
internal::PLY::output_property_header (out, internal::PLY::output_property_header(out, std::make_pair(CGAL::Identity_property_map<Polygon_3>(),
std::make_pair (CGAL::Identity_property_map<Polygon_3>(),
PLY_property<std::vector<int> >("vertex_indices"))); PLY_property<std::vector<int> >("vertex_indices")));
out << "end_header" << std::endl; out << "end_header" << std::endl;
@ -59,8 +55,7 @@ namespace CGAL{
} }
template <class SurfaceMesh> template <class SurfaceMesh>
bool bool write_PLY(std::ostream& out,
write_PLY(std::ostream& out,
const SurfaceMesh& mesh, const SurfaceMesh& mesh,
bool /* verbose */ = false) bool /* verbose */ = false)
{ {
@ -69,9 +64,11 @@ namespace CGAL{
typedef typename boost::graph_traits<SurfaceMesh>::vertex_descriptor vertex_descriptor; typedef typename boost::graph_traits<SurfaceMesh>::vertex_descriptor vertex_descriptor;
typedef typename boost::property_map<SurfaceMesh, boost::vertex_point_t>::type::value_type Point_3; typedef typename boost::property_map<SurfaceMesh, boost::vertex_point_t>::type::value_type Point_3;
typedef typename SurfaceMesh::template Property_map<halfedge_descriptor,std::pair<float, float> > UV_map; typedef typename SurfaceMesh::template Property_map<halfedge_descriptor,std::pair<float, float> > UV_map;
UV_map h_uv; UV_map h_uv;
bool has_texture; bool has_texture;
boost::tie(h_uv, has_texture) = mesh.template property_map<halfedge_descriptor,std::pair<float, float> >("h:uv"); boost::tie(h_uv, has_texture) = mesh.template property_map<halfedge_descriptor,std::pair<float, float> >("h:uv");
if(!out) if(!out)
{ {
std::cerr << "Error: cannot open file" << std::endl; std::cerr << "Error: cannot open file" << std::endl;
@ -118,7 +115,6 @@ namespace CGAL{
make_ply_point_writer (CGAL::Identity_property_map<Point_3>())); make_ply_point_writer (CGAL::Identity_property_map<Point_3>()));
} }
std::vector<std::size_t> polygon; std::vector<std::size_t> polygon;
for(face_descriptor fd : faces(mesh)) for(face_descriptor fd : faces(mesh))
{ {
@ -136,8 +132,7 @@ namespace CGAL{
for(halfedge_descriptor hd : halfedges(mesh)) for(halfedge_descriptor hd : halfedges(mesh))
{ {
typedef std::tuple<unsigned int, unsigned int, float, float> Super_tuple; typedef std::tuple<unsigned int, unsigned int, float, float> Super_tuple;
Super_tuple t = Super_tuple t = std::make_tuple(source(hd, mesh),target(hd, mesh),
std::make_tuple(source(hd, mesh),target(hd, mesh),
h_uv[hd].first, h_uv[hd].first,
h_uv[hd].second); h_uv[hd].second);
@ -152,6 +147,7 @@ namespace CGAL{
PLY_property<float>("v"))); PLY_property<float>("v")));
} }
} }
return out.good(); return out.good();
} }

View File

@ -133,9 +133,8 @@ bool parse_ASCII_STL(std::istream& input,
if(s == solid) if(s == solid)
{ {
if(in_solid) if(in_solid)
{
break; break;
}
in_solid = true; in_solid = true;
} }
if(s == facet) if(s == facet)
@ -149,12 +148,14 @@ bool parse_ASCII_STL(std::istream& input,
} }
} }
if(in_solid){ if(in_solid)
{
if(verbose) if(verbose)
std::cerr << "Error while parsing ASCII file" << std::endl; std::cerr << "Error while parsing ASCII file" << std::endl;
return false; return false;
} }
return true; return true;
} }
@ -331,9 +332,7 @@ bool read_STL(std::istream& input,
return true; // empty file return true; // empty file
// If the first word is not 'solid', the file must be binary // If the first word is not 'solid', the file must be binary
if(s != "solid" if(s != "solid" || (word[5] !='\n' && word[5] != ' '))
|| (word[5] !='\n'
&& word[5] != ' '))
{ {
if(parse_binary_STL(input, points, facets, verbose)) if(parse_binary_STL(input, points, facets, verbose))
{ {

View File

@ -16,13 +16,10 @@
#include <boost/cstdint.hpp> #include <boost/cstdint.hpp>
namespace CGAL { namespace CGAL {
template <class PointRange, class TriangleRange> template <class PointRange, class TriangleRange>
std::ostream& std::ostream& write_STL(const PointRange& points,
write_STL(const PointRange& points,
const TriangleRange& facets, const TriangleRange& facets,
std::ostream& out) std::ostream& out)
{ {
@ -30,7 +27,6 @@ write_STL(const PointRange& points,
typedef typename CGAL::Kernel_traits<Point>::Kernel K; typedef typename CGAL::Kernel_traits<Point>::Kernel K;
typedef typename K::Vector_3 Vector_3; typedef typename K::Vector_3 Vector_3;
if (get_mode(out) == IO::BINARY) if (get_mode(out) == IO::BINARY)
{ {
out << "FileType: Binary "; out << "FileType: Binary ";
@ -43,11 +39,9 @@ write_STL(const PointRange& points,
const Point& q = points[face[1]]; const Point& q = points[face[1]];
const Point& r = points[face[2]]; const Point& r = points[face[2]];
Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0): Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0) : unit_normal(p,q,r);
unit_normal(p,q,r);
const float coords[12]={ const float coords[12] = { static_cast<float>(n.x()), static_cast<float>(n.y()), static_cast<float>(n.z()),
static_cast<float>(n.x()), static_cast<float>(n.y()), static_cast<float>(n.z()),
static_cast<float>(p.x()), static_cast<float>(p.y()), static_cast<float>(p.z()), static_cast<float>(p.x()), static_cast<float>(p.y()), static_cast<float>(p.z()),
static_cast<float>(q.x()), static_cast<float>(q.y()), static_cast<float>(q.z()), static_cast<float>(q.x()), static_cast<float>(q.y()), static_cast<float>(q.z()),
static_cast<float>(r.x()), static_cast<float>(r.y()), static_cast<float>(r.z()) }; static_cast<float>(r.x()), static_cast<float>(r.y()), static_cast<float>(r.z()) };
@ -66,8 +60,7 @@ write_STL(const PointRange& points,
const Point& q = points[face[1]]; const Point& q = points[face[1]];
const Point& r = points[face[2]]; const Point& r = points[face[2]];
Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0): Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0) : unit_normal(p,q,r);
unit_normal(p,q,r);
out << "facet normal " << n << "\nouter loop\n"; out << "facet normal " << n << "\nouter loop\n";
out << "vertex " << p << "\n"; out << "vertex " << p << "\n";
out << "vertex " << q << "\n"; out << "vertex " << q << "\n";
@ -76,9 +69,10 @@ write_STL(const PointRange& points,
} }
out << "endsolid\n"; out << "endsolid\n";
} }
return out; return out;
} }
} // end of namespace CGAL } // namespace CGAL
#endif // CGAL_IO_STL_STL_WRITER_H #endif // CGAL_IO_STL_STL_WRITER_H

View File

@ -18,12 +18,14 @@
#define CGAL_IO_FILE_WRITER_VRML_2_H 1 #define CGAL_IO_FILE_WRITER_VRML_2_H 1
#include <CGAL/basic.h> #include <CGAL/basic.h>
#include <iostream> #include <iostream>
#include <cstddef> #include <cstddef>
namespace CGAL { namespace CGAL {
class CGAL_EXPORT File_writer_VRML_2 { class File_writer_VRML_2
{
std::ostream* m_out; std::ostream* m_out;
std::size_t m_facets; std::size_t m_facets;
public: public:
@ -32,13 +34,47 @@ public:
void write_header( std::ostream& o, void write_header( std::ostream& o,
std::size_t vertices, std::size_t vertices,
std::size_t halfedges, std::size_t halfedges,
std::size_t facets); std::size_t facets)
void write_footer() const; {
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) { void write_vertex( const double& x, const double& y, const double& z) {
out() << " " out() << " "
<< x << ' ' << y << ' ' << z << ',' << '\n'; << x << ' ' << y << ' ' << z << ',' << '\n';
} }
void write_facet_header() const; void write_facet_header() const
{
out() << " ] #point\n"
" } #coord Coordinate\n"
" coordIndex [" << std::endl;
}
void write_facet_begin( std::size_t) { void write_facet_begin( std::size_t) {
out() << " "; out() << " ";
} }
@ -48,9 +84,4 @@ public:
} // namespace CGAL } // namespace CGAL
#ifdef CGAL_HEADER_ONLY
#include <CGAL/IO/File_writer_VRML_2_impl.h>
#endif // CGAL_HEADER_ONLY
#endif // CGAL_IO_FILE_WRITER_VRML_2_H // #endif // CGAL_IO_FILE_WRITER_VRML_2_H //
// EOF //

View File

@ -20,6 +20,7 @@
#define CGAL_IO_VRML_VRML_1_OSTREAM_H #define CGAL_IO_VRML_VRML_1_OSTREAM_H
#include <CGAL/basic.h> #include <CGAL/basic.h>
#include <iostream> #include <iostream>
// Declare the common base class for OpenInventor and VRML 1.0 format. // Declare the common base class for OpenInventor and VRML 1.0 format.
@ -32,18 +33,19 @@
namespace CGAL { namespace CGAL {
class VRML_1_ostream : public Inventor_ostream_base { class VRML_1_ostream : public Inventor_ostream_base
{
public: public:
VRML_1_ostream() {} VRML_1_ostream() {}
VRML_1_ostream(std::ostream& o) : Inventor_ostream_base(o) { VRML_1_ostream(std::ostream& o) : Inventor_ostream_base(o) { header(); }
header();
}
void open(std::ostream& o) { void open(std::ostream& o) {
Inventor_ostream_base::open(o); Inventor_ostream_base::open(o);
header(); header();
} }
private: private:
void header() { void header()
{
os() << "#VRML V1.0 ascii" << std::endl; os() << "#VRML V1.0 ascii" << std::endl;
os() << "# File written with the help of the CGAL Library" os() << "# File written with the help of the CGAL Library"
<< std::endl; << std::endl;
@ -86,11 +88,13 @@ operator<<(VRML_1_ostream& os,
<< CGAL::to_double(t[3].y()) << " " << CGAL::to_double(t[3].y()) << " "
<< CGAL::to_double(t[3].z()) << " ]" << CGAL::to_double(t[3].z()) << " ]"
<< "\n } #Coordinate3" ; << "\n } #Coordinate3" ;
os.os() << "\n IndexedFaceSet {" os.os() << "\n IndexedFaceSet {"
<< Indent << "coordIndex [ 0,1,2,-1, 1,3,2,-1,\n" << Indent << "coordIndex [ 0,1,2,-1, 1,3,2,-1,\n"
<< Indent << " 0,2,3,-1, 0,3,1,-1 ]\n" << Indent << " 0,2,3,-1, 0,3,1,-1 ]\n"
<< "\n } #IndexedFaceSet" << "\n } #IndexedFaceSet"
<< "\n } #Separator\n"; << "\n } #Separator\n";
return os; return os;
} }

View File

@ -24,21 +24,24 @@
namespace CGAL { namespace CGAL {
class VRML_2_ostream { class VRML_2_ostream
{
public: public:
VRML_2_ostream() : m_os(0) {} VRML_2_ostream() : m_os(0) {}
VRML_2_ostream(std::ostream& o) : m_os(&o) { header(); } VRML_2_ostream(std::ostream& o) : m_os(&o) { header(); }
~VRML_2_ostream() { close(); } ~VRML_2_ostream() { close(); }
void open(std::ostream& o) { m_os = &o; header(); } void open(std::ostream& o) { m_os = &o; header(); }
void close() { void close()
{
if ( m_os) if ( m_os)
footer(); footer();
m_os = 0; m_os = 0;
} }
explicit operator bool () {
return m_os && !m_os->fail(); explicit operator bool () { return m_os && !m_os->fail(); }
}
std::ostream& os() { std::ostream& os()
{
// The behaviour if m_os == 0 could be changed to return // The behaviour if m_os == 0 could be changed to return
// cerr or a file handle to /dev/null. The latter one would // cerr or a file handle to /dev/null. The latter one would
// mimick the behaviour that one can still use a stream with // mimick the behaviour that one can still use a stream with
@ -46,8 +49,10 @@ public:
CGAL_assertion( m_os != 0 ); CGAL_assertion( m_os != 0 );
return *m_os; return *m_os;
} }
private: private:
void header() { void header()
{
os() << "#VRML V2.0 utf8\n" os() << "#VRML V2.0 utf8\n"
"# File written with the help of the CGAL Library\n" "# File written with the help of the CGAL Library\n"
"#-- Begin of file header\n" "#-- Begin of file header\n"
@ -66,27 +71,26 @@ private:
" }\n" " }\n"
" #-- End of file header" << std::endl; " #-- End of file header" << std::endl;
} }
void footer() {
void footer()
{
os() << " #-- Begin of file footer\n" os() << " #-- Begin of file footer\n"
" ]\n" " ]\n"
"}\n" "}\n"
"#-- End of file footer" << std::endl; "#-- End of file footer" << std::endl;
} }
std::ostream* m_os; std::ostream* m_os;
}; };
inline inline VRML_2_ostream& operator<<(VRML_2_ostream& os,
VRML_2_ostream&
operator<<(VRML_2_ostream& os,
const char* s) const char* s)
{ {
os.os() << s; os.os() << s;
return os; return os;
} }
inline inline VRML_2_ostream& operator<<(VRML_2_ostream& os,
VRML_2_ostream&
operator<<(VRML_2_ostream& os,
const double& d) const double& d)
{ {
os.os() << d; os.os() << d;
@ -145,6 +149,7 @@ operator<<(VRML_2_ostream& os,
" } #Shape\n" " } #Shape\n"
" ] #children\n" " ] #children\n"
" } #Group\n"; " } #Group\n";
return os; return os;
} }
@ -173,8 +178,7 @@ operator<<(VRML_2_ostream& os,
" PointSet {\n" " PointSet {\n"
" coord Coordinate {\n" " coord Coordinate {\n"
" point [ "; " point [ ";
os << CGAL::to_double(p.x()) << " " << CGAL::to_double(p.y()) os << CGAL::to_double(p.x()) << " " << CGAL::to_double(p.y()) << " " << CGAL::to_double(p.z()) << " ]\n";
<< " " << CGAL::to_double(p.z()) << " ]\n";
os << Indent << "}\n"; os << Indent << "}\n";
os << Indent << "} # PointSet\n"; os << Indent << "} # PointSet\n";
os << " } #Shape\n" os << " } #Shape\n"
@ -188,8 +192,6 @@ operator<<(VRML_2_ostream& os,
#endif // CGAL_IO_VRML_2_POINT_3 #endif // CGAL_IO_VRML_2_POINT_3
#endif // CGAL_POINT_3_H #endif // CGAL_POINT_3_H
#ifdef CGAL_TRIANGLE_3_H #ifdef CGAL_TRIANGLE_3_H
#ifndef CGAL_IO_VRML_2_TRIANGLE_3 #ifndef CGAL_IO_VRML_2_TRIANGLE_3
#define CGAL_IO_VRML_2_TRIANGLE_3 #define CGAL_IO_VRML_2_TRIANGLE_3
@ -211,19 +213,17 @@ operator<<(VRML_2_ostream& os,
" coord Coordinate {\n" " coord Coordinate {\n"
" point [ \n"; " point [ \n";
os << Indent ; os << Indent ;
os << CGAL::to_double(t[0].x()) << " " << CGAL::to_double(t[0].y()) os << CGAL::to_double(t[0].x()) << " " << CGAL::to_double(t[0].y()) << " " << CGAL::to_double(t[0].z()) << ",\n";
<< " " << CGAL::to_double(t[0].z()) << ",\n";
os << Indent; os << Indent;
os << CGAL::to_double(t[1].x()) << " " << CGAL::to_double(t[1].y()) os << CGAL::to_double(t[1].x()) << " " << CGAL::to_double(t[1].y()) << " " << CGAL::to_double(t[1].z()) << ",\n";
<< " " << CGAL::to_double(t[1].z()) << ",\n";
os << Indent; os << Indent;
os << CGAL::to_double(t[2].x()) << " " << CGAL::to_double(t[2].y()) os << CGAL::to_double(t[2].x()) << " " << CGAL::to_double(t[2].y()) << " " << CGAL::to_double(t[2].z()) << " ]\n";
<< " " << CGAL::to_double(t[2].z()) << " ]\n";
os << Indent << "}\n" << Indent << "coordIndex [ 0 1, 1 2, 2 0 -1 ]\n"; os << Indent << "}\n" << Indent << "coordIndex [ 0 1, 1 2, 2 0 -1 ]\n";
os << Indent << "} # IndexedLineSet\n"; os << Indent << "} # IndexedLineSet\n";
os << " } #Shape\n" os << " } #Shape\n"
" ] #children\n" " ] #children\n"
" } #Group\n"; " } #Group\n";
return os; return os;
} }
@ -232,7 +232,6 @@ operator<<(VRML_2_ostream& os,
#endif // CGAL_IO_VRML_2_TRIANGLE_3 #endif // CGAL_IO_VRML_2_TRIANGLE_3
#endif // CGAL_TRIANGLE_3_H #endif // CGAL_TRIANGLE_3_H
#ifdef CGAL_SEGMENT_3_H #ifdef CGAL_SEGMENT_3_H
#ifndef CGAL_IO_VRML_2_SEGMENT_3 #ifndef CGAL_IO_VRML_2_SEGMENT_3
#define CGAL_IO_VRML_2_SEGMENT_3 #define CGAL_IO_VRML_2_SEGMENT_3
@ -253,8 +252,8 @@ operator<<(VRML_2_ostream& os,
" IndexedLineSet {\n" " IndexedLineSet {\n"
" coord Coordinate {\n" " coord Coordinate {\n"
" point [ \n"; " point [ \n";
os << Indent << CGAL::to_double(s.source().x()); os << Indent << CGAL::to_double(s.source().x())
os << " " << CGAL::to_double(s.source().y()) << " " << CGAL::to_double(s.source().y())
<< " " << CGAL::to_double(s.source().z()) << ",\n"; << " " << CGAL::to_double(s.source().z()) << ",\n";
os << Indent; os << Indent;
os << CGAL::to_double(s.target().x()) os << CGAL::to_double(s.target().x())

View File

@ -17,9 +17,9 @@
#include <fstream> #include <fstream>
#include <vector> #include <vector>
template <class FT> template <class FT>
void void write_vector(std::ostream& os,
write_vector(std::ostream& os,
const std::vector<FT>& vect) const std::vector<FT>& vect)
{ {
const char* buffer = reinterpret_cast<const char*>(&(vect[0])); const char* buffer = reinterpret_cast<const char*>(&(vect[0]));

View File

@ -14,19 +14,13 @@
#ifndef CGAL_IO_WKT_H #ifndef CGAL_IO_WKT_H
#define CGAL_IO_WKT_H #define CGAL_IO_WKT_H
#include <CGAL/Point_2.h> #include <CGAL/Point_2.h>
#include <CGAL/Point_3.h> #include <CGAL/Point_3.h>
#include <CGAL/Polygon_2.h> #include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h> #include <CGAL/Polygon_with_holes_2.h>
#if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500)
#include <iostream>
#include <sstream>
#include <string>
#include <boost/geometry/io/wkt/read.hpp>
#include <boost/geometry/io/wkt/write.hpp>
#include <CGAL/IO/WKT/traits_point.h> #include <CGAL/IO/WKT/traits_point.h>
#include <CGAL/IO/WKT/traits_point_3.h> #include <CGAL/IO/WKT/traits_point_3.h>
@ -36,9 +30,14 @@
#include <CGAL/IO/WKT/traits_multilinestring.h> #include <CGAL/IO/WKT/traits_multilinestring.h>
#include <CGAL/IO/WKT/traits_multipolygon.h> #include <CGAL/IO/WKT/traits_multipolygon.h>
#include <boost/geometry/io/wkt/read.hpp>
#include <boost/geometry/io/wkt/write.hpp>
#include <iostream>
#include <sstream>
#include <string>
namespace CGAL { namespace CGAL {
namespace internal { namespace internal {
template <typename K> template <typename K>
@ -46,24 +45,22 @@ namespace internal {
{ {
typename CGAL::Polygon_2<K>::iterator it = poly.end(); typename CGAL::Polygon_2<K>::iterator it = poly.end();
--it; --it;
if( (*poly.begin()) == *it){ if((*poly.begin()) == *it)
poly.erase(it); poly.erase(it);
} }
}
template <typename K> template <typename K>
void pop_back_if_equal_to_front(CGAL::Polygon_with_holes_2<K>& pwh) void pop_back_if_equal_to_front(CGAL::Polygon_with_holes_2<K>& pwh)
{ {
pop_back_if_equal_to_front(pwh.outer_boundary()); pop_back_if_equal_to_front(pwh.outer_boundary());
for(auto i = pwh.holes_begin(); i!= pwh.holes_end(); ++i){ for(auto i = pwh.holes_begin(); i!= pwh.holes_end(); ++i)
pop_back_if_equal_to_front(*i); pop_back_if_equal_to_front(*i);
} }
}
} } // namespace internal
template<typename Point> template<typename Point>
bool bool read_point_WKT(std::istream& in,
read_point_WKT( std::istream& in,
Point& point) Point& point)
{ {
if(!in) if(!in)
@ -81,22 +78,25 @@ read_point_WKT( std::istream& in,
if(type.substr(0, 5).compare("POINT") == 0) if(type.substr(0, 5).compare("POINT") == 0)
{ {
try{ try
{
boost::geometry::read_wkt(line, point); boost::geometry::read_wkt(line, point);
} catch(...) }
catch(...)
{ {
std::cerr << "error." << std::endl; std::cerr << "error." << std::endl;
return false; return false;
} }
break; break;
} }
} }
return in.good(); return in.good();
} }
template<typename MultiPoint> template<typename MultiPoint>
bool bool read_multi_point_WKT(std::istream& in,
read_multi_point_WKT( std::istream& in,
MultiPoint& mp) MultiPoint& mp)
{ {
if(!in) if(!in)
@ -126,10 +126,8 @@ read_multi_point_WKT( std::istream& in,
return in.good(); return in.good();
} }
template<typename LineString> template<typename LineString>
bool bool read_linestring_WKT(std::istream& in,
read_linestring_WKT( std::istream& in,
LineString& polyline) LineString& polyline)
{ {
if(!in) if(!in)
@ -160,8 +158,7 @@ read_linestring_WKT( std::istream& in,
} }
template<typename MultiLineString> template<typename MultiLineString>
bool bool read_multi_linestring_WKT(std::istream& in,
read_multi_linestring_WKT( std::istream& in,
MultiLineString& mls) MultiLineString& mls)
{ {
if(!in) if(!in)
@ -169,6 +166,7 @@ read_multi_linestring_WKT( std::istream& in,
std::cerr << "Error: cannot open file" << std::endl; std::cerr << "Error: cannot open file" << std::endl;
return false; return false;
} }
typedef typename MultiLineString::value_type PointRange; typedef typename MultiLineString::value_type PointRange;
typedef internal::Geometry_container<PointRange, boost::geometry::linestring_tag> LineString; typedef internal::Geometry_container<PointRange, boost::geometry::linestring_tag> LineString;
@ -183,27 +181,29 @@ read_multi_linestring_WKT( std::istream& in,
if(type.substr(0, 15).compare("MULTILINESTRING") == 0) if(type.substr(0, 15).compare("MULTILINESTRING") == 0)
{ {
try{ try
{
boost::geometry::read_wkt(line, gc); boost::geometry::read_wkt(line, gc);
} catch(...){ }
catch(...)
{
std::cerr << "error." << std::endl; std::cerr << "error." << std::endl;
return false; return false;
} }
break; break;
} }
} }
for(LineString& ls : gc) for(LineString& ls : gc)
{
mls.push_back(*ls.range); mls.push_back(*ls.range);
}
return in.good(); return in.good();
} }
template<typename Polygon> template<typename Polygon>
bool bool read_polygon_WKT(std::istream& in,
read_polygon_WKT( std::istream& in, Polygon& polygon)
Polygon& polygon
)
{ {
if(!in) if(!in)
{ {
@ -220,12 +220,16 @@ read_polygon_WKT( std::istream& in,
if(type.substr(0, 7).compare("POLYGON") == 0) if(type.substr(0, 7).compare("POLYGON") == 0)
{ {
try { try
{
boost::geometry::read_wkt(line, polygon); boost::geometry::read_wkt(line, polygon);
} catch( ...){ }
catch( ...)
{
in.setstate(std::ios::failbit); in.setstate(std::ios::failbit);
return false; return false;
}; };
internal::pop_back_if_equal_to_front(polygon); internal::pop_back_if_equal_to_front(polygon);
break; break;
} }
@ -234,16 +238,15 @@ read_polygon_WKT( std::istream& in,
} }
template<typename MultiPolygon> template<typename MultiPolygon>
bool bool read_multi_polygon_WKT(std::istream& in,
read_multi_polygon_WKT( std::istream& in, MultiPolygon& polygons)
MultiPolygon& polygons
)
{ {
if(!in) if(!in)
{ {
std::cerr << "Error: cannot open file" << std::endl; std::cerr << "Error: cannot open file" << std::endl;
return false; return false;
} }
internal::Geometry_container<MultiPolygon, boost::geometry::multi_polygon_tag> gc(polygons); internal::Geometry_container<MultiPolygon, boost::geometry::multi_polygon_tag> gc(polygons);
std::string line; std::string line;
while(std::getline(in, line)) while(std::getline(in, line))
@ -254,18 +257,19 @@ read_multi_polygon_WKT( std::istream& in,
if(type.substr(0, 12).compare("MULTIPOLYGON") == 0) if(type.substr(0, 12).compare("MULTIPOLYGON") == 0)
{ {
try { try
{
boost::geometry::read_wkt(line, gc); boost::geometry::read_wkt(line, gc);
} catch( ...){ }
catch( ...)
{
in.setstate(std::ios::failbit); in.setstate(std::ios::failbit);
return false; return false;
}; };
for( typename
internal::Geometry_container<MultiPolygon, boost::geometry::multi_polygon_tag>::iterator it for(typename internal::Geometry_container<MultiPolygon, boost::geometry::multi_polygon_tag>::iterator it = gc.begin(); it != gc.end(); ++it)
= gc.begin(); it != gc.end(); ++it)
{
internal::pop_back_if_equal_to_front(*it); internal::pop_back_if_equal_to_front(*it);
}
break; break;
} }
} }
@ -273,56 +277,51 @@ read_multi_polygon_WKT( std::istream& in,
} }
template<typename Point> template<typename Point>
std::ostream& std::ostream& write_point_WKT(std::ostream& out,
write_point_WKT( std::ostream& out, const Point& point)
const Point& point
)
{ {
if(!out) if(!out)
{ {
std::cerr << "Error: cannot open file" << std::endl; std::cerr << "Error: cannot open file" << std::endl;
return out; return out;
} }
out << boost::geometry::wkt(point) << std::endl; out << boost::geometry::wkt(point) << std::endl;
return out; return out;
} }
template<typename Polygon> template<typename Polygon>
std::ostream& std::ostream& write_polygon_WKT(std::ostream& out,
write_polygon_WKT( std::ostream& out, const Polygon& poly)
const Polygon& poly
)
{ {
if(!out) if(!out)
{ {
std::cerr << "Error: cannot open file" << std::endl; std::cerr << "Error: cannot open file" << std::endl;
return out; return out;
} }
out << boost::geometry::wkt(poly) << std::endl; out << boost::geometry::wkt(poly) << std::endl;
return out; return out;
} }
template<typename LineString> template<typename LineString>
std::ostream& std::ostream& write_linestring_WKT(std::ostream& out,
write_linestring_WKT( std::ostream& out, LineString ls)
LineString ls
)
{ {
if(!out) if(!out)
{ {
std::cerr << "Error: cannot open file" << std::endl; std::cerr << "Error: cannot open file" << std::endl;
return out; return out;
} }
internal::Geometry_container<LineString, boost::geometry::linestring_tag> gc(ls); internal::Geometry_container<LineString, boost::geometry::linestring_tag> gc(ls);
out << boost::geometry::wkt(gc) << std::endl; out << boost::geometry::wkt(gc) << std::endl;
return out; return out;
} }
template<typename MultiPoint> template<typename MultiPoint>
std::ostream& std::ostream& write_multi_point_WKT(std::ostream& out,
write_multi_point_WKT( std::ostream& out, MultiPoint& mp)
MultiPoint& mp
)
{ {
if(!out) if(!out)
{ {
@ -335,50 +334,50 @@ write_multi_point_WKT( std::ostream& out,
} }
template<typename MultiPolygon> template<typename MultiPolygon>
std::ostream& std::ostream& write_multi_polygon_WKT(std::ostream& out,
write_multi_polygon_WKT( std::ostream& out, MultiPolygon& polygons)
MultiPolygon& polygons
)
{ {
if(!out) if(!out)
{ {
std::cerr << "Error: cannot open file" << std::endl; std::cerr << "Error: cannot open file" << std::endl;
return out; return out;
} }
internal::Geometry_container<MultiPolygon, boost::geometry::multi_polygon_tag> gc(polygons); internal::Geometry_container<MultiPolygon, boost::geometry::multi_polygon_tag> gc(polygons);
out << boost::geometry::wkt(gc) << std::endl; out << boost::geometry::wkt(gc) << std::endl;
return out; return out;
} }
template<typename MultiLineString> template<typename MultiLineString>
std::ostream& std::ostream& write_multi_linestring_WKT(std::ostream& out,
write_multi_linestring_WKT( std::ostream& out, MultiLineString& mls)
MultiLineString& mls
)
{ {
if(!out) if(!out)
{ {
std::cerr << "Error: cannot open file" << std::endl; std::cerr << "Error: cannot open file" << std::endl;
return out; return out;
} }
typedef typename MultiLineString::value_type PointRange; typedef typename MultiLineString::value_type PointRange;
typedef internal::Geometry_container<PointRange, boost::geometry::linestring_tag> LineString; typedef internal::Geometry_container<PointRange, boost::geometry::linestring_tag> LineString;
std::vector<LineString> pr_range; std::vector<LineString> pr_range;
for(PointRange& pr : mls) for(PointRange& pr : mls)
{ {
LineString ls(pr); LineString ls(pr);
pr_range.push_back(ls); pr_range.push_back(ls);
} }
internal::Geometry_container<std::vector<LineString>, boost::geometry::multi_linestring_tag> gc(pr_range); internal::Geometry_container<std::vector<LineString>, boost::geometry::multi_linestring_tag> gc(pr_range);
out << boost::geometry::wkt(gc) << std::endl; out << boost::geometry::wkt(gc) << std::endl;
return out; return out;
} }
template<typename MultiPoint, template<typename MultiPoint,
typename MultiLineString, typename MultiLineString,
typename MultiPolygon> typename MultiPolygon>
std::istream& std::istream& read_WKT(std::istream& input,
read_WKT( std::istream& input,
MultiPoint& points, MultiPoint& points,
MultiLineString& polylines, MultiLineString& polylines,
MultiPolygon& polygons) MultiPolygon& polygons)
@ -388,6 +387,7 @@ read_WKT( std::istream& input,
typedef typename MultiPoint::value_type Point; typedef typename MultiPoint::value_type Point;
typedef typename MultiLineString::value_type LineString; typedef typename MultiLineString::value_type LineString;
typedef typename MultiPolygon::value_type Polygon; typedef typename MultiPolygon::value_type Polygon;
std::string line; std::string line;
std::streampos input_pos = input.tellg(); std::streampos input_pos = input.tellg();
std::getline(input, line); std::getline(input, line);
@ -395,13 +395,16 @@ read_WKT( std::istream& input,
std::string t; std::string t;
std::string type=""; std::string type="";
iss >> t; iss >> t;
for(std::size_t pos=0; pos < t.length(); ++pos) for(std::size_t pos=0; pos < t.length(); ++pos)
{ {
char c = t[pos]; char c = t[pos];
if(c == '(') if(c == '(')
break; break;
type.push_back(c); type.push_back(c);
} }
input.seekg(input_pos); input.seekg(input_pos);
if(type == "POINT") if(type == "POINT")
{ {
@ -443,7 +446,9 @@ read_WKT( std::istream& input,
for(const Polygon& poly : mp) for(const Polygon& poly : mp)
polygons.push_back(poly); polygons.push_back(poly);
} }
}while(input.good() && !input.eof()); }
while(input.good() && !input.eof());
return input; return input;
} }
}//end CGAL }//end CGAL

View File

@ -14,20 +14,27 @@
#ifndef CGAL_IO_WKT_TRAITS_LINESTRING_H #ifndef CGAL_IO_WKT_TRAITS_LINESTRING_H
#define CGAL_IO_WKT_TRAITS_LINESTRING_H #define CGAL_IO_WKT_TRAITS_LINESTRING_H
#if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500)
#include <CGAL/internal/Geometry_container.h> #include <CGAL/internal/Geometry_container.h>
#include <boost/geometry/io/wkt/write.hpp> #include <boost/geometry/io/wkt/write.hpp>
#include <boost/geometry/io/wkt/read.hpp> #include <boost/geometry/io/wkt/read.hpp>
namespace boost { namespace boost {
namespace geometry { namespace geometry {
namespace traits { namespace traits {
template< typename R> struct tag<CGAL::internal::Geometry_container<R, linestring_tag> >
{ typedef linestring_tag type; };
}}} //end namespaces template< typename R>
struct tag<CGAL::internal::Geometry_container<R, linestring_tag> >
{
typedef linestring_tag type;
};
#endif } // namespace traits
#endif // TRAITS_LINESTRING_H } // namespace geometry
} // namespace boost
#endif // BOOST VERSION CHECKS
#endif // CGAL_IO_WKT_TRAITS_LINESTRING_H

View File

@ -14,21 +14,28 @@
#ifndef CGAL_IO_WKT_TRAITS_MULTILINESTRING_H #ifndef CGAL_IO_WKT_TRAITS_MULTILINESTRING_H
#define CGAL_IO_WKT_TRAITS_MULTILINESTRING_H #define CGAL_IO_WKT_TRAITS_MULTILINESTRING_H
#if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500)
#include <CGAL/internal/Geometry_container.h> #include <CGAL/internal/Geometry_container.h>
#include <boost/geometry/io/wkt/write.hpp> #include <boost/geometry/io/wkt/write.hpp>
#include <boost/geometry/io/wkt/read.hpp> #include <boost/geometry/io/wkt/read.hpp>
namespace boost { namespace boost {
namespace geometry { namespace geometry {
namespace traits { namespace traits {
// WKT traits for MultiLinestring // WKT traits for MultiLinestring
template< typename R > template< typename R >
struct tag<CGAL::internal::Geometry_container<R, multi_linestring_tag> > struct tag<CGAL::internal::Geometry_container<R, multi_linestring_tag> >
{ typedef multi_linestring_tag type; }; {
typedef multi_linestring_tag type;
};
}//end traits } // namespace traits
}//end geometry } // namespace geometry
}//end boost } // namespace boost
#endif // TRAITS_MULTILINESTRING_H
#endif #endif // BOOST VERSION CHECKS
#endif // CGAL_IO_WKT_TRAITS_MULTILINESTRING_H

View File

@ -14,21 +14,28 @@
#ifndef CGAL_IO_WKT_TRAITS_MULTIPOINT_H #ifndef CGAL_IO_WKT_TRAITS_MULTIPOINT_H
#define CGAL_IO_WKT_TRAITS_MULTIPOINT_H #define CGAL_IO_WKT_TRAITS_MULTIPOINT_H
#if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500)
#include <CGAL/internal/Geometry_container.h> #include <CGAL/internal/Geometry_container.h>
#include <boost/geometry/io/wkt/write.hpp> #include <boost/geometry/io/wkt/write.hpp>
#include <boost/geometry/io/wkt/read.hpp> #include <boost/geometry/io/wkt/read.hpp>
namespace boost { namespace boost {
namespace geometry { namespace geometry {
namespace traits { namespace traits {
// WKT traits for MultiPoint // WKT traits for MultiPoint
template< typename R > template< typename R >
struct tag<CGAL::internal::Geometry_container<R, multi_point_tag > > struct tag<CGAL::internal::Geometry_container<R, multi_point_tag > >
{ typedef multi_point_tag type; }; {
typedef multi_point_tag type;
};
}//end traits } // namespace traits
}//end geometry } // namespace geometry
}//end boost } // namespace boost
#endif // TRAITS_MULTIPOINT_H
#endif #endif // BOOST VERSION CHECKS
#endif // CGAL_IO_WKT_TRAITS_MULTIPOINT_H

View File

@ -14,24 +14,29 @@
#ifndef CGAL_IO_WKT_TRAITS_MULTIPOLYGON_H #ifndef CGAL_IO_WKT_TRAITS_MULTIPOLYGON_H
#define CGAL_IO_WKT_TRAITS_MULTIPOLYGON_H #define CGAL_IO_WKT_TRAITS_MULTIPOLYGON_H
#if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500)
#include <CGAL/internal/Geometry_container.h> #include <CGAL/internal/Geometry_container.h>
#include <boost/geometry/io/wkt/write.hpp> #include <boost/geometry/io/wkt/write.hpp>
#include <boost/geometry/io/wkt/read.hpp> #include <boost/geometry/io/wkt/read.hpp>
namespace boost { namespace boost {
namespace geometry { namespace geometry {
namespace traits { namespace traits {
// WKT traits for MultiPolygon // WKT traits for MultiPolygon
template< typename R > template< typename R >
struct tag<CGAL::internal::Geometry_container<R, multi_polygon_tag> > struct tag<CGAL::internal::Geometry_container<R, multi_polygon_tag> >
{ typedef multi_polygon_tag type; }; {
typedef multi_polygon_tag type;
};
}//end traits } // namespace traits
}//end geometry } // namespace geometry
}//end boost } // namespace boost
#endif #endif // BOOST VERSION CHECKS
#endif #endif // CGAL_IO_WKT_TRAITS_MULTIPOLYGON_H

View File

@ -14,9 +14,12 @@
#ifndef CGAL_IO_WKT_TRAITS_POINT_H #ifndef CGAL_IO_WKT_TRAITS_POINT_H
#define CGAL_IO_WKT_TRAITS_POINT_H #define CGAL_IO_WKT_TRAITS_POINT_H
#if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500)
#include <CGAL/number_utils.h> #include <CGAL/number_utils.h>
#include <CGAL/Point_2.h> #include <CGAL/Point_2.h>
#include <boost/geometry/io/wkt/write.hpp> #include <boost/geometry/io/wkt/write.hpp>
#include <boost/geometry/io/wkt/read.hpp> #include <boost/geometry/io/wkt/read.hpp>
@ -25,47 +28,46 @@ namespace geometry{
namespace traits { namespace traits {
//WKT traits for Points //WKT traits for Points
template< typename K > struct tag<CGAL::Point_2<K> > template< typename K >
{ typedef point_tag type; }; struct tag<CGAL::Point_2<K> >
{
typedef point_tag type;
};
template< typename K > struct coordinate_type<CGAL::Point_2<K> > template< typename K >
{ typedef double type; }; struct coordinate_type<CGAL::Point_2<K> >
{
typedef double type;
};
template< typename K > struct coordinate_system<CGAL::Point_2<K> > template< typename K >
{ typedef cs::cartesian type; }; struct coordinate_system<CGAL::Point_2<K> >
{
typedef cs::cartesian type;
};
template< typename K > struct dimension<CGAL::Point_2<K> > : boost::mpl::int_<2> {}; template< typename K >
struct dimension<CGAL::Point_2<K> >
: boost::mpl::int_<2>
{};
template< typename K > template< typename K >
struct access<CGAL::Point_2<K>, 0> struct access<CGAL::Point_2<K>, 0>
{ {
static double get(CGAL::Point_2<K> const& p) static double get(const CGAL::Point_2<K>& p) { return CGAL::to_double(p.x()); }
{ static void set(CGAL::Point_2<K>& p, typename K::FT c) { p = CGAL::Point_2<K>(c, p.y()); }
return CGAL::to_double(p.x());
}
static void set(CGAL::Point_2<K> & p, typename K::FT c)
{
p = CGAL::Point_2<K> (c, p.y());
}
}; };
template< typename K > template< typename K >
struct access<CGAL::Point_2<K>, 1> struct access<CGAL::Point_2<K>, 1>
{ {
static double get(CGAL::Point_2<K> const& p) static double get(const CGAL::Point_2<K>& p) { return CGAL::to_double(p.y()); }
{ static void set(CGAL::Point_2<K>& p, typename K::FT c) { p = CGAL::Point_2<K>(p.x(), c); }
return CGAL::to_double(p.y());
}
static void set(CGAL::Point_2<K> & p, typename K::FT c)
{
p = CGAL::Point_2<K> (p.x(), c);
}
}; };
}}}//end namespaces } // namespace traits
#endif } // namespace geometry
#endif } // namespace boost
#endif // BOOST VERSION CHECKS
#endif // CGAL_IO_WKT_TRAITS_POINT_H

View File

@ -14,9 +14,12 @@
#ifndef CGAL_IO_WKT_TRAITS_POINT_3_H #ifndef CGAL_IO_WKT_TRAITS_POINT_3_H
#define 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) #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500)
#include <CGAL/number_utils.h> #include <CGAL/number_utils.h>
#include <CGAL/Point_3.h> #include <CGAL/Point_3.h>
#include <boost/geometry/io/wkt/write.hpp> #include <boost/geometry/io/wkt/write.hpp>
#include <boost/geometry/io/wkt/read.hpp> #include <boost/geometry/io/wkt/read.hpp>
@ -25,61 +28,53 @@ namespace geometry{
namespace traits { namespace traits {
//WKT traits for Points //WKT traits for Points
template< typename K > struct tag<CGAL::Point_3<K> > template< typename K >
{ typedef point_tag type; }; struct tag<CGAL::Point_3<K> >
{
typedef point_tag type;
};
template< typename K > struct coordinate_type<CGAL::Point_3<K> > template< typename K >
{ typedef typename K::FT type; }; struct coordinate_type<CGAL::Point_3<K> >
{
typedef typename K::FT type;
};
template< typename K > struct coordinate_system<CGAL::Point_3<K> > template< typename K >
{ typedef cs::cartesian type; }; struct coordinate_system<CGAL::Point_3<K> >
{
typedef cs::cartesian type;
};
template< typename K > struct dimension<CGAL::Point_3<K> > : boost::mpl::int_<3> {}; template< typename K >
struct dimension<CGAL::Point_3<K> >
: boost::mpl::int_<3>
{};
template< typename K > template< typename K >
struct access<CGAL::Point_3<K>, 0> struct access<CGAL::Point_3<K>, 0>
{ {
static double get(CGAL::Point_3<K> const& p) static double get(const CGAL::Point_3<K>& p) { return CGAL::to_double(p.x()); }
{ static void set(CGAL::Point_3<K>& p, typename K::FT c) { p = CGAL::Point_3<K> (c, p.y(), p.z()); }
return CGAL::to_double(p.x());
}
static void set(CGAL::Point_3<K> & p, typename K::FT c)
{
p = CGAL::Point_3<K> (c, p.y(), p.z());
}
}; };
template< typename K > template< typename K >
struct access<CGAL::Point_3<K>, 1> struct access<CGAL::Point_3<K>, 1>
{ {
static double get(CGAL::Point_3<K> const& p) static double get(const CGAL::Point_3<K>& p) { return CGAL::to_double(p.y()); }
{ static void set(CGAL::Point_3<K>& p, typename K::FT c) { p = CGAL::Point_3<K> (p.x(), c, p.z()); }
return CGAL::to_double(p.y());
}
static void set(CGAL::Point_3<K> & p, typename K::FT c)
{
p = CGAL::Point_3<K> (p.x(), c, p.z());
}
}; };
template< typename K > template< typename K >
struct access<CGAL::Point_3<K>, 2> struct access<CGAL::Point_3<K>, 2>
{ {
static double get(CGAL::Point_3<K> const& p) static double get(const CGAL::Point_3<K>& p) { return CGAL::to_double(p.z()); }
{ static void set(CGAL::Point_3<K>& p, typename K::FT c) { p = CGAL::Point_3<K> (p.x(), p.y(), c); }
return CGAL::to_double(p.z());
}
static void set(CGAL::Point_3<K> & p, typename K::FT c)
{
p = CGAL::Point_3<K> (p.x(), p.y(), c);
}
}; };
}}}//end namespaces } // namespace traits
#endif } // namespace geometry
#endif } // namespace boost
#endif // BOOST VERSION CHECKS
#endif // CGAL_IO_WKT_TRAITS_POINT_3_H

View File

@ -14,35 +14,50 @@
#ifndef CGAL_IO_WKT_TRAITS_POLYGON_H #ifndef CGAL_IO_WKT_TRAITS_POLYGON_H
#define CGAL_IO_WKT_TRAITS_POLYGON_H #define CGAL_IO_WKT_TRAITS_POLYGON_H
#if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500)
#include <CGAL/Polygon_2.h> #include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h> #include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Point_2.h> #include <CGAL/Point_2.h>
#include <boost/geometry/io/wkt/write.hpp> #include <boost/geometry/io/wkt/write.hpp>
#include <boost/geometry/io/wkt/read.hpp> #include <boost/geometry/io/wkt/read.hpp>
namespace boost { namespace boost {
namespace geometry { namespace geometry {
namespace traits { namespace traits {
// WKT traits for Polygon // WKT traits for Polygon
template< typename K > struct tag<CGAL::Polygon_2<K> > template< typename K >
{ typedef ring_tag type; }; struct tag<CGAL::Polygon_2<K> >
{
typedef ring_tag type;
};
template< typename K > template< typename K >
struct tag<CGAL::Polygon_with_holes_2<K> > struct tag<CGAL::Polygon_with_holes_2<K> >
{ typedef polygon_tag type; }; {
typedef polygon_tag type;
};
template< typename K > template< typename K >
struct ring_const_type<CGAL::Polygon_with_holes_2<K> > struct ring_const_type<CGAL::Polygon_with_holes_2<K> >
{ typedef const CGAL::Polygon_2<K>& type; }; {
typedef const CGAL::Polygon_2<K>& type;
};
template< typename K > template< typename K >
struct ring_mutable_type<CGAL::Polygon_with_holes_2<K> > struct ring_mutable_type<CGAL::Polygon_with_holes_2<K> >
{ typedef CGAL::Polygon_2<K>& type; }; {
typedef CGAL::Polygon_2<K>& type;
};
template< typename K > template< typename K >
struct interior_const_type<CGAL::Polygon_with_holes_2<K> > struct interior_const_type<CGAL::Polygon_with_holes_2<K> >
{ typedef const typename CGAL::Polygon_with_holes_2<K>::Holes_container& type; }; {
typedef const typename CGAL::Polygon_with_holes_2<K>::Holes_container& type;
};
template< typename K > template< typename K >
struct interior_mutable_type<CGAL::Polygon_with_holes_2<K> > struct interior_mutable_type<CGAL::Polygon_with_holes_2<K> >
@ -55,7 +70,7 @@ struct exterior_ring<CGAL::Polygon_with_holes_2<K> >
{ {
return (p.outer_boundary()); return (p.outer_boundary());
} }
static CGAL::Polygon_2<K> const& get(CGAL::Polygon_with_holes_2<K> const& p) static const CGAL::Polygon_2<K>& get(const CGAL::Polygon_with_holes_2<K>& p)
{ {
return (p.outer_boundary()); return (p.outer_boundary());
} }
@ -73,8 +88,9 @@ struct interior_rings<CGAL::Polygon_with_holes_2<K> >
return p.holes(); return p.holes();
} }
}; };
}//end traits
}//end geometry } // namespace traits
} // namespace geometry
//extra specialization //extra specialization
template< typename K > template< typename K >
@ -83,7 +99,7 @@ struct range_value<CGAL::Polygon_2<K> >
typedef typename CGAL::Polygon_2<K>::Point_2 type; typedef typename CGAL::Polygon_2<K>::Point_2 type;
}; };
}//end boost } // namespace boost
#endif #endif // BOOST VERSION CHECKS
#endif #endif // CGAL_IO_WKT_TRAITS_POLYGON_H