9#ifndef vtkWebGPUVolumeTestHelpers_h
10#define vtkWebGPUVolumeTestHelpers_h
37 if (
object ==
nullptr || std::string(object->
GetClassName()) != expected)
39 std::cerr <<
"Expected a " << expected <<
" but got "
40 << (
object !=
nullptr ?
object->GetClassName() :
"nothing") <<
".\n";
55 const unsigned char*
At(
int x,
int y)
const
57 return &this->Pixels[3 * (
static_cast<std::size_t
>(y) * this->Width + x)];
61 std::size_t
CountLit(
const double background[3],
int tolerance = 12)
const
63 std::size_t
count = 0;
64 for (std::size_t i = 0; i + 2 < this->Pixels.size(); i += 3)
67 for (
int c = 0; c < 3; ++c)
69 const int reference =
static_cast<int>(background[c] * 255.0 + 0.5);
70 lit = lit || std::abs(
static_cast<int>(this->Pixels[i + c]) - reference) > tolerance;
81 const int* size = window->
GetSize();
82 frame.
Width = size[0];
88 pixels->
GetPointer(0) +
static_cast<std::size_t
>(pixels->GetNumberOfValues()));
102 for (std::size_t i = 0; i < left.
Pixels.size(); ++i)
105 largest, std::abs(
static_cast<int>(left.
Pixels[i]) -
static_cast<int>(right.
Pixels[i])));
120 for (std::size_t i = 0; i < left.
Pixels.size(); ++i)
122 total += std::abs(
static_cast<int>(left.
Pixels[i]) -
static_cast<int>(right.
Pixels[i]));
124 return total / left.
Pixels.size();
131 const double range[2],
const double rgb[3] =
nullptr)
136 color->AddRGBPoint(range[0], 0.0, 0.0, 0.0);
137 color->AddRGBPoint(range[1], rgb[0], rgb[1], rgb[2]);
141 color->AddRGBPoint(range[0], 0.0, 0.1, 0.6);
142 color->AddRGBPoint(0.5 * (range[0] + range[1]), 0.1, 0.9, 0.3);
143 color->AddRGBPoint(range[1], 1.0, 0.8, 0.1);
147 opacity->AddPoint(range[0], 0.0);
148 opacity->AddPoint(0.5 * (range[0] + range[1]), 0.05);
149 opacity->AddPoint(range[1], 0.6);
152 property->SetColor(color);
153 property->SetScalarOpacity(opacity);
154 property->SetScalarOpacityUnitDistance(2.0);
155 property->SetInterpolationTypeToLinear();
Allocate and hold a VTK object.
T * GetPointer() const noexcept
Get a raw pointer to the contained object.
const char * GetClassName() const
Return the class name as a string.
abstract base class for most VTK objects
create a window for renderers to draw into
Hold a reference to a vtkObjectBase instance.
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
virtual unsigned char * GetPixelData(int, int, int, int, int, int=0)
Get the pixel data of an image, transmitted as RGBRGBRGB.
virtual int * GetSize()
Get the size (width and height) of the rendering window in screen coordinates (in pixels).
Shared scaffolding for the WebGPU volume tests: it pins the rendering backend, builds the transfer fu...
Frame Capture(vtkRenderWindow *window)
vtkSmartPointer< vtkVolumeProperty > MakeProperty(const double range[2], const double rgb[3]=nullptr)
A property that maps range onto a blue to yellow ramp of growing opacity.
int LargestDifference(const Frame &left, const Frame &right)
Largest per channel difference between two frames of the same size.
double MeanDifference(const Frame &left, const Frame &right)
Mean per channel difference between two frames of the same size.
bool CheckClass(vtkObject *object, const char *expected)
Fail loudly when the factory handed back something other than the class under test,...
A frame, as RGB triples ordered row by row.
std::size_t CountLit(const double background[3], int tolerance=12) const
Pixels that differ from the background by more than tolerance per channel.
const unsigned char * At(int x, int y) const
std::vector< unsigned char > Pixels