Commit a0ed591d authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[geometrysampler] remove point argument from () operator

Geometry samplers can now be called to return a random geometry by
simply calling the () operator, without the need to externally compute
the point around which the geometry is to be created. This means that
the point sampler is now contained in the geometry sampler class. The
only currently available implementation (DiskSampler) has been modified
accordingly.
parent b420c365
......@@ -34,7 +34,6 @@
// writes an entity network to a meshable Gmsh .geo file format
#include <frackit/io/gmshwriter.hh>
int main(int argc, char** argv)
{
//! print welcome message
......@@ -90,14 +89,16 @@ int main(int argc, char** argv)
const ctype meanMinAxisLength = 15.0;
// sampler for disks of orientation 1
DiskSampler diskSampler1(std::normal_distribution<ctype>(meanMajAxisLength, 6.5), // major axis length: mean value & standard deviation
DiskSampler diskSampler1(pointSampler, // sampler for disk center points
std::normal_distribution<ctype>(meanMajAxisLength, 6.5), // major axis length: mean value & standard deviation
std::normal_distribution<ctype>(meanMinAxisLength, 4.5), // minor axis length: mean value & standard deviation
std::normal_distribution<ctype>(toRadians(0.0), toRadians(7.5)), // rotation around x-axis: mean value & standard deviation
std::normal_distribution<ctype>(toRadians(0.0), toRadians(7.5)), // rotation around y-axis: mean value & standard deviation
std::normal_distribution<ctype>(toRadians(0.0), toRadians(7.5))); // rotation around z-axis: mean value & standard deviation
// sampler for disks of orientation 2
DiskSampler diskSampler2(std::normal_distribution<ctype>(meanMajAxisLength, 6.5), // major axis length: mean value & standard deviation
DiskSampler diskSampler2(pointSampler, // sampler for disk center points
std::normal_distribution<ctype>(meanMajAxisLength, 6.5), // major axis length: mean value & standard deviation
std::normal_distribution<ctype>(meanMinAxisLength, 4.5), // minor axis length: mean value & standard deviation
std::normal_distribution<ctype>(toRadians(90.0), toRadians(7.5)), // rotation around x-axis: mean value & standard deviation
std::normal_distribution<ctype>(toRadians(0.0), toRadians(7.5)), // rotation around y-axis: mean value & standard deviation
......@@ -158,8 +159,8 @@ int main(int argc, char** argv)
else if (createSecondary && accepted_2 == numTargetEntities_2)
createSecondary = false;
auto disk = createSecondary ? diskSampler1( pointSampler() )
: diskSampler2( pointSampler() );
auto disk = createSecondary ? diskSampler1()
: diskSampler2();
total++;
// We don't want ellipses of too large aspect ratio
......
......@@ -23,13 +23,17 @@
#ifndef FRACKIT_DISK_SAMPLER_HH
#define FRACKIT_DISK_SAMPLER_HH
#include <memory>
#include <random>
#include <type_traits>
#include <frackit/common/math.hh>
#include <frackit/geometry/disk.hh>
#include <frackit/geometry/point.hh>
#include <frackit/geometry/vector.hh>
#include <frackit/geometry/direction.hh>
#include <frackit/geometry/disk.hh>
#include "pointsampler.hh"
#include "geometrysampler.hh"
namespace Frackit {
......@@ -86,6 +90,7 @@ class DiskSampler : public GeometrySampler< Disk<ctype> >
using YAngleDistribution = typename T::YAngleDistribution;
using ZAngleDistribution = typename T::ZAngleDistribution;
using Point = Frackit::Point<ctype, 3>;
using Vector = Frackit::Vector<ctype, 3>;
using Direction = Frackit::Direction<ctype, 3>;
......@@ -99,6 +104,7 @@ public:
/*!
* \brief Constructor.
* \param pointSampler Samples the center points of the disks
* \param majAxis Distribution used to sample major axis lengths
* \param minAxis Distribution used to sample minor axis lengths
* \param xAngle Distribution used to sample the angle of rotation around x-axis
......@@ -107,25 +113,29 @@ public:
* \note For more info on the meaning of the rotation angles, see the description
* of this class.
*/
DiskSampler(const MajorAxisLengthDistribution& majAxis,
template<class PointSamplerImpl>
DiskSampler(PointSamplerImpl& pointSampler,
const MajorAxisLengthDistribution& majAxis,
const MinorAxisLengthDistribution& minAxis,
const XAngleDistribution& xAngle,
const YAngleDistribution& yAngle,
const ZAngleDistribution& zAngle)
: generator_(std::random_device{}())
: pointSampler_(std::make_shared<PointSamplerImpl>(pointSampler))
, generator_(std::random_device{}())
, p_majorAxisLength_(majAxis)
, p_minorAxisLength_(minAxis)
, p_angle_x_(xAngle)
, p_angle_y_(yAngle)
, p_angle_z_(zAngle)
{}
{
static_assert(std::is_base_of<PointSampler<Point>, PointSamplerImpl>::value,
"The provided point sampler does not inherit from the point sampler interface");
}
/*!
* \brief Generate a random disk.
* \param point The point around which the disk should
* be created. This is taken as the disk center.
*/
Disk operator() (const Point<ctype, 3>& point) override
Disk operator() () override
{
auto a = p_majorAxisLength_(generator_);
while (a <= 0.0) a = p_majorAxisLength_(generator_);
......@@ -157,17 +167,19 @@ public:
// rotate both axes around z
rotate(axes, e3, gamma);
return Disk(point, Direction(axes[0]), Direction(axes[1]), a, b);
// sample center point and make disk
return Disk((*pointSampler_)(), Direction(axes[0]), Direction(axes[1]), a, b);
}
private:
std::default_random_engine generator_;
MajorAxisLengthDistribution p_majorAxisLength_;
MinorAxisLengthDistribution p_minorAxisLength_;
XAngleDistribution p_angle_x_;
YAngleDistribution p_angle_y_;
ZAngleDistribution p_angle_z_;
std::shared_ptr<PointSampler<Point>> pointSampler_; //!< pointer to the sampler for disk center points
std::default_random_engine generator_; //!< Random number generator
MajorAxisLengthDistribution p_majorAxisLength_; //!< Distribution used for major axis length
MinorAxisLengthDistribution p_minorAxisLength_; //!< Distribution used for minor axis length
XAngleDistribution p_angle_x_; //!< Distribution used for x-axis rotation of local basis
YAngleDistribution p_angle_y_; //!< Distribution used for y-axis rotation of local basis
ZAngleDistribution p_angle_z_; //!< Distribution used for z-axis rotation of local basis
};
} // end namespace Frackit
......
......@@ -24,31 +24,28 @@
#ifndef FRACKIT_GEOMETRY_SAMPLER_HH
#define FRACKIT_GEOMETRY_SAMPLER_HH
#include <frackit/common/extractctype.hh>
#include <frackit/common/extractdimension.hh>
#include <frackit/geometry/point.hh>
namespace Frackit {
/*!
* \brief Interface for geometry sampler classes.
* The interface is defined by a () operator that
* receives a point, which is the point around which
* the geometry is to be created, and it returns an
* object of the geometry.
* Sampler class implemetations must implement
* the () operator, with which a random geometry
* of the given type is created.
* \tparam Geometry The type of the geometry to be sampled.
*/
template<class Geometry>
class GeometrySampler
{
using ctype = typename CoordinateTypeTraits<Geometry>::type;
static constexpr int worldDim = DimensionalityTraits<Geometry>::worldDimension();
public:
//! every abstract base class has a virtual destructor
virtual ~GeometrySampler () {}
/*!
* \brief Creates an object of Geometry around the given point.
* \param point The point around which the geometry is to be created
* \brief Creates an object of Geometry.
*/
virtual Geometry operator() (const Point<ctype, worldDim>& point) = 0;
virtual Geometry operator() () = 0;
};
} // end namespace Frackit
......
......@@ -35,14 +35,16 @@ int main()
auto pointSampler = makeUniformPointSampler(domain);
// sampler for disks of orientation 1
DiskSampler diskSampler_1(std::normal_distribution<ctype>(0.35, 0.1),
DiskSampler diskSampler_1(pointSampler,
std::normal_distribution<ctype>(0.35, 0.1),
std::normal_distribution<ctype>(0.225, 0.05),
std::normal_distribution<ctype>(toRadians(25.0), toRadians(5.0)),
std::normal_distribution<ctype>(toRadians(0.0), toRadians(5.0)),
std::normal_distribution<ctype>(toRadians(45.0), toRadians(5.0)));
// sampler for disks of orientation 1
DiskSampler diskSampler_2(std::normal_distribution<ctype>(0.35, 0.1),
DiskSampler diskSampler_2(pointSampler,
std::normal_distribution<ctype>(0.35, 0.1),
std::normal_distribution<ctype>(0.225, 0.05),
std::normal_distribution<ctype>(toRadians(-35.0), toRadians(5.0)),
std::normal_distribution<ctype>(toRadians(0.0), toRadians(5.0)),
......@@ -101,8 +103,8 @@ int main()
else if (createSecondary && accepted_2 == numTargetEntities_2)
createSecondary = false;
auto disk = createSecondary ? diskSampler_1( pointSampler() )
: diskSampler_2( pointSampler() );
auto disk = createSecondary ? diskSampler_1()
: diskSampler_2();
total++;
// We don't want ellipses of too large aspect ratio
......
......@@ -57,14 +57,16 @@ int main(int argc, char** argv)
auto pointSampler = makeUniformPointSampler(OCCUtilities::getBoundingBox(domain));
// sampler for disks of orientation 1
DiskSampler diskSampler_1(std::normal_distribution<ctype>(40.0, 6.5),
DiskSampler diskSampler_1(pointSampler,
std::normal_distribution<ctype>(40.0, 6.5),
std::normal_distribution<ctype>(20.0, 4.5),
std::normal_distribution<ctype>(toRadians(0.0), toRadians(5.0)),
std::normal_distribution<ctype>(toRadians(0.0), toRadians(5.0)),
std::normal_distribution<ctype>(toRadians(0.0), toRadians(5.0)));
// sampler for disks of orientation 1
DiskSampler diskSampler_2(std::normal_distribution<ctype>(40.0, 6.5),
DiskSampler diskSampler_2(pointSampler,
std::normal_distribution<ctype>(40.0, 6.5),
std::normal_distribution<ctype>(20.0, 4.5),
std::normal_distribution<ctype>(toRadians(45.0), toRadians(5.0)),
std::normal_distribution<ctype>(toRadians(0.0), toRadians(5.0)),
......@@ -123,8 +125,8 @@ int main(int argc, char** argv)
else if (createSecondary && accepted_2 == numTargetEntities_2)
createSecondary = false;
auto disk = createSecondary ? diskSampler_1( pointSampler() )
: diskSampler_2( pointSampler() );
auto disk = createSecondary ? diskSampler_1()
: diskSampler_2();
total++;
// We don't want ellipses of too large aspect ratio
......
......@@ -25,7 +25,8 @@ int main()
Cylinder cylinder(0.5, 1.0);
auto cylPointSampler = makeUniformPointSampler(cylinder);
DiskSampler diskSampler(std::normal_distribution<ctype>(0.5, 0.05),
DiskSampler diskSampler(cylPointSampler,
std::normal_distribution<ctype>(0.5, 0.05),
std::normal_distribution<ctype>(0.25, 0.025),
std::normal_distribution<ctype>(toRadians(45.0),toRadians(10.0)),
std::normal_distribution<ctype>(toRadians(45.0),toRadians(10.0)),
......@@ -34,7 +35,7 @@ int main()
// sample 5 disks
std::vector<Disk> disks;
for (unsigned int i = 0; i < 5; ++i)
disks.emplace_back(diskSampler( cylPointSampler() ));
disks.emplace_back(diskSampler());
// create a single compound and write to .brep file
// build a single compound shape
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment