1 #include "laplacesmoother.h"
2 #include <vtkCellLocator.h>
3 #include <vtkCharArray.h>
5 LaplaceSmoother::LaplaceSmoother()
10 LaplaceSmoother::~LaplaceSmoother()
14 void LaplaceSmoother::operate()
16 if(DebugLevel
>10) cout
<<"LaplaceSmoother reporting in."<<endl
;
18 QVector
<vtkIdType
> AllCells
;
19 getAllSurfaceCells(AllCells
, m_grid
);
20 QVector
<vtkIdType
> SelectedCells
;
21 getSurfaceCells(m_bcs
, SelectedCells
, m_grid
);
23 cout
<<"setCells START"<<endl
;
25 cout
<<"setCells END"<<endl
;
27 QSet
<vtkIdType
> SelectedNodes
;
28 getSurfaceNodes(m_bcs
,SelectedNodes
,m_grid
);
30 EG_VTKDCC(vtkIntArray
, cell_code
, m_grid
, "cell_code");
32 EG_VTKSP(vtkUnstructuredGrid
,grid_tmp
);
33 EG_VTKSP(vtkUnstructuredGrid
,m_grid_orig
);
34 makeCopy(m_grid
, m_grid_orig
);
36 double closestPoint
[3];
40 vtkCellLocator
* terminator
=vtkCellLocator::New();
41 terminator
->SetDataSet(m_grid_orig
);
42 terminator
->BuildLocator();
45 EG_VTKDCN(vtkCharArray
, node_type
, m_grid
, "node_type");
48 makeCopy(m_grid
, grid_tmp
);
49 for(int i_iter
=0;i_iter
<NumberOfIterations
;i_iter
++)
51 if(DebugLevel
>10) cout
<<"i_iter="<<i_iter
<<endl
;
53 foreach(vtkIdType id_G
,SelectedNodes
)
55 if(node_type
->GetValue(id_G
)==VTK_SIMPLE_VERTEX
)
58 foreach(int id_M
,n2n
[id_G
])
61 grid_tmp
->GetPoint(id_M
, M
.data());
64 G
=(1./n2n
[id_G
].size())*G
;
66 terminator
->FindClosestPoint(G
.data(),P
.data(),cellId
,subId
,dist2
);
67 grid_tmp
->GetPoints()->SetPoint(id_G
, P
.data());
72 makeCopy(grid_tmp
,m_grid
);
74 if(DebugLevel
>10) cout
<< "SelectedNodes.size()=" << SelectedNodes
.size() << endl
;
75 if(DebugLevel
>10) cout
<< "moved_points=" << moved_points
<< endl
;
76 if(DebugLevel
>10) cout_grid(cout
,m_grid
);
80 // void LaplaceSmoother::operate()
82 // if(DebugLevel>10) cout<<"LaplaceSmoother reporting in."<<endl;
84 // QVector<vtkIdType> AllCells;
85 // getAllSurfaceCells(AllCells, m_grid);
86 // QVector<vtkIdType> SelectedCells;
87 // getSurfaceCells(m_bcs, SelectedCells, m_grid);
89 // EG_VTKDCC(vtkIntArray, cell_code, m_grid, "cell_code");
90 // createCellToCell(AllCells, c2c, m_grid);
92 // QSet <vtkIdType> SelectedNodes;
93 // QSet <vtkIdType> InternalNodes;
94 // QSet <vtkIdType> ExternalNodes;
96 // foreach(vtkIdType id_cell, SelectedCells)
98 // vtkIdType N_pts, *pts;
99 // m_grid->GetCellPoints(id_cell, N_pts, pts);
100 // for(int i=0;i<N_pts;i++)
103 // foreach(vtkIdType C, n2c[pts[i]])
105 // bc.insert(cell_code->GetValue(C));
107 // if(DebugLevel>10) cout<<"pts[i]="<<pts[i]<<" and bc="<<bc<<endl;
108 // SelectedNodes.insert(pts[i]);
109 // if(bc.size()>1) ExternalNodes.insert(pts[i]);
112 // vtkIdType point=pts[i];
113 // QSet< int > NeighbourCells=n2c[point];
114 // vtkIdType start=*(NeighbourCells.begin());
115 // vtkIdType current=start;
118 // vtkIdType next=nextcell(current,point,c2c,m_grid);
120 // } while (current!=start && current!=-1);
121 // if(current==-1) ExternalNodes.insert(point);
122 // if(current==start) InternalNodes.insert(point);
127 // createNodeToNode(cells, nodes, _nodes, n2n, m_grid);
129 // EG_VTKSP(vtkUnstructuredGrid,grid_tmp);
130 // EG_VTKSP(vtkUnstructuredGrid,m_grid_orig);
131 // makeCopy(m_grid, m_grid_orig);
133 // double closestPoint[3];
137 // vtkCellLocator* terminator=vtkCellLocator::New();
138 // terminator->SetDataSet(m_grid_orig);
139 // terminator->BuildLocator();
141 // for(int i_iter=0;i_iter<NumberOfIterations;i_iter++)
143 // if(DebugLevel>10) cout<<"i_iter="<<i_iter<<endl;
144 // makeCopy(m_grid, grid_tmp);
146 // foreach(vtkIdType id_G,InternalNodes)
149 // foreach(int id_M,n2n[id_G])
152 // m_grid->GetPoint(id_M, M.data());
155 // G=(1./n2n[id_G].size())*G;
157 // terminator->FindClosestPoint(G.data(),P.data(),cellId,subId,dist2);
158 // grid_tmp->GetPoints()->SetPoint(id_G, P.data());
161 // if(DebugLevel>10) cout << "SelectedNodes.size()=" << SelectedNodes.size() << endl;
162 // if(DebugLevel>10) cout << "InternalNodes.size()=" << InternalNodes.size() << endl;
163 // if(DebugLevel>10) cout << "ExternalNodes.size()=" << ExternalNodes.size() << endl;
164 // if(DebugLevel>10) cout << "InternalNodes=" << InternalNodes << endl;
166 // makeCopy(grid_tmp,m_grid);
168 // if(DebugLevel>10) cout_grid(cout,m_grid);