Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleMeshFromImage.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 ExampleMeshFromImage.cpp
26  * @relates TriangleMesh, ThreeDOut
27  @ingroup g_examples
28  @brief Example for generating a trianglemesh from an image
29  @author MIP */
30 
31 #include <Utils/TriangleMesh.hh>
32 #include <Utils/ThreeDOut.hh>
33 #include <Base/Image/ImageIO.hh>
34 #include <Base/Image/ImageConvert.hh>
35 #include <Image/HomographyMapping.hh>
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<<" <depthmap> <texture> [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  ImageBase depthMap;
55  if(ImageIO::Load(argv[1], depthMap)!=0) {
56  cout<<"depth map could not be loaded!\n";
57  usage(argv[0]);
58  return -1;
59  }
60 
61  Image<float> source, enlarged;
62  ImageConvert::ConvertST(depthMap, source, ImageBase::ST_float);
63 
64  //Unhardcode Scale Factor
66  HMatrix H(MatrixIdentity);
67  H[0][0]=H[1][1]=0.5;
68  HMapper.SetHomography(H);
69  enlarged.Init(source.GetWidth()*2,source.GetHeight()*2,1 );
70  HMapper.Map(source, enlarged);
71  Image<unsigned char> texture;
72  if(ImageIO::Load(argv[2], texture)!=0) {
73  cout<<"texture could not be loaded!\n";
74  usage(argv[0]);
75  return -1;
76  }
77 
78  cout<<"meshing..."; cout.flush();
79  TriangleMesh mesh;
80 
81  mesh.GenerateDenseMesh(enlarged, texture);
82  cout<<"finished\n";
83 
84  ThreeDOut vrmlOut;
85  vrmlOut.AddTriangleMesh(mesh, "mesh_from_"+string(argv[1]),
86  argv[2], false);
87 
88  cout<<"Writing VRML to ";
89  if(argc>3) {
90  cout<<argv[3]<<"... ";cout.flush();
91  vrmlOut.VRMLOut(argv[3]);
92  }
93  else {
94  cout<<"DenseTriangleMesh.wrl... ";cout.flush();
95  vrmlOut.VRMLOut("DenseTriangleMesh.wrl");
96  }
97  cout<<"finished\n";
98 
99  return 0;
100 }
unsigned int AddTriangleMesh(const TriangleMesh &mesh, const std::string &name="", const std::string &textureOutputName="", bool writeOutTexture=true, bool calcNormals=false)
Adds triangle mesh as IndexedFaceSet to ThreeDOut mem.
Definition: ThreeDOut.cpp:1104
int GenerateDenseMesh(const BIAS::Image< float > &DenseDepthMap, const BIAS::Image< unsigned char > &Texture)
Calculate a triangle mesh from dense depth map without PMatrix.
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
a 3x3 Matrix describing projective transformations between planes
Definition: HMatrix.hh:39
Maps image src to image sink with homography H (software implementation)
Unified output of 3D entities via OpenGL or VRML.
Definition: ThreeDOut.hh:349
unsigned int GetWidth() const
Definition: ImageBase.hh:312
Create and represent a 3D triangle mesh.
Definition: TriangleMesh.hh:84
unsigned int GetHeight() const
Definition: ImageBase.hh:319
int Map(const Image< InputStorageType > &src, Image< OutputStorageType > &sink, InterpolationMethod=MapTrilinear, bool newSink=false, double SuperSampling=1.0)
backward mapping with various interpolations
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
Definition: Image.cpp:421
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
void SetHomography(const HMatrix &H)
set your homography H (source = H * sink) before calling Map()