Example for TriangleMesh object, writes a wrl with an image using level of detail ,TriangleMesh
#include <Utils/TriangleMesh.hh>
#include <Utils/ThreeDOut.hh>
#include <Base/Image/ImageIO.hh>
#include <Filter/Rescale.hh>
#include <Base/Common/FileHandling.hh>
#include <Image/Camera.hh>
#include <sstream>
#include <iostream>
using namespace std;
using namespace BIAS;
#define TILE_WIDTH 129
#define TILE_HEIGHT 129
void usage(char* name)
{
cout<<"usage:\n";
cout<<name<<" <depthmap> <projection> <texture> [minCornerAngleDEG] [outputFile] [LevelOfDetail]\n";
cout<<endl<<endl;
cout<<"minCornerAngleDEG: discard triangle which contain a smaller angle"
<<endl;
cout<<"LevelOfDetail: 1:vertex for each pixel of full resolution, 2:"
<<" of half resolution"<<endl;
}
int main(int argc, char* argv[])
{
bool TileMode = true;
if(argc<3) {
usage(argv[0]);
return -1;
}
if(ImageIO::Load(argv[3], texture)!=0) {
cout<<"texture could not be loaded!\n";
usage(argv[0]);
return -1;
}
if(ImageIO::Load(argv[1], depthMap)!=0) {
cout<<"depth map could not be loaded!\n";
usage(argv[0]);
if (string(argv[1])==string("UNITSPHERE")) {
}
else return -1;
}
if (P.
Load(argv[2])!=0) {
} else {
cout<<"Projection could not be loaded from file or meta data!\n";
usage(argv[0]);
return -1;
}
}
cout<<"meshing..."; cout.flush();
double minCornerAngle = 3.0*M_PI/180.0;
double maxViewingAngle = 91.0 * M_PI / 180.0;
if(argc>4) {
minCornerAngle = atof(argv[4])*M_PI/180.0;
}
cout<<"minCornerAngle = "<<minCornerAngle<<endl;
double LevelOfDetail = -1.0;
if(argc>6) {
LevelOfDetail = atof(argv[6]);
}
if (LevelOfDetail>=0.0) TileMode = false;
else TileMode = true;
cout<<"Level of detail is "<< LevelOfDetail<<endl;
if (fabs(LevelOfDetail)!=1.0) {
for (double curLevel = 1.0;
curLevel<fabs(LevelOfDetail); curLevel += 1.0) {
DepthSmooth.
SetSigma(sqrt(1.0*1.0 - 0.5*0.5));
0.0f);
for (
unsigned int y=0; y<depthMap.
GetHeight(); y++) {
for (
unsigned int x=0; x<depthMap.
GetWidth(); x++) {
}
}
ImageIO::Save("depth"+FileHandling::toString(curLevel), depthMap);
}
}
string vrmlfilename = "DenseTriangleMesh.wrl";
if(argc>5) vrmlfilename = argv[5];
if (!TileMode) {
mesh.GenerateSimplifiedMesh(depthMap, P, texture, 0, 0,
cout<<"finished\n"<<flush;
argv[3], true);
cout<<"Writing VRML to "<<vrmlfilename<<flush<<endl;
cout<<"finished\n";
} else {
ofstream vrmlfile(vrmlfilename.c_str());
unsigned int width, height;
unsigned int tileWidth, tileHeight;
bool xFinished = false;
bool yFinished = false;
unsigned int xStart, yStart;
unsigned int tileNum = 0;
yStart = 0;
int numTiles = (height/(TILE_HEIGHT-1)+1)*(width/(TILE_WIDTH-1)+1);
cout<<"Writing "<< numTiles
<<" tiles: "<<flush;
while(!yFinished) {
if(yStart+TILE_HEIGHT >= height) {
yFinished = true;
tileHeight = height-yStart;
}
else tileHeight = TILE_HEIGHT;
cout<< double(tileNum)/double(numTiles)*100.0<<"% "<<flush;
xFinished = false;
xStart = 0;
while(!xFinished) {
stringstream ss;
ss<<"mesh_from_"<<string(argv[1])<<"_t"<<tileNum;
tileNum++;
if(xStart+TILE_WIDTH >= width) {
xFinished = true;
tileWidth = width -xStart;
}
else
tileWidth = TILE_WIDTH;
if(mesh.GenerateDenseMesh(depthMap, P, texture,
xStart, yStart, tileWidth, tileHeight)==0) {
argv[3], false);
}
xStart+=(tileWidth-1);
}
yStart+=(tileHeight-1);
}
cout<< " finished."<<endl<<flush;
}
return 0;
}