3 #ifndef __solve_Splat_h__ 4 #define __solve_Splat_h__ 11 inline void zero(t_solve_real &a_value)
16 inline void zero(t_solve_v2 &a_value)
18 a_value = t_solve_v2(0.0, 0.0);
21 inline void zero(t_solve_v3 &a_value)
23 a_value = t_solve_v3(0.0, 0.0, 0.0);
27 template<
typename T,
unsigned int D>
32 typedef t_solve_real t_span[D];
40 for(
unsigned int d = 0; d < D; d++)
45 std::vector<T> m_gradient;
55 typedef t_pivot_e t_pivot[D];
56 typedef c_gradient t_gradient;
57 typedef std::vector<t_gradient> t_gradients;
58 typedef std::vector<T> t_cells;
59 typedef std::vector<t_solve_real> t_mass;
66 void setAll(t_span &a_span, t_solve_real a_value)
68 for(
unsigned int d = 0; d < D; d++)
84 void splat(
const t_solve_real &a_mass,
const typename Splat<T,D>::t_span &a_location,
const T &a_value);
85 void unitSplat(
const t_solve_real &a_mass,
const typename Splat<T,D>::t_span &a_location,
const T &a_value);
86 void massSplat(
const t_solve_real &a_mass,
const t_index &a_index,
const T &a_value);
87 void gradientSplat(
const t_solve_real &a_mass,
const t_index &a_index,
const T &a_value,
const t_span &a_direction);
90 void create(
const t_index &a_count,
93 const T &
get(
const t_index &a_index)
const;
94 const T &direct(
const t_index &a_index)
const;
95 const t_solve_real &getMass(
const t_index &a_index)
const;
96 void set(
const t_index &a_index,
const T &a_value);
97 void setMass(
const t_index &a_index,
const t_solve_real &a_value);
99 void spanize(t_span &a_span,
const t_index &a_index);
100 t_solve_real magnitude(
const t_span &a_span);
102 void blur(t_solve_real a_factor);
107 void fillSolve(
unsigned int a_aspect);
113 void setSpace(
const t_span &a_lo,
const t_span &a_hi);
117 virtual ~Functor(
void) {}
118 virtual void process(
Splat<T,D> &a_splat, t_index &a_index)
122 void iterate(Functor &a_functor);
124 void dump(
const char *a_filename);
125 void dbsave(
const char *a_filename);
126 void dbload(
const char *a_filename);
127 void location( t_span &a_location,
128 const t_index &a_index)
const;
132 unsigned int m_totalCount;
139 t_gradients m_gradients;
140 t_mass m_gradient_mass;
142 void aspectFillSolve(
unsigned int a_aspect);
143 unsigned int calc_array_index(
const t_index &a_index)
const;
144 bool safe( t_index &a_index)
const;
145 t_span &safe( t_span &a_span)
const;
146 bool safe(
unsigned int a_d,
147 t_index &a_index)
const;
148 void unit( t_span &a_unit_location,
const t_span &a_location);
149 void pivot( t_pivot &a_pivot,
151 const t_span &a_location)
const;
152 const t_span &cellsize(
void)
const {
return m_size; }
154 const t_index &count(
void)
const {
return m_count; }
156 T &access(
const t_index &a_index);
158 void rIterate(
unsigned int a_d, t_index &a_index, Functor &a_functor);
160 unsigned int totalCount(
void)
const {
return m_totalCount; }
161 void index( t_index &a_index,
162 const t_span &a_location)
const;
165 template<
typename T,
unsigned int D>
171 unit(unit_location, a_location);
175 pivot(i_pivot, i_lower, unit_location);
177 for(
unsigned int i = 0; i < D; i++)
179 if(i_pivot[i] == e_pivot_within)
181 bnd[i].m_lo = unit_location[i]/cellsize()[i] - (Real)i_lower[i];
182 bnd[i].m_hi = 1.0 - bnd[i].m_lo;
184 else if(i_pivot[i] == e_pivot_over)
190 else if(i_pivot[i] == e_pivot_under)
201 rSplat(D-1, index, i_lower, r, bnd, a_mass, a_value);
204 template<
typename T,
unsigned int D>
211 pivot(i_pivot, i_lower, a_location);
213 for(
unsigned int i = 0; i < D; i++)
215 if(i_pivot[i] == e_pivot_within)
217 bnd[i].m_lo = a_location[i]/cellsize()[i] - (Real)i_lower[i];
218 bnd[i].m_hi = 1.0 - bnd[i].m_lo;
220 else if(i_pivot[i] == e_pivot_over)
225 else if(i_pivot[i] == e_pivot_under)
235 rSplat(D-1, index, i_lower, r, bnd, a_mass, a_value);
238 template<
typename T,
unsigned int D>
241 if(a_mass < 1.0e-12) {
return; }
244 unsigned int i = calc_array_index(safe_index);
245 t_solve_real sum = a_mass + m_mass[i];
246 m_cells[i] = (m_mass[i] / sum) * m_cells[i] + (a_mass / sum) * a_value;
250 template<
typename T,
unsigned int D>
253 for(
unsigned int i = 0; i < D; i++)
255 a_location[i] = m_root[i] + (Real)a_index[i] * cellsize()[i] / m_scale[i];
259 template<
typename T,
unsigned int D>
262 if(a_mass < 1.0e-12) {
return; }
266 unsigned int i_cell = calc_array_index(safe_index);
267 t_gradient &gradient = m_gradients[i_cell];
269 t_solve_real sum = a_mass + m_gradient_mass[i_cell];
270 t_solve_real sum_ratio = a_mass / sum;
271 t_solve_real sum_m_ratio = m_gradient_mass[i_cell] / sum;
272 m_gradient_mass[i_cell] += a_mass;
274 for(
unsigned int d = 0; d < D; d++)
276 gradient.m_gradient[d] = sum_m_ratio * gradient.m_gradient[d] + sum_ratio * (a_value * a_unit_dir[d]);
280 template<
typename T,
unsigned int D>
283 for(
unsigned int d = 0; d < D; d++)
286 m_scale[d] = 1.0 / (a_hi[d] - a_lo[d]);
291 template<
typename T,
unsigned int D>
294 for(
unsigned int i = 0; i < D; i++)
296 a_unit_location[i] = (a_location[i] - m_root[i]) * m_scale[i];
300 template<
typename T,
unsigned int D>
303 return m_cells[calc_array_index(a_index)];
306 template<
typename T,
unsigned int D>
309 for(
unsigned int i = 0; i < D; i++)
311 a_index[i] = (int)(a_location[i] / m_size[i]);
315 template<
typename T,
unsigned int D>
318 for(
unsigned int i = 0; i < D; i++)
320 a_index[i] = (int)((a_location[i]) / m_size[i]);
322 if((
int)a_index[i] < 0)
324 a_pivot[i] = e_pivot_under;
327 else if((
int)a_index[i] >= (int)(m_count[i])-1)
329 a_pivot[i] = e_pivot_over;
330 a_index[i] = m_count[i]-1;
334 a_pivot[i] = e_pivot_within;
339 template<
typename T,
unsigned int D>
342 for(
unsigned int i = 0; i < D; i++)
344 a_span[i] = (Real)a_index[i] * cellsize()[i];
348 template<
typename T,
unsigned int D>
351 t_solve_real m = 0.0;
352 for(
unsigned int d = 0; d < D; d++)
354 m += a_span[d]*a_span[d];
359 template<
typename T,
unsigned int D>
363 a_index[a_d] = a_lower[a_d];
365 m = a_bnd[a_d].m_hi * a_mult;
370 massSplat(m * a_mass, a_index, a_value);
374 rSplat(a_d-1, a_index, a_lower, m, a_bnd, a_mass, a_value);
378 a_index[a_d] = a_lower[a_d] + 1;
380 m = a_bnd[a_d].m_lo * a_mult;
385 massSplat(m * a_mass, a_index, a_value);
389 rSplat(a_d-1, a_index, a_lower, m, a_bnd, a_mass, a_value);
394 inline t_solve_real &value(t_solve_real &a_value,
unsigned int a_aspect)
399 inline t_solve_real &value(
t_solve_v2 &a_value,
unsigned int a_aspect)
401 return a_value[a_aspect];
404 inline t_solve_real &value(
t_solve_v3 &a_value,
unsigned int a_aspect)
406 return a_value[a_aspect];
409 template<
typename T,
unsigned int D>
417 a_index[a_d] = a_lower[a_d];
419 m = a_bnd[a_d].m_hi * a_mult;
424 accum += m * direct(a_index);
428 accum += rLinearSample(a_d-1, a_index, a_lower, a_pivot, m, a_bnd);
433 a_index[a_d] = a_lower[a_d] + 1;
435 m = a_bnd[a_d].m_lo * a_mult;
441 accum += m * direct(a_index);
445 accum += rLinearSample(a_d-1, a_index, a_lower, a_pivot, m, a_bnd);
454 template<
typename T,
unsigned int D>
460 unit(unit_location, a_location);
464 pivot(i_pivot, i_lower, unit_location);
466 for(
unsigned int i = 0; i < D; i++)
468 if(i_pivot[i] == e_pivot_within)
470 bnd[i].m_lo = unit_location[i]/cellsize()[i] - (Real)i_lower[i];
471 bnd[i].m_hi = 1.0 - bnd[i].m_lo;
473 else if(i_pivot[i] == e_pivot_over)
479 else if(i_pivot[i] == e_pivot_under)
488 return rLinearSample(D-1, index, i_lower, i_pivot, r, bnd);
495 a_splat.unit(unit_location, a_location);
499 a_splat.pivot(i_pivot, i_lower, unit_location);
501 for(
unsigned int i = 0; i < 3; i++)
505 bnd[i].m_lo = unit_location[i]/a_splat.cellsize()[i] - (Real)i_lower[i];
506 bnd[i].m_hi = 1.0 - bnd[i].m_lo;
523 i_sample[0]=i_lower[0];i_sample[1]=i_lower[1];i_sample[2]=i_lower[2];
524 accum += a_splat.direct(i_sample) * bnd[0].m_hi * bnd[1].m_hi * bnd[2].m_hi;
526 i_sample[0]=i_lower[0];i_sample[1]=i_lower[1];i_sample[2]=i_lower[2]+1;
527 accum += a_splat.direct(i_sample) * bnd[0].m_hi * bnd[1].m_hi * bnd[2].m_lo;
529 i_sample[0]=i_lower[0];i_sample[1]=i_lower[1]+1;i_sample[2]=i_lower[2]+1;
530 accum += a_splat.direct(i_sample) * bnd[0].m_hi * bnd[1].m_lo * bnd[2].m_lo;
532 i_sample[0]=i_lower[0]+1;i_sample[1]=i_lower[1]+1;i_sample[2]=i_lower[2]+1;
533 accum += a_splat.direct(i_sample) * bnd[0].m_lo * bnd[1].m_lo * bnd[2].m_lo;
535 i_sample[0]=i_lower[0]+1;i_sample[1]=i_lower[1]+1;i_sample[2]=i_lower[2];
536 accum += a_splat.direct(i_sample) * bnd[0].m_lo * bnd[1].m_lo * bnd[2].m_hi;
538 i_sample[0]=i_lower[0]+1;i_sample[1]=i_lower[1];i_sample[2]=i_lower[2];
539 accum += a_splat.direct(i_sample) * bnd[0].m_lo * bnd[1].m_hi * bnd[2].m_hi;
541 i_sample[0]=i_lower[0]+1;i_sample[1]=i_lower[1];i_sample[2]=i_lower[2]+1;
542 accum += a_splat.direct(i_sample) * bnd[0].m_lo * bnd[1].m_hi * bnd[2].m_lo;
544 i_sample[0]=i_lower[0];i_sample[1]=i_lower[1]+1;i_sample[2]=i_lower[2];
545 accum += a_splat.direct(i_sample) * bnd[0].m_hi * bnd[1].m_lo * bnd[2].m_hi;
553 a_splat.unit(unit_location, a_location);
557 a_splat.pivot(i_pivot, i_lower, unit_location);
559 for(
unsigned int i = 0; i < 2; i++)
563 bnd[i].m_hi = unit_location[i]/a_splat.cellsize()[i] - (Real)i_lower[i];
564 bnd[i].m_lo = 1.0 - bnd[i].m_hi;
581 i_sample[0]=i_lower[0];i_sample[1]=i_lower[1];
582 accum += a_splat.direct(i_sample) * bnd[0].m_lo * bnd[1].m_lo;
584 i_sample[0]=i_lower[0];i_sample[1]=i_lower[1]+1;
585 accum += a_splat.direct(i_sample) * bnd[0].m_lo * bnd[1].m_hi;
587 i_sample[0]=i_lower[0]+1;i_sample[1]=i_lower[1]+1;
588 accum += a_splat.direct(i_sample) * bnd[0].m_hi * bnd[1].m_hi;
590 i_sample[0]=i_lower[0]+1;i_sample[1]=i_lower[1];
591 accum += a_splat.direct(i_sample) * bnd[0].m_hi * bnd[1].m_lo;
596 template<
typename T,
unsigned int D>
597 class SubFill :
virtual public Splat<T,D>::Functor
600 SubFill(
typename Splat<T,D>::t_index &a_index,
const T &a_value, t_solve_real a_mass, std::vector<t_solve_v2> *a_data)
607 virtual ~SubFill(
void)
612 unsigned int i_cell = a_splat.calc_array_index(a_index);
613 t_solve_real sum = 0;
616 for(
unsigned int i = 0; i < D; i++)
618 t_solve_real a = (t_solve_real)(m_index[i] - a_index[i]) * a_splat.m_size[i];
621 t_solve_real distance = sqrt(sum);
622 if(distance < (*m_data)[i_cell][0])
624 t_solve_real dial = 0.1;
625 if(a_splat.m_mass[i_cell] <= dial && m_mass > dial)
627 (*m_data)[i_cell][0] = distance;
628 a_splat.m_cells[i_cell] = m_value;
629 a_splat.m_mass[i_cell] = dial;
635 std::vector<t_solve_v2> *m_data;
639 template<
typename T,
unsigned int D>
640 class Fill :
virtual public Splat<T,D>::Functor
643 Fill(
typename Splat<T,D>::t_cells *a_cells,
typename Splat<T,D>::t_mass *a_mass)
645 m_src_cells = a_cells;
647 m_data.resize(m_src_mass->size());
648 for(
unsigned int i = 0; i < m_data.size(); i++)
658 unsigned int i_cell = a_splat.calc_array_index(a_index);
659 T &src_value = (*m_src_cells)[i_cell];
660 t_solve_real src_mass = (*m_src_mass)[i_cell];
661 SubFill<T,D> subfill(a_index, src_value, src_mass, &m_data);
662 a_splat.iterate(subfill);
664 typename Splat<T,D>::t_cells *m_src_cells;
665 typename Splat<T,D>::t_mass *m_src_mass;
666 std::vector<t_solve_v2> m_data;
669 template<
typename T,
unsigned int D>
677 Fill<T,D> fill(&src_cells, &src_mass);
682 template<
typename T,
unsigned int D>
683 class SubStrut :
virtual public Splat<T,D>::Functor
692 m_closest0 = a_closest0;
693 m_closest1 = a_closest1;
695 virtual ~SubStrut(
void)
700 unsigned int i_cell = a_splat.calc_array_index(a_index);
701 t_solve_real sum = 0;
702 t_solve_real closest0 = 0;
703 t_solve_real closest1 = 0;
706 for(
unsigned int i = 0; i < D; i++)
708 t_solve_real a = (t_solve_real)(m_index[i] - a_index[i]) * a_splat.m_size[i];
711 a = (t_solve_real)((*m_closest0)[i] - m_index[i]) * a_splat.m_size[i];
714 a = (t_solve_real)((*m_closest1)[i] - m_index[i]) * a_splat.m_size[i];
719 if((*m_mass)[i_cell] > 1.0e-6)
723 (*m_closest1) = (*m_closest0);
724 (*m_closest0) = a_index;
726 sum = 0.0; closest0 = 0.0; closest1 = 0.0;
727 for(
unsigned int i = 0; i < D; i++)
729 t_solve_real a = (t_solve_real)(m_index[i] - a_index[i]) * a_splat.m_size[i];
731 a = (t_solve_real)((*m_closest0)[i] - m_index[i]) * a_splat.m_size[i];
733 a = (t_solve_real)((*m_closest1)[i] - m_index[i]) * a_splat.m_size[i];
737 else if(sum < closest1)
739 (*m_closest1) = a_index;
740 sum = 0.0; closest0 = 0.0; closest1 = 0.0;
741 for(
unsigned int i = 0; i < D; i++)
743 t_solve_real a = (t_solve_real)(m_index[i] - a_index[i]) * a_splat.m_size[i];
745 a = (t_solve_real)((*m_closest0)[i] - m_index[i]) * a_splat.m_size[i];
747 a = (t_solve_real)((*m_closest1)[i] - m_index[i]) * a_splat.m_size[i];
755 std::vector<t_solve_v2> *m_data;
756 typename Splat<T,D>::t_mass *m_mass;
761 template<
typename T,
unsigned int D>
762 class Closest :
virtual public Splat<T,D>::Functor
771 m_closest0 = a_closest0;
773 virtual ~Closest(
void)
778 unsigned int i_cell = a_splat.calc_array_index(a_index);
779 m_exclude.push_back(i_cell);
783 unsigned int i_cell = a_splat.calc_array_index(a_index);
784 for(
unsigned int i = 0; i < m_exclude.size(); i++)
786 if(i_cell == m_exclude[i])
791 t_solve_real sum = 0;
792 t_solve_real closest0 = 0;
793 for(
unsigned int i = 0; i < D; i++)
795 t_solve_real a = (t_solve_real)(m_index[i] - a_index[i]) * a_splat.m_size[i];
798 a = (t_solve_real)((*m_closest0)[i] - m_index[i]) * a_splat.m_size[i];
803 if((*m_mass)[i_cell] > 1.0e-6)
807 (*m_closest0) = a_index;
809 sum = 0.0; closest0 = 0.0;
810 for(
unsigned int i = 0; i < D; i++)
812 t_solve_real a = (t_solve_real)(m_index[i] - a_index[i]) * a_splat.m_size[i];
814 a = (t_solve_real)((*m_closest0)[i] - m_index[i]) * a_splat.m_size[i];
821 std::vector<unsigned int> m_exclude;
823 std::vector<t_solve_v2> *m_data;
824 typename Splat<T,D>::t_mass *m_mass;
828 template<
typename T,
unsigned int D>
829 class ClosestMate :
virtual public Splat<T,D>::Functor
838 m_closest = a_closest;
839 m_closest_mate = a_closest_mate;
841 virtual ~ClosestMate(
void)
846 unsigned int i_cell = a_splat.calc_array_index(a_index);
849 a_splat.spanize(M, (*m_closest) - m_index);
851 a_splat.spanize(C, a_index - m_index);
853 t_solve_real DOT = 0.0;
854 t_solve_real MM = 0.0;
855 t_solve_real CC = 0.0;
856 for(
unsigned int d = 0; d < D; d++)
863 if(MM < 1.0e-8) {
return; }
864 if(CC < 1.0e-8) {
return; }
866 for(
unsigned int d = 0; d < D; d++)
868 DOT += M[d]/MM * C[d]/MM;
871 if(DOT >= -1.0e-8) {
return; }
874 t_solve_real sum = 0;
875 t_solve_real closest_mate = 0;
876 for(
unsigned int i = 0; i < D; i++)
878 t_solve_real a = (t_solve_real)(m_index[i] - a_index[i]) * a_splat.m_size[i];
881 a = (t_solve_real)((*m_closest_mate)[i] - m_index[i]) * a_splat.m_size[i];
886 if((*m_mass)[i_cell] > 1.0e-6)
888 if(sum < closest_mate)
890 (*m_closest_mate) = a_index;
896 std::vector<t_solve_v2> *m_data;
897 typename Splat<T,D>::t_mass *m_mass;
902 template<
typename T,
unsigned int D>
903 class Strut :
virtual public Splat<T,D>::Functor
906 Strut(
typename Splat<T,D>::t_cells *a_cells,
typename Splat<T,D>::t_mass *a_mass)
908 m_src_cells = a_cells;
910 m_data.resize(m_src_mass->size());
911 for(
unsigned int i = 0; i < m_data.size(); i++)
921 unsigned int i_cell = a_splat.calc_array_index(a_index);
922 T &src_value = (*m_src_cells)[i_cell];
923 t_solve_real src_mass = (*m_src_mass)[i_cell];
925 if(src_mass > 1.0e-8)
927 a_splat.set(a_index, src_value);
928 a_splat.setMass(a_index, 1.0);
933 for(
unsigned int d = 0; d < D; d++)
935 m_closest0[d] = 1000;
936 m_closest1[d] = 1000;
937 m_closest2[d] = 1000;
938 m_closest0mate[d] = 1000;
939 m_closest1mate[d] = 1000;
940 m_closest2mate[d] = 1000;
946 Closest<T,D> closest(a_index, src_value, m_src_mass, &m_data, &m_closest0);
947 closest.exclude(a_splat, a_index);
948 a_splat.iterate(closest);
951 ClosestMate<T,D> closestmate(a_index, src_value, m_src_mass, &m_data, &m_closest0, &m_closest0mate);
952 a_splat.iterate(closestmate);
956 Closest<T,D> closest(a_index, src_value, m_src_mass, &m_data, &m_closest1);
957 closest.exclude(a_splat, a_index);
958 closest.exclude(a_splat, m_closest0);
959 closest.exclude(a_splat, m_closest0mate);
960 a_splat.iterate(closest);
963 if(m_closest0mate[0] != 1000)
965 ClosestMate<T,D> closestmate(a_index, src_value, m_src_mass, &m_data, &m_closest0mate, &m_closest1mate);
966 a_splat.iterate(closestmate);
975 Closest<T,D> closest(a_index, src_value, m_src_mass, &m_data, &m_closest2);
976 closest.exclude(a_splat, a_index);
977 closest.exclude(a_splat, m_closest0mate);
978 a_splat.iterate(closest);
980 if(m_closest2[0] != 1000)
982 ClosestMate<T,D> closestmate(a_index, src_value, m_src_mass, &m_data, &m_closest2, &m_closest2mate);
983 a_splat.iterate(closestmate);
988 t_solve_real closest0 = 0;
989 t_solve_real closest1 = 0;
990 t_solve_real closest2 = 0;
991 t_solve_real closest0mate = 0;
992 t_solve_real closest1mate = 0;
993 t_solve_real closest2mate = 0;
994 for(
unsigned int i = 0; i < D; i++)
997 a = (t_solve_real)(m_closest0[i] - a_index[i]) * a_splat.m_size[i];
1000 a = (t_solve_real)(m_closest1[i] - a_index[i]) * a_splat.m_size[i];
1003 a = (t_solve_real)(m_closest2[i] - a_index[i]) * a_splat.m_size[i];
1006 a = (t_solve_real)(m_closest0mate[i] - a_index[i]) * a_splat.m_size[i];
1007 closest0mate += a*a;
1009 a = (t_solve_real)(m_closest1mate[i] - a_index[i]) * a_splat.m_size[i];
1010 closest1mate += a*a;
1012 a = (t_solve_real)(m_closest2mate[i] - a_index[i]) * a_splat.m_size[i];
1013 closest2mate += a*a;
1017 a_splat.spanize(U, m_closest1 - m_closest0);
1019 a_splat.spanize(P, a_index - m_closest0);
1026 a_splat.spanize(AI, a_index);
1028 t_solve_real c0z = 0.0;
1029 t_solve_real L = 0.0;
1030 for(
unsigned int d = 0; d < D; d++)
1041 t_solve_real DOT = 0.0;
1042 for(
unsigned int d = 0; d < D; d++)
1049 T c0 = (*m_src_cells)[a_splat.calc_array_index(m_closest0)];
1050 if(m_closest0mate[0] == 1000
1051 || m_closest1mate[0] == 1000 )
1055 for(
unsigned int d = 0; d < D; d++)
1057 G = G + a_splat.m_gradients[a_splat.calc_array_index(m_closest0)].m_gradient[d] * P[d];
1059 a_splat.set(a_index, c0 + G);
1061 closest0 = sqrt(closest0);
1062 a_splat.setMass(a_index, 1.0-closest0);
1067 T c0m = (*m_src_cells)[a_splat.calc_array_index(m_closest0mate)];
1068 closest0 = sqrt(closest0);
1069 closest0mate = sqrt(closest0mate);
1071 T c1 = (*m_src_cells)[a_splat.calc_array_index(m_closest1)];
1072 T c1m = (*m_src_cells)[a_splat.calc_array_index(m_closest1mate)];
1073 closest1 = sqrt(closest1);
1074 closest1mate = sqrt(closest1mate);
1078 closest2 = sqrt(closest2);
1079 closest2mate = sqrt(closest2mate);
1083 for(
unsigned int d = 0; d < D; d++)
1085 G0 = G0 + a_splat.m_gradients[a_splat.calc_array_index(m_closest0)].m_gradient[d] * P[d];
1086 G1 = G1 + a_splat.m_gradients[a_splat.calc_array_index(m_closest1)].m_gradient[d] * P[d];
1089 t_solve_real w0 = closest0mate / (closest0 + closest0mate);
1090 t_solve_real w0m = 1.0 - w0;
1091 t_solve_real w1 = closest1mate / (closest1 + closest1mate);
1092 t_solve_real w1m = 1.0 - w1;
1096 t_solve_real W0 = closest1 / (closest0 + closest1);
1097 t_solve_real W1 = 1.0 - W0;
1099 T C0 = w0*c0 + w0m*c0m;
1100 T C1 = w1*c1 + w1m*c1m;
1102 T C = W0*C0 + W1*C1;
1104 a_splat.set(a_index, C);
1106 a_splat.setMass(a_index, 1.0 - closest0);
1112 typename Splat<T,D>::t_cells *m_src_cells;
1113 typename Splat<T,D>::t_mass *m_src_mass;
1120 std::vector<t_solve_v2> m_data;
1123 template<
typename T,
unsigned int D>
1128 src_cells = m_cells;
1130 for(
unsigned int i = 0; i < m_cells.size(); i++)
1132 m_cells[i] = m_init;
1136 Strut<T,D> strt(&src_cells, &src_mass);
1140 template<
typename T,
unsigned int D>
1141 class ReSplat :
virtual public Splat<T,D>::Functor
1146 m_other_splat = a_other_splat;
1148 virtual ~ReSplat(
void)
1154 a_splat.spanize(span, a_index);
1155 m_other_splat->unitSplat(1.0, span, a_splat.get(a_index));
1162 template<
typename T,
unsigned int D>
1165 ReSplat<T,D> resplat(a_other_splat);
1169 template<
typename T,
unsigned int D>
1170 class Pull :
virtual public Splat<T,D>::Functor
1175 m_other_splat = a_other_splat;
1183 a_splat.location(span, a_index);
1184 a_splat.splat(1.0, span, m_other_splat->sample(span));
1191 template<
typename T,
unsigned int D>
1194 Pull<T,D> p(a_other_splat);
1198 template<
typename T,
unsigned int D>
1199 class Push :
virtual public Splat<T,D>::Functor
1204 m_other_splat = a_other_splat;
1212 a_splat.location(span, a_index);
1214 m_other_splat->splat(1.0, span, a_splat.sample(span));
1221 template<
typename T,
unsigned int D>
1224 Push<T,D> p(a_other_splat);
1228 template<
typename T,
unsigned int D>
1229 class SubGradient :
virtual public Splat<T,D>::Functor
1236 virtual ~SubGradient(
void)
1241 unsigned int i_cell = a_splat.calc_array_index(a_index);
1242 unsigned int i_m_cell = a_splat.calc_array_index(m_index);
1245 a_splat.spanize(Dspan, Dindex);
1246 t_solve_real Dmagnitude = a_splat.magnitude(Dspan);
1248 if(i_cell == i_m_cell || Dmagnitude < 1.0e-8) {
return; }
1251 for(
unsigned int d = 0; d < D; d++)
1253 Dunit[d] = Dspan[d] / Dmagnitude;
1259 T value_delta_per_distance = (a_splat.m_cells[i_m_cell] - a_splat.m_cells[i_cell]) / Dmagnitude;
1261 t_solve_real use_mass = a_splat.m_mass[i_m_cell] / Dmagnitude;
1263 if(a_splat.m_mass[i_m_cell] > 1.0e-8) { use_mass = 1.0 / Dmagnitude; }
1266 a_splat.gradientSplat(use_mass, a_index, value_delta_per_distance, Dunit);
1271 template<
typename T,
unsigned int D>
1272 class Gradient :
virtual public Splat<T,D>::Functor
1278 virtual ~Gradient(
void)
1283 SubGradient<T,D> subgradient(a_index);
1284 a_splat.iterate(subgradient);
1288 template<
typename T,
unsigned int D>
1291 Gradient<T,D> gradient_fn;
1292 iterate(gradient_fn);
1296 template<
typename T,
unsigned int D>
1297 class ReApply :
virtual public Splat<T,D>::Functor
1306 virtual ~ReApply(
void)
1312 a_splat.location(loc, a_index);
1313 t_solve_real sum = 0;
1314 for(
unsigned int i = 0; i < D; i++)
1316 t_solve_real a = (m_loc[i] - loc[i]) * a_splat.m_scale[i];
1321 a_splat.splat(m_mass, loc, m_value);
1325 t_solve_real m_mass;
1328 template<
typename T,
unsigned int D>
1329 class Blurt :
virtual public Splat<T,D>::Functor
1332 Blurt(
typename Splat<T,D>::t_index &a_index,
const T &a_value, t_solve_real a_mass, t_solve_real a_factor)
1337 m_factor = a_factor;
1339 virtual ~Blurt(
void)
1344 t_solve_real sum = 0;
1345 for(
unsigned int i = 0; i < D; i++)
1347 t_solve_real a = (t_solve_real)(m_index[i] - a_index[i]) * a_splat.m_size[i];
1350 t_solve_real d = fabs(sum);
1351 t_solve_real metric = m_factor / (m_factor + d);
1352 if(metric < 0.0) { metric = 0.0; }
1353 t_solve_real use_mass = 1.0 * m_mass * metric;
1354 a_splat.massSplat(use_mass, a_index, m_value);
1358 t_solve_real m_mass;
1359 t_solve_real m_factor;
1362 template<
typename T,
unsigned int D>
1363 class Blurer :
virtual public Splat<T,D>::Functor
1366 Blurer(
typename Splat<T,D>::t_cells *a_cells,
typename Splat<T,D>::t_mass *a_mass, t_solve_real a_factor)
1368 m_src_cells = a_cells;
1369 m_src_mass = a_mass;
1370 m_factor = a_factor;
1372 virtual ~Blurer(
void)
1377 unsigned int i_cell = a_splat.calc_array_index(a_index);
1378 T &src_value = (*m_src_cells)[i_cell];
1379 t_solve_real src_mass = (*m_src_mass)[i_cell];
1381 Blurt<T,D> blurt(a_index, src_value, src_mass, m_factor);
1382 a_splat.iterate(blurt);
1389 typename Splat<T,D>::t_cells *m_src_cells;
1390 typename Splat<T,D>::t_mass *m_src_mass;
1391 t_solve_real m_factor;
1394 template<
typename T,
unsigned int D>
1399 src_cells = m_cells;
1401 for(
unsigned int i = 0; i < m_cells.size(); i++)
1407 Blurer<T,D> blurer(&src_cells, &src_mass, a_factor);
1412 template<
typename T,
unsigned int D>
1413 class Connector :
virtual public Splat<T,D>::Functor
1416 Connector(
sp<Scope> spScope,
sp<RecordGroup> rg_fill, std::vector<Record> *r_ps, std::vector<Record> *r_cs, std::vector<Record> *r_ks)
1418 m_spScope = spScope;
1419 m_rg_fill = rg_fill;
1421 m_asSolverParticle.bind(spScope);
1422 m_asParticle.bind(spScope);
1423 m_asColored.bind(spScope);
1424 m_asLinearSpring.bind(spScope);
1426 l_point = m_spScope->declare(
"l_point");
1427 m_asSolverParticle.populate(l_point);
1428 m_asParticle.populate(l_point);
1429 m_asColored.populate(l_point);
1431 l_link = m_spScope->declare(
"l_link");
1432 m_asLinearSpring.populate(l_link);
1438 virtual ~Connector(
void)
1443 for(
unsigned int d = 0; d < D; d++)
1445 if(a_index[d] < a_splat.m_count[d]-1)
1447 unsigned int i_a = a_splat.calc_array_index(a_index);
1449 other_index = a_index;
1450 other_index[d] += 1;
1451 unsigned int i_b = a_splat.calc_array_index(other_index);
1453 Record r_link = m_spScope->createRecord(l_link);
1454 m_asLinearSpring.left(r_link) = (*m_pps)[i_a];
1455 m_asLinearSpring.right(r_link) = (*m_pps)[i_b];
1456 m_asLinearSpring.length(r_link) = 0.0;
1457 m_asLinearSpring.stiffness(r_link) = 1.0e4;
1458 m_asLinearSpring.damping(r_link) = 1.0e1;
1459 m_rg_fill->add(r_link);
1464 std::vector<Record> *m_pps;
1465 std::vector<Record> *m_pcs;
1466 std::vector<Record> *m_pks;
1469 AsSolverParticle1D m_asSolverParticle;
1471 AsColored m_asColored;
1472 AsLinearSpringExtended m_asLinearSpring;
1478 template<
typename T,
unsigned int D>
1482 sp<Master> spMaster(FLEXI_NEW( gSTMBase.GetMemPool(), gSTMDebug.GetMemTrace(), MWL::Base::BDbgString(
"Splat") )
Master);
1484 spRegistry->
manage(
"fexCathedralDL");
1486 assertMath(spMaster->typeMaster());
1487 spSemiImplicit = FLEXI_NEW( gSTMBase.GetMemPool(), gSTMDebug.GetMemTrace(), MWL::Base::BDbgString(
"Splat") )
SemiImplicit1D();
1488 spSemiImplicit->initialize(spScope);
1491 sp<SemiImplicit1D::Force> spForce(FLEXI_NEW( gSTMBase.GetMemPool(), gSTMDebug.GetMemTrace(), MWL::Base::BDbgString(
"Splat") ) LinearSpringForce1D(spSemiImplicit));
1492 spSemiImplicit->addForce(spForce,
true);
1496 rg_fill = FLEXI_NEW( gSTMBase.GetMemPool(), gSTMDebug.GetMemTrace(), MWL::Base::BDbgString(
"SetaTireRig") )
RecordGroup();
1498 AsSolverParticle1D asSolverParticle;
1499 asSolverParticle.bind(spScope);
1501 asParticle.bind(spScope);
1503 asForcePoint.bind(spScope);
1504 AsColored asColored;
1505 asColored.bind(spScope);
1508 asSolverParticle.populate(l_point);
1509 asParticle.populate(l_point);
1510 asColored.populate(l_point);
1513 asForcePoint.populate(l_constraint);
1514 asColored.populate(l_constraint);
1516 AsLinearSpringExtended asLinearSpring;
1517 asLinearSpring.bind(spScope);
1519 asLinearSpring.populate(l_spring);
1521 std::vector<Record> r_ps;
1522 std::vector<Record> r_cs;
1523 std::vector<Record> r_ks;
1524 r_ps.resize(m_cells.size());
1525 r_cs.resize(m_cells.size());
1526 r_ks.resize(m_cells.size());
1527 for(
unsigned int i = 0; i < m_cells.size(); i++)
1530 asParticle.
mass(r_ps[i]) = 1.0;
1531 asParticle.location(r_ps[i]) = 0.0;
1532 asParticle.velocity(r_ps[i]) = 0.0;
1533 rg_fill->
add(r_ps[i]);
1536 asParticle.location(r_cs[i]) = value(m_cells[i], a_aspect);
1537 asParticle.velocity(r_cs[i]) = 0.0;
1538 rg_fill->
add(r_cs[i]);
1541 asLinearSpring.left(r_ks[i]) = r_ps[i];
1542 asLinearSpring.right(r_ks[i]) = r_cs[i];
1543 asLinearSpring.length(r_ks[i]) = 0.0;
1544 asLinearSpring.stiffness(r_ks[i]) = 1.0e8 * m_mass[i];
1545 asLinearSpring.damping(r_ks[i]) = 1.0e2;
1546 rg_fill->
add(r_ks[i]);
1549 Connector<T,D> connector(spScope, rg_fill, &r_ps, &r_cs, &r_ks);
1552 spSemiImplicit->compile(rg_fill);
1553 std::vector<SemiImplicit1D::Particle> &particles =
1554 spSemiImplicit->particles();
1558 for(
unsigned int t = 0; t < 1000; t++)
1560 spSemiImplicit->step(0.001, dummy);
1563 for(
unsigned int i = 0 ; i < r_ps.size(); i++)
1565 unsigned int i_p = asSolverParticle.index(r_ps[i]);
1566 fe_fprintf(stderr,
"%u %g\n", i_p, particles[i_p].m_location);
1567 value(m_cells[i], a_aspect) = particles[i_p].m_location;
1572 template<
typename T,
unsigned int D>
1574 t_span &a_span)
const 1576 for(
unsigned int i = 0; i < D; i++)
1582 else if(a_span[i] > 1.0)
1591 template<
typename T,
unsigned int D>
1595 for(
unsigned int i = 0; i < D; i++)
1597 if(!safe(i, a_index)) { ok =
false; }
1602 template<
typename T,
unsigned int D>
1607 if(m_count[a_d] == 1)
1609 if(a_index[a_d] != 0)
1615 else if(m_count[a_d] == 2)
1617 if(a_index[a_d] < 0)
1622 else if(a_index[a_d] > 1)
1630 if(a_index[a_d] < 0)
1635 else if(a_index[a_d] >= m_count[a_d])
1638 a_index[a_d] = m_count[a_d]-1;
1645 template<
typename T,
unsigned int D>
1649 for(
unsigned int i = 0; i < D; i++)
1651 m_count[i] = a_count[i];
1652 m_size[i] = 1.0/(m_count[i]-1);
1653 m_totalCount *= m_count[i];
1657 m_cells.resize(m_totalCount, a_init);
1658 m_mass.resize(m_totalCount, 0.0);
1659 m_gradients.resize(m_totalCount);
1660 m_gradient_mass.resize(m_totalCount, 0.0);
1661 for(
unsigned int i = 0; i < m_totalCount; i++)
1663 for(
unsigned int d = 0; d < D; d++)
1665 zero(m_gradients[i].m_gradient[d]);
1670 template<
typename T,
unsigned int D>
1673 m_totalCount = a_other_splat->m_totalCount;
1674 for(
unsigned int i = 0; i < D; i++)
1676 m_count[i] = a_other_splat->m_count[i];
1677 m_size[i] = a_other_splat->m_size[i];
1679 m_init = a_other_splat->m_init;
1680 m_cells.resize(m_totalCount, m_init);
1684 for(
unsigned int i = 0; i < m_totalCount; i++)
1686 for(
unsigned int d = 0; d < D; d++)
1689 m_cells[i][d] = a_other_splat->m_cells[i][d];
1692 for(
unsigned int d = 0; d < D; d++)
1694 m_root[d] = a_other_splat->m_root[d];
1695 m_scale[d] = a_other_splat->m_scale[d];
1700 template<
typename T,
unsigned int D>
1705 return m_cells[calc_array_index(safe_index)];
1708 template<
typename T,
unsigned int D>
1714 return m_cells[calc_array_index(a_index)];
1717 template<
typename T,
unsigned int D>
1722 return m_mass[calc_array_index(safe_index)];
1725 template<
typename T,
unsigned int D>
1730 m_cells[calc_array_index(safe_index)] = a_value;
1733 template<
typename T,
unsigned int D>
1738 m_mass[calc_array_index(safe_index)] = a_value;
1741 template<
typename T,
unsigned int D>
1745 unsigned int index = 0;
1746 unsigned int step = 1;
1747 for(
int d = D-1; d >= 0; d--)
1749 index += a_index[d] * step;
1755 template<
typename T,
unsigned int D>
1759 rIterate(D-1, index, a_functor);
1762 template<
typename T,
unsigned int D>
1766 for(
int i = 0; i < count()[a_d]; i++)
1771 a_functor.process(*
this, a_index);
1775 rIterate(a_d-1, a_index, a_functor);
1780 template<
typename T,
unsigned int D>
1781 class Dumper :
virtual public Splat<T,D>::Functor
1784 Dumper(
const char *a_filename)
1786 m_fp = fopen(a_filename,
"w");
1788 virtual ~Dumper(
void)
1794 if(D <=2 || a_index[2] == 2)
1798 a_splat.location(loc, a_index);
1799 fe_fprintf(m_fp,
"%g %g %g\n", loc[0], loc[1], a_splat.get(a_index)[0]);
1808 template<
typename T,
unsigned int D>
1811 Dumper<T,D> dumper(a_filename);
1818 template<
typename T,
unsigned int D>
1819 class DBSaver :
virtual public Splat<T,D>::Functor
1822 DBSaver(
const char *a_filename)
1824 m_fp = fopen(a_filename,
"w");
1826 virtual ~DBSaver(
void)
1832 fe_fprintf(m_fp,
"%g %g ", a_splat.get(a_index)[0], a_splat.get(a_index)[1]);
1839 template<
typename T,
unsigned int D>
1842 DBSaver<T,D> saver(a_filename);
1847 template<
typename T,
unsigned int D>
1848 class Saver :
virtual public Splat<T,D>::Functor
1853 m_r_splat = r_splat;
1855 virtual ~Saver(
void)
1872 asSplat.bind(spScope);
1874 asSplat.count(r_splat) =
Vector2i(a_splat.m_count[0], a_splat.m_count[1]);
1878 template<
typename T,
unsigned int D>
1879 class Loader :
virtual public Splat<T,D>::Functor
1882 Loader(
const char *a_filename)
1884 m_fp = fopen(a_filename,
"r");
1886 virtual ~Loader(
void)
1893 fscanf(m_fp,
"%g %g", &f0, &f1);
1902 Requires
new state access methodology...back to tires first
1904 template<
typename T,
unsigned int D>
1907 Loader<T,D> loader(a_filename);
1918 virtual ~TestCase(
void);
1919 virtual void run(
void);
1920 virtual void runCase(
void) = 0;
1922 void mark(t_tire_real a_x, t_tire_real a_y);
1923 void line(t_tire_real a_x, t_tire_real a_y);
1925 void annotate(t_tire_real a_x, t_tire_real a_y,
const String &a_text);
1926 void annotate(t_tire_real a_x, t_tire_real a_y, t_tire_real a_value);
1927 void hilight(t_scalar_tire_data a_datum, t_tire_real a_center, t_tire_real a_falloff, t_tire_v3 a_color);
1928 void hline(t_tire_real a_x, t_tire_real a_y,
const t_tire_v3 &a_color,
const String &a_text);
1929 void hline(t_tire_real a_x, t_tire_real a_y,
const t_tire_v3 &a_color, t_tire_real a_value);
1930 void hline(t_tire_real a_x, t_tire_real a_y,
const t_tire_v3 &a_color);
1931 void vline(t_tire_real a_x, t_tire_real a_y,
const t_tire_v3 &a_color,
const String &a_text);
1932 void vline(t_tire_real a_x, t_tire_real a_y,
const t_tire_v3 &a_color, t_tire_real a_value);
1933 void vline(t_tire_real a_x, t_tire_real a_y,
const t_tire_v3 &a_color);
1934 void bar(t_tire_real a_x, t_tire_real a_y,
const t_tire_v3 &a_color);
1935 void image(
const char *a_filename);
1938 const String &testname(
void) {
return m_testname; }
1939 const String &id(
void) {
return m_id; }
1944 Hilight(t_scalar_tire_data a_datum, t_tire_real a_center, t_tire_real a_falloff, t_tire_v3 a_color)
1948 m_center = a_center;
1949 m_falloff = a_falloff;
1951 t_scalar_tire_data m_datum;
1953 t_tire_real m_center;
1954 t_tire_real m_falloff;
1960 Annotation(t_tire_real a_x, t_tire_real a_y,
const String &a_text) :
1961 m_x(a_x), m_y(a_y), m_text(a_text) {}
1968 t_image_splat m_splat;
1970 t_stdvector< Hilight > m_hilights;
1974 t_stdvector< Annotation > m_annotations;
1975 bool m_line_started;
1976 t_image_splat::t_span m_loc;
1977 t_tire_v3 m_default_color;
1979 unsigned int m_frame;
N dimensional state buffer.
Definition: Splat.h:28
A heterogenous collection of records.
Definition: RecordGroup.h:35
virtual void add(const Record &record)
Add record to the collection.
Definition: RecordGroup.cc:77
Heap-based support for classes participating in fe::ptr <>
Definition: Counted.h:35
Accessor< Real > mass
mass
Definition: shapeAS.h:124
kernel
Definition: namespace.dox:3
sp< Layout > declare(const String &name)
Declare a new layout.
Definition: Scope.cc:434
sp< Layout > layout(void) const
Return the Layout.
Definition: RecordSB.h:189
force application point
Definition: shapeAS.h:98
Semi Implicit time integration.
Definition: SemiImplicit1D.h:154
sp< Component > create(const String &a_pattern, BWORD quiet=FALSE) const
Instantiate a Component of the given named implementation.
Definition: Registry.cc:628
Automatically reference-counted string container.
Definition: String.h:128
Result manage(const String &filename, bool adaptname=true, bool manageDependencies=true)
Register the factories in the named dynamic library.
Definition: Registry.cc:363
Definition: googletest-output-test_.cc:505
Reference to an instance of a Layout.
Definition: RecordSB.h:35
particle in physical space
Definition: shapeAS.h:114
Central access point for key pseudo-global objects.
Definition: Master.h:21
Record createRecord(sp< Layout > spLayout)
Create and return a new Record of layout spLayout.
Definition: Scope.cc:703