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

Example 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 ExampleProjection.cpp
@relates Projection
@brief Example Projection
@ingroup g_examples
@author MIP
*/
#include <Geometry/Projection.hh>
#include <Geometry/ProjectionParametersSpherical.hh>
#include <iostream>
using namespace BIAS;
using namespace std;
int main (int argc, char* argv[])
{
Projection proj1, proj2;
#ifdef BIAS_HAVE_XML2
if (argc<2) {
cout <<"no file given, terminating!"<<endl;
exit(0);
}
else {
if (proj1.XMLRead(argv[1])<0) {
if (proj1.ReadFromCamParamFile(argv[1])<0) {
cout << "Error reading file:" << argv[1] << endl;
exit(0);
}
}
cout << "Read file:" << argv[1] << endl;
}
cout <<"Projection is: "<<proj1<<endl;
dynamic_cast<ProjectionParametersSpherical *> (proj1.GetParameters());
if (pps!=NULL) {
KMatrix K1, K2, K3;
double imgsize1,imgsize2, imgsize3;
K1 = pps->GetFakeKMatrix(imgsize1,0);
K2 = pps->GetFakeKMatrix(imgsize2,1);
K3 = pps->GetFakeKMatrix(imgsize3,2);
cout << "KMatNormal:" << imgsize1 << "x" << imgsize1 << K1 << endl;
cout << "KMatBig:" << imgsize2 << "x" << imgsize1 << K2 << endl;
cout << "KMatSmall:" << imgsize3 << "x" << imgsize1 << K3 << endl;
for (int i=0; i<6; i++) {
Vector3<double> rpt(1.0,
-M_PI*double(i)*M_PI/3.0,
i*pps->GetMaxCamAngle()/6);
cout << "Creating perspective cutout " << i << " with center:"
<< pps->ProjectLocal(rpt.CoordSphereToEuclidean()) << endl;
pps->GetPerspectiveCutOutParameters(pps->ProjectLocal(rpt.CoordSphereToEuclidean()), 25, pp);
Projection p(pp);
stringstream ss;
ss << "PerspectiveCutOut" << i << ".xml";
p.XMLWrite(ss.str().c_str());
cout << "wrote " << ss.str().c_str() << endl;
}
}
string flat;
proj1.XMLWriteToString(flat);
cout <<"My Projection flat as string: "<<flat<<endl;
proj1.XMLReadFromString(flat);
proj1.XMLWrite("PassedThroughString.xml");
cout <<"Externals: "<<proj1.GetParameters()->GetExternals()<<endl;
p3d[0] = 10.0; p3d[1] = 11.0; p3d[2] = -10.0; p3d[3] = 1.0;
p2d = proj1.Project(p3d);
cout <<p3d<<" -> "<<p2d<<endl;
proj1.XMLWrite("CamDataTest.xml");
cout <<"CamDataTest.xml created" << endl;
proj2.XMLRead("CamDataTest.xml");
proj2.XMLWrite("CamDataTestRewrite.xml");
cout <<"CamDataTestRewrite.xml created" << endl;
#endif
return 0;
}