FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
PointDistributionTensor.hpp
1#ifndef __FIBER_BASEOP_POINTDISTRIBUTIONTENSOR_HPP
2#define __FIBER_BASEOP_POINTDISTRIBUTIONTENSOR_HPP
3
4#include "PointCloudIpol.hpp"
5//#include "elementary/eagle/QuadraticMatrix.hpp"
6#include "elementary/eagle/EigenVectors.hpp"
7
8namespace Fiber
9{
10
11namespace PointCloud
12{
13
14
17template<int N>
18inline Eagle::PhysicalSpace::tvector getWeightedVec(const Eagle::PhysicalSpace::tvector& vec, double radius )
19{
20 return vec;
21}
22
23template<>
24inline Eagle::PhysicalSpace::tvector getWeightedVec<LINEAR>(const Eagle::PhysicalSpace::tvector& vec, double radius )
25{
26const double len = norm(vec);
27 return vec * (1 - len/radius );
28}
29template<>
30inline Eagle::PhysicalSpace::tvector getWeightedVec<SQUARE>(const Eagle::PhysicalSpace::tvector& vec, double radius )
31{
32const double len = norm(vec);
33 if(len > 0.0)
34 return vec/(len*len);
35
36 return Eagle::PhysicalSpace::tvector(0,0,0);
37}
38template<>
39inline Eagle::PhysicalSpace::tvector getWeightedVec<SSQUARE>(const Eagle::PhysicalSpace::tvector& vec, double radius )
40{
41const double len = norm(vec);
42 if(len > 0.0)
43 return vec/(len*len);
44
45 return Eagle::PhysicalSpace::tvector(0,0,0);
46}
47template<>
48inline Eagle::PhysicalSpace::tvector getWeightedVec<SPHCUBIC>(const Eagle::PhysicalSpace::tvector& vec, double radius )
49{
50const double len = norm(vec);
51 return vec * PointCloud::sph_cubic( len / radius * 2.0 );
52}
53template<>
54inline Eagle::PhysicalSpace::tvector getWeightedVec<SPHQUARTIC>(const Eagle::PhysicalSpace::tvector& vec, double radius )
55{
56const double len = norm(vec);
57 return vec * PointCloud::sph_quartic( len / radius * 2.5 );
58}
59template<>
60inline Eagle::PhysicalSpace::tvector getWeightedVec<SPHQUINTIC>(const Eagle::PhysicalSpace::tvector& vec, double radius )
61{
62const double len = norm(vec);
63 return vec * PointCloud::sph_quintic( len / radius * 3.0 );
64}
65
66
67
68
69
70
84template<int N,class C>
85Eagle::metric33 computePointDistributionTensor( const std::multimap<double, index_t>& verts,
86 const C& crds,
87 const MultiIndex<1>& mi,
88 const size_t& size,
89 const double& radius )
90{
91size_t j = 0;
92Eagle::metric33 tmp;
93 tmp(0,0) = 0;
94 tmp(1,0) = 0;
95 tmp(2,0) = 0;
96 tmp(1,1) = 0;
97 tmp(2,2) = 0;
98 tmp(1,2) = 0;
99index_t ind = mi[0];
100
101 for (std::multimap<double, index_t>::const_iterator it = verts.begin(); it != verts.end(); it++)
102 {
103 if( std::fabs((*it).first < 1.0e-4) ) continue;
104 if( j == size ) break;
105
106 Eagle::PhysicalSpace::tvector vec = crds[ (*it).second ] - crds[ind];
107
108 vec = getWeightedVec<N>(vec, radius);
109
110 tmp += dyadic(vec, vec);
111
112 j++;
113 }
114
115 if (j > 0)
116 tmp *= 1.0 / double(j);
117
118 return tmp;
119}
120
121template<int N,class C>
122Eagle::metric33 computePointDistributionTensor(const C& crds,
123 const MultiIndex<1>& mi,
124 const unsigned& size,
125 const double& radius)
126{
127Eagle::metric33 tmp;
128 tmp(0,0) = 0;
129 tmp(1,0) = 0;
130 tmp(2,0) = 0;
131 tmp(1,1) = 0;
132 tmp(2,2) = 0;
133 tmp(1,2) = 0;
134
135 for (unsigned i = 0; i < size; i++)
136 {
137 Eagle::PhysicalSpace::tvector vec = crds[ i ] - crds[ mi[0] ];
138
139 if(std::fabs(vec[0]) < 1e-4 && std::fabs(vec[1]) < 1e-4 && std::fabs(vec[2]) < 1e-4)
140 continue;
141
142 vec = getWeightedVec<N>(vec, radius);
143
144 tmp += dyadic(vec, vec);
145 }
146
147 tmp *= 1.0 / double(size);
148
149 return tmp;
150}
151
153template<int N,class C>
154Eagle::metric33 computePointDistributionTensor(const C& crds,
156 const unsigned& size,
157 const double& radius)
158{
159Eagle::metric33 tmp;
160 tmp(0,0) = 0;
161 tmp(1,0) = 0;
162 tmp(2,0) = 0;
163 tmp(1,1) = 0;
164 tmp(2,2) = 0;
165 tmp(1,2) = 0;
166
167 for (unsigned i = 0; i < size; i++)
168 {
169 Eagle::PhysicalSpace::tvector vec = crds[ i ] - p;
170
171 if(std::fabs(vec[0]) < 1e-4 && std::fabs(vec[1]) < 1e-4 && std::fabs(vec[2]) < 1e-4)
172 continue;
173
174 vec = getWeightedVec<N>(vec, radius);
175
176 tmp += dyadic(vec, vec);
177 }
178
179 tmp *= 1.0 / double(size);
180
181 return tmp;
182}
183template <int N, class value>
184double getPlanarity(Eagle::Row<N,value>& Evalues )
185{
186double denominator = Evalues[0]+Evalues[1]+Evalues[2];
187
188 if (std::fabs(denominator) < 1.0e-6)
189 return 0.0;
190 else
191 return 2*(Evalues[1] - Evalues[0]) / denominator;
192}
193
194template <int N, class value>
195double getLinearity(Eagle::Row<N,value>& Evalues )
196{
197double denominator = Evalues[0]+Evalues[1]+Evalues[2];
198
199 if (std::fabs(denominator) < 1.0e-6)
200 return 0.0;
201 else
202 return (Evalues[2] - Evalues[1]) / denominator;
203}
204
205template <int N, class value>
206double getSphericity(Eagle::Row<N,value>& Evalues )
207{
208double denominator = Evalues[0]+Evalues[1]+Evalues[2];
209
210 if (std::fabs(denominator) < 1.0e-6)
211 return 0.0;
212 else
213 return 3*(Evalues[0]) / denominator;
214}
215
217
218double computePlanarity(const std::vector<Eagle::PhysicalSpace::point>& v,
220 const double& radius);
221
223
224double computeLinearity(const std::vector<Eagle::PhysicalSpace::point>& v,
226 const double& radius);
227
229
230double computeSphericity(const std::vector<Eagle::PhysicalSpace::point>& v,
232 const double& radius);
233
234} //PointCloud
235} //Fiber
236
237#endif
valarray< size_t > size() const
_Tp fabs(const std::complex< _Tp > &__z)
const_iterator end() const noexcept
const_iterator begin() const noexcept
Metric dyadic(const vector &a, const vector &b)
double norm(const PhysicalSpace::bivector &v)
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2