Skip to content

Commit 13da51c

Browse files
committed
Implemented the function to calculate the weights
1 parent f910758 commit 13da51c

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

ca_smoothing.cxx

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include <vtkCell.h>
3333

3434
vtkPolyData* read_stl(char*);
35-
vtkDoubleArray* find_staircase_artifacts(vtkPolyData*, const double[3], double);
35+
vtkIdList* find_staircase_artifacts(vtkPolyData*, const double[3], double);
3636
vtkIdList* get_near_vertices_to_v(vtkPolyData*, int, double);
3737
vtkDoubleArray* calc_artifacts_weight(vtkPolyData*, vtkIdList*, double, double);
3838

@@ -42,7 +42,7 @@ int main(int argc, char *argv[])
4242
vtkPolyData *stl, *nm, *cl, *pd;
4343
vtkPolyDataNormals *normals;
4444
vtkCleanPolyData *clean;
45-
vtkDoubleArray *vertices_staircase;
45+
vtkIdList *vertices_staircase;
4646

4747
stl = read_stl(argv[1]);
4848

@@ -58,7 +58,8 @@ int main(int argc, char *argv[])
5858
pd = clean->GetOutput();
5959
pd->BuildLinks();
6060

61-
vertices_staircase = find_staircase_artifacts(pd, stack_orientation, 0.7);
61+
vertices_staircase = find_staircase_artifacts(pd, stack_orientation, atof(argv[2]));
62+
calc_artifacts_weight(pd, vertices_staircase, atof(argv[3]), 1);
6263

6364
vtkXMLPolyDataWriter *writer = vtkXMLPolyDataWriter::New();
6465
writer->SetInput(pd);
@@ -74,7 +75,7 @@ vtkPolyData* read_stl(char* filename) {
7475
return stl_reader->GetOutput();
7576
}
7677

77-
vtkDoubleArray* find_staircase_artifacts(vtkPolyData* pd, const double stack_orientation[3], double T) {
78+
vtkIdList* find_staircase_artifacts(vtkPolyData* pd, const double stack_orientation[3], double T) {
7879
/*
7980
This function is used to find vertices at staircase artifacts, which are
8081
those vertices whose incident faces' orientation differences are
@@ -86,7 +87,7 @@ vtkDoubleArray* find_staircase_artifacts(vtkPolyData* pd, const double stack_ori
8687
double of, min, max;
8788

8889
double *ni;
89-
vtkDoubleArray *output = vtkDoubleArray::New();
90+
vtkIdList *output = vtkIdList::New();
9091
vtkDoubleArray *scalars = vtkDoubleArray::New();
9192
vtkIdList *idfaces;//idfaces = vtk.vtkIdList()
9293

@@ -111,7 +112,7 @@ vtkDoubleArray* find_staircase_artifacts(vtkPolyData* pd, const double stack_ori
111112
// Getting the ones which normals dot is 90°, its vertex is added to
112113
// output
113114
if (max - min >= T) {
114-
output->InsertNextValue(vid);
115+
output->InsertNextId(vid);
115116
scalars->InsertNextValue(1);
116117
}
117118
else {
@@ -189,16 +190,38 @@ vtkDoubleArray* calc_artifacts_weight(vtkPolyData* pd, vtkIdList* vertices_stair
189190
considered to calculate the weight;
190191
bmin=0.1 - The minimun weight.
191192
*/
193+
double vi[3], vj[3], d, value;
194+
int viid, vjid, nnv;
195+
int nid = vertices_staircase->GetNumberOfIds();
196+
vtkIdList* near_vertices;
192197
vtkDoubleArray* weights = vtkDoubleArray::New();
193198
vtkDataArray* scalars = pd->GetPointData()->GetScalars();
194-
double vi[3], vj[3];
195-
int viid, vjid;
196-
int nid = vertices_staircase->GetNumberOfIds();
197-
for(int i=0; i < nid; i++) {
199+
for (int i=0; i < pd->GetNumberOfPoints(); i++){
200+
weights->InsertNextValue(0);
201+
}
202+
for (int i=0; i < nid; i++) {
198203
viid = vertices_staircase->GetId(i);
204+
pd->GetPoint(viid, vi);
205+
near_vertices = get_near_vertices_to_v(pd, viid, tmax);
206+
nnv = near_vertices->GetNumberOfIds();
207+
for (int j=0; j < nnv; j++){
208+
vjid = near_vertices->GetId(j);
209+
pd->GetPoint(vjid, vj);
210+
d = sqrt((vi[0] - vj[0]) * (vi[0] - vj[0])\
211+
+ (vi[1] - vj[1]) * (vi[1] - vj[1])\
212+
+ (vi[2] - vj[2]) * (vi[2] - vj[2]));
213+
value = (1.0 - d/tmax) * (1 - bmin) + bmin;
214+
if (value > weights->GetValue(vjid)) {
215+
printf("%f\n", value);
216+
weights->SetValue(vjid, value);
217+
scalars->SetTuple1(vjid, value);
218+
}
219+
}
199220
}
221+
222+
vtkPointData* pointData = pd->GetPointData();
223+
pointData->SetScalars(scalars);
200224
return weights;
201-
202225
}
203226
/*
204227
def get_near_vertices_to_v(pd, v, dmax):

0 commit comments

Comments
 (0)