diff --git a/CurveTools/src/GPU/Core/Lineargenerator.cu b/CurveTools/src/GPU/Core/Lineargenerator.cu index 2f1505c8a35050d1874e9c2a71fa7bb7ebb8c13a..ca798138e682e5048f2bd1a1977dfe1c994fe9a5 100644 --- a/CurveTools/src/GPU/Core/Lineargenerator.cu +++ b/CurveTools/src/GPU/Core/Lineargenerator.cu @@ -10,21 +10,32 @@ namespace ct::gpu { : StreamedGenerator() {} __host__ Point LinearGenerator::generate(const thrust::universal_vector<Point> & ctrlPoint, const float t) const { + if(ctrlPoint.empty()) { + return Point(0.0); + } size_t max_size = ctrlPoint.size(); + if(max_size == 1) { + return Point(ctrlPoint[0].x, ctrlPoint[0].y, ctrlPoint[0].z); + } + float range = 1.f/static_cast<float>(max_size); size_t current = 0; - for(float i = 0.f; i <= t; i += range) { + for(float i = 0.f; i < t; i += range) { ++current; } - if(current == max_size) { - --current; + if(current == 0) { + ++current; } - Point p1 = ctrlPoint[current]; - Point p2 = ctrlPoint[current+1]; + if(current >= max_size) { + current = max_size-1; + } + + Point p1 = ctrlPoint[current-1]; + Point p2 = ctrlPoint[current]; Point r, * d_r; cudaMalloc(&d_r, sizeof(Point));