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 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkGenericCompositePolyDataMapper2.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 "vtkGenericCompositePolyDataMapper2.h"
#include "vtkBoundingBox.h"
#include "vtkCommand.h"
#include "vtkCompositeDataIterator.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkCompositeDataSet.h"
#include "vtkCompositeDataDisplayAttributes.h"
#include "vtkHardwareSelector.h"
#include "vtkInformation.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLVertexBufferObject.h"
#include "vtkPolyData.h"
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkScalarsToColors.h"
#include "vtkShaderProgram.h"
#include "vtkUnsignedCharArray.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkMultiPieceDataSet.h"
#include <algorithm>
//===================================================================
// We define a helper class that is a subclass of vtkOpenGLPolyDataMapper
// We use this to get some performance improvements over the generic
// mapper case.
class vtkCompositeMapperHelper : public vtkOpenGLPolyDataMapper
{
public:
static vtkCompositeMapperHelper* New();
vtkTypeMacro(vtkCompositeMapperHelper, vtkOpenGLPolyDataMapper);
vtkGenericCompositePolyDataMapper2 *Parent;
int LastColorCoordinates;
int LastNormalsOffset;
int LastTCoordComponents;
protected:
vtkCompositeMapperHelper() {};
~vtkCompositeMapperHelper() {};
// Description:
// Set the shader parameteres related to the property, called by UpdateShader
virtual void SetPropertyShaderParameters(
vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
// Description:
// Set the shader parameteres related to lighting, called by UpdateShader
virtual void SetLightingShaderParameters(
vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
// Description:
// Set the shader parameteres related to the Camera, called by UpdateShader
virtual void SetCameraShaderParameters(
vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
// Description:
// Does the shader source need to be recomputed
virtual bool GetNeedToRebuildShaders(
vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
// Description:
// Make sure an appropriate shader is defined, compiled and bound. This method
// orchistrates the process, much of the work is done in other methods
virtual void UpdateShaders(
vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
// Description:
// Perform string replacments on the shader templates, called from
// ReplaceShaderValues
virtual void ReplaceShaderColor(
std::map<vtkShader::Type, vtkShader *> shaders,
vtkRenderer *ren, vtkActor *act);
private:
vtkCompositeMapperHelper(const vtkCompositeMapperHelper&); // Not implemented.
void operator=(const vtkCompositeMapperHelper&); // Not implemented.
};
vtkStandardNewMacro(vtkCompositeMapperHelper);
void vtkCompositeMapperHelper::SetCameraShaderParameters(vtkOpenGLHelper &cellBO,
vtkRenderer *ren, vtkActor *actor)
{
if (!this->Parent->GetShaderInitialized(cellBO.Program))
{
this->Superclass::SetCameraShaderParameters(cellBO, ren, actor);
}
}
void vtkCompositeMapperHelper::SetLightingShaderParameters(vtkOpenGLHelper &cellBO,
vtkRenderer *ren, vtkActor *actor)
{
if (!this->Parent->GetShaderInitialized(cellBO.Program))
{
this->Superclass::SetLightingShaderParameters(cellBO, ren, actor);
}
}
void vtkCompositeMapperHelper::SetPropertyShaderParameters(vtkOpenGLHelper &cellBO,
vtkRenderer *ren, vtkActor *actor)
{
if (!this->Parent->GetShaderInitialized(cellBO.Program))
{
this->Superclass::SetPropertyShaderParameters(cellBO, ren, actor);
}
vtkProperty *ppty = actor->GetProperty();
// block colors, if set override scalar coloring
cellBO.Program->SetUniformi("OverridesColor",
this->Parent->BlockState.AmbientColor.size() > 1);
// override the opacity
cellBO.Program->SetUniformf("opacityUniform", this->Parent->BlockState.Opacity.top());
double aIntensity = this->DrawingEdges ? 1.0 : ppty->GetAmbient(); // ignoring renderer ambient
double dIntensity = this->DrawingEdges ? 0.0 : ppty->GetDiffuse();
vtkColor3d &aColor = this->Parent->BlockState.AmbientColor.top();
float ambientColor[3] = {static_cast<float>(aColor[0] * aIntensity),
static_cast<float>(aColor[1] * aIntensity),
static_cast<float>(aColor[2] * aIntensity)};
vtkColor3d &dColor = this->Parent->BlockState.DiffuseColor.top();
float diffuseColor[3] = {static_cast<float>(dColor[0] * dIntensity),
static_cast<float>(dColor[1] * dIntensity),
static_cast<float>(dColor[2] * dIntensity)};
cellBO.Program->SetUniform3f("ambientColorUniform", ambientColor);
cellBO.Program->SetUniform3f("diffuseColorUniform", diffuseColor);
}
void vtkCompositeMapperHelper::ReplaceShaderColor(
std::map<vtkShader::Type, vtkShader *> shaders,
vtkRenderer *ren, vtkActor *actor)
{
std::string FSSource = shaders[vtkShader::Fragment]->GetSource();
vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Dec",
"uniform bool OverridesColor;\n"
"//VTK::Color::Dec",false);
vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Impl",
"//VTK::Color::Impl\n"
" if (OverridesColor) {\n"
" ambientColor = ambientColorUniform;\n"
" diffuseColor = diffuseColorUniform; }\n",
false);
shaders[vtkShader::Fragment]->SetSource(FSSource);
this->Superclass::ReplaceShaderColor(shaders,ren,actor);
}
//-----------------------------------------------------------------------------
void vtkCompositeMapperHelper::UpdateShaders(
vtkOpenGLHelper &cellBO,
vtkRenderer* ren, vtkActor *actor)
{
// invoke superclass
this->Superclass::UpdateShaders(cellBO, ren, actor);
// mark this shader as initialized
this->Parent->SetShaderInitialized(cellBO.Program, true);
}
//-----------------------------------------------------------------------------
// smarter version that knows actor/property/camera/lights are not changing
bool vtkCompositeMapperHelper::GetNeedToRebuildShaders(
vtkOpenGLHelper &cellBO, vtkRenderer* ren, vtkActor *actor)
{
if (!cellBO.Program || !this->Parent->GetShaderInitialized(cellBO.Program))
{
bool result =
this->Superclass::GetNeedToRebuildShaders(cellBO, ren, actor);
this->LastColorCoordinates = this->VBO->ColorComponents;
this->LastNormalsOffset = this->VBO->NormalOffset;
this->LastTCoordComponents = this->VBO->TCoordComponents;
return result;
}
// after the first datasedt we only look for changes in pointdata
if (this->LastColorCoordinates != this->VBO->ColorComponents ||
this->LastNormalsOffset != this->VBO->NormalOffset ||
this->LastTCoordComponents != this->VBO->TCoordComponents)
{
return true;
}
return false;
}
//===================================================================
// Now the main class methods
vtkStandardNewMacro(vtkGenericCompositePolyDataMapper2);
//----------------------------------------------------------------------------
vtkGenericCompositePolyDataMapper2::vtkGenericCompositePolyDataMapper2()
{
this->LastOpaqueCheckTime = 0;
}
//----------------------------------------------------------------------------
vtkGenericCompositePolyDataMapper2::~vtkGenericCompositePolyDataMapper2()
{
std::map<const vtkDataSet*, vtkCompositeMapperHelper *>::iterator miter = this->Helpers.begin();
for (;miter != this->Helpers.end(); miter++)
{
miter->second->Delete();
}
this->Helpers.clear();
}
bool vtkGenericCompositePolyDataMapper2::GetShaderInitialized(vtkShaderProgram *prog)
{
typedef std::map<const vtkShaderProgram *, bool>::iterator Iter;
Iter found = this->ShadersInitialized.find(prog);
if (found == this->ShadersInitialized.end())
{
this->ShadersInitialized.insert(std::make_pair(prog, false));
return false;
}
else
{
return found->second;
}
}
void vtkGenericCompositePolyDataMapper2::SetShaderInitialized(vtkShaderProgram *prog, bool val)
{
typedef std::map<const vtkShaderProgram *, bool>::iterator Iter;
Iter found = this->ShadersInitialized.find(prog);
if (found == this->ShadersInitialized.end())
{
this->ShadersInitialized.insert(std::make_pair(prog, val));
}
else
{
found->second = val;
}
}
//----------------------------------------------------------------------------
int vtkGenericCompositePolyDataMapper2::FillInputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData");
info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkCompositeDataSet");
return 1;
}
//----------------------------------------------------------------------------
vtkExecutive* vtkGenericCompositePolyDataMapper2::CreateDefaultExecutive()
{
return vtkCompositeDataPipeline::New();
}
//-----------------------------------------------------------------------------
//Looks at each DataSet and finds the union of all the bounds
void vtkGenericCompositePolyDataMapper2::ComputeBounds()
{
vtkMath::UninitializeBounds(this->Bounds);
vtkCompositeDataSet *input = vtkCompositeDataSet::SafeDownCast(
this->GetInputDataObject(0, 0));
// If we don't have hierarchical data, test to see if we have
// plain old polydata. In this case, the bounds are simply
// the bounds of the input polydata.
if (!input)
{
this->Superclass::ComputeBounds();
return;
}
vtkCompositeDataIterator* iter = input->NewIterator();
vtkBoundingBox bbox;
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
vtkPolyData *pd = vtkPolyData::SafeDownCast(iter->GetCurrentDataObject());
if (pd)
{
double bounds[6];
pd->GetBounds(bounds);
bbox.AddBounds(bounds);
}
}
iter->Delete();
bbox.GetBounds(this->Bounds);
// this->BoundsMTime.Modified();
}
//-----------------------------------------------------------------------------
bool vtkGenericCompositePolyDataMapper2::GetIsOpaque()
{
vtkCompositeDataSet *input = vtkCompositeDataSet::SafeDownCast(
this->GetInputDataObject(0, 0));
unsigned long int lastMTime = std::max(input ? input->GetMTime() : 0, this->GetMTime());
if (lastMTime <= this->LastOpaqueCheckTime)
{
return this->LastOpaqueCheckValue;
}
this->LastOpaqueCheckTime = lastMTime;
if (this->ScalarVisibility && input &&
(this->ColorMode == VTK_COLOR_MODE_DEFAULT ||
this->ColorMode == VTK_COLOR_MODE_DIRECT_SCALARS))
{
vtkSmartPointer<vtkCompositeDataIterator> iter;
iter.TakeReference(input->NewIterator());
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
vtkPolyData *pd = vtkPolyData::SafeDownCast(iter->GetCurrentDataObject());
if (pd)
{
int cellFlag;
vtkDataArray* scalars = this->GetScalars(pd,
this->ScalarMode, this->ArrayAccessMode, this->ArrayId,
this->ArrayName, cellFlag);
if (scalars &&
(scalars->IsA("vtkUnsignedCharArray") ||
this->ColorMode == VTK_COLOR_MODE_DIRECT_SCALARS) &&
(scalars->GetNumberOfComponents() == 4 /*(RGBA)*/ ||
scalars->GetNumberOfComponents() == 2 /*(LuminanceAlpha)*/))
{
int opacityIndex = scalars->GetNumberOfComponents() - 1;
unsigned char opacity = 0;
switch (scalars->GetDataType())
{
vtkTemplateMacro(
vtkScalarsToColors::ColorToUChar(
static_cast<VTK_TT>(scalars->GetRange(opacityIndex)[0]),
&opacity));
}
if (opacity < 255)
{
// If the opacity is 255, despite the fact that the user specified
// RGBA, we know that the Alpha is 100% opaque. So treat as opaque.
this->LastOpaqueCheckValue = false;
return false;
}
}
}
}
}
else if(this->CompositeAttributes &&
this->CompositeAttributes->HasBlockOpacities())
{
this->LastOpaqueCheckValue = false;
return false;
}
this->LastOpaqueCheckValue = this->Superclass::GetIsOpaque();
return this->LastOpaqueCheckValue;
}
//----------------------------------------------------------------------------
void vtkGenericCompositePolyDataMapper2::SetBlockVisibility(unsigned int index, bool visible)
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->SetBlockVisibility(index, visible);
this->Modified();
}
}
//----------------------------------------------------------------------------
bool vtkGenericCompositePolyDataMapper2::GetBlockVisibility(unsigned int index) const
{
if(this->CompositeAttributes)
{
return this->CompositeAttributes->GetBlockVisibility(index);
}
else
{
return true;
}
}
//----------------------------------------------------------------------------
void vtkGenericCompositePolyDataMapper2::RemoveBlockVisibility(unsigned int index)
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->RemoveBlockVisibility(index);
this->Modified();
}
}
//----------------------------------------------------------------------------
void vtkGenericCompositePolyDataMapper2::RemoveBlockVisibilites()
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->RemoveBlockVisibilites();
this->Modified();
}
}
//----------------------------------------------------------------------------
void vtkGenericCompositePolyDataMapper2::SetBlockColor(unsigned int index, double color[3])
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->SetBlockColor(index, color);
this->Modified();
}
}
//----------------------------------------------------------------------------
double* vtkGenericCompositePolyDataMapper2::GetBlockColor(unsigned int index)
{
static double white[3] = {1.0,1.0,1.0};
if(this->CompositeAttributes)
{
this->CompositeAttributes->GetBlockColor(index, this->ColorResult);
return this->ColorResult;
}
else
{
return white;
}
}
//----------------------------------------------------------------------------
void vtkGenericCompositePolyDataMapper2::RemoveBlockColor(unsigned int index)
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->RemoveBlockColor(index);
this->Modified();
}
}
//----------------------------------------------------------------------------
void vtkGenericCompositePolyDataMapper2::RemoveBlockColors()
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->RemoveBlockColors();
this->Modified();
}
}
//----------------------------------------------------------------------------
void vtkGenericCompositePolyDataMapper2::SetBlockOpacity(unsigned int index, double opacity)
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->SetBlockOpacity(index, opacity);
this->Modified();
}
}
//----------------------------------------------------------------------------
double vtkGenericCompositePolyDataMapper2::GetBlockOpacity(unsigned int index)
{
if(this->CompositeAttributes)
{
return this->CompositeAttributes->GetBlockOpacity(index);
}
return 1.;
}
//----------------------------------------------------------------------------
void vtkGenericCompositePolyDataMapper2::RemoveBlockOpacity(unsigned int index)
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->RemoveBlockOpacity(index);
this->Modified();
}
}
//----------------------------------------------------------------------------
void vtkGenericCompositePolyDataMapper2::RemoveBlockOpacities()
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->RemoveBlockOpacities();
this->Modified();
}
}
//----------------------------------------------------------------------------
void vtkGenericCompositePolyDataMapper2::SetCompositeDataDisplayAttributes(
vtkCompositeDataDisplayAttributes *attributes)
{
if(this->CompositeAttributes != attributes)
{
this->CompositeAttributes = attributes;
this->Modified();
}
}
//----------------------------------------------------------------------------
vtkCompositeDataDisplayAttributes*
vtkGenericCompositePolyDataMapper2::GetCompositeDataDisplayAttributes()
{
return this->CompositeAttributes;
}
//----------------------------------------------------------------------------
void vtkGenericCompositePolyDataMapper2::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//-----------------------------------------------------------------------------
void vtkGenericCompositePolyDataMapper2::RenderBlock(vtkRenderer *renderer,
vtkActor *actor,
vtkDataObject *dobj,
unsigned int &flat_index)
{
vtkHardwareSelector *selector = renderer->GetSelector();
vtkCompositeDataDisplayAttributes* cda = this->GetCompositeDataDisplayAttributes();
vtkProperty *prop = actor->GetProperty();
bool draw_surface_with_edges =
(prop->GetEdgeVisibility() && prop->GetRepresentation() == VTK_SURFACE);
vtkColor3d ecolor(prop->GetEdgeColor());
bool overrides_visibility = (cda && cda->HasBlockVisibility(flat_index));
if (overrides_visibility)
{
this->BlockState.Visibility.push(cda->GetBlockVisibility(flat_index));
}
bool overrides_opacity = (cda && cda->HasBlockOpacity(flat_index));
if (overrides_opacity)
{
this->BlockState.Opacity.push(cda->GetBlockOpacity(flat_index));
}
bool overrides_color = (cda && cda->HasBlockColor(flat_index));
if (overrides_color)
{
vtkColor3d color = cda->GetBlockColor(flat_index);
this->BlockState.AmbientColor.push(color);
this->BlockState.DiffuseColor.push(color);
this->BlockState.SpecularColor.push(color);
}
unsigned int my_flat_index = flat_index;
// Advance flat-index. After this point, flat_index no longer points to this
// block.
flat_index++;
vtkMultiBlockDataSet *mbds = vtkMultiBlockDataSet::SafeDownCast(dobj);
vtkMultiPieceDataSet *mpds = vtkMultiPieceDataSet::SafeDownCast(dobj);
if (mbds || mpds)
{
unsigned int numChildren = mbds? mbds->GetNumberOfBlocks() :
mpds->GetNumberOfPieces();
for (unsigned int cc=0 ; cc < numChildren; cc++)
{
vtkDataObject* child = mbds ? mbds->GetBlock(cc) : mpds->GetPiece(cc);
if (child == NULL)
{
// speeds things up when dealing with NULL blocks (which is common with
// AMRs).
flat_index++;
continue;
}
this->RenderBlock(renderer, actor, child, flat_index);
}
}
else if (dobj && this->BlockState.Visibility.top() == true && this->BlockState.Opacity.top() > 0.0)
{
// Implies that the block is a non-null leaf node.
// The top of the "stacks" have the state that this block must be rendered
// with.
if (selector)
{
selector->BeginRenderProp();
selector->RenderCompositeIndex(my_flat_index);
}
// do we have a entry for this dataset?
// make sure we have an entry for this dataset
vtkPolyData *ds = vtkPolyData::SafeDownCast(dobj);
if (ds)
{
this->CurrentFlatIndex = my_flat_index;
vtkCompositeMapperHelper *helper;
typedef std::map<const vtkDataSet *,vtkCompositeMapperHelper *>::iterator GVIter;
GVIter found = this->Helpers.find(ds);
if (found == this->Helpers.end())
{
helper = vtkCompositeMapperHelper::New();
helper->Parent = this;
this->CopyMapperValuesToHelper(helper);
this->Helpers.insert(std::make_pair(ds, helper));
helper->SetInputData(ds);
}
else
{
helper = found->second;
}
helper->CurrentInput = ds;
if (ds && ds->GetPoints())
{
helper->RenderPieceStart(renderer,actor);
helper->RenderPieceDraw(renderer,actor);
if (draw_surface_with_edges)
{
this->BlockState.AmbientColor.push(ecolor);
helper->RenderEdges(renderer,actor);
this->BlockState.AmbientColor.pop();
}
helper->RenderPieceFinish(renderer,actor);
}
}
if (selector)
{
selector->EndRenderProp();
}
}
if (overrides_color)
{
this->BlockState.AmbientColor.pop();
this->BlockState.DiffuseColor.pop();
this->BlockState.SpecularColor.pop();
}
if (overrides_opacity)
{
this->BlockState.Opacity.pop();
}
if (overrides_visibility)
{
this->BlockState.Visibility.pop();
}
}
void vtkGenericCompositePolyDataMapper2::CopyMapperValuesToHelper(vtkCompositeMapperHelper *helper)
{
helper->vtkMapper::ShallowCopy(this);
helper->SetStatic(1);
helper->SetPopulateSelectionSettings(0);
}
void vtkGenericCompositePolyDataMapper2::FreeGenericStructures()
{
std::map<const vtkDataSet*, vtkCompositeMapperHelper *>::iterator miter = this->Helpers.begin();
for (;miter != this->Helpers.end(); miter++)
{
miter->second->Delete();
}
this->Helpers.clear();
this->ShadersInitialized.clear();
}
//-----------------------------------------------------------------------------
void vtkGenericCompositePolyDataMapper2::ReleaseGraphicsResources(vtkWindow* win)
{
this->FreeGenericStructures();
this->Superclass::ReleaseGraphicsResources(win);
}
// ---------------------------------------------------------------------------
// Description:
// Method initiates the mapping process. Generally sent by the actor
// as each frame is rendered.
void vtkGenericCompositePolyDataMapper2::RenderGeneric(vtkRenderer *ren, vtkActor *actor)
{
vtkProperty* prop = actor->GetProperty();
// Push base-values on the state stack.
this->BlockState.Visibility.push(true);
this->BlockState.Opacity.push(prop->GetOpacity());
this->BlockState.AmbientColor.push(vtkColor3d(prop->GetAmbientColor()));
this->BlockState.DiffuseColor.push(vtkColor3d(prop->GetDiffuseColor()));
this->BlockState.SpecularColor.push(vtkColor3d(prop->GetSpecularColor()));
// if our input has changed then clear out our helpers
vtkDataObject* inputDO = this->GetInputDataObject(0, 0);
if (inputDO->GetMTime() > this->HelperMTime)
{
std::map<const vtkDataSet*, vtkCompositeMapperHelper *>::iterator miter = this->Helpers.begin();
for (;miter != this->Helpers.end(); miter++)
{
miter->second->Delete();
}
this->Helpers.clear();
this->ShadersInitialized.clear();
this->HelperMTime.Modified();
}
else // otherwise just reinitialize the shaders
{
// if we have changed recopy our mapper settings to the helpers
if (this->GetMTime() > this->HelperMTime)
{
std::map<const vtkDataSet*, vtkCompositeMapperHelper *>::iterator miter = this->Helpers.begin();
for (;miter != this->Helpers.end(); miter++)
{
this->CopyMapperValuesToHelper(miter->second);
}
}
// reset initialized flag on the shaders we use
std::map<const vtkShaderProgram *, bool>::iterator miter = this->ShadersInitialized.begin();
for (;miter != this->ShadersInitialized.end(); miter++)
{
miter->second = false;
}
}
// render using the composite data attributes
unsigned int flat_index = 0;
this->RenderBlock(ren, actor, inputDO, flat_index);
this->BlockState.Visibility.pop();
this->BlockState.Opacity.pop();
this->BlockState.AmbientColor.pop();
this->BlockState.DiffuseColor.pop();
this->BlockState.SpecularColor.pop();
this->UpdateProgress(1.0);
}
|