Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleProjectionParametersFactory.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 /**
27  @example ExampleProjectionParametersFactory.cpp
28  @relates ProjectionParametersFactory
29  @brief small example demonstrating the ProjectionParametersFactory
30  @ingroup g_examples
31  @author woelk 12/2006
32 */
33 
34 #include <Geometry/ProjectionParametersFactory.hh>
35 
36 using namespace BIAS;
37 using namespace std;
38 
39 
40 int main(int argc, char *argv[])
41 {
43  if (argc!=2){
44  cerr << "usage: \n"<<argv[0]<<" <projection parameters type>\n"
45  << "\nvalid types are: ... "<<endl;
46  vector<string> names;
47  ppf.GetValidClassNames(names);
48  for (unsigned i=0; i<names.size(); i++){
49  cout << names[i] << endl;
50  }
51  return -1;
52  }
53 
54  ProjectionParametersBase *ppb = ppf.Create(argv[1]);
55  if (!ppb){
56  cerr << "error creating \""<<argv[1]<<"\"\n";
57  return -2;
58  }
59 
60  Vector3<double> C(0,0,0);
61  ppb->SetC(C);
62  Quaternion<double> Q(0,0,0,1);
63  ppb->SetQ(Q);
64 
65  cout << "created projection parameters: "<<*ppb<<endl;
66  ostringstream oss;
67  oss << argv[1]<<".xml";
68 
69 #ifdef BIAS_HAVE_XML2
70  int res = ppb->XMLWrite(oss.str());
71 
72  if (res!=0){
73  cerr << "error writing \""<<oss.str()<<"\"\n";
74  return -3;
75  }
76  cout << "XMLWrite wrote \""<<oss.str()<<"\"\n";
77 
78  ProjectionParametersBase *read = ppf.Load(oss.str());
79  cout << "read projection parameters: "<<*read<<endl;
80 
81 #else
82  cout<<"did not XMLWrite because BIAS_HAVE_XML2 not available."<<endl;
83 #endif
84  return 0;
85 }
ProjectionParametersBase * Create(const std::string &className)
Creates a projection parameters object by a class name.
ProjectionParametersBase * Load(const std::string &fileName)
Loads a projection parameters object from a file.
virtual void SetQ(const BIAS::Quaternion< double > &Q)
Set orientation from unit quaternion Q.
int XMLWrite(const std::string &Filename, int CompressionLevel=0, bool AutoAddCompressionSuffix=true, std::string encoding="UTF-8") const
call this to add the class to a new xml tree and write it to the file Filename.
Definition: XMLBase.cpp:40
void GetValidClassNames(std::vector< std::string > &names) const
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
virtual void SetC(const BIAS::Vector3< double > &C)
Set projection center.