15#ifdef ENABLE_OPENCASCADE
20#undef _USE_MATH_DEFINES
29#include <BRepAlgoAPI_Common.hxx>
30#include <BRepBuilderAPI_MakeFace.hxx>
31#include <BRepPrimAPI_MakeBox.hxx>
32#include <BRepPrimAPI_MakeHalfSpace.hxx>
40Kernel::Logger logger(
"Plane");
46 :
Quadratic(), m_normVec(1.0, 0.0, 0.0), m_distance(0)
60 return new Plane(*
this);
69 return std::unique_ptr<Plane>(
doClone());
84 std::string
Line = Pstr;
90 double surf[9] = {0.0, 0, 0, 0, 0};
98 if (cnt != 4 && cnt != 9)
118 }
else if (item.size() == 2)
120 const auto ptype =
static_cast<int>(tolower(item[1]) -
'x');
121 if (ptype < 0 || ptype > 2)
144 }
catch (std::runtime_error &) {
145 throw std::invalid_argument(
"Attempt to create Plane with zero normal");
182 return A.scalar_prod(m_normVec) - m_distance;
191 return m_normVec.scalar_prod(A.m_normVec);
213 const double Dp = m_normVec.scalar_prod(A) - m_distance;
215 return (Dp > 0) ? 1 : -1;
226 return (side(A) == 0);
248 for (std::size_t i = 0; i < 3; i++)
276 std::ostringstream cx;
304 double s1 = (projection -
m_distance) / sprod;
305 if (s1 < 0 || s1 > 1)
309 double const ratio = projection / sprod;
310 output[0] = ratio * endpt[0] + (1 - ratio) * startpt[0] - ((endpt[0] - startpt[0]) / sprod) *
m_distance;
311 output[1] = ratio * endpt[1] + (1 - ratio) * startpt[1] - ((endpt[1] - startpt[1]) / sprod) *
m_distance;
312 output[2] = ratio * endpt[2] + (1 - ratio) * startpt[2] - ((endpt[2] - startpt[2]) / sprod) *
m_distance;
329 V3D vertex1(xmin, ymin, zmin);
330 V3D vertex2(xmax, ymin, zmin);
331 V3D vertex3(xmax, ymax, zmin);
332 V3D vertex4(xmin, ymax, zmin);
333 V3D vertex5(xmin, ymin, zmax);
334 V3D vertex6(xmax, ymin, zmax);
335 V3D vertex7(xmax, ymax, zmax);
336 V3D vertex8(xmin, ymax, zmax);
351 std::vector<V3D> listOfPoints;
352 if (this->
side(vertex1) <= 0)
353 listOfPoints.emplace_back(vertex1);
354 if (this->
side(vertex2) <= 0)
355 listOfPoints.emplace_back(vertex2);
356 if (this->
side(vertex3) <= 0)
357 listOfPoints.emplace_back(vertex3);
358 if (this->
side(vertex4) <= 0)
359 listOfPoints.emplace_back(vertex4);
360 if (this->
side(vertex5) <= 0)
361 listOfPoints.emplace_back(vertex5);
362 if (this->
side(vertex6) <= 0)
363 listOfPoints.emplace_back(vertex6);
364 if (this->
side(vertex7) <= 0)
365 listOfPoints.emplace_back(vertex7);
366 if (this->
side(vertex8) <= 0)
367 listOfPoints.emplace_back(vertex8);
368 V3D edge1, edge2, edge3, edge4, edge5, edge6, edge7, edge8, edge9, edge10, edge11, edge12;
370 listOfPoints.emplace_back(edge1);
372 listOfPoints.emplace_back(edge2);
374 listOfPoints.emplace_back(edge3);
376 listOfPoints.emplace_back(edge4);
378 listOfPoints.emplace_back(edge5);
380 listOfPoints.emplace_back(edge6);
382 listOfPoints.emplace_back(edge7);
384 listOfPoints.emplace_back(edge8);
386 listOfPoints.emplace_back(edge9);
388 listOfPoints.emplace_back(edge10);
390 listOfPoints.emplace_back(edge11);
392 listOfPoints.emplace_back(edge12);
395 if (!listOfPoints.empty()) {
396 xmin = ymin = zmin = std::numeric_limits<double>::max();
397 xmax = ymax = zmax = std::numeric_limits<double>::lowest();
398 for (std::vector<V3D>::const_iterator it = listOfPoints.begin(); it != listOfPoints.end(); ++it) {
416#ifdef ENABLE_OPENCASCADE
417TopoDS_Shape Plane::createShape() {
420 double norm2 = normal.
norm2();
422 throw std::runtime_error(
"Cannot create a plane with zero normal");
428 TopoDS_Face P = BRepBuilderAPI_MakeFace(gp_Pln(normal[0], normal[1], normal[2], -
distance)).Face();
430 TopoDS_Shape Result =
431 BRepPrimAPI_MakeHalfSpace(P, gp_Pnt(normal[0] * (1 + t), normal[1] * (1 + t), normal[2] * (1 + t))).Solid();
432 return Result.Complemented();
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
void setBaseEqn() override
set up to be eqn based
void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin, double &zmin) override
Returns the bounding box values for plane, double max is infinity and double min is -infinity A very ...
int side(const Kernel::V3D &) const override
Calcualates the side that the point is on.
double m_distance
Distance from origin.
std::unique_ptr< Plane > clone() const
Makes a clone (implicit virtual copy constructor)
bool onSurface(const Kernel::V3D &) const override
Calcuate the side that the point is on and returns success if it is on the surface.
double distance(const Kernel::V3D &) const override
distance from a point
double getDistance() const
Distance from origin.
int setSurface(const std::string &) override
processes a standard MCNPX plane string: There are three types :
int LineIntersectionWithPlane(Kernel::V3D startpt, Kernel::V3D endpt, Kernel::V3D &output)
Returns the point of intersection of line with the plane.
double dotProd(const Plane &) const
returns normal dot product
const Kernel::V3D & getNormal() const
Normal to plane (+ve surface)
void print() const override
Prints out the surface info and the Plane info.
int setPlane(const Kernel::V3D &, const Kernel::V3D &)
Given a point and a normal direction set the plane.
void write(std::ostream &) const override
Write in MCNPX form.
Plane * doClone() const override
Makes a clone (implicit virtual copy constructor)
Plane()
Constructor: sets plane in y-z plane and throught origin.
std::size_t planeType() const
are we alined on an axis
void rotate(const Kernel::Matrix< double > &) override
Rotate the plane about the origin by MA.
Kernel::V3D crossProd(const Plane &) const
returns normal cross product
Kernel::V3D m_normVec
Normal vector.
void displace(const Kernel::V3D &) override
Displace the plane by Point Sp.
Holds a basic quadratic surface.
std::vector< double > BaseEqn
Base equation (as a 10 point vector)
void displace(const Kernel::V3D &) override
Apply a general displacement to the surface.
void rotate(const Kernel::Matrix< double > &) override
Rotate the surface by matrix MX.
void print() const override
Print out the genreal equation for debugging.
void writeHeader(std::ostream &) const
Writes out the start of an MCNPX surface description .
static const int Nprecision
Precision of the output.
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
double normalize()
Make a normalized vector (return norm value)
constexpr V3D cross_prod(const V3D &v) const noexcept
Cross product (this * argument)
void rotate(const Matrix< double > &) noexcept
Rotate a point by a matrix.
constexpr double norm2() const noexcept
Vector length squared.
int section(std::string &A, T &out)
Convert and cut a string.
MANTID_KERNEL_DLL void writeMCNPX(const std::string &Line, std::ostream &OX)
Write file in standard MCNPX input form.
int convert(const std::string &A, T &out)
Convert a string into a number.
constexpr double Tolerance
Standard tolerance value.
MANTID_KERNEL_DLL V3D normalize(V3D v)
Normalizes a V3D.