From 46e4e9f8e1b41717dda34904266c87f1b999268a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9au?= <theau.baton@etu.univ-amu.fr> Date: Wed, 22 May 2024 20:18:10 +0200 Subject: [PATCH] CurveTools Refactoring --- CurveTools/CMakeLists.txt | 4 +-- .../CurveTools/CPU/BSplineGenerator.hpp | 9 +++-- .../CurveTools/CPU/BezierGenerator.hpp | 11 +++--- .../CurveTools/CPU/CatmullRomGenerator.hpp | 3 +- .../include/CurveTools/CPU/CurveGenerator.hpp | 25 +++++--------- .../include/CurveTools/CPU/CurveSampler.hpp | 2 +- .../CurveTools/CPU/HermiteGenerator.hpp | 4 ++- .../CurveTools/CPU/LinearGenerator.hpp | 3 +- .../CurveTools/CPU/SmootherstepGenerator.hpp | 3 +- .../CurveTools/CPU/SmoothstepGenerator.hpp | 3 +- .../CurveTools/GPU/BezierGenerator.cuh | 4 +-- .../CurveTools/GPU/CatmullRomGenerator.cuh | 4 +-- .../include/CurveTools/GPU/Generator.cuh | 15 -------- .../CurveTools/GPU/HermiteGenerator.cuh | 4 +-- .../CurveTools/GPU/LinearGenerator.cuh | 4 +-- .../CurveTools/GPU/SmootherstepGenerator.cuh | 4 +-- .../CurveTools/GPU/SmoothstepGenerator.cuh | 4 +-- .../CurveTools/GPU/SplineGenerator.cuh | 16 ++++++--- .../CurveTools/GPU/StreamedGenerator.cuh | 17 ++++++---- CurveTools/include/CurveTools/Generator.hpp | 23 +++++++++++++ CurveTools/src/CPU/BSplineGenerator.cpp | 33 ++++++++---------- CurveTools/src/CPU/BezierGenerator.cpp | 29 +++++++--------- CurveTools/src/CPU/CatmullRomGenerator.cpp | 21 ++++++------ CurveTools/src/CPU/CurveGenerator.cpp | 24 ++++--------- CurveTools/src/CPU/CurveSampler.cpp | 9 ++--- CurveTools/src/CPU/HermiteGenerator.cpp | 21 ++++++------ CurveTools/src/CPU/LinearGenerator.cpp | 21 ++++++------ CurveTools/src/CPU/SmootherstepGenerator.cpp | 21 ++++++------ CurveTools/src/CPU/SmoothstepGenerator.cpp | 21 ++++++------ CurveTools/src/GPU/Core/BezierGenerator.cu | 4 +-- .../src/GPU/Core/CatmullRomGenerator.cu | 4 +-- CurveTools/src/GPU/Core/HermiteGenerator.cu | 4 +-- CurveTools/src/GPU/Core/Lineargenerator.cu | 4 +-- .../src/GPU/Core/SmootherstepGenerator.cu | 4 +-- .../src/GPU/Core/SmoothstepGenerator.cu | 4 +-- CurveTools/src/GPU/Core/SplineGenerator.cu | 34 +++++++++---------- ParticleGenerator/src/Mesh/Trajectory.cpp | 4 +-- 37 files changed, 210 insertions(+), 214 deletions(-) delete mode 100644 CurveTools/include/CurveTools/GPU/Generator.cuh create mode 100644 CurveTools/include/CurveTools/Generator.hpp diff --git a/CurveTools/CMakeLists.txt b/CurveTools/CMakeLists.txt index bb573dc..035b3c4 100644 --- a/CurveTools/CMakeLists.txt +++ b/CurveTools/CMakeLists.txt @@ -60,8 +60,8 @@ project(${PROJECT_NAME} LANGUAGES CXX CUDA) set(CURRENT_TARGET ${LIBRARY_NAME}) -#add_library(${CURRENT_TARGET}) -add_executable(${CURRENT_TARGET}) +add_library(${CURRENT_TARGET}) +#add_executable(${CURRENT_TARGET}) target_include_directories(${CURRENT_TARGET} PUBLIC ${INCLUDE_DIRECTORY}) diff --git a/CurveTools/include/CurveTools/CPU/BSplineGenerator.hpp b/CurveTools/include/CurveTools/CPU/BSplineGenerator.hpp index 220b6c5..50e66aa 100644 --- a/CurveTools/include/CurveTools/CPU/BSplineGenerator.hpp +++ b/CurveTools/include/CurveTools/CPU/BSplineGenerator.hpp @@ -2,16 +2,15 @@ #include "CurveGenerator.hpp" -namespace ct -{ - class CURVETOOLS_API BSplineGenerator : public CurveGenerator - { +namespace ct { + class CURVETOOLS_API BSplineGenerator : public CurveGenerator { private: CurveGenerator* m_generator; public: BSplineGenerator(CurveGenerator* generator); - Point operator()(const Curve& points, double u) const override; + Point generate(const Curve& points, double u) const override; + std::vector<Point> generate(const Curve& points, const std::vector<double> & us) const override; }; } \ No newline at end of file diff --git a/CurveTools/include/CurveTools/CPU/BezierGenerator.hpp b/CurveTools/include/CurveTools/CPU/BezierGenerator.hpp index 2887b25..fc7b4b7 100644 --- a/CurveTools/include/CurveTools/CPU/BezierGenerator.hpp +++ b/CurveTools/include/CurveTools/CPU/BezierGenerator.hpp @@ -2,13 +2,12 @@ #include "CurveGenerator.hpp" -namespace ct -{ - class CURVETOOLS_API BezierGenerator : public CurveGenerator - { +namespace ct { + class CURVETOOLS_API BezierGenerator : public CurveGenerator { public: - BezierGenerator(unsigned int degree = 3); + BezierGenerator(unsigned int degree = 1); - Point operator()(const Curve& points, double t) const override; + Point generate(const Curve& points, double t) const override; + std::vector<Point> generate(const Curve&, const std::vector<double> &) const override; }; } \ No newline at end of file diff --git a/CurveTools/include/CurveTools/CPU/CatmullRomGenerator.hpp b/CurveTools/include/CurveTools/CPU/CatmullRomGenerator.hpp index 0b1f9d5..4060a2f 100644 --- a/CurveTools/include/CurveTools/CPU/CatmullRomGenerator.hpp +++ b/CurveTools/include/CurveTools/CPU/CatmullRomGenerator.hpp @@ -9,6 +9,7 @@ namespace ct public: CatmullRomGenerator(); - Point operator()(const Curve& points, double t) const override; + Point generate(const Curve& points, double t) const override; + std::vector<Point> generate(const Curve& points, const std::vector<double> & us) const override; }; } \ No newline at end of file diff --git a/CurveTools/include/CurveTools/CPU/CurveGenerator.hpp b/CurveTools/include/CurveTools/CPU/CurveGenerator.hpp index 04b00ca..43c42f5 100644 --- a/CurveTools/include/CurveTools/CPU/CurveGenerator.hpp +++ b/CurveTools/include/CurveTools/CPU/CurveGenerator.hpp @@ -1,29 +1,20 @@ #pragma once #include "Export.hpp" +#include "../Generator.hpp" #include <glm/glm.hpp> -#include <vector> -namespace ct -{ +namespace ct { using Point = glm::dvec3; using Curve = std::vector<Point>; - class CURVETOOLS_API CurveGenerator - { - protected: - unsigned int m_degree; + class CURVETOOLS_API CurveGenerator : public Generator<Point, double> { + public: + CurveGenerator(uint16_t degree); - public: - CurveGenerator(unsigned int degree); - - unsigned int getDegree() const; - - virtual Point operator()(const Curve& points, double t) const = 0; - - static Point lerp(const Point& a, const Point& b, double t); - static Point smoothstep(const Point& a, const Point& b, double t); - static Point smootherstep(const Point& a, const Point& b, double t); + static Point lerp(const Point& a, const Point& b, double t); + static Point smoothstep(const Point& a, const Point& b, double t); + static Point smootherstep(const Point& a, const Point& b, double t); }; } \ No newline at end of file diff --git a/CurveTools/include/CurveTools/CPU/CurveSampler.hpp b/CurveTools/include/CurveTools/CPU/CurveSampler.hpp index b92fbfc..c916e1e 100644 --- a/CurveTools/include/CurveTools/CPU/CurveSampler.hpp +++ b/CurveTools/include/CurveTools/CPU/CurveSampler.hpp @@ -8,6 +8,6 @@ namespace ct { public: static std::vector<double> generateSampleValues(unsigned int count, double min, double max); - static Curve sampleCurve(const Curve& curve, const CurveGenerator& generator, const std::vector<double>& t); + static Curve SampleCurve(const Curve& curve, const CurveGenerator& generator, const std::vector<double>& t); }; } \ No newline at end of file diff --git a/CurveTools/include/CurveTools/CPU/HermiteGenerator.hpp b/CurveTools/include/CurveTools/CPU/HermiteGenerator.hpp index b7f996a..6c4893e 100644 --- a/CurveTools/include/CurveTools/CPU/HermiteGenerator.hpp +++ b/CurveTools/include/CurveTools/CPU/HermiteGenerator.hpp @@ -9,6 +9,8 @@ namespace ct public: HermiteGenerator(); - Point operator()(const Curve& points, double t) const override; + Point generate(const Curve& points, double t) const override; + std::vector<Point> generate(const Curve& points, const std::vector<double> & us) const override; + }; } \ No newline at end of file diff --git a/CurveTools/include/CurveTools/CPU/LinearGenerator.hpp b/CurveTools/include/CurveTools/CPU/LinearGenerator.hpp index 0be6c2a..a89e626 100644 --- a/CurveTools/include/CurveTools/CPU/LinearGenerator.hpp +++ b/CurveTools/include/CurveTools/CPU/LinearGenerator.hpp @@ -9,6 +9,7 @@ namespace ct public: LinearGenerator(); - Point operator()(const Curve& points, double t) const override; + Point generate(const Curve& points, double t) const override; + std::vector<Point> generate(const Curve& points, const std::vector<double> & us) const override; }; } \ No newline at end of file diff --git a/CurveTools/include/CurveTools/CPU/SmootherstepGenerator.hpp b/CurveTools/include/CurveTools/CPU/SmootherstepGenerator.hpp index 48390be..07bdf7a 100644 --- a/CurveTools/include/CurveTools/CPU/SmootherstepGenerator.hpp +++ b/CurveTools/include/CurveTools/CPU/SmootherstepGenerator.hpp @@ -9,6 +9,7 @@ namespace ct public: SmootherstepGenerator(); - Point operator()(const Curve& points, double t) const override; + Point generate(const Curve& points, double t) const override; + std::vector<Point> generate(const Curve& points, const std::vector<double> & us) const override; }; } \ No newline at end of file diff --git a/CurveTools/include/CurveTools/CPU/SmoothstepGenerator.hpp b/CurveTools/include/CurveTools/CPU/SmoothstepGenerator.hpp index 25ede85..12dfa7c 100644 --- a/CurveTools/include/CurveTools/CPU/SmoothstepGenerator.hpp +++ b/CurveTools/include/CurveTools/CPU/SmoothstepGenerator.hpp @@ -9,6 +9,7 @@ namespace ct public: SmoothstepGenerator(); - Point operator()(const Curve& points, double t) const override; + Point generate(const Curve& points, double t) const override; + std::vector<Point> generate(const Curve& points, const std::vector<double> & us) const override; }; } \ No newline at end of file diff --git a/CurveTools/include/CurveTools/GPU/BezierGenerator.cuh b/CurveTools/include/CurveTools/GPU/BezierGenerator.cuh index 20c7e57..bf8455d 100644 --- a/CurveTools/include/CurveTools/GPU/BezierGenerator.cuh +++ b/CurveTools/include/CurveTools/GPU/BezierGenerator.cuh @@ -5,8 +5,8 @@ namespace ct::gpu { class BezierGenerator : public StreamedGenerator { public: - __host__ virtual Point operator()(const thrust::universal_vector<Point> &, const float) const override; - __host__ virtual Curve operator()(const thrust::universal_vector<Point> &, const std::vector<float> &, const cudaStream_t & = 0) const; + __host__ Point generate(const thrust::universal_vector<Point> &, const float) const override; + __host__ Curve generate(const thrust::universal_vector<Point> &, const std::vector<float> &, const cudaStream_t & = 0) const; }; namespace kernel { diff --git a/CurveTools/include/CurveTools/GPU/CatmullRomGenerator.cuh b/CurveTools/include/CurveTools/GPU/CatmullRomGenerator.cuh index 96e7e00..153325d 100644 --- a/CurveTools/include/CurveTools/GPU/CatmullRomGenerator.cuh +++ b/CurveTools/include/CurveTools/GPU/CatmullRomGenerator.cuh @@ -5,8 +5,8 @@ namespace ct::gpu { class CatmullRomGenerator : public StreamedGenerator { public: - __host__ virtual Point operator()(const thrust::universal_vector<Point> &, const float) const override; - __host__ virtual Curve operator()(const thrust::universal_vector<Point> &, const std::vector<float> &, const cudaStream_t & = 0) const; + __host__ virtual Point generate(const thrust::universal_vector<Point> &, const float) const override; + __host__ virtual Curve generate(const thrust::universal_vector<Point> &, const std::vector<float> &, const cudaStream_t & = 0) const; }; namespace kernel { diff --git a/CurveTools/include/CurveTools/GPU/Generator.cuh b/CurveTools/include/CurveTools/GPU/Generator.cuh deleted file mode 100644 index 4a89d65..0000000 --- a/CurveTools/include/CurveTools/GPU/Generator.cuh +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include <thrust/universal_vector.h> -#include "CurveTools/GPU/Tools/Types.cuh" - -namespace ct::gpu { - using Point = Vec; - using Curve = std::vector<Point>; - - class Generator { - public: - __host__ virtual Point operator()(const thrust::universal_vector<Point> &, const float) const = 0; - __host__ virtual Curve operator()(const thrust::universal_vector<Point> &, const std::vector<float> &) const = 0; - }; -} \ No newline at end of file diff --git a/CurveTools/include/CurveTools/GPU/HermiteGenerator.cuh b/CurveTools/include/CurveTools/GPU/HermiteGenerator.cuh index 2ab2be0..e826bbf 100644 --- a/CurveTools/include/CurveTools/GPU/HermiteGenerator.cuh +++ b/CurveTools/include/CurveTools/GPU/HermiteGenerator.cuh @@ -5,8 +5,8 @@ namespace ct::gpu { class HermiteGenerator : public StreamedGenerator { public: - __host__ virtual Point operator()(const thrust::universal_vector<Point> &, const float) const override; - __host__ virtual Curve operator()(const thrust::universal_vector<Point> &, const std::vector<float> &, const cudaStream_t & = 0) const; + __host__ virtual Point generate(const thrust::universal_vector<Point> &, const float) const override; + __host__ virtual Curve generate(const thrust::universal_vector<Point> &, const std::vector<float> &, const cudaStream_t & = 0) const; }; namespace kernel { diff --git a/CurveTools/include/CurveTools/GPU/LinearGenerator.cuh b/CurveTools/include/CurveTools/GPU/LinearGenerator.cuh index 7c8f300..5ba9dfa 100644 --- a/CurveTools/include/CurveTools/GPU/LinearGenerator.cuh +++ b/CurveTools/include/CurveTools/GPU/LinearGenerator.cuh @@ -7,8 +7,8 @@ namespace ct::gpu { public: LinearGenerator(); - __host__ virtual Point operator()(const thrust::universal_vector<Point> &, const float) const; - __host__ virtual Curve operator()(const thrust::universal_vector<Point> &, const std::vector<float> &, const cudaStream_t & = 0) const; + __host__ virtual Point generate(const thrust::universal_vector<Point> &, const float) const; + __host__ virtual Curve generate(const thrust::universal_vector<Point> &, const std::vector<float> &, const cudaStream_t & = 0) const; }; namespace kernel { diff --git a/CurveTools/include/CurveTools/GPU/SmootherstepGenerator.cuh b/CurveTools/include/CurveTools/GPU/SmootherstepGenerator.cuh index 141db98..4a7e33d 100644 --- a/CurveTools/include/CurveTools/GPU/SmootherstepGenerator.cuh +++ b/CurveTools/include/CurveTools/GPU/SmootherstepGenerator.cuh @@ -7,8 +7,8 @@ namespace ct::gpu { public: SmootherstepGenerator(); - __host__ virtual Point operator()(const thrust::universal_vector<Point> &, const float) const; - __host__ virtual Curve operator()(const thrust::universal_vector<Point> &, const std::vector<float> &, const cudaStream_t & = 0) const; + __host__ virtual Point generate(const thrust::universal_vector<Point> &, const float) const; + __host__ virtual Curve generate(const thrust::universal_vector<Point> &, const std::vector<float> &, const cudaStream_t & = 0) const; }; namespace kernel { diff --git a/CurveTools/include/CurveTools/GPU/SmoothstepGenerator.cuh b/CurveTools/include/CurveTools/GPU/SmoothstepGenerator.cuh index 1868fe4..3751d53 100644 --- a/CurveTools/include/CurveTools/GPU/SmoothstepGenerator.cuh +++ b/CurveTools/include/CurveTools/GPU/SmoothstepGenerator.cuh @@ -7,8 +7,8 @@ namespace ct::gpu { public: SmoothstepGenerator(); - __host__ virtual Point operator()(const thrust::universal_vector<Point> &, const float) const; - __host__ virtual Curve operator()(const thrust::universal_vector<Point> &, const std::vector<float> &, const cudaStream_t & = 0) const; + __host__ virtual Point generate(const thrust::universal_vector<Point> &, const float) const; + __host__ virtual Curve generate(const thrust::universal_vector<Point> &, const std::vector<float> &, const cudaStream_t & = 0) const; }; namespace kernel { diff --git a/CurveTools/include/CurveTools/GPU/SplineGenerator.cuh b/CurveTools/include/CurveTools/GPU/SplineGenerator.cuh index 238a7e4..40a1295 100644 --- a/CurveTools/include/CurveTools/GPU/SplineGenerator.cuh +++ b/CurveTools/include/CurveTools/GPU/SplineGenerator.cuh @@ -1,6 +1,6 @@ #pragma once -#include "Generator.cuh" +#include "../Generator.hpp" #include <memory> #include <thrust/universal_vector.h> @@ -8,10 +8,9 @@ #include "StreamedGenerator.cuh" namespace ct::gpu { - class SplineGenerator : public Generator { + class SplineGenerator : public Generator<Point, float> { private: size_t _streamsCount; - size_t _cut; StreamedGenerator * _generator; public: @@ -20,8 +19,15 @@ namespace ct::gpu { inline StreamedGenerator * generator() const {return this->_generator;} - __host__ virtual Point operator()(const thrust::universal_vector<Point> &, float) const; - __host__ virtual Curve operator()(const thrust::universal_vector<Point> &, const std::vector<float> &) const; + __host__ Point generate(const thrust::universal_vector<Point> &, float) const; + __host__ Curve generate(const thrust::universal_vector<Point> &, const std::vector<float> &) const; + + virtual Point generate(const std::vector<Point> & pts, float u) const override final { + return this->generate(thrust::universal_vector<Point>(pts), u); + } + virtual std::vector<Point> generate(const std::vector<Point> & pts, const std::vector<float> & us) const override final { + return this->generate(thrust::universal_vector<Point>(pts), us); + } }; } \ No newline at end of file diff --git a/CurveTools/include/CurveTools/GPU/StreamedGenerator.cuh b/CurveTools/include/CurveTools/GPU/StreamedGenerator.cuh index 72e3c42..2a4c580 100644 --- a/CurveTools/include/CurveTools/GPU/StreamedGenerator.cuh +++ b/CurveTools/include/CurveTools/GPU/StreamedGenerator.cuh @@ -1,6 +1,6 @@ #pragma once -#include "Generator.cuh" +#include "../Generator.hpp" #include <thrust/universal_vector.h> #include "CurveTools/GPU/Tools/Types.cuh" @@ -9,12 +9,17 @@ namespace ct::gpu { using Point = Vec; using Curve = std::vector<Point>; - class StreamedGenerator : public Generator { + class StreamedGenerator : public Generator<Point, float> { public: - __host__ virtual Point operator()(const thrust::universal_vector<Point> &, const float) const = 0; - __host__ virtual Curve operator()(const thrust::universal_vector<Point> &, const std::vector<float> &, const cudaStream_t &) const = 0; - __host__ virtual Curve operator()(const thrust::universal_vector<Point> & ctrlPoint, const std::vector<float> & ps) const override final { - return (*this)(ctrlPoint, ps, 0); + __host__ virtual Point generate(const thrust::universal_vector<Point> &, const float) const = 0; + __host__ virtual Curve generate(const thrust::universal_vector<Point> &, const std::vector<float> &, const cudaStream_t & = 0) const = 0; + + inline Point generate(const Curve& points, float p) const override final { + return this->generate(thrust::universal_vector<Point>(points), p); + } + + inline std::vector<Point> generate(const Curve& points, const std::vector<float> & ps) const override final { + return this->generate(thrust::universal_vector<Point>(points), ps); } }; } \ No newline at end of file diff --git a/CurveTools/include/CurveTools/Generator.hpp b/CurveTools/include/CurveTools/Generator.hpp new file mode 100644 index 0000000..ae8b671 --- /dev/null +++ b/CurveTools/include/CurveTools/Generator.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include <stdint.h> +#include <vector> + +namespace ct { + template <typename T, typename U> + class Generator { + private: + const uint16_t _degree; + + public: + inline Generator(uint16_t degree = 1) : _degree(degree) {} + + inline uint16_t getDegree() const {return this->_degree;} + + virtual T generate(const std::vector<T> &, U) const = 0; + virtual std::vector<T> generate(const std::vector<T> &, const std::vector<U> &) const = 0; + + inline T operator()(const std::vector<T> & pts, U p) const {return this->generate(pts, p);} + inline std::vector<T> operator()(const std::vector<T> & pts, const std::vector<U> & ps) {return this->generate(pts, ps);} + }; +} \ No newline at end of file diff --git a/CurveTools/src/CPU/BSplineGenerator.cpp b/CurveTools/src/CPU/BSplineGenerator.cpp index 1906acd..ecfa901 100644 --- a/CurveTools/src/CPU/BSplineGenerator.cpp +++ b/CurveTools/src/CPU/BSplineGenerator.cpp @@ -1,20 +1,15 @@ #include "CurveTools/CPU/BSplineGenerator.hpp" +#include "CurveTools/CPU/CurveSampler.hpp" -namespace ct -{ - BSplineGenerator::BSplineGenerator(CurveGenerator* generator) : - CurveGenerator(0), - m_generator(generator) - { +namespace ct { + BSplineGenerator::BSplineGenerator(CurveGenerator* generator) + : CurveGenerator(0), m_generator(generator) {} - } - - Point BSplineGenerator::operator()(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); + } unsigned int nbCurves = static_cast<unsigned int>(std::ceil((points.size() - degree + 1) / static_cast<double>(degree - 1))); u = glm::clamp(u, 0.0, static_cast<double>(nbCurves)); @@ -23,14 +18,14 @@ namespace ct double t = std::modf(u, &k); std::vector<Point> generatorPoints(degree); - for (unsigned int i = 0; i < degree; ++i) - { - if (u == nbCurves) - generatorPoints[i] = points[static_cast<size_t>((degree - 1) * (k - 1) + i)]; - else - generatorPoints[i] = points[static_cast<size_t>((degree - 1) * k + 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 (*m_generator)(generatorPoints, t); + return this->m_generator->generate(generatorPoints, t); + } + + 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 diff --git a/CurveTools/src/CPU/BezierGenerator.cpp b/CurveTools/src/CPU/BezierGenerator.cpp index ae307fa..c2b2c1e 100644 --- a/CurveTools/src/CPU/BezierGenerator.cpp +++ b/CurveTools/src/CPU/BezierGenerator.cpp @@ -1,29 +1,22 @@ #include "CurveTools/CPU/BezierGenerator.hpp" +#include "CurveTools/CPU/CurveSampler.hpp" -namespace ct -{ - BezierGenerator::BezierGenerator(unsigned int degree) : - CurveGenerator(degree) - { +namespace ct { + BezierGenerator::BezierGenerator(unsigned int degree) + : CurveGenerator(degree) {} - } - - Point BezierGenerator::operator()(const Curve& points, double t) const - { - if (points.size() < m_degree) + 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)); } @@ -32,4 +25,8 @@ namespace ct return currentPoints.front(); } + + 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 diff --git a/CurveTools/src/CPU/CatmullRomGenerator.cpp b/CurveTools/src/CPU/CatmullRomGenerator.cpp index 5f9025e..ca35e77 100644 --- a/CurveTools/src/CPU/CatmullRomGenerator.cpp +++ b/CurveTools/src/CPU/CatmullRomGenerator.cpp @@ -1,17 +1,14 @@ #include "CurveTools/CPU/CatmullRomGenerator.hpp" +#include "CurveTools/CPU/CurveSampler.hpp" -namespace ct -{ - CatmullRomGenerator::CatmullRomGenerator() : - CurveGenerator(4) - { +namespace ct { + CatmullRomGenerator::CatmullRomGenerator() + : CurveGenerator(4) {} - } - - Point CatmullRomGenerator::operator()(const Curve& points, double t) const - { - if (points.size() < m_degree) + Point CatmullRomGenerator::generate(const Curve& points, double t) const { + if (points.size() < this->getDegree()) { return Point(0.0); + } t = glm::clamp(t, 0.0, 1.0); @@ -25,4 +22,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 { + return CurveSampler::SampleCurve(points, *this, ts); + } } \ No newline at end of file diff --git a/CurveTools/src/CPU/CurveGenerator.cpp b/CurveTools/src/CPU/CurveGenerator.cpp index 8736206..86a0505 100644 --- a/CurveTools/src/CPU/CurveGenerator.cpp +++ b/CurveTools/src/CPU/CurveGenerator.cpp @@ -1,35 +1,23 @@ #include "CurveTools/CPU/CurveGenerator.hpp" -namespace ct -{ - CurveGenerator::CurveGenerator(unsigned int degree) : - m_degree(degree) - { +namespace ct { + CurveGenerator::CurveGenerator(uint16_t degree) + : Generator(degree) {} - } - - unsigned int CurveGenerator::getDegree() const - { - return m_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); diff --git a/CurveTools/src/CPU/CurveSampler.cpp b/CurveTools/src/CPU/CurveSampler.cpp index 913d7fb..37809a6 100644 --- a/CurveTools/src/CPU/CurveSampler.cpp +++ b/CurveTools/src/CPU/CurveSampler.cpp @@ -1,9 +1,7 @@ #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); @@ -14,8 +12,7 @@ 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) diff --git a/CurveTools/src/CPU/HermiteGenerator.cpp b/CurveTools/src/CPU/HermiteGenerator.cpp index 5def6d1..c006e28 100644 --- a/CurveTools/src/CPU/HermiteGenerator.cpp +++ b/CurveTools/src/CPU/HermiteGenerator.cpp @@ -1,17 +1,14 @@ #include "CurveTools/CPU/HermiteGenerator.hpp" +#include "CurveTools/CPU/CurveSampler.hpp" -namespace ct -{ - HermiteGenerator::HermiteGenerator() : - CurveGenerator(4) - { +namespace ct { + HermiteGenerator::HermiteGenerator() + : CurveGenerator(4) {} - } - - Point HermiteGenerator::operator()(const Curve& points, double t) const - { - if (points.size() < m_degree) + Point HermiteGenerator::generate(const Curve& points, double t) const { + if (points.size() < this->getDegree()) { return Point(0.0); + } t = glm::clamp(t, 0.0, 1.0); @@ -25,4 +22,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 { + return CurveSampler::SampleCurve(points, *this, ts); + } } \ No newline at end of file diff --git a/CurveTools/src/CPU/LinearGenerator.cpp b/CurveTools/src/CPU/LinearGenerator.cpp index ba14f8f..e3f9488 100644 --- a/CurveTools/src/CPU/LinearGenerator.cpp +++ b/CurveTools/src/CPU/LinearGenerator.cpp @@ -1,18 +1,19 @@ #include "CurveTools/CPU/LinearGenerator.hpp" +#include "CurveTools/CPU/CurveSampler.hpp" -namespace ct -{ - LinearGenerator::LinearGenerator() : - CurveGenerator(2) - { +namespace ct { + LinearGenerator::LinearGenerator() + : CurveGenerator(2) {} - } - - Point LinearGenerator::operator()(const Curve& points, double t) const - { - if (points.size() < m_degree) + Point LinearGenerator::generate(const Curve& points, double t) const { + if (points.size() < this->getDegree()) { return Point(0.0); + } return lerp(points[0], points[1], t); } + + 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 diff --git a/CurveTools/src/CPU/SmootherstepGenerator.cpp b/CurveTools/src/CPU/SmootherstepGenerator.cpp index b4460a9..70c7a3f 100644 --- a/CurveTools/src/CPU/SmootherstepGenerator.cpp +++ b/CurveTools/src/CPU/SmootherstepGenerator.cpp @@ -1,18 +1,19 @@ #include "CurveTools/CPU/SmootherstepGenerator.hpp" +#include "CurveTools/CPU/CurveSampler.hpp" -namespace ct -{ - SmootherstepGenerator::SmootherstepGenerator() : - CurveGenerator(2) - { +namespace ct { + SmootherstepGenerator::SmootherstepGenerator() + : CurveGenerator(2) {} - } - - Point SmootherstepGenerator::operator()(const Curve& points, double t) const - { - if (points.size() < m_degree) + Point SmootherstepGenerator::generate(const Curve& points, double t) const { + if (points.size() < this->getDegree()) { return Point(0.0); + } return smootherstep(points[0], points[1], t); } + + 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 diff --git a/CurveTools/src/CPU/SmoothstepGenerator.cpp b/CurveTools/src/CPU/SmoothstepGenerator.cpp index 06e483d..58d6026 100644 --- a/CurveTools/src/CPU/SmoothstepGenerator.cpp +++ b/CurveTools/src/CPU/SmoothstepGenerator.cpp @@ -1,18 +1,19 @@ #include "CurveTools/CPU/SmoothstepGenerator.hpp" +#include "CurveTools/CPU/CurveSampler.hpp" -namespace ct -{ - SmoothstepGenerator::SmoothstepGenerator() : - CurveGenerator(2) - { +namespace ct { + SmoothstepGenerator::SmoothstepGenerator() + : CurveGenerator(2) {} - } - - Point SmoothstepGenerator::operator()(const Curve& points, double t) const - { - if (points.size() < m_degree) + 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 { + return CurveSampler::SampleCurve(points, *this, ts); + } } \ No newline at end of file diff --git a/CurveTools/src/GPU/Core/BezierGenerator.cu b/CurveTools/src/GPU/Core/BezierGenerator.cu index 9c0d21d..615ce5f 100644 --- a/CurveTools/src/GPU/Core/BezierGenerator.cu +++ b/CurveTools/src/GPU/Core/BezierGenerator.cu @@ -8,7 +8,7 @@ #include <iostream> namespace ct::gpu { - __host__ Point BezierGenerator::operator()(const thrust::universal_vector<Point> & points, const float t) const { + __host__ Point BezierGenerator::generate(const thrust::universal_vector<Point> & points, const float t) const { size_t max_size = points.size(); thrust::device_vector<Point> dev_p(points); thrust::device_vector<Point> dev_r(max_size-1); @@ -21,7 +21,7 @@ namespace ct::gpu { return dev_r[0]; } - __host__ Curve BezierGenerator::operator()(const thrust::universal_vector<Point> & points, const std::vector<float> & ts, const cudaStream_t & stream) const { + __host__ Curve BezierGenerator::generate(const thrust::universal_vector<Point> & points, const std::vector<float> & ts, const cudaStream_t & stream) const { size_t ts_size = ts.size(); Curve result(ts_size); diff --git a/CurveTools/src/GPU/Core/CatmullRomGenerator.cu b/CurveTools/src/GPU/Core/CatmullRomGenerator.cu index 3d2c078..dbddfbd 100644 --- a/CurveTools/src/GPU/Core/CatmullRomGenerator.cu +++ b/CurveTools/src/GPU/Core/CatmullRomGenerator.cu @@ -8,7 +8,7 @@ #include <iostream> namespace ct::gpu { - __host__ Point CatmullRomGenerator::operator()(const thrust::universal_vector<Point> & points, const float t) const { + __host__ Point CatmullRomGenerator::generate(const thrust::universal_vector<Point> & points, const float t) const { if (points.size() < 4) { return Point(0.0); } @@ -24,7 +24,7 @@ namespace ct::gpu { return r; } - __host__ Curve CatmullRomGenerator::operator()(const thrust::universal_vector<Point> & points, const std::vector<float> & ts, const cudaStream_t & stream) const { + __host__ Curve CatmullRomGenerator::generate(const thrust::universal_vector<Point> & points, const std::vector<float> & ts, const cudaStream_t & stream) const { if (points.size() < 4) { return {}; } diff --git a/CurveTools/src/GPU/Core/HermiteGenerator.cu b/CurveTools/src/GPU/Core/HermiteGenerator.cu index ce11136..cea7504 100644 --- a/CurveTools/src/GPU/Core/HermiteGenerator.cu +++ b/CurveTools/src/GPU/Core/HermiteGenerator.cu @@ -8,7 +8,7 @@ #include <iostream> namespace ct::gpu { - __host__ Point HermiteGenerator::operator()(const thrust::universal_vector<Point> & points, const float t) const { + __host__ Point HermiteGenerator::generate(const thrust::universal_vector<Point> & points, const float t) const { if (points.size() < 4) { return Point(0.0); } @@ -24,7 +24,7 @@ namespace ct::gpu { return r; } - __host__ Curve HermiteGenerator::operator()(const thrust::universal_vector<Point> & points, const std::vector<float> & ts, const cudaStream_t & stream) const { + __host__ Curve HermiteGenerator::generate(const thrust::universal_vector<Point> & points, const std::vector<float> & ts, const cudaStream_t & stream) const { if (points.size() < 4) { return {}; } diff --git a/CurveTools/src/GPU/Core/Lineargenerator.cu b/CurveTools/src/GPU/Core/Lineargenerator.cu index 0cf84a9..2f1505c 100644 --- a/CurveTools/src/GPU/Core/Lineargenerator.cu +++ b/CurveTools/src/GPU/Core/Lineargenerator.cu @@ -9,7 +9,7 @@ namespace ct::gpu { LinearGenerator::LinearGenerator() : StreamedGenerator() {} - __host__ Point LinearGenerator::operator()(const thrust::universal_vector<Point> & ctrlPoint, const float t) const { + __host__ Point LinearGenerator::generate(const thrust::universal_vector<Point> & ctrlPoint, const float t) const { size_t max_size = ctrlPoint.size(); float range = 1.f/static_cast<float>(max_size); @@ -37,7 +37,7 @@ namespace ct::gpu { return r; } - __host__ Curve LinearGenerator::operator()(const thrust::universal_vector<Point> & ctrlPoint, const std::vector<float> & ts, const cudaStream_t & stream) const { + __host__ Curve LinearGenerator::generate(const thrust::universal_vector<Point> & ctrlPoint, const std::vector<float> & ts, const cudaStream_t & stream) const { size_t ts_size = ts.size(); Curve result(ts_size); diff --git a/CurveTools/src/GPU/Core/SmootherstepGenerator.cu b/CurveTools/src/GPU/Core/SmootherstepGenerator.cu index ddb57f3..bb3607d 100644 --- a/CurveTools/src/GPU/Core/SmootherstepGenerator.cu +++ b/CurveTools/src/GPU/Core/SmootherstepGenerator.cu @@ -10,7 +10,7 @@ namespace ct::gpu { SmootherstepGenerator::SmootherstepGenerator() : StreamedGenerator() {} - __host__ Point SmootherstepGenerator::operator()(const thrust::universal_vector<Point> & ctrlPoint, const float t) const { + __host__ Point SmootherstepGenerator::generate(const thrust::universal_vector<Point> & ctrlPoint, const float t) const { if (ctrlPoint.size() < 2) { return Point(0.0); } @@ -26,7 +26,7 @@ namespace ct::gpu { return r; } - __host__ Curve SmootherstepGenerator::operator()(const thrust::universal_vector<Point> & ctrlPoint, const std::vector<float> & ts, const cudaStream_t & stream) const { + __host__ Curve SmootherstepGenerator::generate(const thrust::universal_vector<Point> & ctrlPoint, const std::vector<float> & ts, const cudaStream_t & stream) const { if(ctrlPoint.size() < 2) { return {}; } diff --git a/CurveTools/src/GPU/Core/SmoothstepGenerator.cu b/CurveTools/src/GPU/Core/SmoothstepGenerator.cu index aeeeea0..29cb8c9 100644 --- a/CurveTools/src/GPU/Core/SmoothstepGenerator.cu +++ b/CurveTools/src/GPU/Core/SmoothstepGenerator.cu @@ -10,7 +10,7 @@ namespace ct::gpu { SmoothstepGenerator::SmoothstepGenerator() : StreamedGenerator() {} - __host__ Point SmoothstepGenerator::operator()(const thrust::universal_vector<Point> & ctrlPoint, const float t) const { + __host__ Point SmoothstepGenerator::generate(const thrust::universal_vector<Point> & ctrlPoint, const float t) const { if (ctrlPoint.size() < 2) { return Point(0.0); } @@ -26,7 +26,7 @@ namespace ct::gpu { return r; } - __host__ Curve SmoothstepGenerator::operator()(const thrust::universal_vector<Point> & ctrlPoint, const std::vector<float> & ts, const cudaStream_t & stream) const { + __host__ Curve SmoothstepGenerator::generate(const thrust::universal_vector<Point> & ctrlPoint, const std::vector<float> & ts, const cudaStream_t & stream) const { if(ctrlPoint.size() < 2) { return {}; } diff --git a/CurveTools/src/GPU/Core/SplineGenerator.cu b/CurveTools/src/GPU/Core/SplineGenerator.cu index 0ec90fc..17b6f5d 100644 --- a/CurveTools/src/GPU/Core/SplineGenerator.cu +++ b/CurveTools/src/GPU/Core/SplineGenerator.cu @@ -7,34 +7,34 @@ #include <iostream> namespace ct::gpu { - SplineGenerator::SplineGenerator(StreamedGenerator * generator, size_t cut, size_t streams) - : _streamsCount(streams), _cut(cut), _generator(generator) { - - } + SplineGenerator::SplineGenerator(StreamedGenerator * generator, size_t degree, size_t streams) + : Generator(degree), _streamsCount(streams), _generator(generator) {} - __host__ Point SplineGenerator::operator()(const thrust::universal_vector<Point> & points, float u) const { - thrust::universal_vector<Point> subPoints(this->_cut); + __host__ Point SplineGenerator::generate(const thrust::universal_vector<Point> & points, float u) const { + size_t degree = this->getDegree(); + thrust::universal_vector<Point> subPoints(degree); float e = 0; float f = std::modf(u, &e); - size_t start = static_cast<size_t>(e * this->_cut); + size_t start = static_cast<size_t>(e * degree); if(start != 0) { start--; } - if(e == (points.size()-1)/(this->_cut-1)) { - start -= this->_cut; + if(e == (points.size()-1)/(degree-1)) { + start -= degree; f = 1.0f; } - std::copy(points.begin() + start, points.begin() + start + this->_cut, subPoints.begin()); - return this->_generator->operator()(subPoints, f); + std::copy(points.begin() + start, points.begin() + start + degree, subPoints.begin()); + return this->_generator->generate(subPoints, f); } - __host__ Curve SplineGenerator::operator()(const thrust::universal_vector<Point> & points, const std::vector<float> & us) const { + __host__ Curve SplineGenerator::generate(const thrust::universal_vector<Point> & points, const std::vector<float> & us) const { Curve result(us.size()); + size_t degree = this->getDegree(); - size_t subCurveCount = static_cast<size_t>(std::ceil(points.size() / this->_cut)) + 1; + size_t subCurveCount = static_cast<size_t>(std::ceil(points.size() / degree)) + 1; std::vector<Curve> subCurves(subCurveCount); std::vector<cudaStream_t> streams; @@ -49,8 +49,8 @@ namespace ct::gpu { for(size_t i = 0; i < subCurveCount; i++) { size_t currentStream = i%subCurveCount; - thrust::universal_vector<Point> subPoints(this->_cut); - thrust::copy(points.begin()+currentPoint, points.begin()+currentPoint+this->_cut, subPoints.begin()); + thrust::universal_vector<Point> subPoints(degree); + thrust::copy(points.begin()+currentPoint, points.begin()+currentPoint+degree, subPoints.begin()); std::vector<float> ts; @@ -66,10 +66,10 @@ namespace ct::gpu { } } - Curve subResult = this->_generator->operator()(subPoints, ts, streams[currentStream]); + Curve subResult = this->_generator->generate(subPoints, ts, streams[currentStream]); memmove(&result[usCount == 0 ? 0 : usCount-1], subResult.data(), sizeof(Point) * subResult.size()); - currentPoint += this->_cut-1; + currentPoint += degree-1; } for(auto & stream : streams) { diff --git a/ParticleGenerator/src/Mesh/Trajectory.cpp b/ParticleGenerator/src/Mesh/Trajectory.cpp index 3d0845e..edcd892 100644 --- a/ParticleGenerator/src/Mesh/Trajectory.cpp +++ b/ParticleGenerator/src/Mesh/Trajectory.cpp @@ -40,7 +40,7 @@ namespace pg { ps.push_back(i); } - ct::Curve curve = ct::CurveSampler::sampleCurve(this->_generator->getControlPoint(), *this->_generator->getGenerator(), ps); + ct::Curve curve = ct::CurveSampler::SampleCurve(this->_generator->getControlPoint(), *this->_generator->getGenerator(), ps); for(auto & point : curve) { traj.push_back(static_cast<float>(point.x)); @@ -64,7 +64,7 @@ namespace pg { this->_program.setUniform("uView", camera.getViewMatrix()); GLsizei raw = static_cast<GLsizei>(this->_generator->getControlPoint().size()); - GLsizei total = this->_vbo.vertices(); + GLsizei total = static_cast<GLsizei>(this->_vbo.vertices()); glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(this->_generator->getControlPoint().size())); glDrawArrays(GL_LINE_STRIP, raw, total - raw); -- GitLab