1 #include "laplacesmoother.h"
2 #include <vtkCellLocator.h>
4 LaplaceSmoother::LaplaceSmoother()
9 LaplaceSmoother::~LaplaceSmoother()
13 void LaplaceSmoother::operate()
15 if(DebugLevel
>10) cout
<<"LaplaceSmoother reporting in."<<endl
;
17 QVector
<vtkIdType
> AllCells
;
18 getAllSurfaceCells(AllCells
, m_grid
);
19 QVector
<vtkIdType
> SelectedCells
;
20 getSurfaceCells(m_bcs
, SelectedCells
, m_grid
);
22 EG_VTKDCC(vtkIntArray
, cell_code
, m_grid
, "cell_code");
23 createCellToCell(AllCells
, c2c
, m_grid
);
25 QSet
<vtkIdType
> SelectedNodes
;
26 QSet
<vtkIdType
> InternalNodes
;
27 QSet
<vtkIdType
> ExternalNodes
;
29 foreach(vtkIdType id_cell
, SelectedCells
)
31 vtkIdType N_pts
, *pts
;
32 m_grid
->GetCellPoints(id_cell
, N_pts
, pts
);
33 for(int i
=0;i
<N_pts
;i
++)
36 foreach(vtkIdType C
, n2c
[pts
[i
]])
38 bc
.insert(cell_code
->GetValue(C
));
40 if(DebugLevel
>10) cout
<<"pts[i]="<<pts
[i
]<<" and bc="<<bc
<<endl
;
41 SelectedNodes
.insert(pts
[i
]);
42 if(bc
.size()>1) ExternalNodes
.insert(pts
[i
]);
45 vtkIdType point
=pts
[i
];
46 QSet
< int > NeighbourCells
=n2c
[point
];
47 vtkIdType start
=*(NeighbourCells
.begin());
48 vtkIdType current
=start
;
51 vtkIdType next
=nextcell(current
,point
,c2c
,m_grid
);
53 } while (current
!=start
&& current
!=-1);
54 if(current
==-1) ExternalNodes
.insert(point
);
55 if(current
==start
) InternalNodes
.insert(point
);
60 createNodeToNode(cells
, nodes
, _nodes
, n2n
, m_grid
);
62 EG_VTKSP(vtkUnstructuredGrid
,grid_tmp
);
63 EG_VTKSP(vtkUnstructuredGrid
,m_grid_orig
);
64 makeCopy(m_grid
, m_grid_orig
);
66 double closestPoint
[3];
70 vtkCellLocator
* terminator
=vtkCellLocator::New();
71 terminator
->SetDataSet(m_grid_orig
);
72 terminator
->BuildLocator();
74 for(int i_iter
=0;i_iter
<NumberOfIterations
;i_iter
++)
76 if(DebugLevel
>10) cout
<<"i_iter="<<i_iter
<<endl
;
77 makeCopy(m_grid
, grid_tmp
);
79 foreach(vtkIdType id_G
,InternalNodes
)
82 foreach(int id_M
,n2n
[id_G
])
85 m_grid
->GetPoint(id_M
, M
.data());
88 G
=(1./n2n
[id_G
].size())*G
;
90 terminator
->FindClosestPoint(G
.data(),P
.data(),cellId
,subId
,dist2
);
91 grid_tmp
->GetPoints()->SetPoint(id_G
, P
.data());
94 if(DebugLevel
>10) cout
<< "SelectedNodes.size()=" << SelectedNodes
.size() << endl
;
95 if(DebugLevel
>10) cout
<< "InternalNodes.size()=" << InternalNodes
.size() << endl
;
96 if(DebugLevel
>10) cout
<< "ExternalNodes.size()=" << ExternalNodes
.size() << endl
;
97 if(DebugLevel
>10) cout
<< "InternalNodes=" << InternalNodes
<< endl
;
99 makeCopy(grid_tmp
,m_grid
);
101 if(DebugLevel
>10) cout_grid(cout
,m_grid
);