Welcome to mirror list, hosted at ThFree Co, Russian Federation.

spline_poly.cc « intern « blenkernel « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aa9935cb055f7241a4870293f1051b49244af4f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * 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 2
 * 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, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "BLI_array.hh"
#include "BLI_listbase.h"
#include "BLI_span.hh"

#include "BKE_curve.h"
#include "BKE_spline.hh"

using blender::Array;
using blender::float3;
using blender::float4x4;
using blender::IndexRange;
using blender::MutableSpan;
using blender::Span;
using blender::Vector;

SplinePtr PolySpline::copy() const
{
  SplinePtr new_spline = std::make_unique<PolySpline>(*this);

  return new_spline;
}

int PolySpline::size() const
{
  const int size = this->positions_.size();
  BLI_assert(this->radii_.size() == size);
  BLI_assert(this->tilts_.size() == size);
  return size;
}

int PolySpline::resolution() const
{
  return 1;
}

void PolySpline::set_resolution(const int UNUSED(value))
{
  /* Poly curve has no resolution, there is just one evaluated point per control point. */
}

void PolySpline::add_point(const float3 position, const float radius, const float tilt)
{
  this->positions_.append(position);
  this->radii_.append(radius);
  this->tilts_.append(tilt);
}

void PolySpline::drop_front(const int count)
{
  BLI_assert(this->size() - count > 0);
  this->positions_.remove(0, count);
  this->radii_.remove(0, count);
  this->tilts_.remove(0, count);
  this->mark_cache_invalid();
}

void PolySpline::drop_back(const int count)
{
  const int new_size = this->size() - count;
  BLI_assert(new_size > 0);
  this->positions_.resize(new_size);
  this->radii_.resize(new_size);
  this->tilts_.resize(new_size);
  this->mark_cache_invalid();
}

MutableSpan<float3> PolySpline::positions()
{
  return this->positions_;
}
Span<float3> PolySpline::positions() const
{
  return this->positions_;
}
MutableSpan<float> PolySpline::radii()
{
  return this->radii_;
}
Span<float> PolySpline::radii() const
{
  return this->radii_;
}
MutableSpan<float> PolySpline::tilts()
{
  return this->tilts_;
}
Span<float> PolySpline::tilts() const
{
  return this->tilts_;
}

int PolySpline::evaluated_points_size() const
{
  return this->size();
}

void PolySpline::correct_end_tangents() const
{
}

/* TODO: Consider refactoring to avoid copying and "mapping" for poly splines. */
void PolySpline::ensure_base_cache() const
{
  if (!this->base_cache_dirty_) {
    return;
  }

  std::lock_guard lock{this->base_cache_mutex_};
  if (!this->base_cache_dirty_) {
    return;
  }

  const int total = this->evaluated_points_size();
  this->evaluated_positions_cache_.resize(total);
  this->evaluated_mapping_cache_.resize(total);

  MutableSpan<float3> positions = this->evaluated_positions_cache_.as_mutable_span();
  MutableSpan<PointMapping> mappings = this->evaluated_mapping_cache_.as_mutable_span();

  for (const int i : positions.index_range()) {
    positions[i] = this->positions_[i];
    mappings[i].control_point_index = i;
    mappings[i].factor = 0.0f;
  }

  this->base_cache_dirty_ = false;
}