Spinning Topp Logo BlackTopp Studios
inc
path.h
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 _graphicsproceduralpath_h
68 #define _graphicsproceduralpath_h
69 
70 #include "vector3.h"
71 #include "interpolator.h"
72 #include "track.h"
73 
74 #include "Graphics/Procedural/proceduraldatatypes.h"
75 
76 namespace Mezzanine
77 {
78  namespace Graphics
79  {
80  class Mesh;
81  namespace Procedural
82  {
83  class Path;
84  class Shape;
85 
86  /// @brief Basic container type for the storage of Paths.
87  typedef std::vector< Path > PathContainer;
88 
89  ///////////////////////////////////////////////////////////////////////////////
90  /// @brief A collection of interconnected 3D points used to express path through 3D space.
91  /// @details
92  ///////////////////////////////////////
93  class MEZZ_LIB Path
94  {
95  protected:
96  /// @internal
97  /// @brief A container storing all of the points in this path.
99  /// @internal
100  /// @brief Whether or not the end of this path connects to the beginning of this path.
102  public:
103  /// @brief Blank constructor.
104  Path();
105  /// @brief Create a Path from an iterator range.
106  /// @param Begin An iterator pointing to the beginning of a range to copy.
107  /// @param End an iterator pointing to one past the rang to copy.
109  /// @brief Create a Path from a Point3DContainer instance.
110  /// @param DataSet A collection of points to copy.
111  Path(const Point3DContainer& DataSet);
112  /// @brief Class destructor.
113  ~Path();
114 
115  ///////////////////////////////////////////////////////////////////////////////
116  // Utility
117 
118  /// @brief Generates one or more paths from a series of segments.
119  /// @param Segments The segments to use to generate paths.
120  /// @param GeneratedPaths A container to be populated with the paths that are generated.
121  static void BuildFromSegmentSoup(const LineSeg3DVec& Segments, PathContainer& GeneratedPaths);
122 
123  /// @brief Outputs a mesh representing this path.
124  /// @param Name The name of the mesh to be generated.
125  /// @param Group The name of the resource group to create the mesh in.
126  /// @return Returns a pointer to the new mesh.
127  Mesh* GenerateMesh(const String& Name, const String& Group) const;
128 
129  /// @brief Appends all the points from another path to this path.
130  /// @param Other The other path to append to this path.
131  /// @return Returns a reference to this.
132  Path& AppendPath(const Path& Other);
133  /// @brief Appends all the points from another path to this path with their positions relative to the position of the last point in this path.
134  /// @param Other The other path to append to this path.
135  /// @return Returns a reference to this.
136  Path& AppendPathRel(const Path& Other);
137  /// @brief Extracts a part of the path as a new path.
138  /// @param First The first index of this path to be in the new path.
139  /// @param Last The last index of this path to be in the new path.
140  /// @return Returns a reference to this.
141  Path ExtractSubPath(const Whole First, const Whole Last);
142 
143  /// @brief Appends the contents of a 3D track to this shape.
144  /// @remarks Low values for NumPoints will cause curves to look blocky. How how it should be depends on the resolution of the curve you want.
145  /// @param Curve The 3D curved track of points to append to this shape.
146  /// @param NumPoints The number of points along the curve to generate for this shape.
147  template< template<class> class Interpolator >
148  void AppendTrack(const Track< Interpolator< Vector3 > >& Curve, const Whole NumPoints)
149  {
150  // Minus one because we want to include the end of the curve without going over the number of points requested
151  for( Whole CurrPoint = 0 ; CurrPoint < NumPoints ; ++CurrPoint )
152  {
153  Real InterpolateVal = static_cast<Real>( CurrPoint ) / static_cast<Real>( NumPoints - 1 );
154  Vector3 CurvePoint = Curve.GetInterpolated(InterpolateVal);
155  this->AddPoint(CurvePoint);
156  }
157  }
158 
159  /// @brief Gets the number of segments in this path.
160  /// @return Returns a Whole containing the number of segments that form this path.
161  Integer GetSegCount() const;
162  /// @brief Gets the total length of all segments in this path.
163  /// @return Returns a Real representing the combined length of each segment in this path.
164  Real GetTotalLength() const;
165  /// @brief Gets the total length to the point in this path at an index.
166  /// @param PointIndex The point to retrieve the length to.
167  /// @return Returns a Real representing the combined length of each segment to the point at the specified index.
168  Real GetLengthAtPoint(const Whole PointIndex) const;
169 
170  /// @brief Reflect all points in this path against a zero-origined plane with a given normal.
171  /// @param Normal The normal to reflect all points on.
172  /// @return Returns a reference to this.
173  Path& Reflect(const Vector3& Normal);
174 
175  /// @brief Reverses direction/ordering of the segments in this path.
176  /// @return Returns a reference to this.
177  Path& Reverse();
178 
179  /// @brief Connects the last point in this path to the first point.
180  /// @return Returns a reference to this.
181  Path& Close();
182  /// @brief Gets whether or not the final point in this path connects to the first point.
183  /// @return Returns true if this path is currently closed.
184  Boole IsClosed() const;
185 
186  ///////////////////////////////////////////////////////////////////////////////
187  // Point Management
188 
189  /// @brief Adds a point to this path.
190  /// @param ToAdd The location of the point to add.
191  /// @return Returns a reference to this.
192  Path& AddPoint(const Vector3& ToAdd);
193  /// @brief Adds a point to this path.
194  /// @param X The location of the point to add on the X axis.
195  /// @param Y The location of the point to add on the Y axis.
196  /// @param Z The location of the point to add on the Z axis.
197  /// @return Returns a reference to this.
198  Path& AddPoint(const Real X, const Real Y, const Real Z);
199 
200  /// @brief Inserts a point to the path.
201  /// @param Index the index before the inserted point.
202  /// @param X The position of the point to insert on the X axis.
203  /// @param Y The position of the point to insert on the Y axis.
204  /// @param Y The position of the point to insert on the Z axis.
205  /// @return Returns a reference to this.
206  Path& InsertPoint(const Whole Index, const Real X, const Real Y, const Real Z);
207  /// @brief Inserts a point to the path.
208  /// @param Index the index before the inserted point.
209  /// @param Point The point to be inserted.
210  /// @return Returns a reference to this.
211  Path& InsertPoint(const Whole Index, const Vector3& Point);
212 
213  /// @brief Safely gets a point in this path.
214  /// @param Index The index of the point to retrieve. Negative values will be clamped to zero.
215  /// @return Returns a const reference to the Vector3 at the specified index.
216  const Vector3& GetPoint(const Integer Index) const;
217 
218  /// @brief Gets all of the points in this path.
219  /// @return Returns a reference to the container storing each point in this path.
220  Point3DContainer& GetPoints();
221  /// @brief Gets all of the points in this path.
222  /// @return Returns a const reference to the container storing each point in this path.
223  const Point3DContainer& GetPoints() const;
224 
225  ///////////////////////////////////////////////////////////////////////////////
226  // Transform
227 
228  /// @brief Applies the given translation to all the points in this path.
229  /// @note This will only transfrom the points currently in this path, not any additional points made after calling this.
230  /// @param Trans The amount of translation to apply.
231  /// @return Returns a reference to this.
232  Path& Translate(const Vector3& Trans);
233  /// @brief Applies the given translation to all the points in this path.
234  /// @note This will only transfrom the points currently in this path, not any additional points made after calling this.
235  /// @param TransX The amount of translation to apply on the X axis.
236  /// @param TransY The amount of translation to apply on the Y axis.
237  /// @param TransZ The amount of translation to apply on the Z axis.
238  /// @return Returns a reference to this.
239  Path& Translate(const Real TransX, const Real TransY, const Real TransZ);
240  /// @brief Applies the given scale to all the points in this path.
241  /// @note This will only transfrom the points currently in this path, not any additional points made after calling this.
242  /// @param Scaling The amount of scaling to apply to each axis.
243  /// @return Returns a reference to this.
244  Path& Scale(const Real Scaling);
245  /// @brief Applies the given scale to all the points in this path.
246  /// @note This will only transfrom the points currently in this path, not any additional points made after calling this.
247  /// @param ScaleX The amount of scaling to be applied on the X axis.
248  /// @param ScaleY The amount of scaling to be applied on the Y axis.
249  /// @param ScaleZ The amount of scaling to be applied on the Z axis.
250  /// @return Returns a reference to this.
251  Path& Scale(const Real ScaleX, const Real ScaleY, const Real ScaleZ);
252  /// @brief Applies the given scale to all the points in this path.
253  /// @note This will only transfrom the points currently in this path, not any additional points made after calling this.
254  /// @param Scaling The amount of scaling to apply to each axis.
255  /// @return Returns a reference to this.
256  Path& Scale(const Vector3& Scaling);
257 
258  ///////////////////////////////////////////////////////////////////////////////
259  // Directions and Normals
260 
261  /// @brief Gets the direction of a point to the next point in the sequence.
262  /// @param Index The index of the point to retrieve the direction for.
263  /// @return Returns a Vector3 containing the direction from the specified point to the next point.
264  Vector3 GetDirectionAfter(const Whole Index) const;
265  /// @brief Gets the direction from a point to the previous point in the sequence.
266  /// @param Index The index of the point to retrieve the direction for.
267  /// @return Returns a Vector3 containing the direction from the specified point to the previous point.
268  Vector3 GetDirectionBefore(const Whole Index) const;
269  /// @brief Gets the averaged direction from the specified point to both the next and previous points in the sequence.
270  /// @param Index The index of the point to retrieve the direction for.
271  /// @return Returns a Vector3 containing the averaged direction for both the next and previous points from the specified point.
272  Vector3 GetAvgDirection(const Whole Index) const;
273 
274  ///////////////////////////////////////////////////////////////////////////////
275  // Conversion
276 
277  /// @brief Converts the path to a 2D shape, dropping the Z component.
278  /// @return Returns a shape where the X and Y components are copied, and the Z component is dropped for each point.
279  Shape ConvertToShape() const;
280  };//Path
281  }//Procedural
282  }//Graphics
283 }//Mezzanine
284 
285 #endif
void AppendTrack(const Track< Interpolator< Vector3 > > &Curve, const Whole NumPoints)
Appends the contents of a 3D track to this shape.
Definition: path.h:148
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.
This class is used to check and modify the properties of a graphics mesh.
Definition: mesh.h:63
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
Point3DContainer::iterator Point3DIterator
Iterator type for a Point3DContainer.
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
Point3DContainer Points
A container storing all of the points in this path.
Definition: path.h:98
Boole Closed
Whether or not the end of this path connects to the beginning of this path.
Definition: path.h:101
std::vector< Path > PathContainer
Basic container type for the storage of Paths.
Definition: path.h:84
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
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
std::vector< LineSegment3D > LineSeg3DVec
Basic container type for the storage of 3D line segments.
A collection of interconnected 2D points used to express an arbitrary 2D shape.
Definition: shape.h:95
Helper classes to assist in generating data points between two other data points. ...
A collection of interconnected 3D points used to express path through 3D space.
Definition: path.h:93
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
A base type that provides container features for different tracks.
Definition: track.h:65