-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split Bounds class from Box classes and out of Utils (#2473)
* Separate BOX and Bounds. * Include limits.
- Loading branch information
1 parent
051f10e
commit 0b06b87
Showing
28 changed files
with
236 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/****************************************************************************** | ||
* Copyright (c) 2019, Hobu Inc. (info@hobu.co) | ||
* | ||
* 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 Hobu, Inc. 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 <limits> | ||
|
||
#include <pdal/Bounds.hpp> | ||
|
||
namespace | ||
{ | ||
|
||
const double LOWEST = (std::numeric_limits<double>::lowest)(); | ||
const double HIGHEST = (std::numeric_limits<double>::max)(); | ||
|
||
} | ||
|
||
namespace pdal | ||
{ | ||
|
||
Bounds::Bounds(const BOX3D& box) : m_box(box) | ||
{} | ||
|
||
|
||
Bounds::Bounds(const BOX2D& box) : m_box(box) | ||
{ | ||
m_box.minz = HIGHEST; | ||
m_box.maxz = LOWEST; | ||
} | ||
|
||
|
||
// We don't allow implicit conversion from a BOX2D to BOX3D. Use the explicit | ||
// BOX3D ctor that takes a BOX2D if that's what you want. | ||
BOX3D Bounds::to3d() const | ||
{ | ||
if (!is3d()) | ||
return BOX3D(); | ||
return m_box; | ||
} | ||
|
||
|
||
BOX2D Bounds::to2d() const | ||
{ | ||
return m_box.to2d(); | ||
} | ||
|
||
|
||
bool Bounds::is3d() const | ||
{ | ||
return (m_box.minz != HIGHEST || m_box.maxz != LOWEST); | ||
} | ||
|
||
|
||
void Bounds::set(const BOX3D& box) | ||
{ | ||
m_box = box; | ||
} | ||
|
||
|
||
void Bounds::set(const BOX2D& box) | ||
{ | ||
m_box = BOX3D(box); | ||
m_box.minz = HIGHEST; | ||
m_box.maxz = LOWEST; | ||
} | ||
|
||
std::istream& operator>>(std::istream& in, Bounds& bounds) | ||
{ | ||
std::streampos start = in.tellg(); | ||
BOX3D b3d; | ||
in >> b3d; | ||
if (in.fail()) | ||
{ | ||
in.clear(); | ||
in.seekg(start); | ||
BOX2D b2d; | ||
in >> b2d; | ||
if (!in.fail()) | ||
bounds.set(b2d); | ||
} | ||
else | ||
bounds.set(b3d); | ||
return in; | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& out, const Bounds& bounds) | ||
{ | ||
if (bounds.is3d()) | ||
out << bounds.to3d(); | ||
else | ||
out << bounds.to2d(); | ||
return out; | ||
} | ||
|
||
} // namespace pdal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/****************************************************************************** | ||
* Copyright (c) 2019, Hobu Inc. (info@hobu.co) | ||
* | ||
* 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 Hobu, Inc. 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. | ||
****************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <pdal/util/Box.hpp> | ||
|
||
namespace pdal | ||
{ | ||
|
||
/** | ||
Wrapper for BOX3D and BOX2D to allow extraction as either. Typically used | ||
to facilitate streaming either a BOX2D or BOX3D | ||
*/ | ||
class PDAL_DLL Bounds | ||
{ | ||
public: | ||
Bounds() | ||
{} | ||
|
||
explicit Bounds(const BOX3D& box); | ||
explicit Bounds(const BOX2D& box); | ||
|
||
BOX3D to3d() const; | ||
BOX2D to2d() const; | ||
bool is3d() const; | ||
|
||
friend PDAL_DLL std::istream& operator >> (std::istream& in, | ||
Bounds& bounds); | ||
friend PDAL_DLL std::ostream& operator << (std::ostream& out, | ||
const Bounds& bounds); | ||
|
||
private: | ||
BOX3D m_box; | ||
|
||
void set(const BOX3D& box); | ||
void set(const BOX2D& box); | ||
}; | ||
|
||
PDAL_DLL std::istream& operator >> (std::istream& in, Bounds& bounds); | ||
PDAL_DLL std::ostream& operator << (std::ostream& in, const Bounds& bounds); | ||
|
||
} // namespace pdal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.