Skip to content

Commit

Permalink
Change vertex storage for ConvexPolygon
Browse files Browse the repository at this point in the history
The points are now stored in a container rather than a custom
linked-list. This will cut down on the the operations required to
insert a new node.
Refs #12584
  • Loading branch information
martyngigg committed Jun 22, 2015
1 parent 9b2bad6 commit 283af1c
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 363 deletions.
38 changes: 19 additions & 19 deletions Code/Mantid/Framework/Geometry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ set ( SRC_FILES
src/Crystal/CrystalStructure.cpp
src/Crystal/CyclicGroup.cpp
src/Crystal/Group.cpp
src/Crystal/IPeak.cpp
src/Crystal/IPeak.cpp
src/Crystal/IndexingUtils.cpp
src/Crystal/IsotropicAtomBraggScatterer.cpp
src/Crystal/NiggliCell.cpp
src/Crystal/OrientedLattice.cpp
src/Crystal/PeakTransform.cpp
src/Crystal/PeakTransformHKL.cpp
src/Crystal/PeakTransformQLab.cpp
src/Crystal/PeakTransformQSample.cpp
src/Crystal/PeakTransformSelector.cpp
src/Crystal/PeakTransform.cpp
src/Crystal/PeakTransformHKL.cpp
src/Crystal/PeakTransformQLab.cpp
src/Crystal/PeakTransformQSample.cpp
src/Crystal/PeakTransformSelector.cpp
src/Crystal/PointGroup.cpp
src/Crystal/PointGroupFactory.cpp
src/Crystal/ProductOfCyclicGroups.cpp
Expand Down Expand Up @@ -128,24 +128,24 @@ set ( INC_FILES
inc/MantidGeometry/Crystal/BraggScattererInCrystalStructure.h
inc/MantidGeometry/Crystal/CenteringGroup.h
inc/MantidGeometry/Crystal/CompositeBraggScatterer.h
inc/MantidGeometry/Crystal/ConcretePeakTransformFactory.h
inc/MantidGeometry/Crystal/ConcretePeakTransformFactory.h
inc/MantidGeometry/Crystal/ConventionalCell.h
inc/MantidGeometry/Crystal/CrystalStructure.h
inc/MantidGeometry/Crystal/CyclicGroup.h
inc/MantidGeometry/Crystal/Group.h
inc/MantidGeometry/Crystal/IPeak.h
inc/MantidGeometry/Crystal/IPeak.h
inc/MantidGeometry/Crystal/IndexingUtils.h
inc/MantidGeometry/Crystal/IsotropicAtomBraggScatterer.h
inc/MantidGeometry/Crystal/NiggliCell.h
inc/MantidGeometry/Crystal/OrientedLattice.h
inc/MantidGeometry/Crystal/PeakShape.h
inc/MantidGeometry/Crystal/PeakTransform.h
inc/MantidGeometry/Crystal/PeakTransformFactory.h
inc/MantidGeometry/Crystal/PeakTransformHKL.h
inc/MantidGeometry/Crystal/PeakTransformQLab.h
inc/MantidGeometry/Crystal/PeakTransformQSample.h
inc/MantidGeometry/Crystal/PeakTransformSelector.h
inc/MantidGeometry/Crystal/PointGroup.h
inc/MantidGeometry/Crystal/PeakTransformFactory.h
inc/MantidGeometry/Crystal/PeakTransformHKL.h
inc/MantidGeometry/Crystal/PeakTransformQLab.h
inc/MantidGeometry/Crystal/PeakTransformQSample.h
inc/MantidGeometry/Crystal/PeakTransformSelector.h
inc/MantidGeometry/Crystal/PointGroup.h
inc/MantidGeometry/Crystal/PointGroupFactory.h
inc/MantidGeometry/Crystal/ProductOfCyclicGroups.h
inc/MantidGeometry/Crystal/ReducedCell.h
Expand Down Expand Up @@ -303,11 +303,11 @@ set ( TEST_FILES
ParObjComponentTest.h
ParameterMapTest.h
ParametrizedComponentTest.h
PeakTransformHKLTest.h
PeakTransformQLabTest.h
PeakTransformQSampleTest.h
PeakTransformSelectorTest.h
PlaneTest.h
PeakTransformHKLTest.h
PeakTransformQLabTest.h
PeakTransformQSampleTest.h
PeakTransformSelectorTest.h
PlaneTest.h
PointGroupFactoryTest.h
PointGroupTest.h
PolygonEdgeTest.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,28 @@
// Includes
//-----------------------------------------------------------------------------
#include "MantidGeometry/DllConfig.h"
#include "MantidGeometry/Math/PolygonEdge.h"
#include <iosfwd>
#include <vector>

namespace Mantid {
namespace Geometry {

//---------------------------------------------------------------------------
// Forward declarations
//---------------------------------------------------------------------------
class Vertex2D;
namespace Kernel {
class V2D;
}

namespace Geometry {

//---------------------------------------------------------------------------
// Typedefs
//---------------------------------------------------------------------------

/**
An implementation of a convex polygon. It contains a list of vertices that
make up a convex polygon and the list is assumed to be ordered in an
anti-clockwise manner.
make up a convex polygon and the list is assumed to be ordered in a
clockwise manner and the polygon is assumed to be closed.
A polygon is convex if:
<UL>
Expand All @@ -31,8 +35,6 @@ A polygon is convex if:
the polygon.</LI>
</UL>
@author Martyn Gigg, Tessella plc
Copyright &copy; 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
Expand All @@ -57,21 +59,34 @@ Code Documentation is available at: <http://doxygen.mantidproject.org>
class MANTID_GEOMETRY_DLL ConvexPolygon {

public:
/// Construct a polygon with a head vertex
ConvexPolygon(Vertex2D *head);
/// Construct a rectangle as these will be quite common
ConvexPolygon(const double x_lower, const double x_upper,
const double y_lower, const double y_upper);
/// Type of the point list
typedef std::vector<Kernel::V2D> Vertices;

/// Default constructor
ConvexPolygon();
/// Construct a polygon from a collection of points
ConvexPolygon(const Vertices &vertices);
/// Copy constructor
ConvexPolygon(const ConvexPolygon &rhs);
/// Copy-assignment operator
ConvexPolygon &operator=(const ConvexPolygon &rhs);
/// Destructor
virtual ~ConvexPolygon();
/// Return a pointer to the head vertex
virtual inline const Vertex2D *head() const { return m_head; }

/// Check if polygon is valid
bool isValid() const;
/// Clears all points
void clear();
/// Insert a new vertex. The point is assumed that it forms the next point in
/// a clockwise-sense around the shape
void insert(const Kernel::V2D &pt);
/// Insert a new vertex based on x,y values
void insert(double x, double y);

/// Index access.
virtual const Kernel::V2D &operator[](const size_t index) const;
/// Return the number of vertices
inline size_t numVertices() const { return m_numVertices; }
virtual size_t npoints() const;
/// Is a point inside this polygon
virtual bool contains(const Kernel::V2D &point) const;
/// Is a the given polygon completely encosed by this one
Expand All @@ -81,38 +96,31 @@ class MANTID_GEOMETRY_DLL ConvexPolygon {
/// Compute the 'determinant' of the points
virtual double determinant() const;
/// Return the lowest X value in the polygon
double smallestX() const;
virtual double minX() const;
/// Return the largest X value in the polygon
double largestX() const;
virtual double maxX() const;
/// Return the lowest Y value in the polygon
double smallestY() const;
virtual double minY() const;
/// Return the largest Y value in the polygon
double largestY() const;
virtual double maxY() const;

protected:
/// Default constructor
ConvexPolygon();
private:
/// Setup the meta-data
void setup();
/// The size of the polygon
size_t m_numVertices;
/// Head vertex
Vertex2D *m_head;
/// Compute the area of a triangle given by 3 points
double triangleArea(const Kernel::V2D &a, const Kernel::V2D &b,
const Kernel::V2D &c) const;

// Points of the polygon
Vertices m_vertices;
/// Lowest X value
double m_lowestX;
double m_minX;
/// Highest X value
double m_highestX;
double m_maxX;
/// Lowest Y value
double m_lowestY;
double m_minY;
/// Highest Y value
double m_highestY;

private:
/// Test if a list of vertices is valid
void validate(const Vertex2D *head) const;
/// Compute the area of a triangle given by 3 points
double triangleArea(const Kernel::V2D &a, const Kernel::V2D &b,
const Kernel::V2D &c) const;
double m_maxY;
};

/// Print a polygon to a stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Includes
//------------------------------------------------------------------------------
#include "MantidGeometry/Math/ConvexPolygon.h"
#include "MantidGeometry/Math/Vertex2D.h"
#include "MantidKernel/V2D.h"

namespace Mantid {
namespace Geometry {
Expand All @@ -15,9 +15,6 @@ namespace Geometry {
A ConvexPolygon with only 4 vertices. Better performance as no dynamic
allocation
@author Martyn Gigg
@date 2011-07-22
Copyright &copy; 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
Expand Down Expand Up @@ -45,35 +42,46 @@ class DLLExport Quadrilateral : public ConvexPolygon {
Quadrilateral(const Kernel::V2D &lowerLeft, const Kernel::V2D &lowerRight,
const Kernel::V2D &upperRight, const Kernel::V2D &upperLeft);
/// Special constructor for a rectangle
Quadrilateral(const double lowerX, const double upperX, const double lowerY,
const double upperY);
Quadrilateral(const double lowerX, const double upperX,
const double lowerY, const double upperY);
/// Copy constructor
Quadrilateral(const Quadrilateral &other);
/// Copy-assignment operator
Quadrilateral &operator=(const Quadrilateral &rhs);

/// Destructor
~Quadrilateral();
/// Index access.
virtual const Kernel::V2D &operator[](const size_t index) const;
/// Compute the area of the quadrilateral
/// Return the number of vertices
virtual size_t npoints() const { return 4; }
/// Is a point inside this polygon
virtual bool contains(const Kernel::V2D &point) const;
/// Is a the given polygon completely encosed by this one
virtual bool contains(const ConvexPolygon &poly) const;
/// Compute the area of the polygon using triangulation
virtual double area() const;
/// Compute the 'determinant' of the points
virtual double determinant() const;
/// Return the lowest X value in the polygon
virtual double minX() const;
/// Return the max X value in the polygon
virtual double maxX() const;
/// Return the lowest Y value in the polygon
virtual double minY() const;
/// Return the max Y value in the polygon
virtual double maxY() const;


private:
/// Default constructor
Quadrilateral();
/// Initalize the object
void initialize();
/// Lower left
Vertex2D m_lowerLeft;
Kernel::V2D m_lowerLeft;
/// Lower right
Vertex2D m_lowerRight;
Kernel::V2D m_lowerRight;
/// Upper right
Vertex2D m_upperRight;
Kernel::V2D m_upperRight;
/// Upper left
Vertex2D m_upperLeft;
Kernel::V2D m_upperLeft;
};

} // namespace Geometry
Expand Down

0 comments on commit 283af1c

Please sign in to comment.