Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleVRMLOutProjection.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 /** @example ExampleVRMLOutProjection.cpp
26  * @relates ThreeDOut,Projection
27  @ingroup g_examples
28  @brief Example for VRML output of a BIAS::Projection
29  @author MIP */
30 
31 #include <Utils/ThreeDOut.hh>
32 #include <Geometry/Projection.hh>
33 #include <Base/Image/ImageIO.hh>
34 #include <Base/Image/ImageConvert.hh>
35 #include <iostream>
36 #include <Base/Math/Random.hh>
37 
38 using namespace std;
39 using namespace BIAS;
40 
41 int main(int argc, char* argv[])
42 {
43  if(argc<4) {
44  cout<<"usage:\n";
45  cout<<argv[0]<<" <projectionFile.xml> <ouputFile> [texture]\n";
46  return -1;
47  }
48 
49  int count = atoi(argv[3]);
50  ThreeDOut vrmlWriter;
51 
52  CameraData camData;
53 
54  for(int i = 0; i < count; i++){
55  /**
56  time_t uc;
57 
58  // get the seed (seconds since 1.1.1970 0:00)
59  time(&uc);
60  srand( (unsigned int)(uc) );
61  **/
62 
63  ProjectionParametersBase* ppb = NULL;
64 
65  //SPHERICAL CAMERAS
66 
67  // ProjectionParametersSpherical* pps = new ProjectionParametersSpherical();
68 // pps->SetRadius(camData.radius_);
69 // pps->SetUndistortion(camData.AngleCorrX_, camData.AngleCorrY_,
70 // camData.radius_);
71 // ppb = (ProjectionParametersBase*) pps;
72 
73 
74  //ZOOMED CAMERAS
75  /**
76  ProjectionParametersZoom* ppz = new ProjectionParametersZoom();
77  std::vector<CPDiscreteParam>::iterator it;
78  ppz->Clear();
79  for (unsigned int j=0; j<camData.knownparams_vect_.size(); j++) {
80  ppz->AddZoomStep(camData.knownparams_vect_[j].zoom,
81  camData.knownparams_vect_[j].focallength,
82  camData.knownparams_vect_[j].kc1,
83  camData.knownparams_vect_[j].kc2,
84  camData.knownparams_vect_[j].kc3,
85  camData.knownparams_vect_[j].kc4);
86  }
87  ppb = (ProjectionParametersBase*) ppz;
88  **/
89 
90  //PERSPECTIVE CAMERAS
91  /**
92  ProjectionParametersPerspective* ppp =
93  new ProjectionParametersPerspective();
94  ppp->SetFocalLengthAndAspect( camData.focallengthDef_,
95  camData.aspectratio_);
96  ppp->SetUndistortion(camData.kc1Def_,camData.kc2Def_,
97  camData.kc3Def_,camData.kc4Def_);
98  ppb = (ProjectionParametersBase*) ppp;
99  **/
100 
103  ppp->SetFocalLengthAndAspect( (double)(rand()%1000)/100.0,
104  (double)(rand()%1000)/100.0);
105  ppp->SetUndistortion((double)(rand()%1000)/100.0,
106  (double)(rand()%1000)/100.0,
107  (double)(rand()%1000)/100.0,
108  (double)(rand()%1000)/100.0);
109  ppb = (ProjectionParametersBase*) ppp;
110 
111  ppb->SetImageSize(640, 480);
112  ppb->SetPrincipal((rand()%640), (rand()%480));
113 
114  ppb->SetAspectratio((double)(rand()%100)/10.0);
115 
116  BIAS::Vector3<double> c_mat ((double)(rand()%1000)/100.0,
117  (double)(rand()%1000)/100.0,
118  (double)(rand()%1000)/100.0);
119  ppb->SetC(c_mat);
120  RMatrix R;
122 
123  R.SetXYZ((double)(rand()%1000)/100.0,
124  (double)(rand()%1000)/100.0,
125  (double)(rand()%1000)/100.0);
126  R.GetQuaternion(Q);
127 
128  ppb->SetQ(Q);
129 
130  cout << Q[0] << ", " << Q[1] << ", " << Q[2] << ", " << Q[3] << endl;
131 
132  Projection P(*ppb);
133 
134  /**
135  if(P.XMLRead(argv[1])!=0) {
136  cout<<"could not read projection file!\n";
137  return -1;
138  }
139  **/
140  if(P.GetParameters() == NULL) {
141  cout<<"Fatal error generating projection object!\n";
142  return -1;
143  }
144  BIAS::Random Rand;
145  vrmlWriter.AddProjection(P, RGBAuc(0, 255, 0, 0),
146  1.3,//(double)(rand()%1000)/100.00,
147  (double)(rand()%100)/100.00,
148  "puppy me", (rand()%2));
149 
150  cout << "Projection " << i << " added" << endl;
151  }
152 
153  ThreeDOut vrmlWriter2;
154  //vrmlWriter.AddProjection(P, RGBAuc(0, 255, 0, 0) );
155  //vrmlWriter.AddProjection(P, "funny P");
156 
157  vrmlWriter.VRMLOut(argv[2]);
158 
159  cout<<"finished\n"<<flush;
160 
161  /**
162  if (argc>3) {
163  cout<<"writing textured triangle mesh \n"<<flush;
164  TriangleMesh T;
165  Image<unsigned char> texture, textureRGB;
166  ImageIO::Load(argv[3], texture);
167  ImageConvert::ToRGB(texture, textureRGB);
168  T.GenerateTexturedCamera(P.GetParameters(), textureRGB, T, 1.0);
169  vrmlWriter2.AddTriangleMesh(T);
170  vrmlWriter2.AddPoint(P.GetC());
171  vrmlWriter2.VRMLOut(string("textured-")+string(argv[2]));
172  }
173  **/
174 
175  return 0;
176 }
virtual void SetPrincipal(const double x, const double y)
Set principal point (in pixels relative to top left corner).
void SetXYZ(ROTATION_MATRIX_TYPE PhiX, ROTATION_MATRIX_TYPE PhiY, ROTATION_MATRIX_TYPE PhiZ)
Set Euler angles (in rad) in order XYZ.
int VRMLOut(const std::string &sFilename)
flush all 3d objects to a vrml file with name sFilename, this is the function most users would call ...
Definition: ThreeDOut.cpp:3670
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
class RGBAuc is asynonym for a Vector4 of corerct type
virtual void SetImageSize(const unsigned int w, const unsigned int h)
Set image dimensions (in pixels).
Unified output of 3D entities via OpenGL or VRML.
Definition: ThreeDOut.hh:349
int GetQuaternion(Quaternion< ROTATION_MATRIX_TYPE > &quat) const
Calculates quaternion representation for this rotation matrix.
unsigned int AddProjection(const Projection &p, const RGBAuc &colorSelection=RGBAuc_WHITE_OPAQUE, const double radius=0.1, const double scale=1.0, const std::string &identifier="", const int camera_type=-1)
Add a projection object to ThreeDOut mem.
Definition: ThreeDOut.cpp:1308
3D rotation matrix
Definition: RMatrix.hh:49
virtual void SetQ(const BIAS::Quaternion< double > &Q)
Set orientation from unit quaternion Q.
This class hides the underlying projection model, like projection matrix, spherical camera...
Definition: Projection.hh:70
virtual void SetAspectratio(const double AspectRatio)
Set CCD aspect ratio (i.e.
void SetFocalLengthAndAspect(double f, double AspectRatio)
Set the current camera focal length in pixel and the a spect ratio.
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.
class for producing random numbers from different distributions
Definition: Random.hh:51