LensFlareVisualPlugin.cc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2017 Open Source Robotics Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. #include <gazebo/rendering/Camera.hh>
  18. #include <gazebo/rendering/UserCamera.hh>
  19. #include <gazebo/rendering/Scene.hh>
  20. #include <gazebo/rendering/LensFlare.hh>
  21. #include <gazebo/rendering/RenderingIface.hh>
  22. #include "LensFlareVisualPlugin.hh"
  23. namespace gazebo
  24. {
  25. /// \internal
  26. /// \class LensFlareVisualPlugin LensFlareVisualPlugin.hh
  27. /// \brief Private data for the LensFlareVisualPlugin class.
  28. class LensFlareVisualPluginPrivate
  29. {
  30. /// \brief Lens flare
  31. public: std::vector<rendering::LensFlarePtr> lensFlares;
  32. };
  33. }
  34. using namespace gazebo;
  35. GZ_REGISTER_VISUAL_PLUGIN(LensFlareVisualPlugin)
  36. /////////////////////////////////////////////////
  37. LensFlareVisualPlugin::LensFlareVisualPlugin()
  38. : dataPtr(new LensFlareVisualPluginPrivate)
  39. {
  40. }
  41. /////////////////////////////////////////////////
  42. LensFlareVisualPlugin::~LensFlareVisualPlugin()
  43. {
  44. }
  45. /////////////////////////////////////////////////
  46. void LensFlareVisualPlugin::Load(rendering::VisualPtr _visual,
  47. sdf::ElementPtr /*_sdf*/)
  48. {
  49. if (!_visual)
  50. gzerr << "Invalid visual pointer." << std::endl;
  51. auto scene = _visual->GetScene();
  52. for (unsigned int i = 0; i < scene->CameraCount(); ++i)
  53. {
  54. this->AddLensFlare(scene->GetCamera(i));
  55. }
  56. for (unsigned int i = 0; i < scene->UserCameraCount(); ++i)
  57. {
  58. rendering::CameraPtr cam =
  59. boost::dynamic_pointer_cast<rendering::Camera>(
  60. scene->GetUserCamera(i));
  61. this->AddLensFlare(cam);
  62. }
  63. return;
  64. }
  65. /////////////////////////////////////////////////
  66. void LensFlareVisualPlugin::AddLensFlare(rendering::CameraPtr _camera)
  67. {
  68. if (!_camera)
  69. return;
  70. rendering::LensFlarePtr lensFlare;
  71. lensFlare.reset(new rendering::LensFlare);
  72. lensFlare->SetCamera(_camera);
  73. this->dataPtr->lensFlares.push_back(lensFlare);
  74. }