PreviewImageProviderInterface Implementation

Table of Contents

About

An implementation of maxon::nodes::PreviewImageProviderInterface provides preview images of a node.

Methods

Note
Initialize() should not take long since it blocks the UI. One should create a clone of the given node graph and access that clone in ComputeIteration().

For accessing and searching for nodes in the node graph, see GraphNodes Manual.

Settings provided in Initialize() are:

  • maxon::nodes::PREVIEWIMAGEREQUEST::TEXTURESIZE: Defines the requested preview size in pixels.
  • maxon::nodes::PREVIEWIMAGEREQUEST::SUBJECT: Points to the node requested for preview.
  • maxon::nodes::PREVIEWIMAGEREQUEST::PROGRESSIONTHRESHOLD: Constraints the iterative refinement.
  • maxon::nodes::PREVIEWIMAGEREQUEST::URANGE: For 2D previews defines the horizontal range to be sampled.
  • maxon::nodes::PREVIEWIMAGEREQUEST::VRANGE: For 2D previews defines the vertical range to be sampled.
  • maxon::nodes::PREVIEWIMAGEREQUEST::SCENETYPE: The type of the 3D scene. See also maxon::nodes::NODESPACE::MATERIALPREVIEWIDS.
  • maxon::nodes::PREVIEWIMAGEREQUEST::FLIPVERTICALLY: Defines whether a request was made for a flipped version
  • maxon::nodes::PREVIEWIMAGEREQUEST::TEXTUREIDS: The set of attributes requested for preview.
  • maxon::nodes::PREVIEWIMAGEREQUEST::PROVIDER: Defines the instance of a PreviewImageProviderRef that is used to compute the preview.
// This example implementation of PreviewImageProviderInterface::Initialize() stores the given texture size,
// the node path and creates a copy of the given node graph.
MAXON_METHOD maxon::Result<void> Initialize(maxon::DataDictionaryObjectRef request, maxon::Int numThreads)
{
// store target image size
_imageSize = request.Get(maxon::nodes::PREVIEWIMAGEREQUEST::TEXTURESIZE, maxon::IntVector2d());
// get node or port for this call
maxon::GraphNode node = request.Get(maxon::nodes::PREVIEWIMAGEREQUEST::SUBJECT, maxon::GraphNode());
if (node.IsValid() == false)
{
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
}
// get graph clone
maxon::nodes::NodesGraphModelRef graph = maxon::Cast<maxon::nodes::NodesGraphModelRef>(node.GetGraph());
_graph = graph.GetManager().GetMainView().Clone() iferr_return;
// get node path
_nodePath = node.GetPath();
// get preview scene if needed
maxon::UseVariable(sceneType);
return maxon::OK;
}
// These are example implementations of ComputeIteration() and TakeOutput().
// ComputeIteration() is called asynchronously so it must operate on the previously stored copy of the graph.
MAXON_METHOD maxon::Result<void> ComputeIteration(const maxon::JobRef parentThread)
{
// the path either references a port/node or is nullptr (render the material node)
// get node the node from the graph copy
const maxon::GraphNode node = _graph.GetNode(_nodePath);
// depending on the node, fill the image
// prepare image
maxon::nodes::SamplesFloat32& result = *_currentResult;
result.Resize(_imageSize.x * _imageSize.y) iferr_return;
// fill image
for (maxon::Int y = 0; y < _imageSize.y; ++y)
{
for (maxon::Int x = 0; x < _imageSize.x; ++x)
{
maxon::nodes::SampleFloat32& sample = result[x + y * _imageSize.x];
sample = maxon::nodes::SampleFloat32(maxon::Vector32(1.0, 1.0, 1.0));
}
}
_final = true;
return maxon::OK;
}
{
// provide information on the rendering process if the preview image is rendered iteratively.
output._iterationCount = 2;
// store image data
image._imageSize = _imageSize;
image._samplesFloat32Linear = _currentResult;
image._isFinal = _final;
output.SetResult(image) iferr_return;
return output;
}
private:
maxon::IntVector2d _imageSize;
maxon::Bool _final;
maxon::NodePath _nodePath;
maxon::nodes::NodesGraphModelRef _graph;
maxon::nodes::PreviewImageProviderOutput::_iterationCount
Int _iterationCount
Definition: previewimageprovider.h:281
maxon::GraphNode::GetGraph
const GraphModelRef & GetGraph() const
Definition: graph.h:2253
maxon::nodes::PreviewImageProviderOutputImage::_isFinal
Bool _isFinal
Definition: previewimageprovider.h:249
maxon::GraphNode::IsValid
Bool IsValid() const
Definition: graph.h:2224
maxon::nodes::PreviewImageProviderOutputImage
Definition: previewimageprovider.h:229
maxon::nodes::PreviewImageProviderOutputImage::_imageSize
IntVector2d _imageSize
Definition: previewimageprovider.h:235
maxon::nodes::PREVIEW::SCENETYPE::MatPreviewDefault
@ MatPreviewDefault
Default (may be a user preference).
maxon::OK
return OK
Definition: apibase.h:2546
maxon::BaseArray::Resize
ResultMem Resize(Int newCnt, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::DEFAULT)
Definition: basearray.h:1077
maxon::Bool
bool Bool
boolean type, possible values are only false/true, 8 bit
Definition: apibase.h:179
maxon::Vec4
A vector consisting of four components X, Y, Z and W.
Definition: vec4.h:14
iferr_return
#define iferr_return
Definition: resultbase.h:1465
maxon::nodes::PREVIEW::SCENETYPE
SCENETYPE
Definition: previewimageprovider.h:88
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:66
maxon::BaseArray
Definition: basearray.h:366
maxon::nodes::SampleFloat32
Vec4< Float32 > SampleFloat32
Convenience definitions for the immutable preview image.
Definition: previewimageprovider.h:134
maxon::Result< void >
MAXON_METHOD
#define MAXON_METHOD
Definition: interfacebase.h:877
maxon::Vec3
A vector consisting of three components X, Y and Z.
Definition: vec.h:14
maxon::GraphNode::GetPath
const NodePath & GetPath() const
Definition: graph.h:2263
maxon::Int
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:186
iferr_scope
#define iferr_scope
Definition: resultbase.h:1374
maxon::Vec2< Int, 1 >
maxon::nodes::PreviewImageProviderOutput::SetResult
Result< void > SetResult(const PreviewImageProviderOutputImage &image)
Definition: previewimageprovider.h:316
maxon::nodes::PreviewImageProviderOutputImage::_samplesFloat32Linear
SamplesFloat32ConstRef _samplesFloat32Linear
Definition: previewimageprovider.h:242
NewObj
#define NewObj(T,...)
Definition: newobj.h:108
maxon::nodes::PreviewImageProviderOutput
Definition: previewimageprovider.h:264
maxon::nodes::PreviewImageProviderOutput::_currentIterationIndex
Int _currentIterationIndex
Definition: previewimageprovider.h:273
maxon::JobRef
Reference to a job (JobInterface).
Definition: job.h:1117
maxon::BaseRef
Definition: apibase.h:1527
maxon::GraphNode
Definition: graph.h:2210