diff --git a/CurveTools/CMakeLists.txt b/CurveTools/CMakeLists.txt index bb573dc4e6984de76735e9b3ff3f74dff253cb23..035b3c406b65fb07dc0914e8170ec4449125154b 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 220b6c56016488d5801857b2c52231d159d1e9a9..50e66aa6bb37a48b2ee3a0a9f1ee4f65240c9741 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 2887b259a54c09df7007d210a86455846142a505..fc7b4b70f678f7f142aaa0313f4805694c683291 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 0b1f9d5d57be8e0bc71c09a4d22685d34b7c5c1b..4060a2fc67f0ddcbdccbf72616416e6cec040876 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 04b00ca2622d08f5bb7eb6c8714f72e927a9b525..43c42f598d56e6d9f7c3ef579866be383849223a 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 b92fbfccb727f1d21e5e6cb3c442c4f9665de7a4..c916e1e8268f73f13b5026df0725405744eef73e 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 b7f996a8a348a8fa5b77d1bb82b05a8336f78d0d..6c4893e91d2ebd64f3ceaab75ad512c32738a25e 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 0be6c2abc3b64f1e4deafecd91ba33f8876db26c..a89e626e8514bd76d7a0b5066d8f96eb29faf2f0 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 48390bef9719876bb1b123f738a0c1019865c62b..07bdf7abfc2218f54d72a79a91ea58f81be8d304 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 25ede8581a64e233f49b7afd500cf02a74d93fee..12dfa7c36289fcce2cc89395af1236cf941031b8 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 20c7e57e6815e85d500aaa8e06168a1e189fd557..bf8455d83d2ce9d97b7f5bb27d45c15b148379f0 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 96e7e0070933798d632ab173deb6734507fe5c20..153325da0e374079bd990343db7141ca4fb6b2db 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 4a89d65539369e1fa955b3db269d293d612abee9..0000000000000000000000000000000000000000 --- 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 2ab2be04c2d2cf489e1b2e931324d7d95bfe0605..e826bbffb48e25c7889b181b8a4d781c9d4e5366 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 7c8f300e456d10414ad02c49707bb24d7c4cbbbb..5ba9dfa7c7531b6885ad3a54cae164db0ad43486 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 141db9830b1fb3256d546956fd63e290be86aaaf..4a7e33d7e8a24ef261a98f88fdaf3b174d465806 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 1868fe4ab0fc5ced4c209be14dfd44a495aadd8d..3751d5358c6df2161e9ab6040dd6c185ce2fd3e3 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 238a7e470614a45965420336591a61929e12273b..40a12958cf2092b6a679628eb3ced3167ff0391f 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 72e3c420d03818506b68595bb6fcf9dfd7999cce..2a4c580d2ea39c392557d25f6c844111367c211b 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 0000000000000000000000000000000000000000..ae8b671d63a0a4f643c5258eac0e09065703fdb2 --- /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 1906acdd904e1dba61fc3f7c842ac37a06575d17..ecfa90197e0b6f919788b96d4d0821dfa8716a32 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 ae307fa7d64b34133750ff808aa66de7ce64006f..c2b2c1e36a71059a81a31d64a174836f1ce63c9c 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 5f9025ec195c5a477d77c48e5fe195dd500553a5..ca35e77571f7ab205eaaca4d5352a5615d5bc0b4 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 8736206d89c776aa72875c8731879336dbb83656..86a0505788786ad06fd6566227cc8521fca263e5 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 913d7fb9620e53a7dc521203c8e4f88b7ab84b2d..37809a6bbe2d4e15efee20c22dd9a7211612aa50 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 5def6d1f1c73b7b3b08e91896e46d65671844324..c006e281707e918f9798a5ef9032428410fd66f7 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 ba14f8fe8fbef8931a0c9000fdaffbcf1a73c664..e3f9488e4b692893ad423a1b8309174b8d650367 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 b4460a9117c2c5ccc0c0467a3fbf41356a88f54c..70c7a3ffb7d072d8b410fbdd3cd44a1e139fd891 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 06e483d1c86c13438b0835ca7c368a3ae7007db0..58d6026fc896e2430c044f57fc0a9d452850ef66 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 9c0d21d4063844d598ec8f6634857c3cc03396c6..615ce5f2aa26fe2f8ace8429dae34cbc6cc9a668 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 3d2c078534c65febf46bcf303315198d8b674267..dbddfbd816af3184056338c959400c0bd38d83d3 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 ce11136d2eb131f8e993d2a37532b838d5dfb668..cea7504d450f675b67cfcd1e8b04da160fc984a0 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 0cf84a9994947118e7f46612307723691c96a8a4..2f1505c8a35050d1874e9c2a71fa7bb7ebb8c13a 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 ddb57f38be95c63e865a5e54c910a3de4f9f294a..bb3607da35b559d04ee2eb019a8c3e5190fe46bc 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 aeeeea035b9f6ef795b915fd1a01320a49ccfc84..29cb8c996c2eebaafa80a89a528debe4be11a7c2 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 0ec90fc2d6f835f60bd0b3f7001bca75d6fbef7a..17b6f5d8ec068db60e56c015e6d9b24cf72e9d74 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 3d0845e5574661945642a2d5e75da1988a7ed349..edcd8927e273f5cce4fbe95ab0e7e21fc5a8d57e 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);