-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Add new constructors to PCLVisualizer #2004
Merged
taketwo
merged 9 commits into
PointCloudLibrary:master
from
denix56:PCLVisualizerCustomRenderers
Oct 9, 2017
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9abebf0
Add new constructors to PCLVisualizer
21248c3
Replace raw pointers with smart pointers, code re-usage
19b308c
Fix indents, remove repeating code
9e95ccd
Remove double window resizing
1fe27c9
Add missed comment
492d6a5
Remove unused parameter
c1a3d85
Split construct into several small functions
6f4fe43
Fix one name per line issue
a0219bb
Add missing header file
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,62 +128,15 @@ pcl::visualization::PCLVisualizer::PCLVisualizer (const std::string &name, const | |
, exit_main_loop_timer_callback_ () | ||
, exit_callback_ () | ||
, rens_ (vtkSmartPointer<vtkRendererCollection>::New ()) | ||
, win_ () | ||
, win_ (vtkSmartPointer<vtkRenderWindow>::New ()) | ||
, style_ (vtkSmartPointer<pcl::visualization::PCLVisualizerInteractorStyle>::New ()) | ||
, cloud_actor_map_ (new CloudActorMap) | ||
, shape_actor_map_ (new ShapeActorMap) | ||
, coordinate_actor_map_ (new CoordinateActorMap) | ||
, camera_set_ () | ||
, camera_file_loaded_ (false) | ||
{ | ||
// Create a Renderer | ||
vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New (); | ||
ren->AddObserver (vtkCommand::EndEvent, update_fps_); | ||
// Add it to the list of renderers | ||
rens_->AddItem (ren); | ||
|
||
// FPS callback | ||
vtkSmartPointer<vtkTextActor> txt = vtkSmartPointer<vtkTextActor>::New (); | ||
update_fps_->actor = txt; | ||
update_fps_->pcl_visualizer = this; | ||
update_fps_->decimated = false; | ||
ren->AddActor (txt); | ||
txt->SetInput("0 FPS"); | ||
|
||
// Create a RendererWindow | ||
win_ = vtkSmartPointer<vtkRenderWindow>::New (); | ||
win_->SetWindowName (name.c_str ()); | ||
|
||
// Get screen size | ||
int scr_size_x = win_->GetScreenSize ()[0]; | ||
int scr_size_y = win_->GetScreenSize ()[1]; | ||
// Set the window size as 1/2 of the screen size | ||
win_->SetSize (scr_size_x / 2, scr_size_y / 2); | ||
|
||
// By default, don't use vertex buffer objects | ||
use_vbos_ = false; | ||
|
||
// Add all renderers to the window | ||
rens_->InitTraversal (); | ||
vtkRenderer* renderer = NULL; | ||
while ((renderer = rens_->GetNextItem ()) != NULL) | ||
win_->AddRenderer (renderer); | ||
|
||
// Set renderer window in case no interactor is created | ||
style_->setRenderWindow (win_); | ||
|
||
// Create the interactor style | ||
style_->Initialize (); | ||
style_->setRendererCollection (rens_); | ||
style_->setCloudActorMap (cloud_actor_map_); | ||
style_->setShapeActorMap (shape_actor_map_); | ||
style_->UseTimersOn (); | ||
style_->setUseVbos(use_vbos_); | ||
|
||
if (create_interactor) | ||
createInteractor (); | ||
|
||
win_->SetWindowName (name.c_str ()); | ||
construct (vtkSmartPointer<vtkRenderer>::New (), name, create_interactor); | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////////////////////// | ||
|
@@ -197,87 +150,61 @@ pcl::visualization::PCLVisualizer::PCLVisualizer (int &argc, char **argv, const | |
, exit_main_loop_timer_callback_ () | ||
, exit_callback_ () | ||
, rens_ (vtkSmartPointer<vtkRendererCollection>::New ()) | ||
, win_ () | ||
, win_ (vtkSmartPointer<vtkRenderWindow>::New ()) | ||
, style_ (style) | ||
, cloud_actor_map_ (new CloudActorMap) | ||
, shape_actor_map_ (new ShapeActorMap) | ||
, coordinate_actor_map_ (new CoordinateActorMap) | ||
, camera_set_ () | ||
, camera_file_loaded_ (false) | ||
{ | ||
// Create a Renderer | ||
vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New (); | ||
ren->AddObserver (vtkCommand::EndEvent, update_fps_); | ||
// Add it to the list of renderers | ||
rens_->AddItem (ren); | ||
|
||
// FPS callback | ||
vtkSmartPointer<vtkTextActor> txt = vtkSmartPointer<vtkTextActor>::New (); | ||
update_fps_->actor = txt; | ||
update_fps_->pcl_visualizer = this; | ||
update_fps_->decimated = false; | ||
ren->AddActor (txt); | ||
txt->SetInput("0 FPS"); | ||
|
||
// Create a RendererWindow | ||
win_ = vtkSmartPointer<vtkRenderWindow>::New (); | ||
win_->SetWindowName (name.c_str ()); | ||
|
||
// By default, don't use vertex buffer objects | ||
use_vbos_ = false; | ||
|
||
// Add all renderers to the window | ||
rens_->InitTraversal (); | ||
vtkRenderer* renderer = NULL; | ||
while ((renderer = rens_->GetNextItem ()) != NULL) | ||
win_->AddRenderer (renderer); | ||
|
||
// Set renderer window in case no interactor is created | ||
style_->setRenderWindow (win_); | ||
|
||
// Create the interactor style | ||
style_->Initialize (); | ||
style_->setRendererCollection (rens_); | ||
style_->setCloudActorMap (cloud_actor_map_); | ||
style_->setShapeActorMap (shape_actor_map_); | ||
style_->UseTimersOn (); | ||
|
||
// Get screen size | ||
int scr_size_x = win_->GetScreenSize ()[0]; | ||
int scr_size_y = win_->GetScreenSize ()[1]; | ||
|
||
// Set default camera parameters | ||
initCameraParameters (); | ||
|
||
// Parse the camera settings and update the internal camera | ||
camera_set_ = getCameraParameters (argc, argv); | ||
// Calculate unique camera filename for camera parameter saving/restoring | ||
if (!camera_set_) | ||
{ | ||
std::string camera_file = getUniqueCameraFile (argc, argv); | ||
if (!camera_file.empty ()) | ||
{ | ||
if (boost::filesystem::exists (camera_file) && style_->loadCameraParameters (camera_file)) | ||
{ | ||
camera_file_loaded_ = true; | ||
} | ||
else | ||
{ | ||
style_->setCameraFile (camera_file); | ||
} | ||
} | ||
} | ||
// Set the window size as 1/2 of the screen size or the user given parameter | ||
if (!camera_set_ && !camera_file_loaded_) | ||
{ | ||
win_->SetSize (scr_size_x/2, scr_size_y/2); | ||
win_->SetPosition (0, 0); | ||
} | ||
construct (argc, argv, vtkSmartPointer<vtkRenderer>::New (), name, create_interactor); | ||
} | ||
|
||
if (create_interactor) | ||
createInteractor (); | ||
///////////////////////////////////////////////////////////////////////////////////////////// | ||
pcl::visualization::PCLVisualizer::PCLVisualizer (vtkSmartPointer<vtkRenderer> ren, vtkSmartPointer<vtkRenderWindow> wind, | ||
const std::string &name, const bool create_interactor) | ||
: interactor_ () | ||
, update_fps_ (vtkSmartPointer<FPSCallback>::New ()) | ||
#if !((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4)) | ||
, stopped_ () | ||
, timer_id_ () | ||
#endif | ||
, exit_main_loop_timer_callback_ () | ||
, exit_callback_ () | ||
, rens_ (vtkSmartPointer<vtkRendererCollection>::New ()) | ||
, win_ (wind) | ||
, style_ (vtkSmartPointer<pcl::visualization::PCLVisualizerInteractorStyle>::New ()) | ||
, cloud_actor_map_ (new CloudActorMap) | ||
, shape_actor_map_ (new ShapeActorMap) | ||
, coordinate_actor_map_ (new CoordinateActorMap) | ||
, camera_set_ () | ||
, camera_file_loaded_ (false) | ||
{ | ||
construct (ren, name, create_interactor); | ||
} | ||
|
||
win_->SetWindowName (name.c_str ()); | ||
///////////////////////////////////////////////////////////////////////////////////////////// | ||
pcl::visualization::PCLVisualizer::PCLVisualizer (int &argc, char **argv, vtkSmartPointer<vtkRenderer> ren, vtkSmartPointer<vtkRenderWindow> wind, | ||
const std::string &name, PCLVisualizerInteractorStyle* style, const bool create_interactor) | ||
: interactor_ () | ||
, update_fps_ (vtkSmartPointer<FPSCallback>::New ()) | ||
#if !((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4)) | ||
, stopped_ () | ||
, timer_id_ () | ||
#endif | ||
, exit_main_loop_timer_callback_ () | ||
, exit_callback_ () | ||
, rens_ (vtkSmartPointer<vtkRendererCollection>::New ()) | ||
, win_ (wind) | ||
, style_ (style) | ||
, cloud_actor_map_ (new CloudActorMap) | ||
, shape_actor_map_ (new ShapeActorMap) | ||
, coordinate_actor_map_ (new CoordinateActorMap) | ||
, camera_set_ () | ||
, camera_file_loaded_ (false) | ||
{ | ||
construct (argc, argv, ren, name, create_interactor); | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////////////////////// | ||
|
@@ -387,6 +314,96 @@ pcl::visualization::PCLVisualizer::setupInteractor ( | |
// iren->SetPicker (pp); | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////////////////////// | ||
void pcl::visualization::PCLVisualizer::construct (vtkSmartPointer<vtkRenderer> ren, | ||
const std::string & name, const bool create_interactor, const bool resize_window) | ||
{ | ||
if (!ren) | ||
PCL_ERROR ("Passed pointer to renderer is 0"); | ||
|
||
if (!win_) | ||
PCL_ERROR ("Pointer to render window is 0"); | ||
// Create a Renderer | ||
ren->AddObserver (vtkCommand::EndEvent, update_fps_); | ||
// Add it to the list of renderers | ||
rens_->AddItem (ren); | ||
|
||
// FPS callback | ||
vtkSmartPointer<vtkTextActor> txt = vtkSmartPointer<vtkTextActor>::New (); | ||
update_fps_->actor = txt; | ||
update_fps_->pcl_visualizer = this; | ||
update_fps_->decimated = false; | ||
ren->AddActor (txt); | ||
txt->SetInput ("0 FPS"); | ||
|
||
win_->SetWindowName (name.c_str ()); | ||
if (resize_window) | ||
{ | ||
int scr_size_x = win_->GetScreenSize ()[0], | ||
scr_size_y = win_->GetScreenSize ()[1]; | ||
win_->SetSize (scr_size_x / 2, scr_size_y / 2); | ||
win_->SetPosition (0, 0); | ||
} | ||
// Set default camera parameters | ||
|
||
|
||
// By default, don't use vertex buffer objects | ||
use_vbos_ = false; | ||
|
||
// Add all renderers to the window | ||
rens_->InitTraversal (); | ||
vtkRenderer* renderer = NULL; | ||
while ((renderer = rens_->GetNextItem ()) != NULL) | ||
win_->AddRenderer (renderer); | ||
|
||
// Set renderer window in case no interactor is created | ||
style_->setRenderWindow (win_); | ||
|
||
// Create the interactor style | ||
style_->Initialize (); | ||
style_->setRendererCollection (rens_); | ||
style_->setCloudActorMap (cloud_actor_map_); | ||
style_->setShapeActorMap (shape_actor_map_); | ||
style_->UseTimersOn (); | ||
style_->setUseVbos (use_vbos_); | ||
|
||
if (create_interactor) | ||
createInteractor (); | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////////////////////// | ||
void pcl::visualization::PCLVisualizer::construct (int & argc, char ** argv, vtkSmartPointer<vtkRenderer> ren, const std::string & name, const bool create_interactor) | ||
{ | ||
construct (ren, name, create_interactor, false); | ||
initCameraParameters (); | ||
|
||
// Parse the camera settings and update the internal camera | ||
camera_set_ = getCameraParameters (argc, argv); | ||
// Calculate unique camera filename for camera parameter saving/restoring | ||
if (!camera_set_) | ||
{ | ||
std::string camera_file = getUniqueCameraFile (argc, argv); | ||
if (!camera_file.empty ()) | ||
{ | ||
if (boost::filesystem::exists (camera_file) && style_->loadCameraParameters (camera_file)) | ||
{ | ||
camera_file_loaded_ = true; | ||
} | ||
else | ||
{ | ||
style_->setCameraFile (camera_file); | ||
} | ||
} | ||
} | ||
if (!camera_set_ && !camera_file_loaded_) | ||
{ | ||
int scr_size_x = win_->GetScreenSize ()[0], | ||
scr_size_y = win_->GetScreenSize ()[1]; | ||
win_->SetSize (scr_size_x / 2, scr_size_y / 2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I miss something, but why do we need this conditional resizing/repositioning? Resizing already happened in the other |
||
win_->SetPosition (0, 0); | ||
} | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////////////////////// | ||
pcl::visualization::PCLVisualizer::~PCLVisualizer () | ||
{ | ||
|
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.
Please only declare one name per line.