Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleTriangleMeshQuad.cpp

Example for TriangleMesh object, writes a wrl with an image using textured quad ,TriangleMesh

Author
MIP
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/** @example ExampleTriangleMeshQuad.cpp
* @relates ThreeDOut,TriangleMesh
@ingroup g_examples
@brief Example for TriangleMesh object, writes a wrl with an image using textured quad
@author MIP */
#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 <Base/Math/Random.hh>
#include <iostream>
using namespace std;
using namespace BIAS;
//#define TILE_MODE
#define TILE_WIDTH 129
#define TILE_HEIGHT 129
void usage(char* name)
{
cout<<"usage:\n";
cout<<name<<" <depthmap> <texture> [projection] \n";
cout<<endl<<endl;
}
int main(int argc, char* argv[])
{
if(argc<3) {
usage(argv[0]);
return -1;
}
if(ImageIO::Load(argv[2], texture)!=0) {
cout<<"texture could not be loaded!\n";
usage(argv[0]);
return -1;
}
texture.ParseMetaData();
Camera<float> depthMap;
if(ImageIO::Load(argv[1], depthMap)!=0) {
cout<<"depth map could not be loaded!\n";
usage(argv[0]);
if (string(argv[1])==string("UNITSPHERE")) {
depthMap.Init(texture.GetWidth(), texture.GetHeight(), 1);
depthMap.FillImageWithConstValue(1.0f);
}
else return -1;
}
depthMap.ParseMetaData();
bool loaded = false;
if (argc>3) if (P.Load(argv[2])==0) loaded = true;
if (!loaded) {
if (texture.IsProjValid()) {
P = texture.GetProj();
} else if (depthMap.IsProjValid()) {
P = depthMap.GetProj();
} 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;
TriangleMesh mesh(minCornerAngle, maxViewingAngle);
ThreeDOut vrmlOut;
Random R;
double hws = 20;
double hws2 = hws + 2;
for (unsigned int q=0; q<30; q++) {
texture.GetWidth()-hws2),
texture.GetHeight()-hws2));
for (unsigned int i=0; i<4; i++) {
p[i] = p1;
switch (i) {
case 0: p[i][0] -= hws; p[i][1] -= hws; break;
case 1: p[i][0] += hws; p[i][1] -= hws; break;
case 2: p[i][0] -= hws; p[i][1] += hws; break;
case 3: p[i][0] += hws; p[i][1] += hws; break;
}
X[i] =
depthMap.BilinearInterpolation(p[i][0],p[i][1]));
}
PMatrix Pmat = ppp->GetP();
mesh.GenerateTexturedQuad(Pmat, texture, X[0], X[1], X[2], X[3]);
vrmlOut.AddTriangleMesh(mesh,string("myquad"), argv[2], false);
}
string vrmlfilename = "Quad.wrl";
cout<<"Writing VRML to "<<vrmlfilename<<flush<<endl;
vrmlOut.VRMLOut(vrmlfilename);
cout<<"finished\n";
return 0;
}