File: LAS_io_plugin.cpp

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (102 lines) | stat: -rw-r--r-- 2,948 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "Scene_points_with_normal_item.h"
#include <CGAL/Three/CGAL_Lab_io_plugin_interface.h>
#include <CGAL/Three/Three.h>
#include <CGAL/Three/Scene_item.h>
#include <CGAL/Point_set_3/IO.h>
#include <fstream>
using namespace CGAL::Three;
class CGAL_Lab_las_plugin :
  public QObject,
  public CGAL::Three::CGAL_Lab_io_plugin_interface
{
  Q_OBJECT
  Q_INTERFACES(CGAL::Three::CGAL_Lab_io_plugin_interface)
  Q_PLUGIN_METADATA(IID "com.geometryfactory.CGALLab.IOPluginInterface/1.90" FILE "las_io_plugin.json")

public:
  QString name() const { return "las_plugin"; }
  QString nameFilters() const { return "LAS files (*.las);;Compressed LAS files (*.laz)"; }
  bool canLoad(QFileInfo fileinfo) const;
  QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);

  bool canSave(const CGAL::Three::Scene_item*);
  bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& );
};

bool CGAL_Lab_las_plugin::canLoad(QFileInfo ) const {
  return true;
}

QList<Scene_item*> CGAL_Lab_las_plugin::
load(QFileInfo fileinfo, bool& ok, bool add_to_scene) {
  std::ifstream in(fileinfo.filePath().toUtf8(), std::ios_base::binary);

  if(!in)
    std::cerr << "Error!\n";

  Scene_points_with_normal_item* item;
  item = new Scene_points_with_normal_item();
  Q_ASSERT(item->point_set() != nullptr);

  item->point_set()->clear();

  ok = CGAL::IO::read_LAS (in, *(item->point_set())) && !item->isEmpty();
  if(ok)
  {
    std::cerr << item->point_set()->info();

    if (!item->point_set()->has_normal_map())
    {
      item->setRenderingMode(Points);
    }
    else{
      item->setRenderingMode(CGAL::Three::Three::defaultPointSetRenderingMode());
    }
    if (item->point_set()->check_colors())
      std::cerr << "-> Point set has colors" << std::endl;

    item->invalidateOpenGLBuffers();
  }
  if(!ok)
  {
    delete item;
    return QList<Scene_item*>();
  }

  item->setName(fileinfo.completeBaseName());
  ok = true;
  if(add_to_scene)
    CGAL::Three::Three::scene()->addItem(item);
  return QList<Scene_item*>()<<item;
}

bool CGAL_Lab_las_plugin::canSave(const CGAL::Three::Scene_item* item)
{
  return qobject_cast<const Scene_points_with_normal_item*>(item);
}

bool CGAL_Lab_las_plugin::save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
{
  Scene_item* item = items.front();
  // Check extension (quietly)
  std::string extension = fileinfo.suffix().toUtf8().data();
  if (extension != "las" && extension != "LAS")
    return false;

  // This plugin supports point sets
  Scene_points_with_normal_item* point_set_item =
    qobject_cast<Scene_points_with_normal_item*>(item);
  if(!point_set_item)
    return false;

  std::ofstream out(fileinfo.filePath().toUtf8().data());
  items.pop_front();
  Q_ASSERT(point_set_item->point_set() != nullptr);

  point_set_item->point_set()->reset_indices();

  return CGAL::IO::write_LAS(out, *(point_set_item->point_set()));
}


#include "LAS_io_plugin.moc"