Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Example3DImagePlane.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 Example3DImagePlane.cpp
26  * @relates TriangleMesh,ThreeDOut
27  @ingroup g_examples
28  @brief Example for creating a textured 3D plane using BIAS classes
29  @author MIP */
30 
31 #include <Utils/TriangleMesh.hh>
32 #include <Utils/ThreeDOut.hh>
33 #include <Base/Image/ImageIO.hh>
34 #include <Image/Camera.hh>
35 
36 #include <iostream>
37 
38 using namespace std;
39 using namespace BIAS;
40 
41 void usage(char* name)
42 {
43  cout<<"usage:\n";
44  cout<<name<<" <texture> <projection> [outputFile]\n";
45 }
46 
47 int main(int argc, char* argv[])
48 {
49  if(argc<2) {
50  usage(argv[0]);
51  return -1;
52  }
53 
54  Camera<unsigned char> texture;
55  if(ImageIO::Load(argv[1], texture)!=0) {
56  cout<<"texture could not be loaded!\n";
57  usage(argv[0]);
58  return -1;
59  }
60  texture.ParseMetaData();
61  Projection P;
62  if ((argc<3) && texture.IsProjValid()){
63  P = texture.GetProj();
64  } else if(P.Load(argv[2])!=0) {
65  cout<<"Projection could not be loaded!\n";
66  usage(argv[0]);
67  return -1;
68  }
69 
70  cout<<"meshing..."; cout.flush();
71  TriangleMesh mesh(0.0,180.0);
72 
73 //#define QUAD_ONLY
74 #ifdef QUAD_ONLY
75 
76  // make one quad in 3d space
77  mesh.GenerateImagePlane(P, texture);
78 
79 #else
80 
81  // make sphere, cylinder, plane,.. (assume depthmap==1)
82  double downsamplingfactor = 8.0;
83  mesh.GenerateTexturedCamera(P.GetParameters(),
84  texture, 1.0, 1.0, downsamplingfactor);
85 #endif
86 
87 
88  cout<<"finished\n";
89  ThreeDOutParameters params3d;
90  params3d.WCSAxesLength = -1;
91  ThreeDOut vrmlOut(params3d);
92  vrmlOut.AddTriangleMesh(mesh, "mesh_from_"+string(argv[1]),
93  argv[1], true);
94 
95  cout<<"Writing VRML to ";
96  if(argc>3) {
97  cout<<argv[3]<<"... ";cout.flush();
98  vrmlOut.VRMLOut(argv[3]);
99  } else {
100  cout<<"DenseTriangleMesh.wrl... ";cout.flush();
101  vrmlOut.VRMLOut("DenseTriangleMesh.wrl");
102  }
103  cout<<"finished\n";
104 
105  return 0;
106 }
virtual int Load(const std::string &filename)
convenience wrapper which tries to read different formats
Definition: Projection.cpp:62
Unified output of 3D entities via OpenGL or VRML.
Definition: ThreeDOut.hh:349
configuration struct for drawing styles of various 3d objects
Definition: ThreeDOut.hh:309
double WCSAxesLength
&lt;=0 means no visual coordinate axes
Definition: ThreeDOut.hh:321
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
Definition: Projection.hh:194
This class hides the underlying projection model, like projection matrix, spherical camera...
Definition: Projection.hh:70
Create and represent a 3D triangle mesh.
Definition: TriangleMesh.hh:84
bool IsProjValid() const
Definition: Camera.hh:221
const BIAS::Projection & GetProj() const
Definition: Camera.hh:109
int ParseMetaData(bool bUse2x64bitTS=true)
After ImageIO::Load() operated on AppData_, this method fills P_, Timestamp, DC_*, ...
Definition: Camera.cpp:154