vtkPieChartActor.cxx 21.5 KB
Newer Older
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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkPieChartActor.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 "vtkPieChartActor.h"

#include "vtkAxisActor2D.h"
#include "vtkCellArray.h"
#include "vtkFieldData.h"
#include "vtkCellData.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper2D.h"
#include "vtkTextMapper.h"
#include "vtkTextProperty.h"
#include "vtkViewport.h"
#include "vtkWindow.h"
#include "vtkLegendBoxActor.h"
#include "vtkGlyphSource2D.h"
#include "vtkProperty2D.h"
#include <vtkstd/string>
#include <vtkstd/vector>

vtkStandardNewMacro(vtkPieChartActor);

vtkCxxSetObjectMacro(vtkPieChartActor,Input,vtkDataObject);
vtkCxxSetObjectMacro(vtkPieChartActor,LabelTextProperty,vtkTextProperty);
vtkCxxSetObjectMacro(vtkPieChartActor,TitleTextProperty,vtkTextProperty);

// PIMPL'd list of labels
class vtkPieceLabelArray : public vtkstd::vector<vtkstd::string> {};


//----------------------------------------------------------------------------
// Instantiate object
vtkPieChartActor::vtkPieChartActor()
{
  // Actor2D positions
  this->PositionCoordinate->SetCoordinateSystemToNormalizedViewport();
  this->PositionCoordinate->SetValue(0.1,0.1);
  this->Position2Coordinate->SetCoordinateSystemToNormalizedViewport();
  this->Position2Coordinate->SetValue(0.9, 0.8);
  this->Position2Coordinate->SetReferenceCoordinate(NULL);
  
  this->Input = NULL;
  this->ArrayNumber = 0;
  this->ComponentNumber = 0;
  this->TitleVisibility = 1;
  this->Title = NULL;
  this->Labels = new vtkPieceLabelArray;
  this->PieceMappers = NULL;
  this->PieceActors = NULL;
  this->LabelTextProperty = vtkTextProperty::New();
  this->LabelTextProperty->SetFontSize(12);
  this->LabelTextProperty->SetBold(1);
  this->LabelTextProperty->SetItalic(1);
  this->LabelTextProperty->SetShadow(0);
  this->LabelTextProperty->SetFontFamilyToArial();
  this->TitleTextProperty = vtkTextProperty::New();
  this->TitleTextProperty->ShallowCopy(this->LabelTextProperty);
  this->TitleTextProperty->SetFontSize(24);
  this->TitleTextProperty->SetBold(1);
  this->TitleTextProperty->SetItalic(0);
  this->TitleTextProperty->SetShadow(1);
  this->TitleTextProperty->SetFontFamilyToArial();
  this->LabelVisibility = 1;

  this->LegendVisibility = 1;

  this->LegendActor = vtkLegendBoxActor::New();
  this->LegendActor->GetPositionCoordinate()->SetCoordinateSystemToViewport();
  this->LegendActor->GetPosition2Coordinate()->SetCoordinateSystemToViewport();
  this->LegendActor->GetPosition2Coordinate()->SetReferenceCoordinate(NULL);
  this->LegendActor->BorderOff();
  this->LegendActor->SetNumberOfEntries(100); //initial allocation
  this->LegendActor->SetPadding(2);
  this->LegendActor->ScalarVisibilityOff();
  this->GlyphSource = vtkGlyphSource2D::New();
  this->GlyphSource->SetGlyphTypeToNone();
  this->GlyphSource->DashOn();
  this->GlyphSource->FilledOff();

  this->PlotData = vtkPolyData::New();
  this->PlotMapper = vtkPolyDataMapper2D::New();
  this->PlotMapper->SetInput(this->PlotData);
  this->PlotActor = vtkActor2D::New();
  this->PlotActor->SetMapper(this->PlotMapper);

  this->TitleMapper = vtkTextMapper::New();
  this->TitleActor = vtkActor2D::New();
  this->TitleActor->SetMapper(this->TitleMapper);
  this->TitleActor->GetPositionCoordinate()->SetCoordinateSystemToViewport();

  this->N = 0;
  this->Total = 0.0;
  this->Fractions = NULL;

  this->WebData = vtkPolyData::New();
  this->WebMapper = vtkPolyDataMapper2D::New();
  this->WebMapper->SetInput(this->WebData);
  this->WebActor = vtkActor2D::New();
  this->WebActor->SetMapper(this->WebMapper);

  this->LastPosition[0] = 
    this->LastPosition[1] = 
    this->LastPosition2[0] = 
    this->LastPosition2[1] = 0;
  
  this->P1[0] = this->P1[1] = this->P2[0] = this->P2[1] = 0.0;
}

//----------------------------------------------------------------------------
vtkPieChartActor::~vtkPieChartActor()
{
  if ( this->Input )
    {
    this->Input->Delete();
    this->Input = NULL;
    }

  if (this->Title)
    {
    delete [] this->Title;
    this->Title = NULL;
    }
  
  delete this->Labels;
  this->SetLabelTextProperty(NULL);
  this->SetTitleTextProperty(NULL);

  this->LegendActor->Delete();
  this->GlyphSource->Delete();
  
  this->Initialize();
  
  this->TitleMapper->Delete();
  this->TitleMapper = NULL;
  this->TitleActor->Delete();
  this->TitleActor = NULL;
  
  this->WebData->Delete();
  this->WebMapper->Delete();
  this->WebActor->Delete();

  this->PlotData->Delete();
  this->PlotMapper->Delete();
  this->PlotActor->Delete();
}

//----------------------------------------------------------------------------
// Free-up axes and related stuff
void vtkPieChartActor::Initialize()
{
  if ( this->PieceActors )
    {
    for (int i=0; i<this->N; i++)
      {
      this->PieceMappers[i]->Delete();
      this->PieceActors[i]->Delete();
      }
    delete [] this->PieceMappers;
    this->PieceMappers = NULL;
    delete [] this->PieceActors;
    this->PieceActors = NULL;
    }

  this->N = 0;
  this->Total = 0.0;
  if ( this->Fractions )
    {
    delete [] this->Fractions;
    }
}

//----------------------------------------------------------------------------
// Plot scalar data for each input dataset.
int vtkPieChartActor::RenderOverlay(vtkViewport *viewport)
{
  int renderedSomething=0;

  if ( !this->BuildPlot(viewport) )
    {
    return 0;
    }

  // Done rebuilding, render as appropriate.
  if ( this->Input == NULL || this->N <= 0 )
    {
    vtkErrorMacro(<< "Nothing to plot!");
    return 0;
    }

  if ( this->TitleVisibility )
    {
    renderedSomething += this->TitleActor->RenderOverlay(viewport);
    }

  this->WebActor->SetProperty(this->GetProperty());
  renderedSomething += this->PlotActor->RenderOverlay(viewport);
  renderedSomething += this->WebActor->RenderOverlay(viewport);

  if ( this->LabelVisibility )
    {
    for (int i=0; i<this->N; i++)
      {
      renderedSomething += this->PieceActors[i]->RenderOverlay(viewport);
      }
    }
  
  if ( this->LegendVisibility )
    {
    renderedSomething += this->LegendActor->RenderOverlay(viewport);
    }

  return renderedSomething;
}

//----------------------------------------------------------------------------
// Plot scalar data for each input dataset.
int vtkPieChartActor::RenderOpaqueGeometry(vtkViewport *viewport)
{
  int renderedSomething=0;

  if ( !this->BuildPlot(viewport) )
    {
    return 0;
    }

  // Done rebuilding, render as appropriate.
  if ( this->Input == NULL || this->N <= 0 )
    {
    vtkErrorMacro(<< "Nothing to plot!");
    return 0;
    }

  if ( this->TitleVisibility )
    {
    renderedSomething += this->TitleActor->RenderOpaqueGeometry(viewport);
    }

  this->WebActor->SetProperty(this->GetProperty());
  renderedSomething += this->PlotActor->RenderOpaqueGeometry(viewport);
  renderedSomething += this->WebActor->RenderOpaqueGeometry(viewport);

  if ( this->LabelVisibility )
    {
    for (int i=0; i<this->N; i++)
      {
      renderedSomething += this->PieceActors[i]->RenderOpaqueGeometry(viewport);
      }
    }
  
  if ( this->LegendVisibility )
    {
    renderedSomething += this->LegendActor->RenderOpaqueGeometry(viewport);
    }

  return renderedSomething;
}

//-----------------------------------------------------------------------------
// Description:
// Does this prop have some translucent polygonal geometry?
int vtkPieChartActor::HasTranslucentPolygonalGeometry()
{
  return 0;
}


//-----------------------------------------------------------------------------  
int vtkPieChartActor::BuildPlot(vtkViewport *viewport)
{
  // Initialize
  vtkDebugMacro(<<"Building pie chart plot");
  
  // Make sure input is up to date, and that the data is the correct shape to
  // plot.
  if (!this->Input)
    {
    vtkErrorMacro(<< "Nothing to plot!");
    return 0;
    }

  if (!this->TitleTextProperty)
    {
    vtkErrorMacro(<<"Need title text property to render plot");
    return 0;
    }
  if (!this->LabelTextProperty)
    {
    vtkErrorMacro(<<"Need label text property to render plot");
    return 0;
    }

  // Viewport change may not require rebuild
  int positionsHaveChanged = 0;
  if (viewport->GetMTime() > this->BuildTime || 
      (viewport->GetVTKWindow() && 
       viewport->GetVTKWindow()->GetMTime() > this->BuildTime))
    {
    int *lastPosition = 
      this->PositionCoordinate->GetComputedViewportValue(viewport);
    int *lastPosition2 =
      this->Position2Coordinate->GetComputedViewportValue(viewport);
    if (lastPosition[0] != this->LastPosition[0] ||
        lastPosition[1] != this->LastPosition[1] ||
        lastPosition2[0] != this->LastPosition2[0] ||
        lastPosition2[1] != this->LastPosition2[1] )
      {
      this->LastPosition[0] = lastPosition[0];
      this->LastPosition[1] = lastPosition[1];
      this->LastPosition2[0] = lastPosition2[0];
      this->LastPosition2[1] = lastPosition2[1];
      positionsHaveChanged = 1;
      }
    }
  
  // Check modified time to see whether we have to rebuild.
330
  //this->Input->Update();
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

  if (positionsHaveChanged ||
      this->GetMTime() > this->BuildTime ||
      this->Input->GetMTime() > this->BuildTime ||
      this->LabelTextProperty->GetMTime() > this->BuildTime ||
      this->TitleTextProperty->GetMTime() > this->BuildTime)
    {
    vtkDebugMacro(<<"Rebuilding plot");

    // Build axes
    int *size = viewport->GetSize();
    if (!this->PlaceAxes(viewport, size))
      {
      return 0;
      }

    this->BuildTime.Modified();
    } // If need to rebuild the plot
  
  return 1;
}

//----------------------------------------------------------------------------
int vtkPieChartActor::PlaceAxes(vtkViewport *viewport, int* vtkNotUsed(size))
{
  vtkIdType i, j;
  vtkDataObject *input = this->GetInput();
  vtkFieldData *field = input->GetFieldData();
  double v = 0.0;

  this->Initialize();

  if ( ! field )
    {
    return 0;
    }
  
  // Retrieve the appropriate data array
  vtkDataArray *da = field->GetArray(this->ArrayNumber);
  if ( ! da )
    {
    return 0;
    }

  // Determine the number of independent variables
  this->N = da->GetNumberOfTuples();
  if ( this->N <= 0 || this->N >= VTK_LARGE_ID )
    {
    this->N = 0;
    vtkErrorMacro(<<"No field data to plot");
    return 0;
    }
  
  // We need to loop over the field to determine the total
  this->Total = 0.0;
  this->Fractions = new double[this->N];
  for (i=0; i<this->N; i++)
    {
    v = fabs(da->GetComponent(i,this->ComponentNumber));
    this->Fractions[i] = v;
    this->Total += v;
    }
  if ( this->Total > 0.0 )
    {
    double total=0.0;
    for (i=0; i<this->N; i++)
      {
      total += this->Fractions[i];
      this->Fractions[i] = total/this->Total;
      }
    }
  
  // Get the location of the corners of the box
  double *p1 = this->PositionCoordinate->GetComputedDoubleViewportValue(viewport);
  double *p2 = this->Position2Coordinate->GetComputedDoubleViewportValue(viewport);
  this->P1[0] = (p1[0] < p2[0] ? p1[0] : p2[0]);
  this->P1[1] = (p1[1] < p2[1] ? p1[1] : p2[1]);
  this->P2[0] = (p1[0] > p2[0] ? p1[0] : p2[0]);
  this->P2[1] = (p1[1] > p2[1] ? p1[1] : p2[1]);
  p1 = this->P1;
  p2 = this->P2;

  // Create the borders of the pie pieces.
  // Determine the center of the pie. Leave room for the title and the legend.
  double titleSpace=0.0, legendSpace=0.0;
  if ( this->TitleVisibility )
    {
    titleSpace = 0.1;
    }
  if ( this->LegendVisibility )
    {
    legendSpace = 0.15;
    }
  
  double d1 = p2[0] - legendSpace*(p2[0]-p1[0]) - p1[0];
  double d2 = p2[1] - titleSpace*(p2[1]-p1[1]) - p1[1];

  this->Center[0] = p1[0] + d1/2.0;
  this->Center[1] = p1[1] + d2/2.0;
  this->Center[2] = 0.0;
  this->Radius = (d1 < d2 ? d1 : d2);
  this->Radius /= 2.0;

  // Now generate the web points
  this->WebData->Initialize(); //remove old polydata, if any
  vtkPoints *webPts = vtkPoints::New();
  webPts->Allocate(this->N+1);
  vtkCellArray *webLines = vtkCellArray::New();
  webLines->Allocate(this->N,2);
  this->WebData->SetPoints(webPts);
  this->WebData->SetLines(webLines);
  vtkIdType ptId, pIds[2];
  double theta, x[3]; x[2] = 0.0;

  // Specify the positions for the axes
  pIds[0] = webPts->InsertNextPoint(this->Center);
  for (i=0; i<this->N; i++)
    {
    theta = this->Fractions[i] * 2.0*vtkMath::Pi();
    x[0] = this->Center[0] + this->Radius*cos(theta);
    x[1] = this->Center[1] + this->Radius*sin(theta);
    pIds[1] = webPts->InsertNextPoint(x);
    webLines->InsertNextCell(2,pIds);
    }

  // Draw a bounding ring
  webLines->InsertNextCell(65);
  theta = 2.0*vtkMath::Pi() / 64;
  for (j=0; j<65; j++)
    {
    x[0] = this->Center[0] + this->Radius*cos(j*theta);
    x[1] = this->Center[1] + this->Radius*sin(j*theta);
    ptId = webPts->InsertNextPoint(x);
    webLines->InsertCellPoint(ptId);
    }

  // Produce labels around the rim of the plot
  double thetaM;
  char label[1024];
  const char *str;
  int minFontSize=1000, fontSize, tsize[2];
  if ( this->LabelVisibility )
    {
    this->PieceActors = new vtkActor2D* [this->N];
    this->PieceMappers = new vtkTextMapper* [this->N];
    for (i=0; i<this->N; i++)
      {
      thetaM = (i==0 ? 0.0 : this->Fractions[i-1] * 2.0*vtkMath::Pi());
      theta = this->Fractions[i] * 2.0*vtkMath::Pi();
      x[0] = this->Center[0] + (this->Radius+5)*cos((theta+thetaM)/2.0);
      x[1] = this->Center[1] + (this->Radius+5)*sin((theta+thetaM)/2.0);
      this->PieceMappers[i] = vtkTextMapper::New();
      if ( (str=this->GetPieceLabel(i)) != NULL )
        {
        this->PieceMappers[i]->SetInput(str);
        }
      else
        {
Will Schroeder's avatar
Will Schroeder committed
489
        sprintf(label,"%d",static_cast<int>(i));
490 491 492 493
        this->PieceMappers[i]->SetInput(label);
        }
      this->PieceMappers[i]->GetTextProperty()->
        ShallowCopy(this->LabelTextProperty);
494 495
      tsize[0] = static_cast<int>(0.15*d1);
      tsize[1] = static_cast<int>(0.15*d2);
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
      fontSize = this->PieceMappers[i]->SetConstrainedFontSize(
        viewport, tsize[0], tsize[1]);
      minFontSize = (fontSize < minFontSize ? fontSize : minFontSize);
      this->PieceActors[i] = vtkActor2D::New();
      this->PieceActors[i]->SetMapper(this->PieceMappers[i]);
      this->PieceActors[i]->GetPositionCoordinate()->
        SetCoordinateSystemToViewport();
      this->PieceActors[i]->SetPosition(x);
      // depending on the qudrant, the text is aligned differently
      if ( x[0] >= this->Center[0] && x[1] >= this->Center[1] )
        {
        this->PieceMappers[i]->GetTextProperty()->SetJustificationToLeft();
        this->PieceMappers[i]->GetTextProperty()->SetVerticalJustificationToBottom();
        }
      else if ( x[0] < this->Center[0] && x[1] >= this->Center[1] )
        {
        this->PieceMappers[i]->GetTextProperty()->SetJustificationToRight();
        this->PieceMappers[i]->GetTextProperty()->SetVerticalJustificationToBottom();
        }
      else if ( x[0] < this->Center[0] && x[1] < this->Center[1] )
        {
        this->PieceMappers[i]->GetTextProperty()->SetJustificationToRight();
        this->PieceMappers[i]->GetTextProperty()->SetVerticalJustificationToTop();
        }
      else if ( x[0] >= this->Center[0] && x[1] < this->Center[1] )
        {
        this->PieceMappers[i]->GetTextProperty()->SetJustificationToLeft();
        this->PieceMappers[i]->GetTextProperty()->SetVerticalJustificationToTop();
        }
      }//for all pieces of pie
    //Now reset font sizes to the same value
    for (i=0; i<this->N; i++)
      {
      this->PieceMappers[i]->GetTextProperty()->SetFontSize(minFontSize);
      }
    }

  // Now generate the pie polygons
  this->PlotData->Initialize(); //remove old polydata, if any
  vtkPoints *pts = vtkPoints::New();
  pts->Allocate(this->N*2);
  vtkCellArray *polys = vtkCellArray::New();
  vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
  colors->SetNumberOfComponents(3);
  this->PlotData->SetPoints(pts);
  this->PlotData->SetPolys(polys);
  this->PlotData->GetCellData()->SetScalars(colors);
  colors->Delete();

  double *color, delTheta;
  vtkIdType numDivs;
  polys->Allocate(polys->EstimateSize(this->N,12));

  pIds[0] = pts->InsertNextPoint(this->Center);
  for (i=0; i<this->N; i++)
    {
    thetaM = (i==0 ? 0.0 : this->Fractions[i-1] * 2.0*vtkMath::Pi());
    theta = this->Fractions[i] * 2.0*vtkMath::Pi();
554
    numDivs = static_cast<vtkIdType>(32 * (theta-thetaM) / vtkMath::Pi());
555 556 557 558 559 560 561 562 563 564 565 566 567 568
    numDivs = (numDivs < 2 ? 2 : numDivs);
    delTheta = (theta - thetaM) / numDivs;
    
    polys->InsertNextCell(numDivs+2);
    polys->InsertCellPoint(pIds[0]);
    color = this->LegendActor->GetEntryColor(i);
    colors->InsertNextTuple3(255*color[0],255*color[1],255*color[2]);
    this->LegendActor->SetEntrySymbol(i,this->GlyphSource->GetOutput());
    if ( (str=this->GetPieceLabel(i)) != NULL )
      {
      this->LegendActor->SetEntryString(i,str);
      }
    else
      {
Will Schroeder's avatar
Will Schroeder committed
569
      sprintf(label,"%d",static_cast<int>(i));
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
      this->LegendActor->SetEntryString(i,label);
      }

    for (j=0; j<=numDivs; j++)
      {
      theta = thetaM + j*delTheta;
      x[0]  = this->Center[0] + this->Radius * cos(theta);
      x[1]  = this->Center[1] + this->Radius * sin(theta);
      ptId = pts->InsertNextPoint(x);
      polys->InsertCellPoint(ptId);
      }
    }
  
  //Display the legend
  if ( this->LegendVisibility )
    {
    this->LegendActor->GetProperty()->DeepCopy(this->GetProperty());
    this->LegendActor->GetPositionCoordinate()->SetValue(
      p1[0] + 0.85*(p2[0]-p1[0]),p1[1] + 0.20*(p2[1]-p1[1]));
    this->LegendActor->GetPosition2Coordinate()->SetValue(
      p2[0], p1[1] + 0.80*(p2[1]-p1[1]));
    }

  // Build title
  this->TitleMapper->SetInput(this->Title);
  if (this->TitleTextProperty->GetMTime() > this->BuildTime)
    {
    // Shallow copy here since the justification is changed but we still
    // want to allow actors to share the same text property, and in that case
    // specifically allow the title and label text prop to be the same.
    this->TitleMapper->GetTextProperty()->ShallowCopy(
      this->TitleTextProperty);
    this->TitleMapper->GetTextProperty()->SetJustificationToCentered();
    }

  // We could do some caching here, but hey, that's just the title
606 607
  tsize[0] = static_cast<int>(0.25*d1);
  tsize[1] = static_cast<int>(0.15*d2);
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
  this->TitleMapper->SetConstrainedFontSize(viewport, tsize[0], tsize[1]);

  this->TitleActor->GetPositionCoordinate()->
    SetValue(this->Center[0],this->Center[1]+this->Radius+tsize[1]);
  this->TitleActor->SetProperty(this->GetProperty());

  //Clean up
  webPts->Delete();
  webLines->Delete();
  pts->Delete();
  polys->Delete();

  return 1;
}

//----------------------------------------------------------------------------
// Release any graphics resources that are being consumed by this actor.
// The parameter window could be used to determine which graphic
// resources to release.
void vtkPieChartActor::ReleaseGraphicsResources(vtkWindow *win)
{
  this->TitleActor->ReleaseGraphicsResources(win);
  this->LegendActor->ReleaseGraphicsResources(win);
  this->WebActor->ReleaseGraphicsResources(win);
  this->PlotActor->ReleaseGraphicsResources(win);
  for (int i=0; this->PieceActors && i<this->N; i++)
    {
    this->PieceActors[i]->ReleaseGraphicsResources(win);
    }
}

//----------------------------------------------------------------------------
void vtkPieChartActor::SetPieceLabel(const int i, const char *label)
{
  if ( i < 0 )
    {
    return;
    }
  
  if ( static_cast<unsigned int>(i) >= this->Labels->size() )
    {
    this->Labels->resize(i+1);
    }
  (*this->Labels)[i] = vtkstd::string(label);
  this->Modified();
}

//----------------------------------------------------------------------------
const char* vtkPieChartActor::GetPieceLabel(int i)
{
  if ( i < 0 || static_cast<unsigned int>(i) >= this->Labels->size())
    {
    return NULL;
    }
  
  return this->Labels->at(i).c_str();
}

//----------------------------------------------------------------------------
void vtkPieChartActor::SetPieceColor(int i, double r, double g, double b)
{
  this->LegendActor->SetEntryColor(i, r, g, b);
}

//----------------------------------------------------------------------------
double *vtkPieChartActor::GetPieceColor(int i)
{
  return this->LegendActor->GetEntryColor(i);
}

//----------------------------------------------------------------------------
void vtkPieChartActor::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);

  os << indent << "Input: " << this->Input << "\n";

  os << indent << "Title Visibility: " 
     << (this->TitleVisibility ? "On\n" : "Off\n");
  
  os << indent << "Title: " << (this->Title ? this->Title : "(none)") << "\n";

  if (this->TitleTextProperty)
    {
    os << indent << "Title Text Property:\n";
    this->TitleTextProperty->PrintSelf(os,indent.GetNextIndent());
    }
  else
    {
    os << indent << "Title Text Property: (none)\n";
    }

  os << indent << "Label Visibility: " 
     << (this->LabelVisibility ? "On\n" : "Off\n");
  
  if (this->LabelTextProperty)
    {
    os << indent << "Label Text Property:\n";
    this->LabelTextProperty->PrintSelf(os,indent.GetNextIndent());
    }
  else
    {
    os << indent << "Label Text Property: (none)\n";
    }

  os << indent << "Legend Visibility: " 
     << (this->LegendVisibility ? "On\n" : "Off\n");
  
  os << indent << "Legend Actor: " 
     << this->LegendActor << "\n";
  this->LegendActor->PrintSelf(os, indent.GetNextIndent());
  
}