#include <iostream>
#include <fstream>
int main(int argc, char *argv[])
{
bool plot = false;
bool toxml = false;
bool noSmooth = false;
bool writePatchNumbers = false;
std::string filename = "off/mushroom_triangulated.off";
real_t cutoffAngle = 40.0;
real_t innerAngle = 15.0;
real_t patchAreaWeight = 0.2;
real_t mergeSmallPatches = 2;
gsCmdLine cmd(
"Recover the features of a triangulated surface.");
cmd.addPlainString("filename", "File containing the input mesh", filename);
cmd.addSwitch("plot", "Output mesh in ParaView format", plot);
cmd.addSwitch("xml", "Output solid to xml file", toxml);
cmd.addSwitch("nosmooth", "Do not smooth corners of faces", noSmooth);
cmd.addSwitch("writenums", "Write patch numbers to patchnumbers.txt", writePatchNumbers);
cmd.addInt("f", "interiorweight","Surface fitting: weight for interior points.",
wInterior);
cmd.addInt("e", "edgeweight","Surface fitting: weight for edges.",
wEdge);
cmd.addInt("i", "interior","Interior knot points of each dimension of trimmed surface.",
interiorPts);
cmd.addInt("d", "degree","Degree of each dimension of trimmed surface.",
degree);
cmd.addReal("p", "paw","Patch area weight.", patchAreaWeight);
cmd.addReal("m", "msp","Merge small patches.", mergeSmallPatches);
cmd.addReal("y", "innerangle","Cutoff angle (degrees) for second pass.",
innerAngle);
cmd.addReal("c", "cutoff","Cutoff angle (degrees).", cutoffAngle);
try { cmd.getValues(argc,argv); } catch (int rv) { return rv; }
if ( filename.empty() )
{
gsInfo <<
"Could not find file.\n";
return EXIT_SUCCESS;
}
size_t nameStartIdx = filename.rfind('/');
if ( nameStartIdx == std::string::npos)
nameStartIdx = 0;
else
nameStartIdx+= 1;
size_t nameEndIdx = filename.rfind('.');
std::string baseName = filename.substr(nameStartIdx, nameEndIdx - nameStartIdx);
gsInfo <<
"--- Settings ---\n";
gsInfo <<
"Processing " << baseName <<
"\n";
gsInfo <<
"Cutoff angle is " << cutoffAngle <<
"\n";
gsInfo <<
"Master surfaces have degree " << degree <<
" and " << interiorPts <<
" interior knot points.\n";
gsInfo <<
"Surface fit: edge weighting is " << wEdge <<
" and interior point weighting is " << wInterior <<
".\n";
if(noSmooth)
gsInfo <<
"Will NOT smooth corners of faces\n";
else gsInfo <<
"WILL smooth corners of faces\n";
if(plot)
gsInfo <<
"WILL create paraview plot\n";
else gsInfo <<
"Will NOT create paraview plot\n";
gsInfo <<
"----------------\n";
if (m)
else
{
gsInfo<<
"Problem encountered in file "<<filename<<
", quitting." <<
"\n";
return EXIT_SUCCESS;
}
std::vector< gsMesh<> * > paraMeshes;
std::vector< gsMesh<> * > fitMeshes;
std::vector< gsMesh<> * > patchMeshes;
std::vector< std::vector< gsVertex<>* > > iPoints;
std::vector< std::vector< gsVertex<>* > > oPoints;
std::vector< std::vector< std::vector<gsVertex<>* > > > innerBdrys;
std::vector< std::vector< gsVertex<> > > innerBdrysMassP;
std::vector< std::vector< bool > > oPointsConvexFlag;
bool non_manifold, warning_borders;
tmts.getFeatures(cutoffAngle, non_manifold, warning_borders);
m->cleanMesh();
tmts.calcPatchNumbers();
tmts.storeNeighboringFaces();
tmts.divideAndMergePatches(innerAngle, patchAreaWeight, mergeSmallPatches);
tmts.calcPatchNumbers();
if(writePatchNumbers)
{
gsInfo <<
"Writing patch numbers...\n";
std::ofstream pn("patchnumbers.txt");
for(std::vector<gsMeshElement<>::gsFaceHandle >::const_iterator it(m->faces().begin());it!=m->faces().end();++it)
{
pn << (**it).faceIdentity << "\n";
}
}
tmts.getFaces(iPoints, oPoints, innerBdrys, innerBdrysMassP, oPointsConvexFlag);
tmts.toSolid(sl,iPoints,oPoints,innerBdrys,innerBdrysMassP,oPointsConvexFlag,paraMeshes,fitMeshes,patchMeshes,degree,interiorPts,true,300,true,wEdge,wInterior,1,noSmooth);
if (toxml)
{
gsInfo <<
"Writing xml file..." <<
"\n";
newdata << sl;
std::string outputFilename;
outputFilename = "corner_data.txt";
std::ofstream myfile (outputFilename.c_str());
if (myfile.is_open())
{
myfile << oPoints.size()<<"\n";
for(size_t i=0;i<oPoints.size();i++)
{
myfile << oPoints[i].size()<<" ";
for(size_t j=0;j<oPoints[i].size();j++)
myfile<<(oPoints[i][j]->numEdges>2)<<" ";
myfile << "\n";
}
myfile << "\n";
for(size_t i=0;i<innerBdrys.size();i++)
{
myfile << innerBdrys[i].size()<<" ";
for(size_t j=0;j<innerBdrys[i].size();j++)
{
myfile << innerBdrys[i][j].size()<<" ";
for(size_t k=0;k<innerBdrys[i][j].size();k++)
myfile<<(innerBdrys[i][j][k]->numEdges>2)<<" ";
}
myfile << "\n";
}
myfile.close();
}
}
if (plot)
{
gsInfo<<
"Writing paraview file..." <<
"\n";
gsWriteParaview( *m, "output");
}
else
{
gsInfo <<
"Done. No output created, re-run with --plot to get a ParaView "
"file containing the solution.\n";
}
return EXIT_SUCCESS;
}
Class for command-line argument parsing.
Definition gsCmdLine.h:57
This class represents an XML data tree which can be read from or written to a (file) stream.
Definition gsFileData.h:34
void dump(String const &fname="dump") const
Dump file contents to an xml file.
Definition gsFileData.hpp:86
static std::string find(std::string fn)
Find a file.
Definition gsFileManager.cpp:283
Reads an object from a data file, if such the requested object exists in the file.
Definition gsReadFile.h:43
Class for representing a solid made up of vertices, edges, faces, and volumes.
Definition gsSolid.h:33
Class gsTriMeshToSolid object.
Definition gsTriMeshToSolid.h:32
Main header to be included by clients using the G+Smo library.
#define index_t
Definition gsConfig.h:32
#define gsInfo
Definition gsDebug.h:43
The G+Smo namespace, containing all definitions for the library.
void freeAll(It begin, It end)
Frees all pointers in the range [begin end)
Definition gsMemory.h:312