1 2 3 4 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
|
/*=========================================================================
Program: ParaView
Module: vtkPVServerOptions.cxx
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 "vtkPVServerOptions.h"
#include "vtkObjectFactory.h"
#include "vtkProcessModule.h"
#include "vtkPVServerOptionsInternals.h"
#include <sstream>
#include <vtksys/SystemTools.hxx>
#include <cstdio>
namespace
{
// redefining from vtkRenderWindow.h to avoid a dependency on rendering.
// we need to fix this at some point.
static int VTK_STEREO_CRYSTAL_EYES=1;
static int VTK_STEREO_RED_BLUE=2;
static int VTK_STEREO_INTERLACED=3;
static int VTK_STEREO_LEFT=4;
static int VTK_STEREO_RIGHT=5;
static int VTK_STEREO_DRESDEN=6;
static int VTK_STEREO_ANAGLYPH=7;
static int VTK_STEREO_CHECKERBOARD=8;
static int VTK_STEREO_SPLITVIEWPORT_HORIZONTAL=9;
};
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPVServerOptions);
//----------------------------------------------------------------------------
vtkPVServerOptions::vtkPVServerOptions()
{
this->Internals = new vtkPVServerOptionsInternals;
// initialize host names
this->ClientHostName = 0;
this->SetClientHostName(this->GetHostName());
// This default value for ServerPort is setup in Initialize().
this->ServerPort = 0;
}
//----------------------------------------------------------------------------
vtkPVServerOptions::~vtkPVServerOptions()
{
this->SetClientHostName(0);
delete this->Internals;
this->Internals = 0;
}
//----------------------------------------------------------------------------
void vtkPVServerOptions::Initialize()
{
this->Superclass::Initialize();
this->AddArgument("--client-host", "-ch", &this->ClientHostName,
"Tell the data|render server the host name of the client, use with -rc.",
vtkPVOptions::PVRENDER_SERVER | vtkPVOptions::PVDATA_SERVER |
vtkPVOptions::PVSERVER);
switch (vtkProcessModule::GetProcessType())
{
case vtkProcessModule::PROCESS_SERVER:
this->ServerPort = 11111;
this->AddArgument(
"--server-port", "-sp", &this->ServerPort,
"What port should the combined server use to connect to the client. (default 11111).",
vtkPVOptions::PVSERVER);
break;
case vtkProcessModule::PROCESS_DATA_SERVER:
this->ServerPort = 11111;
this->AddArgument(
"--data-server-port", "-dsp", &this->ServerPort,
"What port data server use to connect to the client. (default 11111).",
vtkPVOptions::PVDATA_SERVER);
break;
case vtkProcessModule::PROCESS_RENDER_SERVER:
this->ServerPort = 22221;
this->AddArgument(
"--render-server-port", "-rsp", &this->ServerPort,
"What port should the render server use to connect to the client. (default 22221).",
vtkPVOptions::PVRENDER_SERVER);
break;
default:
vtkErrorMacro("vtkPVServerOptions is only meant for server-processes.");
}
}
//----------------------------------------------------------------------------
int vtkPVServerOptions::AddMachineInformation(const char** atts)
{
vtkPVServerOptionsInternals::MachineInformation info;
int caveBounds = 0;
for (int i = 0; atts[i] && atts[i + 1]; i += 2)
{
std::string key = atts[i];
std::string value = atts[i + 1];
if(key == "Name")
{
info.Name = value;
}
else if(key == "Environment")
{
info.Environment = value;
}
else if(key == "Geometry")
{
for(int j = 0; j < 4; j++)
{
int matches = sscanf(value.c_str(), "%dx%d+%d+%d", &info.Geometry[2],
&info.Geometry[3], &info.Geometry[0], &info.Geometry[1]);
if (matches != 4)
{
vtkErrorMacro("Malformed geometry specification: " << value.c_str()
<< " (expected <X>x<Y>+<width>+<height>).");
info.Geometry[0] = 0;
info.Geometry[1] = 0;
info.Geometry[2] = 0;
info.Geometry[3] = 0;
}
}
}
else if(key == "FullScreen")
{
std::istringstream str(const_cast<char *>(value.c_str()));
str >> info.FullScreen;
}
else if(key == "ShowBorders")
{
std::istringstream str(const_cast<char *>(value.c_str()));
str >> info.ShowBorders;
}
else if(key == "StereoType")
{
std::map<std::string, int> map;
map["crystal eyes"] = VTK_STEREO_CRYSTAL_EYES;
map["red-blue"] = VTK_STEREO_RED_BLUE;
map["interlaced"] = VTK_STEREO_INTERLACED;
map["left"] = VTK_STEREO_LEFT;
map["right"] = VTK_STEREO_RIGHT;
map["dresden"] = VTK_STEREO_DRESDEN;
map["anaglyph"] = VTK_STEREO_ANAGLYPH;
map["checkerboard"] = VTK_STEREO_CHECKERBOARD;
map["splitviewporthorizontal"] = VTK_STEREO_SPLITVIEWPORT_HORIZONTAL;
value = vtksys::SystemTools::LowerCase(value);
if (map.find(value) != map.end())
{
info.StereoType = map[value];
}
else
{
info.StereoType = 0; // no stereo (or invalid stereo mode).
}
// Currently, we only support left or right stereo. We cannot simply support
// other types since that causes multiple renders and those need to match
// up across all processes, including the client.
if (info.StereoType != VTK_STEREO_LEFT &&
info.StereoType != VTK_STEREO_RIGHT &&
info.StereoType != 0)
{
vtkErrorMacro("Only 'Left' or 'Right' can be used as the StereoType. "
"For all other modes, please use the command line arguments for the "
"ParaView client.");
info.StereoType = -1;
}
}
else if(key == "LowerLeft")
{
caveBounds++;
std::istringstream str(const_cast<char *>(value.c_str()));
for(int j =0; j < 3; j++)
{
str >> info.LowerLeft[j];
}
}
else if(key == "LowerRight")
{
caveBounds++;
std::istringstream str(const_cast<char *>(value.c_str()));
for(int j =0; j < 3; j++)
{
str >> info.LowerRight[j];
}
}
else if(key == "UpperRight")
{
caveBounds++;
std::istringstream str(const_cast<char *>(value.c_str()));
for(int j =0; j < 3; j++)
{
str >> info.UpperRight[j];
}
}
}
if(caveBounds && caveBounds != 3)
{
vtkErrorMacro("LowerRight LowerLeft and UpperRight must all be present, if one is present");
return 0;
}
if(caveBounds)
{
info.CaveBoundsSet = 1;
}
this->Internals->MachineInformationVector.push_back(info);
return 1;
}
// ----------------------------------------------------------------------------
int vtkPVServerOptions::AddEyeSeparationInformation(const char** atts)
{
std::string key = atts[0];
std::string value = atts[1];
if(key == "Value")
{
std::istringstream str(const_cast<char *>(value.c_str()));
str >> this->Internals->EyeSeparation;
}
else
{
vtkErrorMacro("<EyeSeparation Value=\"...\"/> needs to be specified");
return 0;
}
return 1;
}
//----------------------------------------------------------------------------
int vtkPVServerOptions::ParseExtraXMLTag(const char* name, const char** atts)
{
// handle the Machine tag
if(strcmp(name, "Machine") == 0)
{
return this->AddMachineInformation(atts);
}
// Hande the EyeSeparation tag
if(strcmp(name, "EyeSeparation") == 0)
{
return this->AddEyeSeparationInformation(atts);
}
return 0;
}
//----------------------------------------------------------------------------
double vtkPVServerOptions::GetEyeSeparation()
{
return static_cast<double> ( this->Internals->EyeSeparation );
}
//----------------------------------------------------------------------------
unsigned int vtkPVServerOptions::GetNumberOfMachines()
{
return static_cast<unsigned int>(
this->Internals->MachineInformationVector.size());
}
//----------------------------------------------------------------------------
const char* vtkPVServerOptions::GetMachineName(unsigned int idx)
{
if (idx >= this->Internals->MachineInformationVector.size())
{
return 0;
}
return this->Internals->MachineInformationVector[idx].Name.c_str();
}
//----------------------------------------------------------------------------
const char* vtkPVServerOptions::GetDisplayName(unsigned int idx)
{
if (idx >= this->Internals->MachineInformationVector.size())
{
return 0;
}
return this->Internals->MachineInformationVector[idx].Environment.c_str();
}
//----------------------------------------------------------------------------
int* vtkPVServerOptions::GetGeometry(unsigned int idx)
{
if (idx >= this->Internals->MachineInformationVector.size())
{
return 0;
}
return this->Internals->MachineInformationVector[idx].Geometry;
}
//----------------------------------------------------------------------------
bool vtkPVServerOptions::GetFullScreen(unsigned int idx)
{
if (idx >= this->Internals->MachineInformationVector.size())
{
return false;
}
return this->Internals->MachineInformationVector[idx].FullScreen != 0;
}
//----------------------------------------------------------------------------
int vtkPVServerOptions::GetStereoType(unsigned int idx)
{
if (idx >= this->Internals->MachineInformationVector.size())
{
return -1;
}
return this->Internals->MachineInformationVector[idx].StereoType;
}
//----------------------------------------------------------------------------
bool vtkPVServerOptions::GetShowBorders(unsigned int idx)
{
if (idx >= this->Internals->MachineInformationVector.size())
{
return false;
}
return this->Internals->MachineInformationVector[idx].ShowBorders != 0;
}
//----------------------------------------------------------------------------
double* vtkPVServerOptions::GetLowerLeft(unsigned int idx)
{
if (idx >= this->Internals->MachineInformationVector.size())
{
return 0;
}
return this->Internals->MachineInformationVector[idx].LowerLeft;
}
//----------------------------------------------------------------------------
double* vtkPVServerOptions::GetLowerRight(unsigned int idx)
{
if (idx >= this->Internals->MachineInformationVector.size())
{
return 0;
}
return this->Internals->MachineInformationVector[idx].LowerRight;
}
//----------------------------------------------------------------------------
double* vtkPVServerOptions::GetUpperRight(unsigned int idx)
{
if (idx >= this->Internals->MachineInformationVector.size())
{
return 0;
}
return this->Internals->MachineInformationVector[idx].UpperRight;
}
//----------------------------------------------------------------------------
void vtkPVServerOptions::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
this->Internals->PrintSelf(os, indent);
os << indent << "ClientHostName: "
<< (this->ClientHostName?this->ClientHostName:"(none)") << endl;
os << indent << "ServerPort: " << this->ServerPort << endl;
}
|