[Liblas-commits] libpc: added Color (from liblas)
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Feb 11 17:00:46 EST 2011
details: http://hg.liblas.orglibpc/rev/f1c9ab596938
changeset: 42:f1c9ab596938
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Feb 11 13:45:24 2011 -0800
description:
added Color (from liblas)
Subject: libpc: moved in some utility funcs
details: http://hg.liblas.orglibpc/rev/0083f658832d
changeset: 43:0083f658832d
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Feb 11 14:00:41 2011 -0800
description:
moved in some utility funcs
diffstat:
apps/pc2pc.cpp | 3 +
include/libpc/Color.hpp | 156 ++++++++++++++++++++++++++++++++++++++++++++++++
include/libpc/Utils.hpp | 23 ++----
src/CMakeLists.txt | 2 +
src/Color.cpp | 101 +++++++++++++++++++++++++++++++
src/Utils.cpp | 70 +++++++++++++++++++++-
6 files changed, 340 insertions(+), 15 deletions(-)
diffs (truncated from 431 to 300 lines):
diff -r 9bce9c5cf461 -r 0083f658832d apps/pc2pc.cpp
--- a/apps/pc2pc.cpp Fri Feb 11 13:35:19 2011 -0800
+++ b/apps/pc2pc.cpp Fri Feb 11 14:00:41 2011 -0800
@@ -14,6 +14,7 @@
#include "libpc/version.hpp"
#include "libpc/version.hpp"
#include "libpc/Bounds.hpp"
+#include "libpc/Color.hpp"
#include "libpc/Dimension.hpp"
#include "libpc/Schema.hpp"
@@ -48,6 +49,8 @@
std::cout << schema;
}
+ Color c;
+
return 0;
}
#if 0
diff -r 9bce9c5cf461 -r 0083f658832d include/libpc/Color.hpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/include/libpc/Color.hpp Fri Feb 11 14:00:41 2011 -0800
@@ -0,0 +1,156 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Project: libLAS - http://liblas.org - A BSD library for LAS format data.
+ * Purpose: LAS color class
+ * Author: Howard Butler, hobu.inc at gmail.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2008, 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 rede 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.
+ ****************************************************************************/
+
+#ifndef LIBPC_COLOR_HPP_INCLUDED
+#define LIBPC_COLOR_HPP_INCLUDED
+
+#include <libpc/export.hpp>
+
+// boost
+#include <boost/array.hpp>
+#include <boost/cstdint.hpp>
+
+// std
+//#include <cstdlib> // std::size_t
+
+namespace libpc
+{
+
+/// RGB color container
+class LIBPC_DLL Color
+{
+public:
+ typedef boost::uint16_t value_type;
+
+ /// Default constructor.
+ /// Initializes with black color using RGB {0, 0, 0}.
+ Color();
+
+ /// User-defined constructor.
+ /// Initializes object with given RGB values.
+ /// \exception std::invalid_argument if color component value is out of range of unsigned 8-bit integer.
+ Color(boost::uint32_t red, boost::uint32_t green, boost::uint32_t blue);
+
+ /// User-defined constructor.
+ /// Initializes colour components based on values of 3-element array.
+ /// \exception std::invalid_argument if color component value is out of range of unsigned 8-bit integer.
+ Color(boost::array<value_type, 3> const& color);
+
+ /// Copy constructor.
+ Color(Color const& other);
+
+ /// Assignment operator.
+ Color& operator=(Color const& rhs);
+
+ /// Fetch value of the red image channel
+ value_type GetRed() const
+ {
+ return m_color[0];
+ }
+
+ /// Set value of the red image channel
+ void SetRed(value_type const& value)
+ {
+ m_color[0] = value;
+ }
+
+ /// Fetch value of the green image channel
+ value_type GetGreen() const
+ {
+ return m_color[1];
+ }
+
+ /// Set value of the red image channel
+ void SetGreen(value_type const& value)
+ {
+ m_color[1] = value;
+ }
+
+ /// Fetch value of the blue image channel
+ value_type GetBlue() const
+ {
+ return m_color[2];
+ }
+
+ /// Set value of the blue image channel
+ void SetBlue(value_type const& value)
+ {
+ m_color[2] = value;
+ }
+
+ /// Index operator providing access to RGB values.
+ /// Valid index values are 0, 1 or 2.
+ /// \exception std::out_of_range if requested index is out of range (> 2).
+ value_type& operator[](std::size_t const& index)
+ {
+ return m_color[index];
+ }
+
+ /// Const version of index operator providing access to RGB values.
+ /// Valid index values are 0, 1 or 2.
+ /// \exception std::out_of_range if requested index is out of range (> 2).
+ value_type const& operator[](std::size_t const& index) const
+ {
+ return m_color[index];
+ }
+
+private:
+ typedef boost::array<value_type, 3> base_type;
+ base_type m_color;
+
+ void throw_index_out_of_range() const;
+ void throw_invalid_color_component() const;
+};
+
+
+LIBPC_DLL inline bool operator==(Color const& lhs, Color const& rhs)
+{
+ return lhs[0] == rhs[0] && lhs[1] == rhs[1] && lhs[2] == rhs[2];
+}
+
+
+LIBPC_DLL inline bool operator!=(Color const& lhs, Color const& rhs)
+{
+ return !(lhs == rhs);
+}
+
+} // namespace libpc
+
+#endif // LIBPC_COLOR_HPP_INCLUDED
diff -r 9bce9c5cf461 -r 0083f658832d include/libpc/Utils.hpp
--- a/include/libpc/Utils.hpp Fri Feb 11 13:35:19 2011 -0800
+++ b/include/libpc/Utils.hpp Fri Feb 11 14:00:41 2011 -0800
@@ -35,8 +35,9 @@
#ifndef INCLUDED_UTILS_HPP
#define INCLUDED_UTILS_HPP
-#include <cassert>
-#include <limits>
+#include <iosfwd>
+#include <string>
+
#include "libpc/export.hpp"
namespace libpc
@@ -45,18 +46,7 @@
class LIBPC_DLL Utils
{
public:
- static double random(double min, double max)
- {
- double r = (double)rand(); // [0..32767]
- double v = (max - min) / (double)RAND_MAX;
- double s = r * v; // [0..(max-min)]
- double t = min + s; // [min..max]
-
- assert(t >= min);
- assert(t <= max);
-
- return t;
- }
+ static double random(double minimum, double maximum);
template<class T>
static bool compare_distance(const T& actual, const T& expected)
@@ -71,6 +61,11 @@
return true;
}
+ static std::istream* Open(std::string const& filename, std::ios::openmode mode=std::ios::in | std::ios::binary);
+ static std::ostream* Create(std::string const& filename, std::ios::openmode mode=std::ios::in | std::ios::binary);
+
+ static void Cleanup(std::ostream* ofs);
+ static void Cleanup(std::istream* ifs);
};
} // namespace libpc
diff -r 9bce9c5cf461 -r 0083f658832d src/CMakeLists.txt
--- a/src/CMakeLists.txt Fri Feb 11 13:35:19 2011 -0800
+++ b/src/CMakeLists.txt Fri Feb 11 14:00:41 2011 -0800
@@ -24,6 +24,7 @@
${LIBPC_HEADERS_DIR}/export.hpp
${LIBPC_HEADERS_DIR}/version.hpp
${LIBPC_HEADERS_DIR}/Bounds.hpp
+ ${LIBPC_HEADERS_DIR}/Color.hpp
${LIBPC_HEADERS_DIR}/ColorFilter.hpp
${LIBPC_HEADERS_DIR}/CropFilter.hpp
${LIBPC_HEADERS_DIR}/Dimension.hpp
@@ -45,6 +46,7 @@
set(LIBPC_CPP
version.cpp
Bounds.cpp
+ Color.cpp
ColorFilter.cpp
Dimension.cpp
FauxReader.cpp
diff -r 9bce9c5cf461 -r 0083f658832d src/Color.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Color.cpp Fri Feb 11 14:00:41 2011 -0800
@@ -0,0 +1,101 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Project: libLAS - http://liblas.org - A BSD library for LAS format data.
+ * Purpose: LAS color class
+ * Author: Howard Butler, hobu.inc at gmail.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2008, 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.
+ ****************************************************************************/
+
+#include <libpc/Color.hpp>
+
+// boost
+//#include <boost/cstdint.hpp>
+// std
+//#include <stdexcept>
+//#include <limits>
+
+namespace libpc
More information about the Liblas-commits
mailing list