22 namespace visualization {
39 return Eigen::Vector2d(0.0, 0.0);
41 auto itr_x = std::min_element(
43 [](
const Eigen::Vector2d &a,
const Eigen::Vector2d &b) {
46 auto itr_y = std::min_element(
48 [](
const Eigen::Vector2d &a,
const Eigen::Vector2d &b) {
51 return Eigen::Vector2d((*itr_x)(0), (*itr_y)(1));
56 return Eigen::Vector2d(0.0, 0.0);
58 auto itr_x = std::max_element(
60 [](
const Eigen::Vector2d &a,
const Eigen::Vector2d &b) {
63 auto itr_y = std::max_element(
65 [](
const Eigen::Vector2d &a,
const Eigen::Vector2d &b) {
68 return Eigen::Vector2d((*itr_x)(0), (*itr_y)(1));
79 std::vector<int> nodes;
80 for (
int y = 0; y <
height; y++) {
82 for (
size_t i = 0; i <
polygon_.size(); i++) {
83 size_t j = (i + 1) %
polygon_.size();
94 std::sort(nodes.begin(), nodes.end());
95 for (
size_t i = 0; i < nodes.size(); i += 2) {
96 if (nodes[i] >=
width) {
99 if (nodes[i + 1] > 0) {
100 if (nodes[i] < 0) nodes[i] = 0;
101 if (nodes[i + 1] >
width) nodes[i + 1] =
width;
102 for (
int x = nodes[i]; x < nodes[i + 1]; x++) {
113 return std::make_shared<ccPointCloud>();
117 return CropPointCloudInRectangle(input, view);
119 return CropPointCloudInPolygon(input, view);
122 return std::shared_ptr<ccPointCloud>();
129 return std::make_shared<ccMesh>(
nullptr);
133 "ccMesh contains vertices, but no triangles; "
134 "cropping will always yield an empty "
136 return std::make_shared<ccMesh>(
nullptr);
140 return CropTriangleMeshInRectangle(input, view);
142 return CropTriangleMeshInPolygon(input, view);
145 return std::shared_ptr<ccMesh>();
149 std::shared_ptr<SelectionPolygonVolume>
151 auto volume = std::make_shared<SelectionPolygonVolume>();
153 if (!editing_view.IsLocked() ||
158 switch (editing_view.GetEditingMode()) {
161 volume->orthogonal_axis_ =
"X";
166 volume->orthogonal_axis_ =
"Y";
171 volume->orthogonal_axis_ =
"Z";
182 volume->bounding_polygon_.push_back(point3d);
186 boundingbox.
GetMaxBound()(idx) - boundingbox.GetMinBound()(idx);
187 volume->axis_min_ = boundingbox.GetMinBound()(idx) - axis_len;
188 volume->axis_max_ = boundingbox.GetMaxBound()(idx) + axis_len;
192 std::shared_ptr<ccPointCloud> SelectionPolygon::CropPointCloudInRectangle(
197 std::shared_ptr<ccPointCloud> SelectionPolygon::CropPointCloudInPolygon(
202 std::shared_ptr<ccMesh> SelectionPolygon::CropTriangleMeshInRectangle(
203 const ccMesh &input,
const ViewControl &view) {
207 std::shared_ptr<ccMesh> SelectionPolygon::CropTriangleMeshInPolygon(
208 const ccMesh &input,
const ViewControl &view) {
212 std::vector<size_t> SelectionPolygon::CropInRectangle(
213 const std::vector<CCVector3> &input,
const ViewControl &view) {
214 std::vector<size_t> output_index;
215 Eigen::Matrix4d mvp_matrix = view.GetMVPMatrix().cast<
double>();
216 double half_width = (double)view.GetWindowWidth() * 0.5;
217 double half_height = (double)view.GetWindowHeight() * 0.5;
220 utility::ConsoleProgressBar
progress_bar((int64_t)input.size(),
221 "Cropping geometry: ");
222 for (
size_t i = 0; i < input.size(); i++) {
224 const auto &
point = input[i];
225 Eigen::Vector4d pos =
227 if (pos(3) == 0.0)
break;
229 double x = (pos(0) + 1.0) * half_width;
230 double y = (pos(1) + 1.0) * half_height;
231 if (x >= min_bound(0) && x <= max_bound(0) && y >= min_bound(1) &&
233 output_index.push_back(i);
239 std::vector<size_t> SelectionPolygon::CropInPolygon(
240 const std::vector<CCVector3> &input,
const ViewControl &view) {
241 std::vector<size_t> output_index;
242 Eigen::Matrix4d mvp_matrix = view.GetMVPMatrix().cast<
double>();
243 double half_width = (double)view.GetWindowWidth() * 0.5;
244 double half_height = (double)view.GetWindowHeight() * 0.5;
245 std::vector<double> nodes;
246 utility::ConsoleProgressBar
progress_bar((int64_t)input.size(),
247 "Cropping geometry: ");
248 for (
size_t k = 0; k < input.size(); k++) {
250 const auto &
point = input[k];
251 Eigen::Vector4d pos =
253 if (pos(3) == 0.0)
break;
255 double x = (pos(0) + 1.0) * half_width;
256 double y = (pos(1) + 1.0) * half_height;
258 for (
size_t i = 0; i <
polygon_.size(); i++) {
259 size_t j = (i + 1) %
polygon_.size();
268 std::sort(nodes.begin(), nodes.end());
269 auto loc = std::lower_bound(nodes.begin(), nodes.end(), x);
270 if (std::distance(nodes.begin(), loc) % 2 == 1) {
271 output_index.push_back(k);
utility::CountingProgressReporter * progress_bar
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
std::shared_ptr< ccMesh > SelectByIndex(const std::vector< size_t > &indices, bool cleanup=true) const
const std::vector< CCVector3 > & getVertices() const
ccGenericPointCloud * getAssociatedCloud() const override
Returns the vertices cloud.
virtual unsigned size() const override
Returns the number of triangles.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
std::shared_ptr< ccPointCloud > SelectByIndex(const std::vector< size_t > &indices, bool invert=false) const
Function to select points from input ccPointCloud into output ccPointCloud.
std::vector< CCVector3 > & getPoints()
Image & Prepare(int width, int height, int num_of_channels, int bytes_per_channel)
Prepare Image properties and allocate Image buffer.
std::vector< uint8_t > data_
Image storage buffer.
void FillPolygon(int width, int height)
std::vector< Eigen::Vector2d > polygon_
std::shared_ptr< ccMesh > CropTriangleMesh(const ccMesh &input, const ViewControl &view)
SectionPolygonType polygon_type_
SelectionPolygon & Clear()
virtual Eigen::Vector2d GetMax2DBound() const override
std::shared_ptr< ccPointCloud > CropPointCloud(const ccPointCloud &input, const ViewControl &view)
std::shared_ptr< SelectionPolygonVolume > CreateSelectionPolygonVolume(const ViewControl &view)
virtual Eigen::Vector2d GetMin2DBound() const override
geometry::Image polygon_interior_mask_
View controller for visualizer.
int GetWindowWidth() const
int GetWindowHeight() const
const ccBBox & GetBoundingBox() const
gl_util::GLMatrix4f GetMVPMatrix() const
Eigen::Vector3d Unproject(const Eigen::Vector3d &screen_point, const GLMatrix4f &mvp_matrix, const int width, const int height)
Generic file read and write utility for python interface.