#include "GeomAPI_Shape.h"
+#include <GeomAPI_Pnt.h>
#include <GeomAPI_Vertex.h>
#include <GeomAPI_Edge.h>
#include <GeomAPI_Wire.h>
#include <TopoDS_Shape.hxx>
#include <NCollection_List.hxx>
+#include <BOPAlgo_CheckerSI.hxx>
+#include <BOPDS_DS.hxx>
+
#include <sstream>
#include <algorithm> // for std::transform
if (aShape.IsNull())
return false;
Bnd_Box aBndBox;
- BRepBndLib::Add(aShape, aBndBox);
+ BRepBndLib::Add(aShape, aBndBox, false);
+ if (aBndBox.IsVoid())
+ return false;
aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax);
return true;
}
+GeomPointPtr GeomAPI_Shape::middlePoint() const
+{
+ GeomPointPtr aMiddlePoint;
+
+ switch (shapeType()) {
+ case VERTEX:
+ aMiddlePoint = vertex()->point();
+ break;
+ case EDGE:
+ aMiddlePoint = edge()->middlePoint();
+ break;
+ case WIRE:
+ aMiddlePoint = wire()->middlePoint();
+ break;
+ case FACE:
+ aMiddlePoint = face()->middlePoint();
+ break;
+ case SHELL:
+ aMiddlePoint = shell()->middlePoint();
+ break;
+ case SOLID:
+ aMiddlePoint = solid()->middlePoint();
+ break;
+ default: {
+ // get middle point as center of the bounding box
+ double aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ;
+ computeSize(aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ);
+ aMiddlePoint = GeomPointPtr(new GeomAPI_Pnt(
+ (aMinX + aMaxX) * 0.5, (aMinY + aMaxY) * 0.5, (aMinZ + aMaxZ) * 0.5));
+ }
+ }
+
+ return aMiddlePoint;
+}
+
std::string GeomAPI_Shape::getShapeStream() const
{
std::ostringstream aStream;
TopoDS_Shape aResult = MY_SHAPE->Moved(aTranslation);
setImpl(new TopoDS_Shape(aResult));
}
+
+bool GeomAPI_Shape::isSelfIntersected(const int theLevelOfCheck) const
+{
+ BOPAlgo_CheckerSI aCSI; // checker of self-interferences
+ aCSI.SetLevelOfCheck(theLevelOfCheck);
+ TopTools_ListOfShape aList;
+ const TopoDS_Shape& aThisShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+ aList.Append(aThisShape);
+ aCSI.SetArguments(aList);
+ aCSI.Perform();
+ if (aCSI.HasErrors() || aCSI.DS().Interferences().Extent() > 0) {
+ return true;
+ }
+
+ return false;
+}