54#include "progmesh.hxx"
60int mapVertex(::List<int>& collapse_map,
int a,
int mx)
75int main(
int argc,
char *argv[])
79 "Surface coarsening using 'bunnylod'"
82 argList::noParallel();
83 argList::addArgument(
"input",
"The input surface file");
84 argList::addArgument(
"factor",
"The reduction factor [0,1)");
85 argList::addArgument(
"output",
"The output surface file");
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);
122 ::List<::Vector> vert;
123 ::List<::tridata> tri;
130 for (
const point& pt : pts)
132 vert.Add(::Vector(pt.x(), pt.y(), pt.z()));
144 ::List<int> collapse_map;
145 ::List<int> permutation;
147 ::ProgressiveMesh(vert,tri,collapse_map,permutation);
150 ::List<::Vector> temp_list;
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);
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Extract command arguments and options from the supplied argc and argv parameters.
T get(const label index) const
Get a value from the argument at index.
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
A class for handling file names.
A triFace with additional (region) index.
Triangulated surface description with patch information.
const volScalarField & p0
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a)
Foam::argList args(argc, argv)