GluGeometryHandler.cpp 5.1 KB
Newer Older
1
#include "MantidGeometry/Rendering/GluGeometryHandler.h"
Peterson, Peter's avatar
Peterson, Peter committed
2
#include "MantidGeometry/Instrument/ObjComponent.h"
3
#include "MantidGeometry/Objects/CSGObject.h"
Peterson, Peter's avatar
Peterson, Peter committed
4
5
#include "MantidGeometry/Rendering/GeometryHandler.h"
#include "MantidGeometry/Rendering/GluGeometryRenderer.h"
6
#include "MantidKernel/make_unique.h"
Peterson, Peter's avatar
Peterson, Peter committed
7

Hahn, Steven's avatar
Hahn, Steven committed
8
9
#include <boost/make_shared.hpp>

10
11
12
namespace Mantid {
namespace Geometry {
using Kernel::V3D;
13

14
GluGeometryHandler::GluGeometryHandler(IObjComponent *comp)
15
16
    : GeometryHandler(comp),
      Renderer(Kernel::make_unique<GluGeometryRenderer>()), radius(0.0),
17
      height(0.0), type(GeometryType::NOSHAPE) {}
Peterson, Peter's avatar
Peterson, Peter committed
18

19
GluGeometryHandler::GluGeometryHandler(boost::shared_ptr<CSGObject> obj)
20
21
    : GeometryHandler(std::move(obj)),
      Renderer(Kernel::make_unique<GluGeometryRenderer>()), radius(0.0),
22
      height(0.0), type(GeometryType::NOSHAPE) {}
Peterson, Peter's avatar
Peterson, Peter committed
23

24
GluGeometryHandler::GluGeometryHandler(CSGObject *obj)
25
26
    : GeometryHandler(obj),
      Renderer(Kernel::make_unique<GluGeometryRenderer>()), radius(0.0),
27
      height(0.0), type(GeometryType::NOSHAPE) {}
28

29
30
31
32
33
34
GluGeometryHandler::GluGeometryHandler(const GluGeometryHandler &other)
    : GeometryHandler(other), m_points(other.m_points), radius(other.radius),
      height(other.height), type(other.type) {
  this->Renderer = Kernel::make_unique<GluGeometryRenderer>();
}

35
boost::shared_ptr<GeometryHandler> GluGeometryHandler::clone() const {
36
  return boost::make_shared<GluGeometryHandler>(*this);
37
}
Peterson, Peter's avatar
Peterson, Peter committed
38

39
GluGeometryHandler::~GluGeometryHandler() = default;
Peterson, Peter's avatar
Peterson, Peter committed
40

41
42
43
GeometryHandler *GluGeometryHandler::createInstance(IObjComponent *comp) {
  return new GluGeometryHandler(comp);
}
Peterson, Peter's avatar
Peterson, Peter committed
44

45
GeometryHandler *
46
GluGeometryHandler::createInstance(boost::shared_ptr<CSGObject> obj) {
47
48
  return new GluGeometryHandler(obj);
}
49

50
GeometryHandler *GluGeometryHandler::createInstance(CSGObject *obj) {
51
52
  return new GluGeometryHandler(obj);
}
Sri Nagella's avatar
Sri Nagella committed
53

54
55
56
57
58
void GluGeometryHandler::Triangulate() {
  // Check whether Object is triangulated otherwise triangulate
  // Doesn't have to do anything because we are not going to triangulate
  // anything
}
Peterson, Peter's avatar
Peterson, Peter committed
59

60
void GluGeometryHandler::Render() {
61
  if (Obj != nullptr) {
62
    switch (type) {
Moore's avatar
Moore committed
63
    case GeometryType::CUBOID:
64
      Renderer->RenderCube(m_points[0], m_points[1], m_points[2], m_points[3]);
65
      break;
66
    case GeometryType::HEXAHEDRON:
67
68
69
      Renderer->RenderHexahedron(m_points[0], m_points[1], m_points[2],
                                 m_points[3], m_points[4], m_points[5],
                                 m_points[6], m_points[7]);
70
      break;
71
    case GeometryType::SPHERE:
72
      Renderer->RenderSphere(m_points[0], radius);
73
      break;
74
    case GeometryType::CYLINDER:
75
      Renderer->RenderCylinder(m_points[0], m_points[1], radius, height);
76
      break;
77
    case GeometryType::CONE:
78
      Renderer->RenderCone(m_points[0], m_points[1], radius, height);
79
      break;
80
    case GeometryType::SEGMENTED_CYLINDER:
81
82
      Renderer->RenderSegmentedCylinder(m_points[0], m_points[1], radius,
                                        height);
Moore's avatar
Moore committed
83
      break;
84
    case GeometryType::NOSHAPE:
85
86
      break;
    }
87
  } else if (ObjComp != nullptr) {
88
89
90
    Renderer->Render(ObjComp);
  }
}
Peterson, Peter's avatar
Peterson, Peter committed
91

92
93
94
95
void GluGeometryHandler::GetObjectGeom(int &mytype,
                                       std::vector<Kernel::V3D> &vectors,
                                       double &myradius, double &myheight) {
  mytype = 0;
96
  if (Obj != nullptr) {
97
98
    mytype = static_cast<int>(type);
    vectors = m_points;
99
    switch (type) {
100
    case GeometryType::CUBOID:
Lamar Moore's avatar
Lamar Moore committed
101
      break;
102
    case GeometryType::HEXAHEDRON:
Moore's avatar
Moore committed
103
      break;
104
    case GeometryType::SPHERE:
105
106
      myradius = radius;
      break;
Hahn, Steven's avatar
Hahn, Steven committed
107
    default:
108
109
110
      myradius = radius;
      myheight = height;
      break;
111
    }
112
113
  }
}
Peterson, Peter's avatar
Peterson, Peter committed
114

115
void GluGeometryHandler::Initialize() {
116
  if (Obj != nullptr) {
117
118
    // There is no initialization or probably call render
    Render();
119
  }
Peterson, Peter's avatar
Peterson, Peter committed
120
}
121

Lamar Moore's avatar
Lamar Moore committed
122
123
void GluGeometryHandler::setCuboid(const V3D &p1, const V3D &p2, const V3D &p3,
                                   const V3D &p4) {
124
  type = GeometryType::CUBOID;
125
  m_points.assign({p1, p2, p3, p4});
126
}
127

Lamar Moore's avatar
Lamar Moore committed
128
129
130
131
void GluGeometryHandler::setHexahedron(const V3D &p1, const V3D &p2,
                                       const V3D &p3, const V3D &p4,
                                       const V3D &p5, const V3D &p6,
                                       const V3D &p7, const V3D &p8) {
132
  type = GeometryType::HEXAHEDRON;
133
  m_points.assign({p1, p2, p3, p4, p5, p6, p7, p8});
134
135
}

Lamar Moore's avatar
Lamar Moore committed
136
void GluGeometryHandler::setSphere(const V3D &c, double r) {
137
  type = GeometryType::SPHERE;
138
  m_points.assign({c});
139
140
  radius = r;
}
Lamar Moore's avatar
Lamar Moore committed
141
142
void GluGeometryHandler::setCylinder(const V3D &c, const V3D &a, double r,
                                     double h) {
143
  type = GeometryType::CYLINDER;
144
  m_points.assign({c, a});
145
146
147
  radius = r;
  height = h;
}
Lamar Moore's avatar
Lamar Moore committed
148
149
void GluGeometryHandler::setCone(const V3D &c, const V3D &a, double r,
                                 double h) {
150
  type = GeometryType::CONE;
151
  m_points.assign({c, a});
152
153
154
  radius = r;
  height = h;
}
Lamar Moore's avatar
Lamar Moore committed
155
156
void GluGeometryHandler::setSegmentedCylinder(const V3D &c, const V3D &a,
                                              double r, double h) {
157
  type = GeometryType::SEGMENTED_CYLINDER;
158
  m_points.assign({c, a});
159
160
161
162
163
  radius = r;
  height = h;
}
}
}