Loading...
Searching...
No Matches
knots.C
Go to the documentation of this file.
1/*
2 * This file is part of the SPLINTER library.
3 * Copyright (C) 2012 Bjarne Grimstad (bjarne.grimstad@gmail.com).
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8*/
9
10#include <knots.h>
11#include <algorithm>
12
13namespace SPLINTER
14{
15
16bool isKnotVectorRegular(const std::vector<double>& knots, unsigned int degree)
17{
18 // Check size
19 if (knots.size() < 2 * (degree + 1))
20 {
21 return false;
22 }
23
24 // Check order
25 if (!std::is_sorted(knots.begin(), knots.end()))
26 {
27 return false;
28 }
29
30 // Check multiplicity of knots
31 for (std::vector<double>::const_iterator it = knots.begin(); it != knots.end();
32 ++it)
33 {
34 if (count(knots.begin(), knots.end(), *it) > degree + 1)
35 {
36 return false;
37 }
38 }
39
40 return true;
41}
42
43bool isKnotVectorClamped(const std::vector<double>& knots, unsigned int degree)
44{
45 // Check multiplicity of first knot
46 if (std::count(knots.begin(), knots.begin() + degree + 1,
47 knots.front()) != degree + 1)
48 {
49 return false;
50 }
51
52 // Check multiplicity of last knot
53 if (std::count(knots.end() - degree - 1, knots.end(),
54 knots.back()) != degree + 1)
55 {
56 return false;
57 }
58
59 return true;
60}
61
62bool isKnotVectorRefinement(const std::vector<double>& knots,
63 const std::vector<double>& refinedKnots)
64{
65 // Check size
66 if (refinedKnots.size() < knots.size())
67 {
68 return false;
69 }
70
71 // Check that each element in knots occurs at least as many times in refinedKnots
72 for (std::vector<double>::const_iterator it = knots.begin() ; it != knots.end();
73 ++it)
74 {
75 int m_tau = count(knots.begin(), knots.end(), *it);
76 int m_t = count(refinedKnots.begin(), refinedKnots.end(), *it);
77
78 if (m_t < m_tau)
79 {
80 return false;
81 }
82 }
83
84 // Check that range is not changed
85 if (knots.front() != refinedKnots.front())
86 {
87 return false;
88 }
89
90 if (knots.back() != refinedKnots.back())
91 {
92 return false;
93 }
94
95 return true;
96}
97
98} // namespace SPLINTER
bool isKnotVectorRegular(const std::vector< double > &knots, unsigned int degree)
Definition knots.C:16
bool isKnotVectorRefinement(const std::vector< double > &knots, const std::vector< double > &refinedKnots)
Definition knots.C:62
bool isKnotVectorClamped(const std::vector< double > &knots, unsigned int degree)
Definition knots.C:43