1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkOptiXWindowNode.cxx 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 16 #include "vtkOptiXWindowNode.h" 17 18 #include "vtkCollectionIterator.h" 19 #include "vtkFloatArray.h" 20 #include "vtkObjectFactory.h" 21 #include "vtkOptiXRendererNode.h" 22 #include "vtkOptiXViewNodeFactory.h" 23 #include "vtkRendererCollection.h" 24 #include "vtkRenderWindow.h" 25 #include "vtkUnsignedCharArray.h" 26 #include "vtkViewNodeCollection.h" 27 28 #include <stdexcept> 29 30 //============================================================================ 31 vtkStandardNewMacro(vtkOptiXWindowNode); 32 33 //------------------------------------------------------------------------------ vtkOptiXWindowNode()34vtkOptiXWindowNode::vtkOptiXWindowNode() 35 { 36 vtkOptiXViewNodeFactory *fac = vtkOptiXViewNodeFactory::New(); 37 this->SetMyFactory(fac); 38 fac->Delete(); 39 } 40 41 //------------------------------------------------------------------------------ ~vtkOptiXWindowNode()42vtkOptiXWindowNode::~vtkOptiXWindowNode() 43 { 44 } 45 46 //------------------------------------------------------------------------------ PrintSelf(ostream & os,vtkIndent indent)47void vtkOptiXWindowNode::PrintSelf(ostream& os, vtkIndent indent) 48 { 49 this->Superclass::PrintSelf(os, indent); 50 } 51 52 //------------------------------------------------------------------------------ Render(bool prepass)53void vtkOptiXWindowNode::Render(bool prepass) 54 { 55 if (!prepass) 56 { 57 //composite all renderers framebuffers together 58 this->ColorBuffer->SetNumberOfComponents(4); 59 this->ColorBuffer->SetNumberOfTuples(this->Size[0]*this->Size[1]); 60 unsigned char *rgba = static_cast<unsigned char *> 61 (this->ColorBuffer->GetVoidPointer(0)); 62 63 this->ZBuffer->SetNumberOfComponents(1); 64 this->ZBuffer->SetNumberOfTuples(this->Size[0]*this->Size[1]); 65 float *z = static_cast<float *>(this->ZBuffer->GetVoidPointer(0)); 66 67 vtkViewNodeCollection *renderers = this->GetChildren(); 68 vtkCollectionIterator *it = renderers->NewIterator(); 69 it->InitTraversal(); 70 71 int layer = 0; 72 int count = 0; 73 while (count < renderers->GetNumberOfItems()) 74 { 75 it->InitTraversal(); 76 while (!it->IsDoneWithTraversal()) 77 { 78 vtkOptiXRendererNode *child = 79 vtkOptiXRendererNode::SafeDownCast(it->GetCurrentObject()); 80 vtkRenderer *ren = vtkRenderer::SafeDownCast(child->GetRenderable()); 81 if (ren->GetLayer() == layer) 82 { 83 child->WriteLayer(rgba, z, this->Size[0], this->Size[1], layer); 84 count++; 85 } 86 it->GoToNextItem(); 87 } 88 layer++; 89 } 90 it->Delete(); 91 } 92 } 93