54 #include "progmesh.hxx"
60 int mapVertex(::
List<int>& collapse_map,
int a,
int mx)
75 int main(
int argc,
char *argv[])
79 "Surface coarsening using 'bunnylod'"
90 "Input geometry scaling factor"
96 const auto reduction =
args.
get<scalar>(2);
99 if (reduction <= 0 || reduction > 1)
102 <<
"Reduction factor " << reduction
103 <<
" should be within 0..1" <<
endl
104 <<
"(it is the reduction in number of vertices)"
110 Info<<
"Input surface :" << inFileName <<
nl
111 <<
"Scaling factor :" << scaleFactor <<
nl
112 <<
"Reduction factor:" << reduction <<
nl
113 <<
"Output surface :" << outFileName <<
nl
116 const triSurface surf(inFileName, scaleFactor);
119 surf.writeStats(
Info);
130 for (
const point& pt : pts)
132 vert.Add(::
Vector(pt.x(), pt.y(), pt.z()));
147 ::ProgressiveMesh(vert,tri,collapse_map,permutation);
151 for (
int i=0; i<vert.num; i++)
153 temp_list.Add(vert[i]);
155 for (
int i=0; i<vert.num; i++)
157 vert[permutation[i]] = temp_list[i];
161 for (
int i=0; i<tri.num; i++)
163 for (
int j=0; j<3; j++)
165 tri[i].v[j] = permutation[tri[i].v[j]];
170 int render_num = int(reduction * surf.nPoints());
172 Info<<
"Reducing to " << render_num <<
" vertices" <<
endl;
180 for (
int i=0; i<tri.num; i++)
182 int p0 = mapVertex(collapse_map, tri[i].v[0], render_num);
183 int p1 = mapVertex(collapse_map, tri[i].v[1], render_num);
184 int p2 = mapVertex(collapse_map, tri[i].v[2], render_num);
189 if (
p0 == p1 || p1 == p2 || p2 ==
p0)
196 newTris.setSize(newI);
201 for (
int i=0; i<vert.num; i++)
203 const ::Vector & v = vert[i];
205 newPoints[i] =
point(v.x, v.y, v.z);
217 Info<<
"Coarsened surface:" <<
endl;
218 surf2.writeStats(
Info);
221 Info<<
"Writing to file " << outFileName <<
endl <<
endl;
223 surf2.
write(outFileName);