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

Example for creating a textured 3D plane using BIAS classes ,ThreeDOut

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 Example3DImagePlane.cpp
* @relates TriangleMesh,ThreeDOut
@ingroup g_examples
@brief Example for creating a textured 3D plane using BIAS classes
@author MIP */
#include <Utils/TriangleMesh.hh>
#include <Utils/ThreeDOut.hh>
#include <Base/Image/ImageIO.hh>
#include <Image/Camera.hh>
#include <iostream>
using namespace std;
using namespace BIAS;
void usage(char* name)
{
cout<<"usage:\n";
cout<<name<<" <texture> <projection> [outputFile]\n";
}
int main(int argc, char* argv[])
{
if(argc<2) {
usage(argv[0]);
return -1;
}
if(ImageIO::Load(argv[1], texture)!=0) {
cout<<"texture could not be loaded!\n";
usage(argv[0]);
return -1;
}
texture.ParseMetaData();
if ((argc<3) && texture.IsProjValid()){
P = texture.GetProj();
} else if(P.Load(argv[2])!=0) {
cout<<"Projection could not be loaded!\n";
usage(argv[0]);
return -1;
}
cout<<"meshing..."; cout.flush();
TriangleMesh mesh(0.0,180.0);
//#define QUAD_ONLY
#ifdef QUAD_ONLY
// make one quad in 3d space
mesh.GenerateImagePlane(P, texture);
#else
// make sphere, cylinder, plane,.. (assume depthmap==1)
double downsamplingfactor = 8.0;
mesh.GenerateTexturedCamera(P.GetParameters(),
texture, 1.0, 1.0, downsamplingfactor);
#endif
cout<<"finished\n";
params3d.WCSAxesLength = -1;
ThreeDOut vrmlOut(params3d);
vrmlOut.AddTriangleMesh(mesh, "mesh_from_"+string(argv[1]),
argv[1], true);
cout<<"Writing VRML to ";
if(argc>3) {
cout<<argv[3]<<"... ";cout.flush();
vrmlOut.VRMLOut(argv[3]);
} else {
cout<<"DenseTriangleMesh.wrl... ";cout.flush();
vrmlOut.VRMLOut("DenseTriangleMesh.wrl");
}
cout<<"finished\n";
return 0;
}