Mantid
Loading...
Searching...
No Matches
Rules.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9#include <map>
10#include <memory>
11
12class TopoDS_Shape;
13
14namespace Mantid {
15namespace Kernel {
16class V3D;
17}
18namespace Geometry {
19
20class CSGObject;
21class Surface;
22
33class MANTID_GEOMETRY_DLL Rule {
34private:
36 virtual Rule *doClone() const = 0;
37
38 static int addToKey(std::vector<int> &AV, const int passN = -1);
39
40 int getBaseKeys(std::vector<int> &) const;
41protected:
42 Rule(const Rule &);
43 Rule &operator=(const Rule &);
44
45public:
46 static int makeCNFcopy(std::unique_ptr<Rule> &);
47 static int makeFullDNF(std::unique_ptr<Rule> &);
48 static int makeCNF(std::unique_ptr<Rule> &);
49 static int removeComplementary(std::unique_ptr<Rule> &);
50 static int removeItem(std::unique_ptr<Rule> &TRule, const int SurfN);
51
52 Rule();
53 Rule(Rule *);
54 std::unique_ptr<Rule> clone() const { return std::unique_ptr<Rule>(doClone()); }
55 virtual ~Rule() = default;
56 virtual std::string className() const { return "Rule"; }
57
59 virtual Rule *leaf(const int = 0) const { return nullptr; }
60 void setParent(Rule *);
61 Rule *getParent() const;
62 void makeParents();
63 int checkParents() const;
64 int getKeyList(std::vector<int> &) const;
65 int commonType() const;
66
67 virtual void setLeaves(std::unique_ptr<Rule>,
68 std::unique_ptr<Rule>) = 0;
69 virtual void setLeaf(std::unique_ptr<Rule>,
70 const int = 0) = 0;
71 virtual int findLeaf(const Rule *) const = 0;
72 virtual Rule *findKey(const int) = 0;
73 virtual int type() const { return 0; }
74
76 virtual bool isValid(const Kernel::V3D &) const = 0;
78 virtual bool isValid(const std::map<int, int> &) const = 0;
80 virtual int simplify() = 0;
81
82 virtual int isComplementary() const { return 0; }
83
84 int Eliminate();
85 int substituteSurf(const int SurfN, const int newSurfN, const std::shared_ptr<Surface> &SPtr);
86
88 virtual std::string display() const = 0;
90 virtual std::string displayAddress() const = 0;
92 virtual void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin, double &zmin) = 0;
93#ifdef ENABLE_OPENCASCADE
94 virtual TopoDS_Shape analyze() = 0;
95#endif
96};
97
109class MANTID_GEOMETRY_DLL Intersection : public Rule {
110
111private:
112 std::unique_ptr<Rule> A;
113 std::unique_ptr<Rule> B;
114 Intersection *doClone() const override;
115protected:
116 Intersection(const Intersection &);
117 Intersection &operator=(const Intersection &);
118
119public:
120 Intersection() = default;
121 explicit Intersection(std::unique_ptr<Rule>, std::unique_ptr<Rule>);
122 explicit Intersection(Rule *, std::unique_ptr<Rule>, std::unique_ptr<Rule>);
123 std::unique_ptr<Intersection> clone() const;
124 std::string className() const override { return "Intersection"; }
125
126 Rule *leaf(const int ipt = 0) const override { return ipt ? B.get() : A.get(); }
127 void setLeaves(std::unique_ptr<Rule>,
128 std::unique_ptr<Rule>) override;
129 void setLeaf(std::unique_ptr<Rule> nR,
130 const int side = 0) override;
131 int findLeaf(const Rule *) const override;
132 Rule *findKey(const int KeyN) override;
133 int isComplementary() const override;
134
135 int type() const override { return 1; } // effective name
136 std::string display() const override;
137 std::string displayAddress() const override;
138
139 bool isValid(const Kernel::V3D &) const override;
140 bool isValid(const std::map<int, int> &) const override;
141 int simplify() override;
142 void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin,
143 double &zmin) override;
144#ifdef ENABLE_OPENCASCADE
145 TopoDS_Shape analyze() override;
146#endif
147};
148
160class MANTID_GEOMETRY_DLL Union : public Rule {
161
162private:
163 std::unique_ptr<Rule> A;
164 std::unique_ptr<Rule> B;
165 Union *doClone() const override;
166
167protected:
168 Union(const Union &);
169 Union &operator=(const Union &);
170
171public:
172 Union() = default;
173 explicit Union(std::unique_ptr<Rule>, std::unique_ptr<Rule>);
174 explicit Union(Rule *, std::unique_ptr<Rule>, std::unique_ptr<Rule>);
175
176 std::unique_ptr<Union> clone() const;
177 std::string className() const override { return "Union"; }
178
179 Rule *leaf(const int ipt = 0) const override { return ipt ? B.get() : A.get(); }
180 void setLeaves(std::unique_ptr<Rule>,
181 std::unique_ptr<Rule>) override;
182 void setLeaf(std::unique_ptr<Rule>, const int side = 0) override;
183 int findLeaf(const Rule *) const override;
184 Rule *findKey(const int KeyN) override;
185
186 int isComplementary() const override;
187 int type() const override { return -1; }
188
189 bool isValid(const Kernel::V3D &) const override;
190 bool isValid(const std::map<int, int> &) const override;
191 std::string display() const override;
192 std::string displayAddress() const override;
193 int simplify() override;
194 void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin,
195 double &zmin) override;
196#ifdef ENABLE_OPENCASCADE
197 TopoDS_Shape analyze() override;
198#endif
199};
200
213class MANTID_GEOMETRY_DLL SurfPoint : public Rule {
214private:
215 std::shared_ptr<Surface> m_key;
216 SurfPoint *doClone() const override;
217 int keyN;
218 int sign;
219public:
220 SurfPoint();
221 std::string className() const override { return "SurfPoint"; }
222 std::unique_ptr<SurfPoint> clone() const;
223
224 Rule *leaf(const int = 0) const override { return nullptr; }
225 void setLeaves(std::unique_ptr<Rule>, std::unique_ptr<Rule>) override;
226 void setLeaf(std::unique_ptr<Rule>, const int = 0) override;
227 int findLeaf(const Rule *) const override;
228 Rule *findKey(const int KeyNum) override;
229
230 int type() const override { return 0; }
231
232 void setKeyN(const int Ky);
233 void setKey(const std::shared_ptr<Surface> &Spoint);
234 bool isValid(const Kernel::V3D &) const override;
235 bool isValid(const std::map<int, int> &) const override;
236 int getSign() const { return sign; }
237 int getKeyN() const { return keyN; }
238 int simplify() override;
239
240 Surface *getKey() const { return m_key.get(); }
241 std::string display() const override;
242 std::string displayAddress() const override;
243 void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin,
244 double &zmin) override;
245#ifdef ENABLE_OPENCASCADE
246 TopoDS_Shape analyze() override;
247#endif
248};
249
262class MANTID_GEOMETRY_DLL CompObj : public Rule {
263private:
264 int objN;
266 CompObj *doClone() const override;
267
268protected:
269 CompObj(const CompObj &) = default;
270 CompObj &operator=(const CompObj &) = default;
271
272public:
273 CompObj();
274 std::unique_ptr<CompObj> clone() const;
275 std::string className() const override { return "CompObj"; }
276
277 void setLeaves(std::unique_ptr<Rule>, std::unique_ptr<Rule>) override;
278 void setLeaf(std::unique_ptr<Rule>, const int = 0) override;
279 int findLeaf(const Rule *) const override;
280 Rule *findKey(const int i) override;
281
282 int type() const override { return 0; }
283 int isComplementary() const override { return 1; }
284
285 void setObjN(const int Ky);
286 void setObj(CSGObject *);
287 bool isValid(const Kernel::V3D &) const override;
288 bool isValid(const std::map<int, int> &) const override;
290 int getObjN() const { return objN; }
291 int simplify() override;
292
293 CSGObject *getObj() const { return key; }
294 std::string display() const override;
295 std::string displayAddress() const override;
296 void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin,
297 double &zmin) override;
298#ifdef ENABLE_OPENCASCADE
299 TopoDS_Shape analyze() override;
300#endif
301};
302
315class MANTID_GEOMETRY_DLL CompGrp : public Rule {
316private:
317 std::unique_ptr<Rule> A;
318 CompGrp *doClone() const override;
319
320protected:
321 CompGrp(const CompGrp &);
322 CompGrp &operator=(const CompGrp &);
323
324public:
325 CompGrp() = default;
326 explicit CompGrp(Rule *, std::unique_ptr<Rule>);
327 std::unique_ptr<CompGrp> clone() const;
328 std::string className() const override { return "CompGrp"; }
329
330 Rule *leaf(const int) const override { return A.get(); }
331 void setLeaves(std::unique_ptr<Rule>, std::unique_ptr<Rule>) override;
332 void setLeaf(std::unique_ptr<Rule> nR, const int side = 0) override;
333 int findLeaf(const Rule *) const override;
334 Rule *findKey(const int i) override;
335
336 int type() const override { return 0; }
337 int isComplementary() const override { return 1; }
338
339 bool isValid(const Kernel::V3D &) const override;
340 bool isValid(const std::map<int, int> &) const override;
341 int simplify() override;
342
343 std::string display() const override;
344 std::string displayAddress() const override;
345 void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin,
346 double &zmin) override;
347#ifdef ENABLE_OPENCASCADE
348 TopoDS_Shape analyze() override;
349#endif
350};
351
363class MANTID_GEOMETRY_DLL BoolValue : public Rule {
364private:
365 int status;
366 BoolValue *doClone() const override;
367
368protected:
369 BoolValue(const BoolValue &) = default;
370 BoolValue &operator=(const BoolValue &);
371
372public:
373 BoolValue();
374 std::unique_ptr<BoolValue> clone() const;
375 std::string className() const override { return "BoolValue"; }
376
377 Rule *leaf(const int = 0) const override { return nullptr; }
378 void setLeaves(std::unique_ptr<Rule>, std::unique_ptr<Rule>) override;
379 void setLeaf(std::unique_ptr<Rule>, const int = 0) override;
380 int findLeaf(const Rule *) const override;
381 Rule *findKey(const int) override { return nullptr; }
382
383 int type() const override { return 0; } // effective name
384
386 void setStatus(int val) {
387 if (val == 0 || val == 1 || val == -1)
388 status = val;
389 }
390 bool isValid(const Kernel::V3D &) const override;
391 bool isValid(const std::map<int, int> &) const override;
392 int simplify() override;
393
394 std::string display() const override;
395 std::string displayAddress() const override;
396 void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin,
397 double &zmin) override;
398#ifdef ENABLE_OPENCASCADE
399 TopoDS_Shape analyze() override;
400#endif
401};
402
403} // NAMESPACE Geometry
404
405} // NAMESPACE Mantid
void removeItem(WorkspaceGroup &self, const std::string &name)
std::string m_key
Rule Status class.
Definition: Rules.h:363
BoolValue(const BoolValue &)=default
std::string className() const override
Returns class name as string.
Definition: Rules.h:375
void setStatus(int val)
< write val into status, if in valid range
Definition: Rules.h:386
Rule * findKey(const int) override
Abstract key find.
Definition: Rules.h:381
int status
Three values 0 False : 1 True : -1 doesn't matter.
Definition: Rules.h:365
int type() const override
Null rule.
Definition: Rules.h:383
Rule * leaf(const int=0) const override
No leaves.
Definition: Rules.h:377
Constructive Solid Geometry object.
Definition: CSGObject.h:51
Compemented Grup.
Definition: Rules.h:315
int type() const override
Is it a branched object.
Definition: Rules.h:336
std::string className() const override
Returns class name as string.
Definition: Rules.h:328
Rule * leaf(const int) const override
selects leaf component
Definition: Rules.h:330
std::unique_ptr< Rule > A
The rule.
Definition: Rules.h:317
int isComplementary() const override
Always returns true (1)
Definition: Rules.h:337
Compemented Object.
Definition: Rules.h:262
int type() const override
Is it a branched object.
Definition: Rules.h:282
std::string className() const override
Returns class name as string.
Definition: Rules.h:275
int objN
Object number.
Definition: Rules.h:264
CSGObject * getObj() const
Get Object Ptr.
Definition: Rules.h:293
CSGObject * key
Object Pointer.
Definition: Rules.h:265
CompObj & operator=(const CompObj &)=default
int isComplementary() const override
Always returns true (1)
Definition: Rules.h:283
int getObjN() const
Get object number of component.
Definition: Rules.h:290
CompObj(const CompObj &)=default
Combines two Rule objects in an intersection.
Definition: Rules.h:109
int type() const override
Null rule.
Definition: Rules.h:135
std::string className() const override
Returns class name as string.
Definition: Rules.h:124
Rule * leaf(const int ipt=0) const override
selects leaf component
Definition: Rules.h:126
std::unique_ptr< Rule > A
Rule 1.
Definition: Rules.h:112
std::unique_ptr< Rule > B
Rule 2.
Definition: Rules.h:113
Object generation rule tree.
Definition: Rules.h:33
virtual Rule * leaf(const int=0) const
No leaf for a base rule.
Definition: Rules.h:59
std::unique_ptr< Rule > clone() const
Definition: Rules.h:54
virtual int isComplementary() const
Always returns false (0)
Definition: Rules.h:82
virtual Rule * doClone() const =0
abstract clone object
virtual std::string className() const
Returns class name as string.
Definition: Rules.h:56
virtual Rule * findKey(const int)=0
Abstract key find.
int getBaseKeys(std::vector< int > &) const
Fills the vector with the surfaces.
virtual int findLeaf(const Rule *) const =0
Abstract find.
virtual void setLeaf(std::unique_ptr< Rule >, const int=0)=0
Abstract set.
virtual bool isValid(const std::map< int, int > &) const =0
Abstract Validity based on surface true/false map.
virtual ~Rule()=default
virtual std::string displayAddress() const =0
Abstract Display Address.
virtual void setLeaves(std::unique_ptr< Rule >, std::unique_ptr< Rule >)=0
abstract set leaves
static int makeFullDNF(std::unique_ptr< Rule > &)
Make Rule into a full DNF format.
Rule * Parent
Parent object (for tree)
Definition: Rules.h:35
virtual bool isValid(const Kernel::V3D &) const =0
Abstract: The point is within the object.
virtual std::string display() const =0
Abstract Display.
virtual int simplify()=0
Abstract: Can the rule be simplified.
virtual void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin, double &zmin)=0
Abstract getBoundingBox.
virtual int type() const
Null rule.
Definition: Rules.h:73
Surface leaf node.
Definition: Rules.h:213
std::shared_ptr< Surface > m_key
Actual Surface Base Object.
Definition: Rules.h:215
int sign
+/- in Object unit
Definition: Rules.h:218
std::string className() const override
Returns class name as string.
Definition: Rules.h:221
int keyN
Key Number (identifer)
Definition: Rules.h:217
int getKeyN() const
Get Key.
Definition: Rules.h:237
int getSign() const
Get Sign.
Definition: Rules.h:236
Rule * leaf(const int=0) const override
No Leaves.
Definition: Rules.h:224
Surface * getKey() const
Get Surface Ptr.
Definition: Rules.h:240
int type() const override
Effective name.
Definition: Rules.h:230
Holds a basic quadratic surface.
Definition: Surface.h:33
Combines two Rule objects in an union.
Definition: Rules.h:160
std::unique_ptr< Rule > A
Leaf rule A.
Definition: Rules.h:163
Rule * leaf(const int ipt=0) const override
Select a leaf component.
Definition: Rules.h:179
std::string className() const override
Returns class name as string.
Definition: Rules.h:177
std::unique_ptr< Rule > B
Leaf rule B.
Definition: Rules.h:164
int type() const override
effective name
Definition: Rules.h:187
Class for 3D vectors.
Definition: V3D.h:34
Helper class which provides the Collimation Length for SANS instruments.