-
Notifications
You must be signed in to change notification settings - Fork 2
/
utility.h
109 lines (83 loc) · 3.05 KB
/
utility.h
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
#ifndef UTILITY_H
#define UTILITY_H
#include<iostream>
#include<list>
#include<random>
#include<vector>
#include <igl/opengl/glfw/Viewer.h>
#include <igl/cotmatrix.h>
#include <igl/massmatrix.h>
#include <igl/invert_diag.h>
#include <igl/gaussian_curvature.h>
#include <igl/jet.h>
#include <igl/parula.h>
#include <igl/principal_curvature.h>
#include "NURBSSurface.h"
namespace t_mesh{
template<class T,int num>
struct Array;
template<class T>
class Node;
template<class T>
class Mesh;
typedef Array<float,3> Point3f;
typedef Array<double,3> Point3d;
typedef Array<int,2> Parameter;
typedef Mesh<Point3d> Mesh3d;
typedef Mesh<Point3d> Mesh3f;
const Eigen::RowVector3d red(1, 0, 0);
const Eigen::RowVector3d green(0, 1, 0);
const Eigen::RowVector3d blue(0, 0, 1);
const Eigen::RowVector3d yellow(1, 1, 0);
const Eigen::RowVector3d white(1, 1, 1);
const Eigen::RowVector3d black(0, 0, 0);
const Eigen::RowVector3d deeppink(255, 20, 147);
// Blending function N[s0,s1,s2,s3,s4](p)
template<class T>
double B(const T& s,double p);
template<class T, int num>
void array2matrixd(const Array<T, num> &a, Eigen::MatrixXd &m);
int FindSpan(const Eigen::MatrixXd &knots, double t, int p = 3);
// Blending function N[s0,s1,s2,s3,s4](p)
double Basis1(const Eigen::MatrixXd &knotvector, double t, int i = 0, int p = 4);
double Basis(const Eigen::MatrixXd &knots, double t, int i = 0, int p = 3);
// Berivative of Blending function N[s0,s1,s2,s3,s4](t)
Eigen::RowVectorXd DersBasis(const Eigen::MatrixXd &knots, double t, int i = 0, int p = 3);
bool loadpoints(std::string name, Eigen::MatrixXd &mat);
bool savepoints(std::string name, const Eigen::MatrixXd &mat);
void vec_insert(Eigen::VectorXd &vec, double t);
void TsplineSimplify(const NURBSSurface& surface, Mesh3d& tspline, int maxIterNum = 20, double eps = 1e-5);
};
namespace t_mesh{
template<class T>
double B(const T& s,double p){
if(p<=s[0])
return 0.0;
if(p<=s[1])
return 1.0*(p-s[0])*(p-s[0])*(p-s[0])/(s[1]-s[0])/(s[2]-s[0])/(s[3]-s[0]);
else if(p<=s[2])
return 1.0*(p-s[0])*(p-s[0])*(s[2]-p)/(s[2]-s[1])/(s[2]-s[0])/(s[3]-s[0])+
1.0*(p-s[0])*(p-s[1])*(s[3]-p)/(s[2]-s[1])/(s[3]-s[0])/(s[3]-s[1])+
1.0*(p-s[1])*(p-s[1])*(s[4]-p)/(s[2]-s[1])/(s[4]-s[1])/(s[3]-s[1])
;
else if(p<=s[3])
return 1.0*(p-s[0])*(s[3]-p)*(s[3]-p)/(s[3]-s[2])/(s[3]-s[1])/(s[3]-s[0])+
1.0*(p-s[1])*(s[4]-p)*(s[3]-p)/(s[3]-s[2])/(s[4]-s[1])/(s[3]-s[1])+
1.0*(p-s[2])*(s[4]-p)*(s[4]-p)/(s[3]-s[2])/(s[4]-s[2])/(s[4]-s[1])
;
else if(p<s[4])
return 1.0*(s[4]-p)*(s[4]-p)*(s[4]-p)/(s[4]-s[3])/(s[4]-s[2])/(s[4]-s[1]);
return 0.0;
}
template<class T, int num>
void array2matrixd(const Array<T, num> &a, Eigen::MatrixXd &m) {
m.resize(1, num);
for (int i = 0; i < num; i++) {
m(0, i) = 1.0*a[i];
}
}
};
#include"array.hpp"
#include"node.hpp"
#include"mesh.hpp"
#endif