From a9de89ef70ae5b78c1f1f655d068a9d9bf115491 Mon Sep 17 00:00:00 2001 From: ageay Date: Mon, 29 Sep 2008 07:24:29 +0000 Subject: [PATCH] *** empty log message *** --- src/INTERP_KERNEL/Geometric2D/Bounds.cxx | 18 ++++--- src/INTERP_KERNEL/Geometric2D/Bounds.hxx | 5 +- .../Geometric2D/ComposedEdge.cxx | 24 +++++++-- .../Geometric2D/ComposedEdge.hxx | 1 + src/INTERP_KERNEL/Geometric2D/Edge.cxx | 6 ++- .../Geometric2D/EdgeArcCircle.cxx | 2 + .../Geometric2D/EdgeArcCircle.hxx | 4 +- src/INTERP_KERNEL/Geometric2D/Node.cxx | 35 ++++++------- src/INTERP_KERNEL/Geometric2D/Node.hxx | 3 +- .../Geometric2D/QuadraticPolygon.cxx | 16 ++++++ .../Geometric2D/QuadraticPolygon.hxx | 2 + .../Test/QuadraticPlanarInterpTest4.cxx | 50 +++++++++++++++++++ 12 files changed, 131 insertions(+), 35 deletions(-) diff --git a/src/INTERP_KERNEL/Geometric2D/Bounds.cxx b/src/INTERP_KERNEL/Geometric2D/Bounds.cxx index 3def5ad51..850a39249 100644 --- a/src/INTERP_KERNEL/Geometric2D/Bounds.cxx +++ b/src/INTERP_KERNEL/Geometric2D/Bounds.cxx @@ -3,8 +3,6 @@ #include "EdgeArcCircle.hxx" #include "Node.hxx" -#include - using namespace INTERP_KERNEL; const double& Bounds::operator[](int i) const @@ -46,6 +44,17 @@ double Bounds::getDiagonal() const return sqrt(a*a+b*b); } +/*! + * See Node::applySimilarity to see signification of params. + */ +void Bounds::applySimilarity(double xBary, double yBary, double dimChar) +{ + _xMin=(_xMin-xBary)/dimChar; + _xMax=(_xMax-xBary)/dimChar; + _yMin=(_yMin-yBary)/dimChar; + _yMax=(_yMax-yBary)/dimChar; +} + void Bounds::getBarycenter(double& xBary, double& yBary) const { xBary=(_xMin+_xMax)/2.; @@ -168,8 +177,3 @@ void Bounds::aggregate(const Bounds& other) _xMin=fmin(_xMin,other._xMin); _xMax=fmax(_xMax,other._xMax); _yMin=fmin(_yMin,other._yMin); _yMax=fmax(_yMax,other._yMax); } - -double Bounds::getCaracteristicDim() const -{ - return fmax(_xMax-_xMin,_yMax-_yMin); -} diff --git a/src/INTERP_KERNEL/Geometric2D/Bounds.hxx b/src/INTERP_KERNEL/Geometric2D/Bounds.hxx index 85d6378cd..485be9cb5 100644 --- a/src/INTERP_KERNEL/Geometric2D/Bounds.hxx +++ b/src/INTERP_KERNEL/Geometric2D/Bounds.hxx @@ -1,6 +1,8 @@ #ifndef __BOUNDS_HXX__ #define __BOUNDS_HXX__ +#include + namespace INTERP_KERNEL { /*! @@ -22,6 +24,7 @@ namespace INTERP_KERNEL const double& operator[](int i) const; double getDiagonal() const; void getBarycenter(double& xBary, double& yBary) const; + void applySimilarity(double xBary, double yBary, double dimChar); Bounds& operator=(const Bounds& other) { _xMin=other._xMin; _xMax=other._xMax; _yMin=other._yMin; _yMax=other._yMax; return *this; } Bounds(double xMin, double xMax, double yMin, double yMax):_xMin(xMin),_xMax(xMax),_yMin(yMin),_yMax(yMax) { } void setValues(double xMin, double xMax, double yMin, double yMax) { _xMin=xMin; _xMax=xMax; _yMin=yMin; _yMax=yMax; } @@ -38,7 +41,7 @@ namespace INTERP_KERNEL //! Idem where method but with approximations. Position nearlyWhere(double x, double y) const; void aggregate(const Bounds& other); - double getCaracteristicDim() const; + double getCaracteristicDim() const { return fmax(_xMax-_xMin,_yMax-_yMin); } protected: double _xMin; double _xMax; diff --git a/src/INTERP_KERNEL/Geometric2D/ComposedEdge.cxx b/src/INTERP_KERNEL/Geometric2D/ComposedEdge.cxx index 6b69bad8c..8618922c5 100644 --- a/src/INTERP_KERNEL/Geometric2D/ComposedEdge.cxx +++ b/src/INTERP_KERNEL/Geometric2D/ComposedEdge.cxx @@ -133,13 +133,13 @@ double ComposedEdge::normalize(ComposedEdge *other) { Bounds b; b.prepareForAggregation(); - fillBounds(b); + fillBounds(b); other->fillBounds(b); - double dimChar=b.getDiagonal(); + double dimChar=b.getCaracteristicDim(); double xBary,yBary; b.getBarycenter(xBary,yBary); - applySimilarity(xBary,yBary,dimChar); - other->applySimilarity(xBary,yBary,dimChar); + applyGlobalSimilarity(xBary,yBary,dimChar); + other->applyGlobalSimilarity(xBary,yBary,dimChar); return dimChar; } @@ -176,12 +176,28 @@ void ComposedEdge::fillBounds(Bounds& output) const (*iter)->fillBounds(output); } +/*! + * \b WARNING : applies similarity \b ONLY on edges without any change on Nodes. To perform a global similarity call applyGlobalSimilarity. + */ void ComposedEdge::applySimilarity(double xBary, double yBary, double dimChar) { for(list::iterator iter=_subEdges.begin();iter!=_subEdges.end();iter++) (*iter)->applySimilarity(xBary,yBary,dimChar); } +/*! + * Perform Similarity transformation on all elements of this Nodes and Edges. + */ +void ComposedEdge::applyGlobalSimilarity(double xBary, double yBary, double dimChar) +{ + set allNodes; + getAllNodes(allNodes); + for(set::iterator iter=allNodes.begin();iter!=allNodes.end();iter++) + (*iter)->applySimilarity(xBary,yBary,dimChar); + for(list::iterator iter=_subEdges.begin();iter!=_subEdges.end();iter++) + (*iter)->applySimilarity(xBary,yBary,dimChar); +} + /*! * @param part1 INOUT parameter. If an edge in 'this' is found with an id in 'ids1', 'part1' is \b incremented. * @param part2 INOUT parameter. If an edge in 'this' is found with an id in 'ids2', 'part2' is \b incremented. diff --git a/src/INTERP_KERNEL/Geometric2D/ComposedEdge.hxx b/src/INTERP_KERNEL/Geometric2D/ComposedEdge.hxx index b02d8f6ff..da20266d0 100644 --- a/src/INTERP_KERNEL/Geometric2D/ComposedEdge.hxx +++ b/src/INTERP_KERNEL/Geometric2D/ComposedEdge.hxx @@ -33,6 +33,7 @@ namespace INTERP_KERNEL double normalize(ComposedEdge *other); void fillBounds(Bounds& output) const; void applySimilarity(double xBary, double yBary, double dimChar); + void applyGlobalSimilarity(double xBary, double yBary, double dimChar); void dispatchPerimeter(const std::set& ids1, const std::set& ids2, double& part1, double& part2, double& commonPart) const; double dispatchPerimeterAdv(const ComposedEdge& father, std::vector& result) const; diff --git a/src/INTERP_KERNEL/Geometric2D/Edge.cxx b/src/INTERP_KERNEL/Geometric2D/Edge.cxx index 708873564..574e277cf 100644 --- a/src/INTERP_KERNEL/Geometric2D/Edge.cxx +++ b/src/INTERP_KERNEL/Geometric2D/Edge.cxx @@ -644,10 +644,12 @@ Intersector *Edge::buildIntersectorWith(const Edge *e1, const Edge *e2) return ret; } +/*! + * See Node::applySimilarity to see signification of params. + */ void Edge::applySimilarity(double xBary, double yBary, double dimChar) { - _start->applySimilarity(xBary,yBary,dimChar); - _end->applySimilarity(xBary,yBary,dimChar); + _bounds.applySimilarity(xBary,yBary,dimChar); } bool Edge::intersect(const Edge *f1, const Edge *f2, Intersector *intersector, const Bounds *whereToFind, MergePoints& commonNode, diff --git a/src/INTERP_KERNEL/Geometric2D/EdgeArcCircle.cxx b/src/INTERP_KERNEL/Geometric2D/EdgeArcCircle.cxx index 3d94d2021..38f0aa027 100644 --- a/src/INTERP_KERNEL/Geometric2D/EdgeArcCircle.cxx +++ b/src/INTERP_KERNEL/Geometric2D/EdgeArcCircle.cxx @@ -464,6 +464,8 @@ void EdgeArcCircle::applySimilarity(double xBary, double yBary, double dimChar) { Edge::applySimilarity(xBary,yBary,dimChar); _radius/=dimChar; + _center[0]=(_center[0]-xBary)/dimChar; + _center[1]=(_center[1]-yBary)/dimChar; } double EdgeArcCircle::getAbsoluteAngle(const double *vect, double& normVect) diff --git a/src/INTERP_KERNEL/Geometric2D/EdgeArcCircle.hxx b/src/INTERP_KERNEL/Geometric2D/EdgeArcCircle.hxx index 90bdbcf18..3448e69e2 100644 --- a/src/INTERP_KERNEL/Geometric2D/EdgeArcCircle.hxx +++ b/src/INTERP_KERNEL/Geometric2D/EdgeArcCircle.hxx @@ -90,9 +90,9 @@ namespace INTERP_KERNEL void updateBounds(); Edge *buildEdgeLyingOnMe(Node *start, Node *end, bool direction=true) const; protected: - //Value between -2Pi and 2Pi + //!Value between -2Pi and 2Pi double _angle; - //Value between -Pi and Pi + //!Value between -Pi and Pi double _angle0; double _radius; double _center[2]; diff --git a/src/INTERP_KERNEL/Geometric2D/Node.cxx b/src/INTERP_KERNEL/Geometric2D/Node.cxx index 5a0aaf022..031fba515 100644 --- a/src/INTERP_KERNEL/Geometric2D/Node.cxx +++ b/src/INTERP_KERNEL/Geometric2D/Node.cxx @@ -4,33 +4,28 @@ using namespace std; using namespace INTERP_KERNEL; -Node::Node(double x, double y):_isToDel(true),_cnt(1),_loc(UNKNOWN) +Node::Node(double x, double y):_cnt(1),_loc(UNKNOWN) { - const unsigned SPACEDIM=2; - _coords=new double[SPACEDIM]; _coords[0]=x; _coords[1]=y; } -Node::Node(const double *coords):_isToDel(false),_cnt(1),_loc(UNKNOWN),_coords((double *)coords) +Node::Node(const double *coords):_cnt(1),_loc(UNKNOWN) { + _coords[0]=coords[0]; + _coords[1]=coords[1]; } -Node::Node(std::istream& stream):_isToDel(true),_cnt(1),_loc(UNKNOWN) +Node::Node(std::istream& stream):_cnt(1),_loc(UNKNOWN) { - const unsigned SPACEDIM=2; - _coords=new double[SPACEDIM]; - for(unsigned i=0;i> tmp; - _coords[i]=((double) tmp)/1e4; - } + int tmp; + stream >> tmp; + _coords[0]=((double) tmp)/1e4; + stream >> tmp; + _coords[1]=((double) tmp)/1e4; } Node::~Node() { - if(_isToDel) - delete [] _coords; } bool Node::decrRef() @@ -110,8 +105,14 @@ double Node::computeAngle(const double *pt1, const double *pt2) return -ret; } +/*! + * apply a Similarity transformation on this. + * @param xBary is the opposite of the X translation to do. + * @param yBary is the opposite of the Y translation to do. + * @param dimChar is the reduction factor. + */ void Node::applySimilarity(double xBary, double yBary, double dimChar) { - _coords[0]=(_coords[0]+xBary)/dimChar; - _coords[1]=(_coords[1]+yBary)/dimChar; + _coords[0]=(_coords[0]-xBary)/dimChar; + _coords[1]=(_coords[1]-yBary)/dimChar; } diff --git a/src/INTERP_KERNEL/Geometric2D/Node.hxx b/src/INTERP_KERNEL/Geometric2D/Node.hxx index 961090050..8752461a3 100644 --- a/src/INTERP_KERNEL/Geometric2D/Node.hxx +++ b/src/INTERP_KERNEL/Geometric2D/Node.hxx @@ -65,10 +65,9 @@ namespace INTERP_KERNEL protected: ~Node(); protected: - bool _isToDel; mutable unsigned char _cnt; mutable TypeOfLocInPolygon _loc; - double *_coords; + double _coords[2]; }; } diff --git a/src/INTERP_KERNEL/Geometric2D/QuadraticPolygon.cxx b/src/INTERP_KERNEL/Geometric2D/QuadraticPolygon.cxx index 3f0c2e890..dca8f06ff 100644 --- a/src/INTERP_KERNEL/Geometric2D/QuadraticPolygon.cxx +++ b/src/INTERP_KERNEL/Geometric2D/QuadraticPolygon.cxx @@ -145,6 +145,22 @@ void QuadraticPolygon::dumpInXfigFile(std::ostream& stream, int resolution, cons ComposedEdge::dumpInXfigFile(stream,resolution,box); } +/*! + * Warning contrary to intersectWith method this method is \b NOT const. 'this' and 'other' are modified after call of this method. + */ +double QuadraticPolygon::intersectWithAbs(QuadraticPolygon& other) +{ + double ret=0.; + double fact=normalize(&other); + vector polygs=intersectMySelfWith(other); + for(vector::iterator iter=polygs.begin();iter!=polygs.end();iter++) + { + ret+=fabs((*iter)->getArea()); + delete *iter; + } + return ret*fact*fact; +} + double QuadraticPolygon::intersectWith(const QuadraticPolygon& other) const { double ret=0.; diff --git a/src/INTERP_KERNEL/Geometric2D/QuadraticPolygon.hxx b/src/INTERP_KERNEL/Geometric2D/QuadraticPolygon.hxx index 301c991a8..7d69dbcd1 100644 --- a/src/INTERP_KERNEL/Geometric2D/QuadraticPolygon.hxx +++ b/src/INTERP_KERNEL/Geometric2D/QuadraticPolygon.hxx @@ -27,6 +27,8 @@ namespace INTERP_KERNEL void circularPermute(); void dumpInXfigFile(const char *fileName) const; void dumpInXfigFileWithOther(const ComposedEdge& other, const char *fileName) const; + //! Before intersecting as intersectWith a normalization is done. + double intersectWithAbs(QuadraticPolygon& other); double intersectWith(const QuadraticPolygon& other) const; std::vector intersectMySelfWith(const QuadraticPolygon& other) const; void intersectForPerimeter(const QuadraticPolygon& other, double& perimeterThisPart, double& perimeterOtherPart, double& perimeterCommonPart, double& area) const; diff --git a/src/INTERP_KERNEL/Test/QuadraticPlanarInterpTest4.cxx b/src/INTERP_KERNEL/Test/QuadraticPlanarInterpTest4.cxx index 5dd6639f3..38edb6b1b 100644 --- a/src/INTERP_KERNEL/Test/QuadraticPlanarInterpTest4.cxx +++ b/src/INTERP_KERNEL/Test/QuadraticPlanarInterpTest4.cxx @@ -1081,3 +1081,53 @@ void QuadraticPlanarInterpTest::checkNonRegression12() delete pol1; delete pol2; } + +void QuadraticPlanarInterpTest::checkNormalize() +{ + INTERP_KERNEL::QUADRATIC_PLANAR::setPrecision(1e-14); + Node *n1=new Node(0.,0.); Node *n4=new Node(0.,-3.); + Node *n2=new Node(10.,0.); Node *n5=new Node(10.,-3.); + Node *n3=new Node(5.,10.); Node *n6=new Node(5.,7.); + EdgeLin *e1_2=new EdgeLin(n1,n2); EdgeLin *e4_5=new EdgeLin(n4,n5); + EdgeLin *e2_3=new EdgeLin(n2,n3); EdgeLin *e5_6=new EdgeLin(n5,n6); + EdgeLin *e3_1=new EdgeLin(n3,n1); EdgeLin *e6_4=new EdgeLin(n6,n4); + // + QuadraticPolygon pol1; pol1.pushBack(e1_2); pol1.pushBack(e2_3); pol1.pushBack(e3_1); + QuadraticPolygon pol2; pol2.pushBack(e4_5); pol2.pushBack(e5_6); pol2.pushBack(e6_4); + n1->decrRef(); n2->decrRef(); n3->decrRef(); n4->decrRef(); n5->decrRef(); n6->decrRef(); + double area1Start=pol1.getArea(); + double fact=pol1.normalize(&pol2); + double area1End=pol1.getArea(); + CPPUNIT_ASSERT_DOUBLES_EQUAL(area1Start,area1End*fact*fact,1e-14); + CPPUNIT_ASSERT_DOUBLES_EQUAL(13.,fact,1.e-14); + double area=pol1.intersectWith(pol2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(24.5,area*fact*fact,1e-14); + // + n1=new Node(0.,0.); n4=new Node(0.,-3.); + n2=new Node(10.,0.); n5=new Node(10.,-3.); + n3=new Node(5.,10.); n6=new Node(5.,7.); + e1_2=new EdgeLin(n1,n2); e4_5=new EdgeLin(n4,n5); + e2_3=new EdgeLin(n2,n3); e5_6=new EdgeLin(n5,n6); + e3_1=new EdgeLin(n3,n1); e6_4=new EdgeLin(n6,n4); + QuadraticPolygon pol3; pol3.pushBack(e1_2); pol3.pushBack(e2_3); pol3.pushBack(e3_1); + QuadraticPolygon pol4; pol4.pushBack(e4_5); pol4.pushBack(e5_6); pol4.pushBack(e6_4); + n1->decrRef(); n2->decrRef(); n3->decrRef(); n4->decrRef(); n5->decrRef(); n6->decrRef(); + CPPUNIT_ASSERT_DOUBLES_EQUAL(24.5,pol3.intersectWithAbs(pol4),1.e-14); + // Ok testing EdgeArcCircle update. + double center[2]={5.,5.}; + double radius=300.; + EdgeArcCircle *e1=buildArcOfCircle(center,radius,M_PI/4.,M_PI/3.); + const Bounds& b=e1->getBounds(); + double x,y,fact2; + fact2=b.getCaracteristicDim(); + b.getBarycenter(x,y); + CPPUNIT_ASSERT_DOUBLES_EQUAL(78.539816339744817,e1->getCurveLength(),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(15106.061037591669,e1->getAreaOfZone(),1e-10); + e1->getStartNode()->applySimilarity(x,y,fact2); + e1->getEndNode()->applySimilarity(x,y,fact2); + e1->applySimilarity(x,y,fact2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(62.132034355964237,fact2,1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.2640792652913602,e1->getCurveLength(),1e-14); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.034741420428165526,e1->getAreaOfZone(),1e-13); + e1->decrRef(); +} -- 2.39.2