Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #pragma once 11 : 12 : // MOOSE includes 13 : #include "DataIO.h" 14 : 15 : #include "json.h" 16 : #include "libmesh/point.h" 17 : 18 : // forward declarations 19 : namespace libMesh 20 : { 21 : class Plane; 22 : } 23 : 24 : /** 25 : * The LineSegment class is used by the LineMaterialSamplerBase class 26 : * and for some ray tracing stuff. 27 : */ 28 : class LineSegment 29 : { 30 : public: 31 : LineSegment() = default; 32 : LineSegment(const Point & p0, const Point & p1); 33 : 34 2097 : virtual ~LineSegment() = default; 35 : 36 : /** 37 : * Returns the closest point on the LineSegment 38 : * to the passed in point. Note that the closest point may be 39 : * one of the ends of the LineSegment. 40 : */ 41 : Point closest_point(const Point & p) const; 42 : 43 : /** 44 : * Finds the closest point on the Line determined by the 45 : * Line Segments. Returns a boolean indicating whether 46 : * that normal point is within the LineSegment or not 47 : */ 48 : bool closest_normal_point(const Point & p, Point & closest_p) const; 49 : 50 : /** 51 : * Determines whether a point is in a line segment or not 52 : */ 53 : bool contains_point(const Point & p) const; 54 : 55 : bool intersect(const libMesh::Plane & pl, Point & intersect_p) const; 56 : 57 : bool intersect(const LineSegment & l1, Point & intersect_p) const; 58 : 59 : /** 60 : * Beginning of the line segment. 61 : */ 62 0 : const Point & start() const { return _p0; } 63 : 64 : /** 65 : * Ending of the line segment. 66 : */ 67 251 : const Point & end() const { return _p1; } 68 : 69 : /** 70 : * Sets the beginning of the line segment. 71 : */ 72 0 : void setStart(const Point & p0) { _p0 = p0; } 73 : 74 : /** 75 : * Sets the end of the line segment. 76 : */ 77 0 : void setEnd(const Point & p1) { _p1 = p1; } 78 : 79 : /** 80 : * Sets the points on the line segment. 81 : * @param p0 The start point of the line segment 82 : * @param p1 The end point of the line segment 83 : */ 84 : void set(const Point & p0, const Point & p1); 85 : 86 : /** 87 : * Length of segment 88 : */ 89 : Real length() const { return (_p0 - _p1).norm(); } 90 : 91 : private: 92 : bool closest_point(const Point & p, bool clamp_to_segment, Point & closest_p) const; 93 : 94 : Point _p0, _p1; 95 : }; 96 : 97 : void dataStore(std::ostream & stream, LineSegment & l, void * context); 98 : void dataLoad(std::istream & stream, LineSegment & l, void * context); 99 : 100 : void to_json(nlohmann::json & json, const LineSegment & l);