Skip to content
Snippets Groups Projects
Commit 8b3e274e authored by Andrew Wilson's avatar Andrew Wilson :elephant:
Browse files

Merge branch 'feature/screenshot-names' into 'master'

Enable screenshots to be named with a specific name

See merge request iMSTK/iMSTK!549
parents 4d0097fc 05b25e79
No related branches found
No related tags found
No related merge requests found
......@@ -29,24 +29,23 @@
namespace imstk
{
VTKScreenCaptureUtility::VTKScreenCaptureUtility(vtkRenderWindow* const rw, const std::string prefix /*= "Screenshot-"*/) :
ScreenCaptureUtility(prefix),
m_windowToImageFilter(vtkSmartPointer<vtkWindowToImageFilter>::New()),
m_pngWriter(vtkSmartPointer<vtkPNGWriter>::New())
{
m_screenShotNumber = 0;
m_screenShotPrefix = prefix;
if (rw != nullptr)
{
m_renderWindow = rw;
}
}
void
VTKScreenCaptureUtility::saveScreenShot()
std::string
VTKScreenCaptureUtility::saveScreenShot(const std::string& captureName)
{
if (m_renderWindow == nullptr)
{
LOG(WARNING) << "Render window has not been set yet! ";
return;
return "";
}
if (m_windowToImageFilter->GetInput() == nullptr)
......@@ -63,13 +62,13 @@ VTKScreenCaptureUtility::saveScreenShot()
m_windowToImageFilter->Modified();
std::string captureName = m_screenShotPrefix + std::to_string(m_screenShotNumber) + ".png";
std::string filename = captureName + ".png";
m_pngWriter->SetFileName(captureName.data());
m_pngWriter->SetFileName(filename.data());
m_pngWriter->Write();
LOG(INFO) << "Screen shot " << m_screenShotNumber << " saved as " << captureName << "\n";
m_screenShotNumber++;
return filename;
}
} // imstk
......@@ -39,6 +39,8 @@ namespace imstk
class VTKScreenCaptureUtility : public ScreenCaptureUtility
{
public:
using ScreenCaptureUtility::saveScreenShot;
///
/// \brief Constructor
///
......@@ -52,7 +54,7 @@ public:
///
/// \brief Saves the screenshot as a png file
///
virtual void saveScreenShot() override;
virtual std::string saveScreenShot(const std::string& captureName) override;
protected:
vtkSmartPointer<vtkWindowToImageFilter> m_windowToImageFilter;
......
......@@ -26,16 +26,14 @@
namespace imstk
{
VulkanScreenCaptureUtility::VulkanScreenCaptureUtility(const std::string prefix /*= "Screenshot-"*/)
ScreenCaptureUtility(prefix)
{
m_screenShotNumber = 0;
m_screenShotPrefix = prefix;
}
void
VulkanScreenCaptureUtility::saveScreenShot()
std::string
VulkanScreenCaptureUtility::saveScreenShot(const std::string)
{
LOG(WARNING) << "Screen capture not supported\n";
m_screenShotNumber++;
return "";
}
} // imstk
......@@ -48,7 +48,7 @@ public:
///
/// \brief Saves the screenshot as a png file
///
virtual void saveScreenShot();
std::string saveScreenShot(const std::string&) override;
protected:
};
......
......@@ -23,6 +23,18 @@
namespace imstk
{
ScreenCaptureUtility::ScreenCaptureUtility(std::string prefix) : m_screenShotPrefix(prefix), m_screenShotNumber(0)
{
}
std::string
ScreenCaptureUtility::saveScreenShot()
{
std::string captureName = m_screenShotPrefix + std::to_string(m_screenShotNumber) + ".png";
++m_screenShotNumber;
return saveScreenShot(captureName);
}
unsigned int
ScreenCaptureUtility::getScreenShotNumber() const
{
......
......@@ -34,35 +34,46 @@ class ScreenCaptureUtility
{
public:
///
/// \brief Saves the screenshot as a png file
/// \brief Constructor
///
ScreenCaptureUtility(std::string prefix = "Screenshot-");
///
/// \brief Saves a screenshot with a name of <prefix><screenshotNumber>.<implementationImageType>
/// the <ImplementationImageType> is most likely `.png`.
/// \return the file name that was actually used to store the file, "" if the file storage failed
std::string saveScreenShot();
///
virtual void saveScreenShot() = 0;
/// \brief Saves a screenshot with the given name, the implementation will add the image
/// type used to store the file
/// \param name base name for the file to store
/// \return the file name that was actually used to store the file, "" if the file storage failed
virtual std::string saveScreenShot(const std::string& name) = 0;
///
/// \brief Returns the number of the screenshot
/// \brief Returns the number of the next screenshot
///
unsigned int getScreenShotNumber() const;
///
/// \brief set/reset the prefix amd the count numbers
/// \brief set/reset the prefix and the count numbers
///
void setScreenShotPrefix(const std::string& newPrefix);
///
/// \brief reset the screenshot number indicator
/// \brief reset the screenshot number
///
void resetScreenShotNumber();
protected:
///
/// \brief Constructor
///
ScreenCaptureUtility() = default;
///
/// \brief Destructor
///
virtual ~ScreenCaptureUtility() = default;
unsigned int m_screenShotNumber = 0; //> screen shot number is added to the file prefix, and incremented everytime a screen shot is taken
std::string m_screenShotPrefix; //> the prefix for the screenshots to be saved
unsigned int m_screenShotNumber = 0; ///< screen shot number is added to the file prefix, and incremented everytime a screen shot is taken
std::string m_screenShotPrefix; ///< the prefix for the screenshots to be saved
};
} // imstk
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment