Commit 2d0e27c2 authored by Lamar Moore's avatar Lamar Moore
Browse files

Refactored geometry handling to single class re #21248

parent 8c0deff4
......@@ -108,13 +108,9 @@ set ( SRC_FILES
src/Objects/Rules.cpp
src/Objects/ShapeFactory.cpp
src/Objects/Track.cpp
src/Rendering/BitmapGeometryHandler.cpp
src/Rendering/CacheGeometryHandler.cpp
src/Rendering/GeometryHandler.cpp
src/Rendering/Renderer.cpp
src/Rendering/ShapeInfo.cpp
src/Rendering/GluGeometryHandler.cpp
src/Rendering/StructuredGeometryHandler.cpp
src/Rendering/vtkGeometryCacheReader.cpp
src/Rendering/vtkGeometryCacheWriter.cpp
src/Rendering/GeometryTriangulator.cpp
......@@ -131,14 +127,8 @@ set ( SRC_FILES
src/Surfaces/Torus.cpp
)
set ( OPENCASCADE_SRC
src/Rendering/OCGeometryHandler.cpp
)
set ( SRC_UNITY_IGNORE_FILES src/Instrument/CompAssembly.cpp
src/Instrument/ObjCompAssembly.cpp
src/Rendering/OCGeometryHandler.cpp
src/Rendering/OCGeometryRenderer.cpp
)
set ( INC_FILES
......@@ -270,15 +260,10 @@ set ( INC_FILES
inc/MantidGeometry/Objects/Rules.h
inc/MantidGeometry/Objects/ShapeFactory.h
inc/MantidGeometry/Objects/Track.h
inc/MantidGeometry/Rendering/BitmapGeometryHandler.h
inc/MantidGeometry/Rendering/CacheGeometryHandler.h
inc/MantidGeometry/Rendering/GeometryHandler.h
inc/MantidGeometry/Rendering/Renderer.h
inc/MantidGeometry/Rendering/ShapeInfo.h
inc/MantidGeometry/Rendering/GluGeometryHandler.h
inc/MantidGeometry/Rendering/OCGeometryHandler.h
inc/MantidGeometry/Rendering/OpenGL_Headers.h
inc/MantidGeometry/Rendering/StructuredGeometryHandler.h
inc/MantidGeometry/Rendering/vtkGeometryCacheReader.h
inc/MantidGeometry/Rendering/vtkGeometryCacheWriter.h
inc/MantidGeometry/Rendering/GeometryTriangulator.h
......@@ -403,6 +388,7 @@ set ( TEST_FILES
SampleEnvironmentTest.h
ScalarUtilsTest.h
ShapeFactoryTest.h
ShapeInfoTest.h
SpaceGroupFactoryTest.h
SpaceGroupTest.h
SphereTest.h
......@@ -439,11 +425,6 @@ if(UNITY_BUILD)
enable_unity_build(Geometry SRC_FILES SRC_UNITY_IGNORE_FILES 10)
endif(UNITY_BUILD)
# ===================== Open Cascade ===================
if (ENABLE_OPENCASCADE)
LIST (APPEND SRC_FILES ${OPENCASCADE_SRC} )
endif ()
# A few defines needed for OpenCascade on the Mac
if ( APPLE )
add_definitions ( -DHAVE_IOSTREAM -DHAVE_LIMITS -DHAVE_IOMANIP )
......
......@@ -5,6 +5,7 @@
// Includes
//----------------------------------------------------------------------
#include "MantidGeometry/DllConfig.h"
#include "MantidGeometry/Rendering/ShapeInfo.h"
#include "MantidGeometry/Objects/IObject.h"
#include "BoundingBox.h"
......@@ -23,7 +24,6 @@ class V3D;
}
namespace Geometry {
class CacheGeometryHandler;
class CompGrp;
class GeometryHandler;
class Rule;
......@@ -188,7 +188,7 @@ public:
/// set vtkGeometryCache reader
void setVtkGeometryCacheReader(
boost::shared_ptr<vtkGeometryCacheReader>) override;
void GetObjectGeom(int &type, std::vector<Kernel::V3D> &vectors,
void GetObjectGeom(detail::ShapeInfo::GeometryShape &type, std::vector<Kernel::V3D> &vectors,
double &myradius, double &myheight) const override;
/// Getter for the shape xml
std::string getShapeXML() const override;
......@@ -249,8 +249,7 @@ private:
int ObjNum;
/// Geometry Handle for rendering
boost::shared_ptr<GeometryHandler> m_handler;
friend class CacheGeometryHandler;
friend class GeometryRenderer;
friend class GeometryHandler;
/// Is geometry caching enabled?
bool bGeometryCaching;
/// a pointer to a class for reading from the geometry cache
......
#ifndef BITMAPGEOMETRYHANDLER_H
#define BITMAPGEOMETRYHANDLER_H
#ifndef Q_MOC_RUN
#include <boost/weak_ptr.hpp>
#endif
#include "MantidGeometry/DllConfig.h"
#include "MantidKernel/Logger.h"
#include "MantidGeometry/IObjComponent.h"
#include "MantidGeometry/Rendering/GeometryHandler.h"
#include "MantidGeometry/Objects/CSGObject.h"
#include "MantidGeometry/Instrument/RectangularDetector.h"
namespace Mantid {
namespace Geometry {
/**
\class BitmapGeometryHandler
\brief Handler for geometry objects that are rendered as bitmaps (e.g.
RectangularDetector), rather than primitives.
\author Janik Zikovsky
\date October 2010
\version 1.0
This class supports drawing RectangularDetector - as a bitmap plotted by openGL
rather
than a million individual pixels rendered as cubes.
A texture will have been created by the RectangularDetectorActor (in MantidPlot)
and this is what will be mapped.
Copyright &copy; 2008 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>
*/
class ObjComponent;
class CSGObject;
class MANTID_GEOMETRY_DLL BitmapGeometryHandler : public GeometryHandler {
private:
static Kernel::Logger &PLog; ///< The official logger
boost::shared_ptr<GeometryHandler> clone() const override;
/// The RectangularDetector object being plotted.
RectangularDetector *m_rectDet;
public:
BitmapGeometryHandler(RectangularDetector *comp);
BitmapGeometryHandler();
//
// BitmapGeometryHandler(IObjComponent *comp); ///<
// Constructor
// BitmapGeometryHandler(boost::shared_ptr<Object> obj);
// ///<Constructor
// BitmapGeometryHandler(Object *obj); ///<Constructor
BitmapGeometryHandler *createInstance(
IObjComponent *) override; ///< Create an instance of concrete geometry
/// handler for ObjComponent
BitmapGeometryHandler *createInstance(boost::shared_ptr<CSGObject>)
override; ///< Create an instance of concrete geometry handler for Object
GeometryHandler *createInstance(CSGObject *)
override; ///< Create an instance of concrete geometry handler for Object
void Triangulate() override; ///< Triangulate the Object
void Render() override; ///< Render Object or ObjComponent
void Initialize()
override; ///< Prepare/Initialize Object/ObjComponent to be rendered
/// Returns true if the shape can be triangulated
bool canTriangulate() override { return false; }
};
} // NAMESPACE Geometry
} // NAMESPACE Mantid
#endif
#ifndef CACHE_GEOMETRYHANDLER_H
#define CACHE_GEOMETRYHANDLER_H
#include "MantidGeometry/DllConfig.h"
#include "MantidGeometry/Rendering/GeometryHandler.h"
namespace Mantid {
namespace Kernel {
class V3D;
}
namespace Geometry {
class GeometryHandler;
class CacheGeometryGenerator;
class IObjComponent;
class CSGObject;
namespace detail {
class GeometryTriangulator;
}
/**
\class CacheGeometryHandler
\brief Place holder for geometry triangulation and rendering with caching
triangles.
\author Srikanth Nagella
\date Jan 2009
\version 1.0
This is an implementation class for handling geometry from cache, if the
cache doesn't exist then the
triangulation is done using another triangulation handler and store in cache.
Copyright &copy; 2008 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>
*/
class MANTID_GEOMETRY_DLL CacheGeometryHandler : public GeometryHandler {
private:
std::unique_ptr<detail::GeometryTriangulator>
m_triangulator; ///< Triangulates geometry
public:
CacheGeometryHandler(IObjComponent *comp); ///< Constructor
CacheGeometryHandler(boost::shared_ptr<CSGObject> obj); ///< Constructor
CacheGeometryHandler(CSGObject *obj); ///< Constructor
CacheGeometryHandler(const CacheGeometryHandler &handler);
boost::shared_ptr<GeometryHandler> clone() const override;
~CacheGeometryHandler() override; ///< Destructor
GeometryHandler *createInstance(IObjComponent *comp) override;
GeometryHandler *createInstance(boost::shared_ptr<CSGObject> obj) override;
GeometryHandler *createInstance(CSGObject *obj) override;
void Triangulate() override;
void Render() override;
void Initialize() override;
bool canTriangulate() override { return true; }
/// get the number of triangles
size_t numberOfTriangles() override;
/// get the number of points or vertices
size_t numberOfPoints() override;
boost::optional<const std::vector<double> &> getTriangleVertices() override;
boost::optional<const std::vector<int> &> getTriangleFaces() override;
/// Sets the geometry cache using the triangulation information provided
void setGeometryCache(size_t nPts, size_t nFaces, std::vector<double> &&pts,
std::vector<int> &&faces) override;
};
} // NAMESPACE Geometry
} // NAMESPACE Mantid
#endif
......@@ -2,12 +2,11 @@
#define GEOMETRYHANDLER_H
#include "MantidGeometry/DllConfig.h"
#include "MantidGeometry/Rendering/Renderer.h"
#include "MantidGeometry/Rendering/ShapeInfo.h"
#include "MantidKernel/Logger.h"
#include "MantidKernel/V3D.h"
#include <boost/shared_ptr.hpp>
#include "MantidGeometry/Rendering/Renderer.h"
#include <vector>
#include <boost/optional.hpp>
namespace Mantid {
......@@ -15,111 +14,86 @@ namespace Geometry {
class IObjComponent;
class ObjComponent;
class CSGObject;
class GeometryRenderer;
namespace detail {
class Renderer;
}
/**
\class GeometryHandler
\brief Place holder for geometry triangulation and rendering.
\author Srikanth Nagella
\date July 2008
\version 1.0
\class GeometryHandler
\brief Handles rendering of all object Geometry.
\author Lamar Moore
\date December 2017
This is an abstract class for handling geometry primitives.
Handles the rendering of all geometry types in Mantid.
Copyright &copy; 2008 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
Copyright &copy; 2008 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
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 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.
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/>.
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>
File change history is stored at: <https://github.com/mantidproject/mantid>
*/
class MANTID_GEOMETRY_DLL GeometryHandler {
private:
static Kernel::Logger &PLog; ///< The official logger
protected:
detail::Renderer m_renderer;
IObjComponent *ObjComp; ///< ObjComponent that uses this geometry handler
CSGObject *Obj; ///< Object that uses this geometry handler
bool boolTriangulated; ///< state of the geometry triangulation
bool
boolIsInitialized; ///< state of the geometry initialization for rendering
std::unique_ptr<detail::Renderer> m_renderer = nullptr;
std::shared_ptr<detail::ShapeInfo> m_shapeInfo = nullptr;
std::unique_ptr<detail::GeometryTriangulator> m_triangulator = nullptr;
RectangularDetector *m_rectDet = nullptr;
StructuredDetector *m_structDet = nullptr;
IObjComponent *m_objComp =
nullptr; ///< ObjComponent that uses this geometry handler
CSGObject *m_obj = nullptr; ///< Object that uses this geometry handler
public:
GeometryHandler(IObjComponent *comp); ///< Constructor
GeometryHandler(boost::shared_ptr<CSGObject> obj); ///<Constructor
GeometryHandler(CSGObject *obj); ///<Constructor
GeometryHandler(const GeometryHandler &) = default;
virtual boost::shared_ptr<GeometryHandler>
clone() const = 0; ///< Virtual copy constructor
virtual ~GeometryHandler();
virtual GeometryHandler *createInstance(IObjComponent *) = 0; ///< Create an
/// instance of
/// concrete
/// geometry
/// handler for
/// ObjComponent
virtual GeometryHandler *createInstance(
boost::shared_ptr<CSGObject>) = 0; ///< Create an instance of
/// concrete geometry
/// handler for Object
virtual GeometryHandler *
createInstance(CSGObject *) = 0; ///< Create an instance
/// of concrete geometry
/// handler for Object
virtual void Triangulate() = 0; ///< Triangulate the Object
virtual void Render() = 0; ///< Render Object or ObjComponent
virtual void
Initialize() = 0; ///< Prepare/Initialize Object/ObjComponent to be rendered
/// Returns true if the shape can be triangulated
virtual bool canTriangulate() { return false; }
GeometryHandler(boost::shared_ptr<Object> obj); ///< Constructor
GeometryHandler(CSGObject *obj); ///< Constructor
GeometryHandler(RectangularDetector *comp);
GeometryHandler(StructuredDetector *comp);
GeometryHandler(const GeometryHandler &renderer);
boost::shared_ptr<GeometryHandler> clone() const;
~GeometryHandler();
void render(); ///< Render Object or ObjComponent
void initialize(); ///< Prepare/Initialize Object/ObjComponent to be rendered
bool canTriangulate() const { return !(m_triangulator == nullptr); }
/// get the number of triangles
virtual size_t numberOfTriangles() { return 0; }
size_t numberOfTriangles();
/// get the number of points or vertices
virtual size_t numberOfPoints() { return 0; }
size_t numberOfPoints();
bool hasShapeInfo() const { return !(m_shapeInfo == nullptr); }
const detail::ShapeInfo &shapeInfo() const { return *m_shapeInfo; }
/// Extract the vertices of the triangles
virtual boost::optional<const std::vector<double> &> getTriangleVertices() {
return boost::none;
}
boost::optional<const std::vector<double> &> getTriangleVertices();
/// Extract the Faces of the triangles
virtual boost::optional<const std::vector<int> &> getTriangleFaces() {
return boost::none;
}
boost::optional<const std::vector<int> &> getTriangleFaces();
/// Sets the geometry cache using the triangulation information provided
virtual void setGeometryCache(size_t nPts, size_t nFaces,
std::vector<double> &&pts,
std::vector<int> &&faces) {
UNUSED_ARG(nPts);
UNUSED_ARG(nFaces);
UNUSED_ARG(pts);
UNUSED_ARG(faces);
};
void setGeometryCache(size_t nPts, size_t nFaces, std::vector<double> &&pts,
std::vector<int> &&faces);
/// return the actual type and points of one of the "standard" objects,
/// cuboid/cone/cyl/sphere
virtual void GetObjectGeom(int &mytype, std::vector<Kernel::V3D> &vectors,
double &myradius, double &myheight) {
UNUSED_ARG(vectors);
UNUSED_ARG(myradius);
UNUSED_ARG(myheight);
// Flag that this is unknown at this point
mytype = -1;
};
void GetObjectGeom(detail::ShapeInfo::GeometryShape &mytype,
std::vector<Kernel::V3D> &vectors, double &myradius,
double &myheight) const;
void setShapeInfo(detail::ShapeInfo &&shapeInfo);
};
} // NAMESPACE Geometry
} // NAMESPACE Mantid
#endif
#ifndef MANTID_GEOMETRY_GEOMETRYRENDERER_H_
#define MANTID_GEOMETRY_GEOMETRYRENDERER_H_
#include "MantidGeometry/DllConfig.h"
#include "MantidGeometry/Rendering/OpenGL_Headers.h"
class TopoDS_Shape;
namespace Mantid {
namespace Kernel {
class V3D;
}
namespace Geometry {
class RectangularDetector;
class StructuredDetector;
class IObjComponent;
/** GeometryRenderer : Handles rendering of geometry within mantid.
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 GeometryRenderer {
public:
enum class RenderMode { Basic, Volumetric };
GeometryRenderer() = default;
~GeometryRenderer() = default;
/// General method for rendering geometry
template <typename... Args>
void render(RenderMode mode, Args &&... args) const &;
/// Render Basic geometry without transparency (non-volumetric)
template <typename... Args> void render(Args &&... args) const &;
/// Render IObjComponent
void renderIObjComponent(IObjComponent *objComp,
RenderMode mode = RenderMode::Basic) const;
/// Render Traingulated Surface
void renderTriangulated(int noPts, int noFaces, double *points, int *faces,
RenderMode mode = RenderMode::Basic) const;
/// Render OpenCascade Shape
void renderOpenCascade(TopoDS_Shape *objSurf,
RenderMode mode = RenderMode::Basic) const;
/// Renders a sphere
void renderSphere(const Kernel::V3D &center, double radius,
RenderMode mode = RenderMode::Basic) const;
/// Renders a cuboid
void renderCuboid(const Kernel::V3D &Point1, const Kernel::V3D &Point2,
const Kernel::V3D &Point3, const Kernel::V3D &Point4,
RenderMode mode = RenderMode::Basic) const;
/// Renders a Hexahedron from the input values
void renderHexahedron(const std::vector<Kernel::V3D> &points,
RenderMode mode = RenderMode::Basic) const;
/// Renders a Cone from the input values
void renderCone(const Kernel::V3D &center, const Kernel::V3D &axis,
double radius, double height,
RenderMode mode = RenderMode::Basic) const;
/// Renders a Cylinder/Segmented cylinder from the input values
void renderCylinder(const Kernel::V3D &center, const Kernel::V3D &axis,
double radius, double height, bool segmented = false,
RenderMode mode = RenderMode::Basic) const;
/// Renders a Bitmap (used for rendering RectangularDetector)
void renderBitmap(const RectangularDetector *rectDet,
RenderMode mode = RenderMode::Basic) const;
/// Renders structured geometry (used for rendering StructuredDetector)
void renderStructured(const StructuredDetector *structDet,
RenderMode mode = RenderMode::Basic) const;
private:
mutable RenderMode m_renderMode;
// general geometry
/// Render IObjComponent
void doRender(IObjComponent *ObjComp) const;
/// Render Traingulated Surface
void doRender(int noPts, int noFaces, double *points, int *faces) const;
/// Render OpenCascade Shape
void doRender(TopoDS_Shape *ObjSurf) const;
// shapes
/// Renders a sphere
void doRender(const Kernel::V3D &center, double radius) const;
/// Renders a cuboid
void doRender(const Kernel::V3D &Point1, const Kernel::V3D &Point2,
const Kernel::V3D &Point3, const Kernel::V3D &Point4) const;
/// Renders a Hexahedron from the input values
void doRender(const std::vector<Kernel::V3D> &points) const;
/// Renders a Cone from the input values
void doRender(const Kernel::V3D &center, const Kernel::V3D &axis,
double radius, double height) const;
/// Renders a Cylinder/Segmented cylinder from the input values
void doRender(const Kernel::V3D &center, const Kernel::V3D &axis,
double radius, double height, bool segmented) const;
/// Renders a Bitmap (used for rendering RectangularDetector)
void doRender(const RectangularDetector *rectDet) const;
/// Renders structured geometry (used for rendering StructuredDetector)
void doRender(const StructuredDetector *structDet) const;
};
template <typename... Args>
void GeometryRenderer::render(RenderMode mode, Args &&... args) const & {
// Wait for no OopenGL error
while (glGetError() != GL_NO_ERROR)
;
m_renderMode = mode;
doRender(std::forward<Args>(args)...);
}
template <typename... Args>
void GeometryRenderer::render(Args &&... args) const & {
render(RenderMode::Basic, std::forward<Args>(args)...);
}
} // namespace Geometry
} // namespace Mantid
#endif /* MANTID_GEOMETRY_GEOMETRYRENDERER_H_ */
\ No newline at end of file