Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
SweepPlane.h
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_SweepPlane_H_
9#define model_SweepPlane_H_
10
11#include <cfloat>
12#include <tuple>
13#include <map>
14#include <set>
15#include <deque>
16#include <algorithm>
17#include <Eigen/Dense>
18
20
21namespace model
22{
23
26 template <typename LineType,int dim>
27 struct SweepPlane :
28 /* base */ public std::map<float,std::pair<std::map<typename LineType::KeyType,const LineType*>,std::map<typename LineType::KeyType,const LineType*>>>,
29 /* base */ public std::deque<std::pair<const LineType*,const LineType*>>
30 {
31
32// typedef std::set<const LineType*> EventMapType;
33 typedef std::map<typename LineType::KeyType,const LineType*> EventMapType;
34 typedef std::map<float,std::pair<EventMapType,EventMapType>> EventContainerType;
35 typedef std::deque<std::pair<const LineType*,const LineType*>> IntersectionPairContainerType;
36 /**********************************************************************/
38 {
39 return *this;
40 }
41
42 /**********************************************************************/
44 {
45 return *this;
46 }
47
49 {
50 return *this;
51 }
52
53 const std::pair<const LineType*,const LineType*>& potentialIntersectionPair(const size_t& k) const
54 {
56 }
57
58 /**********************************************************************/
59 void addSegment(const double& xStart,const double& xEnd,const LineType& line)
60 {
61
62 const bool success1=events()[std::min(xStart,xEnd)].first.emplace(line.key,&line).second; // line starts at xStart
63 const bool success2=events()[std::max(xStart,xEnd)].second.emplace(line.key,&line).second; // line ends at xEnd
64 if(success1!=success2)
65 {
66 throw std::runtime_error("SweepPlane segment insertion error.");
67 }
68// assert(success1==success2);
69 }
70
71 /**********************************************************************/
73 {
74 std::map<typename LineType::KeyType,const LineType*> activeSegments;
75
76 for(const auto& event : events())
77 {
78
79 for(const auto& startingSegment : event.second.first)
80 {
81 for(const auto& activeSegment : activeSegments)
82 {
83 if(activeSegment.second!=startingSegment.second)
84 {
85 IntersectionPairContainerType::emplace_back(activeSegment.second,startingSegment.second);
86 }
87
88 }
89 const bool success=activeSegments.emplace(startingSegment.first,startingSegment.second).second;
90 if(!success)
91 {
92 throw std::runtime_error("SweepPlane::computeIntersectionPairs() cannot add segment.");
93 }
94// assert(success);
95 }
96
97 for(const auto& endingSegment : event.second.second)
98 {
99 const size_t nErased=activeSegments.erase(endingSegment.first);
100 if(nErased!=1)
101 {
102 throw std::runtime_error("SweepPlane::computeIntersectionPairs() cannot erase segment.");
103 }
104// assert(nErased==1);
105 }
106 }
107
108 assert(activeSegments.size()==0); // no segments must be active when plane finishes sweep
109
110 }
111
112
113 };
114
115}
116#endif
const std::pair< const LineType *, const LineType * > & potentialIntersectionPair(const size_t &k) const
Definition SweepPlane.h:53
void addSegment(const double &xStart, const double &xEnd, const LineType &line)
Definition SweepPlane.h:59
const IntersectionPairContainerType & potentialIntersectionPairs() const
Definition SweepPlane.h:48
EventContainerType & events()
Definition SweepPlane.h:43
void computeIntersectionPairs()
Definition SweepPlane.h:72
const EventContainerType & events() const
Definition SweepPlane.h:37
std::map< float, std::pair< EventMapType, EventMapType > > EventContainerType
Definition SweepPlane.h:34
std::deque< std::pair< const LineType *, const LineType * > > IntersectionPairContainerType
Definition SweepPlane.h:35
std::map< typename LineType::KeyType, const LineType * > EventMapType
Definition SweepPlane.h:33
int k
enum insertvertexresult success