5 #include "EXPR_Object.h"
8 #include "core_numeric.h"
22 static const std::array<tBoolean,24> BOUNDING_BOX_POINTS;
29 std::array<tReal,3> mMinPoint;
30 std::array<tReal,3> mMaxPoint;
35 std::array<tReal,9> mAlpha;
36 std::array<tReal,9> mA;
37 std::array<tReal,3> mBeta;
39 std::array<tReal,3> mWork;
81 mem+=mBeta.size()*
sizeof(tReal);
82 mem+=mA.size()*
sizeof(tReal);
83 mem+=mAlpha.size()*
sizeof(tReal);
84 mem+=mMinPoint.size()*
sizeof(tReal);
85 mem+=mMaxPoint.size()*
sizeof(tReal);
100 memcpy(mAlpha.data(),node.
getAlpha().data(),
sizeof(tReal)*mAlpha.size());
101 memcpy(mBeta.data(),node.
getBeta().data(),
sizeof(tReal)*mBeta.size());
113 inline void setAlpha(std::initializer_list<tReal>&& alpha) {
114 auto iAlpha=std::cbegin(alpha);
115 for(
auto& alpha_i:mAlpha) {
126 inline void setBeta(std::initializer_list<tReal>&& beta) {
127 auto iBeta=std::cbegin(beta);
128 for(
auto& beta_i:mBeta) {
136 inline void addToBeta(std::initializer_list<tReal>&& beta) {
137 auto iBeta=std::cbegin(beta);
138 for(
auto& bi: mBeta) {
147 inline const std::array<tReal,3>&
getBeta()
const {
153 inline const std::array<tReal,9>&
getAlpha()
const {
167 const std::array<tReal,3>& B) {
174 tReal *iW=mWork.data();
175 const tReal *eW=iW;eW+=mWork.size();
177 const tReal *Aik=A.data();
179 tReal *iBeta=mBeta.data();
180 const tReal *eBeta=iBeta;eBeta+=mBeta.size();
188 while (iBeta!=eBeta) {
190 (*iW)+=(*Aik)*(*iBeta);
204 const tReal *iB=B.data();
205 while (iBeta!=eBeta) {
208 (*iBeta)=(*iW)+(*iB);
217 alphaLeftComposition(A);
233 tReal *iW=mWork.data();
234 const tReal *eW=iW;eW+=mWork.size();
236 const tReal *Aik=A.data();
238 tReal *iBeta=mBeta.data();
239 const tReal *eBeta=iBeta;eBeta+=mBeta.size();
246 while (iBeta!=eBeta) {
249 (*iW)+=(*Aik)*(*iBeta);
261 memcpy(mBeta.data(),mWork.data(),mWork.size()*
sizeof(tReal));
266 alphaLeftComposition(A);
279 if (fabs(s)<1.e-12) s=0;
280 if (fabs(c)<1.e-12) c=0;
281 std::array<tReal,9> rot={0,0,0,0,0,0,0,0,0};
295 inline void rotation(
const tReal& theta,
const tReal& Ax,
const tReal& Ay,
const tReal& Az) {
298 if (fabs(s)<1.e-12) s=0;
299 if (fabs(c)<1.e-12) c=0;
300 std::array<tReal,9> rot={0,0,0,0,0,0,0,0,0};
301 tReal N=sqrt(Ax*Ax+Ay*Ay+Az*Az);
306 rot[0]=Ux*Ux*(1-c)+c;
307 rot[1]=Ux*Uy*(1-c)-Uz*s;
308 rot[2]=Ux*Uz*(1-c)+Uy*s;
310 rot[3]=Uy*Ux*(1-c)+Uz*s;
311 rot[4]=Uy*Uy*(1-c)+c;
312 rot[5]=Uy*Uz*(1-c)-Ux*s;
314 rot[6]=Uz*Ux*(1-c)-Uy*s;
315 rot[7]=Uz*Uy*(1-c)+Ux*s;
316 rot[8]=Uz*Uz*(1-c)+c;
329 const tReal& Ax,
const tReal& Ay,
const tReal& Az,
330 const tReal& Cx,
const tReal& Cy,
const tReal& Cz) {
335 if (fabs(s)<1.e-12) s=0;
336 if (fabs(c)<1.e-12) c=0;
337 std::array<tReal,9> rot={0,0,0,0,0,0,0,0,0};
338 tReal N=sqrt(Ax*Ax+Ay*Ay+Az*Az);
340 std::array<tReal,3> U;
348 rot[0]=Ux*Ux*(1-c)+c;
349 rot[1]=Ux*Uy*(1-c)-Uz*s;
350 rot[2]=Ux*Uz*(1-c)+Uy*s;
352 rot[3]=Uy*Ux*(1-c)+Uz*s;
353 rot[4]=Uy*Uy*(1-c)+c;
354 rot[5]=Uy*Uz*(1-c)-Ux*s;
356 rot[6]=Uz*Ux*(1-c)-Uy*s;
357 rot[7]=Uz*Uy*(1-c)+Ux*s;
358 rot[8]=Uz*Uz*(1-c)+c;
363 const tReal *Rij=rot.data();
386 const tReal *iT=T.data();
387 for(
auto& Bi:mBeta) {
400 inline static void Inverse(
const std::array<tReal,9>& A,std::array<tReal,9>& invA) {
401 const tReal *alpha=A.data();
403 const tReal &A00=*alpha;alpha++;
404 const tReal &A01=*alpha;alpha++;
405 const tReal &A02=*alpha;alpha++;
406 const tReal &A10=*alpha;alpha++;
407 const tReal &A11=*alpha;alpha++;
408 const tReal &A12=*alpha;alpha++;
409 const tReal &A20=*alpha;alpha++;
410 const tReal &A21=*alpha;alpha++;
411 const tReal &A22=*alpha;
414 tReal *beta=invA.data();
415 tReal detA=A00*A11*A22+A01*A12*A20+A02*A10*A21-A02*A11*A20-A12*A21*A00-A22*A01*A10;
416 *beta=(A11*A22-A12*A21)/detA;beta++;
417 *beta=(A02*A21-A01*A22)/detA;beta++;
418 *beta=(A01*A12-A02*A11)/detA;beta++;
419 *beta=(A12*A20-A10*A22)/detA;beta++;
420 *beta=(A00*A22-A02*A20)/detA;beta++;
421 *beta=(A02*A10-A00*A12)/detA;beta++;
422 *beta=(A10*A21-A11*A20)/detA;beta++;
423 *beta=(A01*A20-A00*A21)/detA;beta++;
424 *beta=(A00*A11-A01*A10)/detA;
430 inline void alphaLeftComposition(
const std::array<tReal,9>& B) {
439 tReal *Aij=mA.data();
441 const tReal *Bik,*Bi=B.data(),*eBi=Bi+B.size();
442 tReal *alpha_j,*alpha_kj;
443 const tReal *eAlpha=mAlpha.data()+3;
448 alpha_j=mAlpha.data();
449 while (alpha_j!=eAlpha) {
458 (*Aij)+=(*Bik)*(*alpha_kj);
474 memcpy(mAlpha.data(),mA.data(),mA.size()*
sizeof(tReal));
485 inline void apply(std::array<tReal,3>& P)
const {
492 P[0]=mAlpha[0]*(Px)+mAlpha[1]*(Py)+mAlpha[2]*(Pz)+mBeta[0];
493 P[1]=mAlpha[3]*(Px)+mAlpha[4]*(Py)+mAlpha[5]*(Pz)+mBeta[1];
494 P[2]=mAlpha[6]*(Px)+mAlpha[7]*(Py)+mAlpha[8]*(Pz)+mBeta[2];
502 inline tBoolean
apply(
const std::array<tReal,3>& P,std::array<tReal,3>& Q)
const {
504 if (P.data()==Q.data())
return false;
509 const tReal *iB=mBeta.data();
510 const tReal *eB=iB;eB+=mBeta.size();
517 const tReal *eP=P.data();eP+=P.size();
520 const tReal *Aki=mAlpha.data();
557 P[0]=mA[0]*(Px-mBeta[0])+mA[1]*(Py-mBeta[1])+mA[2]*(Pz-mBeta[2]);
558 P[1]=mA[3]*(Px-mBeta[0])+mA[4]*(Py-mBeta[1])+mA[5]*(Pz-mBeta[2]);
559 P[2]=mA[6]*(Px-mBeta[0])+mA[7]*(Py-mBeta[1])+mA[8]*(Pz-mBeta[2]);
568 std::array<tReal,3>& Q)
const {
571 if (P.data()==Q.data())
return false;
574 const tReal *iB=mBeta.data();
579 const tReal *eQ=iQ;eQ+=Q.size();
583 const tReal *eP=P.data();eP+=P.size();
586 const tReal *Aki=mA.data();
603 (*iQ)+=(*Aki)*((*iP)-(*iB));
629 inline static void SetEpsilon(
const tReal& eps) {EPSILON=eps;};
641 virtual void adimensionize(
const tReal& L,std::map<tString,tBoolean>& alreadyComputed);
696 const tReal *mk=mMinPoint.data();
697 const tReal *Mk=mMaxPoint.data();
699 if ( (EPSILON<(*mk)-(Pk)) || ((Pk)-(*Mk)>EPSILON) )
return false;
711 virtual tBoolean
isInside(std::array<tReal,3> M)
const=0;
721 virtual tString
toString()
const override;
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278
This class is a base class of the binary tree.
Definition: EXPR_Node.h:16
virtual void adimensionize(const tReal &L, std::map< tString, tBoolean > &alreadyComputed)
adimensionize the node
Definition: EXPR_Node.cpp:135
virtual tMemSize getContentsMemorySize() const override
return nthe memory size of the included associations
Definition: EXPR_Node.h:79
void addToBeta(std::initializer_list< tReal > &&beta)
add to the constant by column
Definition: EXPR_Node.h:136
void leftComposition(const std::array< tReal, 9 > &A, const std::array< tReal, 3 > &B)
compose by the affine function
Definition: EXPR_Node.h:166
const std::array< tReal, 9 > & getAlpha() const
get the alpha value
Definition: EXPR_Node.h:153
static void SetEpsilon(const tReal &eps)
set the tolerance error
Definition: EXPR_Node.h:629
std::array< tReal, 3 > & getBoundingBoxMaxPoint()
get the max point bounding box of the node for writing
Definition: EXPR_Node.h:671
const std::array< tReal, 3 > & getBoundingBoxMinPoint() const
get the min point bounding box of the node for reading
Definition: EXPR_Node.h:652
void linearTransformBoundingBox(std::array< tReal, 3 > &P, std::array< tReal, 3 > &Q) const
compute the bounding box after transformation
Definition: EXPR_Node.cpp:44
virtual tBoolean isInside(std::array< tReal, 3 > M) const =0
return true if the point is in the bounding box of the node
void rotation(const tReal &theta, const tReal &Ax, const tReal &Ay, const tReal &Az, const tReal &Cx, const tReal &Cy, const tReal &Cz)
compute the rotation of the geometry with angle theta and axis (Ax,Ay,Az)a and center (Cx,...
Definition: EXPR_Node.h:328
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: EXPR_Node.h:67
virtual ~EXPR_Node()
delete the class
Definition: EXPR_Node.cpp:40
std::array< tReal, 3 > & getBoundingBoxMinPoint()
get the min point bounding box of the node for writing
Definition: EXPR_Node.h:665
void leftComposition(const std::array< tReal, 9 > &A)
compose by the affine function
Definition: EXPR_Node.h:225
const std::array< tReal, 3 > & getBeta() const
get the beta value
Definition: EXPR_Node.h:147
void rotation(const tReal &theta, const tReal &Ax, const tReal &Ay, const tReal &Az)
compute the rotation of the geometry with angle theta and axis (Ax,Ay,Az)
Definition: EXPR_Node.h:295
tBoolean applyInverse(const std::array< tReal, 3 > &P, std::array< tReal, 3 > &Q) const
apply the inverse transformation to point P
Definition: EXPR_Node.h:567
void translate(const std::array< tReal, 3 > &T)
translate the geometry
Definition: EXPR_Node.h:385
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
void setBeta(std::initializer_list< tReal > &&beta)
set the constant by column
Definition: EXPR_Node.h:126
void setAlpha(std::initializer_list< tReal > &&alpha)
set the matrix alpha by row
Definition: EXPR_Node.h:113
EXPR_Node()
create the class
Definition: EXPR_Node.cpp:18
virtual tString toString() const override
return the string representation of this
Definition: EXPR_Node.cpp:145
const std::array< tReal, 3 > & getBoundingBoxMaxPoint() const
get the max point bounding box of the node for reading
Definition: EXPR_Node.h:658
tBoolean apply(const std::array< tReal, 3 > &P, std::array< tReal, 3 > &Q) const
apply the transformation to point P
Definition: EXPR_Node.h:502
void apply(std::array< tReal, 3 > &P) const
apply the transformation to point P
Definition: EXPR_Node.h:485
static const tReal & GetEpsilon()
get the tolerance error
Definition: EXPR_Node.h:634
virtual void computeBoundingBox(std::map< tString, tBoolean > &alreadyComputed)=0
compute the bounding box of the node
void rotation(const tReal &theta)
compute the rotation of the geometry with angle theta and k-axis
Definition: EXPR_Node.h:276
void applyInverse(std::array< tReal, 3 > &P) const
apply the inverse transformation to point P
Definition: EXPR_Node.h:550
virtual void copy(const EXPR_Node &node)
copy
Definition: EXPR_Node.h:93
This class is the base class of all the parser package.
Definition: EXPR_Object.h:27