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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -18,12 +18,14 @@
#define CGAL_IO_FILE_WRITER_VRML_2_H 1
#include <CGAL/basic.h>
#include <iostream>
#include <cstddef>
namespace CGAL {
class CGAL_EXPORT File_writer_VRML_2 {
class File_writer_VRML_2
{
std::ostream* m_out;
std::size_t m_facets;
public:
@ -32,13 +34,47 @@ public:
void write_header( std::ostream& o,
std::size_t vertices,
std::size_t halfedges,
std::size_t facets);
void write_footer() const;
std::size_t facets)
{
m_out = &o;
m_facets = facets;
out() << " #-- Begin of Polyhedron_3\n";
out() << " # " << vertices << " vertices\n";
out() << " # " << halfedges << " halfedges\n";
out() << " # " << facets << " facets\n";
out() << " Group {\n"
" children [\n"
" Shape {\n"
" appearance Appearance { material "
"USE Material }\n"
" geometry IndexedFaceSet {\n"
" convex FALSE\n"
" solid FALSE\n"
" coord Coordinate {\n"
" point [" << std::endl;
}
void write_footer() const
{
out() << " ] #coordIndex\n"
" } #geometry\n"
" } #Shape\n"
" ] #children\n"
" } #Group" << std::endl;
}
void write_vertex( const double& x, const double& y, const double& z) {
out() << " "
<< x << ' ' << y << ' ' << z << ',' << '\n';
}
void write_facet_header() const;
void write_facet_header() const
{
out() << " ] #point\n"
" } #coord Coordinate\n"
" coordIndex [" << std::endl;
}
void write_facet_begin( std::size_t) {
out() << " ";
}
@ -48,9 +84,4 @@ public:
} // 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 //
// EOF //

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -14,9 +14,12 @@
#ifndef CGAL_IO_WKT_TRAITS_POINT_H
#define CGAL_IO_WKT_TRAITS_POINT_H
#if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500)
#include <CGAL/number_utils.h>
#include <CGAL/Point_2.h>
#include <boost/geometry/io/wkt/write.hpp>
#include <boost/geometry/io/wkt/read.hpp>
@ -25,47 +28,46 @@ namespace geometry{
namespace traits {
//WKT traits for Points
template< typename K > struct tag<CGAL::Point_2<K> >
{ typedef point_tag type; };
template< typename K >
struct tag<CGAL::Point_2<K> >
{
typedef point_tag type;
};
template< typename K > struct coordinate_type<CGAL::Point_2<K> >
{ typedef double type; };
template< typename K >
struct coordinate_type<CGAL::Point_2<K> >
{
typedef double type;
};
template< typename K > struct coordinate_system<CGAL::Point_2<K> >
{ typedef cs::cartesian type; };
template< typename K >
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 >
struct access<CGAL::Point_2<K>, 0>
{
static double get(CGAL::Point_2<K> const& 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());
}
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()); }
};
template< typename K >
struct access<CGAL::Point_2<K>, 1>
{
static double get(CGAL::Point_2<K> const& 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);
}
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); }
};
}}}//end namespaces
#endif
#endif
} // namespace traits
} // namespace geometry
} // 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
#define CGAL_IO_WKT_TRAITS_POINT_3_H
#if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500)
#include <CGAL/number_utils.h>
#include <CGAL/Point_3.h>
#include <boost/geometry/io/wkt/write.hpp>
#include <boost/geometry/io/wkt/read.hpp>
@ -25,61 +28,53 @@ namespace geometry{
namespace traits {
//WKT traits for Points
template< typename K > struct tag<CGAL::Point_3<K> >
{ typedef point_tag type; };
template< typename K >
struct tag<CGAL::Point_3<K> >
{
typedef point_tag type;
};
template< typename K > struct coordinate_type<CGAL::Point_3<K> >
{ typedef typename K::FT type; };
template< typename K >
struct coordinate_type<CGAL::Point_3<K> >
{
typedef typename K::FT type;
};
template< typename K > struct coordinate_system<CGAL::Point_3<K> >
{ typedef cs::cartesian type; };
template< typename K >
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 >
struct access<CGAL::Point_3<K>, 0>
{
static double get(CGAL::Point_3<K> const& 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());
}
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()); }
};
template< typename K >
struct access<CGAL::Point_3<K>, 1>
{
static double get(CGAL::Point_3<K> const& 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());
}
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()); }
};
template< typename K >
struct access<CGAL::Point_3<K>, 2>
{
static double get(CGAL::Point_3<K> const& 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);
}
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); }
};
}}}//end namespaces
#endif
#endif
} // namespace traits
} // namespace geometry
} // 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
#define CGAL_IO_WKT_TRAITS_POLYGON_H
#if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500)
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Point_2.h>
#include <boost/geometry/io/wkt/write.hpp>
#include <boost/geometry/io/wkt/read.hpp>
namespace boost {
namespace geometry {
namespace traits {
// WKT traits for Polygon
template< typename K > struct tag<CGAL::Polygon_2<K> >
{ typedef ring_tag type; };
template< typename K >
struct tag<CGAL::Polygon_2<K> >
{
typedef ring_tag type;
};
template< typename K >
struct tag<CGAL::Polygon_with_holes_2<K> >
{ typedef polygon_tag type; };
{
typedef polygon_tag type;
};
template< typename 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 >
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 >
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 >
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());
}
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());
}
@ -73,8 +88,9 @@ struct interior_rings<CGAL::Polygon_with_holes_2<K> >
return p.holes();
}
};
}//end traits
}//end geometry
} // namespace traits
} // namespace geometry
//extra specialization
template< typename K >
@ -83,7 +99,7 @@ struct range_value<CGAL::Polygon_2<K> >
typedef typename CGAL::Polygon_2<K>::Point_2 type;
};
}//end boost
} // namespace boost
#endif
#endif
#endif // BOOST VERSION CHECKS
#endif // CGAL_IO_WKT_TRAITS_POLYGON_H