From 9a242e189731aa6b33302a916e751fad4c43d06f Mon Sep 17 00:00:00 2001 From: Robert Marskar Date: Fri, 27 Feb 2026 08:40:37 +0100 Subject: [PATCH 1/2] Fix parser bugs --- Source/EBGeometry_PLY.hpp | 16 +- Source/EBGeometry_PLYImplem.hpp | 293 +++++++++++++++------------- Source/EBGeometry_ParserImplem.hpp | 56 +++++- Source/EBGeometry_VTK.hpp | 14 +- Source/EBGeometry_VTKImplem.hpp | 294 ++++++++++++++++------------- 5 files changed, 388 insertions(+), 285 deletions(-) diff --git a/Source/EBGeometry_PLY.hpp b/Source/EBGeometry_PLY.hpp index bb7b6f4a..e8178e65 100644 --- a/Source/EBGeometry_PLY.hpp +++ b/Source/EBGeometry_PLY.hpp @@ -85,16 +85,16 @@ class PLY @return m_vertexProperties at provided property */ std::vector& - getVertexProperties(const std::string a_property) noexcept; + getVertexProperties(const std::string a_property); /*! @brief Get the vertex properties @param[in] a_property Which property to fetch - @note Function will fail if the property does not exist + @note Function will fail if the property does not exist @return m_vertexProperties at provided property */ const std::vector& - getVertexProperties(const std::string a_property) const noexcept; + getVertexProperties(const std::string a_property) const; /*! @brief Get the face properties @@ -103,7 +103,7 @@ class PLY @return m_faceProperties at provided property */ std::vector& - getFaceProperties(const std::string a_property) noexcept; + getFaceProperties(const std::string a_property); /*! @brief Get the vertex properties @@ -112,7 +112,7 @@ class PLY @return m_vertexProperties at provided property */ const std::vector& - getFaceProperties(const std::string a_property) const noexcept; + getFaceProperties(const std::string a_property) const; /*! @brief Set vertex properties @@ -120,7 +120,7 @@ class PLY @param[in] a_data Property data */ void - setVertexProperties(const std::string a_property, const std::vector& a_data) noexcept; + setVertexProperties(const std::string a_property, const std::vector& a_data); /*! @brief Set face properties @@ -128,7 +128,7 @@ class PLY @param[in] a_data Property data */ void - setFaceProperties(const std::string a_property, const std::vector& a_data) noexcept; + setFaceProperties(const std::string a_property, const std::vector& a_data); /*! @brief Turn the PLY mesh into a DCEL mesh. @@ -139,7 +139,7 @@ class PLY std::shared_ptr> convertToDCEL() const noexcept; -protected: + //protected: /*! @brief PLY object ID. */ diff --git a/Source/EBGeometry_PLYImplem.hpp b/Source/EBGeometry_PLYImplem.hpp index 77061e12..e8178e65 100644 --- a/Source/EBGeometry_PLYImplem.hpp +++ b/Source/EBGeometry_PLYImplem.hpp @@ -3,144 +3,171 @@ * Please refer to Copyright.txt and LICENSE in the EBGeometry root directory. */ -#ifndef EBGeometry_PLYImplem -#define EBGeometry_PLYImplem +#ifndef EBGeometry_PLY +#define EBGeometry_PLY + +// Std includes +#include +#include // Our includes -#include "EBGeometry_PLY.hpp" -#include "EBGeometry_Soup.hpp" +#include "EBGeometry_Vec.hpp" #include "EBGeometry_NamespaceHeader.hpp" -template -PLY::PLY() noexcept -{ - m_vertexCoordinates.resize(0); - m_facets.resize(0); - m_vertexProperties.clear(); - m_faceProperties.clear(); - m_id = std::string(); -} - -template -PLY::PLY(const std::string a_id) noexcept : PLY() -{ - m_id = a_id; -} - -template -PLY::~PLY() noexcept -{ - m_vertexCoordinates.resize(0); - m_facets.resize(0); - m_vertexProperties.clear(); - m_faceProperties.clear(); -} - -template -std::string& -PLY::getID() noexcept -{ - return m_id; -} - -template -const std::string& -PLY::getID() const noexcept -{ - return m_id; -} - -template -std::vector>& -PLY::getVertexCoordinates() noexcept -{ - return m_vertexCoordinates; -} - -template -const std::vector>& -PLY::getVertexCoordinates() const noexcept -{ - return m_vertexCoordinates; -} - -template -std::vector>& -PLY::getFacets() noexcept -{ - return m_facets; -} - -template -const std::vector>& -PLY::getFacets() const noexcept -{ - return m_facets; -} - -template -std::vector& -PLY::getVertexProperties(const std::string a_property) noexcept -{ - return m_vertexProperties.at(a_property); -} - -template -const std::vector& -PLY::getVertexProperties(const std::string a_property) const noexcept -{ - return m_vertexProperties.at(a_property); -} - -template -std::vector& -PLY::getFaceProperties(const std::string a_property) noexcept -{ - return m_faceProperties.at(a_property); -} - -template -const std::vector& -PLY::getFaceProperties(const std::string a_property) const noexcept -{ - return m_faceProperties.at(a_property); -} - -template -void -PLY::setVertexProperties(const std::string a_property, const std::vector& a_data) noexcept -{ - m_vertexProperties[a_property] = a_data; -} - -template -void -PLY::setFaceProperties(const std::string a_property, const std::vector& a_data) noexcept -{ - m_faceProperties[a_property] = a_data; -} - -template -template -std::shared_ptr> -PLY::convertToDCEL() const noexcept -{ - // Do a deep copy of the vertices and facets since they might need to be compressed. - std::vector> vertices = m_vertexCoordinates; - std::vector> facets = m_facets; - - if (Soup::containsDegeneratePolygons(vertices, facets)) { - std::cerr << "PLY::convertToDCEL - PLY contains degenerate faces\n"; - } - - auto mesh = std::make_shared>(); - - Soup::compress(vertices, facets); - Soup::soupToDCEL(*mesh, vertices, facets, m_id); - - return mesh; -} +/*! + @brief Class for storing Stanford PLY meshes. + @note T is the precision used for storing the mesh. +*/ +template +class PLY +{ +public: + /*! + @brief Default constructor. Initializes empty member data holder + */ + PLY() noexcept; + + /*! + @brief Constructor. Initializes empty vertices and facets but sets the PLY ID (usually the file name + @param[in] a_id Identifier for PLY object + */ + PLY(const std::string a_id) noexcept; + + /*! + @brief Destructor. Clears all data. + */ + virtual ~PLY() noexcept; + + /*! + @brief Get the identifier for this object + */ + std::string& + getID() noexcept; + + /*! + @brief Get the identifier for this object + */ + const std::string& + getID() const noexcept; + + /*! + @brief Get the vertex coordinates + @return m_vertexCoordinates + */ + std::vector>& + getVertexCoordinates() noexcept; + + /*! + @brief Get the vertex coordinates + @return m_vertexCoordinates + */ + const std::vector>& + getVertexCoordinates() const noexcept; + + /*! + @brief Get the face indices + @return m_facets + */ + std::vector>& + getFacets() noexcept; + + /*! + @brief Get the face indices + @return m_facets + */ + const std::vector>& + getFacets() const noexcept; + + /*! + @brief Get the vertex properties + @param[in] a_property Which property to fetch + @note Function will fail if the property does not exist + @return m_vertexProperties at provided property + */ + std::vector& + getVertexProperties(const std::string a_property); + + /*! + @brief Get the vertex properties + @param[in] a_property Which property to fetch + @note Function will fail if the property does not exist + @return m_vertexProperties at provided property + */ + const std::vector& + getVertexProperties(const std::string a_property) const; + + /*! + @brief Get the face properties + @param[in] a_property Which property to fetch + @note Function will fail if the property does not exist + @return m_faceProperties at provided property + */ + std::vector& + getFaceProperties(const std::string a_property); + + /*! + @brief Get the vertex properties + @param[in] a_property Which property to fetch + @note Function will fail if the property does not exist + @return m_vertexProperties at provided property + */ + const std::vector& + getFaceProperties(const std::string a_property) const; + + /*! + @brief Set vertex properties + @param[in] a_property Property name + @param[in] a_data Property data + */ + void + setVertexProperties(const std::string a_property, const std::vector& a_data); + + /*! + @brief Set face properties + @param[in] a_property Property name + @param[in] a_data Property data + */ + void + setFaceProperties(const std::string a_property, const std::vector& a_data); + + /*! + @brief Turn the PLY mesh into a DCEL mesh. + @details This call does not populate any meta-data in the DCEL mesh structures. If you need to also populate + the meta-data on vertices and faces, you should not use this function but supply your own constructor. + */ + template + std::shared_ptr> + convertToDCEL() const noexcept; + + //protected: + /*! + @brief PLY object ID. + */ + std::string m_id; + + /*! + @brief Vertex coordinates + */ + std::vector> m_vertexCoordinates; + + /*! + @brief Faces -- each entry in the outer vector contains the indices defining one face + */ + std::vector> m_facets; + + /*! + @brief Vertex properties + */ + std::map> m_vertexProperties; + + /*! + @brief Face properties + */ + std::map> m_faceProperties; +}; #include "EBGeometry_NamespaceFooter.hpp" +#include "EBGeometry_PLYImplem.hpp" + #endif diff --git a/Source/EBGeometry_ParserImplem.hpp b/Source/EBGeometry_ParserImplem.hpp index 515515c2..2cde075c 100644 --- a/Source/EBGeometry_ParserImplem.hpp +++ b/Source/EBGeometry_ParserImplem.hpp @@ -556,9 +556,11 @@ Parser::readPLY(const std::string& a_filename) noexcept } } - // Copy properties to PLY object using the setter methods + // Copy properties to PLY object using the setter methods, skipping x/y/z coordinates for (const auto& propName : vertexPropertyNames) { - ply.setVertexProperties(propName, vertexProps[propName]); + if (propName != "x" && propName != "y" && propName != "z") { + ply.setVertexProperties(propName, vertexProps[propName]); + } } for (const auto& propName : facePropertyNames) { @@ -835,9 +837,11 @@ Parser::readPLY(const std::string& a_filename) noexcept } } - // Copy properties to PLY object using the setter methods + // Copy properties to PLY object using the setter methods, skipping x/y/z coordinates for (const auto& propName : vertexPropertyNames) { - ply.setVertexProperties(propName, vertexProps[propName]); + if (propName != "x" && propName != "y" && propName != "z") { + ply.setVertexProperties(propName, vertexProps[propName]); + } } for (const auto& propName : facePropertyNames) { @@ -889,6 +893,7 @@ Parser::readVTK(const std::string& a_filename) noexcept case Parser::Encoding::ASCII: { std::ifstream filestream(a_filename); + std::cout << "reading ascii" << std::endl; if (filestream.is_open()) { std::string line; @@ -1025,6 +1030,8 @@ Parser::readVTK(const std::string& a_filename) noexcept size_t numData; sstream >> numData; + std::cout << "getting point data" << std::endl; + // Read point data arrays while (std::getline(filestream, line)) { std::stringstream ss(line); @@ -1062,6 +1069,23 @@ Parser::readVTK(const std::string& a_filename) noexcept vtk.setPointDataScalars(arrayName, scalarData); } + else if (dataKeyword == "FIELD") { + // Skip FIELD arrays within POINT_DATA + std::string fieldName; + size_t numArrays; + ss >> fieldName >> numArrays; + for (size_t f = 0; f < numArrays; f++) { + std::string fieldArrayName, dataType; + size_t numComponents, numTuples; + filestream >> fieldArrayName >> numComponents >> numTuples >> dataType; + std::getline(filestream, line); + for (size_t v = 0; v < numComponents * numTuples; v++) { + std::string dummy; + filestream >> dummy; + } + std::getline(filestream, line); + } + } else if (dataKeyword == "CELL_DATA") { // Back up - we've hit the next section filestream.seekg(-static_cast(line.length()) - 1, std::ios_base::cur); @@ -1109,6 +1133,28 @@ Parser::readVTK(const std::string& a_filename) noexcept vtk.setCellDataScalars(arrayName, scalarData); } + else if (dataKeyword == "FIELD") { + // Skip FIELD arrays within CELL_DATA + std::string fieldName; + size_t numArrays; + ss >> fieldName >> numArrays; + for (size_t f = 0; f < numArrays; f++) { + std::string fieldArrayName, dataType; + size_t numComponents, numTuples; + filestream >> fieldArrayName >> numComponents >> numTuples >> dataType; + std::getline(filestream, line); + for (size_t v = 0; v < numComponents * numTuples; v++) { + std::string dummy; + filestream >> dummy; + } + std::getline(filestream, line); + } + } + else if (dataKeyword == "POINT_DATA") { + // Back up - we've hit the next section + filestream.seekg(-static_cast(line.length()) - 1, std::ios_base::cur); + break; + } } } } @@ -1311,6 +1357,8 @@ Parser::readVTK(const std::string& a_filename) noexcept size_t numData; sstream >> numData; + std::cout << "getting point data" << std::endl; + // Read point data arrays while (std::getline(filestream, line)) { std::stringstream ss(line); diff --git a/Source/EBGeometry_VTK.hpp b/Source/EBGeometry_VTK.hpp index a3918427..cd70bcda 100644 --- a/Source/EBGeometry_VTK.hpp +++ b/Source/EBGeometry_VTK.hpp @@ -86,7 +86,7 @@ class VTK @return m_pointDataScalars at provided name */ std::vector& - getPointDataScalars(const std::string a_name) noexcept; + getPointDataScalars(const std::string a_name); /*! @brief Get the point data scalars @@ -95,7 +95,7 @@ class VTK @return m_pointDataScalars at provided name */ const std::vector& - getPointDataScalars(const std::string a_name) const noexcept; + getPointDataScalars(const std::string a_name) const; /*! @brief Get the cell data scalars @@ -104,7 +104,7 @@ class VTK @return m_cellDataScalars at provided name */ std::vector& - getCellDataScalars(const std::string a_name) noexcept; + getCellDataScalars(const std::string a_name); /*! @brief Get the cell data scalars @@ -113,7 +113,7 @@ class VTK @return m_cellDataScalars at provided name */ const std::vector& - getCellDataScalars(const std::string a_name) const noexcept; + getCellDataScalars(const std::string a_name) const; /*! @brief Set point data scalars @@ -121,7 +121,7 @@ class VTK @param[in] a_data Array data */ void - setPointDataScalars(const std::string a_name, const std::vector& a_data) noexcept; + setPointDataScalars(const std::string a_name, const std::vector& a_data); /*! @brief Set cell data scalars @@ -129,7 +129,7 @@ class VTK @param[in] a_data Array data */ void - setCellDataScalars(const std::string a_name, const std::vector& a_data) noexcept; + setCellDataScalars(const std::string a_name, const std::vector& a_data); /*! @brief Turn the VTK mesh into a DCEL mesh. @@ -140,7 +140,7 @@ class VTK std::shared_ptr> convertToDCEL() const noexcept; -protected: + //protected: /*! @brief VTK object ID. */ diff --git a/Source/EBGeometry_VTKImplem.hpp b/Source/EBGeometry_VTKImplem.hpp index 4c11fc1a..cd70bcda 100644 --- a/Source/EBGeometry_VTKImplem.hpp +++ b/Source/EBGeometry_VTKImplem.hpp @@ -3,144 +3,172 @@ * Please refer to Copyright.txt and LICENSE in the EBGeometry root directory. */ -#ifndef EBGeometry_VTKImplem -#define EBGeometry_VTKImplem +#ifndef EBGeometry_VTK +#define EBGeometry_VTK + +// Std includes +#include +#include +#include // Our includes -#include "EBGeometry_VTK.hpp" -#include "EBGeometry_Soup.hpp" +#include "EBGeometry_Vec.hpp" #include "EBGeometry_NamespaceHeader.hpp" -template -VTK::VTK() noexcept -{ - m_vertexCoordinates.resize(0); - m_facets.resize(0); - m_pointDataScalars.clear(); - m_cellDataScalars.clear(); - m_id = std::string(); -} - -template -VTK::VTK(const std::string a_id) noexcept : VTK() -{ - m_id = a_id; -} - -template -VTK::~VTK() noexcept -{ - m_vertexCoordinates.resize(0); - m_facets.resize(0); - m_pointDataScalars.clear(); - m_cellDataScalars.clear(); -} - -template -std::string& -VTK::getID() noexcept -{ - return m_id; -} - -template -const std::string& -VTK::getID() const noexcept -{ - return m_id; -} - -template -std::vector>& -VTK::getVertexCoordinates() noexcept -{ - return m_vertexCoordinates; -} - -template -const std::vector>& -VTK::getVertexCoordinates() const noexcept -{ - return m_vertexCoordinates; -} - -template -std::vector>& -VTK::getFacets() noexcept -{ - return m_facets; -} - -template -const std::vector>& -VTK::getFacets() const noexcept -{ - return m_facets; -} - -template -std::vector& -VTK::getPointDataScalars(const std::string a_name) noexcept -{ - return m_pointDataScalars.at(a_name); -} - -template -const std::vector& -VTK::getPointDataScalars(const std::string a_name) const noexcept -{ - return m_pointDataScalars.at(a_name); -} - -template -std::vector& -VTK::getCellDataScalars(const std::string a_name) noexcept -{ - return m_cellDataScalars.at(a_name); -} - -template -const std::vector& -VTK::getCellDataScalars(const std::string a_name) const noexcept -{ - return m_cellDataScalars.at(a_name); -} - -template -void -VTK::setPointDataScalars(const std::string a_name, const std::vector& a_data) noexcept -{ - m_pointDataScalars[a_name] = a_data; -} - -template -void -VTK::setCellDataScalars(const std::string a_name, const std::vector& a_data) noexcept -{ - m_cellDataScalars[a_name] = a_data; -} - -template -template -std::shared_ptr> -VTK::convertToDCEL() const noexcept -{ - // Do a deep copy of the vertices and facets since they might need to be compressed. - std::vector> vertices = m_vertexCoordinates; - std::vector> facets = m_facets; - - if (Soup::containsDegeneratePolygons(vertices, facets)) { - std::cerr << "VTK::convertToDCEL - VTK contains degenerate faces\n"; - } - - auto mesh = std::make_shared>(); - - Soup::compress(vertices, facets); - Soup::soupToDCEL(*mesh, vertices, facets, m_id); - - return mesh; -} +/*! + @brief Class for storing VTK Polydata meshes. + @note T is the precision used for storing the mesh. +*/ +template +class VTK +{ +public: + /*! + @brief Default constructor. Initializes empty member data holder + */ + VTK() noexcept; + + /*! + @brief Constructor. Initializes empty vertices and facets but sets the VTK ID (usually the file name + @param[in] a_id Identifier for VTK object + */ + VTK(const std::string a_id) noexcept; + + /*! + @brief Destructor. Clears all data. + */ + virtual ~VTK() noexcept; + + /*! + @brief Get the identifier for this object + */ + std::string& + getID() noexcept; + + /*! + @brief Get the identifier for this object + */ + const std::string& + getID() const noexcept; + + /*! + @brief Get the vertex coordinates + @return m_vertexCoordinates + */ + std::vector>& + getVertexCoordinates() noexcept; + + /*! + @brief Get the vertex coordinates + @return m_vertexCoordinates + */ + const std::vector>& + getVertexCoordinates() const noexcept; + + /*! + @brief Get the face indices + @return m_facets + */ + std::vector>& + getFacets() noexcept; + + /*! + @brief Get the face indices + @return m_facets + */ + const std::vector>& + getFacets() const noexcept; + + /*! + @brief Get the point data scalars + @param[in] a_name Scalar array name + @note Function will fail if the array does not exist + @return m_pointDataScalars at provided name + */ + std::vector& + getPointDataScalars(const std::string a_name); + + /*! + @brief Get the point data scalars + @param[in] a_name Scalar array name + @note Function will fail if the array does not exist + @return m_pointDataScalars at provided name + */ + const std::vector& + getPointDataScalars(const std::string a_name) const; + + /*! + @brief Get the cell data scalars + @param[in] a_name Scalar array name + @note Function will fail if the array does not exist + @return m_cellDataScalars at provided name + */ + std::vector& + getCellDataScalars(const std::string a_name); + + /*! + @brief Get the cell data scalars + @param[in] a_name Scalar array name + @note Function will fail if the array does not exist + @return m_cellDataScalars at provided name + */ + const std::vector& + getCellDataScalars(const std::string a_name) const; + + /*! + @brief Set point data scalars + @param[in] a_name Array name + @param[in] a_data Array data + */ + void + setPointDataScalars(const std::string a_name, const std::vector& a_data); + + /*! + @brief Set cell data scalars + @param[in] a_name Array name + @param[in] a_data Array data + */ + void + setCellDataScalars(const std::string a_name, const std::vector& a_data); + + /*! + @brief Turn the VTK mesh into a DCEL mesh. + @details This call does not populate any meta-data in the DCEL mesh structures. If you need to also populate + the meta-data on vertices and faces, you should not use this function but supply your own constructor. + */ + template + std::shared_ptr> + convertToDCEL() const noexcept; + + //protected: + /*! + @brief VTK object ID. + */ + std::string m_id; + + /*! + @brief Vertex coordinates + */ + std::vector> m_vertexCoordinates; + + /*! + @brief Faces -- each entry in the outer vector contains the indices defining one face + */ + std::vector> m_facets; + + /*! + @brief Point data scalar arrays + */ + std::map> m_pointDataScalars; + + /*! + @brief Cell data scalar arrays + */ + std::map> m_cellDataScalars; +}; #include "EBGeometry_NamespaceFooter.hpp" +#include "EBGeometry_VTKImplem.hpp" + #endif From e127ab5e72177fcb1ca7e3562936dc84b169e7db Mon Sep 17 00:00:00 2001 From: Robert Marskar Date: Fri, 27 Feb 2026 08:47:46 +0100 Subject: [PATCH 2/2] Fix parser bugs and incorrect noexcept specifier --- Source/EBGeometry_PLYImplem.hpp | 293 +++++++++++++++---------------- Source/EBGeometry_VTKImplem.hpp | 294 +++++++++++++++----------------- 2 files changed, 266 insertions(+), 321 deletions(-) diff --git a/Source/EBGeometry_PLYImplem.hpp b/Source/EBGeometry_PLYImplem.hpp index e8178e65..ea5201ea 100644 --- a/Source/EBGeometry_PLYImplem.hpp +++ b/Source/EBGeometry_PLYImplem.hpp @@ -3,171 +3,144 @@ * Please refer to Copyright.txt and LICENSE in the EBGeometry root directory. */ -#ifndef EBGeometry_PLY -#define EBGeometry_PLY - -// Std includes -#include -#include +#ifndef EBGeometry_PLYImplem +#define EBGeometry_PLYImplem // Our includes -#include "EBGeometry_Vec.hpp" +#include "EBGeometry_PLY.hpp" +#include "EBGeometry_Soup.hpp" #include "EBGeometry_NamespaceHeader.hpp" -/*! - @brief Class for storing Stanford PLY meshes. - @note T is the precision used for storing the mesh. -*/ -template -class PLY -{ -public: - /*! - @brief Default constructor. Initializes empty member data holder - */ - PLY() noexcept; - - /*! - @brief Constructor. Initializes empty vertices and facets but sets the PLY ID (usually the file name - @param[in] a_id Identifier for PLY object - */ - PLY(const std::string a_id) noexcept; - - /*! - @brief Destructor. Clears all data. - */ - virtual ~PLY() noexcept; - - /*! - @brief Get the identifier for this object - */ - std::string& - getID() noexcept; - - /*! - @brief Get the identifier for this object - */ - const std::string& - getID() const noexcept; - - /*! - @brief Get the vertex coordinates - @return m_vertexCoordinates - */ - std::vector>& - getVertexCoordinates() noexcept; - - /*! - @brief Get the vertex coordinates - @return m_vertexCoordinates - */ - const std::vector>& - getVertexCoordinates() const noexcept; - - /*! - @brief Get the face indices - @return m_facets - */ - std::vector>& - getFacets() noexcept; - - /*! - @brief Get the face indices - @return m_facets - */ - const std::vector>& - getFacets() const noexcept; - - /*! - @brief Get the vertex properties - @param[in] a_property Which property to fetch - @note Function will fail if the property does not exist - @return m_vertexProperties at provided property - */ - std::vector& - getVertexProperties(const std::string a_property); - - /*! - @brief Get the vertex properties - @param[in] a_property Which property to fetch - @note Function will fail if the property does not exist - @return m_vertexProperties at provided property - */ - const std::vector& - getVertexProperties(const std::string a_property) const; - - /*! - @brief Get the face properties - @param[in] a_property Which property to fetch - @note Function will fail if the property does not exist - @return m_faceProperties at provided property - */ - std::vector& - getFaceProperties(const std::string a_property); - - /*! - @brief Get the vertex properties - @param[in] a_property Which property to fetch - @note Function will fail if the property does not exist - @return m_vertexProperties at provided property - */ - const std::vector& - getFaceProperties(const std::string a_property) const; - - /*! - @brief Set vertex properties - @param[in] a_property Property name - @param[in] a_data Property data - */ - void - setVertexProperties(const std::string a_property, const std::vector& a_data); - - /*! - @brief Set face properties - @param[in] a_property Property name - @param[in] a_data Property data - */ - void - setFaceProperties(const std::string a_property, const std::vector& a_data); - - /*! - @brief Turn the PLY mesh into a DCEL mesh. - @details This call does not populate any meta-data in the DCEL mesh structures. If you need to also populate - the meta-data on vertices and faces, you should not use this function but supply your own constructor. - */ - template - std::shared_ptr> - convertToDCEL() const noexcept; - - //protected: - /*! - @brief PLY object ID. - */ - std::string m_id; - - /*! - @brief Vertex coordinates - */ - std::vector> m_vertexCoordinates; - - /*! - @brief Faces -- each entry in the outer vector contains the indices defining one face - */ - std::vector> m_facets; - - /*! - @brief Vertex properties - */ - std::map> m_vertexProperties; - - /*! - @brief Face properties - */ - std::map> m_faceProperties; -}; +template +PLY::PLY() noexcept +{ + m_vertexCoordinates.resize(0); + m_facets.resize(0); + m_vertexProperties.clear(); + m_faceProperties.clear(); + m_id = std::string(); +} -#include "EBGeometry_NamespaceFooter.hpp" +template +PLY::PLY(const std::string a_id) noexcept : PLY() +{ + m_id = a_id; +} + +template +PLY::~PLY() noexcept +{ + m_vertexCoordinates.resize(0); + m_facets.resize(0); + m_vertexProperties.clear(); + m_faceProperties.clear(); +} + +template +std::string& +PLY::getID() noexcept +{ + return m_id; +} + +template +const std::string& +PLY::getID() const noexcept +{ + return m_id; +} + +template +std::vector>& +PLY::getVertexCoordinates() noexcept +{ + return m_vertexCoordinates; +} + +template +const std::vector>& +PLY::getVertexCoordinates() const noexcept +{ + return m_vertexCoordinates; +} + +template +std::vector>& +PLY::getFacets() noexcept +{ + return m_facets; +} + +template +const std::vector>& +PLY::getFacets() const noexcept +{ + return m_facets; +} -#include "EBGeometry_PLYImplem.hpp" +template +std::vector& +PLY::getVertexProperties(const std::string a_property) +{ + return m_vertexProperties.at(a_property); +} + +template +const std::vector& +PLY::getVertexProperties(const std::string a_property) const +{ + return m_vertexProperties.at(a_property); +} + +template +std::vector& +PLY::getFaceProperties(const std::string a_property) +{ + return m_faceProperties.at(a_property); +} + +template +const std::vector& +PLY::getFaceProperties(const std::string a_property) const +{ + return m_faceProperties.at(a_property); +} + +template +void +PLY::setVertexProperties(const std::string a_property, const std::vector& a_data) +{ + m_vertexProperties[a_property] = a_data; +} + +template +void +PLY::setFaceProperties(const std::string a_property, const std::vector& a_data) +{ + m_faceProperties[a_property] = a_data; +} + +template +template +std::shared_ptr> +PLY::convertToDCEL() const noexcept +{ + // Do a deep copy of the vertices and facets since they might need to be compressed. + std::vector> vertices = m_vertexCoordinates; + std::vector> facets = m_facets; + + if (Soup::containsDegeneratePolygons(vertices, facets)) { + std::cerr << "PLY::convertToDCEL - PLY contains degenerate faces\n"; + } + + auto mesh = std::make_shared>(); + + Soup::compress(vertices, facets); + Soup::soupToDCEL(*mesh, vertices, facets, m_id); + + return mesh; +} + +#include "EBGeometry_NamespaceFooter.hpp" #endif diff --git a/Source/EBGeometry_VTKImplem.hpp b/Source/EBGeometry_VTKImplem.hpp index cd70bcda..bf36457d 100644 --- a/Source/EBGeometry_VTKImplem.hpp +++ b/Source/EBGeometry_VTKImplem.hpp @@ -3,172 +3,144 @@ * Please refer to Copyright.txt and LICENSE in the EBGeometry root directory. */ -#ifndef EBGeometry_VTK -#define EBGeometry_VTK - -// Std includes -#include -#include -#include +#ifndef EBGeometry_VTKImplem +#define EBGeometry_VTKImplem // Our includes -#include "EBGeometry_Vec.hpp" +#include "EBGeometry_VTK.hpp" +#include "EBGeometry_Soup.hpp" #include "EBGeometry_NamespaceHeader.hpp" -/*! - @brief Class for storing VTK Polydata meshes. - @note T is the precision used for storing the mesh. -*/ -template -class VTK -{ -public: - /*! - @brief Default constructor. Initializes empty member data holder - */ - VTK() noexcept; - - /*! - @brief Constructor. Initializes empty vertices and facets but sets the VTK ID (usually the file name - @param[in] a_id Identifier for VTK object - */ - VTK(const std::string a_id) noexcept; - - /*! - @brief Destructor. Clears all data. - */ - virtual ~VTK() noexcept; - - /*! - @brief Get the identifier for this object - */ - std::string& - getID() noexcept; - - /*! - @brief Get the identifier for this object - */ - const std::string& - getID() const noexcept; - - /*! - @brief Get the vertex coordinates - @return m_vertexCoordinates - */ - std::vector>& - getVertexCoordinates() noexcept; - - /*! - @brief Get the vertex coordinates - @return m_vertexCoordinates - */ - const std::vector>& - getVertexCoordinates() const noexcept; - - /*! - @brief Get the face indices - @return m_facets - */ - std::vector>& - getFacets() noexcept; - - /*! - @brief Get the face indices - @return m_facets - */ - const std::vector>& - getFacets() const noexcept; - - /*! - @brief Get the point data scalars - @param[in] a_name Scalar array name - @note Function will fail if the array does not exist - @return m_pointDataScalars at provided name - */ - std::vector& - getPointDataScalars(const std::string a_name); - - /*! - @brief Get the point data scalars - @param[in] a_name Scalar array name - @note Function will fail if the array does not exist - @return m_pointDataScalars at provided name - */ - const std::vector& - getPointDataScalars(const std::string a_name) const; - - /*! - @brief Get the cell data scalars - @param[in] a_name Scalar array name - @note Function will fail if the array does not exist - @return m_cellDataScalars at provided name - */ - std::vector& - getCellDataScalars(const std::string a_name); - - /*! - @brief Get the cell data scalars - @param[in] a_name Scalar array name - @note Function will fail if the array does not exist - @return m_cellDataScalars at provided name - */ - const std::vector& - getCellDataScalars(const std::string a_name) const; - - /*! - @brief Set point data scalars - @param[in] a_name Array name - @param[in] a_data Array data - */ - void - setPointDataScalars(const std::string a_name, const std::vector& a_data); - - /*! - @brief Set cell data scalars - @param[in] a_name Array name - @param[in] a_data Array data - */ - void - setCellDataScalars(const std::string a_name, const std::vector& a_data); - - /*! - @brief Turn the VTK mesh into a DCEL mesh. - @details This call does not populate any meta-data in the DCEL mesh structures. If you need to also populate - the meta-data on vertices and faces, you should not use this function but supply your own constructor. - */ - template - std::shared_ptr> - convertToDCEL() const noexcept; - - //protected: - /*! - @brief VTK object ID. - */ - std::string m_id; - - /*! - @brief Vertex coordinates - */ - std::vector> m_vertexCoordinates; - - /*! - @brief Faces -- each entry in the outer vector contains the indices defining one face - */ - std::vector> m_facets; - - /*! - @brief Point data scalar arrays - */ - std::map> m_pointDataScalars; - - /*! - @brief Cell data scalar arrays - */ - std::map> m_cellDataScalars; -}; +template +VTK::VTK() noexcept +{ + m_vertexCoordinates.resize(0); + m_facets.resize(0); + m_pointDataScalars.clear(); + m_cellDataScalars.clear(); + m_id = std::string(); +} -#include "EBGeometry_NamespaceFooter.hpp" +template +VTK::VTK(const std::string a_id) noexcept : VTK() +{ + m_id = a_id; +} + +template +VTK::~VTK() noexcept +{ + m_vertexCoordinates.resize(0); + m_facets.resize(0); + m_pointDataScalars.clear(); + m_cellDataScalars.clear(); +} + +template +std::string& +VTK::getID() noexcept +{ + return m_id; +} + +template +const std::string& +VTK::getID() const noexcept +{ + return m_id; +} + +template +std::vector>& +VTK::getVertexCoordinates() noexcept +{ + return m_vertexCoordinates; +} + +template +const std::vector>& +VTK::getVertexCoordinates() const noexcept +{ + return m_vertexCoordinates; +} + +template +std::vector>& +VTK::getFacets() noexcept +{ + return m_facets; +} + +template +const std::vector>& +VTK::getFacets() const noexcept +{ + return m_facets; +} -#include "EBGeometry_VTKImplem.hpp" +template +std::vector& +VTK::getPointDataScalars(const std::string a_name) +{ + return m_pointDataScalars.at(a_name); +} + +template +const std::vector& +VTK::getPointDataScalars(const std::string a_name) const +{ + return m_pointDataScalars.at(a_name); +} + +template +std::vector& +VTK::getCellDataScalars(const std::string a_name) +{ + return m_cellDataScalars.at(a_name); +} + +template +const std::vector& +VTK::getCellDataScalars(const std::string a_name) const +{ + return m_cellDataScalars.at(a_name); +} + +template +void +VTK::setPointDataScalars(const std::string a_name, const std::vector& a_data) +{ + m_pointDataScalars[a_name] = a_data; +} + +template +void +VTK::setCellDataScalars(const std::string a_name, const std::vector& a_data) +{ + m_cellDataScalars[a_name] = a_data; +} + +template +template +std::shared_ptr> +VTK::convertToDCEL() const noexcept +{ + // Do a deep copy of the vertices and facets since they might need to be compressed. + std::vector> vertices = m_vertexCoordinates; + std::vector> facets = m_facets; + + if (Soup::containsDegeneratePolygons(vertices, facets)) { + std::cerr << "VTK::convertToDCEL - VTK contains degenerate faces\n"; + } + + auto mesh = std::make_shared>(); + + Soup::compress(vertices, facets); + Soup::soupToDCEL(*mesh, vertices, facets, m_id); + + return mesh; +} + +#include "EBGeometry_NamespaceFooter.hpp" #endif