-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Releaseable point cloud #24
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"""Contains the PointCloud class.""" | ||
import numpy | ||
|
||
import _zivid | ||
|
||
|
||
class PointCloud: | ||
"""A point cloud.""" | ||
|
||
def __init__(self, internal_point_cloud): | ||
"""Create a point cloud from an internal point cloud. | ||
|
||
Args: | ||
internal_point_cloud: a internal point cloud | ||
|
||
""" | ||
if not isinstance(internal_point_cloud, _zivid.PointCloud): | ||
raise ValueError( | ||
"Unsupported type for argument internal_point_cloud. Got {}, expected {}".format( | ||
type(internal_point_cloud), type(_zivid.PointCloud) | ||
) | ||
) | ||
self.__impl = internal_point_cloud | ||
|
||
def to_array(self): | ||
"""Convert point cloud to numpy array. | ||
|
||
Returns: | ||
a numpy array | ||
|
||
""" | ||
self.__impl.assert_not_released() | ||
return numpy.array(self.__impl) | ||
|
||
@property | ||
def height(self): | ||
"""Return height (number of rows) of point cloud. | ||
|
||
Returns: | ||
a positive integer | ||
|
||
""" | ||
return self.__impl.height() | ||
|
||
@property | ||
def width(self): | ||
"""Return width (number of columns) of point cloud. | ||
|
||
Returns: | ||
a positive integer | ||
|
||
""" | ||
return self.__impl.width() | ||
|
||
def release(self): | ||
"""Release the underlying resources.""" | ||
self.__impl.release() | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, exception_type, exception_value, traceback): | ||
self.release() | ||
|
||
def __del__(self): | ||
self.release() |
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 was deleted.
Oops, something went wrong.
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,20 @@ | ||
#pragma once | ||
|
||
#include <Zivid/PointCloud.h> | ||
#include <ZividPython/Releasable.h> | ||
#include <ZividPython/Wrappers.h> | ||
|
||
namespace ZividPython | ||
{ | ||
class ReleasablePointCloud : public Releasable<Zivid::PointCloud> | ||
{ | ||
public: | ||
using Releasable<Zivid::PointCloud>::Releasable; | ||
|
||
ZIVID_PYTHON_FORWARD_0_ARGS(width) | ||
ZIVID_PYTHON_FORWARD_0_ARGS(height) | ||
ZIVID_PYTHON_FORWARD_0_ARGS(dataPtr) | ||
}; | ||
|
||
void wrapClass(pybind11::class_<ReleasablePointCloud> pyClass); | ||
} // namespace ZividPython |
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 |
---|---|---|
@@ -1,17 +1,71 @@ | ||
def test_point_cloud_to_array(frame): | ||
def test_point_cloud_to_array(point_cloud): | ||
import numpy as np | ||
|
||
point_cloud = frame.get_point_cloud() | ||
np_array = np.array(point_cloud) | ||
np_array = point_cloud.to_array() | ||
assert np_array is not None | ||
assert isinstance(np_array, np.ndarray) | ||
|
||
|
||
def test_to_rgb_image(frame): | ||
def test_to_rgb_image(point_cloud): | ||
import numpy as np | ||
|
||
point_cloud = frame.get_point_cloud() | ||
image = point_cloud[["r", "g", "b"]] | ||
image = np.asarray([point_cloud["r"], point_cloud["g"], point_cloud["b"]]) | ||
np_array = point_cloud.to_array() | ||
image = np_array[["r", "g", "b"]] | ||
image = np.asarray([np_array["r"], np_array["g"], np_array["b"]]) | ||
image = np.moveaxis(image, [0, 1, 2], [2, 0, 1]) | ||
image = image.astype(np.uint8) | ||
|
||
|
||
def test_height(point_cloud): | ||
height = point_cloud.height | ||
|
||
assert height is not None | ||
assert isinstance(height, int) | ||
|
||
|
||
def test_width(point_cloud): | ||
width = point_cloud.width | ||
|
||
assert width is not None | ||
assert isinstance(width, int) | ||
|
||
|
||
def test_height_context_manager(frame): | ||
import pytest | ||
|
||
with frame.get_point_cloud() as point_cloud: | ||
point_cloud.height # pylint: disable=pointless-statement | ||
with pytest.raises(RuntimeError): | ||
point_cloud.height # pylint: disable=pointless-statement | ||
|
||
|
||
def test_width_context_manager(frame): | ||
import pytest | ||
|
||
with frame.get_point_cloud() as point_cloud: | ||
point_cloud.width # pylint: disable=pointless-statement | ||
with pytest.raises(RuntimeError): | ||
point_cloud.width # pylint: disable=pointless-statement | ||
|
||
|
||
def test_to_array_context_manager(frame): | ||
import pytest | ||
|
||
with frame.get_point_cloud() as point_cloud: | ||
point_cloud.to_array() | ||
with pytest.raises(RuntimeError): | ||
point_cloud.to_array() | ||
|
||
|
||
def test_illegal_init(application): # pylint: disable=unused-argument | ||
import pytest | ||
import zivid | ||
|
||
with pytest.raises(TypeError): | ||
zivid.PointCloud() # pylint: disable=no-value-for-parameter | ||
|
||
with pytest.raises(ValueError): | ||
zivid.PointCloud("Should fail.") | ||
|
||
with pytest.raises(ValueError): | ||
zivid.PointCloud(123) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should have a mixin or base class or something for these three functions. They are duplicated many places now.
You are just adding to the existing solution, so no need to fix in this PR. But if you agree please add an issue for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could probably be done through a decorator:
Will create an issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#27