mirror of https://github.com/CGAL/cgal
Clean file IO code in Stream_support (no real changes)
This commit is contained in:
parent
e317c689aa
commit
490a726ec0
|
|
@ -11,30 +11,35 @@
|
|||
|
||||
#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{
|
||||
|
||||
namespace transform_nmr_internal{
|
||||
#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;
|
||||
int i, j;
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
for(i = 0; i < 4; i++) {
|
||||
for(j = 0; j < 3; j++) {
|
||||
mMatrix.m_fFields[j][i] = (i == j) ? 1.0f : 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
return mMatrix;
|
||||
}
|
||||
}//end transform_nmr_internal
|
||||
|
||||
} // namespace transform_nmr_internal
|
||||
|
||||
template<typename PointRange,
|
||||
typename PolygonRange,
|
||||
|
|
@ -44,24 +49,27 @@ 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;
|
||||
|
||||
// Retrieve Mesh Name Length
|
||||
hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, NULL, 0, &nNeededChars);
|
||||
if (hResult != LIB3MF_OK)
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr<<"Error during name extraction.";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Retrieve Mesh Name
|
||||
if (nNeededChars > 0) {
|
||||
if(nNeededChars > 0)
|
||||
{
|
||||
pBuffer.resize(nNeededChars + 1);
|
||||
hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, &pBuffer[0], nNeededChars + 1, NULL);
|
||||
pBuffer[nNeededChars] = 0;
|
||||
|
|
@ -74,17 +82,20 @@ bool extract_soups (NMR::PLib3MFModelMeshObject *pMeshObject,
|
|||
name = std::string(&pBuffer[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
name = std::string("Unknown Mesh");
|
||||
}
|
||||
|
||||
typename Kernel::Aff_transformation_3 t(
|
||||
transform.m_fFields[0][0], transform.m_fFields[0][1], transform.m_fFields[0][2], transform.m_fFields[0][3],
|
||||
transform.m_fFields[1][0], transform.m_fFields[1][1], transform.m_fFields[1][2], transform.m_fFields[1][3],
|
||||
transform.m_fFields[2][0], transform.m_fFields[2][1], transform.m_fFields[2][2], transform.m_fFields[2][3]
|
||||
transform.m_fFields[1][0], transform.m_fFields[1][1], transform.m_fFields[1][2], transform.m_fFields[1][3],
|
||||
transform.m_fFields[2][0], transform.m_fFields[2][1], transform.m_fFields[2][2], transform.m_fFields[2][3]
|
||||
);
|
||||
|
||||
NMR::PLib3MFPropertyHandler * pPropertyHandler;
|
||||
hResult = NMR::lib3mf_meshobject_createpropertyhandler(pMeshObject, &pPropertyHandler);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
DWORD nErrorMessage;
|
||||
LPCSTR pszErrorMessage;
|
||||
std::cerr << "could not create property handler: " << std::hex << hResult << std::endl;
|
||||
|
|
@ -103,6 +114,7 @@ bool extract_soups (NMR::PLib3MFModelMeshObject *pMeshObject,
|
|||
pVertex.m_fPosition[2]);
|
||||
points[vid] = t.transform(p);
|
||||
}
|
||||
|
||||
for(DWORD pid = 0; pid < triangles.size(); ++pid)
|
||||
{
|
||||
NMR::MODELMESHTRIANGLE pTriangle;
|
||||
|
|
@ -117,6 +129,7 @@ bool extract_soups (NMR::PLib3MFModelMeshObject *pMeshObject,
|
|||
colors[pid]=CGAL::Color(mColor.m_Red, mColor.m_Green,
|
||||
mColor.m_Blue, mColor.m_Alpha);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +141,8 @@ bool extract_polylines (NMR::PLib3MFModelMeshObject *pMeshObject,
|
|||
PointRange& points,
|
||||
PolygonRange&,
|
||||
ColorRange& colors,
|
||||
std::string& name) {
|
||||
std::string& name)
|
||||
{
|
||||
typedef typename PointRange::value_type Point_3;
|
||||
|
||||
HRESULT hResult;
|
||||
|
|
@ -136,7 +150,7 @@ bool extract_polylines (NMR::PLib3MFModelMeshObject *pMeshObject,
|
|||
std::vector<char> pBuffer;
|
||||
// Retrieve Mesh Name Length
|
||||
hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, NULL, 0, &nNeededChars);
|
||||
if (hResult != LIB3MF_OK)
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
points.resize(0);
|
||||
std::cerr<<"Error during name extraction.";
|
||||
|
|
@ -144,7 +158,8 @@ bool extract_polylines (NMR::PLib3MFModelMeshObject *pMeshObject,
|
|||
}
|
||||
|
||||
// Retrieve Mesh Name
|
||||
if (nNeededChars > 0) {
|
||||
if(nNeededChars > 0)
|
||||
{
|
||||
pBuffer.resize(nNeededChars + 1);
|
||||
hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, &pBuffer[0], nNeededChars + 1, NULL);
|
||||
pBuffer[nNeededChars] = 0;
|
||||
|
|
@ -164,7 +179,8 @@ bool extract_polylines (NMR::PLib3MFModelMeshObject *pMeshObject,
|
|||
|
||||
NMR::PLib3MFPropertyHandler * pPropertyHandler;
|
||||
hResult = NMR::lib3mf_meshobject_createpropertyhandler(pMeshObject, &pPropertyHandler);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
DWORD nErrorMessage;
|
||||
LPCSTR pszErrorMessage;
|
||||
std::cerr << "could not create property handler: " << std::hex << hResult << std::endl;
|
||||
|
|
@ -188,8 +204,8 @@ bool extract_polylines (NMR::PLib3MFModelMeshObject *pMeshObject,
|
|||
NMR::MODELMESH_TRIANGLECOLOR_SRGB pColor;
|
||||
NMR::lib3mf_propertyhandler_getcolor(pPropertyHandler, 0, &pColor);//get color of the dummy triangle
|
||||
NMR::MODELMESHCOLOR_SRGB mColor = pColor.m_Colors[0];
|
||||
colors[0]=CGAL::Color(mColor.m_Red, mColor.m_Green,
|
||||
mColor.m_Blue, mColor.m_Alpha);
|
||||
colors[0] = CGAL::Color(mColor.m_Red, mColor.m_Green,
|
||||
mColor.m_Blue, mColor.m_Alpha);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -201,15 +217,17 @@ bool extract_point_clouds (NMR::PLib3MFModelMeshObject *pMeshObject,
|
|||
PointRange& points,
|
||||
PolygonRange&,
|
||||
ColorRange& colors,
|
||||
std::string& name) {
|
||||
std::string& name)
|
||||
{
|
||||
typedef typename PointRange::value_type Point_3;
|
||||
|
||||
HRESULT hResult;
|
||||
DWORD nNeededChars;
|
||||
std::vector<char> pBuffer;
|
||||
|
||||
// Retrieve Mesh Name Length
|
||||
hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, NULL, 0, &nNeededChars);
|
||||
if (hResult != LIB3MF_OK)
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr<<"Error during name extraction.";
|
||||
points.resize(0);
|
||||
|
|
@ -217,7 +235,8 @@ bool extract_point_clouds (NMR::PLib3MFModelMeshObject *pMeshObject,
|
|||
}
|
||||
|
||||
// Retrieve Mesh Name
|
||||
if (nNeededChars > 0) {
|
||||
if(nNeededChars > 0)
|
||||
{
|
||||
pBuffer.resize(nNeededChars + 1);
|
||||
hResult = NMR::lib3mf_object_getnameutf8(pMeshObject, &pBuffer[0], nNeededChars + 1, NULL);
|
||||
pBuffer[nNeededChars] = 0;
|
||||
|
|
@ -229,14 +248,15 @@ bool extract_point_clouds (NMR::PLib3MFModelMeshObject *pMeshObject,
|
|||
}
|
||||
name = std::string(&pBuffer[0]);
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
points.resize(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
NMR::PLib3MFPropertyHandler * pPropertyHandler;
|
||||
hResult = NMR::lib3mf_meshobject_createpropertyhandler(pMeshObject, &pPropertyHandler);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK) {
|
||||
DWORD nErrorMessage;
|
||||
LPCSTR pszErrorMessage;
|
||||
std::cerr << "could not create property handler: " << std::hex << hResult << std::endl;
|
||||
|
|
@ -276,32 +296,34 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
|
|||
PointRange&,
|
||||
PolygonRange&,
|
||||
ColorRange&,
|
||||
std::string&)> func
|
||||
)
|
||||
std::string&)> func)
|
||||
{
|
||||
DWORD nInterfaceVersionMajor, nInterfaceVersionMinor, nInterfaceVersionMicro, nbVertices, nbPolygons;
|
||||
HRESULT hResult;
|
||||
NMR::PLib3MFModel * pModel;
|
||||
NMR::PLib3MFModelReader * pReader;
|
||||
|
||||
// Extract Extension of filename
|
||||
std::string sReaderName("3mf");
|
||||
|
||||
hResult = NMR::lib3mf_getinterfaceversion(&nInterfaceVersionMajor, &nInterfaceVersionMinor, &nInterfaceVersionMicro);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr << "could not get 3MF Library version: " << std::hex << hResult << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create Model Instance
|
||||
hResult = NMR::lib3mf_createmodel(&pModel);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK) {
|
||||
std::cerr << "could not create model: " << std::hex << hResult << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create Model Reader
|
||||
hResult = NMR::lib3mf_model_queryreader(pModel, sReaderName.c_str(), &pReader);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr << "could not create model reader: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_release(pModel);
|
||||
return -1;
|
||||
|
|
@ -309,7 +331,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
|
|||
|
||||
// Import Model from File
|
||||
hResult = NMR::lib3mf_reader_readfromfileutf8(pReader, file_name.c_str());
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr << "could not parse file: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_release(pReader);
|
||||
NMR::lib3mf_release(pModel);
|
||||
|
|
@ -325,13 +348,16 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
|
|||
NMR::PLib3MFModelResourceIterator * pResourceIterator;
|
||||
|
||||
hResult = NMR::lib3mf_model_getobjects(pModel, &pResourceIterator);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr << "could not get object: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_release(pModel);
|
||||
return -1;
|
||||
}
|
||||
|
||||
hResult = NMR::lib3mf_resourceiterator_movenext(pResourceIterator, &pbHasNext);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr << "could not get next object: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_release(pResourceIterator);
|
||||
NMR::lib3mf_release(pModel);
|
||||
|
|
@ -350,7 +376,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
|
|||
|
||||
// get current resource
|
||||
hResult = NMR::lib3mf_resourceiterator_getcurrent(pResourceIterator, &pResource);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr << "could not get resource: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_release(pResourceIterator);
|
||||
NMR::lib3mf_release(pModel);
|
||||
|
|
@ -359,68 +386,79 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
|
|||
|
||||
// get resource ID
|
||||
hResult = NMR::lib3mf_resource_getresourceid(pResource, &ResourceID);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr << "could not get resource id: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_release(pResource);
|
||||
NMR::lib3mf_release(pResourceIterator);
|
||||
NMR::lib3mf_release(pModel);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Query mesh interface
|
||||
BOOL bIsMeshObject;
|
||||
hResult = NMR::lib3mf_object_ismeshobject(pResource, &bIsMeshObject);
|
||||
if (hResult == LIB3MF_OK)
|
||||
if(hResult == LIB3MF_OK)
|
||||
{
|
||||
if(bIsMeshObject) {
|
||||
if(bIsMeshObject)
|
||||
{
|
||||
//skip it. Only get it through the components and buildItems.
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
BOOL bIsComponentsObject;
|
||||
hResult = NMR::lib3mf_object_iscomponentsobject(pResource, &bIsComponentsObject);
|
||||
if ((hResult == LIB3MF_OK) && (bIsComponentsObject)) {
|
||||
if((hResult == LIB3MF_OK) && (bIsComponentsObject)) {
|
||||
pComponentsObject = (NMR::PLib3MFModelComponentsObject*)pResource;
|
||||
DWORD nComponentCount;
|
||||
hResult = NMR::lib3mf_componentsobject_getcomponentcount(pComponentsObject, &nComponentCount);
|
||||
if (hResult != LIB3MF_OK)
|
||||
if(hResult != LIB3MF_OK)
|
||||
return -1;
|
||||
//for each component
|
||||
DWORD nIndex;
|
||||
for (nIndex = 0; nIndex < nComponentCount; ++nIndex) {
|
||||
for(nIndex = 0; nIndex < nComponentCount; ++nIndex) {
|
||||
NMR::PLib3MFModelResource * compResource;
|
||||
NMR::PLib3MFModelComponent * pComponent;
|
||||
hResult = NMR::lib3mf_componentsobject_getcomponent(pComponentsObject, nIndex, &pComponent);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
return -1;
|
||||
}
|
||||
|
||||
hResult = NMR::lib3mf_component_getobjectresource(pComponent, &compResource);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
NMR::lib3mf_release(pComponent);
|
||||
return -1;
|
||||
}
|
||||
|
||||
hResult = NMR::lib3mf_object_ismeshobject(compResource, &bIsMeshObject);
|
||||
if (hResult == LIB3MF_OK)
|
||||
if(hResult == LIB3MF_OK)
|
||||
{
|
||||
if(bIsMeshObject) {
|
||||
if(bIsMeshObject)
|
||||
{
|
||||
BOOL bHasTransform;
|
||||
NMR::MODELTRANSFORM Transform;
|
||||
hResult = NMR::lib3mf_component_hastransform(pComponent, &bHasTransform);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
NMR::lib3mf_release(pComponent);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (bHasTransform) {
|
||||
if(bHasTransform)
|
||||
{
|
||||
// Retrieve Transform
|
||||
hResult = NMR::lib3mf_component_gettransform(pComponent, &Transform);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
NMR::lib3mf_release(pComponent);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
Transform = transform_nmr_internal::initMatrix();
|
||||
}
|
||||
|
||||
pMeshObject = compResource;
|
||||
NMR::lib3mf_meshobject_getvertexcount(pMeshObject, &nbVertices);
|
||||
NMR::lib3mf_meshobject_gettrianglecount(pMeshObject, &nbPolygons);
|
||||
|
|
@ -429,7 +467,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
|
|||
ColorRange colors(nbPolygons);
|
||||
std::string name;
|
||||
|
||||
if(func(pMeshObject, Transform, points, triangles, colors, name)){
|
||||
if(func(pMeshObject, Transform, points, triangles, colors, name))
|
||||
{
|
||||
all_points.push_back(points);
|
||||
all_polygons.push_back(triangles);
|
||||
all_colors.push_back(colors);
|
||||
|
|
@ -442,16 +481,17 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// free instances
|
||||
NMR::lib3mf_release(pResource);
|
||||
hResult = NMR::lib3mf_resourceiterator_movenext(pResourceIterator, &pbHasNext);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr << "could not get next object: " << std::hex << hResult << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/********************************************************
|
||||
**** Iterate Build items To Find Transformed Meshes ****
|
||||
********************************************************/
|
||||
|
|
@ -459,7 +499,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
|
|||
// Iterate through all the Build items
|
||||
NMR::PLib3MFModelBuildItemIterator * pBuildItemIterator;
|
||||
hResult = NMR::lib3mf_model_getbuilditems(pModel, &pBuildItemIterator);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cout << "could not get build items: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_release(pBuildItemIterator);
|
||||
NMR::lib3mf_release(pModel);
|
||||
|
|
@ -467,20 +508,23 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
|
|||
}
|
||||
|
||||
hResult = NMR::lib3mf_builditemiterator_movenext(pBuildItemIterator, &pbHasNext);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cout << "could not get next build item: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_release(pBuildItemIterator);
|
||||
NMR::lib3mf_release(pModel);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (pbHasNext) {
|
||||
while (pbHasNext)
|
||||
{
|
||||
NMR::PLib3MFModelMeshObject * pMeshObject;
|
||||
NMR::MODELTRANSFORM Transform;
|
||||
NMR::PLib3MFModelBuildItem * pBuildItem;
|
||||
// Retrieve Build Item
|
||||
hResult = NMR::lib3mf_builditemiterator_getcurrent(pBuildItemIterator, &pBuildItem);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cout << "could not get build item: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_release(pBuildItemIterator);
|
||||
NMR::lib3mf_release(pModel);
|
||||
|
|
@ -490,7 +534,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
|
|||
// Retrieve Resource
|
||||
NMR::PLib3MFModelObjectResource * pObjectResource;
|
||||
hResult = NMR::lib3mf_builditem_getobjectresource(pBuildItem, &pObjectResource);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cout << "could not get build item resource: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_release(pBuildItem);
|
||||
NMR::lib3mf_release(pBuildItemIterator);
|
||||
|
|
@ -500,9 +545,10 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
|
|||
|
||||
BOOL bIsMeshObject;
|
||||
hResult = NMR::lib3mf_object_ismeshobject(pObjectResource, &bIsMeshObject);
|
||||
if (hResult == LIB3MF_OK)
|
||||
if(hResult == LIB3MF_OK)
|
||||
{
|
||||
if(bIsMeshObject) {
|
||||
if(bIsMeshObject)
|
||||
{
|
||||
pMeshObject = pObjectResource;
|
||||
NMR::lib3mf_meshobject_getvertexcount(pMeshObject, &nbVertices);
|
||||
NMR::lib3mf_meshobject_gettrianglecount(pMeshObject, &nbPolygons);
|
||||
|
|
@ -511,11 +557,11 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
|
|||
ColorRange colors(nbPolygons);
|
||||
std::string name;
|
||||
|
||||
|
||||
// Check Object Transform
|
||||
BOOL bHasTransform;
|
||||
hResult = NMR::lib3mf_builditem_hasobjecttransform(pBuildItem, &bHasTransform);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
NMR::lib3mf_release(pBuildItem);
|
||||
NMR::lib3mf_release(pBuildItemIterator);
|
||||
NMR::lib3mf_release(pModel);
|
||||
|
|
@ -523,10 +569,11 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (bHasTransform) {
|
||||
if(bHasTransform)
|
||||
{
|
||||
// Retrieve Transform
|
||||
hResult = NMR::lib3mf_builditem_getobjecttransform(pBuildItem, &Transform);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK) {
|
||||
NMR::lib3mf_release(pBuildItem);
|
||||
NMR::lib3mf_release(pBuildItemIterator);
|
||||
NMR::lib3mf_release(pModel);
|
||||
|
|
@ -534,7 +581,8 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
Transform = transform_nmr_internal::initMatrix();
|
||||
}
|
||||
|
||||
|
|
@ -546,6 +594,7 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Release Object Resource ID
|
||||
NMR::lib3mf_release(pObjectResource);
|
||||
// Release Build Item
|
||||
|
|
@ -553,11 +602,13 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
|
|||
|
||||
// Move to next Item
|
||||
hResult = NMR::lib3mf_builditemiterator_movenext(pBuildItemIterator, &pbHasNext);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr << "could not get next build item: " << std::hex << hResult << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Release Build Item Iterator
|
||||
NMR::lib3mf_release(pBuildItemIterator);
|
||||
return all_points.size();
|
||||
|
|
@ -592,57 +643,54 @@ int read_from_3mf(const std::string& file_name, PointRanges& all_points,
|
|||
*/
|
||||
template<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
|
||||
)
|
||||
PolygonRanges& all_polygons, ColorRanges& all_colors,
|
||||
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>
|
||||
(file_name, all_points, all_polygons, all_colors, names,
|
||||
extract_polylines<PointRange, PolygonRange, ColorRange>);
|
||||
std::vector<ColorRange>, PointRange, PolygonRange, ColorRange>
|
||||
(file_name, all_points, all_polygons, all_colors, names,
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
||||
namespace CGAL{
|
||||
namespace tmf_internal{
|
||||
#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,78 +89,76 @@ bool export_model_to_file(const std::string& file_name,
|
|||
HRESULT hResult;
|
||||
DWORD nErrorMessage;
|
||||
LPCSTR pszErrorMessage;
|
||||
|
||||
// Output mesh as 3MF
|
||||
// Create Model Writer for 3MF
|
||||
NMR::PLib3MFModelWriter * p3MFWriter;
|
||||
hResult = NMR::lib3mf_model_querywriter(pModel, "3mf", &p3MFWriter);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
std::cerr << "could not create model reader: "
|
||||
<< std::hex << hResult << std::endl;
|
||||
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr << "could not create model reader: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_getlasterror(pModel, &nErrorMessage, &pszErrorMessage);
|
||||
std::cerr << "error #" << std::hex << nErrorMessage
|
||||
<< ": " << pszErrorMessage << std::endl;
|
||||
std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
|
||||
NMR::lib3mf_release(pModel);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Export Model into File
|
||||
hResult = NMR::lib3mf_writer_writetofileutf8(p3MFWriter, file_name.c_str());
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK) {
|
||||
std::cerr << "could not write file: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_getlasterror(p3MFWriter, &nErrorMessage, &pszErrorMessage);
|
||||
std::cerr << "error #" << std::hex << nErrorMessage << ": "
|
||||
<< pszErrorMessage << std::endl;
|
||||
std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
|
||||
NMR::lib3mf_release(pModel);
|
||||
NMR::lib3mf_release(p3MFWriter);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Release Model Writer
|
||||
NMR::lib3mf_release(p3MFWriter);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename PointRange, typename PolygonRange, typename ColorRange>
|
||||
bool write_mesh_to_model( const PointRange& points,
|
||||
const PolygonRange& polygons,
|
||||
const ColorRange& colors,
|
||||
const std::string& name,
|
||||
NMR::PLib3MFModelMeshObject** pMeshObject,
|
||||
NMR::PLib3MFModel * pModel
|
||||
)
|
||||
bool write_mesh_to_model(const PointRange& points,
|
||||
const PolygonRange& polygons,
|
||||
const ColorRange& colors,
|
||||
const std::string& name,
|
||||
NMR::PLib3MFModelMeshObject** pMeshObject,
|
||||
NMR::PLib3MFModel * pModel)
|
||||
{
|
||||
DWORD nErrorMessage;
|
||||
LPCSTR pszErrorMessage;
|
||||
HRESULT hResult;
|
||||
|
||||
// Create mesh structure
|
||||
std::vector<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)
|
||||
{
|
||||
|
||||
for(const auto& point : points)
|
||||
pVertices.push_back(tmf_internal::fnCreateVertex(point.x(), point.y(), point.z()));
|
||||
}
|
||||
|
||||
for( auto triangle : polygons)
|
||||
{
|
||||
|
||||
for(const auto& triangle : polygons)
|
||||
pTriangles.push_back(tmf_internal::fnCreateTriangle(triangle[0], triangle[1], triangle[2]));
|
||||
}
|
||||
|
||||
|
||||
hResult = NMR::lib3mf_meshobject_setgeometry(*pMeshObject, pVertices.data(),
|
||||
pVertices.size(), pTriangles.data(),
|
||||
pTriangles.size());
|
||||
if (hResult != LIB3MF_OK) {
|
||||
std::cerr << "could not set mesh geometry: "
|
||||
<< std::hex << hResult << std::endl;
|
||||
pVertices.size(), pTriangles.data(),
|
||||
pTriangles.size());
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr << "could not set mesh geometry: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
|
||||
std::cerr << "error #" << std::hex << nErrorMessage
|
||||
<< ": " << pszErrorMessage << std::endl;
|
||||
|
|
@ -162,16 +166,18 @@ bool write_mesh_to_model( const PointRange& points,
|
|||
NMR::lib3mf_release(pModel);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create color entries
|
||||
NMR::PLib3MFPropertyHandler * pPropertyHandler;
|
||||
hResult = NMR::lib3mf_meshobject_createpropertyhandler(*pMeshObject, &pPropertyHandler);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
std::cerr << "could not create property handler: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
|
||||
std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
|
||||
NMR::lib3mf_release(*pMeshObject);
|
||||
NMR::lib3mf_release(pModel);
|
||||
return false;
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr << "could not create property handler: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
|
||||
std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
|
||||
NMR::lib3mf_release(*pMeshObject);
|
||||
NMR::lib3mf_release(pModel);
|
||||
return false;
|
||||
}
|
||||
|
||||
// define colors
|
||||
|
|
@ -188,7 +194,8 @@ bool write_mesh_to_model( const PointRange& points,
|
|||
// make sure to define a default property
|
||||
NMR::PLib3MFDefaultPropertyHandler * pDefaultPropertyHandler;
|
||||
hResult = NMR::lib3mf_object_createdefaultpropertyhandler(*pMeshObject, &pDefaultPropertyHandler);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr<< "could not create default property handler: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
|
||||
std::cerr<< "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
|
||||
|
|
@ -196,16 +203,17 @@ bool write_mesh_to_model( const PointRange& points,
|
|||
NMR::lib3mf_release(pModel);
|
||||
return false;
|
||||
}
|
||||
|
||||
NMR::MODELMESHCOLOR_SRGB default_color = tmf_internal::fnCreateColor(0,0,0,0);
|
||||
NMR::lib3mf_defaultpropertyhandler_setcolor(pDefaultPropertyHandler,
|
||||
&default_color);
|
||||
NMR::lib3mf_defaultpropertyhandler_setcolor(pDefaultPropertyHandler, &default_color);
|
||||
|
||||
// release default property handler
|
||||
NMR::lib3mf_release(pDefaultPropertyHandler);
|
||||
|
||||
// Set name
|
||||
hResult = NMR::lib3mf_object_setnameutf8(*pMeshObject, name.c_str());
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr << "could not set object name: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
|
||||
std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
|
||||
|
|
@ -224,41 +232,41 @@ bool write_points(const PointRange& points,
|
|||
const Color& color,
|
||||
const std::string& name,
|
||||
NMR::PLib3MFModelMeshObject** pMeshObject,
|
||||
NMR::PLib3MFModel * pModel
|
||||
)
|
||||
NMR::PLib3MFModel * pModel)
|
||||
{
|
||||
DWORD nErrorMessage;
|
||||
LPCSTR pszErrorMessage;
|
||||
HRESULT hResult;
|
||||
|
||||
// Create mesh structure
|
||||
std::vector<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;
|
||||
pVertices.size(), &dummy_triangle, 1);
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr << "could not set mesh geometry: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
|
||||
std::cerr << "error #" << std::hex << nErrorMessage
|
||||
<< ": " << pszErrorMessage << std::endl;
|
||||
std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
|
||||
NMR::lib3mf_release(*pMeshObject);
|
||||
NMR::lib3mf_release(pModel);
|
||||
return false;
|
||||
|
|
@ -267,27 +275,29 @@ bool write_points(const PointRange& points,
|
|||
// Create color entries
|
||||
NMR::PLib3MFPropertyHandler * pPropertyHandler;
|
||||
hResult = NMR::lib3mf_meshobject_createpropertyhandler(*pMeshObject, &pPropertyHandler);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
std::cerr << "could not create property handler: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
|
||||
std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
|
||||
NMR::lib3mf_release(*pMeshObject);
|
||||
NMR::lib3mf_release(pModel);
|
||||
return false;
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr << "could not create property handler: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
|
||||
std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
|
||||
NMR::lib3mf_release(*pMeshObject);
|
||||
NMR::lib3mf_release(pModel);
|
||||
return false;
|
||||
}
|
||||
|
||||
// define colors
|
||||
NMR::MODELMESHCOLOR_SRGB sColor = tmf_internal::fnCreateColor (color.red(),
|
||||
color.green(),
|
||||
color.blue(),
|
||||
color.alpha());
|
||||
// One-colored Triangles
|
||||
NMR::lib3mf_propertyhandler_setsinglecolor(pPropertyHandler, 0, &sColor);
|
||||
NMR::MODELMESHCOLOR_SRGB sColor = tmf_internal::fnCreateColor (color.red(),
|
||||
color.green(),
|
||||
color.blue(),
|
||||
color.alpha());
|
||||
// One-colored Triangles
|
||||
NMR::lib3mf_propertyhandler_setsinglecolor(pPropertyHandler, 0, &sColor);
|
||||
|
||||
// make sure to define a default property
|
||||
NMR::PLib3MFDefaultPropertyHandler * pDefaultPropertyHandler;
|
||||
hResult = NMR::lib3mf_object_createdefaultpropertyhandler(*pMeshObject, &pDefaultPropertyHandler);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr<< "could not create default property handler: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
|
||||
std::cerr<< "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
|
||||
|
|
@ -295,6 +305,7 @@ bool write_points(const PointRange& points,
|
|||
NMR::lib3mf_release(pModel);
|
||||
return false;
|
||||
}
|
||||
|
||||
NMR::MODELMESHCOLOR_SRGB default_color = tmf_internal::fnCreateColor(0,0,0,0);
|
||||
NMR::lib3mf_defaultpropertyhandler_setcolor(pDefaultPropertyHandler,
|
||||
&default_color);
|
||||
|
|
@ -304,7 +315,8 @@ bool write_points(const PointRange& points,
|
|||
|
||||
// Set name
|
||||
hResult = NMR::lib3mf_object_setnameutf8(*pMeshObject, name.c_str());
|
||||
if (hResult != LIB3MF_OK) {
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr << "could not set object name: " << std::hex << hResult << std::endl;
|
||||
NMR::lib3mf_getlasterror(*pMeshObject, &nErrorMessage, &pszErrorMessage);
|
||||
std::cerr << "error #" << std::hex << nErrorMessage << ": " << pszErrorMessage << std::endl;
|
||||
|
|
@ -312,6 +324,7 @@ bool write_points(const PointRange& points,
|
|||
NMR::lib3mf_release(pModel);
|
||||
return false;
|
||||
}
|
||||
|
||||
return add_build_item(pModel, *pMeshObject);
|
||||
}
|
||||
|
||||
|
|
@ -320,8 +333,7 @@ bool write_point_cloud_to_model(const PointRange& points,
|
|||
const Color& color,
|
||||
const std::string& name,
|
||||
NMR::PLib3MFModelMeshObject** pMeshObject,
|
||||
NMR::PLib3MFModel * pModel
|
||||
)
|
||||
NMR::PLib3MFModel * pModel)
|
||||
{
|
||||
std::string pc_name = name;
|
||||
pc_name.append("_cgal_pc");
|
||||
|
|
@ -333,8 +345,7 @@ bool write_polyline_to_model(const PointRange& points,
|
|||
const Color& color,
|
||||
const std::string& name,
|
||||
NMR::PLib3MFModelMeshObject** pMeshObject,
|
||||
NMR::PLib3MFModel * pModel
|
||||
)
|
||||
NMR::PLib3MFModel * pModel)
|
||||
{
|
||||
std::string pc_name = name;
|
||||
pc_name.append("_cgal_pl");
|
||||
|
|
@ -362,33 +373,36 @@ bool write_polyline_to_model(const PointRange& points,
|
|||
*/
|
||||
template<typename PointRanges, typename PolygonRanges>
|
||||
bool write_triangle_soups_to_3mf(const std::string& file_name,
|
||||
const PointRanges& all_points,
|
||||
const PolygonRanges& all_polygons,
|
||||
const std::vector<std::string>& names)
|
||||
const PointRanges& all_points,
|
||||
const PolygonRanges& all_polygons,
|
||||
const std::vector<std::string>& names)
|
||||
{
|
||||
HRESULT hResult;
|
||||
|
||||
// Create Model Instance
|
||||
// Create Model Instance
|
||||
NMR::PLib3MFModel * pModel;
|
||||
hResult = NMR::lib3mf_createmodel(&pModel);
|
||||
if (hResult != LIB3MF_OK) {
|
||||
HRESULT hResult = NMR::lib3mf_createmodel(&pModel);
|
||||
if(hResult != LIB3MF_OK)
|
||||
{
|
||||
std::cerr << "could not create model: " << std::hex << hResult << std::endl;
|
||||
return false;
|
||||
}
|
||||
for(std::size_t id = 0; id < all_points.size(); ++id)
|
||||
|
||||
for(std::size_t id = 0; id < all_points.size(); ++id)
|
||||
{
|
||||
NMR::PLib3MFModelMeshObject* pMeshObject;
|
||||
std::string name;
|
||||
if(names.size() > id
|
||||
&& ! names[id].empty())
|
||||
if(names.size() > id && ! names[id].empty())
|
||||
{
|
||||
name=names[id];
|
||||
}
|
||||
else
|
||||
{
|
||||
name = std::string("");
|
||||
}
|
||||
|
||||
std::vector<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);
|
||||
}
|
||||
|
||||
|
|
@ -412,46 +426,53 @@ bool write_triangle_meshes_to_3mf(const std::string& file_name,
|
|||
const TriangleMeshRange& tms,
|
||||
const std::vector<std::string>& names)
|
||||
{
|
||||
typedef typename TriangleMeshRange::value_type Mesh;
|
||||
typedef typename TriangleMeshRange::value_type Mesh;
|
||||
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 std::vector<std::size_t> Polygon;
|
||||
typedef std::vector<Polygon> PolygonRange;
|
||||
typedef boost::graph_traits<Mesh>::vertex_descriptor vertex_descriptor;
|
||||
typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor;
|
||||
|
||||
typedef std::vector<Point_3> PointRange;
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,57 +1,70 @@
|
|||
// Copyright (c) 1997
|
||||
// Copyright (c) 1997
|
||||
// Utrecht University (The Netherlands),
|
||||
// ETH Zurich (Switzerland),
|
||||
// INRIA Sophia-Antipolis (France),
|
||||
// Max-Planck-Institute Saarbruecken (Germany),
|
||||
// and Tel-Aviv University (Israel). All rights reserved.
|
||||
// and Tel-Aviv University (Israel). All rights reserved.
|
||||
//
|
||||
// This file is part of CGAL (www.cgal.org);
|
||||
//
|
||||
// $URL$
|
||||
// $Id$
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
|
||||
//
|
||||
//
|
||||
//
|
||||
// Author(s) : Lutz Kettner <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 {
|
||||
std::ostream* m_out;
|
||||
std::size_t m_facets;
|
||||
class File_writer_wavefront
|
||||
{
|
||||
std::ostream* m_out;
|
||||
std::size_t m_facets;
|
||||
|
||||
public:
|
||||
std::ostream& out() const { return *m_out; }
|
||||
void write_header( std::ostream& out,
|
||||
std::size_t vertices,
|
||||
std::size_t halfedges,
|
||||
std::size_t facets);
|
||||
void write_footer() const {
|
||||
out() << "\n# End of Wavefront obj format #" << std::endl;
|
||||
}
|
||||
void write_vertex( const double& x, const double& y, const double& z) {
|
||||
out() << "v " << x << ' ' << y << ' ' << z << '\n';
|
||||
}
|
||||
void write_facet_header() {
|
||||
out() << "\n# " << m_facets << " facets\n";
|
||||
out() << "# ------------------------------------------\n\n";
|
||||
}
|
||||
void write_facet_begin( std::size_t) { out() << "f "; }
|
||||
void write_facet_vertex_index( std::size_t idx) { out() << ' ' << idx+1; }
|
||||
void write_facet_end() { out() << '\n'; }
|
||||
std::ostream& out() const { return *m_out; }
|
||||
void write_header(std::ostream& out,
|
||||
std::size_t vertices,
|
||||
std::size_t halfedges,
|
||||
std::size_t facets)
|
||||
{
|
||||
m_out = &o;
|
||||
m_facets = facets;
|
||||
|
||||
// Print header.
|
||||
out() << "# file written from a CGAL tool in Wavefront obj format\n";
|
||||
out() << "# " << vertices << " vertices\n";
|
||||
out() << "# " << halfedges << " halfedges\n";
|
||||
out() << "# " << facets << " facets\n\n";
|
||||
|
||||
out() << "\n# " << vertices << " vertices\n";
|
||||
out() << "# ------------------------------------------\n\n";
|
||||
}
|
||||
|
||||
void write_footer() const { out() << "\n# End of Wavefront obj format #" << std::endl; }
|
||||
|
||||
void write_vertex(const double& x, const double& y, const double& z) {
|
||||
out() << "v " << x << ' ' << y << ' ' << z << '\n';
|
||||
}
|
||||
|
||||
void write_facet_header()
|
||||
{
|
||||
out() << "\n# " << m_facets << " facets\n";
|
||||
out() << "# ------------------------------------------\n\n";
|
||||
}
|
||||
void write_facet_begin(std::size_t) { out() << "f "; }
|
||||
void write_facet_vertex_index(std::size_t idx) { out() << ' ' << idx+1; }
|
||||
void write_facet_end() { out() << '\n'; }
|
||||
};
|
||||
|
||||
} //namespace CGAL
|
||||
} // namespace CGAL
|
||||
|
||||
#ifdef CGAL_HEADER_ONLY
|
||||
#include <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
|
||||
|
|
|
|||
|
|
@ -16,34 +16,37 @@
|
|||
#include <vector>
|
||||
#include <limits>
|
||||
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
//Points_3 a RandomAccessContainer of Point_3,
|
||||
//Faces a RandomAccessContainer of RandomAccessContainer of std::size_t
|
||||
// Points_3 a RandomAccessContainer of Point_3,
|
||||
// Faces a RandomAccessContainer of RandomAccessContainer of std::size_t
|
||||
template <class Points_3, class Faces>
|
||||
bool
|
||||
read_OBJ( std::istream& input,
|
||||
Points_3 &points,
|
||||
Faces &faces)
|
||||
bool read_OBJ(std::istream& input,
|
||||
Points_3 &points,
|
||||
Faces &faces)
|
||||
{
|
||||
typedef typename Points_3::value_type Point_3;
|
||||
typedef typename Points_3::value_type Point_3;
|
||||
|
||||
int mini(1),
|
||||
maxi(-INT_MAX);
|
||||
Point_3 p;
|
||||
std::string line;
|
||||
while(getline(input, line)) {
|
||||
if(line[0] == 'v' && line[1] == ' ') {
|
||||
|
||||
while(getline(input, line))
|
||||
{
|
||||
if(line[0] == 'v' && line[1] == ' ')
|
||||
{
|
||||
std::istringstream iss(line.substr(1));
|
||||
iss >> p;
|
||||
if(!iss)
|
||||
return false;
|
||||
points.push_back(p);
|
||||
}
|
||||
else if(line[0] == 'f') {
|
||||
else if(line[0] == 'f')
|
||||
{
|
||||
std::istringstream iss(line.substr(1));
|
||||
int i;
|
||||
faces.push_back( std::vector<std::size_t>() );
|
||||
faces.push_back(std::vector<std::size_t>());
|
||||
while(iss >> i)
|
||||
{
|
||||
if(i < 1)
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,17 +24,17 @@
|
|||
namespace CGAL {
|
||||
|
||||
template <class Point_3, class Polygon_3>
|
||||
bool
|
||||
read_OFF( std::istream& in,
|
||||
std::vector< Point_3 >& points,
|
||||
std::vector< Polygon_3 >& polygons,
|
||||
bool /* verbose */ = false)
|
||||
bool read_OFF(std::istream& in,
|
||||
std::vector< Point_3 >& points,
|
||||
std::vector< Polygon_3 >& polygons,
|
||||
bool /* verbose */ = false)
|
||||
{
|
||||
CGAL::File_scanner_OFF scanner(in);
|
||||
|
||||
points.resize(scanner.size_of_vertices());
|
||||
polygons.resize(scanner.size_of_facets());
|
||||
for (std::size_t i = 0; i < scanner.size_of_vertices(); ++i) {
|
||||
for(std::size_t i = 0; i < scanner.size_of_vertices(); ++i)
|
||||
{
|
||||
double x, y, z, w;
|
||||
scanner.scan_vertex( x, y, z, w);
|
||||
CGAL_assertion(w!=0);
|
||||
|
|
@ -45,19 +45,20 @@ read_OFF( std::istream& in,
|
|||
if(!in)
|
||||
return false;
|
||||
|
||||
for (std::size_t i = 0; i < scanner.size_of_facets(); ++i) {
|
||||
for(std::size_t i = 0; i < scanner.size_of_facets(); ++i)
|
||||
{
|
||||
std::size_t no;
|
||||
|
||||
scanner.scan_facet( no, i);
|
||||
IO::internal::resize(polygons[i], no);
|
||||
for(std::size_t j = 0; j < no; ++j) {
|
||||
for(std::size_t j = 0; j < no; ++j)
|
||||
{
|
||||
std::size_t id;
|
||||
scanner.scan_facet_vertex_index(id, i);
|
||||
if(id < scanner.size_of_vertices()) {
|
||||
if(id < scanner.size_of_vertices())
|
||||
polygons[i][j] = id;
|
||||
} else {
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -65,13 +66,12 @@ read_OFF( std::istream& in,
|
|||
}
|
||||
|
||||
template <class Point_3, class Polygon_3, class Color_rgb >
|
||||
bool
|
||||
read_OFF( std::istream& in,
|
||||
std::vector< Point_3 >& points,
|
||||
std::vector< Polygon_3 >& polygons,
|
||||
std::vector<Color_rgb>& fcolors,
|
||||
std::vector<Color_rgb>& vcolors,
|
||||
bool /* verbose */ = false)
|
||||
bool read_OFF(std::istream& in,
|
||||
std::vector< Point_3 >& points,
|
||||
std::vector< Polygon_3 >& polygons,
|
||||
std::vector<Color_rgb>& fcolors,
|
||||
std::vector<Color_rgb>& vcolors,
|
||||
bool /* verbose */ = false)
|
||||
{
|
||||
CGAL::File_scanner_OFF scanner(in);
|
||||
|
||||
|
|
@ -81,16 +81,20 @@ read_OFF( std::istream& in,
|
|||
if(scanner.has_colors())
|
||||
vcolors.resize(scanner.size_of_vertices());
|
||||
|
||||
for (std::size_t i = 0; i < scanner.size_of_vertices(); ++i) {
|
||||
for(std::size_t i = 0; i < scanner.size_of_vertices(); ++i)
|
||||
{
|
||||
double x, y, z, w;
|
||||
scanner.scan_vertex( x, y, z, w);
|
||||
CGAL_assertion(w!=0);
|
||||
IO::internal::fill_point( x/w, y/w, z/w, points[i] );
|
||||
if(scanner.has_colors()) {
|
||||
if(scanner.has_colors())
|
||||
{
|
||||
unsigned char r=0, g=0, b=0;
|
||||
scanner.scan_color( r, g, b);
|
||||
vcolors[i] = Color_rgb(r,g,b);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
scanner.skip_to_next_vertex(i);
|
||||
}
|
||||
|
||||
|
|
@ -99,7 +103,7 @@ read_OFF( std::istream& in,
|
|||
}
|
||||
|
||||
bool has_fcolors = false;
|
||||
for (std::size_t i = 0; i < scanner.size_of_facets(); ++i)
|
||||
for(std::size_t i = 0; i < scanner.size_of_facets(); ++i)
|
||||
{
|
||||
std::size_t no;
|
||||
scanner.scan_facet( no, i);
|
||||
|
|
@ -108,30 +112,33 @@ read_OFF( std::istream& in,
|
|||
return false;
|
||||
|
||||
IO::internal::resize(polygons[i], no);
|
||||
for(std::size_t j = 0; j < no; ++j) {
|
||||
for(std::size_t j = 0; j < no; ++j)
|
||||
{
|
||||
std::size_t id;
|
||||
scanner.scan_facet_vertex_index(id, i);
|
||||
if(id < scanner.size_of_vertices()) {
|
||||
if(id < scanner.size_of_vertices())
|
||||
polygons[i][j] = id;
|
||||
} else {
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(i==0)
|
||||
if(i == 0)
|
||||
{
|
||||
std::string col;
|
||||
std::getline(in, col);
|
||||
std::istringstream iss(col);
|
||||
char ci =' ';
|
||||
|
||||
if(iss >> ci) {
|
||||
if(iss >> ci)
|
||||
{
|
||||
has_fcolors = true;
|
||||
fcolors.resize(scanner.size_of_facets());
|
||||
std::istringstream iss2(col);
|
||||
fcolors[i] = scanner.get_color_from_line(iss2);
|
||||
}
|
||||
} else if(has_fcolors) {
|
||||
}
|
||||
else if(has_fcolors)
|
||||
{
|
||||
unsigned char r=0, g=0, b=0;
|
||||
scanner.scan_color(r,g,b);
|
||||
fcolors[i] = Color_rgb(r,g,b);
|
||||
|
|
@ -142,37 +149,33 @@ read_OFF( std::istream& in,
|
|||
}
|
||||
|
||||
template <class Point_3, class Polygon_3>
|
||||
bool
|
||||
write_OFF(std::ostream& out,
|
||||
std::vector< Point_3 >& points,
|
||||
std::vector< Polygon_3 >& polygons)
|
||||
bool write_OFF(std::ostream& out,
|
||||
std::vector< Point_3 >& points,
|
||||
std::vector< Polygon_3 >& polygons)
|
||||
{
|
||||
CGAL::File_writer_OFF writer;
|
||||
writer.write_header(out,
|
||||
points.size(),
|
||||
0,
|
||||
polygons.size());
|
||||
for(std::size_t i = 0, end = points.size();
|
||||
i < end; ++i)
|
||||
writer.write_header(out, points.size(), 0, polygons.size());
|
||||
|
||||
for(std::size_t i = 0, end = points.size(); i < end; ++i)
|
||||
{
|
||||
const Point_3& p = points[i];
|
||||
writer.write_vertex( p.x(), p.y(), p.z() );
|
||||
}
|
||||
|
||||
writer.write_facet_header();
|
||||
for(std::size_t i = 0, end = polygons.size();
|
||||
i < end; ++i)
|
||||
for(std::size_t i=0, end=polygons.size(); i<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
|
||||
|
|
|
|||
|
|
@ -18,36 +18,62 @@
|
|||
#define CGAL_IO_FILE_WRITER_INVENTOR_H 1
|
||||
|
||||
#include <CGAL/basic.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <cstddef>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
class CGAL_EXPORT File_writer_inventor {
|
||||
std::ostream* m_out;
|
||||
std::size_t m_facets;
|
||||
class CGAL_EXPORT File_writer_inventor
|
||||
{
|
||||
std::ostream* m_out;
|
||||
std::size_t m_facets;
|
||||
|
||||
public:
|
||||
File_writer_inventor() {}
|
||||
std::ostream& out() const { return *m_out; }
|
||||
void write_header( std::ostream& o,
|
||||
std::size_t vertices,
|
||||
std::size_t halfedges,
|
||||
std::size_t facets);
|
||||
void write_footer() const;
|
||||
void write_vertex( const double& x, const double& y, const double& z) {
|
||||
out() << " " << x << ' ' << y << ' ' << z << ',' <<'\n';
|
||||
}
|
||||
void write_facet_header() const;
|
||||
void write_facet_begin( std::size_t) { out() << " "; }
|
||||
void write_facet_vertex_index( std::size_t idx) { out() << idx << ',';}
|
||||
void write_facet_end() { out() << "-1,\n"; }
|
||||
File_writer_inventor() {}
|
||||
std::ostream& out() const { return *m_out; }
|
||||
|
||||
void write_header(std::ostream& o,
|
||||
std::size_t vertices,
|
||||
std::size_t halfedges,
|
||||
std::size_t facets)
|
||||
{
|
||||
m_out = &o;
|
||||
m_facets = facets;
|
||||
|
||||
out() << "# " << vertices << " vertices\n";
|
||||
out() << "# " << halfedges << " halfedges\n";
|
||||
out() << "# " << facets << " facets\n\n";
|
||||
out() << "Separator {\n"
|
||||
" Coordinate3 {\n"
|
||||
" point [" << std::endl;
|
||||
}
|
||||
|
||||
void write_footer() const
|
||||
{
|
||||
out() << " ] #coordIndex\n"
|
||||
" } #IndexedFaceSet\n"
|
||||
"} #Separator" << std::endl;
|
||||
}
|
||||
|
||||
void write_vertex( const double& x, const double& y, const double& z) {
|
||||
out() << " " << x << ' ' << y << ' ' << z << ',' <<'\n';
|
||||
}
|
||||
|
||||
void write_facet_header() const
|
||||
{
|
||||
out() << " ] #point\n"
|
||||
" } #Coordinate3\n"
|
||||
" # " << m_facets << " facets\n"
|
||||
" IndexedFaceSet {\n"
|
||||
" coordIndex [\n";
|
||||
}
|
||||
|
||||
void write_facet_begin( std::size_t) { out() << " "; }
|
||||
void write_facet_vertex_index( std::size_t idx) { out() << idx << ','; }
|
||||
void write_facet_end() { out() << "-1,\n"; }
|
||||
};
|
||||
|
||||
} //namespace CGAL
|
||||
|
||||
#ifdef CGAL_HEADER_ONLY
|
||||
#include <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
|
||||
|
|
|
|||
|
|
@ -13,327 +13,324 @@
|
|||
|
||||
#include <CGAL/IO/PLY.h>
|
||||
|
||||
namespace CGAL{
|
||||
namespace CGAL {
|
||||
namespace internal {
|
||||
|
||||
namespace internal
|
||||
{
|
||||
template <typename Integer, class Polygon_3, class Color_rgb>
|
||||
bool
|
||||
read_PLY_faces (std::istream& in,
|
||||
template <typename Integer, class Polygon_3, class Color_rgb>
|
||||
bool read_PLY_faces(std::istream& in,
|
||||
internal::PLY::PLY_element& element,
|
||||
std::vector< Polygon_3 >& polygons,
|
||||
std::vector< Color_rgb >& fcolors,
|
||||
const char* vertex_indices_tag)
|
||||
{
|
||||
bool has_colors = false;
|
||||
std::string rtag = "r", gtag = "g", btag = "b";
|
||||
|
||||
if((element.has_property<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)
|
||||
{
|
||||
for(std::size_t k = 0; k < element.number_of_properties(); ++ k)
|
||||
{
|
||||
internal::PLY::PLY_read_number* property = element.property(k);
|
||||
property->get(in);
|
||||
|
||||
if(in.fail())
|
||||
return false;
|
||||
}
|
||||
|
||||
std::tuple<std::vector<Integer>, boost::uint8_t, boost::uint8_t, boost::uint8_t> new_face;
|
||||
|
||||
if(has_colors)
|
||||
{
|
||||
PLY::process_properties(element, new_face,
|
||||
std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_face),
|
||||
PLY_property<std::vector<Integer> >(vertex_indices_tag)),
|
||||
std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_face),
|
||||
PLY_property<boost::uint8_t>(rtag.c_str())),
|
||||
std::make_pair(CGAL::make_nth_of_tuple_property_map<2>(new_face),
|
||||
PLY_property<boost::uint8_t>(gtag.c_str())),
|
||||
std::make_pair(CGAL::make_nth_of_tuple_property_map<3>(new_face),
|
||||
PLY_property<boost::uint8_t>(btag.c_str())));
|
||||
|
||||
fcolors.push_back(Color_rgb(get<1>(new_face), get<2>(new_face), get<3>(new_face)));
|
||||
}
|
||||
else
|
||||
{
|
||||
PLY::process_properties(element, new_face,
|
||||
std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_face),
|
||||
PLY_property<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)
|
||||
polygons.back()[i] = std::size_t(get<0>(new_face)[i]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
template <class Point_3, class Polygon_3>
|
||||
bool
|
||||
read_PLY(std::istream& in,
|
||||
std::vector< Point_3 >& points,
|
||||
std::vector< Polygon_3 >& polygons,
|
||||
bool /* verbose */ = false)
|
||||
{
|
||||
if(!in)
|
||||
{
|
||||
std::cerr << "Error: cannot open file" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
internal::PLY::PLY_reader reader;
|
||||
|
||||
if(!(reader.init(in)))
|
||||
{
|
||||
in.setstate(std::ios::failbit);
|
||||
return false;
|
||||
}
|
||||
|
||||
for(std::size_t i = 0; i < reader.number_of_elements(); ++ i)
|
||||
{
|
||||
internal::PLY::PLY_element& element = reader.element(i);
|
||||
|
||||
if(element.name() == "vertex" || element.name() == "vertices")
|
||||
{
|
||||
for(std::size_t j = 0; j < element.number_of_items(); ++ j)
|
||||
{
|
||||
for(std::size_t k = 0; k < element.number_of_properties(); ++ k)
|
||||
{
|
||||
internal::PLY::PLY_read_number* property = element.property(k);
|
||||
property->get(in);
|
||||
|
||||
if(in.fail())
|
||||
return false;
|
||||
}
|
||||
|
||||
Point_3 new_vertex;
|
||||
|
||||
internal::PLY::process_properties(element, new_vertex,
|
||||
make_ply_point_reader(CGAL::Identity_property_map<Point_3>()));
|
||||
|
||||
points.push_back(get<0>(new_vertex));
|
||||
}
|
||||
}
|
||||
else if(element.name() == "face" || element.name() == "faces")
|
||||
{
|
||||
std::vector<CGAL::Color> dummy;
|
||||
|
||||
if(element.has_property<std::vector<boost::int32_t> >("vertex_indices"))
|
||||
internal::read_PLY_faces<boost::int32_t>(in, element, polygons, dummy, "vertex_indices");
|
||||
else if(element.has_property<std::vector<boost::uint32_t> >("vertex_indices"))
|
||||
internal::read_PLY_faces<boost::uint32_t>(in, element, polygons, dummy, "vertex_indices");
|
||||
else if(element.has_property<std::vector<boost::int32_t> >("vertex_index"))
|
||||
internal::read_PLY_faces<boost::int32_t>(in, element, polygons, dummy, "vertex_index");
|
||||
else if(element.has_property<std::vector<boost::uint32_t> >("vertex_index"))
|
||||
internal::read_PLY_faces<boost::uint32_t>(in, element, polygons, dummy, "vertex_index");
|
||||
else
|
||||
{
|
||||
std::cerr << "Error: can't find vertex indices in PLY input" << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else // Read other elements and ignore
|
||||
{
|
||||
for(std::size_t j = 0; j < element.number_of_items(); ++ j)
|
||||
{
|
||||
for(std::size_t k = 0; k < element.number_of_properties(); ++ k)
|
||||
{
|
||||
internal::PLY::PLY_read_number* property = element.property(k);
|
||||
property->get(in);
|
||||
|
||||
if(in.fail())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !in.bad();
|
||||
}
|
||||
|
||||
template <class Point_3, class Polygon_3, class Color_rgb>
|
||||
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,
|
||||
std::vector<Color_rgb>& fcolors,
|
||||
std::vector<Color_rgb>& vcolors,
|
||||
std::vector<std::pair<float, float> >& huvs,
|
||||
bool /* verbose */ = false)
|
||||
{
|
||||
if(!in)
|
||||
{
|
||||
std::cerr << "Error: cannot open file" << std::endl;
|
||||
return false;
|
||||
}
|
||||
internal::PLY::PLY_reader reader;
|
||||
|
||||
if(!(reader.init(in)))
|
||||
{
|
||||
in.setstate(std::ios::failbit);
|
||||
return false;
|
||||
}
|
||||
for(std::size_t i = 0; i < reader.number_of_elements(); ++ i)
|
||||
{
|
||||
internal::PLY::PLY_element& element = reader.element(i);
|
||||
|
||||
if(element.name() == "vertex" || element.name() == "vertices")
|
||||
{
|
||||
bool has_colors = false;
|
||||
std::string rtag = "r", gtag = "g", btag = "b";
|
||||
if ((element.has_property<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")))
|
||||
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"))
|
||||
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)
|
||||
|
||||
for(std::size_t j = 0; j < element.number_of_items(); ++ j)
|
||||
{
|
||||
for (std::size_t k = 0; k < element.number_of_properties(); ++ k)
|
||||
for(std::size_t k = 0; k < element.number_of_properties(); ++ k)
|
||||
{
|
||||
internal::PLY::PLY_read_number* property = element.property(k);
|
||||
property->get (in);
|
||||
property->get(in);
|
||||
|
||||
if (in.fail())
|
||||
if(in.fail())
|
||||
return false;
|
||||
}
|
||||
|
||||
std::tuple<std::vector<Integer>, boost::uint8_t, boost::uint8_t, boost::uint8_t> new_face;
|
||||
std::tuple<Point_3, boost::uint8_t, boost::uint8_t, boost::uint8_t> new_vertex;
|
||||
|
||||
if (has_colors)
|
||||
if(has_colors)
|
||||
{
|
||||
PLY::process_properties (element, new_face,
|
||||
std::make_pair (CGAL::make_nth_of_tuple_property_map<0>(new_face),
|
||||
PLY_property<std::vector<Integer> >(vertex_indices_tag)),
|
||||
std::make_pair (CGAL::make_nth_of_tuple_property_map<1>(new_face),
|
||||
PLY_property<boost::uint8_t>(rtag.c_str())),
|
||||
std::make_pair (CGAL::make_nth_of_tuple_property_map<2>(new_face),
|
||||
PLY_property<boost::uint8_t>(gtag.c_str())),
|
||||
std::make_pair (CGAL::make_nth_of_tuple_property_map<3>(new_face),
|
||||
PLY_property<boost::uint8_t>(btag.c_str())));
|
||||
internal::PLY::process_properties(element, new_vertex,
|
||||
make_ply_point_reader(CGAL::make_nth_of_tuple_property_map<0>(new_vertex)),
|
||||
std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_vertex),
|
||||
PLY_property<boost::uint8_t>(rtag.c_str())),
|
||||
std::make_pair(CGAL::make_nth_of_tuple_property_map<2>(new_vertex),
|
||||
PLY_property<boost::uint8_t>(gtag.c_str())),
|
||||
std::make_pair(CGAL::make_nth_of_tuple_property_map<3>(new_vertex),
|
||||
PLY_property<boost::uint8_t>(btag.c_str())));
|
||||
|
||||
fcolors.push_back (Color_rgb (get<1>(new_face), get<2>(new_face), get<3>(new_face)));
|
||||
vcolors.push_back(Color_rgb(get<1>(new_vertex), get<2>(new_vertex), get<3>(new_vertex)));
|
||||
}
|
||||
else
|
||||
PLY::process_properties (element, new_face,
|
||||
std::make_pair (CGAL::make_nth_of_tuple_property_map<0>(new_face),
|
||||
PLY_property<std::vector<Integer> >(vertex_indices_tag)));
|
||||
internal::PLY::process_properties(element, new_vertex,
|
||||
make_ply_point_reader(CGAL::make_nth_of_tuple_property_map<0>(new_vertex)));
|
||||
|
||||
polygons.push_back (Polygon_3(get<0>(new_face).size()));
|
||||
for (std::size_t i = 0; i < get<0>(new_face).size(); ++ i)
|
||||
polygons.back()[i] = std::size_t(get<0>(new_face)[i]);
|
||||
points.push_back(get<0>(new_vertex));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
template <class Point_3, class Polygon_3>
|
||||
bool
|
||||
read_PLY( std::istream& in,
|
||||
std::vector< Point_3 >& points,
|
||||
std::vector< Polygon_3 >& polygons,
|
||||
bool /* verbose */ = false)
|
||||
{
|
||||
if(!in)
|
||||
else if(element.name() == "face" || element.name() == "faces")
|
||||
{
|
||||
std::cerr << "Error: cannot open file" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
internal::PLY::PLY_reader reader;
|
||||
|
||||
if (!(reader.init (in)))
|
||||
{
|
||||
in.setstate(std::ios::failbit);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < reader.number_of_elements(); ++ i)
|
||||
{
|
||||
internal::PLY::PLY_element& element = reader.element(i);
|
||||
|
||||
if (element.name() == "vertex" || element.name() == "vertices")
|
||||
if(element.has_property<std::vector<boost::int32_t> >("vertex_indices"))
|
||||
internal::read_PLY_faces<boost::int32_t>(in, element, polygons, fcolors, "vertex_indices");
|
||||
else if(element.has_property<std::vector<boost::uint32_t> >("vertex_indices"))
|
||||
internal::read_PLY_faces<boost::uint32_t>(in, element, polygons, fcolors, "vertex_indices");
|
||||
else if(element.has_property<std::vector<boost::int32_t> >("vertex_index"))
|
||||
internal::read_PLY_faces<boost::int32_t>(in, element, polygons, fcolors, "vertex_index");
|
||||
else if(element.has_property<std::vector<boost::uint32_t> >("vertex_index"))
|
||||
internal::read_PLY_faces<boost::uint32_t>(in, element, polygons, fcolors, "vertex_index");
|
||||
else
|
||||
{
|
||||
for (std::size_t j = 0; j < element.number_of_items(); ++ j)
|
||||
std::cerr << "Error: can't find vertex indices in PLY input" << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(element.name() == "halfedge" )
|
||||
{
|
||||
bool has_uv = false;
|
||||
std::string stag = "source", ttag = "target", utag = "u", vtag = "v";
|
||||
if( element.has_property<unsigned int>("source") &&
|
||||
element.has_property<unsigned int>("target") &&
|
||||
element.has_property<float>("u") &&
|
||||
element.has_property<float>("v"))
|
||||
{
|
||||
has_uv = true;
|
||||
}
|
||||
cpp11::tuple<unsigned int, unsigned int, float, float, float> new_hedge;
|
||||
for(std::size_t j = 0; j < element.number_of_items(); ++ j)
|
||||
{
|
||||
for(std::size_t k = 0; k < element.number_of_properties(); ++ k)
|
||||
{
|
||||
for (std::size_t k = 0; k < element.number_of_properties(); ++ k)
|
||||
{
|
||||
internal::PLY::PLY_read_number* property = element.property(k);
|
||||
property->get (in);
|
||||
internal::PLY::PLY_read_number* property = element.property(k);
|
||||
property->get(in);
|
||||
|
||||
if (in.fail())
|
||||
return false;
|
||||
}
|
||||
|
||||
Point_3 new_vertex;
|
||||
|
||||
internal::PLY::process_properties (element, new_vertex,
|
||||
make_ply_point_reader (CGAL::Identity_property_map<Point_3>()));
|
||||
|
||||
points.push_back (get<0>(new_vertex));
|
||||
if(in.eof())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (element.name() == "face" || element.name() == "faces")
|
||||
{
|
||||
std::vector<CGAL::Color> dummy;
|
||||
|
||||
if (element.has_property<std::vector<boost::int32_t> > ("vertex_indices"))
|
||||
internal::read_PLY_faces<boost::int32_t> (in, element, polygons, dummy, "vertex_indices");
|
||||
else if (element.has_property<std::vector<boost::uint32_t> > ("vertex_indices"))
|
||||
internal::read_PLY_faces<boost::uint32_t> (in, element, polygons, dummy, "vertex_indices");
|
||||
else if (element.has_property<std::vector<boost::int32_t> > ("vertex_index"))
|
||||
internal::read_PLY_faces<boost::int32_t> (in, element, polygons, dummy, "vertex_index");
|
||||
else if (element.has_property<std::vector<boost::uint32_t> > ("vertex_index"))
|
||||
internal::read_PLY_faces<boost::uint32_t> (in, element, polygons, dummy, "vertex_index");
|
||||
if(has_uv)
|
||||
{
|
||||
internal::PLY::process_properties(element, new_hedge,
|
||||
std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_hedge),
|
||||
PLY_property<unsigned int>(stag.c_str())),
|
||||
std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_hedge),
|
||||
PLY_property<unsigned int>(ttag.c_str())),
|
||||
std::make_pair(CGAL::make_nth_of_tuple_property_map<2>(new_hedge),
|
||||
PLY_property<float>(utag.c_str())),
|
||||
std::make_pair(CGAL::make_nth_of_tuple_property_map<3>(new_hedge),
|
||||
PLY_property<float>(vtag.c_str())));
|
||||
hedges.push_back(std::make_pair(get<0>(new_hedge), get<1>(new_hedge)));
|
||||
huvs.push_back(std::make_pair(get<2>(new_hedge), get<3>(new_hedge)));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Error: can't find vertex indices in PLY input" << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else // Read other elements and ignore
|
||||
{
|
||||
for (std::size_t j = 0; j < element.number_of_items(); ++ j)
|
||||
{
|
||||
for (std::size_t k = 0; k < element.number_of_properties(); ++ k)
|
||||
{
|
||||
internal::PLY::PLY_read_number* property = element.property(k);
|
||||
property->get (in);
|
||||
|
||||
if (in.fail())
|
||||
return false;
|
||||
}
|
||||
internal::PLY::process_properties(element, new_hedge,
|
||||
std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_hedge),
|
||||
PLY_property<unsigned int>(stag.c_str())),
|
||||
std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_hedge),
|
||||
PLY_property<unsigned int>(ttag.c_str()))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !in.bad();
|
||||
}
|
||||
|
||||
template <class Point_3, class Polygon_3, class Color_rgb>
|
||||
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,
|
||||
std::vector<Color_rgb>& fcolors,
|
||||
std::vector<Color_rgb>& vcolors,
|
||||
std::vector<std::pair<float, float> >& huvs,
|
||||
bool /* verbose */ = false)
|
||||
{
|
||||
if(!in)
|
||||
else // Read other elements and ignore
|
||||
{
|
||||
std::cerr << "Error: cannot open file" << std::endl;
|
||||
return false;
|
||||
}
|
||||
internal::PLY::PLY_reader reader;
|
||||
|
||||
if (!(reader.init (in)))
|
||||
{
|
||||
in.setstate(std::ios::failbit);
|
||||
return false;
|
||||
}
|
||||
for (std::size_t i = 0; i < reader.number_of_elements(); ++ i)
|
||||
{
|
||||
internal::PLY::PLY_element& element = reader.element(i);
|
||||
|
||||
if (element.name() == "vertex" || element.name() == "vertices")
|
||||
for(std::size_t j = 0; j < element.number_of_items(); ++ j)
|
||||
{
|
||||
bool has_colors = false;
|
||||
std::string rtag = "r", gtag = "g", btag = "b";
|
||||
if ((element.has_property<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")))
|
||||
for(std::size_t k = 0; k < element.number_of_properties(); ++ k)
|
||||
{
|
||||
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)
|
||||
{
|
||||
for (std::size_t k = 0; k < element.number_of_properties(); ++ k)
|
||||
{
|
||||
internal::PLY::PLY_read_number* property = element.property(k);
|
||||
property->get (in);
|
||||
|
||||
if (in.fail())
|
||||
return false;
|
||||
}
|
||||
|
||||
std::tuple<Point_3, boost::uint8_t, boost::uint8_t, boost::uint8_t> new_vertex;
|
||||
|
||||
if (has_colors)
|
||||
{
|
||||
internal::PLY::process_properties (element, new_vertex,
|
||||
make_ply_point_reader (CGAL::make_nth_of_tuple_property_map<0>(new_vertex)),
|
||||
std::make_pair (CGAL::make_nth_of_tuple_property_map<1>(new_vertex),
|
||||
PLY_property<boost::uint8_t>(rtag.c_str())),
|
||||
std::make_pair (CGAL::make_nth_of_tuple_property_map<2>(new_vertex),
|
||||
PLY_property<boost::uint8_t>(gtag.c_str())),
|
||||
std::make_pair (CGAL::make_nth_of_tuple_property_map<3>(new_vertex),
|
||||
PLY_property<boost::uint8_t>(btag.c_str())));
|
||||
|
||||
vcolors.push_back (Color_rgb (get<1>(new_vertex), get<2>(new_vertex), get<3>(new_vertex)));
|
||||
}
|
||||
else
|
||||
internal::PLY::process_properties (element, new_vertex,
|
||||
make_ply_point_reader (CGAL::make_nth_of_tuple_property_map<0>(new_vertex)));
|
||||
|
||||
points.push_back (get<0>(new_vertex));
|
||||
}
|
||||
}
|
||||
else if (element.name() == "face" || element.name() == "faces")
|
||||
{
|
||||
if (element.has_property<std::vector<boost::int32_t> > ("vertex_indices"))
|
||||
internal::read_PLY_faces<boost::int32_t> (in, element, polygons, fcolors, "vertex_indices");
|
||||
else if (element.has_property<std::vector<boost::uint32_t> > ("vertex_indices"))
|
||||
internal::read_PLY_faces<boost::uint32_t> (in, element, polygons, fcolors, "vertex_indices");
|
||||
else if (element.has_property<std::vector<boost::int32_t> > ("vertex_index"))
|
||||
internal::read_PLY_faces<boost::int32_t> (in, element, polygons, fcolors, "vertex_index");
|
||||
else if (element.has_property<std::vector<boost::uint32_t> > ("vertex_index"))
|
||||
internal::read_PLY_faces<boost::uint32_t> (in, element, polygons, fcolors, "vertex_index");
|
||||
else
|
||||
{
|
||||
std::cerr << "Error: can't find vertex indices in PLY input" << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(element.name() == "halfedge" )
|
||||
{
|
||||
bool has_uv = false;
|
||||
std::string stag = "source", ttag = "target", utag = "u", vtag = "v";
|
||||
if ( element.has_property<unsigned int>("source") &&
|
||||
element.has_property<unsigned int>("target") &&
|
||||
element.has_property<float>("u") &&
|
||||
element.has_property<float>("v"))
|
||||
{
|
||||
has_uv = true;
|
||||
}
|
||||
cpp11::tuple<unsigned int, unsigned int, float, float, float> new_hedge;
|
||||
for (std::size_t j = 0; j < element.number_of_items(); ++ j)
|
||||
{
|
||||
for (std::size_t k = 0; k < element.number_of_properties(); ++ k)
|
||||
{
|
||||
internal::PLY::PLY_read_number* property = element.property(k);
|
||||
property->get (in);
|
||||
|
||||
if (in.eof())
|
||||
return false;
|
||||
}
|
||||
|
||||
if (has_uv)
|
||||
{
|
||||
internal::PLY::process_properties (element, new_hedge,
|
||||
std::make_pair (CGAL::make_nth_of_tuple_property_map<0>(new_hedge),
|
||||
PLY_property<unsigned int>(stag.c_str())),
|
||||
std::make_pair (CGAL::make_nth_of_tuple_property_map<1>(new_hedge),
|
||||
PLY_property<unsigned int>(ttag.c_str())),
|
||||
std::make_pair (CGAL::make_nth_of_tuple_property_map<2>(new_hedge),
|
||||
PLY_property<float>(utag.c_str())),
|
||||
std::make_pair (CGAL::make_nth_of_tuple_property_map<3>(new_hedge),
|
||||
PLY_property<float>(vtag.c_str())));
|
||||
hedges.push_back (std::make_pair(get<0>(new_hedge), get<1>(new_hedge)));
|
||||
huvs.push_back (std::make_pair(get<2>(new_hedge), get<3>(new_hedge)));
|
||||
}
|
||||
else
|
||||
internal::PLY::process_properties (element, new_hedge,
|
||||
std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_hedge),
|
||||
PLY_property<unsigned int>(stag.c_str())),
|
||||
std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_hedge),
|
||||
PLY_property<unsigned int>(ttag.c_str()))
|
||||
);
|
||||
}
|
||||
}
|
||||
else // Read other elements and ignore
|
||||
{
|
||||
for (std::size_t j = 0; j < element.number_of_items(); ++ j)
|
||||
{
|
||||
for (std::size_t k = 0; k < element.number_of_properties(); ++ k)
|
||||
{
|
||||
internal::PLY::PLY_read_number* property = element.property(k);
|
||||
property->get (in);
|
||||
if (in.fail())
|
||||
return false;
|
||||
}
|
||||
internal::PLY::PLY_read_number* property = element.property(k);
|
||||
property->get(in);
|
||||
if(in.fail())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return !in.bad();
|
||||
}
|
||||
return !in.bad();
|
||||
}
|
||||
|
||||
template <class Point_3, class Polygon_3, class Color_rgb>
|
||||
bool read_PLY(std::istream& in,
|
||||
std::vector< Point_3 >& points,
|
||||
std::vector< Polygon_3 >& polygons,
|
||||
std::vector<Color_rgb>& fcolors,
|
||||
std::vector<Color_rgb>& vcolors,
|
||||
bool /* verbose */ = false)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
template <class Point_3, class Polygon_3, class Color_rgb>
|
||||
bool
|
||||
read_PLY( std::istream& in,
|
||||
std::vector< Point_3 >& points,
|
||||
std::vector< Polygon_3 >& polygons,
|
||||
std::vector<Color_rgb>& fcolors,
|
||||
std::vector<Color_rgb>& vcolors,
|
||||
bool /* verbose */ = false)
|
||||
{
|
||||
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);
|
||||
}
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_IO_PLY_PLY_READER_H
|
||||
|
|
|
|||
|
|
@ -13,148 +13,144 @@
|
|||
|
||||
#include <CGAL/IO/PLY.h>
|
||||
|
||||
namespace CGAL{
|
||||
namespace CGAL {
|
||||
|
||||
template <class Point_3, class Polygon_3>
|
||||
bool
|
||||
write_PLY(std::ostream& out,
|
||||
const std::vector< Point_3 >& points,
|
||||
const std::vector< Polygon_3 >& polygons,
|
||||
bool /* verbose */ = false)
|
||||
template <class Point_3, class Polygon_3>
|
||||
bool write_PLY(std::ostream& out,
|
||||
const std::vector< Point_3 >& points,
|
||||
const std::vector< Polygon_3 >& polygons,
|
||||
bool /* verbose */ = false)
|
||||
{
|
||||
if(!out)
|
||||
{
|
||||
|
||||
if(!out)
|
||||
{
|
||||
std::cerr << "Error: cannot open file" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write header
|
||||
out << "ply" << std::endl
|
||||
<< ((get_mode(out) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl
|
||||
<< "comment Generated by the CGAL library" << std::endl
|
||||
<< "element vertex " << points.size() << std::endl;
|
||||
|
||||
internal::PLY::output_property_header (out,
|
||||
make_ply_point_writer (CGAL::Identity_property_map<Point_3>()));
|
||||
|
||||
out << "element face " << polygons.size() << std::endl;
|
||||
|
||||
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;
|
||||
|
||||
for (std::size_t i = 0; i < points.size(); ++ i)
|
||||
internal::PLY::output_properties (out, points.begin() + i,
|
||||
make_ply_point_writer (CGAL::Identity_property_map<Point_3>()));
|
||||
|
||||
for (std::size_t i = 0; i < polygons.size(); ++ i)
|
||||
internal::PLY::output_properties (out, polygons.begin() + i,
|
||||
std::make_pair (CGAL::Identity_property_map<Polygon_3>(),
|
||||
PLY_property<std::vector<int> >("vertex_indices")));
|
||||
|
||||
return out.good();
|
||||
std::cerr << "Error: cannot open file" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class SurfaceMesh>
|
||||
bool
|
||||
write_PLY(std::ostream& out,
|
||||
const SurfaceMesh& mesh,
|
||||
bool /* verbose */ = false)
|
||||
// Write header
|
||||
out << "ply" << std::endl
|
||||
<< ((get_mode(out) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl
|
||||
<< "comment Generated by the CGAL library" << std::endl
|
||||
<< "element vertex " << points.size() << std::endl;
|
||||
|
||||
internal::PLY::output_property_header(out, make_ply_point_writer (CGAL::Identity_property_map<Point_3>()));
|
||||
|
||||
out << "element face " << polygons.size() << std::endl;
|
||||
|
||||
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;
|
||||
|
||||
for (std::size_t i = 0; i < points.size(); ++ i)
|
||||
internal::PLY::output_properties(out, points.begin() + i,
|
||||
make_ply_point_writer (CGAL::Identity_property_map<Point_3>()));
|
||||
|
||||
for (std::size_t i = 0; i < polygons.size(); ++ i)
|
||||
internal::PLY::output_properties(out, polygons.begin() + i,
|
||||
std::make_pair(CGAL::Identity_property_map<Polygon_3>(),
|
||||
PLY_property<std::vector<int> >("vertex_indices")));
|
||||
|
||||
return out.good();
|
||||
}
|
||||
|
||||
template <class SurfaceMesh>
|
||||
bool write_PLY(std::ostream& out,
|
||||
const SurfaceMesh& mesh,
|
||||
bool /* verbose */ = false)
|
||||
{
|
||||
typedef typename boost::graph_traits<SurfaceMesh>::face_descriptor face_descriptor;
|
||||
typedef typename boost::graph_traits<SurfaceMesh>::halfedge_descriptor halfedge_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 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)
|
||||
{
|
||||
typedef typename boost::graph_traits<SurfaceMesh>::face_descriptor face_descriptor;
|
||||
typedef typename boost::graph_traits<SurfaceMesh>::halfedge_descriptor halfedge_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 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;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write header
|
||||
out << "ply" << std::endl
|
||||
<< ((get_mode(out) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl
|
||||
<< "comment Generated by the CGAL library" << std::endl
|
||||
<< "element vertex " << num_vertices(mesh) << std::endl;
|
||||
|
||||
internal::PLY::output_property_header (out,
|
||||
make_ply_point_writer (CGAL::Identity_property_map<Point_3>()));
|
||||
|
||||
out << "element face " << num_faces(mesh) << std::endl;
|
||||
|
||||
internal::PLY::output_property_header (out,
|
||||
std::make_pair (CGAL::Identity_property_map<std::vector<std::size_t> >(),
|
||||
PLY_property<std::vector<int> >("vertex_indices")));
|
||||
|
||||
if(has_texture)
|
||||
{
|
||||
out << "element halfedge " << num_halfedges(mesh) << std::endl;
|
||||
|
||||
internal::PLY::output_property_header (out,
|
||||
std::make_pair (CGAL::Identity_property_map<std::size_t >(),
|
||||
PLY_property<unsigned int >("source")));
|
||||
|
||||
internal::PLY::output_property_header (out,
|
||||
std::make_pair (CGAL::Identity_property_map<std::size_t >(),
|
||||
PLY_property<unsigned int >("target")));
|
||||
internal::PLY::output_property_header (out,
|
||||
std::make_tuple (h_uv,
|
||||
PLY_property<float>("u"),
|
||||
PLY_property<float>("v")));
|
||||
}
|
||||
out << "end_header" << std::endl;
|
||||
|
||||
for(vertex_descriptor vd : vertices(mesh))
|
||||
{
|
||||
Point_3 p = get(get(CGAL::vertex_point, mesh), vd);
|
||||
internal::PLY::output_properties (out, &p,
|
||||
make_ply_point_writer (CGAL::Identity_property_map<Point_3>()));
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::size_t> polygon;
|
||||
for(face_descriptor fd : faces(mesh))
|
||||
{
|
||||
polygon.clear();
|
||||
for(halfedge_descriptor hd : halfedges_around_face(halfedge(fd, mesh), mesh))
|
||||
polygon.push_back (get(get(boost::vertex_index, mesh), target(hd,mesh)));
|
||||
|
||||
internal::PLY::output_properties (out, &polygon,
|
||||
std::make_pair (CGAL::Identity_property_map<std::vector<std::size_t> >(),
|
||||
PLY_property<std::vector<int> >("vertex_indices")));
|
||||
}
|
||||
|
||||
if(has_texture)
|
||||
{
|
||||
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),
|
||||
h_uv[hd].first,
|
||||
h_uv[hd].second);
|
||||
|
||||
internal::PLY::output_properties (out, &t,
|
||||
std::make_pair (Nth_of_tuple_property_map<0,Super_tuple>(),
|
||||
PLY_property<unsigned int >("source")),
|
||||
std::make_pair (Nth_of_tuple_property_map<1,Super_tuple>(),
|
||||
PLY_property<unsigned int >("target")),
|
||||
std::make_pair (Nth_of_tuple_property_map<2,Super_tuple>(),
|
||||
PLY_property<float>("u")),
|
||||
std::make_pair (Nth_of_tuple_property_map<3,Super_tuple>(),
|
||||
PLY_property<float>("v")));
|
||||
}
|
||||
}
|
||||
return out.good();
|
||||
std::cerr << "Error: cannot open file" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write header
|
||||
out << "ply" << std::endl
|
||||
<< ((get_mode(out) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl
|
||||
<< "comment Generated by the CGAL library" << std::endl
|
||||
<< "element vertex " << num_vertices(mesh) << std::endl;
|
||||
|
||||
internal::PLY::output_property_header(out,
|
||||
make_ply_point_writer (CGAL::Identity_property_map<Point_3>()));
|
||||
|
||||
out << "element face " << num_faces(mesh) << std::endl;
|
||||
|
||||
internal::PLY::output_property_header(out,
|
||||
std::make_pair(CGAL::Identity_property_map<std::vector<std::size_t> >(),
|
||||
PLY_property<std::vector<int> >("vertex_indices")));
|
||||
|
||||
if(has_texture)
|
||||
{
|
||||
out << "element halfedge " << num_halfedges(mesh) << std::endl;
|
||||
|
||||
internal::PLY::output_property_header(out,
|
||||
std::make_pair(CGAL::Identity_property_map<std::size_t >(),
|
||||
PLY_property<unsigned int >("source")));
|
||||
|
||||
internal::PLY::output_property_header(out,
|
||||
std::make_pair(CGAL::Identity_property_map<std::size_t >(),
|
||||
PLY_property<unsigned int >("target")));
|
||||
internal::PLY::output_property_header(out,
|
||||
std::make_tuple (h_uv,
|
||||
PLY_property<float>("u"),
|
||||
PLY_property<float>("v")));
|
||||
}
|
||||
out << "end_header" << std::endl;
|
||||
|
||||
for(vertex_descriptor vd : vertices(mesh))
|
||||
{
|
||||
Point_3 p = get(get(CGAL::vertex_point, mesh), vd);
|
||||
internal::PLY::output_properties(out, &p,
|
||||
make_ply_point_writer (CGAL::Identity_property_map<Point_3>()));
|
||||
}
|
||||
|
||||
std::vector<std::size_t> polygon;
|
||||
for(face_descriptor fd : faces(mesh))
|
||||
{
|
||||
polygon.clear();
|
||||
for(halfedge_descriptor hd : halfedges_around_face(halfedge(fd, mesh), mesh))
|
||||
polygon.push_back(get(get(boost::vertex_index, mesh), target(hd,mesh)));
|
||||
|
||||
internal::PLY::output_properties(out, &polygon,
|
||||
std::make_pair(CGAL::Identity_property_map<std::vector<std::size_t> >(),
|
||||
PLY_property<std::vector<int> >("vertex_indices")));
|
||||
}
|
||||
|
||||
if(has_texture)
|
||||
{
|
||||
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),
|
||||
h_uv[hd].first,
|
||||
h_uv[hd].second);
|
||||
|
||||
internal::PLY::output_properties(out, &t,
|
||||
std::make_pair(Nth_of_tuple_property_map<0,Super_tuple>(),
|
||||
PLY_property<unsigned int >("source")),
|
||||
std::make_pair(Nth_of_tuple_property_map<1,Super_tuple>(),
|
||||
PLY_property<unsigned int >("target")),
|
||||
std::make_pair(Nth_of_tuple_property_map<2,Super_tuple>(),
|
||||
PLY_property<float>("u")),
|
||||
std::make_pair(Nth_of_tuple_property_map<3,Super_tuple>(),
|
||||
PLY_property<float>("v")));
|
||||
}
|
||||
}
|
||||
|
||||
return out.good();
|
||||
}
|
||||
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_IO_PLY_PLY_WRITER_H
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
#include <CGAL/IO/io.h>
|
||||
#include <CGAL/IO/reader_helpers.h>
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#include <cctype>
|
||||
#include <iostream>
|
||||
|
|
@ -40,7 +40,7 @@ bool read_ASCII_facet(std::istream& input,
|
|||
|
||||
std::string s;
|
||||
std::string vertex("vertex"),
|
||||
endfacet("endfacet");
|
||||
endfacet("endfacet");
|
||||
|
||||
int count = 0;
|
||||
double x,y,z;
|
||||
|
|
@ -133,9 +133,8 @@ bool parse_ASCII_STL(std::istream& input,
|
|||
if(s == solid)
|
||||
{
|
||||
if(in_solid)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
in_solid = true;
|
||||
}
|
||||
if(s == facet)
|
||||
|
|
@ -149,12 +148,14 @@ bool parse_ASCII_STL(std::istream& input,
|
|||
}
|
||||
}
|
||||
|
||||
if(in_solid){
|
||||
if(in_solid)
|
||||
{
|
||||
if(verbose)
|
||||
std::cerr << "Error while parsing ASCII file" << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -331,9 +332,7 @@ bool read_STL(std::istream& input,
|
|||
return true; // empty file
|
||||
|
||||
// If the first word is not 'solid', the file must be binary
|
||||
if(s != "solid"
|
||||
|| (word[5] !='\n'
|
||||
&& word[5] != ' '))
|
||||
if(s != "solid" || (word[5] !='\n' && word[5] != ' '))
|
||||
{
|
||||
if(parse_binary_STL(input, points, facets, verbose))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,21 +16,17 @@
|
|||
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
|
||||
|
||||
namespace CGAL{
|
||||
namespace CGAL {
|
||||
|
||||
template <class PointRange, class TriangleRange>
|
||||
std::ostream&
|
||||
write_STL(const PointRange& points,
|
||||
const TriangleRange& facets,
|
||||
std::ostream& out)
|
||||
std::ostream& write_STL(const PointRange& points,
|
||||
const TriangleRange& facets,
|
||||
std::ostream& out)
|
||||
{
|
||||
typedef typename PointRange::value_type Point;
|
||||
typedef typename CGAL::Kernel_traits<Point>::Kernel K;
|
||||
typedef typename K::Vector_3 Vector_3;
|
||||
|
||||
|
||||
if (get_mode(out) == IO::BINARY)
|
||||
{
|
||||
out << "FileType: Binary ";
|
||||
|
|
@ -43,14 +39,12 @@ write_STL(const PointRange& points,
|
|||
const Point& q = points[face[1]];
|
||||
const Point& r = points[face[2]];
|
||||
|
||||
Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0):
|
||||
unit_normal(p,q,r);
|
||||
Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0) : unit_normal(p,q,r);
|
||||
|
||||
const float coords[12]={
|
||||
static_cast<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()) };
|
||||
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()) };
|
||||
|
||||
for (int i=0; i<12; ++i)
|
||||
out.write(reinterpret_cast<const char *>(&coords[i]), sizeof(coords[i]));
|
||||
|
|
@ -66,8 +60,7 @@ write_STL(const PointRange& points,
|
|||
const Point& q = points[face[1]];
|
||||
const Point& r = points[face[2]];
|
||||
|
||||
Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0):
|
||||
unit_normal(p,q,r);
|
||||
Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0) : unit_normal(p,q,r);
|
||||
out << "facet normal " << n << "\nouter loop\n";
|
||||
out << "vertex " << p << "\n";
|
||||
out << "vertex " << q << "\n";
|
||||
|
|
@ -76,9 +69,10 @@ write_STL(const PointRange& points,
|
|||
}
|
||||
out << "endsolid\n";
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
} // end of namespace CGAL
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_IO_STL_STL_WRITER_H
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
// Copyright (c) 1997
|
||||
// Copyright (c) 1997
|
||||
// Utrecht University (The Netherlands),
|
||||
// ETH Zurich (Switzerland),
|
||||
// INRIA Sophia-Antipolis (France),
|
||||
// Max-Planck-Institute Saarbruecken (Germany),
|
||||
// and Tel-Aviv University (Israel). All rights reserved.
|
||||
// and Tel-Aviv University (Israel). All rights reserved.
|
||||
//
|
||||
// This file is part of CGAL (www.cgal.org)
|
||||
//
|
||||
// $URL$
|
||||
// $Id$
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
|
||||
//
|
||||
//
|
||||
//
|
||||
// Author(s) : Lutz Kettner <kettner@mpi-sb.mpg.de>
|
||||
|
||||
|
|
@ -18,39 +18,70 @@
|
|||
#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 {
|
||||
std::ostream* m_out;
|
||||
std::size_t m_facets;
|
||||
class File_writer_VRML_2
|
||||
{
|
||||
std::ostream* m_out;
|
||||
std::size_t m_facets;
|
||||
public:
|
||||
File_writer_VRML_2() {}
|
||||
std::ostream& out() const { return *m_out; }
|
||||
void write_header( std::ostream& o,
|
||||
std::size_t vertices,
|
||||
std::size_t halfedges,
|
||||
std::size_t facets);
|
||||
void write_footer() const;
|
||||
void write_vertex( const double& x, const double& y, const double& z) {
|
||||
out() << " "
|
||||
<< x << ' ' << y << ' ' << z << ',' << '\n';
|
||||
}
|
||||
void write_facet_header() const;
|
||||
void write_facet_begin( std::size_t) {
|
||||
out() << " ";
|
||||
}
|
||||
void write_facet_vertex_index( std::size_t idx) { out() << idx << ',';}
|
||||
void write_facet_end() { out() << "-1,\n"; }
|
||||
File_writer_VRML_2() {}
|
||||
std::ostream& out() const { return *m_out; }
|
||||
void write_header( std::ostream& o,
|
||||
std::size_t vertices,
|
||||
std::size_t halfedges,
|
||||
std::size_t facets)
|
||||
{
|
||||
m_out = &o;
|
||||
m_facets = facets;
|
||||
|
||||
out() << " #-- Begin of Polyhedron_3\n";
|
||||
out() << " # " << vertices << " vertices\n";
|
||||
out() << " # " << halfedges << " halfedges\n";
|
||||
out() << " # " << facets << " facets\n";
|
||||
out() << " Group {\n"
|
||||
" children [\n"
|
||||
" Shape {\n"
|
||||
" appearance Appearance { material "
|
||||
"USE Material }\n"
|
||||
" geometry IndexedFaceSet {\n"
|
||||
" convex FALSE\n"
|
||||
" solid FALSE\n"
|
||||
" coord Coordinate {\n"
|
||||
" point [" << std::endl;
|
||||
}
|
||||
|
||||
void write_footer() const
|
||||
{
|
||||
out() << " ] #coordIndex\n"
|
||||
" } #geometry\n"
|
||||
" } #Shape\n"
|
||||
" ] #children\n"
|
||||
" } #Group" << std::endl;
|
||||
}
|
||||
|
||||
void write_vertex( const double& x, const double& y, const double& z) {
|
||||
out() << " "
|
||||
<< x << ' ' << y << ' ' << z << ',' << '\n';
|
||||
}
|
||||
void write_facet_header() const
|
||||
{
|
||||
out() << " ] #point\n"
|
||||
" } #coord Coordinate\n"
|
||||
" coordIndex [" << std::endl;
|
||||
}
|
||||
|
||||
void write_facet_begin( std::size_t) {
|
||||
out() << " ";
|
||||
}
|
||||
void write_facet_vertex_index( std::size_t idx) { out() << idx << ',';}
|
||||
void write_facet_end() { out() << "-1,\n"; }
|
||||
};
|
||||
|
||||
} //namespace CGAL
|
||||
|
||||
#ifdef CGAL_HEADER_ONLY
|
||||
#include <CGAL/IO/File_writer_VRML_2_impl.h>
|
||||
#endif // CGAL_HEADER_ONLY
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_IO_FILE_WRITER_VRML_2_H //
|
||||
// EOF //
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
// Copyright (c) 1997
|
||||
// Copyright (c) 1997
|
||||
// Utrecht University (The Netherlands),
|
||||
// ETH Zurich (Switzerland),
|
||||
// INRIA Sophia-Antipolis (France),
|
||||
// Max-Planck-Institute Saarbruecken (Germany),
|
||||
// and Tel-Aviv University (Israel). All rights reserved.
|
||||
// and Tel-Aviv University (Israel). All rights reserved.
|
||||
//
|
||||
// This file is part of CGAL (www.cgal.org);
|
||||
//
|
||||
// $URL$
|
||||
// $Id$
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
|
||||
//
|
||||
//
|
||||
// Author(s) : Andreas Fabri
|
||||
// Lutz Kettner <kettner@inf.ethz.ch>
|
||||
// Herve Bronnimann <Herve.Bronnimann@sophia.inria.fr>
|
||||
|
|
@ -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,22 +33,23 @@
|
|||
|
||||
namespace CGAL {
|
||||
|
||||
class VRML_1_ostream : public Inventor_ostream_base {
|
||||
class VRML_1_ostream : public Inventor_ostream_base
|
||||
{
|
||||
public:
|
||||
VRML_1_ostream() {}
|
||||
VRML_1_ostream(std::ostream& o) : Inventor_ostream_base(o) {
|
||||
header();
|
||||
}
|
||||
void open(std::ostream& o) {
|
||||
Inventor_ostream_base::open(o);
|
||||
header();
|
||||
}
|
||||
VRML_1_ostream() {}
|
||||
VRML_1_ostream(std::ostream& o) : Inventor_ostream_base(o) { header(); }
|
||||
void open(std::ostream& o) {
|
||||
Inventor_ostream_base::open(o);
|
||||
header();
|
||||
}
|
||||
|
||||
private:
|
||||
void header() {
|
||||
os() << "#VRML V1.0 ascii" << std::endl;
|
||||
os() << "# File written with the help of the CGAL Library"
|
||||
<< std::endl;
|
||||
}
|
||||
void header()
|
||||
{
|
||||
os() << "#VRML V1.0 ascii" << std::endl;
|
||||
os() << "# File written with the help of the CGAL Library"
|
||||
<< std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
} //namespace CGAL
|
||||
|
|
@ -86,11 +88,13 @@ operator<<(VRML_1_ostream& os,
|
|||
<< CGAL::to_double(t[3].y()) << " "
|
||||
<< CGAL::to_double(t[3].z()) << " ]"
|
||||
<< "\n } #Coordinate3" ;
|
||||
|
||||
os.os() << "\n IndexedFaceSet {"
|
||||
<< Indent << "coordIndex [ 0,1,2,-1, 1,3,2,-1,\n"
|
||||
<< Indent << " 0,2,3,-1, 0,3,1,-1 ]\n"
|
||||
<< "\n } #IndexedFaceSet"
|
||||
<< "\n } #Separator\n";
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
// Copyright (c) 1997
|
||||
// Copyright (c) 1997
|
||||
// Utrecht University (The Netherlands),
|
||||
// ETH Zurich (Switzerland),
|
||||
// INRIA Sophia-Antipolis (France),
|
||||
// Max-Planck-Institute Saarbruecken (Germany),
|
||||
// and Tel-Aviv University (Israel). All rights reserved.
|
||||
// and Tel-Aviv University (Israel). All rights reserved.
|
||||
//
|
||||
// This file is part of CGAL (www.cgal.org);
|
||||
//
|
||||
|
|
@ -24,76 +24,80 @@
|
|||
|
||||
namespace CGAL {
|
||||
|
||||
class VRML_2_ostream {
|
||||
class VRML_2_ostream
|
||||
{
|
||||
public:
|
||||
VRML_2_ostream() : m_os(0) {}
|
||||
VRML_2_ostream(std::ostream& o) : m_os(&o) { header();}
|
||||
~VRML_2_ostream() { close(); }
|
||||
void open(std::ostream& o) { m_os = &o; header(); }
|
||||
void close() {
|
||||
if ( m_os)
|
||||
footer();
|
||||
m_os = 0;
|
||||
}
|
||||
explicit operator bool () {
|
||||
return m_os && !m_os->fail();
|
||||
}
|
||||
std::ostream& os() {
|
||||
// The behaviour if m_os == 0 could be changed to return
|
||||
// cerr or a file handle to /dev/null. The latter one would
|
||||
// mimick the behaviour that one can still use a stream with
|
||||
// an invalid stream, but without producing any output.
|
||||
CGAL_assertion( m_os != 0 );
|
||||
return *m_os;
|
||||
}
|
||||
VRML_2_ostream() : m_os(0) {}
|
||||
VRML_2_ostream(std::ostream& o) : m_os(&o) { header(); }
|
||||
~VRML_2_ostream() { close(); }
|
||||
void open(std::ostream& o) { m_os = &o; header(); }
|
||||
void close()
|
||||
{
|
||||
if ( m_os)
|
||||
footer();
|
||||
m_os = 0;
|
||||
}
|
||||
|
||||
explicit operator bool () { return m_os && !m_os->fail(); }
|
||||
|
||||
std::ostream& os()
|
||||
{
|
||||
// The behaviour if m_os == 0 could be changed to return
|
||||
// cerr or a file handle to /dev/null. The latter one would
|
||||
// mimick the behaviour that one can still use a stream with
|
||||
// an invalid stream, but without producing any output.
|
||||
CGAL_assertion( m_os != 0 );
|
||||
return *m_os;
|
||||
}
|
||||
|
||||
private:
|
||||
void header() {
|
||||
os() << "#VRML V2.0 utf8\n"
|
||||
"# File written with the help of the CGAL Library\n"
|
||||
"#-- Begin of file header\n"
|
||||
"Group {\n"
|
||||
" children [\n"
|
||||
" Shape {\n"
|
||||
" appearance DEF A1 Appearance {\n"
|
||||
" material Material {\n"
|
||||
" diffuseColor .6 .5 .9\n"
|
||||
" }\n }\n"
|
||||
" appearance\n"
|
||||
" Appearance {\n"
|
||||
" material DEF Material Material {}\n"
|
||||
" }\n"
|
||||
" geometry nullptr\n"
|
||||
" }\n"
|
||||
" #-- End of file header" << std::endl;
|
||||
}
|
||||
void footer() {
|
||||
os() << " #-- Begin of file footer\n"
|
||||
" ]\n"
|
||||
"}\n"
|
||||
"#-- End of file footer" << std::endl;
|
||||
}
|
||||
std::ostream* m_os;
|
||||
void header()
|
||||
{
|
||||
os() << "#VRML V2.0 utf8\n"
|
||||
"# File written with the help of the CGAL Library\n"
|
||||
"#-- Begin of file header\n"
|
||||
"Group {\n"
|
||||
" children [\n"
|
||||
" Shape {\n"
|
||||
" appearance DEF A1 Appearance {\n"
|
||||
" material Material {\n"
|
||||
" diffuseColor .6 .5 .9\n"
|
||||
" }\n }\n"
|
||||
" appearance\n"
|
||||
" Appearance {\n"
|
||||
" material DEF Material Material {}\n"
|
||||
" }\n"
|
||||
" geometry nullptr\n"
|
||||
" }\n"
|
||||
" #-- End of file header" << std::endl;
|
||||
}
|
||||
|
||||
void footer()
|
||||
{
|
||||
os() << " #-- Begin of file footer\n"
|
||||
" ]\n"
|
||||
"}\n"
|
||||
"#-- End of file footer" << std::endl;
|
||||
}
|
||||
|
||||
std::ostream* m_os;
|
||||
};
|
||||
|
||||
inline
|
||||
VRML_2_ostream&
|
||||
operator<<(VRML_2_ostream& os,
|
||||
const char* s)
|
||||
inline VRML_2_ostream& operator<<(VRML_2_ostream& os,
|
||||
const char* s)
|
||||
{
|
||||
os.os() << s;
|
||||
return os;
|
||||
}
|
||||
|
||||
inline
|
||||
VRML_2_ostream&
|
||||
operator<<(VRML_2_ostream& os,
|
||||
const double& d)
|
||||
inline VRML_2_ostream& operator<<(VRML_2_ostream& os,
|
||||
const double& d)
|
||||
{
|
||||
os.os() << d;
|
||||
return os;
|
||||
}
|
||||
|
||||
} //namespace CGAL
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_IO_VRML_2_OSTREAM_H
|
||||
|
||||
|
|
@ -109,42 +113,43 @@ operator<<(VRML_2_ostream& os,
|
|||
const Tetrahedron_3<R > &t)
|
||||
{
|
||||
const char *Indent = " ";
|
||||
os << " Group {\n"
|
||||
" children [\n"
|
||||
" Shape {\n"
|
||||
" appearance\n"
|
||||
" Appearance {\n"
|
||||
" material USE Material\n"
|
||||
" } #Appearance\n"
|
||||
" geometry\n"
|
||||
" IndexedFaceSet {\n"
|
||||
" coord Coordinate {\n"
|
||||
" point [ \n"
|
||||
<< Indent << " "
|
||||
<< CGAL::to_double(t[0].x()) << " "
|
||||
<< CGAL::to_double(t[0].y()) << " "
|
||||
<< CGAL::to_double(t[0].z()) << " ,\n"
|
||||
<< Indent << " "
|
||||
<< CGAL::to_double(t[1].x()) << " "
|
||||
<< CGAL::to_double(t[1].y()) << " "
|
||||
<< CGAL::to_double(t[1].z()) << " ,\n"
|
||||
<< Indent << " "
|
||||
<< CGAL::to_double(t[2].x()) << " "
|
||||
<< CGAL::to_double(t[2].y()) << " "
|
||||
<< CGAL::to_double(t[2].z()) << " ,\n"
|
||||
<< Indent << " "
|
||||
<< CGAL::to_double(t[3].x()) << " "
|
||||
<< CGAL::to_double(t[3].y()) << " "
|
||||
<< CGAL::to_double(t[3].z()) <<
|
||||
"\n ]\n"
|
||||
" }\n"
|
||||
" solid FALSE\n"
|
||||
<< Indent << "coordIndex [ 0,1,2,-1, 1,3,2,-1,\n"
|
||||
<< Indent << " 0,2,3,-1, 0,3,1,-1 ]\n"
|
||||
" } #IndexedFaceSet\n"
|
||||
" } #Shape\n"
|
||||
" ] #children\n"
|
||||
" } #Group\n";
|
||||
os << " Group {\n"
|
||||
" children [\n"
|
||||
" Shape {\n"
|
||||
" appearance\n"
|
||||
" Appearance {\n"
|
||||
" material USE Material\n"
|
||||
" } #Appearance\n"
|
||||
" geometry\n"
|
||||
" IndexedFaceSet {\n"
|
||||
" coord Coordinate {\n"
|
||||
" point [ \n"
|
||||
<< Indent << " "
|
||||
<< CGAL::to_double(t[0].x()) << " "
|
||||
<< CGAL::to_double(t[0].y()) << " "
|
||||
<< CGAL::to_double(t[0].z()) << " ,\n"
|
||||
<< Indent << " "
|
||||
<< CGAL::to_double(t[1].x()) << " "
|
||||
<< CGAL::to_double(t[1].y()) << " "
|
||||
<< CGAL::to_double(t[1].z()) << " ,\n"
|
||||
<< Indent << " "
|
||||
<< CGAL::to_double(t[2].x()) << " "
|
||||
<< CGAL::to_double(t[2].y()) << " "
|
||||
<< CGAL::to_double(t[2].z()) << " ,\n"
|
||||
<< Indent << " "
|
||||
<< CGAL::to_double(t[3].x()) << " "
|
||||
<< CGAL::to_double(t[3].y()) << " "
|
||||
<< CGAL::to_double(t[3].z()) <<
|
||||
"\n ]\n"
|
||||
" }\n"
|
||||
" solid FALSE\n"
|
||||
<< Indent << "coordIndex [ 0,1,2,-1, 1,3,2,-1,\n"
|
||||
<< Indent << " 0,2,3,-1, 0,3,1,-1 ]\n"
|
||||
" } #IndexedFaceSet\n"
|
||||
" } #Shape\n"
|
||||
" ] #children\n"
|
||||
" } #Group\n";
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
|
@ -165,16 +170,15 @@ operator<<(VRML_2_ostream& os,
|
|||
const Point_3<R > &p)
|
||||
{
|
||||
const char *Indent = " ";
|
||||
os << " Group {\n"
|
||||
" children [\n"
|
||||
" Shape {\n"
|
||||
" appearance USE A1\n"
|
||||
" geometry\n"
|
||||
" PointSet {\n"
|
||||
" coord Coordinate {\n"
|
||||
" point [ ";
|
||||
os << CGAL::to_double(p.x()) << " " << CGAL::to_double(p.y())
|
||||
<< " " << CGAL::to_double(p.z()) << " ]\n";
|
||||
os << " Group {\n"
|
||||
" children [\n"
|
||||
" Shape {\n"
|
||||
" appearance USE A1\n"
|
||||
" geometry\n"
|
||||
" PointSet {\n"
|
||||
" coord Coordinate {\n"
|
||||
" point [ ";
|
||||
os << CGAL::to_double(p.x()) << " " << CGAL::to_double(p.y()) << " " << CGAL::to_double(p.z()) << " ]\n";
|
||||
os << Indent << "}\n";
|
||||
os << Indent << "} # PointSet\n";
|
||||
os << " } #Shape\n"
|
||||
|
|
@ -188,8 +192,6 @@ operator<<(VRML_2_ostream& os,
|
|||
#endif // CGAL_IO_VRML_2_POINT_3
|
||||
#endif // CGAL_POINT_3_H
|
||||
|
||||
|
||||
|
||||
#ifdef CGAL_TRIANGLE_3_H
|
||||
#ifndef CGAL_IO_VRML_2_TRIANGLE_3
|
||||
#define CGAL_IO_VRML_2_TRIANGLE_3
|
||||
|
|
@ -202,37 +204,34 @@ operator<<(VRML_2_ostream& os,
|
|||
const Triangle_3<R > &t)
|
||||
{
|
||||
const char *Indent = " ";
|
||||
os << " Group {\n"
|
||||
" children [\n"
|
||||
" Shape {\n"
|
||||
" appearance USE A1\n"
|
||||
" geometry\n"
|
||||
" IndexedLineSet {\n"
|
||||
" coord Coordinate {\n"
|
||||
" point [ \n";
|
||||
os << " Group {\n"
|
||||
" children [\n"
|
||||
" Shape {\n"
|
||||
" appearance USE A1\n"
|
||||
" geometry\n"
|
||||
" IndexedLineSet {\n"
|
||||
" coord Coordinate {\n"
|
||||
" point [ \n";
|
||||
os << Indent ;
|
||||
os << CGAL::to_double(t[0].x()) << " " << CGAL::to_double(t[0].y())
|
||||
<< " " << CGAL::to_double(t[0].z()) << ",\n";
|
||||
os << CGAL::to_double(t[0].x()) << " " << CGAL::to_double(t[0].y()) << " " << CGAL::to_double(t[0].z()) << ",\n";
|
||||
os << Indent;
|
||||
os << CGAL::to_double(t[1].x()) << " " << CGAL::to_double(t[1].y())
|
||||
<< " " << CGAL::to_double(t[1].z()) << ",\n";
|
||||
os << CGAL::to_double(t[1].x()) << " " << CGAL::to_double(t[1].y()) << " " << CGAL::to_double(t[1].z()) << ",\n";
|
||||
os << Indent;
|
||||
os << CGAL::to_double(t[2].x()) << " " << CGAL::to_double(t[2].y())
|
||||
<< " " << CGAL::to_double(t[2].z()) << " ]\n";
|
||||
os << CGAL::to_double(t[2].x()) << " " << CGAL::to_double(t[2].y()) << " " << CGAL::to_double(t[2].z()) << " ]\n";
|
||||
os << Indent << "}\n" << Indent << "coordIndex [ 0 1, 1 2, 2 0 -1 ]\n";
|
||||
os << Indent << "} # IndexedLineSet\n";
|
||||
os << " } #Shape\n"
|
||||
" ] #children\n"
|
||||
" } #Group\n";
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
} //namespace CGAL
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_IO_VRML_2_TRIANGLE_3
|
||||
#endif // CGAL_TRIANGLE_3_H
|
||||
|
||||
|
||||
#ifdef CGAL_SEGMENT_3_H
|
||||
#ifndef CGAL_IO_VRML_2_SEGMENT_3
|
||||
#define CGAL_IO_VRML_2_SEGMENT_3
|
||||
|
|
@ -245,20 +244,20 @@ operator<<(VRML_2_ostream& os,
|
|||
const Segment_3<R > &s)
|
||||
{
|
||||
const char *Indent = " ";
|
||||
os << " Group {\n"
|
||||
" children [\n"
|
||||
" Shape {\n"
|
||||
" appearance USE A1\n"
|
||||
" geometry\n"
|
||||
" IndexedLineSet {\n"
|
||||
" coord Coordinate {\n"
|
||||
" point [ \n";
|
||||
os << Indent << CGAL::to_double(s.source().x());
|
||||
os << " " << CGAL::to_double(s.source().y())
|
||||
os << " Group {\n"
|
||||
" children [\n"
|
||||
" Shape {\n"
|
||||
" appearance USE A1\n"
|
||||
" geometry\n"
|
||||
" IndexedLineSet {\n"
|
||||
" coord Coordinate {\n"
|
||||
" point [ \n";
|
||||
os << Indent << CGAL::to_double(s.source().x())
|
||||
<< " " << CGAL::to_double(s.source().y())
|
||||
<< " " << CGAL::to_double(s.source().z()) << ",\n";
|
||||
os << Indent;
|
||||
os << CGAL::to_double(s.target().x())
|
||||
<< " " << CGAL::to_double(s.target().y())
|
||||
<< " " << CGAL::to_double(s.target().y())
|
||||
<< " " << CGAL::to_double(s.target().z()) << " ]\n";
|
||||
os << Indent << "}\n" << Indent << "coordIndex [ 0 1 -1 ]\n";
|
||||
os << Indent << "} # IndexedLineSet\n";
|
||||
|
|
@ -285,23 +284,23 @@ VRML_2_ostream&
|
|||
operator<<(VRML_2_ostream& os,
|
||||
const Sphere_3<R > &s)
|
||||
{
|
||||
os << " Group {\n"
|
||||
" children [\n"
|
||||
" Transform {\n"
|
||||
" translation ";
|
||||
os << CGAL::to_double(s.center().x()) << " "
|
||||
<< CGAL::to_double(s.center().y()) << " "
|
||||
<< CGAL::to_double(s.center().z()) << "\n";
|
||||
os << " children Shape {\n"
|
||||
" appearance USE A1\n"
|
||||
" geometry\n"
|
||||
" Sphere { "
|
||||
"radius ";
|
||||
os << std::sqrt(CGAL::to_double(s.squared_radius())) <<" }\n";
|
||||
os << " } #children Shape\n"
|
||||
" } # Transform\n"
|
||||
" ] #children\n"
|
||||
" } #Group\n";
|
||||
os << " Group {\n"
|
||||
" children [\n"
|
||||
" Transform {\n"
|
||||
" translation ";
|
||||
os << CGAL::to_double(s.center().x()) << " "
|
||||
<< CGAL::to_double(s.center().y()) << " "
|
||||
<< CGAL::to_double(s.center().z()) << "\n";
|
||||
os << " children Shape {\n"
|
||||
" appearance USE A1\n"
|
||||
" geometry\n"
|
||||
" Sphere { "
|
||||
"radius ";
|
||||
os << std::sqrt(CGAL::to_double(s.squared_radius())) <<" }\n";
|
||||
os << " } #children Shape\n"
|
||||
" } # Transform\n"
|
||||
" ] #children\n"
|
||||
" } #Group\n";
|
||||
|
||||
return os;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
// Copyright (c) 2018
|
||||
// GeometryFactory( France) All rights reserved.
|
||||
// GeometryFactory (France) All rights reserved.
|
||||
//
|
||||
// This file is part of CGAL (www.cgal.org)
|
||||
//
|
||||
// $URL$
|
||||
// $Id$
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
|
||||
//
|
||||
//
|
||||
//
|
||||
// Author(s) : Stephane Tayeb
|
||||
|
||||
|
|
@ -17,15 +17,15 @@
|
|||
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
template <class FT>
|
||||
void
|
||||
write_vector(std::ostream& os,
|
||||
const std::vector<FT>& vect)
|
||||
|
||||
template <class FT>
|
||||
void write_vector(std::ostream& os,
|
||||
const std::vector<FT>& vect)
|
||||
{
|
||||
const char* buffer = reinterpret_cast<const char*>(&(vect[0]));
|
||||
std::size_t size = vect.size()*sizeof(FT);
|
||||
|
||||
|
||||
os.write(reinterpret_cast<const char *>(&size), sizeof(std::size_t)); // number of bytes encoded
|
||||
os.write(buffer, vect.size()*sizeof(FT)); // encoded data
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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,68 +30,74 @@
|
|||
#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>
|
||||
|
||||
namespace CGAL{
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
namespace CGAL {
|
||||
namespace internal {
|
||||
|
||||
template <typename K>
|
||||
void pop_back_if_equal_to_front(CGAL::Polygon_2<K>& poly)
|
||||
{
|
||||
typename CGAL::Polygon_2<K>::iterator it = poly.end();
|
||||
--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){
|
||||
pop_back_if_equal_to_front(*i);
|
||||
}
|
||||
}
|
||||
template <typename K>
|
||||
void pop_back_if_equal_to_front(CGAL::Polygon_2<K>& poly)
|
||||
{
|
||||
typename CGAL::Polygon_2<K>::iterator it = poly.end();
|
||||
--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)
|
||||
pop_back_if_equal_to_front(*i);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
template<typename Point>
|
||||
bool
|
||||
read_point_WKT( std::istream& in,
|
||||
Point& point)
|
||||
bool read_point_WKT(std::istream& in,
|
||||
Point& point)
|
||||
{
|
||||
if(!in)
|
||||
{
|
||||
std::cerr << "Error: cannot open file" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::string line;
|
||||
while(std::getline(in, line))
|
||||
{
|
||||
std::istringstream iss(line);
|
||||
std::string type;
|
||||
iss >> type;
|
||||
|
||||
if(type.substr(0, 5).compare("POINT")==0)
|
||||
|
||||
if(type.substr(0, 5).compare("POINT") == 0)
|
||||
{
|
||||
try{
|
||||
boost::geometry::read_wkt(line, point);
|
||||
} catch(...)
|
||||
try
|
||||
{
|
||||
std::cerr<<"error."<<std::endl;
|
||||
boost::geometry::read_wkt(line, point);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
std::cerr << "error." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return in.good();
|
||||
}
|
||||
|
||||
template<typename MultiPoint>
|
||||
bool
|
||||
read_multi_point_WKT( std::istream& in,
|
||||
MultiPoint& mp)
|
||||
bool read_multi_point_WKT(std::istream& in,
|
||||
MultiPoint& mp)
|
||||
{
|
||||
if(!in)
|
||||
{
|
||||
|
|
@ -111,13 +111,13 @@ read_multi_point_WKT( std::istream& in,
|
|||
std::istringstream iss(line);
|
||||
std::string type;
|
||||
iss >> type;
|
||||
|
||||
if(type.substr(0, 10).compare("MULTIPOINT")==0)
|
||||
|
||||
if(type.substr(0, 10).compare("MULTIPOINT") == 0)
|
||||
{
|
||||
try{
|
||||
boost::geometry::read_wkt(line, gc);
|
||||
} catch(...){
|
||||
std::cerr<<"error."<<std::endl;
|
||||
std::cerr << "error." << std::endl;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
|
@ -126,11 +126,9 @@ read_multi_point_WKT( std::istream& in,
|
|||
return in.good();
|
||||
}
|
||||
|
||||
|
||||
template<typename LineString>
|
||||
bool
|
||||
read_linestring_WKT( std::istream& in,
|
||||
LineString& polyline)
|
||||
bool read_linestring_WKT(std::istream& in,
|
||||
LineString& polyline)
|
||||
{
|
||||
if(!in)
|
||||
{
|
||||
|
|
@ -144,13 +142,13 @@ read_linestring_WKT( std::istream& in,
|
|||
std::istringstream iss(line);
|
||||
std::string type;
|
||||
iss >> type;
|
||||
|
||||
if(type.substr(0, 10).compare("LINESTRING")==0)
|
||||
|
||||
if(type.substr(0, 10).compare("LINESTRING") == 0)
|
||||
{
|
||||
try{
|
||||
boost::geometry::read_wkt(line, gc);
|
||||
} catch(...){
|
||||
std::cerr<<"error."<<std::endl;
|
||||
std::cerr << "error." << std::endl;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
|
@ -160,18 +158,18 @@ read_linestring_WKT( std::istream& in,
|
|||
}
|
||||
|
||||
template<typename MultiLineString>
|
||||
bool
|
||||
read_multi_linestring_WKT( std::istream& in,
|
||||
MultiLineString& mls)
|
||||
bool read_multi_linestring_WKT(std::istream& in,
|
||||
MultiLineString& mls)
|
||||
{
|
||||
if(!in)
|
||||
{
|
||||
std::cerr << "Error: cannot open file" << std::endl;
|
||||
return false;
|
||||
}
|
||||
typedef typename MultiLineString::value_type PointRange;
|
||||
|
||||
typedef typename MultiLineString::value_type PointRange;
|
||||
typedef internal::Geometry_container<PointRange, boost::geometry::linestring_tag> LineString;
|
||||
|
||||
|
||||
std::vector<LineString> pr_range;
|
||||
internal::Geometry_container<std::vector<LineString>, boost::geometry::multi_linestring_tag> gc(pr_range);
|
||||
std::string line;
|
||||
|
|
@ -180,52 +178,58 @@ read_multi_linestring_WKT( std::istream& in,
|
|||
std::istringstream iss(line);
|
||||
std::string type;
|
||||
iss >> type;
|
||||
|
||||
if(type.substr(0, 15).compare("MULTILINESTRING")==0)
|
||||
|
||||
if(type.substr(0, 15).compare("MULTILINESTRING") == 0)
|
||||
{
|
||||
try{
|
||||
try
|
||||
{
|
||||
boost::geometry::read_wkt(line, gc);
|
||||
} catch(...){
|
||||
std::cerr<<"error."<<std::endl;
|
||||
}
|
||||
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)
|
||||
{
|
||||
std::cerr << "Error: cannot open file" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::string line;
|
||||
while(std::getline(in, line))
|
||||
{
|
||||
std::istringstream iss(line);
|
||||
std::string type;
|
||||
iss >> type;
|
||||
|
||||
if(type.substr(0, 7).compare("POLYGON")==0)
|
||||
|
||||
if(type.substr(0, 7).compare("POLYGON") == 0)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
boost::geometry::read_wkt(line, polygon);
|
||||
} catch( ...){
|
||||
}
|
||||
catch( ...)
|
||||
{
|
||||
in.setstate(std::ios::failbit);
|
||||
return false;
|
||||
};
|
||||
|
||||
internal::pop_back_if_equal_to_front(polygon);
|
||||
break;
|
||||
}
|
||||
|
|
@ -234,16 +238,15 @@ read_polygon_WKT( std::istream& in,
|
|||
}
|
||||
|
||||
template<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))
|
||||
|
|
@ -251,21 +254,22 @@ read_multi_polygon_WKT( std::istream& in,
|
|||
std::istringstream iss(line);
|
||||
std::string type;
|
||||
iss >> type;
|
||||
|
||||
if(type.substr(0, 12).compare("MULTIPOLYGON")==0)
|
||||
|
||||
if(type.substr(0, 12).compare("MULTIPOLYGON") == 0)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
boost::geometry::read_wkt(line, gc);
|
||||
} catch( ...){
|
||||
}
|
||||
catch( ...)
|
||||
{
|
||||
in.setstate(std::ios::failbit);
|
||||
return false;
|
||||
};
|
||||
for( typename
|
||||
internal::Geometry_container<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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
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)
|
||||
{
|
||||
|
|
@ -330,64 +329,65 @@ write_multi_point_WKT( std::ostream& out,
|
|||
return out;
|
||||
}
|
||||
internal::Geometry_container<MultiPoint, boost::geometry::multi_point_tag> gc(mp);
|
||||
out<<boost::geometry::wkt(gc)<<std::endl;
|
||||
out << boost::geometry::wkt(gc) << std::endl;
|
||||
return 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;
|
||||
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 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;
|
||||
out << boost::geometry::wkt(gc) << std::endl;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
template<typename MultiPoint,
|
||||
typename MultiLineString,
|
||||
typename MultiPolygon>
|
||||
std::istream&
|
||||
read_WKT( std::istream& input,
|
||||
MultiPoint& points,
|
||||
MultiLineString& polylines,
|
||||
MultiPolygon& polygons)
|
||||
std::istream& read_WKT(std::istream& input,
|
||||
MultiPoint& points,
|
||||
MultiLineString& polylines,
|
||||
MultiPolygon& polygons)
|
||||
{
|
||||
do
|
||||
{
|
||||
typedef typename MultiPoint::value_type Point;
|
||||
typedef typename MultiLineString::value_type LineString;
|
||||
typedef typename MultiPolygon::value_type Polygon;
|
||||
|
||||
std::string line;
|
||||
std::streampos input_pos = input.tellg();
|
||||
std::getline(input, line);
|
||||
|
|
@ -395,13 +395,16 @@ read_WKT( std::istream& input,
|
|||
std::string t;
|
||||
std::string type="";
|
||||
iss >> t;
|
||||
|
||||
for(std::size_t pos=0; pos < t.length(); ++pos)
|
||||
{
|
||||
char c=t[pos];
|
||||
if(c=='(')
|
||||
char c = t[pos];
|
||||
if(c == '(')
|
||||
break;
|
||||
|
||||
type.push_back(c);
|
||||
}
|
||||
|
||||
input.seekg(input_pos);
|
||||
if(type == "POINT")
|
||||
{
|
||||
|
|
@ -427,24 +430,26 @@ read_WKT( std::istream& input,
|
|||
MultiPoint mp;
|
||||
CGAL::read_multi_point_WKT(input, mp);
|
||||
for(const Point& point : mp)
|
||||
points.push_back(point);
|
||||
points.push_back(point);
|
||||
}
|
||||
else if(type == "MULTILINESTRING")
|
||||
{
|
||||
MultiLineString mls;
|
||||
CGAL::read_multi_linestring_WKT(input, mls);
|
||||
for(const LineString& ls : mls)
|
||||
polylines.push_back(ls);
|
||||
polylines.push_back(ls);
|
||||
}
|
||||
else if(type == "MULTIPOLYGON")
|
||||
{
|
||||
MultiPolygon mp;
|
||||
CGAL::read_multi_polygon_WKT(input, mp);
|
||||
for(const Polygon& poly : mp)
|
||||
polygons.push_back(poly);
|
||||
polygons.push_back(poly);
|
||||
}
|
||||
}while(input.good() && !input.eof());
|
||||
return input;
|
||||
}
|
||||
while(input.good() && !input.eof());
|
||||
|
||||
return input;
|
||||
}
|
||||
}//end CGAL
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
namespace boost{
|
||||
namespace geometry{
|
||||
namespace traits{
|
||||
template< typename R> struct tag<CGAL::internal::Geometry_container<R, linestring_tag> >
|
||||
{ typedef linestring_tag type; };
|
||||
} // namespace traits
|
||||
} // namespace geometry
|
||||
} // namespace boost
|
||||
|
||||
}}} //end namespaces
|
||||
|
||||
#endif
|
||||
#endif // TRAITS_LINESTRING_H
|
||||
#endif // BOOST VERSION CHECKS
|
||||
#endif // CGAL_IO_WKT_TRAITS_LINESTRING_H
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -14,58 +14,60 @@
|
|||
|
||||
#ifndef CGAL_IO_WKT_TRAITS_POINT_H
|
||||
#define CGAL_IO_WKT_TRAITS_POINT_H
|
||||
|
||||
#if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500)
|
||||
|
||||
#include <CGAL/number_utils.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{
|
||||
namespace boost {
|
||||
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 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 dimension<CGAL::Point_2<K> > : boost::mpl::int_<2> {};
|
||||
|
||||
template< typename K >
|
||||
struct access<CGAL::Point_2<K> , 0>
|
||||
struct tag<CGAL::Point_2<K> >
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
typedef point_tag type;
|
||||
};
|
||||
|
||||
template< typename K >
|
||||
struct access<CGAL::Point_2<K> , 1>
|
||||
struct coordinate_type<CGAL::Point_2<K> >
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
typedef double type;
|
||||
};
|
||||
|
||||
}}}//end namespaces
|
||||
#endif
|
||||
#endif
|
||||
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 access<CGAL::Point_2<K>, 0>
|
||||
{
|
||||
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(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); }
|
||||
};
|
||||
|
||||
} // namespace traits
|
||||
} // namespace geometry
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST VERSION CHECKS
|
||||
#endif // CGAL_IO_WKT_TRAITS_POINT_H
|
||||
|
|
|
|||
|
|
@ -14,72 +14,67 @@
|
|||
|
||||
#ifndef CGAL_IO_WKT_TRAITS_POINT_3_H
|
||||
#define CGAL_IO_WKT_TRAITS_POINT_3_H
|
||||
|
||||
#if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500)
|
||||
|
||||
#include <CGAL/number_utils.h>
|
||||
#include <CGAL/Point_3.h>
|
||||
|
||||
#include <boost/geometry/io/wkt/write.hpp>
|
||||
#include <boost/geometry/io/wkt/read.hpp>
|
||||
|
||||
namespace boost{
|
||||
namespace geometry{
|
||||
namespace traits{
|
||||
namespace boost {
|
||||
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 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 dimension<CGAL::Point_3<K> > : boost::mpl::int_<3> {};
|
||||
|
||||
template< typename K >
|
||||
struct access<CGAL::Point_3<K> , 0>
|
||||
struct tag<CGAL::Point_3<K> >
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
typedef point_tag type;
|
||||
};
|
||||
|
||||
template< typename K >
|
||||
struct access<CGAL::Point_3<K> , 1>
|
||||
struct coordinate_type<CGAL::Point_3<K> >
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
};
|
||||
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);
|
||||
}
|
||||
|
||||
typedef typename K::FT type;
|
||||
};
|
||||
|
||||
}}}//end namespaces
|
||||
#endif
|
||||
#endif
|
||||
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 access<CGAL::Point_3<K>, 0>
|
||||
{
|
||||
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(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(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); }
|
||||
};
|
||||
|
||||
} // namespace traits
|
||||
} // namespace geometry
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST VERSION CHECKS
|
||||
#endif // CGAL_IO_WKT_TRAITS_POINT_3_H
|
||||
|
|
|
|||
|
|
@ -14,35 +14,50 @@
|
|||
|
||||
#ifndef CGAL_IO_WKT_TRAITS_POLYGON_H
|
||||
#define CGAL_IO_WKT_TRAITS_POLYGON_H
|
||||
|
||||
#if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500)
|
||||
|
||||
#include <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{
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue