32Kernel::Logger logger(
"Rules");
47 for (
int i = 0; i < static_cast<int>(AV.size()); i++) {
75 if (TopRule->type() == 0)
80 Rule *tmpA, *tmpB, *tmpC;
85 std::stack<DTriple<Rule *, int, Rule *>> TreeLine;
88 while (!active && !TreeLine.empty())
90 TreeComp = TreeLine.top();
93 tmpA = TreeComp.
third;
116 }
else if (tcount == -1)
118 if (TreeComp.
first) {
124 int leafNumber = parentOfA->
findLeaf(tmpA);
125 parentOfA->
setLeaf(
nullptr, leafNumber);
157 Rule *tmpA, *tmpB, *tmpC;
180 std::stack<DTriple<Rule *, int, Rule *>> TreeLine;
189 while (!active && !TreeLine.empty()) {
191 TreeComp = TreeLine.top();
195 tmpA = TreeComp.
third;
200 tmpB = tmpA->
leaf(0);
201 tmpC = tmpA->
leaf(1);
216 if (tmpA->
type() == 1 && tmpB && tmpC)
219 if (tmpB->
type() == -1 || tmpC->
type() == -1)
221 std::unique_ptr<Rule> alpha, beta, gamma;
222 if (tmpB->
type() == -1)
227 gamma = tmpC->
clone();
236 gamma = tmpB->
clone();
243 std::unique_ptr<Rule> tmp1 = std::make_unique<Intersection>(std::move(alpha), gamma->clone());
244 std::unique_ptr<Rule> tmp2 = std::make_unique<Intersection>(std::move(beta), std::move(gamma));
245 std::unique_ptr<Rule> partReplace = std::make_unique<Union>(std::move(tmp1), std::move(tmp2));
250 TreeComp.
first->setLeaf(std::move(partReplace), TreeComp.
second);
253 TopRule = std::move(partReplace);
289 TopRule->makeParents();
292 Rule *tmpA, *tmpB, *tmpC;
297 std::stack<Rule *> TreeLine;
301 TreeLine.push(TopRule.get());
305 if (!TopRule->checkParents())
306 logger.debug() <<
"Parents False\n";
307 while (!active && !TreeLine.empty()) {
309 tmpA = TreeLine.top();
315 tmpB = tmpA->
leaf(0);
316 tmpC = tmpA->
leaf(1);
327 if (tmpA->
type() == 1 && tmpB && tmpC)
330 if (tmpB->
type() == -1 || tmpC->
type() == -1)
332 std::unique_ptr<Rule> alpha, beta, gamma;
333 if (tmpB->
type() == -1)
338 gamma = tmpC->
clone();
347 gamma = tmpB->
clone();
354 std::unique_ptr<Rule> tmp1 = std::make_unique<Intersection>(std::move(alpha), gamma->clone());
355 std::unique_ptr<Rule> tmp2 = std::make_unique<Intersection>(std::move(beta), std::move(gamma));
356 std::unique_ptr<Rule> partReplace = std::make_unique<Union>(std::move(tmp1), std::move(tmp2));
363 const int leafN = Pnt->
findLeaf(tmpA);
364 Pnt->
setLeaf(std::move(partReplace), leafN);
366 TopRule = std::move(partReplace);
390 Rule *LevelTwo = (LevelOne) ? LevelOne->
getParent() :
nullptr;
395 const Rule *PObj = (LevelOne->
leaf(0) != Ptr) ? LevelOne->
leaf(0) : LevelOne->
leaf(1);
397 const int side = (LevelTwo->
leaf(0) != LevelOne) ? 1 : 0;
402 Rule *PObj = (LevelOne->
leaf(0) != Ptr) ? LevelOne->
leaf(0) : LevelOne->
leaf(1);
405 TRule = PObj->
clone();
408 auto *SX =
dynamic_cast<SurfPoint *
>(Ptr);
410 throw std::logic_error(
"Failed to cast Rule object to SurfPoint");
413 SX->setKey(std::shared_ptr<Surface>());
482 std::stack<Rule *> Tree;
484 while (!Tree.empty()) {
485 Rule *Ptmp = Tree.top();
489 for (
int i = 0; i < 2; i++) {
508 std::stack<const Rule *> Tree;
510 while (!Tree.empty()) {
511 const Rule *Ptmp = Tree.top();
515 for (
int i = 0; i < 2; i++) {
537 const int rtype = this->
type();
541 std::stack<const Rule *> Tree;
542 Tree.push(this->
leaf(0));
543 Tree.push(this->
leaf(1));
544 while (!Tree.empty()) {
545 const Rule *tmpA = Tree.top();
548 if (tmpA->
type() == -rtype)
573 Ptr->
setKeyN(Ptr->getSign() * newSurfN);
591 std::stack<const Rule *> TreeLine;
593 while (!TreeLine.empty()) {
594 const Rule *tmpA = TreeLine.top();
604 const auto *SurX =
dynamic_cast<const SurfPoint *
>(tmpA);
606 IList.emplace_back(SurX->getKeyN());
608 logger.error() <<
"Error with surface List\n";
609 return static_cast<int>(IList.size());
613 std::sort(IList.begin(), IList.end());
614 auto px = std::unique(IList.begin(), IList.end());
615 IList.erase(px, IList.end());
616 return static_cast<int>(IList.size());
627 std::map<int, int> Base;
628 std::vector<int> baseVal;
629 std::vector<int> baseKeys;
630 std::vector<int> deadKeys;
633 std::vector<int>::const_iterator xv;
634 for (xv = baseKeys.begin(); xv != baseKeys.end(); ++xv) {
635 baseVal.emplace_back(0);
643 for (
unsigned int TKey = 0; TKey < baseKeys.size(); TKey++) {
645 int valueTrue(1), valueFalse(1);
647 int targetKey = baseKeys[TKey];
648 for (
unsigned int i = 0; i < baseVal.size(); i++) {
650 Base[baseKeys[i]] = 0;
654 while (valueTrue == valueFalse || keyChange >= 0) {
656 Base[baseKeys[targetKey]] = 0;
660 Base[baseKeys[targetKey]] = 1;
664 if (valueTrue == valueFalse) {
665 keyChange =
addToKey(baseVal, TKey);
666 for (
int ic = 0; ic < keyChange; ic++)
667 Base[baseKeys[ic]] = baseVal[ic];
670 deadKeys.emplace_back(targetKey);
672 return static_cast<int>(deadKeys.size());
Triple of three different things.
Object generation rule tree.
int Eliminate()
elimination not written
Rule * getParent() const
Returns the parent object.
void setParent(Rule *)
Sets the parent object (not check for A==this)
virtual Rule * leaf(const int=0) const
No leaf for a base rule.
std::unique_ptr< Rule > clone() const
int commonType() const
Gets a common type.
Rule & operator=(const Rule &)
Assignment operator= does not set parent as Rules are cloned.
void makeParents()
This is initialisation code that populates all the parents in the rule tree.
int getKeyList(std::vector< int > &) const
Generate the key list given an insertion type object.
static int makeCNF(std::unique_ptr< Rule > &)
Make Rule into a CNF format.
virtual Rule * findKey(const int)=0
Abstract key find.
static int addToKey(std::vector< int > &AV, const int passN=-1)
Static function :: Given a vector AV increase the number from lowest to highest in an iterative count...
static int makeCNFcopy(std::unique_ptr< Rule > &)
Make Rule into a CNF format (slow)
virtual int findLeaf(const Rule *) const =0
Abstract find.
virtual void setLeaf(std::unique_ptr< Rule >, const int=0)=0
Abstract set.
static int removeItem(std::unique_ptr< Rule > &TRule, const int SurfN)
Given an item as a surface name, remove the surface from the Rule tree.
int substituteSurf(const int SurfN, const int newSurfN, const std::shared_ptr< Surface > &SPtr)
Substitues a surface item if within a rule.
Rule()
Standard Constructor.
Rule * Parent
Parent object (for tree)
virtual bool isValid(const Kernel::V3D &) const =0
Abstract: The point is within the object.
int checkParents() const
Debug test for parents.
static int removeComplementary(std::unique_ptr< Rule > &)
NOT WORKING.
virtual int simplify()=0
Abstract: Can the rule be simplified.
virtual int type() const
Null rule.
void setKeyN(const int Ky)
set keyNumber