Skip to content
Snippets Groups Projects
Commit 3d9c7c9d authored by BATON Theau's avatar BATON Theau
Browse files

Style change

parent 46e4e9f8
No related branches found
No related tags found
No related merge requests found
Showing
with 89 additions and 48 deletions
......@@ -2,8 +2,10 @@
#include "CurveGenerator.hpp"
namespace ct {
class CURVETOOLS_API BSplineGenerator : public CurveGenerator {
namespace ct
{
class CURVETOOLS_API BSplineGenerator : public CurveGenerator
{
private:
CurveGenerator* m_generator;
......
......@@ -2,12 +2,14 @@
#include "CurveGenerator.hpp"
namespace ct {
class CURVETOOLS_API BezierGenerator : public CurveGenerator {
namespace ct
{
class CURVETOOLS_API BezierGenerator : public CurveGenerator
{
public:
BezierGenerator(unsigned int degree = 1);
Point generate(const Curve& points, double t) const override;
std::vector<Point> generate(const Curve&, const std::vector<double> &) const override;
std::vector<Point> generate(const Curve& points, const std::vector<double>& ts) const override;
};
}
\ No newline at end of file
......@@ -5,11 +5,13 @@
#include <glm/glm.hpp>
namespace ct {
namespace ct
{
using Point = glm::dvec3;
using Curve = std::vector<Point>;
class CURVETOOLS_API CurveGenerator : public Generator<Point, double> {
class CURVETOOLS_API CurveGenerator : public Generator<Point, double>
{
public:
CurveGenerator(uint16_t degree);
......
#include "CurveTools/CPU/BSplineGenerator.hpp"
#include "CurveTools/CPU/CurveSampler.hpp"
namespace ct {
namespace ct
{
BSplineGenerator::BSplineGenerator(CurveGenerator* generator)
: CurveGenerator(0), m_generator(generator) {}
Point BSplineGenerator::generate(const Curve& points, double u) const {
Point BSplineGenerator::generate(const Curve& points, double u) const
{
unsigned int degree = m_generator->getDegree();
if (points.size() < degree) {
if (points.size() < degree)
{
return Point(0.0);
}
......@@ -18,14 +21,16 @@ namespace ct {
double t = std::modf(u, &k);
std::vector<Point> generatorPoints(degree);
for (unsigned int i = 0; i < degree; ++i) {
for (unsigned int i = 0; i < degree; ++i)
{
generatorPoints[i] = u == nbCurves ? points[static_cast<size_t>((degree - 1) * (k - 1) + i)] : points[static_cast<size_t>((degree - 1) * k + i)];
}
return this->m_generator->generate(generatorPoints, t);
}
std::vector<Point> BSplineGenerator::generate(const Curve& points, const std::vector<double> & us) const {
std::vector<Point> BSplineGenerator::generate(const Curve& points, const std::vector<double> & us) const
{
return CurveSampler::SampleCurve(points, *this, us);
}
}
\ No newline at end of file
#include "CurveTools/CPU/BezierGenerator.hpp"
#include "CurveTools/CPU/CurveSampler.hpp"
namespace ct {
namespace ct
{
BezierGenerator::BezierGenerator(unsigned int degree)
: CurveGenerator(degree) {}
Point BezierGenerator::generate(const Curve& points, double t) const {
if (points.size() < this->getDegree()) {
Point BezierGenerator::generate(const Curve& points, double t) const
{
if (points.size() < this->getDegree())
{
return Point(0.0);
}
std::vector<Point> currentPoints = points;
while (currentPoints.size() != 1) {
while (currentPoints.size() != 1)
{
std::vector<Point> nextPoints;
for (size_t i = 0; i < currentPoints.size() - 1; ++i) {
for (size_t i = 0; i < currentPoints.size() - 1; ++i)
{
Point a = currentPoints[i];
Point b = currentPoints[i + 1];
nextPoints.push_back(lerp(a, b, t));
......@@ -26,7 +31,8 @@ namespace ct {
return currentPoints.front();
}
std::vector<Point> BezierGenerator::generate(const Curve& points, const std::vector<double> & ts) const {
std::vector<Point> BezierGenerator::generate(const Curve& points, const std::vector<double> & ts) const
{
return CurveSampler::SampleCurve(points, *this, ts);
}
}
\ No newline at end of file
#include "CurveTools/CPU/CatmullRomGenerator.hpp"
#include "CurveTools/CPU/CurveSampler.hpp"
namespace ct {
namespace ct
{
CatmullRomGenerator::CatmullRomGenerator()
: CurveGenerator(4) {}
Point CatmullRomGenerator::generate(const Curve& points, double t) const {
if (points.size() < this->getDegree()) {
Point CatmullRomGenerator::generate(const Curve& points, double t) const
{
if (points.size() < this->getDegree())
{
return Point(0.0);
}
......@@ -23,7 +26,8 @@ namespace ct {
return (f1 * points[0] + f2 * points[1] + f3 * points[2] + f4 * points[3]) * 0.5;
}
std::vector<Point> CatmullRomGenerator::generate(const Curve& points, const std::vector<double> & ts) const {
std::vector<Point> CatmullRomGenerator::generate(const Curve& points, const std::vector<double> & ts) const
{
return CurveSampler::SampleCurve(points, *this, ts);
}
}
\ No newline at end of file
#include "CurveTools/CPU/CurveGenerator.hpp"
namespace ct {
namespace ct
{
CurveGenerator::CurveGenerator(uint16_t degree)
: Generator(degree) {}
Point CurveGenerator::lerp(const Point& a, const Point& b, double t) {
Point CurveGenerator::lerp(const Point& a, const Point& b, double t)
{
t = glm::clamp(t, 0.0, 1.0);
return (1.0f - t) * a + t * b;
}
Point CurveGenerator::smoothstep(const Point& a, const Point& b, double t) {
Point CurveGenerator::smoothstep(const Point& a, const Point& b, double t)
{
t = glm::clamp(t, 0.0, 1.0);
t = t * t * (3.0 - 2.0 * t);
return lerp(a, b, t);
}
Point CurveGenerator::smootherstep(const Point& a, const Point& b, double t) {
Point CurveGenerator::smootherstep(const Point& a, const Point& b, double t)
{
t = glm::clamp(t, 0.0, 1.0);
t = t * t * t * (6.0 * t * t - 15.0 * t + 10.0);
......
#include "CurveTools/CPU/CurveSampler.hpp"
namespace ct {
std::vector<double> CurveSampler::generateSampleValues(unsigned int count, double min, double max) {
namespace ct
{
std::vector<double> CurveSampler::generateSampleValues(unsigned int count, double min, double max)
{
std::vector<double> sampleValues(count);
double step = (max - min) / static_cast<double>(count - 1);
......@@ -12,7 +14,8 @@ namespace ct {
return sampleValues;
}
Curve CurveSampler::SampleCurve(const Curve& curve, const CurveGenerator& generator, const std::vector<double>& t) {
Curve CurveSampler::SampleCurve(const Curve& curve, const CurveGenerator& generator, const std::vector<double>& t)
{
ct::Curve sampledCurve(t.size());
for (unsigned int i = 0; i < t.size(); ++i)
......
#include "CurveTools/CPU/HermiteGenerator.hpp"
#include "CurveTools/CPU/CurveSampler.hpp"
namespace ct {
namespace ct
{
HermiteGenerator::HermiteGenerator()
: CurveGenerator(4) {}
Point HermiteGenerator::generate(const Curve& points, double t) const {
Point HermiteGenerator::generate(const Curve& points, double t) const
{
if (points.size() < this->getDegree()) {
return Point(0.0);
}
......@@ -23,7 +25,8 @@ namespace ct {
return f1 * points[0] + f2 * points[1] + f3 * points[3] + f4 * points[2];
}
std::vector<Point> HermiteGenerator::generate(const Curve& points, const std::vector<double> & ts) const {
std::vector<Point> HermiteGenerator::generate(const Curve& points, const std::vector<double> & ts) const
{
return CurveSampler::SampleCurve(points, *this, ts);
}
}
\ No newline at end of file
#include "CurveTools/CPU/LinearGenerator.hpp"
#include "CurveTools/CPU/CurveSampler.hpp"
namespace ct {
namespace ct
{
LinearGenerator::LinearGenerator()
: CurveGenerator(2) {}
Point LinearGenerator::generate(const Curve& points, double t) const {
Point LinearGenerator::generate(const Curve& points, double t) const
{
if (points.size() < this->getDegree()) {
return Point(0.0);
}
......@@ -13,7 +15,8 @@ namespace ct {
return lerp(points[0], points[1], t);
}
std::vector<Point> LinearGenerator::generate(const Curve& points, const std::vector<double> & ts) const {
std::vector<Point> LinearGenerator::generate(const Curve& points, const std::vector<double> & ts) const
{
return CurveSampler::SampleCurve(points, *this, ts);
}
}
\ No newline at end of file
#include "CurveTools/CPU/SmootherstepGenerator.hpp"
#include "CurveTools/CPU/CurveSampler.hpp"
namespace ct {
namespace ct
{
SmootherstepGenerator::SmootherstepGenerator()
: CurveGenerator(2) {}
Point SmootherstepGenerator::generate(const Curve& points, double t) const {
Point SmootherstepGenerator::generate(const Curve& points, double t) const
{
if (points.size() < this->getDegree()) {
return Point(0.0);
}
......@@ -13,7 +15,8 @@ namespace ct {
return smootherstep(points[0], points[1], t);
}
std::vector<Point> SmootherstepGenerator::generate(const Curve& points, const std::vector<double> & ts) const {
std::vector<Point> SmootherstepGenerator::generate(const Curve& points, const std::vector<double> & ts) const
{
return CurveSampler::SampleCurve(points, *this, ts);
}
}
\ No newline at end of file
#include "CurveTools/CPU/SmoothstepGenerator.hpp"
#include "CurveTools/CPU/CurveSampler.hpp"
namespace ct {
namespace ct
{
SmoothstepGenerator::SmoothstepGenerator()
: CurveGenerator(2) {}
Point SmoothstepGenerator::generate(const Curve& points, double t) const {
if (points.size() < this->getDegree()) {
Point SmoothstepGenerator::generate(const Curve& points, double t) const
{
if (points.size() < this->getDegree())
{
return Point(0.0);
}
return smoothstep(points[0], points[1], t);
}
std::vector<Point> SmoothstepGenerator::generate(const Curve& points, const std::vector<double> & ts) const {
std::vector<Point> SmoothstepGenerator::generate(const Curve& points, const std::vector<double> & ts) const
{
return CurveSampler::SampleCurve(points, *this, ts);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment