Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bindings/python/tests/mesh_io/test-py-mesh-io-generic-api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ def test_extensions():
check_extensions(
opengeode.PolygonalSurface3D,
["obj", "ply", "vtp", "vtu", "dxf"],
["obj", "ply", "vtp"],
["obj", "ply", "vtp", "dxf"],
)
check_extensions(
opengeode.TriangulatedSurface3D, ["stl", "smesh", "vtu"], ["obj", "stl", "vtp"]
opengeode.TriangulatedSurface3D,
["stl", "smesh", "vtu"],
["obj", "stl", "vtp", "dxf"],
)
check_extensions(opengeode.EdgedCurve3D, ["smesh"], ["vtp"])
check_extensions(opengeode.PolygonalSurface2D, [], ["vtp", "dot"])
Expand Down
55 changes: 55 additions & 0 deletions include/geode/io/mesh/internal/dxf_common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2019 - 2026 Geode-solutions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

#pragma once

#include <string>
#include <string_view>

#include <geode/basic/common.hpp>

namespace geode
{
namespace internal
{
/*!
* Number of corners of a 3DFACE. A triangle repeats its third corner
* as fourth one.
*/
inline constexpr local_index_t NB_3DFACE_CORNERS{ 4 };

/*!
* Encodes the non-ASCII characters of a UTF-8 string as the \U+XXXX
* escapes of DXF strings. Invalid UTF-8 sequences and code points
* above U+FFFF, which cannot be escaped, are replaced by '_'.
*/
[[nodiscard]] std::string encode_unicode_escapes(
std::string_view utf8 );

/*!
* Decodes the \U+XXXX escapes of DXF strings to UTF-8.
*/
[[nodiscard]] std::string decode_unicode_escapes(
std::string_view value );
} // namespace internal
} // namespace geode
64 changes: 64 additions & 0 deletions include/geode/io/mesh/internal/dxf_polygonal_output.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2019 - 2026 Geode-solutions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

#pragma once

#include <string>
#include <vector>

#include <geode/mesh/io/polygonal_surface_output.hpp>

namespace geode
{
FORWARD_DECLARATION_DIMENSION_CLASS( PolygonalSurface );
ALIAS_3D( PolygonalSurface );
} // namespace geode

namespace geode
{
namespace internal
{
/*!
* Writes an ASCII DXF with one 3DFACE per polygon,
* which must have 3 or 4 vertices: see
* write_dxf_surface.
*/
class DXFPolygonalOutput final : public PolygonalSurfaceOutput< 3 >
{
public:
explicit DXFPolygonalOutput( std::string_view filename )
: PolygonalSurfaceOutput< 3 >( filename )
{
}

static std::string_view extension()
{
static constexpr auto EXT = "dxf";
return EXT;
}

std::vector< std::string > write(
const PolygonalSurface3D &surface ) const final;
};
} // namespace internal
} // namespace geode
57 changes: 57 additions & 0 deletions include/geode/io/mesh/internal/dxf_surface_output.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2019 - 2026 Geode-solutions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

#pragma once

#include <string_view>

#include <geode/basic/common.hpp>

namespace geode
{
FORWARD_DECLARATION_DIMENSION_CLASS( SurfaceMesh );
ALIAS_3D( SurfaceMesh );
} // namespace geode

namespace geode
{
namespace internal
{
/*!
* Writes an ASCII DXF (R12) with one 3DFACE per polygon, on a layer
* named after the surface. A triangle is a 3DFACE whose fourth corner
* is the third one. Polygons with more than 4 vertices cannot be
* written: a data exception is raised before creating the file.
*
* The layer name is not strictly R12: R12 only allows up to 31
* characters among A-Z 0-9 $ - _, whereas the surface name is kept
* (spaces, case, length, non-ASCII characters as \U+XXXX escapes),
* only characters forbidden by all DXF versions being replaced by '_'.
* Lenient readers, including the OpenGeode-IO DXF reader, accept it.
* A newer version (e.g. AC1015) is not declared: it requires handles
* and complete TABLES, BLOCKS and OBJECTS sections.
*/
void write_dxf_surface(
std::string_view filename, const SurfaceMesh3D& surface );
} // namespace internal
} // namespace geode
64 changes: 64 additions & 0 deletions include/geode/io/mesh/internal/dxf_triangulated_output.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2019 - 2026 Geode-solutions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

#pragma once

#include <string>
#include <vector>

#include <geode/mesh/io/triangulated_surface_output.hpp>

namespace geode
{
FORWARD_DECLARATION_DIMENSION_CLASS( TriangulatedSurface );
ALIAS_3D( TriangulatedSurface );
} // namespace geode

namespace geode
{
namespace internal
{
/*!
* Writes an ASCII DXF with one 3DFACE per triangle: see
* write_dxf_surface.
*/
class DXFTriangulatedOutput final
: public TriangulatedSurfaceOutput< 3 >
{
public:
explicit DXFTriangulatedOutput( std::string_view filename )
: TriangulatedSurfaceOutput< 3 >( filename )
{
}

static std::string_view extension()
{
static constexpr auto EXT = "dxf";
return EXT;
}

std::vector< std::string > write(
const TriangulatedSurface3D &surface ) const final;
};
} // namespace internal
} // namespace geode
8 changes: 8 additions & 0 deletions src/geode/io/mesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ add_geode_library(
"csv_input_helpers.cpp"
"dot_polygonal_output.cpp"
"dot_triangulated_output.cpp"
"dxf_common.cpp"
"dxf_input.cpp"
"dxf_polygonal_output.cpp"
"dxf_surface_output.cpp"
"dxf_triangulated_output.cpp"
"gexf_output.cpp"
"obj_input.cpp"
"obj_polygonal_output.cpp"
Expand Down Expand Up @@ -97,7 +101,11 @@ add_geode_library(
"internal/assimp_input.hpp"
"internal/assimp_output.hpp"
"internal/csv_input.hpp"
"internal/dxf_common.hpp"
"internal/dxf_input.hpp"
"internal/dxf_polygonal_output.hpp"
"internal/dxf_surface_output.hpp"
"internal/dxf_triangulated_output.hpp"
"internal/gexf_output.hpp"
"internal/obj_input.hpp"
"internal/obj_polygonal_output.hpp"
Expand Down
8 changes: 8 additions & 0 deletions src/geode/io/mesh/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

#include <geode/io/mesh/internal/csv_input.hpp>
#include <geode/io/mesh/internal/dxf_input.hpp>
#include <geode/io/mesh/internal/dxf_polygonal_output.hpp>
#include <geode/io/mesh/internal/dxf_triangulated_output.hpp>
#include <geode/io/mesh/internal/gexf_output.hpp>
#include <geode/io/mesh/internal/obj_input.hpp>
#include <geode/io/mesh/internal/obj_polygonal_output.hpp>
Expand Down Expand Up @@ -127,6 +129,9 @@ namespace
geode::PolygonalSurfaceOutputFactory3D::register_creator<
geode::internal::OBJPolygonalOutput >(
geode::internal::OBJPolygonalOutput::extension().data() );
geode::PolygonalSurfaceOutputFactory3D::register_creator<
geode::internal::DXFPolygonalOutput >(
geode::internal::DXFPolygonalOutput::extension().data() );
geode::PolygonalSurfaceOutputFactory2D::register_creator<
geode::detail::VTPPolygonalOutput< 2 > >(
geode::detail::VTPPolygonalOutput< 2 >::extension().data() );
Expand All @@ -149,6 +154,9 @@ namespace
geode::TriangulatedSurfaceOutputFactory3D::register_creator<
geode::internal::OBJTriangulatedOutput >(
geode::internal::OBJTriangulatedOutput::extension().data() );
geode::TriangulatedSurfaceOutputFactory3D::register_creator<
geode::internal::DXFTriangulatedOutput >(
geode::internal::DXFTriangulatedOutput::extension().data() );
geode::TriangulatedSurfaceOutputFactory2D::register_creator<
geode::detail::VTPTriangulatedOutput< 2 > >(
geode::detail::VTPTriangulatedOutput< 2 >::extension().data() );
Expand Down
Loading
Loading