CacheGeometryGenerator.cpp 2.13 KB
Newer Older
Sri Nagella's avatar
Sri Nagella committed
1
#include <vector>
2
#include <cmath>
3
#include "MantidKernel/Matrix.h"
4
#include "MantidGeometry/Objects/CSGObject.h"
Nick Draper's avatar
re #843    
Nick Draper committed
5
6
#include "MantidGeometry/Rendering/CacheGeometryGenerator.h"
#include "MantidGeometry/Rendering/GeometryHandler.h"
Sri Nagella's avatar
Sri Nagella committed
7

8
9
10
#ifdef ENABLE_OPENCASCADE
#include "MantidGeometry/Rendering/OCGeometryHandler.h"
#endif
11

12
namespace Mantid {
Sri Nagella's avatar
Sri Nagella committed
13

14
15
16
17
18
namespace Geometry {
/**
 * Constructor
 * @param obj :: input object
 */
19
CacheGeometryGenerator::CacheGeometryGenerator(CSGObject *obj) : Obj(obj) {
20
21
  mNoOfVertices = 0;
  mNoOfTriangles = 0;
22
23
  mFaces = nullptr;
  mPoints = nullptr;
24
}
Sri Nagella's avatar
Sri Nagella committed
25

26
27
28
29
30
31
32
33
/**
 * Generate geometry, if there is no cache then it uses OpenCascade to generate
 * surface triangles.
 */
void CacheGeometryGenerator::Generate() {
  if (mNoOfVertices <=
      0) // There are no triangles defined to use OpenCascade handler
  {
34
#ifdef ENABLE_OPENCASCADE
35
36
37
38
39
    OCGeometryHandler h(Obj);
    mNoOfVertices = h.NumberOfPoints();
    mNoOfTriangles = h.NumberOfTriangles();
    mPoints = h.getTriangleVertices();
    mFaces = h.getTriangleFaces();
40
#endif
41
42
  }
}
Sri Nagella's avatar
Sri Nagella committed
43

44
45
46
47
/**
 * Destroy the surface generated for the object
 */
CacheGeometryGenerator::~CacheGeometryGenerator() {
48
  if (mFaces != nullptr)
49
    delete[] mFaces;
50
  if (mPoints != nullptr)
51
52
    delete[] mPoints;
}
Sri Nagella's avatar
Sri Nagella committed
53

54
int CacheGeometryGenerator::getNumberOfTriangles() { return mNoOfTriangles; }
Sri Nagella's avatar
Sri Nagella committed
55

56
int CacheGeometryGenerator::getNumberOfPoints() { return mNoOfVertices; }
Sri Nagella's avatar
Sri Nagella committed
57

58
double *CacheGeometryGenerator::getTriangleVertices() { return mPoints; }
Sri Nagella's avatar
Sri Nagella committed
59

60
int *CacheGeometryGenerator::getTriangleFaces() { return mFaces; }
Sri Nagella's avatar
Sri Nagella committed
61

62
63
64
65
66
67
68
69
70
/**
   Sets the geometry cache using the triangulation information provided
   @param noPts :: the number of points
   @param noFaces :: the number of faces
   @param pts :: a double array of the points
   @param faces :: an int array of the faces
*/
void CacheGeometryGenerator::setGeometryCache(int noPts, int noFaces,
                                              double *pts, int *faces) {
71
  if (mPoints != nullptr)
72
    delete[] mPoints;
73
  if (mFaces != nullptr)
74
75
76
77
78
79
    delete[] mFaces;
  mNoOfVertices = noPts;
  mNoOfTriangles = noFaces;
  mPoints = pts;
  mFaces = faces;
}
Sri Nagella's avatar
Sri Nagella committed
80

81
} // NAMESPACE Geometry
Sri Nagella's avatar
Sri Nagella committed
82

83
} // NAMESPACE Mantid