[Liblas-commits] r1161 - trunk/apps
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Apr 3 06:48:54 EDT 2009
Author: mloskot
Date: Fri Apr 3 06:48:49 2009
New Revision: 1161
URL: http://liblas.org/changeset/1161
Log:
Fixed EOL to LF. Made the tools code more compact.
Modified:
trunk/apps/lascommon.c
trunk/apps/lasinfo.c
Modified: trunk/apps/lascommon.c
==============================================================================
--- trunk/apps/lascommon.c (original)
+++ trunk/apps/lascommon.c Fri Apr 3 06:48:49 2009
@@ -1,12 +1,12 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+// liblas
#include <liblas.h>
-
#ifdef HAVE_GEOTIFF
#include <geotiff.h>
#endif
-
+// std
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
static const char * LASPointClassification [] = {
"Created, never classified",
@@ -43,10 +43,9 @@
"Reserved for ASPRS Definition"
};
-
LASPointSummary* SummarizePoints(LASReaderH reader) {
- LASPointSummary* summary;
+ LASPointSummary* summary = NULL;
LASPointH p = NULL;
LASColorH color = NULL;
LASColorH min_color = NULL;
@@ -72,9 +71,6 @@
summary->classification_keypoint = 0;
summary->classification_withheld = 0;
-
-
-
p = LASReader_GetNextPoint(reader);
if (!p) {
@@ -92,7 +88,6 @@
i = 1;
while (p)
{
-
summary->x = LASPoint_GetX(p);
LASPoint_SetX(summary->pmin, MIN(summary->x, LASPoint_GetX(summary->pmin)));
LASPoint_SetX(summary->pmax, MAX(summary->x, LASPoint_GetX(summary->pmax)));
@@ -177,8 +172,6 @@
LASColor_Destroy(max_color);
LASColor_Destroy(color);
-
-
summary->classification[(cls & 31)]++;
if (cls & 32) summary->classification_synthetic++;
@@ -347,7 +340,6 @@
}
fprintf(file, "\n Total Pulses: %ld\n", rgpsum);
-
for (i = 0; i < 5; i++) {
if (LASHeader_GetPointRecordsByReturnCount(header, i) != summary->number_of_points_by_return[i])
{
@@ -384,8 +376,6 @@
}
}
-
-
void print_header(FILE *file, LASHeaderH header, const char* file_name, int bSkipVLR) {
char *pszSignature = NULL;
@@ -420,15 +410,11 @@
pGTIF = LASSRS_GetGTIF(pSRS);
nVLR = LASHeader_GetRecordsCount(header);
-
-
-
fprintf(file, "\n---------------------------------------------------------\n");
fprintf(file, " Header Summary\n");
fprintf(file, "---------------------------------------------------------\n");
-
fprintf(file, " File Name: %s\n", file_name);
if (strcmp(pszSignature,"LASF") !=0) {
@@ -562,8 +548,7 @@
LASError_Print("Inputted summary to repair_header was NULL ");
exit(1);
- }
-
+ }
if (! repair_bounding_box) {
if ( LASHeader_GetMinX(header) != LASPoint_GetX(summary->pmin) )
@@ -601,10 +586,8 @@
LASError_Print("Could not set minimum for header ");
exit(1);
}
-
}
-
for (i = 0; i < 5; i++) {
if (LASHeader_GetPointRecordsByReturnCount(header, i) !=
@@ -624,4 +607,3 @@
}
}
}
-
Modified: trunk/apps/lasinfo.c
==============================================================================
--- trunk/apps/lasinfo.c (original)
+++ trunk/apps/lasinfo.c Fri Apr 3 06:48:49 2009
@@ -1,29 +1,28 @@
/***************************************************************************
- * $Id$
- * $Date$
- *
- * Project: libLAS -- C/C++ read/write library for LAS LIDAR data
- * Purpose: LAS information reporting and setting
- * Author: Martin Isenburg isenburg at cs.unc.edu
- ***************************************************************************
- * Copyright (c) 2007, Martin Isenburg isenburg at cs.unc.edu
- *
- * See LICENSE.txt in this source distribution for more information.
- **************************************************************************/
+* $Id$
+* $Date$
+*
+* Project: libLAS -- C/C++ read/write library for LAS LIDAR data
+* Purpose: LAS information reporting and setting
+* Author: Martin Isenburg isenburg at cs.unc.edu
+***************************************************************************
+* Copyright (c) 2007, Martin Isenburg isenburg at cs.unc.edu
+*
+* See LICENSE.txt in this source distribution for more information.
+**************************************************************************/
/* TODO: Remove before releasing */
#if defined(_MSC_VER) && defined(USE_VLD)
#include <vld.h>
#endif
-
+// liblas
+#include <liblas.h>
+// std
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <liblas.h>
-
-
LASPointSummary* SummarizePoints(LASReaderH reader);
void print_point_summary(FILE *file, LASPointSummary* summary, LASHeaderH header);
void print_header(FILE *file, LASHeaderH header, const char* file_name, int bSkipVLR);
@@ -46,7 +45,7 @@
fprintf(stderr,"Print header info and point summary and redirect output to a file:\n");
fprintf(stderr," lasinfo --check --input lidar.las 2> output.txt\n");
fprintf(stderr,"\n");
-
+
fprintf(stderr,"Read from stdin, scan the points, and skip printing VLR info:\n");
fprintf(stderr," lasinfo --stdin --check --skip_vlr < lidar.las\n");
fprintf(stderr,"\n");
@@ -63,24 +62,21 @@
fprintf(stderr,"Print this output:\n");
fprintf(stderr, " lasinfo --help\n");
fprintf(stderr,"\n");
-
+
fprintf(stderr, "\nFor more information, see the full documentation for lasinfo at:\n"
" http://liblas.org/browser/trunk/doc/lasinfo.txt\n");
fprintf(stderr,"----------------------------------------------------------\n");
-
}
-
-
int main(int argc, char *argv[])
{
- int i;
+ int i = 0;
char* file_name = NULL;
-
+
LASReaderH reader = NULL;
LASHeaderH header = NULL;
LASWriterH writer = NULL;
-
+
int check_points = FALSE;
int repair_header = FALSE;
int change_header = FALSE;
@@ -89,87 +85,75 @@
int update_return_counts = FALSE;
int skip_vlr = FALSE;
-
char *system_identifier = NULL;
char *generating_software = NULL;
uint8_t file_creation_day = 0;
uint8_t file_creation_year = 0;
-
+
int err = 0;
LASPointSummary* summary = NULL;
for (i = 1; i < argc; i++)
{
- if ( strcmp(argv[i],"-h") == 0 ||
- strcmp(argv[i],"--help") == 0
- )
+ if (strcmp(argv[i],"-h") == 0 || strcmp(argv[i],"--help") == 0)
{
usage();
exit(0);
}
- else if ( strcmp(argv[i],"--input") == 0 ||
- strcmp(argv[i],"-input") == 0 ||
- strcmp(argv[i],"-i") == 0 ||
- strcmp(argv[i],"-in") == 0
- )
+ else if (strcmp(argv[i],"--input") == 0
+ || strcmp(argv[i],"-input") == 0
+ || strcmp(argv[i],"-i") == 0
+ || strcmp(argv[i],"-in") == 0)
{
i++;
file_name = argv[i];
}
- else if ( strcmp(argv[i], "--points") == 0 ||
- strcmp(argv[i], "--check") == 0 ||
- strcmp(argv[i], "--check_points") == 0 ||
- strcmp(argv[i], "-c") == 0 ||
- strcmp(argv[i], "-points") == 0 ||
- strcmp(argv[i], "-check") == 0 ||
- strcmp(argv[i], "-check_points") == 0
- )
+ else if (strcmp(argv[i], "--points") == 0
+ || strcmp(argv[i], "--check") == 0
+ || strcmp(argv[i], "--check_points") == 0
+ || strcmp(argv[i], "-c") == 0
+ || strcmp(argv[i], "-points") == 0
+ || strcmp(argv[i], "-check") == 0
+ || strcmp(argv[i], "-check_points") == 0)
{
check_points = TRUE;
}
- else if ( strcmp(argv[i], "--nocheck") == 0 ||
- strcmp(argv[i], "-nocheck") == 0
- )
+ else if (strcmp(argv[i], "--nocheck") == 0
+ || strcmp(argv[i], "-nocheck") == 0)
{
check_points = FALSE;
}
- else if ( strcmp(argv[i], "--stdin") == 0 ||
- strcmp(argv[i], "-ilas") == 0
- )
+ else if (strcmp(argv[i], "--stdin") == 0
+ || strcmp(argv[i], "-ilas") == 0)
{
use_stdin = TRUE;
}
-
- else if ( strcmp(argv[i], "--repair") == 0 ||
- strcmp(argv[i], "-r") == 0 ||
- strcmp(argv[i], "-repair_header") == 0 ||
- strcmp(argv[i], "-repair") == 0
- )
+ else if (strcmp(argv[i], "--repair") == 0
+ || strcmp(argv[i], "-r") == 0
+ || strcmp(argv[i], "-repair_header") == 0
+ || strcmp(argv[i], "-repair") == 0)
{
repair_header = TRUE;
check_points = TRUE;
}
-
- else if ( strcmp(argv[i], "--repair_bb") == 0 ||
- strcmp(argv[i], "--repair_bounding_box") == 0 ||
- strcmp(argv[i], "--repair_boundingbox") == 0 ||
- strcmp(argv[i], "-repair_bb") == 0 ||
- strcmp(argv[i], "-repair_bounding_box") == 0 ||
- strcmp(argv[i], "-repair_boundingbox") == 0 ||
- strcmp(argv[i], "-repair") == 0 ||
- strcmp(argv[i], "-rb") == 0
-
- )
+ else if (strcmp(argv[i], "--repair_bb") == 0
+ || strcmp(argv[i], "--repair_bounding_box") == 0
+ || strcmp(argv[i], "--repair_boundingbox") == 0
+ || strcmp(argv[i], "-repair_bb") == 0
+ || strcmp(argv[i], "-repair_bounding_box") == 0
+ || strcmp(argv[i], "-repair_boundingbox") == 0
+ || strcmp(argv[i], "-repair") == 0
+ || strcmp(argv[i], "-rb") == 0)
{
repair_bounding_box = TRUE;
check_points = TRUE;
}
- else if ( strcmp(argv[i],"--system_identifier") == 0 ||
- strcmp(argv[i],"-system_identifier") == 0 ||
- strcmp(argv[i],"-s") == 0 ||
- strcmp(argv[i],"-sys_id") == 0)
+ else if (strcmp(argv[i],"--system_identifier") == 0
+ || strcmp(argv[i],"-system_identifier") == 0
+ || strcmp(argv[i],"-s") == 0
+ || strcmp(argv[i],"-sys_id") == 0)
{
i++;
system_identifier = (char*) malloc(31 * sizeof(char));
@@ -177,30 +161,28 @@
change_header = TRUE;
}
- else if ( strcmp(argv[i],"--generating_software") == 0 ||
- strcmp(argv[i],"-generating_software") == 0 ||
- strcmp(argv[i],"-g") == 0 ||
- strcmp(argv[i],"-gen_soft") == 0)
+ else if (strcmp(argv[i],"--generating_software") == 0
+ || strcmp(argv[i],"-generating_software") == 0
+ || strcmp(argv[i],"-g") == 0
+ || strcmp(argv[i],"-gen_soft") == 0)
{
i++;
generating_software = (char*) malloc(31*sizeof(char));
strcpy(generating_software, argv[i]);
change_header = TRUE;
}
-
- else if ( strcmp(argv[i],"--file_creation") == 0 ||
- strcmp(argv[i],"-file_creation") == 0)
+ else if (strcmp(argv[i],"--file_creation") == 0
+ || strcmp(argv[i],"-file_creation") == 0)
{
/* XXX - mloskot: Consider replacing atoi with strtol,
- see http://www.iso-9899.info/wiki/Converting */
+ see http://www.iso-9899.info/wiki/Converting */
i++;
file_creation_day = (uint8_t)atoi(argv[i]);
i++;
file_creation_year = (uint8_t)atoi(argv[i]);
change_header = TRUE;
}
- else if ( strcmp(argv[i],"--skip_vlr") == 0 ||
- strcmp(argv[i],"--no_vlr") == 0)
+ else if (strcmp(argv[i],"--skip_vlr") == 0 || strcmp(argv[i],"--no_vlr") == 0)
{
skip_vlr = TRUE;
}
@@ -215,33 +197,31 @@
fprintf(stderr, "ERROR: unknown argument '%s'\n",argv[i]);
}
}
-
+
if (use_stdin) {
file_name = "stdin";
}
-
+
if (!file_name) {
LASError_Print("No filename was provided to be opened");
usage();
exit(1);
}
-
+
reader = LASReader_Create(file_name);
if (!reader) {
LASError_Print("Could not open file ");
exit(1);
}
-
+
header = LASReader_GetHeader(reader);
if (!header) {
LASError_Print("Could not get LASHeader ");
exit(1);
}
-
-
print_header(stdout, header, file_name, skip_vlr);
-
+
if (change_header) {
if (system_identifier) {
err = LASHeader_SetSystemId (header, system_identifier);
@@ -263,11 +243,11 @@
LASReader_Destroy(reader);
reader = NULL;
}
-
+
writer = LASWriter_Create(file_name, header, LAS_MODE_APPEND);
if (!writer) {
LASError_Print("Problem creating LASWriterH object");
- LASHeader_Destroy(header);
+ LASHeader_Destroy(header);
header = NULL;
exit(1);
}
@@ -277,7 +257,7 @@
if (header) LASHeader_Destroy(header);
header = NULL;
}
-
+
if (check_points)
{
if (!reader) {
@@ -287,7 +267,7 @@
exit(1);
}
}
-
+
if (! header) {
header = LASReader_GetHeader(reader);
if (!header) {
@@ -295,23 +275,21 @@
exit(1);
}
}
-
+
if (!summary)
summary = SummarizePoints(reader);
print_point_summary(stdout, summary, header);
-
+
if (repair_header) {
fprintf(stdout, "\n---------------------------------------------------------\n");
fprintf(stdout, " Repair Summary\n");
fprintf(stdout, "---------------------------------------------------------\n");
-
if (use_stdin) {
LASError_Print("Cannot update header information on piped input!");
exit(1);
}
-
if (! header) {
header = LASReader_GetHeader(reader);
if (!header) {
@@ -319,7 +297,7 @@
exit(1);
}
}
-
+
if (! repair_bounding_box) {
if ( LASHeader_GetMinX(header) != LASPoint_GetX(summary->pmin) )
repair_bounding_box = TRUE;
@@ -335,31 +313,29 @@
if ( LASHeader_GetMaxZ(header) != LASPoint_GetZ(summary->pmax) )
repair_bounding_box = TRUE;
}
-
+
if (repair_bounding_box) {
fprintf(stdout, " Reparing Bounding Box...\n");
err = LASHeader_SetMin( header,
- LASPoint_GetX(summary->pmin),
- LASPoint_GetY(summary->pmin),
- LASPoint_GetZ(summary->pmin)
- );
+ LASPoint_GetX(summary->pmin),
+ LASPoint_GetY(summary->pmin),
+ LASPoint_GetZ(summary->pmin)
+ );
if (err) {
LASError_Print("Could not set minimum for header ");
exit(1);
}
err = LASHeader_SetMax( header,
- LASPoint_GetX(summary->pmax),
- LASPoint_GetY(summary->pmax),
- LASPoint_GetZ(summary->pmax)
- );
+ LASPoint_GetX(summary->pmax),
+ LASPoint_GetY(summary->pmax),
+ LASPoint_GetZ(summary->pmax)
+ );
if (err) {
LASError_Print("Could not set minimum for header ");
exit(1);
}
-
}
-
for (i = 0; i < 5; i++) {
if (LASHeader_GetPointRecordsByReturnCount(header, i) !=
@@ -369,28 +345,25 @@
break;
}
}
-
+
if (update_return_counts) {
fprintf(stdout, " Reparing Point Count by Return...\n");
for (i = 0; i < 5; i++) {
LASHeader_SetPointRecordsByReturnCount( header,
- i,
- summary->number_of_points_by_return[i]);
+ i,
+ summary->number_of_points_by_return[i]);
}
}
-
-
-
if (reader) {
LASReader_Destroy(reader);
reader = NULL;
}
-
+
writer = LASWriter_Create(file_name, header, LAS_MODE_APPEND);
if (!writer) {
LASError_Print("Problem creating LASWriterH object for append");
- LASHeader_Destroy(header);
+ LASHeader_Destroy(header);
header = NULL;
exit(1);
}
@@ -398,21 +371,18 @@
writer = NULL;
LASHeader_Destroy(header);
header = NULL;
-
-
- }
- if (summary) {
- LASPoint_Destroy(summary->pmin);
- LASPoint_Destroy(summary->pmax);
- free(summary);
+ }
- }
+ if (summary) {
+ LASPoint_Destroy(summary->pmin);
+ LASPoint_Destroy(summary->pmax);
+ free(summary);
+
+ }
+ }
-}
-
- if (reader) LASReader_Destroy(reader);
- if (header) LASHeader_Destroy(header);
-
+ if (reader) LASReader_Destroy(reader);
+ if (header) LASHeader_Destroy(header);
- return 0;
+ return 0;
}
More information about the Liblas-commits
mailing list