mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-10-05 01:49:02 +00:00
Image was upside down; flip it over, demo usage.
This commit is contained in:
parent
4e76c00a42
commit
1d4ebaec9f
@ -202,7 +202,7 @@ scene.AddActor(vtkm::rendering::Actor(outputData.GetCellSet(),
|
||||
vtkm::rendering::View3D view(scene, mapper, canvas, camera, bg);
|
||||
view.Initialize();
|
||||
view.Paint();
|
||||
view.SaveAs("demo_output.pnm");
|
||||
view.SaveAs("demo_output.png");
|
||||
```
|
||||
|
||||
A minimal CMakeLists.txt such as the following one can be used to build this
|
||||
|
@ -124,8 +124,12 @@ void TubeThatSpiral(vtkm::FloatDefault radius, vtkm::Id numLineSegments, vtkm::I
|
||||
vtkm::rendering::View3D view(scene, mapper, canvas, camera, bg);
|
||||
view.Initialize();
|
||||
view.Paint();
|
||||
// We can save the file as a .NetBPM:
|
||||
std::string output_filename = "tube_output_" + std::to_string(numSides) + "_sides.pnm";
|
||||
view.SaveAs(output_filename);
|
||||
// Or as a .png:
|
||||
output_filename = "tube_output_" + std::to_string(numSides) + "_sides.png";
|
||||
view.SaveAs(output_filename);
|
||||
}
|
||||
|
||||
|
||||
|
@ -583,13 +583,14 @@ void Canvas::SaveAs(const std::string& fileName) const
|
||||
|
||||
if (ends_with(fileName, ".png"))
|
||||
{
|
||||
std::vector<unsigned char> img(static_cast<size_t>(width * height));
|
||||
std::vector<unsigned char> img(static_cast<size_t>(4 * width * height));
|
||||
for (vtkm::Id yIndex = height - 1; yIndex >= 0; yIndex--)
|
||||
{
|
||||
for (vtkm::Id xIndex = 0; xIndex < width; xIndex++)
|
||||
{
|
||||
vtkm::Vec4f_32 tuple = colorPortal.Get(yIndex * width + xIndex);
|
||||
size_t idx = static_cast<size_t>(4 * width * yIndex + 4 * xIndex);
|
||||
// y = 0 is the top of a .png file.
|
||||
size_t idx = static_cast<size_t>(4 * width * (height - 1 - yIndex) + 4 * xIndex);
|
||||
img[idx + 0] = (unsigned char)(tuple[0] * 255);
|
||||
img[idx + 1] = (unsigned char)(tuple[1] * 255);
|
||||
img[idx + 2] = (unsigned char)(tuple[2] * 255);
|
||||
|
Loading…
Reference in New Issue
Block a user