OCGeometryHandler.cpp 3.13 KB
Newer Older
1
#include "MantidGeometry/Objects/CSGObject.h"
Peterson, Peter's avatar
Peterson, Peter committed
2
3
4
5
6
7
#include "MantidGeometry/IObjComponent.h"
#include "MantidGeometry/Rendering/GeometryHandler.h"
#include "MantidGeometry/Rendering/OCGeometryHandler.h"
#include "MantidGeometry/Rendering/OCGeometryGenerator.h"
#include "MantidGeometry/Rendering/OCGeometryRenderer.h"

8
9
#include <boost/make_shared.hpp>

10
11
12
13
namespace Mantid {
namespace Geometry {
OCGeometryHandler::OCGeometryHandler(IObjComponent *comp)
    : GeometryHandler(comp) {
14
  Triangulator = nullptr;
15
16
17
  Renderer = new OCGeometryRenderer();
}

18
OCGeometryHandler::OCGeometryHandler(boost::shared_ptr<CSGObject> obj)
19
20
21
22
23
    : GeometryHandler(obj) {
  Triangulator = new OCGeometryGenerator(obj.get());
  Renderer = new OCGeometryRenderer();
}

24
OCGeometryHandler::OCGeometryHandler(CSGObject *obj) : GeometryHandler(obj) {
25
26
27
28
29
30
31
32
33
34
35
36
37
  Triangulator = new OCGeometryGenerator(obj);
  Renderer = new OCGeometryRenderer();
}

boost::shared_ptr<GeometryHandler> OCGeometryHandler::clone() const {
  auto clone = boost::make_shared<OCGeometryHandler>(*this);
  clone->Renderer = new OCGeometryRenderer(*(this->Renderer));
  if (this->Triangulator)
    clone->Triangulator = new OCGeometryGenerator(this->Obj);
  return clone;
}

OCGeometryHandler::~OCGeometryHandler() {
38
  if (Triangulator != nullptr)
39
    delete Triangulator;
40
  if (Renderer != nullptr)
41
42
43
44
45
46
47
48
    delete Renderer;
}

GeometryHandler *OCGeometryHandler::createInstance(IObjComponent *comp) {
  return new OCGeometryHandler(comp);
}

GeometryHandler *
49
OCGeometryHandler::createInstance(boost::shared_ptr<CSGObject> obj) {
50
51
52
  return new OCGeometryHandler(obj);
}

53
GeometryHandler *OCGeometryHandler::createInstance(CSGObject *obj) {
54
55
56
57
58
  return new OCGeometryHandler(obj);
}

void OCGeometryHandler::Triangulate() {
  // Check whether Object is triangulated otherwise triangulate
59
  if (Obj != nullptr && !boolTriangulated) {
60
61
62
63
    Triangulator->Generate();
    boolTriangulated = true;
  }
}
Peterson, Peter's avatar
Peterson, Peter committed
64

65
void OCGeometryHandler::Render() {
66
  if (Obj != nullptr) {
67
    if (!boolTriangulated)
68
69
      Triangulate();
    Renderer->Render(Triangulator->getObjectSurface());
70
  } else if (ObjComp != nullptr) {
71
    Renderer->Render(ObjComp);
72
  }
Peterson, Peter's avatar
Peterson, Peter committed
73
}
74
75

void OCGeometryHandler::Initialize() {
76
  if (Obj != nullptr) {
77
    if (!boolTriangulated)
78
79
      Triangulate();
    Renderer->Initialize(Triangulator->getObjectSurface());
80
  } else if (ObjComp != nullptr) {
81
82
83
84
85
    Renderer->Initialize(ObjComp);
  }
}

int OCGeometryHandler::NumberOfTriangles() {
86
  if (Obj != nullptr) {
87
    if (!boolTriangulated)
88
89
90
91
92
93
94
95
      Triangulate();
    return Triangulator->getNumberOfTriangles();
  } else {
    return 0;
  }
}

int OCGeometryHandler::NumberOfPoints() {
96
  if (Obj != nullptr) {
97
    if (!boolTriangulated)
98
99
100
101
102
103
104
105
      Triangulate();
    return Triangulator->getNumberOfPoints();
  } else {
    return 0;
  }
}

double *OCGeometryHandler::getTriangleVertices() {
106
  if (Obj != nullptr) {
107
    if (!boolTriangulated)
108
109
110
      Triangulate();
    return Triangulator->getTriangleVertices();
  } else {
111
    return nullptr;
112
113
114
115
  }
}

int *OCGeometryHandler::getTriangleFaces() {
Hahn, Steven's avatar
Hahn, Steven committed
116
  if (Obj != nullptr) {
117
    if (!boolTriangulated)
118
119
120
      Triangulate();
    return Triangulator->getTriangleFaces();
  } else {
121
    return nullptr;
122
123
124
125
  }
}
}
}