/*========================================================================= Program: Visualization Toolkit Module: vtkVtkJSViewNodeFactory.cxx Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ #include "vtkVtkJSViewNodeFactory.h" #include #include #include #include #include #include #include #include #include #include #include #include "vtkVtkJSSceneGraphSerializer.h" #if VTK_MODULE_ENABLE_VTK_RenderingOpenGL2 #include #endif #include namespace { // A template for performing a compile-time check if a scene element inherits // from vtkAlgorithm and calling Update on it if it does. class UpdateIfAlgorithm { template static typename std::enable_if::value>::type MaybeUpdate(X* x) { x->Update(); } template static typename std::enable_if::value>::type MaybeUpdate(X*) { } public: template static void Update(MaybeAlgorithm* maybeAlgorithm) { UpdateIfAlgorithm::MaybeUpdate(maybeAlgorithm); } }; // A template for constructing view nodes associated with scene elements and // their associated renderables. template class vtkVtkJSViewNode : public Base { public: static vtkViewNode* New() { vtkVtkJSViewNode* result = new vtkVtkJSViewNode; result->InitializeObjectBase(); return result; } void Synchronize(bool prepass) override { this->Base::Synchronize(prepass); if (prepass) { auto factory = vtkVtkJSViewNodeFactory::SafeDownCast(this->GetMyFactory()); if (factory != nullptr) { factory->GetSerializer()->Add(this, Renderable::SafeDownCast(this->GetRenderable())); } } } void Render(bool prepass) override { this->Base::Render(prepass); UpdateIfAlgorithm::Update(Renderable::SafeDownCast(this->GetRenderable())); } }; } //------------------------------------------------------------------------------ vtkStandardNewMacro(vtkVtkJSViewNodeFactory); vtkCxxSetObjectMacro(vtkVtkJSViewNodeFactory, Serializer, vtkVtkJSSceneGraphSerializer); //------------------------------------------------------------------------------ vtkVtkJSViewNodeFactory::vtkVtkJSViewNodeFactory() { this->Serializer = vtkVtkJSSceneGraphSerializer::New(); // Since a view node is constructed if an override exists for one of its base // classes, we only need to span the set of base renderable types and provide // specializations when custom logic is required by vtk-js. // These overrides span the base renderable types. this->RegisterOverride("vtkActor", vtkVtkJSViewNode::New); this->RegisterOverride("vtkMapper", vtkVtkJSViewNode::New); this->RegisterOverride("vtkRenderWindow", vtkVtkJSViewNode::New); this->RegisterOverride("vtkRenderer", vtkVtkJSViewNode::New); // These overrides are necessary to accommodate custom logic that must be // performed when converting these renderables to vtk-js. this->RegisterOverride( "vtkCompositePolyDataMapper", vtkVtkJSViewNode::New); #if VTK_MODULE_ENABLE_VTK_RenderingOpenGL2 this->RegisterOverride("vtkCompositePolyDataMapper2", vtkVtkJSViewNode::New); #endif this->RegisterOverride( "vtkGlyph3DMapper", vtkVtkJSViewNode::New); } //------------------------------------------------------------------------------ vtkVtkJSViewNodeFactory::~vtkVtkJSViewNodeFactory() { this->SetSerializer(nullptr); } //------------------------------------------------------------------------------ void vtkVtkJSViewNodeFactory::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os, indent); }