[Liblas-commits] r1008 - in trunk: include/liblas/capi python/liblas python/tests src

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Feb 10 15:46:52 EST 2009


Author: hobu
Date: Tue Feb 10 15:46:52 2009
New Revision: 1008
URL: http://liblas.org/changeset/1008

Log:
color implementation for C API and Python API

Added:
   trunk/python/liblas/color.py   (contents, props changed)
Modified:
   trunk/include/liblas/capi/liblas.h
   trunk/python/liblas/core.py
   trunk/python/liblas/point.py
   trunk/python/tests/Point.txt
   trunk/src/las_c_api.cpp

Modified: trunk/include/liblas/capi/liblas.h
==============================================================================
--- trunk/include/liblas/capi/liblas.h	(original)
+++ trunk/include/liblas/capi/liblas.h	Tue Feb 10 15:46:52 2009
@@ -59,7 +59,7 @@
 typedef struct LASHeaderHS *LASHeaderH;
 typedef struct LASGuidHS *LASGuidH;
 typedef struct LASVLRHS *LASVLRH;
-
+typedef struct LASColorHS *LASColorH;
 
 LAS_C_START
 
@@ -989,6 +989,70 @@
 */
 LAS_DLL LASError LASVLR_SetData(const LASVLRH hVLR, uint8_t* data, uint16_t length);
 
+
+/****************************************************************************/
+/* Color Operations                                                           */
+/****************************************************************************/
+
+/** Creates a new Color
+ *  @return a new Color
+*/
+LAS_DLL LASColorH LASColor_Create(void);
+
+/** Destroys a Color and removes it from the heap
+*/
+LAS_DLL void LASColor_Destroy(LASColorH hColor);
+
+/** Returns the red value for the color.
+ *  @return the red value for the color.
+*/
+LAS_DLL uint16_t LASColor_GetRed(const LASColorH hColor);
+
+/** Sets the red value for the color
+ *  @param hColor the opaque pointer to the LASColorH instance
+ *  @param value the value to set the red value to
+ *  @return an error number if an error occured.
+*/
+LAS_DLL LASError LASColor_SetRed(LASColorH hColor, uint16_t value);
+
+/** Returns the green value for the color.
+ *  @return the green value for the color.
+*/
+LAS_DLL uint16_t LASColor_GetGreen(const LASColorH hColor);
+
+/** Sets the green value for the color
+ *  @param hColor the opaque pointer to the LASColorH instance
+ *  @param value the value to set the green value to
+ *  @return an error number if an error occured.
+*/
+LAS_DLL LASError LASColor_SetGreen(LASColorH hColor, uint16_t value);
+
+/** Returns the blue value for the color.
+ *  @return the blue value for the color.
+*/
+LAS_DLL uint16_t LASColor_GetBlue(const LASColorH hColor);
+
+/** Sets the blue value for the color
+ *  @param hColor the opaque pointer to the LASColorH instance
+ *  @param value the value to set the blue value to
+ *  @return an error number if an error occured.
+*/
+LAS_DLL LASError LASColor_SetBlue(LASColorH hColor, uint16_t value);
+
+
+/** Returns the color for the LASPointH
+ *  @return the color for the LASPointH.
+*/
+LAS_DLL LASColorH LASPoint_GetColor(const LASPointH hPoint);
+
+/** Sets the color for the point
+ *  @param hPoint the opaque pointer to the LASPointH instance
+ *  @param hColor the opaque pointer to the LASColorH instance
+ *  @return an error number if an error occured.
+*/
+LAS_DLL LASError LASPoint_SetColor(LASPointH hPoint, const LASColorH hColor);
+
+
 LAS_C_END
 #endif
 

Added: trunk/python/liblas/color.py
==============================================================================
--- (empty file)
+++ trunk/python/liblas/color.py	Tue Feb 10 15:46:52 2009
@@ -0,0 +1,75 @@
+"""
+/******************************************************************************
+ * $Id$
+ *
+ * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
+ * Purpose:  Python Color implementation
+ * Author:   Howard Butler, hobu.inc at gmail.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2009, Howard Butler
+ *
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without 
+ * modification, are permitted provided that the following 
+ * conditions are met:
+ * 
+ *     * Redistributions of source code must retain the above copyright 
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright 
+ *       notice, this list of conditions and the following disclaimer in 
+ *       the documentation and/or other materials provided 
+ *       with the distribution.
+ *     * Neither the name of the Martin Isenburg or Iowa Department 
+ *       of Natural Resources nor the names of its contributors may be 
+ *       used to endorse or promote products derived from this software 
+ *       without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
+ * OF SUCH DAMAGE.
+ ****************************************************************************/
+ """
+import core
+import ctypes
+
+class Color(object):
+    def __init__(self, owned=True, handle=None):
+        if handle:
+            self.handle = handle
+        else:
+            self.handle = core.las.LASColor_Create()
+        self.owned = owned
+    def __del__(self):
+        if self.owned:
+            if self.handle and core:
+                core.las.LASColor_Destroy(self.handle)
+    
+    def get_red(self):
+        return core.las.LASColor_GetRed(self.handle)
+    def set_red(self, value):
+        return core.las.LASColor_SetRed(self.handle, value)
+    red = property(get_red, set_red)
+
+    def get_green(self):
+        return core.las.LASColor_GetGreen(self.handle)
+    def set_green(self, value):
+        return core.las.LASColor_SetGreen(self.handle, value)
+    green = property(get_green, set_green)
+    
+    def get_blue(self):
+        return core.las.LASColor_GetBlue(self.handle)
+    def set_blue(self, value):
+        return core.las.LASColor_SetBlue(self.handle, value)
+    blue = property(get_blue, set_blue)
+

Modified: trunk/python/liblas/core.py
==============================================================================
--- trunk/python/liblas/core.py	(original)
+++ trunk/python/liblas/core.py	Tue Feb 10 15:46:52 2009
@@ -529,3 +529,38 @@
 las.LASVLR_SetData.errcheck = check_value
 las.LASVLR_SetData.restype = ctypes.c_int
 
+
+las.LASColor_Create.errcheck = check_void
+las.LASColor_Create.restype = ctypes.c_void_p
+
+las.LASColor_Destroy.argtypes = [ctypes.c_void_p]
+las.LASColor_Destroy.errcheck = check_void_done
+
+
+las.LASColor_GetRed.restype = ctypes.c_short
+las.LASColor_GetRed.argtypes = [ctypes.c_void_p]
+las.LASColor_GetRed.errcheck = check_value
+las.LASColor_SetRed.restype = ctypes.c_int
+las.LASColor_SetRed.argtypes = [ctypes.c_void_p, ctypes.c_short]
+las.LASColor_SetRed.errcheck = check_return
+
+las.LASColor_GetGreen.restype = ctypes.c_short
+las.LASColor_GetGreen.argtypes = [ctypes.c_void_p]
+las.LASColor_GetGreen.errcheck = check_value
+las.LASColor_SetGreen.restype = ctypes.c_int
+las.LASColor_SetGreen.argtypes = [ctypes.c_void_p, ctypes.c_short]
+las.LASColor_SetGreen.errcheck = check_return
+
+las.LASColor_GetBlue.restype = ctypes.c_short
+las.LASColor_GetBlue.argtypes = [ctypes.c_void_p]
+las.LASColor_GetBlue.errcheck = check_value
+las.LASColor_SetBlue.restype = ctypes.c_int
+las.LASColor_SetBlue.argtypes = [ctypes.c_void_p, ctypes.c_short]
+las.LASColor_SetBlue.errcheck = check_return
+
+las.LASPoint_GetColor.argtypes = [ctypes.c_void_p]
+las.LASPoint_GetColor.errcheck = check_void
+las.LASPoint_GetColor.restype = ctypes.c_void_p
+
+las.LASPoint_SetColor.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
+las.LASPoint_SetColor.errcheck = check_return
\ No newline at end of file

Modified: trunk/python/liblas/point.py
==============================================================================
--- trunk/python/liblas/point.py	(original)
+++ trunk/python/liblas/point.py	Tue Feb 10 15:46:52 2009
@@ -44,6 +44,7 @@
 import datetime
 import time
 import math
+import color
 
 class Point(object):
     def __init__(self, owned=True, handle=None, copy=False):
@@ -213,3 +214,9 @@
         core.las.LASPoint_SetTime(self.handle,t)
     time = property(get_time, set_time)
 
+    def get_color(self):
+        return color.Color(handle=core.las.LASPoint_GetColor(self.handle))
+    
+    def set_color(self, value):
+        return core.las.LASPoint_SetColor(self.handle, value.handle)
+    color = property(get_color, set_color)
\ No newline at end of file

Modified: trunk/python/tests/Point.txt
==============================================================================
--- trunk/python/tests/Point.txt	(original)
+++ trunk/python/tests/Point.txt	Tue Feb 10 15:46:52 2009
@@ -73,4 +73,14 @@
   >>> p.intensity = 120
   >>> p.intensity
   120
-   
\ No newline at end of file
+  
+  >>> c = p.color
+  >>> c.red
+  0
+  >>> c.red = 124
+  >>> c.red
+  124
+  
+  >>> p.color = c
+  >>> p.color.red
+  124
\ No newline at end of file

Modified: trunk/src/las_c_api.cpp
==============================================================================
--- trunk/src/las_c_api.cpp	(original)
+++ trunk/src/las_c_api.cpp	Tue Feb 10 15:46:52 2009
@@ -58,6 +58,7 @@
 typedef struct LASHeaderHS *LASHeaderH;
 typedef struct LASGuidHS *LASGuidH;
 typedef struct LASVLRHS *LASVLRH;
+typedef struct LASColorHS *LASColorH;
 
 
 
@@ -1565,6 +1566,113 @@
     return strdup(id->to_string().c_str());
 }
 
+
+
+LAS_DLL LASColorH LASColor_Create(void) {
+    return (LASColorH) new LASColor();
+}
+
+LAS_DLL void LASColor_Destroy(LASColorH hColor){
+    VALIDATE_POINTER0(hColor, "LASColor_Destroy");
+    delete (LASColor*)hColor;
+    hColor = NULL;
+}
+
+LAS_DLL LASErrorEnum LASColor_SetRed(LASColorH hColor, liblas::uint16_t value) {
+    
+    VALIDATE_POINTER1(hColor, "LASColor_SetRed", LE_Failure);
+
+    try {
+        LASColor* color = ((LASColor*) hColor);
+        color->SetRed(value);
+    }
+    catch (std::exception const& e) {
+        LASError_PushError(LE_Failure, e.what(), "LASColor_SetRed");
+        return LE_Failure;
+    }
+
+    return LE_None;
+}
+
+LAS_DLL liblas::uint16_t LASColor_GetRed(LASColorH hColor) {
+    
+    VALIDATE_POINTER1(hColor, "LASColor_GetRed", 0);
+    
+    liblas::uint16_t value = ((LASColor*) hColor)->GetRed();
+    return value;
+}
+
+LAS_DLL LASErrorEnum LASColor_SetBlue(LASColorH hColor, liblas::uint16_t value) {
+    
+    VALIDATE_POINTER1(hColor, "LASColor_SetBlue", LE_Failure);
+
+    try {
+        LASColor* color = ((LASColor*) hColor);
+        color->SetBlue(value);
+    }
+    catch (std::exception const& e) {
+        LASError_PushError(LE_Failure, e.what(), "LASColor_SetBlue");
+        return LE_Failure;
+    }
+
+    return LE_None;
+}
+
+LAS_DLL liblas::uint16_t LASColor_GetBlue(LASColorH hColor) {
+    
+    VALIDATE_POINTER1(hColor, "LASColor_GetBlue", 0);
+    
+    liblas::uint16_t value = ((LASColor*) hColor)->GetBlue();
+    return value;
+}
+
+LAS_DLL LASErrorEnum LASColor_SetGreen(LASColorH hColor, liblas::uint16_t value) {
+    
+    VALIDATE_POINTER1(hColor, "LASColor_SetGreen", LE_Failure);
+
+    try {
+        LASColor* color = ((LASColor*) hColor);
+        color->SetGreen(value);
+    }
+    catch (std::exception const& e) {
+        LASError_PushError(LE_Failure, e.what(), "LASColor_SetGreen");
+        return LE_Failure;
+    }
+
+    return LE_None;
+}
+
+LAS_DLL liblas::uint16_t LASColor_GetGreen(LASColorH hColor) {
+    
+    VALIDATE_POINTER1(hColor, "LASColor_GetGreen", 0);
+    
+    liblas::uint16_t value = ((LASColor*) hColor)->GetGreen();
+    return value;
+}
+
+LAS_DLL LASColorH LASPoint_GetColor(const LASPointH hPoint) {
+    VALIDATE_POINTER1(hPoint, "LASPoint_GetColor", 0);
+    
+    LASColor color = ((LASPoint*) hPoint)->GetColor();
+    return (LASColorH) new LASColor(color);
+}
+
+LAS_DLL LASErrorEnum LASPoint_SetColor(LASPointH hPoint, const LASColorH hColor) {
+    
+    VALIDATE_POINTER1(hPoint, "LASPoint_SetColor", LE_Failure);
+    VALIDATE_POINTER1(hColor, "LASPoint_SetColor", LE_Failure);
+
+    try {
+        ((LASPoint*) hPoint)->SetColor(*((LASColor*)hColor));
+    }
+    catch (std::exception const& e) {
+        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetColor");
+        return LE_Failure;
+    }
+
+    return LE_None;
+}
+
 LAS_C_END
 
 #ifdef _MSC_VER


More information about the Liblas-commits mailing list