27 #include <unordered_map>
35 static const std::unordered_map<
38 const std::string&,
ccHObject&,
const ReadPointCloudOption&)>>
51 static const std::unordered_map<
53 std::function<bool(
const std::string&,
73 bool loadCoordinatesTransEnabled =
false;
90 FileIOFilter::InitInternalFilters();
99 auto container = std::make_shared<ccHObject>();
104 QString extension = QFileInfo(file).suffix();
105 if (extension.isEmpty()) {
107 "[Load] Can't guess file format: no file extension");
117 "[Load] Can't guess file format: unhandled file "
119 extension.toStdString().c_str());
128 "[Load] File '%s' doesn't exist!",
129 file.toStdString().c_str());
140 result = filter->loadFile(file, entity, parameters);
142 result = filter->loadFile(file, *container, parameters);
144 }
catch (
const std::exception&
e) {
146 "[I/O] CC has caught an exception while loading file "
148 file.toStdString().c_str());
152 container->removeAllChildren();
157 "[I/O] CC has caught an unhandled exception while "
159 file.toStdString().c_str());
161 container->removeAllChildren();
171 unsigned childCount = container->getChildrenNumber();
172 if (childCount != 0) {
175 container->setName(QString(
"%1 (%2)").arg(fi.fileName(),
177 for (
unsigned i = 0; i < childCount; ++i) {
181 QString newName = child->
getName();
182 if (newName.startsWith(
"unnamed")) {
186 newName.replace(QString(
"unnamed"), fi.baseName());
199 bool successFlag =
true;
203 for (
unsigned i = 0; i < container->getChildrenNumber(); ++i) {
206 if (!cloud)
continue;
213 for (
unsigned i = 0; i < container->getChildrenNumber(); ++i) {
215 if (!mesh || mesh->
IsEmpty())
continue;
217 if (!outMesh->
merge(mesh,
false)) {
219 "[AutoReadEntity] merge mesh child failed!");
234 container->removeAllChildren();
248 FileIOFilter::InitInternalFilters();
263 if (QFileInfo(completeFileName).suffix().isEmpty())
265 QString(
".%1").arg(filter->getDefaultExtension());
267 QString extension = QFileInfo(completeFileName).suffix();
276 "[AutoWriteEntity] Can't guess file format: unhandled "
277 "file extension '%s'",
285 completeFileName, parameters);
288 "[AutoWriteEntity] CV has caught an unhandled "
289 "exception while saving file '%s'",
318 bool write_vertex_normals ,
319 bool write_vertex_colors ,
320 bool write_triangle_uvs ,
321 bool print_progress) {
331 const std::string&
format,
332 bool print_progress) {
333 auto entity = std::make_shared<ccHObject>(
"Group");
340 const std::string&
format,
341 bool print_progress) {
342 std::string filename_ext;
349 if (filename_ext.empty()) {
367 bool success = map_itr->second(
filename, entity, p);
377 bool print_progress) {
378 std::string filename_ext =
380 if (filename_ext.empty()) {
399 bool success = map_itr->second(
filename, entity, p);
filament::Texture::InternalFormat format
CC_FILE_ERROR
Typical I/O filter errors.
static unsigned IncreaseSesionCounter()
static const FilterContainer & GetFilters()
Returns the set of all registered filters.
static Shared FindBestFilterForExtension(const QString &ext)
Returns the best filter (presumably) to open a given file extension.
QSharedPointer< FileIOFilter > Shared
Shared type.
static void ResetSesionCounter()
static void DisplayErrorMessage(CC_FILE_ERROR err, const QString &action, const QString &filename)
Displays (to console) the message corresponding to a given error code.
static ccMesh * ToMesh(ccHObject *obj)
Converts current object to ccMesh (if possible)
static ccPointCloud * ToPointCloud(ccHObject *obj, bool *isLockedVertices=nullptr)
Converts current object to 'equivalent' ccPointCloud.
Hierarchical CLOUDVIEWER Object.
unsigned getChildrenNumber() const
Returns the number of children.
ccHObject * getChild(unsigned childPos) const
Returns the ith child.
bool merge(const ccMesh *mesh, bool createSubMesh)
Merges another mesh into this one.
virtual bool IsEmpty() const override
ccGenericPointCloud * getAssociatedCloud() const override
Returns the vertices cloud.
void setBaseName(const QString &baseName)
virtual QString getName() const
Returns object name.
bool isA(CV_CLASS_ENUM type) const
virtual void setName(const QString &name)
Sets object name.
void setFullPath(const QString &fullPaht)
bool isKindOf(CV_CLASS_ENUM type) const
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
const ccPointCloud & append(ccPointCloud *cloud, unsigned pointCountBefore, bool ignoreChildren=false)
Appends a cloud to this one.
unsigned size() const override
bool AutoWriteMesh(const std::string &filename, const ccMesh &mesh, bool write_ascii=false, bool compressed=false, bool write_vertex_normals=true, bool write_vertex_colors=true, bool write_triangle_uvs=true, bool print_progress=false)
bool AutoReadEntity(const std::string &filename, ccHObject &entity, const ReadPointCloudOption ¶ms)
bool AutoWriteEntity(const std::string &filename, const ccHObject &entity, const WritePointCloudOption ¶ms)
bool ReadEntity(const std::string &filename, ccHObject &obj, const std::string &format="auto", bool print_progress=false)
static const std::unordered_map< std::string, std::function< bool(const std::string &, ccHObject &, const ReadPointCloudOption &)> > file_extension_to_entity_read_function
bool AutoReadMesh(const std::string &filename, ccMesh &mesh, const ReadTriangleMeshOptions ¶ms={})
std::shared_ptr< ccHObject > CreateEntityFromFile(const std::string &filename, const std::string &format="auto", bool print_progress=false)
bool WriteEntity(const std::string &filename, const ccHObject &obj, bool write_ascii=false, bool compressed=false, bool print_progress=false)
static const std::unordered_map< std::string, std::function< bool(const std::string &, const ccHObject &, const WritePointCloudOption &)> > file_extension_to_entity_write_function
std::string GetFileExtensionInLowerCase(const std::string &filename)
std::string ToUpper(const std::string &s)
Convert string to the upper case.
Generic file read and write utility for python interface.
Generic loading parameters.
CCVector3d * coordinatesShift
If applicable, applied shift on load (optional)
ecvGlobalShiftManager::Mode shiftHandlingMode
How to handle big coordinates.
QWidget * parentWidget
Parent widget (if any)
bool alwaysDisplayLoadDialog
bool sessionStart
Session start (whether the load action is the first of a session)
bool * coordinatesShiftEnabled
Whether shift on load has been applied after loading (optional)
Generic saving parameters.
QWidget * parentWidget
Parent widget (if any)
bool alwaysDisplaySaveDialog
Optional parameters to ReadPointCloud.
std::function< bool(double)> update_progress
Optional parameters to WritePointCloud.
std::function< bool(double)> update_progress
update_progress(double percent) functor for ConsoleProgressBar