C++ mpi module for stochmagnet_main Package
EXPR_VariableNode.h
1 #ifndef EXPR_VariableNode_H
2 #define EXPR_VariableNode_H
3 
4 #include "EXPR_LeafNode.h"
5 
6 #include "EXPR_RootNode.h"
7 
17 class EXPR_VariableNode : public virtual EXPR_LeafNode {
18 
19 private:
20  //attributes
21 
22  tString mName;
23  CORE_UniquePointer<EXPR_RootNode> mTree;
24 
25 private:
26  //associations
27 protected:
28  //builders
29 
33  }
34 
35  //deleters
38  virtual ~EXPR_VariableNode() {
39  }
40 
41 public:
45  static inline CORE_UniquePointer<EXPR_VariableNode> New() {
46  CORE_UniquePointer<EXPR_VariableNode> p(new EXPR_VariableNode(),
48 
49  return p;
50  }
51 
52  //MEMORY
53  //======
61  virtual tMemSize getMemorySize() const override {
62  return sizeof(*this)+getContentsMemorySize();
63  }
64 
73  virtual tMemSize getContentsMemorySize() const override {
75  mem+=(mTree.get()==null)?0:mTree->getContentsMemorySize();
76  mem+=mName.size()*sizeof(tUChar);
77  return mem;
78  }
82  inline void setName(const tString& name) {
83  mName=name;
84  }
85 
89  inline void setExpression(CORE_UniquePointer<EXPR_RootNode> node) {
90  mTree=std::move(node);
91  }
95  inline const EXPR_RootNode* getExpression() const {
96  return mTree.get();
97  }
102  return mTree.get();
103  }
104 
105 
110  virtual tBoolean isInside(std::array<tReal,3> P) const override {
111  if (mTree.get()==null) return false;
112 
113  //test if the point p is in the box
114  if (!isInsideBoundingBox(P)) {
115  return false;
116  }
117 
118  //test if the transform point is inside the geometry
119  applyInverse(P);
120  return mTree->isInside(P);
121  }
122 
127  virtual void computeBoundingBox(std::map<tString,tBoolean>& alreadyComputed) override {
128  if (alreadyComputed.find(getIdentityString())==alreadyComputed.end()) {
129 
130  if (mTree.get()==null) return;
131 
132  mTree->computeBoundingBox(alreadyComputed);
133 
134  //get the value of the bounding box of thee tree
135 
136  const std::array<tReal,3>& P=mTree->getBoundingBoxMinPoint();
137  const std::array<tReal,3>& Q=mTree->getBoundingBoxMaxPoint();
138 
139  //copy it to point of variable
140  std::array<tReal,3>& minPoint=getBoundingBoxMinPoint();
141  std::array<tReal,3>& maxPoint=getBoundingBoxMaxPoint();
142 
143  memcpy(minPoint.data(),P.data(),P.size()*sizeof(tReal));
144  memcpy(maxPoint.data(),Q.data(),Q.size()*sizeof(tReal));
145 
146  alreadyComputed[getIdentityString()]=true;
147  }
148  }
149 
154  virtual void adimensionize(const tReal& L,std::map<tString,tBoolean>& alreadyComputed) override {
155  //cout << getIdentityString()<<"::EXPR_VariableNode::adimensionize("<<L<<") \n";
156  if (alreadyComputed.find(getIdentityString())==alreadyComputed.end()) {
157  if (mTree.get()!=null) {
158  //adimensionize the variable which has not been already adimensionized
159  mTree->adimensionize(L,alreadyComputed);
160  }
161  EXPR_LeafNode::adimensionize(L,alreadyComputed);
162  }
163  }
164 
165 public:
166 
170  virtual tString toString() const override {
171  return mName;
172  }
173 };
174 
175 
176 
177 
178 
179 #endif
180 
181 
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
tString getIdentityString() const
retrun the string identification of the class
Definition: CORE_Object.h:321
This class describes a leaf node of the tree without children.
Definition: EXPR_LeafNode.h:15
virtual tMemSize getContentsMemorySize() const override
return nthe memory size of the included associations
Definition: EXPR_LeafNode.h:62
virtual void adimensionize(const tReal &L, std::map< tString, tBoolean > &alreadyComputed)
adimensionize the node
Definition: EXPR_Node.cpp:135
const std::array< tReal, 3 > & getBoundingBoxMinPoint() const
get the min point bounding box of the node for reading
Definition: EXPR_Node.h:652
tBoolean isInsideBoundingBox(const std::array< tReal, 3 > &P) const
return true if the point P is in the bounding box
Definition: EXPR_Node.h:694
const std::array< tReal, 3 > & getBoundingBoxMaxPoint() const
get the max point bounding box of the node for reading
Definition: EXPR_Node.h:658
void applyInverse(std::array< tReal, 3 > &P) const
apply the inverse transformation to point P
Definition: EXPR_Node.h:550
This class describes the root of the tree.
Definition: EXPR_RootNode.h:16
This class describes a variable node with contains:
Definition: EXPR_VariableNode.h:17
void setName(const tString &name)
set the name of the variable
Definition: EXPR_VariableNode.h:82
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: EXPR_VariableNode.h:61
const EXPR_RootNode * getExpression() const
get the expression of the variable
Definition: EXPR_VariableNode.h:95
virtual tMemSize getContentsMemorySize() const override
return nthe memory size of the included associations
Definition: EXPR_VariableNode.h:73
virtual tString toString() const override
return the string representation of this
Definition: EXPR_VariableNode.h:170
virtual ~EXPR_VariableNode()
delete the class
Definition: EXPR_VariableNode.h:38
virtual tBoolean isInside(std::array< tReal, 3 > P) const override
return true if the point is in the node
Definition: EXPR_VariableNode.h:110
virtual void computeBoundingBox(std::map< tString, tBoolean > &alreadyComputed) override
compute the bounding box of the node
Definition: EXPR_VariableNode.h:127
EXPR_RootNode * getExpression()
get the expression of the variable
Definition: EXPR_VariableNode.h:101
static CORE_UniquePointer< EXPR_VariableNode > New()
crete the new instance of this
Definition: EXPR_VariableNode.h:45
EXPR_VariableNode()
create the class
Definition: EXPR_VariableNode.h:32
virtual void adimensionize(const tReal &L, std::map< tString, tBoolean > &alreadyComputed) override
adimensionize the node
Definition: EXPR_VariableNode.h:154
void setExpression(CORE_UniquePointer< EXPR_RootNode > node)
set the expression of the variable
Definition: EXPR_VariableNode.h:89