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

Example for VRML output of a BIAS::Projection ,Projection

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 ExampleVRMLOutProjection.cpp
* @relates ThreeDOut,Projection
@ingroup g_examples
@brief Example for VRML output of a BIAS::Projection
@author MIP */
#include <Utils/ThreeDOut.hh>
#include <Geometry/Projection.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/Image/ImageConvert.hh>
#include <iostream>
#include <Base/Math/Random.hh>
using namespace std;
using namespace BIAS;
int main(int argc, char* argv[])
{
if(argc<4) {
cout<<"usage:\n";
cout<<argv[0]<<" <projectionFile.xml> <ouputFile> [texture]\n";
return -1;
}
int count = atoi(argv[3]);
ThreeDOut vrmlWriter;
CameraData camData;
for(int i = 0; i < count; i++){
/**
time_t uc;
// get the seed (seconds since 1.1.1970 0:00)
time(&uc);
srand( (unsigned int)(uc) );
**/
//SPHERICAL CAMERAS
// ProjectionParametersSpherical* pps = new ProjectionParametersSpherical();
// pps->SetRadius(camData.radius_);
// pps->SetUndistortion(camData.AngleCorrX_, camData.AngleCorrY_,
// camData.radius_);
// ppb = (ProjectionParametersBase*) pps;
//ZOOMED CAMERAS
/**
ProjectionParametersZoom* ppz = new ProjectionParametersZoom();
std::vector<CPDiscreteParam>::iterator it;
ppz->Clear();
for (unsigned int j=0; j<camData.knownparams_vect_.size(); j++) {
ppz->AddZoomStep(camData.knownparams_vect_[j].zoom,
camData.knownparams_vect_[j].focallength,
camData.knownparams_vect_[j].kc1,
camData.knownparams_vect_[j].kc2,
camData.knownparams_vect_[j].kc3,
camData.knownparams_vect_[j].kc4);
}
ppb = (ProjectionParametersBase*) ppz;
**/
//PERSPECTIVE CAMERAS
/**
ProjectionParametersPerspective* ppp =
new ProjectionParametersPerspective();
ppp->SetFocalLengthAndAspect( camData.focallengthDef_,
camData.aspectratio_);
ppp->SetUndistortion(camData.kc1Def_,camData.kc2Def_,
camData.kc3Def_,camData.kc4Def_);
ppb = (ProjectionParametersBase*) ppp;
**/
ppp->SetFocalLengthAndAspect( (double)(rand()%1000)/100.0,
(double)(rand()%1000)/100.0);
ppp->SetUndistortion((double)(rand()%1000)/100.0,
(double)(rand()%1000)/100.0,
(double)(rand()%1000)/100.0,
(double)(rand()%1000)/100.0);
ppb->SetImageSize(640, 480);
ppb->SetPrincipal((rand()%640), (rand()%480));
ppb->SetAspectratio((double)(rand()%100)/10.0);
BIAS::Vector3<double> c_mat ((double)(rand()%1000)/100.0,
(double)(rand()%1000)/100.0,
(double)(rand()%1000)/100.0);
ppb->SetC(c_mat);
R.SetXYZ((double)(rand()%1000)/100.0,
(double)(rand()%1000)/100.0,
(double)(rand()%1000)/100.0);
ppb->SetQ(Q);
cout << Q[0] << ", " << Q[1] << ", " << Q[2] << ", " << Q[3] << endl;
Projection P(*ppb);
/**
if(P.XMLRead(argv[1])!=0) {
cout<<"could not read projection file!\n";
return -1;
}
**/
if(P.GetParameters() == NULL) {
cout<<"Fatal error generating projection object!\n";
return -1;
}
vrmlWriter.AddProjection(P, RGBAuc(0, 255, 0, 0),
1.3,//(double)(rand()%1000)/100.00,
(double)(rand()%100)/100.00,
"puppy me", (rand()%2));
cout << "Projection " << i << " added" << endl;
}
ThreeDOut vrmlWriter2;
//vrmlWriter.AddProjection(P, RGBAuc(0, 255, 0, 0) );
//vrmlWriter.AddProjection(P, "funny P");
vrmlWriter.VRMLOut(argv[2]);
cout<<"finished\n"<<flush;
/**
if (argc>3) {
cout<<"writing textured triangle mesh \n"<<flush;
TriangleMesh T;
Image<unsigned char> texture, textureRGB;
ImageIO::Load(argv[3], texture);
ImageConvert::ToRGB(texture, textureRGB);
T.GenerateTexturedCamera(P.GetParameters(), textureRGB, T, 1.0);
vrmlWriter2.AddTriangleMesh(T);
vrmlWriter2.AddPoint(P.GetC());
vrmlWriter2.VRMLOut(string("textured-")+string(argv[2]));
}
**/
return 0;
}