Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tools
frackit
Commits
2e555f1e
Commit
2e555f1e
authored
May 01, 2020
by
Dennis Gläser
Browse files
[python][sampling] add bindings for uniform point samplers
parent
d1766a06
Changes
9
Hide whitespace changes
Inline
Side-by-side
frackit/python/CMakeLists.txt
View file @
2e555f1e
add_subdirectory
(
common
)
add_subdirectory
(
geometry
)
add_subdirectory
(
precision
)
add_subdirectory
(
sampling
)
frackit/python/sampling/CMakeLists.txt
0 → 100644
View file @
2e555f1e
install
(
FILES
boxpointsampler.hh
cylinderpointsampler.hh
DESTINATION
${
CMAKE_INSTALL_INCLUDEDIR
}
/frackit/python/sampling
)
frackit/python/sampling/boxpointsampler.hh
0 → 100644
View file @
2e555f1e
// -*- 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 3 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/>. *
*****************************************************************************/
#ifndef FRACKIT_PYTHON_SAMPLING_BOX_POINT_SAMPLER_HH
#define FRACKIT_PYTHON_SAMPLING_BOX_POINT_SAMPLER_HH
#include
<string>
#include
<pybind11/pybind11.h>
#include
<frackit/sampling/uniformpointsamplertraits.hh>
#include
<frackit/sampling/boxpointsampler.hh>
#include
<frackit/sampling/pointsampler.hh>
namespace
Frackit
::
Python
{
namespace
py
=
pybind11
;
template
<
class
ctype
>
void
registerBoxPointSampler
(
py
::
module
&
module
)
{
// TODO: Once JIT compilation is available, rewrite this
// such that different distributions can be used
using
Traits
=
Frackit
::
UniformPointSamplerTraits
<
ctype
,
3
>
;
using
UniformSampler
=
Frackit
::
BoxPointSampler
<
ctype
,
Traits
>
;
using
Point
=
typename
UniformSampler
::
Point
;
using
SamplerInterface
=
PointSampler
<
Point
>
;
py
::
class_
<
UniformSampler
,
SamplerInterface
>
cls
(
module
,
"UniformBoxPointSampler"
);
using
namespace
py
::
literals
;
using
DistroBase1
=
typename
Traits
::
DistributionBase1
;
using
DistroBase2
=
typename
Traits
::
DistributionBase2
;
using
DistroBase3
=
typename
Traits
::
DistributionBase3
;
// register constructor
cls
.
def
(
py
::
init
<
const
DistroBase1
&
,
const
DistroBase2
&
,
const
DistroBase3
&>
(),
"distributionX"
_a
,
"distributionY"
_a
,
"distributionZ"
_a
);
// register point sample function
cls
.
def
(
"sample"
,
&
UniformSampler
::
operator
(),
"returns a randomly sampled point"
);
}
}
// end namespace Frackit::Python
#endif
frackit/python/sampling/cylinderpointsampler.hh
0 → 100644
View file @
2e555f1e
// -*- 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 3 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/>. *
*****************************************************************************/
#ifndef FRACKIT_PYTHON_SAMPLING_CYLINDER_POINT_SAMPLER_HH
#define FRACKIT_PYTHON_SAMPLING_CYLINDER_POINT_SAMPLER_HH
#include
<string>
#include
<pybind11/pybind11.h>
#include
<frackit/geometry/cylinder.hh>
#include
<frackit/sampling/uniformpointsamplertraits.hh>
#include
<frackit/sampling/cylinderpointsampler.hh>
#include
<frackit/sampling/pointsampler.hh>
namespace
Frackit
::
Python
{
namespace
py
=
pybind11
;
template
<
class
ctype
>
void
registerCylinderPointSampler
(
py
::
module
&
module
)
{
// TODO: Once JIT compilation is available, rewrite this
// such that different distributions can be used
using
Traits
=
Frackit
::
UniformPointSamplerTraits
<
ctype
,
3
>
;
using
UniformSampler
=
Frackit
::
CylinderPointSampler
<
ctype
,
Traits
>
;
using
Point
=
typename
UniformSampler
::
Point
;
using
SamplerInterface
=
PointSampler
<
Point
>
;
py
::
class_
<
UniformSampler
,
SamplerInterface
>
cls
(
module
,
"UniformCylinderPointSampler"
);
using
namespace
py
::
literals
;
using
Cylinder
=
Cylinder
<
ctype
>
;
using
DistroBase1
=
typename
Traits
::
DistributionBase1
;
using
DistroBase2
=
typename
Traits
::
DistributionBase2
;
using
DistroBase3
=
typename
Traits
::
DistributionBase3
;
// register constructor
cls
.
def
(
py
::
init
<
const
Cylinder
&
,
const
DistroBase1
&
,
const
DistroBase2
&
,
const
DistroBase3
&>
(),
"cylinder"
_a
,
"distributionR"
_a
,
"distributionPhi"
_a
,
"distributionH"
_a
);
// register point sample function
cls
.
def
(
"sample"
,
&
UniformSampler
::
operator
(),
"returns a randomly sampled point"
);
}
}
// end namespace Frackit::Python
#endif
frackit/python/sampling/pointsampler.hh
0 → 100644
View file @
2e555f1e
// -*- 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 3 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/>. *
*****************************************************************************/
#ifndef FRACKIT_PYTHON_SAMPLING_POINT_SAMPLER_HH
#define FRACKIT_PYTHON_SAMPLING_POINT_SAMPLER_HH
#include
<string>
#include
<pybind11/pybind11.h>
#include
<frackit/geometry/point.hh>
#include
<frackit/sampling/pointsampler.hh>
namespace
Frackit
::
Python
{
namespace
py
=
pybind11
;
template
<
class
ctype
,
int
worldDim
>
void
registerPointSamplerInterface
(
py
::
module
&
module
)
{
using
Point
=
Point
<
ctype
,
worldDim
>
;
using
Sampler
=
PointSampler
<
Point
>
;
std
::
string
className
=
"PointSamplerInterface_"
+
std
::
to_string
(
worldDim
);
py
::
class_
<
Sampler
>
cls
(
module
,
className
.
c_str
());
}
}
// end namespace Frackit::Python
#endif
python/frackit/CMakeLists.txt
View file @
2e555f1e
add_subdirectory
(
common
)
add_subdirectory
(
geometry
)
add_subdirectory
(
precision
)
add_subdirectory
(
sampling
)
python/frackit/sampling/CMakeLists.txt
0 → 100644
View file @
2e555f1e
frackit_symlink_or_copy
(
FILES __init__.py
)
pybind11_add_module
(
_sampling _sampling.cc
)
python/frackit/sampling/__init__.py
0 → 100644
View file @
2e555f1e
from
._sampling
import
*
python/frackit/sampling/_sampling.cc
0 → 100644
View file @
2e555f1e
// -*- 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 3 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/>. *
*****************************************************************************/
#include
<pybind11/pybind11.h>
#include
<frackit/geometry/box.hh>
#include
<frackit/geometry/cylinder.hh>
#include
<frackit/geometry/hollowcylinder.hh>
#include
<frackit/sampling/makeuniformpointsampler.hh>
#include
<frackit/python/sampling/pointsampler.hh>
#include
<frackit/python/sampling/boxpointsampler.hh>
#include
<frackit/python/sampling/cylinderpointsampler.hh>
namespace
Frackit
::
Python
{
template
<
class
ctype
>
auto
makeUniformBoxPointSampler
(
const
Frackit
::
Box
<
ctype
>&
box
)
->
decltype
(
Frackit
::
makeUniformPointSampler
(
box
))
{
return
Frackit
::
makeUniformPointSampler
(
box
);
}
template
<
class
ctype
>
auto
makeUniformCylinderPointSampler
(
const
Frackit
::
Cylinder
<
ctype
>&
cylinder
)
->
decltype
(
Frackit
::
makeUniformPointSampler
(
cylinder
))
{
return
Frackit
::
makeUniformPointSampler
(
cylinder
);
}
template
<
class
ctype
>
auto
makeUniformHollowCylinderPointSampler
(
const
Frackit
::
HollowCylinder
<
ctype
>&
hollowCyl
)
->
decltype
(
Frackit
::
makeUniformPointSampler
(
hollowCyl
))
{
return
Frackit
::
makeUniformPointSampler
(
hollowCyl
);
}
template
<
class
ctype
>
void
registerPointSamplerCreatorFunctions
(
pybind11
::
module
&
module
)
{
using
namespace
pybind11
::
literals
;
module
.
def
(
"makeUniformPointSampler"
,
&
makeUniformBoxPointSampler
<
ctype
>
,
"box"
_a
,
"returns a uniform point sampler on the given box"
);
module
.
def
(
"makeUniformPointSampler"
,
&
makeUniformCylinderPointSampler
<
ctype
>
,
"cylinder"
_a
,
"returns a uniform point sampler on the given cylinder"
);
module
.
def
(
"makeUniformPointSampler"
,
&
makeUniformHollowCylinderPointSampler
<
ctype
>
,
"hollowcylinder"
_a
,
"returns a uniform point sampler on the given hollow cylinder"
);
}
}
// end namespace Frackit::Python
PYBIND11_MODULE
(
_sampling
,
module
)
{
// register base class for all dimensions
Frackit
::
Python
::
registerPointSamplerInterface
<
double
,
1
>
(
module
);
Frackit
::
Python
::
registerPointSamplerInterface
<
double
,
2
>
(
module
);
Frackit
::
Python
::
registerPointSamplerInterface
<
double
,
3
>
(
module
);
// register point samplers on geometries
Frackit
::
Python
::
registerBoxPointSampler
<
double
>
(
module
);
Frackit
::
Python
::
registerCylinderPointSampler
<
double
>
(
module
);
// register creator functions
Frackit
::
Python
::
registerPointSamplerCreatorFunctions
<
double
>
(
module
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment