31 #include <Utils/TriangleMesh.hh>
32 #include <Utils/ThreeDOut.hh>
33 #include <Base/Image/ImageIO.hh>
34 #include <Filter/Rescale.hh>
35 #include <Base/Common/FileHandling.hh>
36 #include <Image/Camera.hh>
45 #define TILE_WIDTH 129
46 #define TILE_HEIGHT 129
48 void usage(
char* name)
51 cout<<name<<
" <depthmap> <projection> <texture> [minCornerAngleDEG] [outputFile] [LevelOfDetail]\n";
53 cout<<
"minCornerAngleDEG: discard triangle which contain a smaller angle"
55 cout<<
"LevelOfDetail: 1:vertex for each pixel of full resolution, 2:"
56 <<
" of half resolution"<<endl;
59 int main(
int argc,
char* argv[])
68 if(ImageIO::Load(argv[3], texture)!=0) {
69 cout<<
"texture could not be loaded!\n";
75 if(ImageIO::Load(argv[1], depthMap)!=0) {
76 cout<<
"depth map could not be loaded!\n";
78 if (
string(argv[1])==
string(
"UNITSPHERE")) {
87 if (P.
Load(argv[2])!=0) {
93 cout<<
"Projection could not be loaded from file or meta data!\n";
99 cout<<
"meshing..."; cout.flush();
100 double minCornerAngle = 3.0*M_PI/180.0;
101 double maxViewingAngle = 91.0 * M_PI / 180.0;
103 minCornerAngle = atof(argv[4])*M_PI/180.0;
105 cout<<
"minCornerAngle = "<<minCornerAngle<<endl;
108 double LevelOfDetail = -1.0;
110 LevelOfDetail = atof(argv[6]);
112 if (LevelOfDetail>=0.0) TileMode =
false;
113 else TileMode =
true;
115 cout<<
"Level of detail is "<< LevelOfDetail<<endl;
116 if (fabs(LevelOfDetail)!=1.0) {
120 for (
double curLevel = 1.0;
121 curLevel<fabs(LevelOfDetail); curLevel += 1.0) {
123 DepthSmooth.
SetSigma(sqrt(1.0*1.0 - 0.5*0.5));
129 for (
unsigned int y=0; y<depthMap.
GetHeight(); y++) {
130 for (
unsigned int x=0; x<depthMap.
GetWidth(); x++) {
137 ImageIO::Save(
"depth"+FileHandling::toString(curLevel), depthMap);
142 string vrmlfilename =
"DenseTriangleMesh.wrl";
143 if(argc>5) vrmlfilename = argv[5];
147 mesh.GenerateSimplifiedMesh(depthMap, P, texture, 0, 0,
150 cout<<
"finished\n"<<flush;
154 cout<<
"Writing VRML to "<<vrmlfilename<<flush<<endl;
160 ofstream vrmlfile(vrmlfilename.c_str());
163 unsigned int width, height;
165 unsigned int tileWidth, tileHeight;
166 bool xFinished =
false;
167 bool yFinished =
false;
169 unsigned int xStart, yStart;
170 unsigned int tileNum = 0;
172 int numTiles = (height/(TILE_HEIGHT-1)+1)*(width/(TILE_WIDTH-1)+1);
173 cout<<
"Writing "<< numTiles
176 if(yStart+TILE_HEIGHT >= height) {
178 tileHeight = height-yStart;
180 else tileHeight = TILE_HEIGHT;
182 cout<< double(tileNum)/double(numTiles)*100.0<<
"% "<<flush;
187 ss<<
"mesh_from_"<<string(argv[1])<<
"_t"<<tileNum;
189 if(xStart+TILE_WIDTH >= width) {
191 tileWidth = width -xStart;
194 tileWidth = TILE_WIDTH;
196 if(mesh.GenerateDenseMesh(depthMap, P, texture,
197 xStart, yStart, tileWidth, tileHeight)==0) {
203 xStart+=(tileWidth-1);
205 yStart+=(tileHeight-1);
207 cout<<
" finished."<<endl<<flush;
void Release()
reimplemented from ImageBase
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.
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 ...
virtual int Load(const std::string &filename)
convenience wrapper which tries to read different formats
int Filter7x7GreyIgnoreBelowThreshold(const Image< InputStorageType > &src, Image< OutputStorageType > &dst, const InputStorageType &thresh)
7x7 gauss filtering, values below threshold are ignored useful for depth map filtering ...
Unified output of 3D entities via OpenGL or VRML.
void Rescale(float ratio, unsigned int cam=0)
adapt internal params to resampled image
unsigned int GetWidth() const
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
This class hides the underlying projection model, like projection matrix, spherical camera...
Create and represent a 3D triangle mesh.
unsigned int GetHeight() const
void SetSigma(const double si)
int VRMLOutIndexedFaceSets(std::ostream &VRMLFile)
only write (previously stored) face sets into an open vrml file Will include texture into VRML as Pix...
void FillImageWithConstValue(StorageType Value)
fill grey images
virtual int GetImageSize(unsigned int &Width, unsigned int &Height) const
Obtain image dimensions.
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
void RemoveAll()
removes all entites Essentially a clear on each entityt container.
const BIAS::Projection & GetProj() const
int ParseMetaData(bool bUse2x64bitTS=true)
After ImageIO::Load() operated on AppData_, this method fills P_, Timestamp, DC_*, ...
int VRMLOutWriteHeader(std::ostream &vrml)
write the VRML 2.0 header into an open file
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase