52 #if (_MSC_VER <= 1916)
53 #define QT_NO_FLOAT16_OPERATORS
61#include "FileBundle.hh"
71#include <OpenMesh/Core/IO/IOManager.hh>
79static const char IMAGELIST_SUFFIX[] =
".txt";
80static const char IMAGELIST_FALLBACK[] =
"image_list.txt";
86static std::string readLine( FILE *_file )
89 std::string result =
"";
95 fscanf( _file,
"%c", &c );
98 if( feof( _file ) || c ==
'\0' || c ==
'\n' || c ==
'\r' )
113static void splitFilename(
const std::string &_str, std::string &_path, std::string &_name, std::string &_ext )
115 size_t i = _str.find_last_of(
"/\\" );
119 if( i == std::string::npos )
126 _path = _str.substr( 0, i+1 );
127 rest = _str.substr( i+1 );
130 size_t j = rest.find_last_of(
'.' );
132 if( j == std::string::npos )
139 _name = rest.substr( 0, j );
140 _ext = rest.substr( j );
148bool FileBundlePlugin::addEmptyObjects(
unsigned int _num,
const DataType &_dataType, std::vector<int> &_objectIDs )
150 deleteObjects( _objectIDs );
151 _objectIDs.reserve( _num );
153 OpenFlipper::Options::blockSceneGraphUpdates();
156 for( i=0; i<_num; ++i )
159 emit addEmptyObject( _dataType, objectId );
164 _objectIDs.push_back( objectId );
167 OpenFlipper::Options::unblockSceneGraphUpdates();
172 deleteObjects( _objectIDs );
180void FileBundlePlugin::deleteObjects( std::vector<int> &_objectIDs )
182 unsigned int i, num = _objectIDs.size();
183 for( i=0; i<num; ++i )
184 emit deleteObject( _objectIDs[ i ] );
193bool FileBundlePlugin::readImagelistFile(
const char *_filename, std::vector<std::string> &_imagePaths )
197 FILE *file = fopen( _filename,
"rt" );
200 emit log(
LOGINFO, tr(
"Could not open imagelist file \"%1\".\n").arg( _filename ) );
209 fscanf( file,
"%4095s", path );
210 fscanf( file,
"%31s", temp );
211 fscanf( file,
"%31s", temp );
216 _imagePaths.push_back( std::string( path ) );
221 emit log(
LOGINFO, tr(
"Using imagelist file \"%1\".\n").arg( _filename ) );
229void FileBundlePlugin::readCameras( FILE *_file,
const std::vector<int> &_cameraObjectIDs, SplatCloud_Cameras &_cameras )
233 unsigned int cameraIdx = 0;
234 SplatCloud_Cameras::iterator cameraIter;
235 for( cameraIter = _cameras.begin(); cameraIter != _cameras.end(); ++cameraIter, ++cameraIdx )
239 camera.objectId_ = _cameraObjectIDs[ cameraIdx ];
242 fscanf( _file,
"%32s", str ); proj.f_ = atof( str );
243 fscanf( _file,
"%32s", str ); proj.k1_ = atof( str );
244 fscanf( _file,
"%32s", str ); proj.k2_ = atof( str );
245 fscanf( _file,
"%32s", str ); proj.r_[0][0] = atof( str );
246 fscanf( _file,
"%32s", str ); proj.r_[0][1] = atof( str );
247 fscanf( _file,
"%32s", str ); proj.r_[0][2] = atof( str );
248 fscanf( _file,
"%32s", str ); proj.r_[1][0] = atof( str );
249 fscanf( _file,
"%32s", str ); proj.r_[1][1] = atof( str );
250 fscanf( _file,
"%32s", str ); proj.r_[1][2] = atof( str );
251 fscanf( _file,
"%32s", str ); proj.r_[2][0] = atof( str );
252 fscanf( _file,
"%32s", str ); proj.r_[2][1] = atof( str );
253 fscanf( _file,
"%32s", str ); proj.r_[2][2] = atof( str );
254 fscanf( _file,
"%32s", str ); proj.t_[0] = atof( str );
255 fscanf( _file,
"%32s", str ); proj.t_[1] = atof( str );
256 fscanf( _file,
"%32s", str ); proj.t_[2] = atof( str );
258 camera.imagePath_ =
"";
260 camera.imageWidth_ = 0;
261 camera.imageHeight_ = 0;
269void FileBundlePlugin::readPoints( FILE *_file,
const std::vector<int> &_cameraObjectIDs,
SplatCloud &_splatCloud )
273 int maxCamObjId = _cameraObjectIDs.size() - 1;
275 unsigned int splatIdx;
276 for( splatIdx = 0; splatIdx < _splatCloud.
numSplats(); ++splatIdx )
280 fscanf( _file,
"%32s", str ); pos[0] = atof( str );
281 fscanf( _file,
"%32s", str ); pos[1] = atof( str );
282 fscanf( _file,
"%32s", str ); pos[2] = atof( str );
287 unsigned int r=0, g=0, b=0;
288 fscanf( _file,
"%16u", &r ); col[0] = r;
289 fscanf( _file,
"%16u", &g ); col[1] = g;
290 fscanf( _file,
"%16u", &b ); col[2] = b;
294 SplatCloud::Viewlist &viewlist = _splatCloud.
viewlists( splatIdx );
296 unsigned int numEntries = 0;
297 fscanf( _file,
"%16u", &numEntries );
299 viewlist.resize( numEntries );
301 SplatCloud::Viewlist::iterator viewIter;
302 for( viewIter = viewlist.begin(); viewIter != viewlist.end(); ++viewIter )
306 fscanf( _file,
"%16i", &i ); viewIter->cameraObjectId_ = ((i >= 0) && (i <= maxCamObjId)) ? _cameraObjectIDs[ i ] : -1;
307 fscanf( _file,
"%16i", &j ); viewIter->featureIdx_ = j;
308 fscanf( _file,
"%32s", str ); viewIter->x_ = atof( str );
309 fscanf( _file,
"%32s", str ); viewIter->y_ = atof( str );
319bool FileBundlePlugin::readBundleFile(
const char *_filename,
SplatCloud &_splatCloud )
325 FILE *file = fopen( _filename,
"rt" );
328 emit log(
LOGERR, tr(
"Could not open input file \"%1\".\n").arg( _filename ) );
333 std::string magicAndVersion = readLine( file );
334 if( magicAndVersion.compare(
"# Bundle file v0.3" ) != 0 )
336 emit log(
LOGERR, tr(
"Bad magic/version \"%1\" in input file \"%2\".\n").arg( magicAndVersion.c_str(), _filename ) );
342 unsigned int numCameras = 0;
343 unsigned int numPoints = 0;
344 fscanf( file,
"%16u", &numCameras );
345 fscanf( file,
"%16u", &numPoints );
348 std::vector<int> cameraObjectIDs;
349 if( !addEmptyObjects( numCameras,
DATA_CAMERA, cameraObjectIDs ) )
351 emit log(
LOGERR, tr(
"Unable to add %1 cameras for input file \"%2\".\n").arg( QString::number( numCameras ), _filename ) );
357 if( numCameras != 0 )
361 cameraManager.cameras_.resize( numCameras );
362 readCameras( file, cameraObjectIDs, cameraManager.cameras_ );
366 std::vector<std::string> imagePaths;
368 std::string path,
name, ext;
369 splitFilename( _filename, path,
name, ext );
371 if( !readImagelistFile( (path +
name + IMAGELIST_SUFFIX).c_str(), imagePaths ) )
372 readImagelistFile( (path + IMAGELIST_FALLBACK ).c_str(), imagePaths );
374 bool hasImg = (cameraManager.cameras_.size() <= imagePaths.size());
378 unsigned int cameraIdx = 0;
379 SplatCloud_Cameras::iterator cameraIter;
380 for( cameraIter = cameraManager.cameras_.begin(); cameraIter != cameraManager.cameras_.end(); ++cameraIter, ++cameraIdx )
381 cameraIter->imagePath_ = imagePaths[ cameraIdx ];
384 _splatCloud.
requestCloudProperty( SPLATCLOUD_GENERALMANAGER_HANDLE )->data().flags_.set( SPLATCLOUD_CAMERA_HAS_IMAGEPATH_FLAG, hasImg );
395 readPoints( file, cameraObjectIDs, _splatCloud );
397 _splatCloud.
requestCloudProperty( SPLATCLOUD_GENERALMANAGER_HANDLE )->data().flags_.set( SPLATCLOUD_SPLAT_VIEWLIST_HAS_FEATURE_INDICES_FLAG,
true );
398 _splatCloud.
requestCloudProperty( SPLATCLOUD_GENERALMANAGER_HANDLE )->data().flags_.set( SPLATCLOUD_SPLAT_VIEWLIST_COORDS_NORMALIZED_FLAG,
false );
404 emit log(
LOGERR, tr(
"Unexpected end in input file \"%1\".\n" ).arg( _filename ) );
420bool FileBundlePlugin::writeBundleFile(
const char *_filename,
const SplatCloud &_splatCloud )
429int FileBundlePlugin::loadObject( QString _filename )
432 int splatCloudObjectId = -1;
434 if( splatCloudObjectId != -1 )
447 if( (splatCloud != 0) && (splatCloudNode != 0) )
450 if( readBundleFile( _filename.toLatin1(), *splatCloud ) )
453 emit updatedObject( splatCloudObjectId,
UPDATE_ALL );
454 emit openedFile( splatCloudObjectId );
466 emit log(
LOGERR, tr(
"Shader DrawModes for SplatCloud not existent!") );
478 drawmode |= pointsDrawMode;
484 return splatCloudObjectId;
498bool FileBundlePlugin::saveObject(
int _objectId, QString _filename )
510 if( splatCloud != 0 )
513 if( writeBundleFile( _filename.toLatin1(), *splatCloud ) )
bool containsAtomicDrawMode(const DrawMode &_atomicDrawMode) const
Check whether an Atomic DrawMode is active in this draw Mode.
QString filename() const
return the filename of the object
void setFromFileName(const QString &_filename)
QWidget * saveOptionsWidget(QString)
QString name()
Return a name for the plugin.
QWidget * loadOptionsWidget(QString)
SplatCloudNode * splatCloudNode()
Get SplatCloud's scenegraph Node.
SplatCloud * splatCloud()
Get SplatCloud.
void setName(QString _name)
Set the name of the Object.
void resizeSplats(unsigned int _num)
Resize the data vector of all splat-properties.
Viewlist & viewlists(int _idx)
Get a reference of the predefined property's value.
CloudPropertyT< T > * requestCloudProperty(const PropertyHandleT< T > &_handle)
Request a new property.
unsigned int numSplats() const
Get the number of splats.
bool requestViewlists()
Request the predefined property.
Position & positions(int _idx)
Get a reference of the predefined property's value.
bool requestColors()
Request the predefined property.
Color & colors(int _idx)
Get a reference of the predefined property's value.
bool requestPositions()
Request the predefined property.
void clear()
Remove all properties and reset the number of splats.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
const DrawMode & getDrawMode(const std::string &_name)
Get a custom DrawMode.
DrawMode NONE
not a valid draw mode
SplatCloudObject * splatCloudObject(BaseObjectData *_object)
Cast an SplatCloudObject to a SplatCloudObject if possible.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
ACG::SceneGraph::DrawModes::DrawMode drawMode(int _viewer)
Get the current draw Mode of a Viewer.
SplatCloud * splatCloud(BaseObjectData *_object)
Get a SplatCloud from an object.
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .
SplatCloudNode * splatCloudNode(BaseObjectData *_object)
Get a SplatCloudNode from an object.