Skip to content

Commit

Permalink
emplace_back
Browse files Browse the repository at this point in the history
  • Loading branch information
neka-nat committed Mar 15, 2024
1 parent 0eb7d8b commit df3a164
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion examples/cpp/kinematics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) {
auto poses = kin.ForwardKinematics();
auto meshes = kin.GetTransformedVisualGeometryMap(poses);
std::vector<std::shared_ptr<const geometry::Geometry>> geoms;
for (const auto& m: meshes) { geoms.push_back(m.second); };
for (const auto& m: meshes) { geoms.emplace_back(m.second); };
visualization::DrawGeometries(geoms);
return 0;
}
4 changes: 2 additions & 2 deletions src/cupoch/geometry/image.cu
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ ImagePyramid Image::FilterPyramid(const ImagePyramid &input,
std::vector<std::shared_ptr<Image>> output;
for (size_t i = 0; i < input.size(); i++) {
auto layer_filtered = input[i]->Filter(type);
output.push_back(layer_filtered);
output.emplace_back(layer_filtered);
}
return output;
}
Expand All @@ -549,7 +549,7 @@ ImagePyramid Image::BilateralFilterPyramid(const ImagePyramid &input,
for (size_t i = 0; i < input.size(); i++) {
auto layer_filtered =
input[i]->BilateralFilter(diameter, sigma_color, sigma_space);
output.push_back(layer_filtered);
output.emplace_back(layer_filtered);
}
return output;
}
Expand Down
6 changes: 3 additions & 3 deletions src/cupoch/geometry/image_factory.cu
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,17 @@ ImagePyramid Image::CreatePyramid(size_t num_of_levels,
if (i == 0) {
std::shared_ptr<Image> input_copy_ptr = std::make_shared<Image>();
*input_copy_ptr = *this;
pyramid_image.push_back(input_copy_ptr);
pyramid_image.emplace_back(input_copy_ptr);
} else {
if (with_gaussian_filter && num_of_channels_ == 1) {
// https://en.wikipedia.org/wiki/Pyramid_(image_processing)
auto level_b = pyramid_image[i - 1]->Filter(
Image::FilterType::Gaussian3);
auto level_bd = level_b->Downsample();
pyramid_image.push_back(level_bd);
pyramid_image.emplace_back(level_bd);
} else {
auto level_d = pyramid_image[i - 1]->Downsample();
pyramid_image.push_back(level_d);
pyramid_image.emplace_back(level_d);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/cupoch/geometry/rgbdimage.cu
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ RGBDImagePyramid RGBDImage::FilterPyramid(
auto depth_level_filtered = depth_level.Filter(type);
auto rgbd_image_level_filtered = std::make_shared<RGBDImage>(
RGBDImage(*color_level_filtered, *depth_level_filtered));
rgbd_image_pyramid_filtered.push_back(rgbd_image_level_filtered);
rgbd_image_pyramid_filtered.emplace_back(rgbd_image_level_filtered);
}
return rgbd_image_pyramid_filtered;
}
Expand All @@ -87,7 +87,7 @@ RGBDImagePyramid RGBDImage::BilateralFilterPyramidDepth(
depth_level.BilateralFilter(diameter, sigma_depth, sigma_space);
auto rgbd_image_level_filtered = std::make_shared<RGBDImage>(RGBDImage(
rgbd_image_pyramid[level]->color_, *depth_level_filtered));
rgbd_image_pyramid_filtered.push_back(
rgbd_image_pyramid_filtered.emplace_back(
std::move(rgbd_image_level_filtered));
}
return rgbd_image_pyramid_filtered;
Expand All @@ -106,7 +106,7 @@ RGBDImagePyramid RGBDImage::CreatePyramid(
for (size_t level = 0; level < num_of_levels; level++) {
auto rgbd_image_level = std::make_shared<RGBDImage>(
RGBDImage(*color_pyramid[level], *depth_pyramid[level]));
rgbd_image_pyramid.push_back(rgbd_image_level);
rgbd_image_pyramid.emplace_back(rgbd_image_level);
}
return rgbd_image_pyramid;
}
12 changes: 6 additions & 6 deletions src/cupoch/kinematics/kinematic_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ KinematicChain& KinematicChain::BuildFromURDF(const std::string& filename) {
for (std::map<std::string, urdf::JointSharedPtr>::const_iterator itr =
jmap.begin();
itr != jmap.end(); ++itr) {
joints.push_back(itr->second);
joints.emplace_back(itr->second);
}
int n_joints = joints.size();
std::vector<bool> has_root(n_joints, true);
Expand All @@ -84,11 +84,11 @@ KinematicChain& KinematicChain::BuildFromURDF(const std::string& filename) {
root_.joint_ = Joint("root_joint");
std::vector<ShapeInfo> collisions;
for (const auto& col : root_link->collision_array) {
collisions.push_back(ConvertCollision(col, root_path_));
collisions.emplace_back(ConvertCollision(col, root_path_));
}
std::vector<ShapeInfo> visuals;
for (const auto& vis : root_link->visual_array) {
visuals.push_back(ConvertVisual(vis, root_path_));
visuals.emplace_back(ConvertVisual(vis, root_path_));
}
root_.link_ = Link(root_link->name, collisions, visuals);
link_map_[root_.link_.name_] = &(root_.link_);
Expand Down Expand Up @@ -137,16 +137,16 @@ std::vector<std::shared_ptr<Frame>> KinematicChain::BuildChainRecurse(
auto link = lmap.at(joint->child_link_name);
std::vector<ShapeInfo> collisions;
for (const auto& col : link->collision_array) {
collisions.push_back(ConvertCollision(col, root_path_));
collisions.emplace_back(ConvertCollision(col, root_path_));
}
std::vector<ShapeInfo> visuals;
for (const auto& vis : link->visual_array) {
visuals.push_back(ConvertVisual(vis, root_path_));
visuals.emplace_back(ConvertVisual(vis, root_path_));
}
child->link_ = Link(link->name, collisions, visuals);
link_map_[child->link_.name_] = &(child->link_);
child->children_ = BuildChainRecurse(*child, lmap, joints);
children.push_back(child);
children.emplace_back(child);
}
}
return children;
Expand Down
2 changes: 1 addition & 1 deletion src/cupoch/utility/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void cupoch::utility::SplitString(std::vector<std::string> &tokens,
pos = str.find_first_of(delimiters, last_pos);
new_pos = (pos == std::string::npos ? str.length() : pos);
if (new_pos != last_pos || !trim_empty_str) {
tokens.push_back(str.substr(last_pos, new_pos - last_pos));
tokens.emplace_back(str.substr(last_pos, new_pos - last_pos));
}
last_pos = new_pos + 1;
}
Expand Down
8 changes: 4 additions & 4 deletions src/cupoch/visualization/visualizer/visualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ void Visualizer::BuildUtilities() {
grid_line_ptr_) == false) {
return;
}
utility_ptrs_.push_back(coordinate_frame_mesh_ptr_);
utility_renderer_ptrs_.push_back(coordinate_frame_mesh_renderer_ptr_);
utility_ptrs_.push_back(grid_line_ptr_);
utility_renderer_ptrs_.push_back(grid_line_renderer_ptr_);
utility_ptrs_.emplace_back(coordinate_frame_mesh_ptr_);
utility_renderer_ptrs_.emplace_back(coordinate_frame_mesh_renderer_ptr_);
utility_ptrs_.emplace_back(grid_line_ptr_);
utility_renderer_ptrs_.emplace_back(grid_line_renderer_ptr_);
}

void Visualizer::Run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void Visualizer::CopyViewStatusToClipboard() {
utility::LogError("Something is wrong copying view status.");
}
ViewTrajectory trajectory;
trajectory.view_status_.push_back(current_status);
trajectory.view_status_.emplace_back(current_status);
std::string clipboard_string;
if (io::WriteIJsonConvertibleToJSONString(clipboard_string, trajectory) ==
false) {
Expand Down
10 changes: 5 additions & 5 deletions src/python/cupoch_pybind/docstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void FunctionDoc::ParseArguments() {
std::vector<std::string> argument_tokens = GetArgumentTokens(pybind_doc_);
argument_docs_.clear();
for (const std::string& argument_token : argument_tokens) {
argument_docs_.push_back(ParseArgumentToken(argument_token));
argument_docs_.emplace_back(ParseArgumentToken(argument_token));
}
}

Expand Down Expand Up @@ -348,29 +348,29 @@ std::vector<std::string> FunctionDoc::GetArgumentTokens(
size_t pos = res.position(0) + (start_iter - str.cbegin());
start_iter = res.suffix().first;
// Now the pos include ", ", which needs to be removed
argument_start_positions.push_back(pos + 2);
argument_start_positions.emplace_back(pos + 2);
}

// Get end positions (non-inclusive)
// The 1st argument's end pos is 2nd argument's start pos - 2 and etc.
// The last argument's end pos is the location of the parenthesis before ->
std::vector<size_t> argument_end_positions;
for (size_t i = 0; i + 1 < argument_start_positions.size(); ++i) {
argument_end_positions.push_back(argument_start_positions[i + 1] - 2);
argument_end_positions.emplace_back(argument_start_positions[i + 1] - 2);
}
std::size_t arrow_pos = str.rfind(") -> ");
if (arrow_pos == std::string::npos) {
return {};
} else {
argument_end_positions.push_back(arrow_pos);
argument_end_positions.emplace_back(arrow_pos);
}

std::vector<std::string> argument_tokens;
for (size_t i = 0; i < argument_start_positions.size(); ++i) {
std::string token = str.substr(
argument_start_positions[i],
argument_end_positions[i] - argument_start_positions[i]);
argument_tokens.push_back(token);
argument_tokens.emplace_back(token);
}
return argument_tokens;
}
Expand Down

0 comments on commit df3a164

Please sign in to comment.