Counting point cloud's volume : part of application - PMaslowski/PictureAnalysis GitHub Wiki
After going through the UTM-conversion algorithm, points belonging to a selected area go to the class VolumeCounter. In this class the approximate volume of the selected area it is calculated. To determine the depth of the top of the Y-axis, the program assumes that the mountain is located on a plane parallel to the x-axis, and placed at the height of the lowest point of a set of selected points. Run_test method is started in the VolumeCounter class constructor. It takes the vector points of the selected surface as a parameter and returns a calculated volume.
To obtain the above described surface every thousandth point is being projected. In addition, every two-thousandth point is being projected to a height which is a half of the height between the base of the area and the projected point.
All points are added to the vector “pointsVector” and then are given as input to the method tetrahedralize. Tetrahedralize method is a method from tetgen library. It runs tetrahedralize of the entry points and return them with the edges connecting them in tetrahedrons. The method also has a parameter 'eQ', by which returned indexes of points that connect to the edges.
Individual volume of the tetrahedron is calculated as follows: The coordinates of vertices of tetrahedrons are use to calculate volume of the tetrahedrons. The volume of each tetrahedrons is given by volume formula V = sqrt(delta)/288, where variable delta is a determinant:
where aij is the length of edge connecting vertex Ai and Aj.
To calculate the distance between the vertices is used the method distanceBetweenPoints (Point p1, Point p2), where the parameters are the two objects of the class Point, which points contain three coordinates x, y, z. An array of determinant is create using the method fillArray (Tetrahedron tet) which has one parameter - an object of class Tetrahedron, or tetrahedron consists of four objects of the class Point, so it contains the coordinates of the four vertices of the tetrahedron. In order to calculate the determinant is used method determinant (VolumeArray volumeArray, int n), where the first parameter is an array of determinant to calculate, and the second parameter determines its size. With these data we call method calculateVolume (double determinants), which pass as a parameter to the previously calculated value of the determinant. This function returns the volume of a single tetrahedron.
Then the volume of all tetrahedra are summed and returned as the approximate volume of the entire surface.