got keys + clicks :)
[engrid.git] / laplacesmoother.cpp
blobce21754a3baed7dd5acba07ee003387d6fe2d837
1 #include "laplacesmoother.h"
2 #include <vtkCellLocator.h>
3 #include <vtkCharArray.h>
5 LaplaceSmoother::LaplaceSmoother()
7 DebugLevel=0;
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;
24 setCells(AllCells);
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];
37 vtkIdType cellId;
38 int subId;
39 double dist2;
40 vtkCellLocator* terminator=vtkCellLocator::New();
41 terminator->SetDataSet(m_grid_orig);
42 terminator->BuildLocator();
44 UpdateNodeType_all();
45 EG_VTKDCN(vtkCharArray, node_type, m_grid, "node_type");
46 int moved_points=0;
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)
57 vec3_t G(0,0,0);
58 foreach(int id_M,n2n[id_G])
60 vec3_t M;
61 grid_tmp->GetPoint(id_M, M.data());
62 G+=M;
64 G=(1./n2n[id_G].size())*G;
65 vec3_t P;
66 terminator->FindClosestPoint(G.data(),P.data(),cellId,subId,dist2);
67 grid_tmp->GetPoints()->SetPoint(id_G, P.data());
68 moved_points++;
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()
81 // {
82 // if(DebugLevel>10) cout<<"LaplaceSmoother reporting in."<<endl;
83 //
84 // QVector<vtkIdType> AllCells;
85 // getAllSurfaceCells(AllCells, m_grid);
86 // QVector<vtkIdType> SelectedCells;
87 // getSurfaceCells(m_bcs, SelectedCells, m_grid);
88 //
89 // EG_VTKDCC(vtkIntArray, cell_code, m_grid, "cell_code");
90 // createCellToCell(AllCells, c2c, m_grid);
91 //
92 // QSet <vtkIdType> SelectedNodes;
93 // QSet <vtkIdType> InternalNodes;
94 // QSet <vtkIdType> ExternalNodes;
95 //
96 // foreach(vtkIdType id_cell, SelectedCells)
97 // {
98 // vtkIdType N_pts, *pts;
99 // m_grid->GetCellPoints(id_cell, N_pts, pts);
100 // for(int i=0;i<N_pts;i++)
101 // {
102 // QSet <int> bc;
103 // foreach(vtkIdType C, n2c[pts[i]])
104 // {
105 // bc.insert(cell_code->GetValue(C));
106 // }
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]);
110 // else
111 // {
112 // vtkIdType point=pts[i];
113 // QSet< int > NeighbourCells=n2c[point];
114 // vtkIdType start=*(NeighbourCells.begin());
115 // vtkIdType current=start;
116 // do
117 // {
118 // vtkIdType next=nextcell(current,point,c2c,m_grid);
119 // current=next;
120 // } while (current!=start && current!=-1);
121 // if(current==-1) ExternalNodes.insert(point);
122 // if(current==start) InternalNodes.insert(point);
123 // }
124 // }
125 // }
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];
134 // vtkIdType cellId;
135 // int subId;
136 // double dist2;
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++)
142 // {
143 // if(DebugLevel>10) cout<<"i_iter="<<i_iter<<endl;
144 // makeCopy(m_grid, grid_tmp);
146 // foreach(vtkIdType id_G,InternalNodes)
147 // {
148 // vec3_t G(0,0,0);
149 // foreach(int id_M,n2n[id_G])
150 // {
151 // vec3_t M;
152 // m_grid->GetPoint(id_M, M.data());
153 // G+=M;
154 // }
155 // G=(1./n2n[id_G].size())*G;
156 // vec3_t P;
157 // terminator->FindClosestPoint(G.data(),P.data(),cellId,subId,dist2);
158 // grid_tmp->GetPoints()->SetPoint(id_G, P.data());
159 // }
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);
167 // }
168 // if(DebugLevel>10) cout_grid(cout,m_grid);
170 // }