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

[disksampler] use new geometry sampler interface

parent af257c13
......@@ -23,7 +23,7 @@
// sampler for points and disks
#include <frackit/sampling/pointsampler.hh>
#include <frackit/sampling/geometrysampling.hh>
#include <frackit/sampling/disksampler.hh>
// constraints to be enforced on the network (distance, angles, etc.)
#include <frackit/entitynetwork/constraints.hh>
......@@ -78,7 +78,6 @@ int main(int argc, char** argv)
//////////////////////////////////////////////////////////////////////
using ctype = double;
using Disk = Disk<ctype>;
using DiskSampler = GeometrySampler<Disk>;
// sample points within bounding box of domain
const auto domainBBox = OCCUtilities::getBoundingBox(networkDomain);
......@@ -159,8 +158,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( pointSampler() )
: diskSampler2( pointSampler() );
total++;
// We don't want ellipses of too large aspect ratio
......
......@@ -30,15 +30,16 @@
#include <frackit/geometry/vector.hh>
#include <frackit/geometry/direction.hh>
#include "geometrysampling.hh"
#include "geometrysampler.hh"
namespace Frackit {
/*!
* \brief Specialization of the default traits for the disk sampler.
* \brief Default traits class for the disk sampler.
* Uses uniform distributions for all parameters.
*/
template<class ctype>
struct DefaultSamplerTraits<Disk<ctype>>
struct DefaultDiskSamplerTraits
{
// Distribution used for the major axis length
using MajorAxisLengthDistribution = std::normal_distribution<ctype>;
......@@ -60,7 +61,7 @@ struct DefaultSamplerTraits<Disk<ctype>>
};
/*!
* \brief Geometry sampler for disks.
* \brief Sampler for disk geometries.
* The disks are generated by sampling from provided
* distributions for:
* - major axis length
......@@ -76,8 +77,8 @@ struct DefaultSamplerTraits<Disk<ctype>>
* since independent sampling of the axis vectors is not possible
* due to the requirement that they must form an orthonormal basis.
*/
template< class ctype, class T >
class GeometrySampler< Disk<ctype>, T >
template< class ctype = double, class T = DefaultDiskSamplerTraits<ctype> >
class DiskSampler : public GeometrySampler< Disk<ctype> >
{
using MajorAxisLengthDistribution = typename T::MajorAxisLengthDistribution;
using MinorAxisLengthDistribution = typename T::MinorAxisLengthDistribution;
......@@ -106,11 +107,11 @@ public:
* \note For more info on the meaning of the rotation angles, see the description
* of this class.
*/
GeometrySampler(const MajorAxisLengthDistribution& majAxis,
const MinorAxisLengthDistribution& minAxis,
const XAngleDistribution& xAngle,
const YAngleDistribution& yAngle,
const ZAngleDistribution& zAngle)
DiskSampler(const MajorAxisLengthDistribution& majAxis,
const MinorAxisLengthDistribution& minAxis,
const XAngleDistribution& xAngle,
const YAngleDistribution& yAngle,
const ZAngleDistribution& zAngle)
: generator_(std::random_device{}())
, p_majorAxisLength_(majAxis)
, p_minorAxisLength_(minAxis)
......@@ -121,12 +122,10 @@ public:
/*!
* \brief Generate a random disk.
* \param pointSampler Point sampler class to
* randomly sample a point used
* as the center of the disk.
* \param point The point around which the disk should
* be created. This is taken as the disk center.
*/
template<class PointSampler>
Disk operator() (PointSampler& pointSampler)
Disk operator() (const Point<ctype, 3>& point) override
{
auto a = p_majorAxisLength_(generator_);
while (a <= 0.0) a = p_majorAxisLength_(generator_);
......@@ -136,7 +135,6 @@ public:
if (b > a) b = a;
const auto c = pointSampler();
const auto alpha = p_angle_x_(generator_);
const auto beta = p_angle_y_(generator_);
const auto gamma = p_angle_z_(generator_);
......@@ -159,7 +157,7 @@ public:
// rotate both axes around z
rotate(axes, e3, gamma);
return Disk(c, Direction(axes[0]), Direction(axes[1]), a, b);
return Disk(point, Direction(axes[0]), Direction(axes[1]), a, b);
}
private:
......
......@@ -12,7 +12,7 @@
#include <frackit/occ/breputilities.hh>
#include <frackit/sampling/pointsampler.hh>
#include <frackit/sampling/geometrysampling.hh>
#include <frackit/sampling/disksampler.hh>
#include <frackit/entitynetwork/constraints.hh>
......@@ -35,7 +35,6 @@ int main()
auto pointSampler = makeUniformPointSampler(domain);
// sampler for disks of orientation 1
using DiskSampler = GeometrySampler<Disk>;
DiskSampler diskSampler_1(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)),
......@@ -102,8 +101,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( pointSampler() )
: diskSampler_2( pointSampler() );
total++;
// We don't want ellipses of too large aspect ratio
......
......@@ -16,7 +16,7 @@
#include <frackit/occ/breputilities.hh>
#include <frackit/sampling/pointsampler.hh>
#include <frackit/sampling/geometrysampling.hh>
#include <frackit/sampling/disksampler.hh>
#include <frackit/entitynetwork/constraints.hh>
......@@ -52,7 +52,6 @@ int main(int argc, char** argv)
// create the disk samplers
using ctype = double;
using Disk = Disk<ctype>;
using DiskSampler = GeometrySampler<Disk>;
// sample points within bounding box of domain
auto pointSampler = makeUniformPointSampler(OCCUtilities::getBoundingBox(domain));
......@@ -124,8 +123,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( pointSampler() )
: diskSampler_2( pointSampler() );
total++;
// We don't want ellipses of too large aspect ratio
......
......@@ -22,7 +22,7 @@
#include <frackit/precision/precision.hh>
#include <frackit/sampling/pointsampler.hh>
#include <frackit/sampling/geometrysampling.hh>
#include <frackit/sampling/disksampler.hh>
#include <frackit/entitynetwork/containedentitynetwork.hh>
#include <frackit/entitynetwork/networkbuilder.hh>
......
......@@ -10,7 +10,8 @@
#include <frackit/common/math.hh>
#include <frackit/geometry/disk.hh>
#include <frackit/occ/breputilities.hh>
#include <frackit/sampling/geometrysampling.hh>
#include <frackit/sampling/disksampler.hh>
#include <frackit/sampling/pointsampler.hh>
//! test random sampling of points on geometries
......@@ -21,7 +22,6 @@ int main()
using namespace Frackit;
using Cylinder = Cylinder<ctype>;
using Disk = Disk<ctype>;
using DiskSampler = GeometrySampler<Disk>;
Cylinder cylinder(0.5, 1.0);
auto cylPointSampler = makeUniformPointSampler(cylinder);
......@@ -34,7 +34,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( cylPointSampler() ));
// 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