Skip to content
Snippets Groups Projects
GeometryTriangulator.h 3.15 KiB
Newer Older
#ifndef MANTID_GEOMETRY_SURFACETRIANGULATOR_H_
#define MANTID_GEOMETRY_SURFACETRIANGULATOR_H_

#include "MantidGeometry/DllConfig.h"
Lamar Moore's avatar
Lamar Moore committed
#include <memory>
#include <vector>

class TopoDS_Shape;

namespace Mantid {
namespace Geometry {
class CSGObject;
Lamar Moore's avatar
Lamar Moore committed
class MeshObject;

namespace detail {
/** GeometryTriangulator : Triangulates object surfaces. May or may not use
  opencascade.

  Copyright &copy; 2017 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
  National Laboratory & European Spallation Source

  This file is part of Mantid.

  Mantid is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 3 of the License, or
  (at your option) any later version.

  Mantid is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

  File change history is stored at: <https://github.com/mantidproject/mantid>
  Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_GEOMETRY_DLL GeometryTriangulator {
private:
  bool m_isTriangulated;
  size_t m_nFaces;
  size_t m_nPoints;
Lamar Moore's avatar
Lamar Moore committed
  std::vector<double> m_points;        ///< double array or points
  std::vector<uint32_t> m_faces;       ///< Integer array of faces
Lamar Moore's avatar
Lamar Moore committed
  const CSGObject *m_csgObj = nullptr; ///< Input Object
  const MeshObject *m_meshObj = nullptr;
  void checkTriangulated();

public:
Lamar Moore's avatar
Lamar Moore committed
  GeometryTriangulator(const CSGObject *obj = nullptr);
Lamar Moore's avatar
Lamar Moore committed
  GeometryTriangulator(const MeshObject *obj);
  GeometryTriangulator(const GeometryTriangulator &) = delete;
  GeometryTriangulator &operator=(const GeometryTriangulator &) = delete;
  ~GeometryTriangulator();
  void triangulate();
Lamar Moore's avatar
Lamar Moore committed
  void generateMesh();
  void setGeometryCache(size_t nPoints, size_t nFaces,
Lamar Moore's avatar
Lamar Moore committed
                        std::vector<double> &&points,
                        std::vector<uint32_t> &&faces);
  /// Return the number of triangle faces
  size_t numTriangleFaces();
  /// Return the number of triangle vertices
  size_t numTriangleVertices();
  /// get a pointer to the 3x(NumberOfPoints) coordinates (x1,y1,z1,x2..) of
  /// mesh
  const std::vector<double> &getTriangleVertices();
  /// get a pointer to the 3x(NumberOFaces) integers describing points forming
  /// faces (p1,p2,p3)(p4,p5,p6).
Lamar Moore's avatar
Lamar Moore committed
  const std::vector<uint32_t> &getTriangleFaces();
#ifdef ENABLE_OPENCASCADE
private:
Lamar Moore's avatar
Lamar Moore committed
  std::unique_ptr<TopoDS_Shape>
      m_objSurface; ///< Storage for the output surface
                    /// Analyze the object
                    /// OpenCascade analysis of object surface
  void OCAnalyzeObject();
  size_t numPoints() const;
  size_t numFaces() const;
  void setupPoints();
  void setupFaces();

public:
  /// Return OpenCascade surface.
Lamar Moore's avatar
Lamar Moore committed
  bool hasOCSurface() const;
  const TopoDS_Shape &getOCSurface();
#endif
};
} // namespace detail
} // namespace Geometry
} // namespace Mantid

#endif /* MANTID_GEOMETRY_SURFACETRIANGULATOR_H_ */