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 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>());
481 std::stack<Rule *> Tree;
483 while (!Tree.empty()) {
484 Rule *Ptmp = Tree.top();
488 for (
int i = 0; i < 2; i++) {
507 std::stack<const Rule *> Tree;
509 while (!Tree.empty()) {
510 const Rule *Ptmp = Tree.top();
514 for (
int i = 0; i < 2; i++) {
536 const int rtype = this->
type();
540 std::stack<const Rule *> Tree;
541 Tree.push(this->
leaf(0));
542 Tree.push(this->
leaf(1));
543 while (!Tree.empty()) {
544 const Rule *tmpA = Tree.top();
547 if (tmpA->
type() == -rtype)
572 Ptr->
setKeyN(Ptr->getSign() * newSurfN);
590 std::stack<const Rule *> TreeLine;
592 while (!TreeLine.empty()) {
593 const Rule *tmpA = TreeLine.top();
603 const auto *SurX =
dynamic_cast<const SurfPoint *
>(tmpA);
605 IList.emplace_back(SurX->getKeyN());
607 logger.error() <<
"Error with surface List\n";
608 return static_cast<int>(IList.size());
612 std::sort(IList.begin(), IList.end());
613 auto px = std::unique(IList.begin(), IList.end());
614 IList.erase(px, IList.end());
615 return static_cast<int>(IList.size());
626 std::map<int, int> Base;
627 std::vector<int> baseVal;
628 std::vector<int> baseKeys;
629 std::vector<int> deadKeys;
632 std::vector<int>::const_iterator xv;
633 for (xv = baseKeys.begin(); xv != baseKeys.end(); ++xv) {
634 baseVal.emplace_back(0);
642 for (
unsigned int TKey = 0; TKey < baseKeys.size(); TKey++) {
644 int valueTrue(1), valueFalse(1);
646 int targetKey = baseKeys[TKey];
647 for (
unsigned int i = 0; i < baseVal.size(); i++) {
649 Base[baseKeys[i]] = 0;
653 while (valueTrue == valueFalse || keyChange >= 0) {
655 Base[baseKeys[targetKey]] = 0;
659 Base[baseKeys[targetKey]] = 1;
663 if (valueTrue == valueFalse) {
664 keyChange =
addToKey(baseVal, TKey);
665 for (
int ic = 0; ic < keyChange; ic++)
666 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