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

Merge branch 'feature/improve-geometry-sampler' into 'master'

Feature/improve geometry sampler

See merge request DennisGlaeser/frackit!18
parents 440d6dd1 5d8eab70
......@@ -22,8 +22,8 @@
#include <frackit/occ/breputilities.hh>
// sampler for points and disks
#include <frackit/sampling/pointsampling.hh>
#include <frackit/sampling/geometrysampling.hh>
#include <frackit/sampling/pointsampler.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
......
install(FILES
disksampler.hh
geometrysampler.hh
geometrysampling.hh
pointsampling.hh
pointsampler.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/frackit/sampling)
......@@ -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:
......
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*****************************************************************************
* See the file COPYING for full copying permissions. *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
/*!
* \file
* \brief Class that defines the interface for
* sampler classes of geometries.
*/
#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.
*/
template<class Geometry>
class GeometrySampler
{
using ctype = typename CoordinateTypeTraits<Geometry>::type;
static constexpr int worldDim = DimensionalityTraits<Geometry>::worldDimension();
public:
/*!
* \brief Creates an object of Geometry around the given point.
* \param point The point around which the geometry is to be created
*/
virtual Geometry operator() (const Point<ctype, worldDim>& point) = 0;
};
} // end namespace Frackit
#endif // FRACKIT_GEOMETRY_SAMPLER_HH
......@@ -38,7 +38,7 @@ template<class Geometry> struct DefaultSamplerTraits;
* sampler implementation.
*/
template<class Geometry, class T = DefaultSamplerTraits<Geometry>>
struct GeometrySampler;
class GeometrySampler;
} // end namespace Frackit
......
......@@ -11,8 +11,8 @@
#include <frackit/magnitude/containedmagnitude.hh>
#include <frackit/occ/breputilities.hh>
#include <frackit/sampling/pointsampling.hh>
#include <frackit/sampling/geometrysampling.hh>
#include <frackit/sampling/pointsampler.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
......
......@@ -15,8 +15,8 @@
#include <frackit/magnitude/containedmagnitude.hh>
#include <frackit/occ/breputilities.hh>
#include <frackit/sampling/pointsampling.hh>
#include <frackit/sampling/geometrysampling.hh>
#include <frackit/sampling/pointsampler.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
......
......@@ -21,8 +21,8 @@
#include <frackit/occ/breputilities.hh>
#include <frackit/precision/precision.hh>
#include <frackit/sampling/pointsampling.hh>
#include <frackit/sampling/geometrysampling.hh>
#include <frackit/sampling/pointsampler.hh>
#include <frackit/sampling/disksampler.hh>
#include <frackit/entitynetwork/containedentitynetwork.hh>
#include <frackit/entitynetwork/networkbuilder.hh>
......
......@@ -10,8 +10,9 @@
#include <frackit/common/math.hh>
#include <frackit/geometry/disk.hh>
#include <frackit/occ/breputilities.hh>
#include <frackit/sampling/geometrysampling.hh>
#include <frackit/sampling/pointsampling.hh>
#include <frackit/sampling/disksampler.hh>
#include <frackit/sampling/pointsampler.hh>
//! test random sampling of points on geometries
int main()
......@@ -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
......
......@@ -6,7 +6,7 @@
#include <BRep_Builder.hxx>
#include <TopoDS_Compound.hxx>
#include <frackit/sampling/pointsampling.hh>
#include <frackit/sampling/pointsampler.hh>
#include <frackit/geometry/point.hh>
#include <frackit/geometry/cylinder.hh>
#include <frackit/occ/breputilities.hh>
......
Supports Markdown
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