X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModelGeomAlgo%2FModelGeomAlgo_Point2D.cpp;h=19328db10fcc361a6e0526a72ac33d2d95188925;hb=d04ea67117f609da08de8ae7631e8f2f844ea437;hp=70cd9cb72e59f4c4ea8ca550c86c1b4170dbe065;hpb=a2ab2dc339b560c7309540e1f10b6ad60e5ed0af;p=modules%2Fshaper.git diff --git a/src/ModelGeomAlgo/ModelGeomAlgo_Point2D.cpp b/src/ModelGeomAlgo/ModelGeomAlgo_Point2D.cpp old mode 100755 new mode 100644 index 70cd9cb72..19328db10 --- a/src/ModelGeomAlgo/ModelGeomAlgo_Point2D.cpp +++ b/src/ModelGeomAlgo/ModelGeomAlgo_Point2D.cpp @@ -1,8 +1,21 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: ModelAPI_Tools.cpp -// Created: 20 Jul 2016 -// Author: Natalia ERMOLAEVA +// Copyright (C) 2014-2020 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include "ModelGeomAlgo_Point2D.h" @@ -26,6 +39,12 @@ #include #include #include +#include + +//#define DEBUG_POINT_INSIDE_SHAPE +#ifdef DEBUG_POINT_INSIDE_SHAPE +#include +#endif #ifdef WIN32 #pragma warning(disable : 4996) // for sprintf @@ -156,6 +175,9 @@ void appendPoint(const std::shared_ptr& thePoint, anObjects.push_back(theResult); thePointToAttributeOrObject[thePoint] = std::make_pair(anAttributes, anObjects); } +#ifdef DEBUG_POINT_INSIDE_SHAPE + std::cout << "["<< thePoint->x() << ", " << thePoint->y() << "," << thePoint->z() << "]"; +#endif } } @@ -191,10 +213,14 @@ void appendShapePoints(const GeomShapePtr& theShape, } } -void ModelGeomAlgo_Point2D::getPointsIntersectedShape(const std::shared_ptr& theBaseFeature, +void ModelGeomAlgo_Point2D::getPointsIntersectedShape( + const std::shared_ptr& theBaseFeature, const std::list >& theFeatures, PointToRefsMap& thePointToAttributeOrObject) { +#ifdef DEBUG_POINT_INSIDE_SHAPE + std::cout << "ModelGeomAlgo_Point2D::getPointsIntersectedShape" << std::endl; +#endif GeomShapePtr aFeatureShape; { std::set anEdgeShapes; @@ -222,7 +248,15 @@ void ModelGeomAlgo_Point2D::getPointsIntersectedShape(const std::shared_ptrshape(); GeomShapePtr aShapeOfIntersection = aFeatureShape->intersect(aShape); +#ifdef DEBUG_POINT_INSIDE_SHAPE + int aPrevSize = thePointToAttributeOrObject.size(); +#endif appendShapePoints(aShapeOfIntersection, aResult, thePointToAttributeOrObject); +#ifdef DEBUG_POINT_INSIDE_SHAPE + if (aPrevSize != thePointToAttributeOrObject.size()) + std::cout << " <- appendShapePoints" + << thePointToAttributeOrObject.size() - aPrevSize << std::endl; +#endif } } } @@ -251,6 +285,9 @@ void ModelGeomAlgo_Point2D::getPointsInsideShape( const std::shared_ptr& theDirY, PointToRefsMap& thePointToAttributeOrObject) { +#ifdef DEBUG_POINT_INSIDE_SHAPE + std::cout << "ModelGeomAlgo_Point2D::getPointsInsideShape:" << std::endl; +#endif std::set >::const_iterator anIt = theAttributes.begin(), aLast = theAttributes.end(); for (; anIt != aLast; anIt++) { @@ -258,7 +295,7 @@ void ModelGeomAlgo_Point2D::getPointsInsideShape( std::shared_ptr aPnt2d = anAttribute->pnt(); std::shared_ptr aPoint = aPnt2d->to3D(theOrigin, theDirX, theDirY); std::shared_ptr aProjectedPoint; - if (isPointOnEdge(theBaseShape, aPoint, aProjectedPoint)) { + if (isInnerPointOnEdge(theBaseShape, aPoint, aProjectedPoint)) { if (thePointToAttributeOrObject.find(aProjectedPoint) != thePointToAttributeOrObject.end()) thePointToAttributeOrObject.at(aProjectedPoint).first.push_back(anAttribute); else { @@ -267,6 +304,17 @@ void ModelGeomAlgo_Point2D::getPointsInsideShape( anAttributes.push_back(anAttribute); thePointToAttributeOrObject[aProjectedPoint] = std::make_pair(anAttributes, anObjects); } +#ifdef DEBUG_POINT_INSIDE_SHAPE + std::cout << " " << anAttribute->owner()->data()->name() << ": " << anAttribute->id() + << "[" << aPoint->x() << ", " << aPoint->y() << ", " << aPoint->z() << "]" + << std::endl; +#endif + } + else { +#ifdef DEBUG_POINT_INSIDE_SHAPE + std::cout << " " << anAttribute->owner()->data()->name() << ": " << anAttribute->id() + << "OUT of shape" << std::endl; +#endif } } } @@ -288,7 +336,7 @@ void ModelGeomAlgo_Point2D::getPointsInsideShape_p( std::shared_ptr aPnt2d = anAttribute->pnt(); std::shared_ptr aPoint = aPnt2d->to3D(theOrigin, theDirX, theDirY); std::shared_ptr aProjectedPoint; - if (isPointOnEdge(theBaseShape, aPoint, aProjectedPoint)) { + if (isInnerPointOnEdge(theBaseShape, aPoint, aProjectedPoint)) { thePoints.push_back(aProjectedPoint); theAttributeToPoint[anAttribute] = aProjectedPoint; } @@ -301,15 +349,8 @@ bool ModelGeomAlgo_Point2D::isPointOnEdge(const std::shared_ptr t { bool isInside = false; if (theBaseShape->shapeType() == GeomAPI_Shape::EDGE) { - std::shared_ptr anEdge(new GeomAPI_Edge(theBaseShape)); - if (anEdge->isLine()) { - std::shared_ptr aLine = anEdge->line(); - theProjectedPoint = aLine->project(thePoint); - } - else if (anEdge->isCircle() || anEdge->isArc()) { - std::shared_ptr aCircle = anEdge->circle(); - theProjectedPoint = aCircle->project(thePoint); - } + GeomCurvePtr aCurve(new GeomAPI_Curve(theBaseShape->edge())); + theProjectedPoint = aCurve->project(thePoint); if (theProjectedPoint.get()) { std::shared_ptr aVertexShape(new GeomAPI_Vertex(theProjectedPoint->x(), theProjectedPoint->y(), theProjectedPoint->z())); @@ -319,11 +360,33 @@ bool ModelGeomAlgo_Point2D::isPointOnEdge(const std::shared_ptr t return isInside; } + +bool ModelGeomAlgo_Point2D::isInnerPointOnEdge(const std::shared_ptr theBaseShape, + const std::shared_ptr& thePoint, + std::shared_ptr& theProjectedPoint) +{ + bool isInside = isPointOnEdge(theBaseShape, thePoint, theProjectedPoint); + if (isInside) { + std::shared_ptr anEdge(new GeomAPI_Edge(theBaseShape)); + if (!anEdge->isClosed()) { + // check the point is not on the boundary + GeomVertexPtr aVertex(new GeomAPI_Vertex(theProjectedPoint->x(), + theProjectedPoint->y(), theProjectedPoint->z())); + GeomAPI_ShapeExplorer anExp(anEdge, GeomAPI_Shape::VERTEX); + for (; anExp.more(); anExp.next()) { + GeomVertexPtr aCurV = anExp.current()->vertex(); + isInside = !GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(aVertex, aCurV); + } + } + } + return isInside; +} + std::string doubleToString(double theValue) { std::string aValueStr; char aBuf[50]; - int n = sprintf(aBuf, "%g", theValue); + sprintf(aBuf, "%g", theValue); aValueStr = std::string(aBuf); return aValueStr; }