Object.h 10.2 KB
Newer Older
1
2
#ifndef MANTID_GEOMETRY_OBJECT_H_
#define MANTID_GEOMETRY_OBJECT_H_
3

4
5
6
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
7
#include "MantidGeometry/DllConfig.h"
8

9
#include "BoundingBox.h"
10
#include <map>
11
#include <memory>
12

13
14
15
16
namespace Mantid {
//----------------------------------------------------------------------
// Forward declarations
//----------------------------------------------------------------------
17
namespace Kernel {
18
class PseudoRandomNumberGenerator;
19
class Material;
20
class V3D;
21
22
}

23
namespace Geometry {
24
class CacheGeometryHandler;
25
class CompGrp;
26
27
class GeometryHandler;
class Rule;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class Surface;
class Track;
class vtkGeometryCacheReader;
class vtkGeometryCacheWriter;

/**
\class Object
\brief Global object for object
\version 1.0
\date July 2007
\author S. Ansell

An object is a collection of Rules and surface objects

Copyright &copy; 2007-2010 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 Object {
public:
  /// Default constructor
  Object();
  /// Constructor providing shape xml.
  Object(const std::string &shapeXML);
  /// Copy constructor
  Object(const Object &);
  /// Assignment operator
  Object &operator=(const Object &);
  /// Destructor
  virtual ~Object();

  /// Return the top rule
77
  const Rule *topRule() const { return TopRule.get(); }
Martyn Gigg's avatar
Martyn Gigg committed
78
79
  void setID(const std::string &id) { m_id = id; }
  inline const std::string &id() const { return m_id; }
80

Martyn Gigg's avatar
Martyn Gigg committed
81
82
  void setName(const int nx) { ObjNum = nx; } ///< Set Name
  int getName() const { return ObjNum; }      ///< Get Name
83
84

  void setMaterial(const Kernel::Material &material);
85
  const Kernel::Material material() const;
86
87
88
89
90
91
92
93
94

  /// Return whether this object has a valid shape
  bool hasValidShape() const;
  int setObject(const int ON, const std::string &Ln);
  int procString(const std::string &Line);
  int complementaryObject(const int Cnum,
                          std::string &Ln); ///< Process a complementary object
  int hasComplement() const;

95
  int populate(const std::map<int, boost::shared_ptr<Surface>> &);
96
97
98
  int createSurfaceList(const int outFlag = 0); ///< create Surface list
  int addSurfString(const std::string &);       ///< Not implemented
  int removeSurface(const int SurfN);
99
100
  int substituteSurf(const int SurfN, const int NsurfN,
                     const boost::shared_ptr<Surface> &SPtr);
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
  void makeComplement();
  void convertComplement(const std::map<int, Object> &);

  virtual void print() const;
  void printTree() const;

  bool isValid(const Kernel::V3D &) const; ///< Check if a point is valid
  bool isValid(const std::map<int, int> &)
      const; ///< Check if a set of surfaces are valid.
  bool isOnSide(const Kernel::V3D &) const;
  int calcValidType(const Kernel::V3D &Pt, const Kernel::V3D &uVec) const;

  std::vector<int> getSurfaceIndex() const;
  /// Get the list of surfaces (const version)
  const std::vector<const Surface *> &getSurfacePtr() const { return SurList; }
  /// Get the list of surfaces
  std::vector<const Surface *> &getSurfacePtr() { return SurList; }

  std::string cellCompStr() const;
  std::string cellStr(const std::map<int, Object> &) const;

  std::string str() const;
  void write(std::ostream &) const; ///< MCNPX output

  // INTERSECTION
  int interceptSurface(Geometry::Track &) const;

  // Solid angle - uses triangleSolidAngle unless many (>30000) triangles
  double solidAngle(const Kernel::V3D &observer) const;
  // Solid angle with a scaling of the object
  double solidAngle(const Kernel::V3D &observer,
                    const Kernel::V3D &scaleFactor) const;
  // solid angle via triangulation
  double triangleSolidAngle(const Kernel::V3D &observer) const;
  // Solid angle via triangulation with scaling factor for object size
  double triangleSolidAngle(const Kernel::V3D &observer,
                            const Kernel::V3D &scaleFactor) const;
  // solid angle via ray tracing
  double rayTraceSolidAngle(const Kernel::V3D &observer) const;

141
142
143
  /// Calculates the volume of this object.
  double volume() const;

144
145
146
147
148
149
150
151
  /// Calculate (or return cached value of) Axis Aligned Bounding box
  /// (DEPRECATED)
  void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin,
                      double &ymin, double &zmin) const;

  /// Return cached value of axis-aligned bounding box
  const BoundingBox &getBoundingBox() const;
  /// Define axis-aligned bounding box
152
153
154
  void defineBoundingBox(const double &xMax, const double &yMax,
                         const double &zMax, const double &xMin,
                         const double &yMin, const double &zMin);
155
156
157
158
159
  /// Set a null bounding box for this object
  void setNullBoundingBox();
  // find internal point to object
  int getPointInObject(Kernel::V3D &point) const;

160
161
162
163
164
165
166
  /// Select a random point within the object
  Kernel::V3D generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
                                    const size_t) const;
  Kernel::V3D generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
                                    const BoundingBox &activeRegion,
                                    const size_t) const;

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
  // Rendering member functions
  void draw() const;
  // Initialize Drawing
  void initDraw() const;
  // Get Geometry Handler
  boost::shared_ptr<GeometryHandler> getGeometryHandler();
  /// Set Geometry Handler
  void setGeometryHandler(boost::shared_ptr<GeometryHandler> h);

  /// set vtkGeometryCache writer
  void setVtkGeometryCacheWriter(boost::shared_ptr<vtkGeometryCacheWriter>);
  /// set vtkGeometryCache reader
  void setVtkGeometryCacheReader(boost::shared_ptr<vtkGeometryCacheReader>);
  void GetObjectGeom(int &type, std::vector<Kernel::V3D> &vectors,
                     double &myradius, double &myheight) const;
  /// Getter for the shape xml
  std::string getShapeXML() const;

private:
186
  int procPair(std::string &Ln, std::map<int, std::unique_ptr<Rule>> &Rlist,
187
               int &compUnit) const;
188
  std::unique_ptr<CompGrp> procComp(std::unique_ptr<Rule>) const;
189
190
  int checkSurfaceValid(const Kernel::V3D &, const Kernel::V3D &) const;

191
192
193
194
195
196
197
198
199
  /// Calculate bounding box using Rule system
  void calcBoundingBoxByRule();

  /// Calculate bounding box using object's vertices
  void calcBoundingBoxByVertices();

  /// Calculate bounding box using object's geometric data
  void calcBoundingBoxByGeometry();

200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
  int searchForObject(Kernel::V3D &) const;
  double getTriangleSolidAngle(const Kernel::V3D &a, const Kernel::V3D &b,
                               const Kernel::V3D &c,
                               const Kernel::V3D &observer) const;
  double CuboidSolidAngle(const Kernel::V3D observer,
                          const std::vector<Kernel::V3D> vectors) const;
  double SphereSolidAngle(const Kernel::V3D observer,
                          const std::vector<Kernel::V3D> vectors,
                          const double radius) const;
  double CylinderSolidAngle(const Kernel::V3D &observer,
                            const Mantid::Kernel::V3D &centre,
                            const Mantid::Kernel::V3D &axis,
                            const double radius, const double height) const;
  double ConeSolidAngle(const Kernel::V3D &observer,
                        const Mantid::Kernel::V3D &centre,
                        const Mantid::Kernel::V3D &axis, const double radius,
                        const double height) const;

218
219
220
221
222
  /// Returns the volume.
  double monteCarloVolume() const;
  /// Returns the volume.
  double triangleVolume() const;

Martyn Gigg's avatar
Martyn Gigg committed
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
  /// Top rule [ Geometric scope of object]
  std::unique_ptr<Rule> TopRule;
  /// Object's bounding box
  BoundingBox m_boundingBox;
  // -- DEPRECATED --
  mutable double AABBxMax,  ///< xmax of Axis aligned bounding box cache
      AABByMax,             ///< ymax of Axis aligned bounding box cache
      AABBzMax,             ///< zmax of Axis aligned bounding box cache
      AABBxMin,             ///< xmin of Axis aligned bounding box cache
      AABByMin,             ///< xmin of Axis aligned bounding box cache
      AABBzMin;             ///< zmin of Axis Aligned Bounding Box Cache
  mutable bool boolBounded; ///< flag true if a bounding box exists, either by

  /// Creation number
  int ObjNum;
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
  /// Geometry Handle for rendering
  boost::shared_ptr<GeometryHandler> handle;
  friend class CacheGeometryHandler;
  /// Is geometry caching enabled?
  bool bGeometryCaching;
  /// a pointer to a class for reading from the geometry cache
  boost::shared_ptr<vtkGeometryCacheReader> vtkCacheReader;
  /// a pointer to a class for writing to the geometry cache
  boost::shared_ptr<vtkGeometryCacheWriter> vtkCacheWriter;
  void updateGeometryHandler();
  /// for solid angle from triangulation
  int NumberOfTriangles() const;
  int NumberOfPoints() const;
  int *getTriangleFaces() const;
  double *getTriangleVertices() const;
  /// original shape xml used to generate this object.
  std::string m_shapeXML;
Martyn Gigg's avatar
Martyn Gigg committed
255
256
  /// Optional string identifier
  std::string m_id;
257
  /// material composition
258
  std::unique_ptr<Kernel::Material> m_material;
259
260
261
262
263
264
265
266
267
268
269
270
271

protected:
  std::vector<const Surface *>
      SurList; ///< Full surfaces (make a map including complementary object ?)
};

/// Typdef for a shared pointer
typedef boost::shared_ptr<Object> Object_sptr;
/// Typdef for a shared pointer to a const object
typedef boost::shared_ptr<const Object> Object_const_sptr;

} // NAMESPACE Geometry
} // NAMESPACE Mantid
272

273
#endif /*MANTID_GEOMETRY_OBJECT_H_*/