[Liblas-commits] hg: add {Get|Set}Data methods for LASPointH for
manipulating raw...
liblas-commits at liblas.org
liblas-commits at liblas.org
Thu Jan 20 13:55:48 EST 2011
details: http://hg.liblas.orghg/rev/104d1f1c250e
changeset: 2797:104d1f1c250e
user: Howard Butler <hobu.inc at gmail.com>
date: Thu Jan 20 12:55:22 2011 -0600
description:
add {Get|Set}Data methods for LASPointH for manipulating raw point data
diffstat:
include/liblas/capi/liblas.h | 18 +++++++++++
src/c_api.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 89 insertions(+), 1 deletions(-)
diffs (117 lines):
diff -r 39fbbdf0882b -r 104d1f1c250e include/liblas/capi/liblas.h
--- a/include/liblas/capi/liblas.h Thu Jan 20 12:15:41 2011 -0600
+++ b/include/liblas/capi/liblas.h Thu Jan 20 12:55:22 2011 -0600
@@ -508,6 +508,24 @@
LAS_DLL void LASPoint_SetHeader( LASPointH hPoint, const LASHeaderH hHeader);
+/** Gets the data stream for the VLR as an array of bytes. The length of this
+ * array should be the same as LASVLR_GetRecordLength. You must allocate it on
+ * the heap and you are responsible for its destruction.
+ * @param hPoint the LASPointH instance
+ * @param data a pointer to your array where you want the data copied
+ * @return LASErrorEnum
+*/
+LAS_DLL LASError LASPoint_GetData(const LASPointH hPoint, unsigned char* data);
+
+/** Sets the data stream for the Point as an array of bytes. The length of this
+ * array should be the same as LASPoint_GetHeader(LASHeader_GetDataRecordLength()). The data are copied into
+ * the Point .
+ * @param hPoint the LASPointH instance
+ * @param data a pointer to your array. It must be LASPoint_GetHeader(LASHeader_GetDataRecordLength()) in size
+ * @return LASErrorEnum
+*/
+LAS_DLL LASError LASPoint_SetData(LASPointH hPoint, unsigned char* data);
+
/****************************************************************************/
/* Header operations */
/****************************************************************************/
diff -r 39fbbdf0882b -r 104d1f1c250e src/c_api.cpp
--- a/src/c_api.cpp Thu Jan 20 12:15:41 2011 -0600
+++ b/src/c_api.cpp Thu Jan 20 12:55:22 2011 -0600
@@ -481,6 +481,76 @@
point->SetHeaderPtr(h);
}
+LAS_DLL LASErrorEnum LASPoint_SetData(LASPointH hPoint, unsigned char* data) {
+
+ VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetData", LE_Failure);
+ VALIDATE_LAS_POINTER1(data, "LASPoint_SetData", LE_Failure);
+
+ try {
+ liblas::Point* p = ((liblas::Point*) hPoint);
+ boost::uint16_t size = 0;
+
+ liblas::HeaderPtr h = p->GetHeaderPtr();
+ if (h.get())
+ {
+ size = h->GetDataRecordLength();
+ } else
+ {
+ size = liblas::DefaultHeader::get().GetDataRecordLength();
+ }
+
+ std::vector<boost::uint8_t> & d = p->GetData();
+ if (d.size() != size)
+ {
+ d.resize(size);
+ d.assign(0, size);
+ }
+
+ for (boost::uint16_t i=0; i < size; i++) {
+ d[i] = data[i];
+ }
+ }
+ catch (std::exception const& e) {
+ LASError_PushError(LE_Failure, e.what(), "LASPoint_SetData");
+ return LE_Failure;
+ }
+
+
+ return LE_None;
+}
+
+LAS_DLL LASErrorEnum LASPoint_GetData( const LASPointH hPoint, boost::uint8_t* data) {
+
+ VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetData", LE_Failure);
+ VALIDATE_LAS_POINTER1(data, "LASPoint_GetData", LE_Failure);
+
+ try {
+ liblas::Point* p = ((liblas::Point*) hPoint);
+ boost::uint16_t size = 0;
+ std::vector<boost::uint8_t> const& d = p->GetData();
+
+ liblas::HeaderPtr h = p->GetHeaderPtr();
+ if (h.get())
+ {
+ size = h->GetDataRecordLength();
+ } else
+ {
+ size = liblas::DefaultHeader::get().GetDataRecordLength();
+ }
+ for (boost::uint16_t i=0; i < size; i++) {
+ data[i] = d[i];
+ }
+ }
+ catch (std::exception const& e) {
+ LASError_PushError(LE_Failure, e.what(), "LASPoint_GetData");
+ return LE_Failure;
+ }
+
+
+ return LE_None;
+}
+
+
LAS_DLL void LASPoint_Destroy(LASPointH hPoint) {
VALIDATE_LAS_POINTER0(hPoint, "LASPoint_Destroy");
delete (liblas::Point*) hPoint;
@@ -1808,7 +1878,7 @@
try {
liblas::VariableRecord* vlr = ((liblas::VariableRecord*) hVLR);
- std::vector<boost::uint8_t> d = vlr->GetData();
+ std::vector<boost::uint8_t> const& d = vlr->GetData();
boost::uint16_t length = vlr->GetRecordLength();
for (boost::uint16_t i=0; i < length; i++) {
data[i] = d[i];
More information about the Liblas-commits
mailing list