vtkCompositeRenderManager.cxx 4.2 KB
Newer Older
1 2 3 4 5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkCompositeRenderManager.cxx

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 8 9
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

10 11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkCompositeRenderManager.h"

#include "vtkCompressCompositer.h"
#include "vtkFloatArray.h"
#include "vtkMultiProcessController.h"
#include "vtkObjectFactory.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkTimerLog.h"
#include "vtkUnsignedCharArray.h"

vtkStandardNewMacro(vtkCompositeRenderManager);

vtkCxxSetObjectMacro(vtkCompositeRenderManager, Compositer, vtkCompositer);

Mathieu Malaterre's avatar
Mathieu Malaterre committed
30
//----------------------------------------------------------------------------
31 32
vtkCompositeRenderManager::vtkCompositeRenderManager()
{
33 34
  this->Compositer = vtkCompressCompositer::New();
  this->Compositer->Register( this );
35 36 37 38 39 40 41 42 43 44 45
  this->Compositer->Delete();

  this->DepthData = vtkFloatArray::New();
  this->TmpPixelData = vtkUnsignedCharArray::New();
  this->TmpDepthData = vtkFloatArray::New();

  this->DepthData->SetNumberOfComponents(1);
  this->TmpPixelData->SetNumberOfComponents(4);
  this->TmpDepthData->SetNumberOfComponents(1);
}

Mathieu Malaterre's avatar
Mathieu Malaterre committed
46
//----------------------------------------------------------------------------
47 48 49 50 51 52 53 54
vtkCompositeRenderManager::~vtkCompositeRenderManager()
{
  this->SetCompositer(NULL);
  this->DepthData->Delete();
  this->TmpPixelData->Delete();
  this->TmpDepthData->Delete();
}

Mathieu Malaterre's avatar
Mathieu Malaterre committed
55
//----------------------------------------------------------------------------
56 57 58 59 60 61 62 63 64
void vtkCompositeRenderManager::PrintSelf(ostream &os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);

  os << indent << "ImageProcessingTime: " << this->ImageProcessingTime << endl;
  os << indent << "Compositer: " << endl;
  this->Compositer->PrintSelf(os, indent.GetNextIndent());
}

Mathieu Malaterre's avatar
Mathieu Malaterre committed
65
//----------------------------------------------------------------------------
66 67
void vtkCompositeRenderManager::PreRenderProcessing()
{
68
  vtkTimerLog::MarkStartEvent("Compositing");
69 70
  // Turn swap buffers off before the render so the end render method has a
  // chance to add to the back buffer.
71
  if (this->UseBackBuffer)
72
  {
73
    this->RenderWindow->SwapBuffersOff();
74
  }
75 76 77

  this->SavedMultiSamplesSetting = this->RenderWindow->GetMultiSamples();
  this->RenderWindow->SetMultiSamples(0);
78 79
}

Mathieu Malaterre's avatar
Mathieu Malaterre committed
80
//----------------------------------------------------------------------------
81 82
void vtkCompositeRenderManager::PostRenderProcessing()
{
83 84
  this->RenderWindow->SetMultiSamples(this->SavedMultiSamplesSetting);

85
  if (!this->UseCompositing || this->CheckForAbortComposite())
86
  {
87
    vtkTimerLog::MarkEndEvent("Compositing");
88
    return;
89
  }
90

91
  if (this->Controller->GetNumberOfProcesses() > 1)
92
  {
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
    // Read in data.
    this->ReadReducedImage();
    this->Timer->StartTimer();
    this->RenderWindow->GetZbufferData(0, 0, this->ReducedImageSize[0]-1,
                                       this->ReducedImageSize[1]-1,
                                       this->DepthData);

    // Set up temporary buffers.
    this->TmpPixelData->SetNumberOfComponents
      (this->ReducedImage->GetNumberOfComponents());
    this->TmpPixelData->SetNumberOfTuples
      (this->ReducedImage->GetNumberOfTuples());
    this->TmpDepthData->SetNumberOfComponents
      (this->DepthData->GetNumberOfComponents());
    this->TmpDepthData->SetNumberOfTuples(this->DepthData->GetNumberOfTuples());

    // Do composite
    this->Compositer->SetController(this->Controller);
    this->Compositer->CompositeBuffer(this->ReducedImage, this->DepthData,
                                      this->TmpPixelData, this->TmpDepthData);

    this->Timer->StopTimer();
    this->ImageProcessingTime = this->Timer->GetElapsedTime();
116
  }
117 118

  this->WriteFullImage();
119

120 121
  // Swap buffers here
  if (this->UseBackBuffer)
122
  {
123
    this->RenderWindow->SwapBuffersOn();
124
  }
125
  this->RenderWindow->Frame();
126 127

  vtkTimerLog::MarkEndEvent("Compositing");
128 129 130
}