Spinning Topp Logo BlackTopp Studios
inc
multipath.cpp
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 /*
41  -----------------------------------------------------------------------------
42  This source file is part of ogre-procedural
43 
44  For the latest info, see http://code.google.com/p/ogre-procedural/
45 
46  Copyright (c) 2010-2013 Michael Broutin
47 
48  Permission is hereby granted, free of charge, to any person obtaining a copy
49  of this software and associated documentation files (the "Software"), to deal
50  in the Software without restriction, including without limitation the rights
51  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
52  copies of the Software, and to permit persons to whom the Software is
53  furnished to do so, subject to the following conditions:
54 
55  The above copyright notice and this permission notice shall be included in
56  all copies or substantial portions of the Software.
57 
58  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
61  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
62  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
63  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
64  THE SOFTWARE.
65  -----------------------------------------------------------------------------
66  */
67 #ifndef _graphicsproceduralmultipath_cpp
68 #define _graphicsproceduralmultipath_cpp
69 
70 #include "Graphics/Procedural/multipath.h"
71 #include "Graphics/Procedural/path.h"
72 
73 namespace Mezzanine
74 {
75  namespace Graphics
76  {
77  namespace Procedural
78  {
79  ///////////////////////////////////////////////////////////////////////////////
80  // PathCoordinate Methods
81 
83  PathIndex(0),
84  PointIndex(0)
85  { }
86 
88  PathIndex(Path),
89  PointIndex(Point)
90  { }
91 
93  { }
94 
95  ///////////////////////////////////////////////////////////////////////////////
96  // Comparison
97 
99  {
100  if( this->PathIndex == Other.PathIndex ) return this->PointIndex < Other.PointIndex;
101  else return this->PathIndex < Other.PathIndex;
102  }
103 
104  ///////////////////////////////////////////////////////////////////////////////
105  // MultiPath Methods
106 
108  { }
109 
111  { }
112 
113  ///////////////////////////////////////////////////////////////////////////////
114  // Utility
115 
116  MultiPath& MultiPath::SetPath(const Whole PathIndex, const Path& ToSet)
117  {
118  this->Paths.at(PathIndex) = ToSet;
119  return *this;
120  }
121 
123  {
124  this->Intersections.clear();
125  this->UniqueIntersections.clear();
126  std::map< Vector3, PathIntersection, Vector3LengthCompare > IntersectionMap;
127  for( PathIterator PathIt = this->Paths.begin() ; PathIt != this->Paths.end() ; ++PathIt )
128  {
129  const Point3DContainer& PathPoints = (*PathIt).GetPoints();
130  for( ConstPoint3DIterator PointIt = PathPoints.begin() ; PointIt != PathPoints.end() ; ++PointIt )
131  {
132  PathCoordinate Coord(PathIt - this->Paths.begin(),PointIt - PathPoints.begin());
133  if( IntersectionMap.find(*PointIt) == IntersectionMap.end() ) {
134  PathIntersection Intersect;
135  Intersect.push_back(Coord);
136  IntersectionMap[*PointIt] = Intersect;
137  }else{
138  IntersectionMap[*PointIt].push_back(Coord);
139  }
140  }
141  }
142  for( std::map< Vector3, PathIntersection, Vector3LengthCompare >::iterator IntersectionIt = IntersectionMap.begin() ; IntersectionIt != IntersectionMap.end() ; ++IntersectionIt )
143  {
144  if( IntersectionIt->second.size() > 1 ) {
145  for( PathIntersection::iterator PointIt = IntersectionIt->second.begin() ; PointIt != IntersectionIt->second.end() ; ++PointIt )
146  {
147  this->UniqueIntersections[ *PointIt ] = IntersectionIt->second;
148  }
149  this->Intersections.push_back( IntersectionIt->second );
150  }
151  }
152  return *this;
153  }
154 
156  {
157  const Path& RetPath = this->Paths[PathIndex];
158  PathSegmentContainer RetSegments;
159  std::vector<Integer> TempIntersections;
160  for( IntersectionMap::const_iterator IntersectIt = this->UniqueIntersections.begin() ; IntersectIt != this->UniqueIntersections.end() ; ++IntersectIt )
161  {
162  if( (*IntersectIt).first.PathIndex == PathIndex ) {
163  TempIntersections.push_back( (*IntersectIt).first.PointIndex );
164  }
165  }
166  std::sort(TempIntersections.begin(),TempIntersections.end());
167  Integer BeginIndex = 0;
168  for( std::vector<Integer>::iterator IntersectIt = TempIntersections.begin() ; IntersectIt != TempIntersections.end() ; ++IntersectIt )
169  {
170  if( (*IntersectIt) - 1 > BeginIndex ) {
171  RetSegments.push_back( PathSegment(BeginIndex,(*IntersectIt) - 1) );
172  }
173  BeginIndex = (*IntersectIt) + 1;
174  }
175  if( RetPath.GetSegCount() > BeginIndex ) {
176  RetSegments.push_back( PathSegment(BeginIndex,RetPath.GetSegCount()) );
177  }
178  return RetSegments;
179  }
180 
181  ///////////////////////////////////////////////////////////////////////////////
182  // Path Management
183 
185  {
186  this->Paths.push_back(ToAdd);
187  return *this;
188  }
189 
191  {
192  for( ConstPathIterator PathIt = Other.Paths.begin() ; PathIt != Other.Paths.end() ; ++PathIt )
193  {
194  this->Paths.push_back( *PathIt );
195  }
196  return *this;
197  }
198 
200  {
201  return this->Paths.at(Index);
202  }
203 
204  const Path& MultiPath::GetPath(const Whole Index) const
205  {
206  return this->Paths.at(Index);
207  }
208 
210  {
211  return this->Paths.size();
212  }
213 
215  {
216  this->Paths.clear();
217  this->Intersections.clear();
218  this->UniqueIntersections.clear();
219  }
220 
221  ///////////////////////////////////////////////////////////////////////////////
222  // Intersection Management
223 
225  {
226  return this->Intersections;
227  }
228 
230  {
231  return this->UniqueIntersections;
232  }
233  }//Procedural
234  }//Graphics
235 }//Mezzanine
236 
237 #endif
MultiPath & AddMultiPath(const MultiPath &Other)
Append every path of another MultiShape to this MultiPath.
Definition: multipath.cpp:190
Path & GetPath(const Whole Index)
Gets a path by index.
Definition: multipath.cpp:199
const IntersectionMap & GetIntersectionsMap() const
Gets the container storing all calculated intersections based on their path coordinate.
Definition: multipath.cpp:229
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
std::vector< Vector3 > Point3DContainer
Basic container type for the storage of 3D points.
MultiPath & CalculateIntersections()
Generates all the known intersections between the paths in this MultiPath.
Definition: multipath.cpp:122
IntersectionVector Intersections
Container storing all known intersections.
Definition: multipath.h:143
const IntersectionVector & GetIntersections() const
Gets the container storing all calculated intersections.
Definition: multipath.cpp:224
A convenience class for tracking points in a MultiPath.
Definition: multipath.h:83
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
IntersectionMap UniqueIntersections
Container storing all intersections based on their coordinate.
Definition: multipath.h:146
std::vector< PathCoordinate > PathIntersection
Convenience type used to represent the intersection of two or more paths.
Definition: multipath.h:128
PathContainer Paths
Container storing all of the Paths that form this MultiPath.
Definition: multipath.h:140
Boole operator<(const PathCoordinate &Other) const
Less-than comparison operator.
Definition: multipath.cpp:98
Whole PathIndex
The index of the path where this coordinate is located.
Definition: multipath.h:89
Whole PointIndex
The index of the point in the path where this coordinate is located.
Definition: multipath.h:91
MultiPath & AddPath(const Path &ToAdd)
Adds a path to this MultiPath.
Definition: multipath.cpp:184
PathSegmentContainer GetNoIntersectionParts(const Whole PathIndex) const
Gets segments from a specific sub-path that do not intersect other Paths of this MultiPath.
Definition: multipath.cpp:155
std::map< PathCoordinate, PathIntersection > IntersectionMap
Container type for the storage of unique intersections.
Definition: multipath.h:132
std::vector< PathSegment > PathSegmentContainer
Container type for segments in a Path.
Definition: multipath.h:136
MultiPath & SetPath(const Whole PathIndex, const Path &ToSet)
Sets a path at a specific index.
Definition: multipath.cpp:116
std::vector< PathIntersection > IntersectionVector
Container type for the storage of intersections.
Definition: multipath.h:130
PathContainer::iterator PathIterator
Iterator type for Path instances being stored in this class.
Definition: multipath.h:124
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
A grouping of individual 3D curves used to express complicated structures.
Definition: multipath.h:118
Integer GetSegCount() const
Gets the number of segments in this path.
Definition: path.cpp:221
Point3DContainer::const_iterator ConstPoint3DIterator
Const Iterator type for a Point3DContainer.
Whole GetNumPaths() const
Gets the number of shapes in this MultiPath.
Definition: multipath.cpp:209
std::pair< Whole, Whole > PathSegment
Convenience type for a pair of indexes to express a segment of a Path.
Definition: multipath.h:134
void RemoveAllPaths()
Removes all shapes from this MultiPath.
Definition: multipath.cpp:214
A collection of interconnected 3D points used to express path through 3D space.
Definition: path.h:93
PathContainer::const_iterator ConstPathIterator
Const Iterator type for Path instances being stored in this class.
Definition: multipath.h:126