vtkClientServerCompositePass.cxx 4.4 KB
Newer Older
1 2 3
/*=========================================================================

  Program:   Visualization Toolkit
4
  Module:    vtkClientServerCompositePass.cxx
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

  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 "vtkClientServerCompositePass.h"

#include "vtkObjectFactory.h"
#include "vtkMultiProcessController.h"
#include "vtkSynchronizedRenderers.h"
#include "vtkRenderState.h"

vtkStandardNewMacro(vtkClientServerCompositePass);
vtkCxxSetObjectMacro(vtkClientServerCompositePass, Controller, vtkMultiProcessController);
vtkCxxSetObjectMacro(vtkClientServerCompositePass, RenderPass, vtkRenderPass);
vtkCxxSetObjectMacro(vtkClientServerCompositePass, PostProcessingRenderPass, vtkRenderPass);
//----------------------------------------------------------------------------
vtkClientServerCompositePass::vtkClientServerCompositePass()
{
  this->Controller = 0;
  this->RenderPass = 0;
  this->PostProcessingRenderPass = 0;
  this->ServerSideRendering = true;
  this->ProcessIsServer = false;
}

//----------------------------------------------------------------------------
vtkClientServerCompositePass::~vtkClientServerCompositePass()
{
  this->SetController(0);
  this->SetRenderPass(0);
  this->SetPostProcessingRenderPass(0);
}

//----------------------------------------------------------------------------
void vtkClientServerCompositePass::ReleaseGraphicsResources(vtkWindow *w)
{
  this->Superclass::ReleaseGraphicsResources(w);
  if (this->RenderPass)
49
  {
50
    this->RenderPass->ReleaseGraphicsResources(w);
51
  }
52
  if (this->PostProcessingRenderPass)
53
  {
54
    this->PostProcessingRenderPass->ReleaseGraphicsResources(w);
55
  }
56 57 58 59 60 61
}

//----------------------------------------------------------------------------
void vtkClientServerCompositePass::Render(const vtkRenderState *s)
{
  if (!this->ServerSideRendering  || this->ProcessIsServer)
62
  {
63
    if (this->RenderPass)
64
    {
65
      this->RenderPass->Render(s);
66
    }
67
    else
68
    {
69 70
      vtkWarningMacro("No render pass set.");
    }
71
  }
72 73

  if (this->ServerSideRendering)
74
  {
75
    if (!this->Controller)
76
    {
77
      vtkErrorMacro("Cannot do remote rendering with a controller.");
78
    }
79
    else if (this->ProcessIsServer)
80
    {
81 82 83 84 85 86 87 88 89 90 91 92
      // server.
      vtkSynchronizedRenderers::vtkRawImage rawImage;
      rawImage.Capture(s->GetRenderer());
      int header[4];
      header[0] = rawImage.IsValid()? 1 : 0;
      header[1] = rawImage.GetWidth();
      header[2] = rawImage.GetHeight();
      header[3] = rawImage.IsValid()?
        rawImage.GetRawPtr()->GetNumberOfComponents() : 0;
      // send the image to the client.
      this->Controller->Send(header, 4, 1, 0x023430);
      if (rawImage.IsValid())
93
      {
94 95
        this->Controller->Send(rawImage.GetRawPtr(), 1, 0x023430);
      }
96
    }
97
    else
98
    {
99 100 101 102 103
      // client.
      vtkSynchronizedRenderers::vtkRawImage rawImage;
      int header[4];
      this->Controller->Receive(header, 4, 1, 0x023430);
      if (header[0] > 0)
104
      {
105 106 107 108
        rawImage.Resize(header[1], header[2], header[3]);
        this->Controller->Receive(rawImage.GetRawPtr(), 1, 0x023430);
        rawImage.MarkValid();
      }
109
      rawImage.PushToViewport(s->GetRenderer());
110
    }
111
  }
112

113
  if (this->PostProcessingRenderPass)
114
  {
115
    this->PostProcessingRenderPass->Render(s);
116
  }
117 118 119 120 121 122
}

//----------------------------------------------------------------------------
void vtkClientServerCompositePass::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
123 124
  os << indent << "Controller: ";
  if(this->Controller==0)
125
  {
126
    os << "(none)" << endl;
127
  }
128
  else
129
  {
130
    os << this->Controller << endl;
131
  }
132 133 134 135 136 137

  os << indent << "ServerSideRendering: " << this->ServerSideRendering << endl;
  os << indent << "ProcessIsServer: " << this->ProcessIsServer << endl;

  os << indent << "RenderPass: ";
  if(this->RenderPass==0)
138
  {
139
    os << "(none)" << endl;
140
  }
141
  else
142
  {
143
    os << this->RenderPass << endl;
144
  }
145 146
  os << indent << "PostProcessingRenderPass: ";
  if(this->PostProcessingRenderPass==0)
147
  {
148
    os << "(none)" << endl;
149
  }
150
  else
151
  {
152
    os << this->PostProcessingRenderPass << endl;
153
  }
154

155 156
}