Version 6 (modified by jaho, 12 years ago) (diff) |
---|
LAG Developers FAQ
1. What is LAG?
2. What are major components of LAG?
3. How do I edit the GUI?
4. What are LAS files?
[#q4.1 4.1 What's the deal with LAS 1.3 files?
5. What do I need to know about laslib?
6. How do I make laslib a shared library?
7. Why is LAG's code so messy?
8. How can I make LAG's code better?
9. Where can I learn good C++ coding practices?
10. Who should I ask for help?
11. How does Quadtree work?
12. How is Quadtree structured?
13. What is the reason behind subbuckets?
14. How does caching work?
15. What is the reason behind data compression?
16. What are LasSaver and LasLoader classes in the quadtree?
17. How is LAG's code structured?
18. How does loading of files work?
19. How does saving of files work?
21. How is LAS 1.3 point format handled?
22. How does rendering work?
23. What are main ideas for further LAG development?
24. What are some major issues with LAG that need fixing?
25. What are some additional features that can be added to LAG?
26. What tools are there to help me with LAG development?
Question X?
Question X?
Question X?
Question X?
1. What is LAG?
LAG stands for LiDAR Analysis GUI. It is a software which provides graphical user interface for processing and visualisation of LiDAR point cloud data. LAG is written in C++ and uses Gtk (gtkmm) for its GUI, and OpenGL for rendering.
2. What are major components of LAG
LAG consist of the main GUI application and a Lidar Quadtree library used for storing and querying the data.
3. How do I edit the GUI?
The GUI layout is stored in lag.ui Glade file which is in plain xml. This allows editing the interface without the need for recompiling the source code every time a change is made. The lag.ui file can be opened in Glade User Interface Designer which can by run with glade-3 command.
The interface of the application is created from xml using Gtk::Builder object, which is instantiated in lag.cpp and then passed by Glib::RefPtr to each of the classes that handle the GUI. All of these classes are located under src/ui folder and each of them has two common methods: void load_xml(builder) and void connect_signals() which are called in their constructors.
The load_xml(const Glib::RefPtr<Gtk::Builder>& builder) method gets widgets from the builder file and assigns them to the class members (pointers). Widgets instantiated by Gtk::Builder have to be deleted manually. In fact, according to documentation, this only applies to top-level widgets (windows and dialogs), but LAG's authors seem to prefer to delete every single one anyway.
The connect_signals() method is responsible for connecting various input signals to class methods. An example lifetime of a Gtk Widget then looks like this:
// Declare a pointer to the widget (as class member) class MyClass { Gtk::Button* my_button; void on_my_button_clicked(); } // Load the widget from xml (in MyClass::load_xml(const Glib::RefPtr<Gtk::Builder>& builder)) builder->get_widget("mybutton", my_button); // Connect some method to it (in MyClass::connect_signals()) my_button->signal_clicked().connect(sigc::mem_fun(*this, &MyClass::on_my_button_clicked)); // Delete the widget (in the class destructor) delete my_button;
Modifying the GUI is just as simple as adding new widgets to the Glade file and then handling them in the ui classes.
4. What are LAS files?
LAS is a binary, public file format designed to hold LiDAR point data. An alternative to LAS are ASCII files, which are however much less efficient in terms of both processing time and file size.
LAS files consist of several parts: Public Header Block, Variable Length Records, Point Records and in format 1.3 and later Waveform Records.
One thing to note about LAS is that point coordinates are stored as scaled integers and are then unscaled upon loading to double values with the use of scale factors and offsets stored in the header.
A detailed LAS format specification can be found at: http://www.asprs.org/Committee-General/LASer-LAS-File-Format-Exchange-Activities.html
5. What do I need to know about laslib?
Laslib is a library for handling various LiDAR file formats including LAS. LAG makes use of laslib for loading and saving points.
There is no official documentation for laslib API, however it is a fairly well written C++ which provides an easy to use interface. The best way to learn laslib is to study the source code of programs included in lastools.
The main classes of our interest are LASreader and LASwriter. A simple program that reads points from a file, filters out points with classification 7 (noise), prints points' coordinates and then saves them to another file may look like this (note there's no error checking or exception handling for simplicity, but you should always include it the real code):
#include <iostream> #include "laslib/lasreader.hpp" #include "laslib/laswriter.hpp" #include "laslib/lasdefinitions.hpp" int main(int argc, char** argv) { // Assume that's correct for simplicity std::string filename = argv[1]; std::string file_out = argv[2]; LASreadOpener lasreadopener; LASwriteOpener laswriteopener; lasreadopener.set_file_name(filename.c_str()); laswriteopener.set_file_name(file_out.c_str()); // Filter out points with classification 7 std::vecor<char*> filter_args; // this simulates a command line arguments for parse() function further down filter_args.push_back("filter"); // a dummy first argument filter_args.push_back("-drop_classification"); filter_args.push_back("7"); filter_args.push_back(0); // null termination lasreadopener.parse(args.size(), &args[0]); // &args[0] = *args so we're passing char** args instead of a vector<char*> // Declare lasreader LASreader* lasreader; // Open the file lasreader = lasreadopener.open(); // Create and open the writer LASwriter* laswriter = laswriteopener.open(&lasreader->header); // Loop through the points (note they will already be filtered) while (lasreader->read_point()) { // Show coordinates std::cout << lasreader->point.get_x() << ", " << lareader->point.get_y() << ", " << lasreader->point.get_z() << std::endl; // Write point laswriter->write_point(&lasreader->point); // Add it to the inventory (keeps track of min/max values for the header) laswriter->update_inventory(&lasreader->point); } laswriter->update_header(&lasreader->header, TRUE); laswriter->close(); lasreader->close(); delete laswriter(); delete lasreader(); }
6. How do I make laslib a shared library?
It seems that laslib is mainly developed for Windows users so there are no targets for shared libraries in the Makefiles by default. At the same time shared libraries are needed by LAG to work correctly. To fix this you're going to need to modify the Makefiles and add -fPIC option to the compiler. You'll also have to change the name of the library from laslib to liblaslib for the linker to detect it.
You'll normally find modified Makefiles somewhere around, so you can copy them after downloading a new version of laslib and hopefully they will work. If this is not the case, below is the part that needs to be added to the Makefile inside laslib/src folder.
all: static shared # these targets set the output directory for the object # files and then call make again with the appropriate library targets. # This is done so that the fpic flag is set correctly for the library # we're building. static: test -d static || mkdir static $(MAKE) liblaslib.a OBJDIR=static shared: test -d shared || mkdir shared $(MAKE) liblaslib.so.${VERSION} OBJDIR=shared EXTRA_COPTS=-fPIC liblaslib.a: ${TARGET_OBJS} $(AR) $@ ${TARGET_OBJS} cp -p $@ ../lib liblaslib.so.${VERSION}: ${TARGET_OBJS} ${COMPILER} -shared -Wl,-soname,liblaslib.so.1 -o \ liblaslib.so.${VERSION} ${TARGET_OBJS} cp -p $@ ../lib ${TARGET_OBJS}: ${OBJDIR}/%.o: %.cpp ${COMPILER} ${BITS} -c ${COPTS} ${EXTRA_COPTS} ${INCLUDE} $< -o $@
You're not likely to have to alter this part and if a newly downloaded version of laslib fails to build with modified Makefiles, the first thing to check is if OBJ_LAS (the list of object files) hasn't changed since the previous release.
7. Why is LAG's code so messy?
The lag has been in development since 2009 and there were at least four different people working on it, each with different coding style, ideas and barely any supervision. It is now much better then it used to be, but it's easy to see that different parts have been written by different people. There also still seems to be a lot of temporary solutions which were never implemented properly, since they worked at the time.
8. How can I make LAG's code better?
Think before you code. Take users of your classes into consideration and try to design easy to use interfaces. Do some refactoring if you think it's going to make things easier to maintain, and to understand the code better. Use consistent coding style and comments. Try to learn good coding practices before you start writing the code (eg. implementing const correctness from the start is much easier then adding it once everything has been written).
9. Where can I learn good C++?
Whether you already know C++, come from C or are just starting to learn, it is a good idea to familiarise yourself with good programming practice before writing production code. Assuming you already know the basics of the language I highly recommend these two sources:
C++ FAQ - every C++ programmer should read this at least once. It's well written, to the point and covers a lot of things from OO design to freestore management.
Google C++ Style Guide - you don't have to blindly follow it, but it should give you an idea of what a good coding style looks like.
10. Who can I ask for help?
One problem with LAG is that it has been entirely developed by students, so the only people that know how it really works are most likely gone (thus this FAQ). For general help with programming you should probably ask Mike Grant (he knows a bit about LAG) or Mark Warren as they seem to be the best programmers in ARSF. They also tend to be quite busy though so if you don't feel like bugging them Stack Overflow is always a good place to look for help.
11. How does Quadtree work?
The Lidar Quadtree library provides a quadtree data structure for storing and indexing points. It also contains a caching mechanism for loading and unloading points from memory.
Each node of the quadtree represents a bounding box in x and y coordinates. Whenever a point is inserted into the quadtree it is determined which of the four nodes it falls into and then the same happens for each node recursively until a leaf node is found. Whenever the number of points in a node goes above the maximum capacity specified, the node splits into four.
When retrieving points a bounding box is passed to the quadtree and all nodes which intersect with it are queried for the points. It's quite simple really.
12. How is quadtree's code structured?
Quadtree.cpp
Provides an interface for the quadtree. It is the only class that should be used from the outside. It also holds metadata about the quadtree and a pointer to the root node.
QuadtreeNode.cpp
Represents a single quadtree node. Provides methods for inserting and retrieving the points.
Point.cpp
Represents a single point in space with three coordinates: x, y, z.
LidarPoint.cpp
Represents a lidar point with coordinates (inherits from Point) and other attributes like time, intensity, classification etc. Note that size of the point directly affects the size and performance of the quadtree, thus only necessary attributes are held inside this class.
PointBucket.cpp
A flat data structure which actually holds the points. Each quadtree node holds a pointer to a PointBucket which holds the points in an array of LidarPoints. The PointBucket is also responsible for caching and uncaching of data.
PointData.cpp
A struct to hold LAS 1.3+ point attributes which are stored separately.
CacheMinder.cpp
A class to keep track of how many points are currently loaded into memory.
13. What is the reason behind subbuckets?
The PointBucket class may hold copies of the same point in several arrays called sub-buckets. There are two parameters which control of how many sub-buckets are created: Resolution Depth and Resolution Base. The Resolution Depth determines the number of sub-buckets for each bucket and Resolution Base determines the number of points at each level by specifying the interval between included points based on a formula of Resolution Base(Level - 1). For example the default LAG values of 5 and 4 create 4 sub-buckets per bucket: one containing every point (50), second containing every 5th point (51), third containing every 25th point (52) and fourth with every 125th point (53). The reason for this is rendering of points. For example when viewing a whole flightline in the overview window there is no need to render every single point or store all the points in memory at once. Thus sub-buckets containing every n-th point are used instead. Note that you could just pass every-nth point for rendering, but it is really the memory usage and caching issue that sub-buckets solve. Because each resolution level effectively slowers the quadtree (some points need to be inserted n times into n arrays) for applications other then LAG, which make no use of sub-buckets Resolution Depth and Resolution Base should be set to 1.
14. How does caching work?
Upon creation of the quadtree the user specifies a maximum number of points to be held in cache.
15. What is the reason behind data compression?
To make caching faster. PointBucket uses lzo compression to compress buckets before writing them to disk. It may seem like a sub-optimal solution but, since quadtree's performance is mainly IO bound, the compression time is still much lower then reading/writing to the hard drive. Since the volume of data gets smaller thanks to compression in the end it speeds up IO operations which are the major bottleneck.
16. What are LasSaver and LasLoader classes in the quadtree?
These should be removed at some point together with geoprojectionconverter. They are currently there only for backwards compatibility with other programs that use the quadtree (classify_las). From design point of view these classes should not be a part of the quadtree which should only serve as a data container. In practice, when these classes were used, making any changes in LAG regarding saving or loading files required alterations to the quadtree which was less then convenient. Now that loading and saving has been moved to separate classes inside LAG it is much more maintainable.
17. How is LAG's code structured?
lag.cpp
That's were main()function is. Not much happens here. The program looks for glade ui files, instantiates main classes, then starts Gtk thread where everything runs.
BoxOverlay.cpp
This is the box (fence or a profile) that you can draw on the screen.
ClassifyWorker.cpp
A worker class responsible for classifying points. This is kind of a stub at the moment, since the methods that do points classification are actually elsewhere and are only called from this class in separate thread.
Coulour.cpp
Represents an RGB colour.
FileUtils.cpp
An utility class which holds several methods used by classes that deal with files.
LagDisplay.cpp
An abstract class responsible for rendering. Profile and TwoDeeOverview inherit from this class.
LoadWorker.cpp
A worker class responsible for loading files. This is also the point where the quadtree is being created.
MathFuncs.cpp
An utility class with some common math functions.
PointFilter.h
A struct to hold a filter string which is then passed to the laslib::LASreadOpener.parse() method to create a filter for the points.
Profile.cpp
Represents the profile view of the data. The rendering of the profile and classification of points is done here in a particularly messy way.
ProfileWorker.cpp
A worker class that loads points selected in the overview into a profile. This is another stub as the actual methods for loading the profile are currently in Profile.cpp.
SaveWorker.cpp
A worker class responsible for saving points to a file.
SelectionBox.cpp
Holds the coordinates of a selection made on the screen.
TwoDeeOverview.cpp
A mess. Represents the 2d overview of the data and handles its rendering.
Worker.h
An abstract worker class.
ui classes
These classes represent top-level interface elements (windows and dialogs) and are responsible for connecting the UI to signal handlers.
18. How does loading of files work?
Upon pressing Add or Refresh button an instance of LoadWorker is created in the FileOpener class with all the parameters from the file opening dialog (like filenames, ASCII parse string, filters etc) passed to its constructor. Then its run() method is called which actually does all the loading and then sends a signal back to the GUI thread through Glib::Dispatcher when the loading has finished.
Inside the run() method if the first file is being loaded a new quadtree object is created with its boundary equal to the values taken from the file's header. Every time a new file is loaded this boundary is adjusted to accommodate new points.
Once the quadtree has been set up a load_points() method is called which loads points from a file one by one and creates LidarPoint to insert them into the quadtree.
If the file is in latlong projection a GeoProjectionConverter class (which comes from lastools) is used to first adjust scale factors and offsets in the header, and then transform point coordinates. The points stored inside the quadtree are always in UTM projection as it is much easier to handle (in latlong x, y are in degrees and z is in metres which causes some difficulties with rendering).
20. How does saving of files work?
Upon pressing Save button an instance of SaveWorker is created with all necessary parameters from the save dialog passed to its constructor. Then its run() method is called where the saving actually happens.
Inside run() method an array of LidarPoints is created and then a query is run on the entire quadtree to get all the buckets. It then iterates through each bucket and through each point and then inserts each point which belongs to a given flightline into an array. Once an array fills up the points are saved to a file and new points are added from the start of the array until everything has been saved.
If the output or the input file is in loatlong projecion two GeoProjectionConverter objects are used to get correct scale factor and offset values in the header and then convert points' coordinates. This is because the points inside the quadtree are in UTM projection and if the input file is in latlong then its scale factors and offsets need to be converted to UTM. At the same time if the output file is in latlong point coordinates need to be converted.
21. How is LAS 1.3 point format and waveform data handled?
The problem with points in LAS 1.3+ files is that they contain a number of additional attributes which are used to describe corresponding waveform data, but which are not needed by lag. These values are all 32 or 64 bit and adding them to the LidarPoint class would effectively double its size. In turn they would considerably slower the quadtree and make it occupy additional memory. Therefore all these attributes are stored in a temporary file on the hard drive and then retrieved when points are being saved with help of LidarPoint::dataindex variable. (If you have any doubts it is much faster add several double values to LidarPoint class and profile some quadtree operations. The performance impact is huge and maybe it would be a good idea at some point to try to store coordinates as scaled integers and have the Quadtree unscale them whenever they're requested. It would make get_x() operations a bit slower but the overall quadtree quite faster.)
The LoadWorker class containst the following two static members:
static std::tr1::unordered_map<uint8_t, std::string> point_data_paths; static std::vector<int> point_number;
23. What are main ideas for further LAG development?
24. What are some major issues with LAG that need fixing?
25. What are some additional features that can be added to LAG?
26. What tools are there to help me with LAG development?
Attachments (2)
-
kcachegrind.png
(361.5 KB) -
added by jaho 12 years ago.
kcachegrind
-
class_diagram.png
(17.2 KB) -
added by besm 11 years ago.
Class Diagram
Download all attachments as: .zip