26 #include <Utils/ThreeDOut.hh>
27 #ifdef BIAS_HAVE_OPENSCENEGRAPH
28 #include <GLviewer/ThreeDOutOpenSceneGraph.hh>
30 #include <Utils/TriangleMesh.hh>
31 #include <Base/Image/ImageIO.hh>
32 #include <Base/Image/ImageConvert.hh>
33 #include <Filter/Rescale.hh>
34 #include <Base/Common/FileHandling.hh>
35 #include <Image/Camera.hh>
36 #include <Utils/Param.hh>
44 #define TILE_WIDTH 129
45 #define TILE_HEIGHT 129
86 int main(
int argc,
char *argv[])
112 "if not specified -> triangle mesh will be untextured",
118 "specify projection, "
119 "if not specified -> trying to parse meta data from (1.)texture or (2.)depth map",
125 params.
SetGroupName(inputParamGroupID,
"input parameters");
131 "reduce the triangles in the generated mesh to X percent of the original mesh ",
144 double* MinCornerAngleDEG = params.
AddParamDouble(
"MinCornerAngleDEG",
145 "discard triangles containing a smaller angle (in degree), "
151 double* MaxAngleDEG =
153 "maximum angle between normal and viewray in degree, "
154 "0 means frontal view, default is: 91.0 (disabled)",
160 "set level of detail, "
161 "1: vertex for each pixel of full resolution, "
162 "2: of half resolution",
168 params.
SetGroupName(configParamGroupID,
"configuration parameters");
175 "write results into this file",
176 "DenseTriangleMesh.wrl",
179 #ifdef BIAS_HAVE_OPENSCENEGRAPH
180 string* osgOutFile = params.
AddParamString(
"ostOutFile",
"write results in osg file",
"DenseMesh.osg",
'O', outputGroupID);
196 cout <<
"==> Too few arguments."<<endl;
203 if (
string(*inputTexture) ==
"") {
204 cout<<
"no texture specified, drawing untextured triangle mesh!"<<endl;
206 if(ImageIO::Load(*inputTexture, texture)!=0) {
207 if(ImageIO::Load(*inputTexture, texFloat)==0){
212 ImageConvert::ConvertST(texFloat, texture, ImageBase::ST_unsignedchar);
214 cout<<
"texture could not be loaded!\n";
222 if(ImageIO::Load(*inputDepthMap, depthMap)!=0) {
223 cout<<
"depth map could not be loaded!\n";
225 if (
string(*inputDepthMap)==
string(
"UNITSPHERE")) {
237 if (
string(*inputProjection) ==
"") {
238 cout<<
"no projection specified, trying to parse from meta data..."<<endl;
240 pLoad = Ptmp.
Load(*inputProjection);
249 cout<<
"Projection could not be loaded from file or meta data!\n";
258 int widthDepth = depthMap.
GetWidth();
260 unsigned int widthP, heightP;
262 if(widthTex != (
int)widthP || heightTex != (
int)heightP){
267 unsigned int widthTmp, heightTmp;
269 cout <<
"rescaling texP tex size " << widthTex <<
" " << heightTex <<
" P size "
270 << widthP <<
" " << heightP <<
" new P " << widthTmp <<
" " << heightTmp << endl;
272 cout <<
"P size still the same? " << widthTmp <<
" " << heightTmp << endl;
276 unsigned int widthTmp, heightTmp;
278 cout <<
"keeping size of texP " << widthTmp <<
" " << heightTmp << endl;
281 if(widthDepth != (
int)widthP || heightDepth != (
int)heightP){
287 unsigned int widthTmp, heightTmp;
289 cout <<
"rescaling depth P depth size " << widthDepth <<
" " << heightDepth <<
" P size "
290 << widthP <<
" " << heightP <<
" new P " << widthTmp <<
" " << heightTmp << endl;
294 unsigned int widthTmp, heightTmp;
296 cout <<
"keeping size of depthP " << widthTmp <<
" " << heightTmp << endl;
299 cout<<
"meshing..."<<flush<<endl;
300 double minCornerAngle = (*MinCornerAngleDEG)*M_PI/180.0;
301 double maxViewingAngle = (*MaxAngleDEG)*M_PI/180.0;
304 cout<<
"minCornerAngle = "<<minCornerAngle<<endl;
305 cout<<
"maxViewingAngle = "<<maxViewingAngle<<endl;
309 cout<<
"Level of detail is "<< *LevelOfDetail<<endl;
310 if (!(*LevelOfDetail == 1.0)) {
314 for (
double curLevel = 1.0;
315 curLevel < *LevelOfDetail; curLevel += 1.0) {
317 DepthSmooth.
SetSigma(sqrt(1.0*1.0 - 0.5*0.5));
323 for (
unsigned int y=0; y<depthMap.
GetHeight(); y++) {
324 for (
unsigned int x=0; x<depthMap.
GetWidth(); x++) {
331 ImageIO::Save(
"depth"+FileHandling::toString(curLevel), depthMap);
336 string vrmlfilename = *Outfile;
337 cout<<
"vrml file name is now "<<vrmlfilename<<endl;
338 #ifdef BIAS_HAVE_OPENSCENEGRAPH
345 cout<<
"Tile Mode is set to "<<*TileMode<<endl;
350 ofstream vrmlfile(vrmlfilename.c_str());
353 unsigned int width, height;
355 unsigned int tileWidth, tileHeight;
356 bool xFinished =
false;
357 bool yFinished =
false;
359 unsigned int xStart, yStart;
360 unsigned int tileNum = 0;
362 int numTiles = (height/(TILE_HEIGHT-1)+1)*(width/(TILE_WIDTH-1)+1);
363 cout<<
"Writing "<< numTiles
365 cout <<
"inputReduce " << *LevelOfDetail <<endl;
374 if(yStart+TILE_HEIGHT >= height) {
376 tileHeight = height-yStart;
378 tileHeight = TILE_HEIGHT;
381 cout<< double(tileNum)/double(numTiles)*100.0<<
"% "<<flush;
386 ss<<
"mesh_from_"<<string(*inputDepthMap)<<
"_t"<<tileNum;
388 if(xStart+TILE_WIDTH >= width) {
390 tileWidth = width -xStart;
393 tileWidth = TILE_WIDTH;
395 int res = mesh.GenerateDenseMesh(depthMap, P, texture, texP,
396 xStart, yStart, tileWidth, tileHeight);
399 *inputTexture,
false);
403 xStart+=(tileWidth-1);
405 yStart+=(tileHeight-1);
408 cout<<
" finished."<<endl<<flush;
412 if(*inputReduce != 0.0){
413 mesh.GenerateDenseMesh(depthMap,P,texture,texP,
true,*inputReduce);
416 mesh.GenerateSimplifiedMesh(depthMap, P, texture, texP, 0, 0,
420 cout<<
"finished\n"<<flush;
423 string texturefilename = *Outfile;
424 int dotIndex = texturefilename.find_last_of(
".");
425 texturefilename.replace(dotIndex+1, 3,
"png");
427 cout<<
"Writing Texture to "<<texturefilename<<flush<<endl;
429 texturefilename,
true);
435 cout<<
"Writing VRML to "<<vrmlfilename<<flush<<endl;
437 #ifdef BIAS_HAVE_OPENSCENEGRAPH
438 cout <<
"Writing osg file to " << *osgOutFile << endl;
439 vrmlOut.OpenSceneGraphOut(*osgOutFile);
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.
StorageType GetMaxPixelValue(unsigned short int channel=0, unsigned int *coo=NULL) const
Get the maximal pixel value if coo!=NULL the coo[0]=x of max and coo[1]=y of max. ...
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 ...
virtual void Rescale(double ratio, const double offset=0.0)
Adapt internal parameters to resampled image.
Unified output of 3D entities via OpenGL or VRML.
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
double * AddParamDouble(const std::string &name, const std::string &help, double deflt=0.0, double min=-DBL_MAX, double max=DBL_MAX, char cmdshort=0, int Group=GRP_NOSHOW)
int ScaleShift(double Scale, double Shift)
scales and shifts image (all channels simultanously)
unsigned int GetWidth() const
int ParseCommandLine(int &argc, char *argv[])
scan command line arguments for valid parameters
void Usage(std::ostream &os=std::cout)
print Help-Information to stdout
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 GetFreeGroupID()
returns unused group id
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
a class for exporting ThreeDOut objects to OSG scene graphs
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
This class Param provides generic support for parameters.
int SetGroupName(const int group_id, const std::string &name)
sets the name for a group
const BIAS::Projection & GetProj() const
std::string * AddParamString(const std::string &name, const std::string &help, std::string deflt="", char cmdshort=0, int Group=GRP_NOSHOW)
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