2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008,2009 Oliver Gloth +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "guismoothsurface.h"
24 #include "swaptriangles.h"
25 #include "createspecialmapping.h"
26 #include "vertexdelegate.h"
27 #include "settingssheet.h"
28 #include "laplacesmoother.h"
30 #include "guimainwindow.h"
32 #include <vtkSmoothPolyDataFilter.h>
33 #include <vtksmoothpolydatafilter2.h>
34 #include <vtkWindowedSincPolyDataFilter.h>
36 #include <vtkLongArray.h>
39 #include <QTextStream>
42 #include "vtkEgNormalExtrusion.h"
43 #include "containertricks.h"
47 #include <vtkIdList.h>
50 #include <vtkCellLocator.h>
51 #include <vtkFloatArray.h>
52 #include <vtkCellArray.h>
54 #include "vtkeggridsmoothpolydatafilter.h"
55 #include "vtkeggridwindowedsincpolydatafilter.h"
57 ///////////////////////////////////////////
58 /* Here is how we we get QTextStreams that look like iostreams */
59 QTextStream
Qcin(stdin
, QIODevice::ReadOnly
);
60 QTextStream
Qcout(stdout
, QIODevice::WriteOnly
);
61 QTextStream
Qcerr(stderr
, QIODevice::WriteOnly
);
62 ///////////////////////////////////////////
64 //////////////////////////////////////////////
66 int cout_vtkWindowedSincPolyDataFilter(vtkWindowedSincPolyDataFilter
* smooth
)
68 cout
<<"NumberOfIterations="<<smooth
->GetNumberOfIterations()<<endl
;
69 cout
<<"PassBand="<<smooth
->GetPassBand()<<endl
;
70 cout
<<"FeatureEdgeSmoothing="<<smooth
->GetFeatureEdgeSmoothing()<<endl
;
71 cout
<<"FeatureAngle="<<smooth
->GetFeatureAngle()<<endl
;
72 cout
<<"EdgeAngle="<<smooth
->GetEdgeAngle()<<endl
;
73 cout
<<"BoundarySmoothing="<<smooth
->GetBoundarySmoothing()<<endl
;
74 cout
<<"GenerateErrorScalars="<<smooth
->GetGenerateErrorScalars()<<endl
;
75 cout
<<"GenerateErrorVectors="<<smooth
->GetGenerateErrorVectors()<<endl
;
79 int cout_vtkSmoothPolyDataFilter(vtkSmoothPolyDataFilter
* smooth
)
81 cout
<<"GetConvergence="<<smooth
->GetConvergence()<<endl
;
82 cout
<<"GetNumberOfIterations="<<smooth
->GetNumberOfIterations()<<endl
;
83 cout
<<"GetRelaxationFactor="<<smooth
->GetRelaxationFactor()<<endl
;
84 cout
<<"GetFeatureEdgeSmoothing="<<smooth
->GetFeatureEdgeSmoothing()<<endl
;
85 cout
<<"GetFeatureAngle="<<smooth
->GetFeatureAngle()<<endl
;
86 cout
<<"GetEdgeAngle="<<smooth
->GetEdgeAngle()<<endl
;
87 cout
<<"GetBoundarySmoothing="<<smooth
->GetBoundarySmoothing()<<endl
;
88 cout
<<"GetGenerateErrorScalars="<<smooth
->GetGenerateErrorScalars()<<endl
;
89 cout
<<"GetGenerateErrorVectors="<<smooth
->GetGenerateErrorVectors()<<endl
;
93 ///////////////////////////////////////////
95 int GuiSmoothSurface::readSettings()
97 local_qset
=new QSettings("enGits","enGrid_smoothsurface");
98 // current_settingssheet_name=local_qset->value("Filename", "").toString();
99 ui
.SmoothMethod
->setCurrentIndex(local_qset
->value("Method", 0).toInt());
100 ui
.spinBox_NumberOfSmoothIterations
->setValue(local_qset
->value("NumberOfSmoothIterations", 20).toInt());
101 ui
.spinBox_maxiter_density
->setValue(local_qset
->value("maxiter_density", 1000).toInt());
102 ui
.spinBox_DebugLevel
->setValue(local_qset
->value("DebugLevel", 0).toInt());
103 ui
.spinBox_NumberOfIterations
->setValue(local_qset
->value("NumberOfIterations", 1).toInt());
105 ui
.doubleSpinBox_Convergence_meshdensity
->setValue(local_qset
->value("Convergence_meshdensity", 0.000001).toDouble());
106 ui
.checkBox_insert_FP
->setCheckState(int2CheckState(local_qset
->value("insert_FP", 2).toInt()));
107 ui
.checkBox_insert_EP
->setCheckState(int2CheckState(local_qset
->value("insert_EP", 2).toInt()));
108 ui
.checkBox_remove_FP
->setCheckState(int2CheckState(local_qset
->value("remove_FP", 2).toInt()));
109 ui
.checkBox_remove_EP
->setCheckState(int2CheckState(local_qset
->value("remove_EP", 2).toInt()));
110 ui
.checkBox_Swap
->setCheckState(int2CheckState(local_qset
->value("DoSwap", 2).toInt()));
111 ui
.checkBox_LaplaceSmoothing
->setCheckState(int2CheckState(local_qset
->value("DoLaplaceSmoothing", 2).toInt()));
113 if(local_qset
->value("DensityUnit_is_length", false).toBool()){
114 ui
.radioButton_length
->toggle();
117 ui
.radioButton_density
->toggle();
121 size
= local_qset
->beginReadArray("list_BC");
122 if(ui
.listWidget
->count()==size
)
124 for (int i
= 0; i
< size
; ++i
) {
125 local_qset
->setArrayIndex(i
);
126 Qt::CheckState x
=int2CheckState(local_qset
->value("state").toInt());
127 ui
.listWidget
->item(i
)->setCheckState(x
);
129 local_qset
->endArray();
132 size
= local_qset
->beginReadArray("list_BC_Source");
133 if(ui
.listWidget_Source
->count()==size
)
135 for (int i
= 0; i
< size
; ++i
) {
136 local_qset
->setArrayIndex(i
);
137 Qt::CheckState x
=int2CheckState(local_qset
->value("state").toInt());
138 ui
.listWidget_Source
->item(i
)->setCheckState(x
);
140 local_qset
->endArray();
145 int GuiSmoothSurface::writeSettings()
147 local_qset
=new QSettings("enGits","enGrid_smoothsurface");
148 // local_qset->setValue("Filename", current_settingssheet_name);
149 local_qset
->setValue("Method", ui
.SmoothMethod
->currentIndex());
150 local_qset
->setValue("NumberOfSmoothIterations", ui
.spinBox_NumberOfSmoothIterations
->value());
151 local_qset
->setValue("NumberOfIterations", ui
.spinBox_NumberOfIterations
->value());
152 local_qset
->setValue("maxiter_density", ui
.spinBox_maxiter_density
->value());
153 local_qset
->setValue("DebugLevel", ui
.spinBox_DebugLevel
->value());
154 local_qset
->setValue("Convergence_meshdensity", ui
.doubleSpinBox_Convergence_meshdensity
->value());
155 local_qset
->setValue("insert_FP", ui
.checkBox_insert_FP
->checkState());
156 local_qset
->setValue("insert_EP", ui
.checkBox_insert_EP
->checkState());
157 local_qset
->setValue("remove_FP", ui
.checkBox_remove_FP
->checkState());
158 local_qset
->setValue("remove_EP", ui
.checkBox_remove_EP
->checkState());
159 local_qset
->setValue("DoSwap", ui
.checkBox_Swap
->checkState());
160 local_qset
->setValue("DoLaplaceSmoothing", ui
.checkBox_LaplaceSmoothing
->checkState());
161 local_qset
->setValue("DensityUnit_is_length",ui
.radioButton_length
->isChecked());
163 QList
<Qt::CheckState
> list
;
165 for (int i
= 0; i
< ui
.listWidget
->count(); ++i
) {
166 list
<< ui
.listWidget
->item(i
)->checkState();
168 local_qset
->beginWriteArray("list_BC");
169 for (int i
= 0; i
< list
.size(); ++i
) {
170 local_qset
->setArrayIndex(i
);
171 local_qset
->setValue("state", list
.at(i
));
173 local_qset
->endArray();
176 for (int i
= 0; i
< ui
.listWidget_Source
->count(); ++i
) {
177 list
<< ui
.listWidget_Source
->item(i
)->checkState();
179 local_qset
->beginWriteArray("list_BC_Source");
180 for (int i
= 0; i
< list
.size(); ++i
) {
181 local_qset
->setArrayIndex(i
);
182 local_qset
->setValue("state", list
.at(i
));
184 local_qset
->endArray();
189 ///////////////////////////////////////////
191 void GuiSmoothSurface::before()
194 tableWidget
=new SettingsSheet();
195 ui
.verticalLayout_SettingsSheet
->addWidget(tableWidget
);
197 populateBoundaryCodes(ui
.listWidget
);
198 populateBoundaryCodes(ui
.listWidget_Source
);
200 ui
.SmoothMethod
->addItem("Method 0: vtkSmoothPolyDataFilter smoothing");
201 ui
.SmoothMethod
->addItem("Method 1: vtkWindowedSincPolyDataFilter smoothing");
202 ui
.SmoothMethod
->addItem("Method 2: edge subdivision");
203 ui
.SmoothMethod
->addItem("Method 3: swap triangles");
204 ui
.SmoothMethod
->addItem("Method 4: center subdivision");
205 ui
.SmoothMethod
->addItem("Method 5: boundary refinement");
206 ui
.SmoothMethod
->addItem("Method 6: Laplacian smoothing");
207 ui
.SmoothMethod
->addItem("Method 7: VertexAvgDist test");
208 ui
.SmoothMethod
->addItem("Method 8: Create mesh density map");
209 ui
.SmoothMethod
->addItem("Method 9: vtkWindowedSincPolyDataFilter smoothing");
210 ui
.SmoothMethod
->addItem("Method 10: Super smoothing :)");
211 ui
.SmoothMethod
->addItem("Method 11: Update current mesh density + node types");
212 ui
.SmoothMethod
->addItem("Method 12: Delete all possible points :)");
213 ui
.SmoothMethod
->addItem("Method 13: Delete selected points");
214 ui
.SmoothMethod
->addItem("Method 14");
215 ui
.SmoothMethod
->addItem("Method 15");
216 ui
.SmoothMethod
->addItem("Method 16");
217 ui
.SmoothMethod
->addItem("Method 17");
218 ui
.SmoothMethod
->addItem("Method 18");
220 if(ui
.listWidget
->count()>0) ui
.lineEdit_BoundaryCode
-> setText(ui
.listWidget
->item(0)->text());
221 else ui
.lineEdit_BoundaryCode
-> setText("42");
222 ui
.spinBox_NumberOfSubdivisions
->setValue(1);
224 vtkSmoothPolyDataFilter
* smooth
=vtkSmoothPolyDataFilter::New();
225 vtkWindowedSincPolyDataFilter
* smooth2
=vtkWindowedSincPolyDataFilter::New();
227 cout_vtkSmoothPolyDataFilter(smooth
);
228 cout_vtkWindowedSincPolyDataFilter(smooth2
);
230 ui
.doubleSpinBox_Convergence
->setValue(smooth
->GetConvergence());
231 // ui.spinBox_NumberOfIterations->setValue(smooth->GetNumberOfIterations());
232 // ui.spinBox_NumberOfIterations->setValue(1000);
233 // ui.spinBox_NumberOfIterations->setValue(1);
235 ui
.lineEdit_RelaxationFactor
->setText(tmp
.setNum(smooth
->GetRelaxationFactor()));
236 ui
.doubleSpinBox_PassBand
->setValue(smooth2
->GetPassBand());
237 // ui.checkBox_FeatureEdgeSmoothing->setCheckState(int2CheckState(smooth->GetFeatureEdgeSmoothing()));
238 ui
.checkBox_FeatureEdgeSmoothing
->setCheckState(Qt::Checked
);
239 // ui.checkBox_FeatureEdgeSmoothing->setFlags(Qt::ItemIsTristate | ui.checkBox_FeatureEdgeSmoothing->flags);
240 ui
.doubleSpinBox_FeatureAngle
->setValue(smooth
->GetFeatureAngle());
241 ui
.doubleSpinBox_EdgeAngle
->setValue(smooth
->GetEdgeAngle());
242 ui
.checkBox_BoundarySmoothing
->setCheckState(int2CheckState(smooth
->GetBoundarySmoothing()));
243 /* ui.checkBox_GenerateErrorScalars->setCheckState(int2CheckState(smooth->GetGenerateErrorScalars()));
244 ui.checkBox_GenerateErrorVectors->setCheckState(int2CheckState(smooth->GetGenerateErrorVectors()));*/
245 ui
.checkBox_GenerateErrorScalars
->setCheckState(int2CheckState(2));
246 ui
.checkBox_GenerateErrorVectors
->setCheckState(int2CheckState(2));
248 /* ui.doubleSpinBox_VTK_SIMPLE_VERTEX->setValue(-1);
249 ui.doubleSpinBox_VTK_FIXED_VERTEX->setValue(-1);
250 ui.doubleSpinBox_VTK_FEATURE_EDGE_VERTEX->setValue(-1);
251 ui.doubleSpinBox_VTK_BOUNDARY_EDGE_VERTEX->setValue(-1);*/
258 QTableWidgetItem
*newItem
= new QTableWidgetItem(tr("%1").arg((row
+1)*(column
+1)));
259 tableWidget
->setItem(row
, column
, newItem
);
261 cout
<<"tableWidget->rowCount()="<<tableWidget
->rowCount()<<endl
;
262 cout
<<"tableWidget->columnCount()="<<tableWidget
->columnCount()<<endl
;
264 Nrow
=tableWidget
->rowCount();
265 Ncol
=tableWidget
->columnCount();
268 list
<< "VTK_SIMPLE_VERTEX"
270 <<"VTK_FEATURE_EDGE_VERTEX"
271 <<"VTK_BOUNDARY_EDGE_VERTEX"
274 QList
<QString
> list2
;
279 Nbc
=ui
.listWidget
-> count ();
280 tableWidget
->setColumnCount(Nbc
+3);
281 tableWidget
->setItemDelegate(new VertexDelegate(Nbc
, list
));
284 for(int i
=0;i
<Nbc
;i
++)
286 // Qcout<<"BASE!!!="<<ui.listWidget->item(i)->text()<<endl;
287 L
<<ui
.listWidget
->item(i
)->text();
292 tableWidget
->setHorizontalHeaderLabels(L
);
293 tableWidget
->resizeColumnsToContents();
296 current_filename
= GuiMainWindow::pointer()->GetFilename();
297 Qcout
<<"current_filename="<<current_filename
<<endl
;
298 Qcout
<<"Loading settings from "+current_filename
+".sp..."<<endl
;
300 if (!tableWidget
->readFile(current_filename
+".sp",0)) {
301 cout
<<"Loading settingssheet failed"<<endl
;
303 /* if (!current_settingssheet_name.isEmpty() && !tableWidget->readFile(current_settingssheet_name,0)) {
304 cout<<"Loading failed"<<endl;
307 connect(ui
.pushButton_AddSet
, SIGNAL(clicked()), this, SLOT(AddSet()));
308 connect(ui
.pushButton_RemoveSet
, SIGNAL(clicked()), this, SLOT(RemoveSet()));
309 connect(ui
.pushButton_TestSet
, SIGNAL(clicked()), this, SLOT(TestSet()));
310 connect(ui
.pushButton_Load
, SIGNAL(clicked()), this, SLOT(Load()));
311 connect(ui
.pushButton_Save
, SIGNAL(clicked()), this, SLOT(Save()));
312 connect(ui
.pushButton_SelectAll_BC
, SIGNAL(clicked()), this, SLOT(SelectAll_BC()));
313 connect(ui
.pushButton_ClearAll_BC
, SIGNAL(clicked()), this, SLOT(ClearAll_BC()));
314 connect(ui
.pushButton_SelectAll_Source
, SIGNAL(clicked()), this, SLOT(SelectAll_Source()));
315 connect(ui
.pushButton_ClearAll_Source
, SIGNAL(clicked()), this, SLOT(ClearAll_Source()));
318 void GuiSmoothSurface::Load()
320 QString current_settingssheet_name
= QFileDialog::getOpenFileName(this,tr("Open SettingsSheet"), ".",tr("SettingsSheet files (*.sp)"));
321 if (!current_settingssheet_name
.isEmpty() && !tableWidget
->readFile(current_settingssheet_name
)) {
322 cout
<<"Loading failed"<<endl
;
325 void GuiSmoothSurface::Save()
327 QString current_settingssheet_name
= QFileDialog::getSaveFileName(this,tr("Save SettingsSheet as..."), ".",tr("SettingsSheet files (*.sp)"));
328 if (!current_settingssheet_name
.isEmpty() && !tableWidget
->writeFile(current_settingssheet_name
)) {
329 cout
<<"Saving failed"<<endl
;
333 void GuiSmoothSurface::SelectAll_BC()
335 for (int i
= 0; i
< ui
.listWidget
->count(); ++i
) {
336 ui
.listWidget
->item(i
)->setCheckState(Qt::Checked
);
339 void GuiSmoothSurface::ClearAll_BC()
341 for (int i
= 0; i
< ui
.listWidget
->count(); ++i
) {
342 ui
.listWidget
->item(i
)->setCheckState(Qt::Unchecked
);
345 void GuiSmoothSurface::SelectAll_Source()
347 for (int i
= 0; i
< ui
.listWidget_Source
->count(); ++i
) {
348 ui
.listWidget_Source
->item(i
)->setCheckState(Qt::Checked
);
351 void GuiSmoothSurface::ClearAll_Source()
353 for (int i
= 0; i
< ui
.listWidget_Source
->count(); ++i
) {
354 ui
.listWidget_Source
->item(i
)->setCheckState(Qt::Unchecked
);
358 void GuiSmoothSurface::TestSet()
360 cout
<<"Testing set"<<endl
;
364 //This is where we get the user defined mesh densities
365 QVector
<VertexMeshDensity
> GuiSmoothSurface::GetSet()
367 cout
<<"Getting set"<<endl
;
368 QVector
<VertexMeshDensity
> VMDvector
;
369 cout
<<"VMDvector:"<<VMDvector
<<endl
;
371 int N_VMD
=tableWidget
->rowCount();
372 VMDvector
.resize(N_VMD
);
373 cout
<<"VMDvector.size()="<<VMDvector
.size()<<endl
;
374 for(int i
=0;i
<N_VMD
;i
++)
376 for(int j
=0;j
<Nbc
;j
++)
378 if(tableWidget
->item(i
,j
)->checkState()) VMDvector
[i
].BClist
.push_back(tableWidget
->horizontalHeaderItem(j
)->text().toInt());
379 int bc
= tableWidget
->horizontalHeaderItem(j
)->text().toInt();
380 int state
= CheckState2int( tableWidget
->item(i
,j
)->checkState() );
381 // VMDvector[i].BClist2.push_back(pair<int,int>(bc,state));
382 VMDvector
[i
].BCmap
[bc
]=state
;
384 VMDvector
[i
].type
=Str2VertexType(tableWidget
->item(i
,Nbc
)->text());
385 VMDvector
[i
].SetNodes(tableWidget
->item(i
,Nbc
+1)->text());
386 if(ui
.radioButton_density
->isChecked()){
387 VMDvector
[i
].density
=tableWidget
->item(i
,Nbc
+2)->text().toDouble();
390 cout
<<"ze_density="<<1.0/(tableWidget
->item(i
,Nbc
+2)->text().toDouble())<<endl
;
391 VMDvector
[i
].density
=1.0/(tableWidget
->item(i
,Nbc
+2)->text().toDouble());
394 cout
<<"VMDvector:"<<VMDvector
<<endl
;
399 void GuiSmoothSurface::AddSet()
401 cout
<<"Adding set"<<endl
;
402 int row
=tableWidget
->rowCount();
403 tableWidget
->insertRow(row
);
405 int Nbc
=ui
.listWidget
->count();
406 for(int i
=0;i
<Nbc
;i
++)
408 TriStateTableWidgetItem
*newBC
= new TriStateTableWidgetItem();
409 newBC
->setFlags(Qt::ItemIsTristate
| Qt::ItemIsEnabled
| Qt::ItemIsUserCheckable
);
410 tableWidget
->setItem(row
, i
, newBC
);
412 QTableWidgetItem
*item
;
413 item
= new QTableWidgetItem("any");
414 tableWidget
->setItem(row
, Nbc
, item
);
415 item
= new QTableWidgetItem("");
416 tableWidget
->setItem(row
, Nbc
+1, item
);
417 item
= new QTableWidgetItem("-1");
418 tableWidget
->setItem(row
, Nbc
+2, item
);
419 tableWidget
->resizeColumnsToContents();
422 void GuiSmoothSurface::RemoveSet()
424 cout
<<"Removing set"<<endl
;
425 tableWidget
->removeRow(tableWidget
->currentRow());
426 tableWidget
->resizeColumnsToContents();
429 int GuiSmoothSurface::DisplayErrorScalars(vtkPolyDataAlgorithm
* algo
)
432 cout
<<"==============="<<endl
;
433 cout
<<"ErrorScalars:"<<endl
;
435 double x1
[3], x2
[3], x3
[3], l1
[3], l2
[3];
438 N1
=algo
->GetOutput()->GetPointData()->GetNumberOfArrays();
439 // cout<<"nb of arrays="<<N1<<endl;
440 algo
->GetOutput();//vtkPolyData
441 // cout<<algo->GetOutput()->GetPointData()<<endl;//vtkPointData*
442 vtkFloatArray
*newScalars
= vtkFloatArray::New();
443 newScalars
=(vtkFloatArray
*)algo
->GetOutput()->GetPointData()->GetArray(1);
444 N1
=newScalars
->GetNumberOfComponents();
445 N2
=newScalars
->GetNumberOfTuples();
446 cout
<<"Number of components=N1="<<N1
<<endl
;
447 cout
<<"Number of tuples=N2="<<N2
<<endl
;
448 for (int i
=0; i
<N2
; i
++)
450 dist
=newScalars
->GetComponent(i
-1,1);//strange, but works. O.o
451 cout
<<"dist["<<i
<<"]="<<dist
<<endl
;
454 cout
<<"==============="<<endl
;
458 int GuiSmoothSurface::DisplayErrorVectors(vtkPolyDataAlgorithm
* algo
)
460 cout
<<"==============="<<endl
;
461 cout
<<"ErrorVectors:"<<endl
;
464 algo->GetOutput()->GetPoint(0, xx.data());*/
465 int N1
=algo
->GetOutput()->GetPointData()->GetVectors()->GetNumberOfComponents();
466 int N2
=algo
->GetOutput()->GetPointData()->GetVectors()->GetNumberOfTuples();
467 cout
<<"Number of components=N1="<<N1
<<endl
;
468 cout
<<"Number of tuples=N2="<<N2
<<endl
;
469 /* vtkPointData* newPointData = vtkPointData::New();
470 newPointData=algo->GetOutput()->GetPointData();
471 cout<<"Are you aware?:"<<newPointData->IsA("vtkDataArray")<<endl;*/
473 /* void vtkFieldData::GetTuple ( const vtkIdType i,
476 Copy the ith tuple value into a user provided tuple array. Make sure that you've allocated enough space for the copy.
478 as of VTK 5.2. Using this method for FieldData having arrays that are not subclasses of vtkDataArray may yield unexpected results. */
479 //Yes, indeed, very unexpected... And what should we do instead?
481 for(vtkIdType i
=0;i
<N2
;i
++)
485 algo
->GetOutput()->GetPointData()->GetTuple(i
,tuple
);
486 cout
<<"tuple["<<tuple
[0]<<"]=("<<tuple
[1]<<","<<tuple
[2]<<","<<tuple
[3]<<")"<<endl
;//TODO: This works, but seems incorrect
488 cout
<<"==============="<<endl
;
492 void GuiSmoothSurface::operate()
494 cout
<<"Saving settings..."<<endl
;
498 Qcout
<<"current_filename="<<current_filename
<<endl
;
499 Qcout
<<"Saving settings as "+current_filename
+".sp..."<<endl
;
500 // if(!current_settingssheet_name.isEmpty()) tableWidget->writeFile(current_settingssheet_name);
501 if(!tableWidget
->writeFile(current_filename
+".sp")) cout
<<"Saving settingssheet failed."<<endl
;
503 cout
<<"METHOD "<<ui
.SmoothMethod
->currentIndex()<<endl
;
504 //can't use switch case because dynamic variables seem to be forbidden inside case statements
505 //////////////////////////////////////////////////////////////////////////////////////////////
506 if(ui
.SmoothMethod
->currentIndex()==0)//vtkSmoothPolyDataFilter smoothing
510 getSelectedItems(ui
.listWidget
, bcs
);
511 QVector
<vtkIdType
> cells
;
512 getSurfaceCells(bcs
, cells
, grid
);
513 EG_VTKSP(vtkPolyData
, pdata
);
514 addToPolyData(cells
, pdata
, grid
);
515 EG_VTKSP(vtkSmoothPolyDataFilter
, smooth
);
517 // EG_VTKSP(vtkEgGridSmoothPolyDataFilter, smooth2);
518 // vtkSmartPointer<vtkEgGridSmoothPolyDataFilter> smooth2 = vtkSmartPointer<vtkEgGridSmoothPolyDataFilter>::New();
520 cout_vtkSmoothPolyDataFilter(smooth
);
522 //configure vtkSmoothPolyDataFilter
523 smooth
->SetInput(pdata
);
525 smooth
->SetConvergence (ui
.doubleSpinBox_Convergence
->value());
526 smooth
->SetNumberOfIterations (ui
.spinBox_NumberOfIterations
->value());
527 smooth
->SetRelaxationFactor (ui
.lineEdit_RelaxationFactor
->text().toDouble());
528 smooth
->SetFeatureEdgeSmoothing (ui
.checkBox_FeatureEdgeSmoothing
->checkState());
529 smooth
->SetFeatureAngle (ui
.doubleSpinBox_FeatureAngle
->value());
530 smooth
->SetEdgeAngle (ui
.doubleSpinBox_EdgeAngle
->value());
531 smooth
->SetBoundarySmoothing (ui
.checkBox_BoundarySmoothing
->checkState());
532 smooth
->SetGenerateErrorScalars (ui
.checkBox_GenerateErrorScalars
->checkState());
533 smooth
->SetGenerateErrorVectors (ui
.checkBox_GenerateErrorVectors
->checkState());
535 QSet
<int> bcs_Source
;
536 getSelectedItems(ui
.listWidget
,bcs_Source
);
537 QVector
<vtkIdType
> cells_Source
;
538 getSurfaceCells(bcs_Source
, cells_Source
, grid
);
539 EG_VTKSP(vtkPolyData
, pdata_Source
);
540 addToPolyData(cells_Source
, pdata_Source
, grid
);
541 smooth
->SetSource (pdata_Source
);
543 cout_vtkSmoothPolyDataFilter(smooth
);
548 if(ui
.checkBox_GenerateErrorScalars
->checkState()) DisplayErrorScalars(smooth
);
549 if(ui
.checkBox_GenerateErrorVectors
->checkState()) DisplayErrorVectors(smooth
);
551 //copy smoothed grid to main grid
552 EG_VTKDCN(vtkLongArray_t
, node_index
, pdata
, "node_index");
553 for (vtkIdType i
= 0; i
< smooth
->GetOutput()->GetNumberOfPoints(); ++i
) {
555 smooth
->GetOutput()->GetPoints()->GetPoint(i
, x
.data());
556 vtkIdType nodeId
= node_index
->GetValue(i
);
557 grid
->GetPoints()->SetPoint(nodeId
, x
.data());
561 //////////////////////////////////////////////////////////////////////////////////////////////
562 else if(ui
.SmoothMethod
->currentIndex()==1)//vtkWindowedSincPolyDataFilter smoothing
565 getSelectedItems(ui
.listWidget
, bcs
);
566 QVector
<vtkIdType
> cells
;
567 getSurfaceCells(bcs
, cells
, grid
);
568 EG_VTKSP(vtkPolyData
, pdata
);
569 addToPolyData(cells
, pdata
, grid
);
570 EG_VTKSP(vtkWindowedSincPolyDataFilter
, smooth
);
572 cout_vtkWindowedSincPolyDataFilter(smooth
);
574 smooth
->SetInput(pdata
);
576 smooth
->SetNumberOfIterations(ui
.spinBox_NumberOfIterations
->value());
577 smooth
->SetPassBand(ui
.doubleSpinBox_PassBand
->value());
578 smooth
->SetFeatureEdgeSmoothing(ui
.checkBox_FeatureEdgeSmoothing
->checkState());
579 smooth
->SetFeatureAngle(ui
.doubleSpinBox_FeatureAngle
->value());
580 smooth
->SetEdgeAngle(ui
.doubleSpinBox_EdgeAngle
->value());
581 smooth
->SetBoundarySmoothing(ui
.checkBox_BoundarySmoothing
->checkState());
582 smooth
->SetGenerateErrorScalars(ui
.checkBox_GenerateErrorScalars
->checkState());
583 smooth
->SetGenerateErrorVectors(ui
.checkBox_GenerateErrorVectors
->checkState());
585 cout_vtkWindowedSincPolyDataFilter(smooth
);
589 if(ui
.checkBox_GenerateErrorScalars
->checkState()) DisplayErrorScalars(smooth
);
590 if(ui
.checkBox_GenerateErrorVectors
->checkState()) DisplayErrorVectors(smooth
);
592 EG_VTKDCN(vtkLongArray_t
, node_index
, pdata
, "node_index");
593 for (vtkIdType i
= 0; i
< smooth
->GetOutput()->GetNumberOfPoints(); ++i
) {
595 smooth
->GetOutput()->GetPoints()->GetPoint(i
, x
.data());
596 vtkIdType nodeId
= node_index
->GetValue(i
);
597 grid
->GetPoints()->SetPoint(nodeId
, x
.data());
601 //////////////////////////////////////////////////////////////////////////////////////////////
602 else if(ui
.SmoothMethod
->currentIndex()==2)//edge subdivision
604 cout_grid(cout
,grid
);
607 getSelectedItems(ui
.listWidget
, bcs
);
609 int N_iter
=ui
.spinBox_NumberOfSubdivisions
->value();
610 for(int i_iter
=0;i_iter
<N_iter
;i_iter
++)
612 cout
<<"i_iter="<<i_iter
<<endl
;
614 QVector
<vtkIdType
> SelectedCells
;
615 getSurfaceCells(bcs
, SelectedCells
, grid
);
616 QVector
<vtkIdType
> AllCells
;
617 getAllSurfaceCells(AllCells
,grid
);
619 createCellToCell(AllCells
, c2c
, grid
);
621 int N_points
=grid
->GetNumberOfPoints();
622 int N_cells
=grid
->GetNumberOfCells();
624 QMap
< pair
<vtkIdType
,vtkIdType
>, vtkIdType
> midpoint_map
;
625 // QMap<double, int> midpoint_map;
626 int N_extmidpoints
=0;
627 int N_intmidpoints
=0;
631 vtkIdType nodeId
= N_points
;
632 foreach(vtkIdType id_cell
, SelectedCells
)
634 vtkIdType type_cell
= grid
->GetCellType(id_cell
);
635 int N_neighbours
=c2c
[id_cell
].size();
636 for(int i
=0;i
<N_neighbours
;i
++)
638 vtkIdType id_neighbour
=c2c
[id_cell
][i
];
645 midpoint_map
[OrderedPair(id_cell
,id_neighbour
)]=nodeId
; nodeId
++;
648 if (type_cell
== VTK_TRIANGLE
)
652 if (type_cell
== VTK_QUAD
)
659 int N_c2cmidpoints
=midpoint_map
.size();
660 N_newpoints
=N_c2cmidpoints
+N_extmidpoints
+N_intmidpoints
;
662 cout
<<"N_c2cmidpoints="<<N_c2cmidpoints
<<endl
;
663 cout
<<"N_extmidpoints="<<N_extmidpoints
<<endl
;
664 cout
<<"N_intmidpoints="<<N_intmidpoints
<<endl
;
665 cout
<<"N_newpoints="<<N_newpoints
<<endl
;
666 cout
<<"N_newcells="<<N_newcells
<<endl
;
667 cout
<<"N_cells="<<N_cells
<<endl
;
668 cout
<<"N_points="<<N_points
<<endl
;
670 EG_VTKSP(vtkUnstructuredGrid
,grid_tmp
);
671 allocateGrid(grid_tmp
,N_cells
+N_newcells
,N_points
+N_newpoints
);
672 makeCopyNoAlloc(grid
, grid_tmp
);
674 EG_VTKDCC(vtkIntArray
, cell_code
, grid_tmp
, "cell_code");
676 midpoint_map
.clear();//clear midpoint_map
677 nodeId
=N_points
;//reset nodeId
679 foreach(vtkIdType id_cell
, SelectedCells
)
681 vtkIdType N_pts
, *pts
;
682 grid
->GetCellPoints(id_cell
, N_pts
, pts
);
683 vtkIdType intmidpoint
;
684 vtkIdType edgemidpoints
[4];
687 vtkIdType type_cell
= grid
->GetCellType(id_cell
);
688 int N_neighbours
=c2c
[id_cell
].size();
690 for(int i
=0;i
<N_neighbours
;i
++)
692 grid
->GetPoints()->GetPoint(pts
[i
], corner
[i
].data());
695 for(int i
=0;i
<N_neighbours
;i
++)
697 vtkIdType id_neighbour
=c2c
[id_cell
][i
];
700 M
[i
]=0.5*(corner
[i
]+corner
[(i
+1)%N_neighbours
]);
701 addPoint(grid_tmp
,nodeId
,M
[i
].data());
702 edgemidpoints
[i
]=nodeId
;
707 if(midpoint_map
.contains(OrderedPair(id_cell
,id_neighbour
)))
710 /* cout<<"pt already exists!: i="<<i<<" midpoint_map[OrderedPair(id_cell,id_neighbour)]="<<midpoint_map[OrderedPair(id_cell,id_neighbour)]<<endl;*/
711 edgemidpoints
[i
]=midpoint_map
[OrderedPair(id_cell
,id_neighbour
)];
715 M
[i
]=0.5*(corner
[i
]+corner
[(i
+1)%N_neighbours
]);
716 addPoint(grid_tmp
,nodeId
,M
[i
].data());
717 midpoint_map
[OrderedPair(id_cell
,id_neighbour
)]=nodeId
;
718 edgemidpoints
[i
]=nodeId
;
723 if (type_cell
== VTK_TRIANGLE
)
725 vtkIdType pts_triangle
[4][3];
726 pts_triangle
[0][0]=pts
[0];//A;
727 pts_triangle
[0][1]=edgemidpoints
[0];
728 pts_triangle
[0][2]=edgemidpoints
[2];
729 pts_triangle
[1][0]=pts
[1];//B;
730 pts_triangle
[1][1]=edgemidpoints
[1];
731 pts_triangle
[1][2]=edgemidpoints
[0];
732 pts_triangle
[2][0]=pts
[2];//C;
733 pts_triangle
[2][1]=edgemidpoints
[2];
734 pts_triangle
[2][2]=edgemidpoints
[1];
735 pts_triangle
[3][0]=edgemidpoints
[0];
736 pts_triangle
[3][1]=edgemidpoints
[1];
737 pts_triangle
[3][2]=edgemidpoints
[2];
740 newCellId
= grid_tmp
->InsertNextCell(VTK_TRIANGLE
,3,pts_triangle
[0]);
741 cell_code
->SetValue(newCellId
, ui
.lineEdit_BoundaryCode
->text().toInt());
742 newCellId
= grid_tmp
->InsertNextCell(VTK_TRIANGLE
,3,pts_triangle
[1]);
743 cell_code
->SetValue(newCellId
, ui
.lineEdit_BoundaryCode
->text().toInt());
744 newCellId
= grid_tmp
->InsertNextCell(VTK_TRIANGLE
,3,pts_triangle
[2]);
745 cell_code
->SetValue(newCellId
, ui
.lineEdit_BoundaryCode
->text().toInt());
746 grid_tmp
->ReplaceCell(id_cell
, 3, pts_triangle
[3]);
747 cell_code
->SetValue(id_cell
, ui
.lineEdit_BoundaryCode
->text().toInt());
749 if (type_cell
== VTK_QUAD
)
751 vec3_t C
=0.25*(corner
[0]+corner
[1]+corner
[2]+corner
[3]);
752 addPoint(grid_tmp
,nodeId
,C
.data());
756 vtkIdType pts_quad
[4][4];
757 pts_quad
[0][0]=pts
[0];
758 pts_quad
[0][1]=edgemidpoints
[0];
759 pts_quad
[0][2]=intmidpoint
;
760 pts_quad
[0][3]=edgemidpoints
[3];
761 pts_quad
[1][0]=pts
[1];
762 pts_quad
[1][1]=edgemidpoints
[1];
763 pts_quad
[1][2]=intmidpoint
;
764 pts_quad
[1][3]=edgemidpoints
[0];
765 pts_quad
[2][0]=pts
[2];
766 pts_quad
[2][1]=edgemidpoints
[2];
767 pts_quad
[2][2]=intmidpoint
;
768 pts_quad
[2][3]=edgemidpoints
[1];
769 pts_quad
[3][0]=pts
[3];
770 pts_quad
[3][1]=edgemidpoints
[3];
771 pts_quad
[3][2]=intmidpoint
;
772 pts_quad
[3][3]=edgemidpoints
[2];
775 newCellId
= grid_tmp
->InsertNextCell(VTK_QUAD
,4,pts_quad
[0]);
776 cell_code
->SetValue(newCellId
, ui
.lineEdit_BoundaryCode
->text().toInt());
777 newCellId
= grid_tmp
->InsertNextCell(VTK_QUAD
,4,pts_quad
[1]);
778 cell_code
->SetValue(newCellId
, ui
.lineEdit_BoundaryCode
->text().toInt());
779 newCellId
= grid_tmp
->InsertNextCell(VTK_QUAD
,4,pts_quad
[2]);
780 cell_code
->SetValue(newCellId
, ui
.lineEdit_BoundaryCode
->text().toInt());
781 grid_tmp
->ReplaceCell(id_cell
, 4, pts_quad
[3]);
782 cell_code
->SetValue(id_cell
, ui
.lineEdit_BoundaryCode
->text().toInt());
786 // cout_grid(cout,grid_tmp,true,true,true,true);
787 cout
<<"Copying..."<<endl
;
788 makeCopy(grid_tmp
,grid
);
789 cout
<<"Copy successful"<<endl
;
791 cout_grid(cout
,grid
);
794 //////////////////////////////////////////////////////////////////////////////////////////////
795 else if(ui
.SmoothMethod
->currentIndex()==3)//swap triangles
797 cout_grid(cout
,grid
);
800 getSelectedItems(ui
.listWidget
, bcs
);
802 QSet
<int> bcs_complement
=complementary_bcs(bcs
,grid
,cells
);
804 cout
<<"bcs="<<bcs
<<endl
;
805 cout
<<"bcs_complement="<<bcs_complement
<<endl
;
809 swap
.setBoundaryCodes(bcs_complement
);
812 cout_grid(cout
,grid
);
815 //////////////////////////////////////////////////////////////////////////////////////////////
816 else if(ui
.SmoothMethod
->currentIndex()==4)//center subdivision
818 cout_grid(cout
,grid
);
821 getSelectedItems(ui
.listWidget
, bcs
);
822 QSet
<int> bcs_complement
=complementary_bcs(bcs
,grid
,cells
);
823 cout
<<"bcs="<<bcs
<<endl
;
824 cout
<<"bcs_complement="<<bcs_complement
<<endl
;
826 int N_iter
=ui
.spinBox_NumberOfSubdivisions
->value();
827 for(int i_iter
=0;i_iter
<N_iter
;i_iter
++)
829 int N_points
=grid
->GetNumberOfPoints();
830 int N_cells
=grid
->GetNumberOfCells();
832 QVector
<vtkIdType
> cells
;
833 getSurfaceCells(bcs
, cells
, grid
);
836 foreach(int id_cell
, cells
)
838 vtkIdType type_cell
= grid
->GetCellType(id_cell
);
839 if (type_cell
== VTK_TRIANGLE
) N_newcells
+=2;
840 if (type_cell
== VTK_QUAD
) N_newcells
+=3;
843 cout
<<"N_newcells="<<N_newcells
<<endl
;
845 EG_VTKSP(vtkUnstructuredGrid
,grid_tmp
);
846 allocateGrid(grid_tmp
,N_cells
+N_newcells
,N_points
+1*N_cells
);
847 makeCopyNoAlloc(grid
, grid_tmp
);
848 EG_VTKDCC(vtkIntArray
, cell_code
, grid_tmp
, "cell_code");
850 vtkIdType nodeId
=N_points
;
851 foreach(int id_cell
, cells
)
853 vtkIdType N_pts
, *pts
;
854 grid
->GetCellPoints(id_cell
, N_pts
, pts
);
857 vtkIdType type_cell
= grid
->GetCellType(id_cell
);
858 int N_neighbours
=N_pts
;
859 if(DebugLevel
>42) cout
<<"N_neighbours="<<N_neighbours
<<endl
;
861 vtkIdType pts_triangle
[4][3];
862 for(int i
=0;i
<N_neighbours
;i
++)
864 grid
->GetPoints()->GetPoint(pts
[i
], corner
[i
].data());
865 C
+=(1/(double)N_neighbours
)*corner
[i
];
867 addPoint(grid_tmp
,nodeId
,C
.data());
868 vtkIdType intmidpoint
=nodeId
;
871 for(int i
=0;i
<N_neighbours
;i
++)
873 pts_triangle
[i
][0]=pts
[i
];
874 pts_triangle
[i
][1]=pts
[(i
+1)%N_neighbours
];
875 pts_triangle
[i
][2]=intmidpoint
;
878 grid_tmp
->ReplaceCell(id_cell
, 3, pts_triangle
[0]);
879 cell_code
->SetValue(id_cell
, ui
.lineEdit_BoundaryCode
->text().toInt());
883 vtkIdType newCellId
= grid_tmp
->InsertNextCell(VTK_TRIANGLE
,3,pts_triangle
[i
]);
884 cell_code
->SetValue(newCellId
, ui
.lineEdit_BoundaryCode
->text().toInt());
889 makeCopy(grid_tmp
,grid
);
891 cout_grid(cout
,grid
,true,true,true,true);
894 //////////////////////////////////////////////////////////////////////////////////////////////
895 else if(ui
.SmoothMethod
->currentIndex()==5)//boundary refinement
897 cout_grid(cout
,grid
);
900 getSelectedItems(ui
.listWidget
, bcs
);
901 QSet
<int> bcs_complement
=complementary_bcs(bcs
,grid
,cells
);
902 cout
<<"bcs="<<bcs
<<endl
;
903 cout
<<"bcs_complement="<<bcs_complement
<<endl
;
905 int N_iter
=ui
.spinBox_NumberOfIterations
->value();
906 for(int i_iter
=0;i_iter
<N_iter
;i_iter
++){
907 int N_points
=grid
->GetNumberOfPoints();
908 int N_cells
=grid
->GetNumberOfCells();
910 QVector
<vtkIdType
> SelectedCells
;
911 getSurfaceCells(bcs
, SelectedCells
, grid
);
912 QVector
<vtkIdType
> AllCells
;
913 getAllSurfaceCells(AllCells
,grid
);
915 EG_VTKDCC(vtkIntArray
, cell_code
, grid
, "cell_code");
917 // QSet <int> cells_to_split;
918 QVector
<stencil_t
> StencilVector
;
920 QMap
<vtkIdType
,bool> marked
;
922 createCellMapping(AllCells
, _cells
, grid
);
923 createCellToCell(AllCells
, c2c
, grid
);
926 cout
<<"AllCells.size()="<<AllCells
.size()<<endl
;
927 cout
<<"SelectedCells.size()="<<SelectedCells
.size()<<endl
;
931 foreach(vtkIdType id_cell
, SelectedCells
)
933 cout
<<"==>id_cell="<<id_cell
<<endl
;
934 int bc0
=cell_code
->GetValue(id_cell
);
937 vtkIdType N_pts
, *pts
;
938 grid
->GetCellPoints(id_cell
, N_pts
, pts
);
940 for(int i
=0;i
<N_pts
;i
++)
942 int bc1
=cell_code
->GetValue(c2c
[id_cell
][i
]);
943 if(bc0
!=bc1
) count
++;
945 if(count
>0)//cell is near at least one neighbour with different cell code
947 int SideToSplit
= getLongestSide(id_cell
,grid
);
948 cout
<<"SideToSplit="<<SideToSplit
<<endl
;
949 cout
<<"c2c[id_cell][SideToSplit]="<<c2c
[id_cell
][SideToSplit
]<<endl
;
950 for(int i
=0;i
<3;i
++) cout
<<"c2c[id_cell]["<<i
<<"]="<<c2c
[id_cell
][i
]<<endl
;
951 stencil_t S
=getStencil(id_cell
,SideToSplit
);
952 if(S
.valid
){//there is a neighbour cell
953 if(!marked
[S
.id_cell2
])
955 /* cells_to_split.insert(S.id_cell1);
956 cells_to_split.insert(S.id_cell2);*/
957 cout
<<"marked["<<S
.id_cell1
<<"]=true;"<<endl
;
958 cout
<<"marked["<<S
.id_cell2
<<"]=true;"<<endl
;
959 marked
[S
.id_cell1
]=true;
960 marked
[S
.id_cell2
]=true;
961 StencilVector
.push_back(S
);
966 else{//there is no neighbour cell
967 // cells_to_split.insert(S.id_cell1);
968 cout
<<"marked["<<S
.id_cell1
<<"]=true;"<<endl
;
969 marked
[S
.id_cell1
]=true;
970 StencilVector
.push_back(S
);
978 /* cout<<"cells_to_split.size()="<<cells_to_split.size()<<endl;
979 cout<<cells_to_split<<endl;*/
980 cout
<<"StencilVector.size()="<<StencilVector
.size()<<endl
;
981 cout
<<"N_newpoints="<<N_newpoints
<<endl
;
982 cout
<<"N_newcells="<<N_newcells
<<endl
;
984 EG_VTKSP(vtkUnstructuredGrid
,grid_tmp
);
985 allocateGrid(grid_tmp
,N_cells
+N_newcells
,N_points
+N_newpoints
);
986 makeCopyNoAlloc(grid
, grid_tmp
);
987 EG_VTKDCC(vtkIntArray
, cell_code_tmp
, grid_tmp
, "cell_code");
989 vtkIdType nodeId
=N_points
;
990 foreach(stencil_t S
,StencilVector
)
993 vtkIdType N_pts
, *pts
;
995 grid_tmp
->GetPoint(S
.p
[1],A
.data());
996 grid_tmp
->GetPoint(S
.p
[3],B
.data());
998 addPoint(grid_tmp
,nodeId
,M
.data());
1000 vtkIdType pts_triangle
[4][3];
1002 if(S
.valid
){//there is a neighbour cell
1003 for(int i
=0;i
<4;i
++)
1005 pts_triangle
[i
][0]=S
.p
[i
];
1006 pts_triangle
[i
][1]=S
.p
[(i
+1)%4];
1007 pts_triangle
[i
][2]=nodeId
;
1010 int bc1
=cell_code_tmp
->GetValue(S
.id_cell1
);
1011 int bc2
=cell_code_tmp
->GetValue(S
.id_cell2
);
1013 grid_tmp
->ReplaceCell(S
.id_cell1
, 3, pts_triangle
[0]);
1014 cell_code_tmp
->SetValue(S
.id_cell1
, bc1
);
1016 grid_tmp
->ReplaceCell(S
.id_cell2
, 3, pts_triangle
[1]);
1017 cell_code_tmp
->SetValue(S
.id_cell2
, bc2
);
1019 vtkIdType newCellId
;
1020 newCellId
= grid_tmp
->InsertNextCell(VTK_TRIANGLE
,3,pts_triangle
[2]);
1021 cell_code_tmp
->SetValue(newCellId
, bc2
);
1022 newCellId
= grid_tmp
->InsertNextCell(VTK_TRIANGLE
,3,pts_triangle
[3]);
1023 cell_code_tmp
->SetValue(newCellId
, bc1
);
1025 else{//there is no neighbour cell
1026 pts_triangle
[0][0]=S
.p
[0];
1027 pts_triangle
[0][1]=S
.p
[1];
1028 pts_triangle
[0][2]=nodeId
;
1029 pts_triangle
[3][0]=S
.p
[3];
1030 pts_triangle
[3][1]=S
.p
[0];
1031 pts_triangle
[3][2]=nodeId
;
1033 int bc1
=cell_code_tmp
->GetValue(S
.id_cell1
);
1035 grid_tmp
->ReplaceCell(S
.id_cell1
, 3, pts_triangle
[0]);
1036 cell_code_tmp
->SetValue(S
.id_cell1
, bc1
);
1038 vtkIdType newCellId
;
1039 newCellId
= grid_tmp
->InsertNextCell(VTK_TRIANGLE
,3,pts_triangle
[3]);
1040 cell_code_tmp
->SetValue(newCellId
, bc1
);
1046 makeCopy(grid_tmp
,grid
);
1047 }//end of i_iter loop
1048 // cout_grid(cout,grid,true,true,true,true);
1051 //////////////////////////////////////////////////////////////////////////////////////////////
1052 else if(ui
.SmoothMethod
->currentIndex()==6)//Laplacian smoothing
1055 getSelectedItems(ui
.listWidget
, bcs
);
1057 LaplaceSmoother Lap
;
1058 Lap
.SetInput(bcs
,grid
);
1059 Lap
.SetNumberOfIterations(ui
.spinBox_NumberOfSmoothIterations
->value());
1060 setDebugLevel(ui
.spinBox_DebugLevel
->value());
1065 cout
<<"===DEFAULT VALUES==="<<endl
;
1066 vtkSmoothPolyDataFilter
* smooth
=vtkSmoothPolyDataFilter::New();
1067 vtkWindowedSincPolyDataFilter
* smooth2
=vtkWindowedSincPolyDataFilter::New();
1068 cout_vtkSmoothPolyDataFilter(smooth
);
1069 cout_vtkWindowedSincPolyDataFilter(smooth2
);
1070 cout
<<"===DEFAULT VALUES==="<<endl
;
1073 //////////////////////////////////////////////////////////////////////////////////////////////
1074 else if(ui
.SmoothMethod
->currentIndex()==7)//VertexAvgDist test
1076 cout_grid(cout
,grid
);
1079 getSelectedItems(ui
.listWidget
, bcs
);
1080 QSet
<int> bcs_complement
=complementary_bcs(bcs
,grid
,cells
);
1081 cout
<<"bcs="<<bcs
<<endl
;
1082 cout
<<"bcs_complement="<<bcs_complement
<<endl
;
1084 int N_points
=grid
->GetNumberOfPoints();
1085 int N_cells
=grid
->GetNumberOfCells();
1087 QVector
<vtkIdType
> SelectedCells
;
1088 getSurfaceCells(bcs
, SelectedCells
, grid
);
1089 QVector
<vtkIdType
> AllCells
;
1090 getAllSurfaceCells(AllCells
,grid
);
1092 QSet
<vtkIdType
> SelectedNodes
;
1093 getSurfaceNodes(bcs
,SelectedNodes
,grid
);
1094 createNodeToNode(cells
, nodes
, _nodes
, n2n
, grid
);
1096 foreach(vtkIdType node
,SelectedNodes
)
1098 cout
<<"node="<<node
<<" VertexAvgDist="<<CurrentVertexAvgDist(node
,n2n
,grid
)<<endl
;
1103 //////////////////////////////////////////////////////////////////////////////////////////////
1104 else if(ui
.SmoothMethod
->currentIndex()==8)//Create mesh density map
1106 cout_grid(cout
,grid
);
1109 getSelectedItems(ui
.listWidget
, bcs
);
1110 QSet
<int> bcs_complement
=complementary_bcs(bcs
,grid
,cells
);
1111 cout
<<"bcs="<<bcs
<<endl
;
1112 cout
<<"bcs_complement="<<bcs_complement
<<endl
;
1114 int N_points
=grid
->GetNumberOfPoints();
1115 int N_cells
=grid
->GetNumberOfCells();
1117 QVector
<vtkIdType
> SelectedCells
;
1118 getSurfaceCells(bcs
, SelectedCells
, grid
);
1119 QVector
<vtkIdType
> AllCells
;
1120 getAllSurfaceCells(AllCells
,grid
);
1122 EG_VTKDCC(vtkIntArray
, cell_code
, grid
, "cell_code");
1123 EG_VTKDCN(vtkDoubleArray
, node_meshdensity
, grid
, "node_meshdensity");
1125 QSet
<vtkIdType
> SelectedNodes
;
1126 getSurfaceNodes(bcs
,SelectedNodes
,grid
);
1127 createNodeToNode(cells
, nodes
, _nodes
, n2n
, grid
);
1129 foreach(vtkIdType node
,SelectedNodes
)
1131 double L
=CurrentVertexAvgDist(node
,n2n
,grid
);
1133 cout
<<"node="<<node
<<" VertexAvgDist="<<L
<<" Net density="<<D
<<endl
;
1134 node_meshdensity
->SetValue(node
, D
);
1137 int N_iter
=ui
.spinBox_maxiter_density
->value();
1138 for(int i_iter
=0;i_iter
<N_iter
;i_iter
++)
1140 foreach(vtkIdType node
,SelectedNodes
)
1142 double D
=DesiredMeshDensity(node
,n2n
,grid
);
1144 cout
<<"node="<<node
<<" VertexAvgDist="<<L
<<" Net density="<<D
<<endl
;
1145 node_meshdensity
->SetValue(node
, D
);
1151 //////////////////////////////////////////////////////////////////////////////////////////////
1152 else if(ui
.SmoothMethod
->currentIndex()==9)//vtkWindowedSincPolyDataFilter smoothing
1155 getSelectedItems(ui
.listWidget
, bcs
);
1156 QVector
<vtkIdType
> cells
;
1157 getSurfaceCells(bcs
, cells
, grid
);
1158 EG_VTKSP(vtkPolyData
, input
);
1159 addToPolyData(cells
, input
, grid
);
1161 EG_VTKSP(vtkSmoothPolyDataFilter
, smooth
);
1162 smooth
->SetInput(input
);
1169 vtkCellArray
*inVerts
, *inLines
, *inPolys
, *inStrips
;
1171 cout
<<"input->GetVerts()="<<input
->GetVerts()<<endl
;
1172 cout
<<"input->GetVerts()->GetSize()="<<input
->GetVerts()->GetSize()<<endl
;
1173 inVerts
=input
->GetVerts();
1174 inVerts
->InitTraversal();
1175 cout
<<"inVerts->GetSize()="<<inVerts
->GetSize()<<endl
;
1176 cout
<<"inVerts->GetNextCell(npts,pts)="<<inVerts
->GetNextCell(npts
,pts
)<<endl
;
1177 cout
<<"inVerts->GetNumberOfCells()="<<inVerts
->GetNumberOfCells()<<endl
;
1179 cout
<<"input->GetVerts()->GetSize()="<<input
->GetVerts()->GetSize()<<endl
;
1180 cout
<<"input->GetVerts()->GetNextCell(npts,pts)="<<input
->GetVerts()->GetNextCell(npts
,pts
)<<endl
;
1181 cout
<<"input->GetVerts()->GetNumberOfCells()="<<input
->GetVerts()->GetNumberOfCells()<<endl
;
1183 // check vertices first. Vertices are never smoothed_--------------
1184 for (inVerts
=input
->GetVerts(), inVerts
->InitTraversal();
1185 inVerts
->GetNextCell(npts
,pts
); )
1187 cout
<<"npts="<<npts
<<endl
;
1188 for (j
=0; j
<npts
; j
++)
1190 cout
<<"pts["<<j
<<"]="<<pts
[j
]<<endl
;
1196 //////////////////////////////////////////////////////////////////////////////////////////////
1197 else if(ui
.SmoothMethod
->currentIndex()==10)// super smoothing
1200 getSelectedItems(ui
.listWidget
, bcs
);
1202 QVector
<VertexMeshDensity
> VMDvector
=GetSet();
1204 CreateSpecialMapping toto
;
1206 toto
.SetInput(bcs
,grid
);
1207 toto
.SetVertexMeshDensityVector(VMDvector
);
1208 toto
.SetConvergence (ui
.doubleSpinBox_Convergence
->value());
1209 toto
.SetNumberOfIterations (ui
.spinBox_NumberOfIterations
->value());
1210 toto
.SetRelaxationFactor (ui
.lineEdit_RelaxationFactor
->text().toDouble());
1211 toto
.SetFeatureEdgeSmoothing (ui
.checkBox_FeatureEdgeSmoothing
->checkState());
1212 toto
.SetFeatureAngle (ui
.doubleSpinBox_FeatureAngle
->value());
1213 toto
.SetEdgeAngle (ui
.doubleSpinBox_EdgeAngle
->value());
1214 toto
.SetBoundarySmoothing (ui
.checkBox_BoundarySmoothing
->checkState());
1215 toto
.SetGenerateErrorScalars (ui
.checkBox_GenerateErrorScalars
->checkState());
1216 toto
.SetGenerateErrorVectors (ui
.checkBox_GenerateErrorVectors
->checkState());
1218 /* toto.Set_SV_value(ui.doubleSpinBox_VTK_SIMPLE_VERTEX->value());
1219 toto.Set_FV_value(ui.doubleSpinBox_VTK_FIXED_VERTEX->value());
1220 toto.Set_FEV_value(ui.doubleSpinBox_VTK_FEATURE_EDGE_VERTEX->value());
1221 toto.Set_BEV_value(ui.doubleSpinBox_VTK_BOUNDARY_EDGE_VERTEX->value());*/
1223 toto
.SetConvergence_meshdensity(ui
.doubleSpinBox_Convergence_meshdensity
->value());
1225 toto
.Set_insert_FP(ui
.checkBox_insert_FP
->checkState());
1226 toto
.Set_insert_EP(ui
.checkBox_insert_EP
->checkState());
1227 toto
.Set_remove_FP(ui
.checkBox_remove_FP
->checkState());
1228 toto
.Set_remove_EP(ui
.checkBox_remove_EP
->checkState());
1229 toto
.DoSwap
=ui
.checkBox_Swap
->checkState();
1230 toto
.DoLaplaceSmoothing
=ui
.checkBox_LaplaceSmoothing
->checkState();
1232 toto
.N_SmoothIterations
=ui
.spinBox_NumberOfSmoothIterations
->value();
1233 toto
.maxiter_density
=ui
.spinBox_maxiter_density
->value();
1234 toto
.setDebugLevel(ui
.spinBox_DebugLevel
->value());
1240 //////////////////////////////////////////////////////////////////////////////////////////////
1241 else if(ui
.SmoothMethod
->currentIndex()==11)// Update current mesh density + node types
1244 getSelectedItems(ui
.listWidget
, bcs
);
1245 CreateSpecialMapping toto
;
1246 toto
.SetInput(bcs
,grid
);
1247 setDebugLevel(ui
.spinBox_DebugLevel
->value());
1249 SetConvergence(ui
.doubleSpinBox_Convergence
->value());
1250 SetFeatureEdgeSmoothing(ui
.checkBox_FeatureEdgeSmoothing
->checkState());
1251 SetFeatureAngle(ui
.doubleSpinBox_FeatureAngle
->value());
1252 SetEdgeAngle(ui
.doubleSpinBox_EdgeAngle
->value());
1253 SetBoundarySmoothing(ui
.checkBox_BoundarySmoothing
->checkState());
1255 UpdateMeshDensity();
1256 UpdateNodeType_all();
1259 //////////////////////////////////////////////////////////////////////////////////////////////
1260 else if(ui
.SmoothMethod
->currentIndex()==12)// Delete all possible points
1263 getSelectedItems(ui
.listWidget
, bcs
);
1264 CreateSpecialMapping toto
;
1266 SetConvergence(ui
.doubleSpinBox_Convergence
->value());
1267 SetFeatureEdgeSmoothing(ui
.checkBox_FeatureEdgeSmoothing
->checkState());
1268 SetFeatureAngle(ui
.doubleSpinBox_FeatureAngle
->value());
1269 SetEdgeAngle(ui
.doubleSpinBox_EdgeAngle
->value());
1270 SetBoundarySmoothing(ui
.checkBox_BoundarySmoothing
->checkState());
1275 vtkIdType N_points
=grid
->GetNumberOfPoints();
1276 vtkIdType N_cells
=grid
->GetNumberOfCells();
1278 bool Global_DelResult
=true;
1279 while(Global_DelResult
)
1281 Global_DelResult
=false;
1282 vtkIdType DeadNode
=0;
1283 while(DeadNode
<grid
->GetNumberOfPoints())
1285 bool Local_DelResult
=true;
1286 while(Local_DelResult
)
1288 Local_DelResult
=DeletePoint_2(grid
,DeadNode
,N_newpoints
,N_newcells
);
1289 if(Local_DelResult
) Global_DelResult
=true;
1296 //////////////////////////////////////////////////////////////////////////////////////////////
1297 else if(ui
.SmoothMethod
->currentIndex()==13)// Delete selected points
1300 getSelectedItems(ui
.listWidget
, bcs
);
1301 CreateSpecialMapping toto
;
1303 setDebugLevel(ui
.spinBox_DebugLevel
->value());
1305 SetConvergence(ui
.doubleSpinBox_Convergence
->value());
1306 SetFeatureEdgeSmoothing(ui
.checkBox_FeatureEdgeSmoothing
->checkState());
1307 SetFeatureAngle(ui
.doubleSpinBox_FeatureAngle
->value());
1308 SetEdgeAngle(ui
.doubleSpinBox_EdgeAngle
->value());
1309 SetBoundarySmoothing(ui
.checkBox_BoundarySmoothing
->checkState());
1314 vtkIdType N_points
=grid
->GetNumberOfPoints();
1315 vtkIdType N_cells
=grid
->GetNumberOfCells();
1317 QVector
<VertexMeshDensity
> VMDvector
=GetSet();
1318 // cout<<"VMDvector="<<VMDvector<<endl;
1319 for(int i
=0;i
<VMDvector
.size();i
++)
1321 cout
<<"VMDvector["<<i
<<"].nodeset="<<VMDvector
[i
].nodeset
<<endl
;
1324 DeleteSetOfPoints(grid
, VMDvector
[i
].nodeset
, N_newpoints
, N_newcells
);
1325 cout
<<"N_newpoints="<<N_newpoints
<<endl
;
1326 cout
<<"N_newcells="<<N_newcells
<<endl
;
1329 /* vector <vtkIdType> nodeId_vector(3);
1334 /* bool Global_DelResult=true;
1335 while(Global_DelResult)
1337 Global_DelResult=false;
1338 vtkIdType DeadNode=0;
1339 while(DeadNode<grid->GetNumberOfPoints())
1341 bool Local_DelResult=true;
1342 while(Local_DelResult)
1344 Local_DelResult=DeletePoint_2(grid,DeadNode,N_newpoints,N_newcells);
1345 if(Local_DelResult) Global_DelResult=true;
1352 //////////////////////////////////////////////////////////////////////////////////////////////
1355 cout
<<"UNKNOWN METHOD"<<endl
;
1357 getSelectedItems(ui
.listWidget
, bcs
);
1358 QVector
<vtkIdType
> cells
;
1359 getSurfaceCells(bcs
, cells
, grid
);
1361 cout
<<"cells="<<cells
<<endl
;
1362 cout
<<"_cells="<<_cells
<<endl
;
1363 cout
<<"nodes="<<nodes
<<endl
;
1364 cout
<<"_nodes="<<_nodes
<<endl
;
1365 /* QVector< QSet< int > > n2c;
1366 QVector< QSet< int > > n2n;
1367 QVector< QVector< int > > c2c;*/
1368 cout
<<"n2c="<<n2c
<<endl
;
1369 cout
<<"n2n="<<n2n
<<endl
;
1370 cout
<<"c2c="<<c2c
<<endl
;