vtkSectorSource.cxx 4.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkSectorSource.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.

14
     =========================================================================*/
15 16 17 18 19 20 21 22
#include "vtkSectorSource.h"

#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPolyData.h"
#include "vtkLineSource.h"
#include "vtkRotationalExtrusionFilter.h"
23
#include "vtkMath.h"
24
#include "vtkStreamingDemandDrivenPipeline.h"
25 26

#include "vtkSmartPointer.h"
27
#define VTK_CREATE(type, name)                                  \
28 29 30 31 32 33 34 35
  vtkSmartPointer<type> name = vtkSmartPointer<type>::New()

vtkStandardNewMacro(vtkSectorSource);

vtkSectorSource::vtkSectorSource()
{
  this->InnerRadius = 1.0;
  this->OuterRadius = 2.0;
36
  this->ZCoord = 0.0;
37 38 39 40
  this->StartAngle = 0.0;
  this->EndAngle = 90.0;
  this->RadialResolution = 1;
  this->CircumferentialResolution = 6;
41

42 43 44 45 46 47 48 49 50 51
  this->SetNumberOfInputPorts(0);
}

int vtkSectorSource::RequestData(
  vtkInformation *vtkNotUsed(request),
  vtkInformationVector **vtkNotUsed(inputVector),
  vtkInformationVector *outputVector)
{
  // get the info object
  vtkInformation *outInfo = outputVector->GetInformationObject(0);
52

53 54 55
  // get the ouptut
  vtkPolyData *output = vtkPolyData::SafeDownCast(
    outInfo->Get(vtkDataObject::DATA_OBJECT()));
56

57
  int piece, numPieces;
58 59
  piece = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER());
  numPieces = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES());
60
  outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_GHOST_LEVELS());
61

62 63 64 65 66 67 68 69 70
//   if( (this->StartAngle == 0. && this->EndAngle == 360.) ||
//       (this->StartAngle == 360. && this->EndAngle == 0. ) )
//   {
//       //use vtkDiskSource
//     VTK_CREATE(vtkDiskSource, diskSource );
//     diskSource->SetCircumferentialResolution( this->CircumferentialResolution );
//     diskSource->SetRadialResolution( this->RadialResolution );
//     diskSource->SetInnerRadius( this->InnerRadius );
//     diskSource->SetOuterRadius( this->OuterRadius );
71

72 73 74 75 76 77 78 79 80 81 82 83 84
//     if (output->GetUpdatePiece() == 0 && numPieces > 0)
//     {
//       diskSource->Update();
//       output->ShallowCopy(diskSource->GetOutput());
//     }
//     output->SetUpdatePiece(piece);
//     output->SetUpdateNumberOfPieces(numPieces);
//     output->SetUpdateGhostLevel(ghostLevel);
//   }
//   else
//   {
  VTK_CREATE(vtkLineSource, lineSource);
  lineSource->SetResolution( this->RadialResolution );
85

86 87
  //set vertex 1, adjust for start angle
  //set vertex 2, adjust for start angle
88 89 90 91
  double x1[3], x2[3];
  x1[0] = this->InnerRadius * cos( vtkMath::RadiansFromDegrees( this->StartAngle ) );
  x1[1] = this->InnerRadius * sin( vtkMath::RadiansFromDegrees( this->StartAngle ) );
  x1[2] = this->ZCoord;
92

93 94 95
  x2[0] = this->OuterRadius * cos( vtkMath::RadiansFromDegrees( this->StartAngle ) );
  x2[1] = this->OuterRadius * sin( vtkMath::RadiansFromDegrees( this->StartAngle ) );
  x2[2] = this->ZCoord;
96

97 98 99
  lineSource->SetPoint1(x1);
  lineSource->SetPoint2(x2);
  lineSource->Update();
100

101 102
  VTK_CREATE(vtkRotationalExtrusionFilter, rotateFilter);
  rotateFilter->SetResolution( this->CircumferentialResolution );
103
  rotateFilter->SetInputConnection(lineSource->GetOutputPort());
104
  rotateFilter->SetAngle( this->EndAngle - this->StartAngle );
105

106
  if (piece == 0 && numPieces > 0)
107
  {
108 109
    rotateFilter->Update();
    output->ShallowCopy(rotateFilter->GetOutput());
110
  }
111
//  }
112

113 114 115 116 117 118
  return 1;
}

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

120 121
  os << indent << "InnerRadius: " << this->InnerRadius << "\n";
  os << indent << "OuterRadius: " << this->OuterRadius << "\n";
122
  os << indent << "ZCoord: " << this->ZCoord << "\n";
123 124 125 126 127
  os << indent << "StartAngle: " << this->StartAngle << "\n";
  os << indent << "EndAngle: " << this->EndAngle << "\n";;
  os << indent << "CircumferentialResolution: " << this->CircumferentialResolution << "\n";
  os << indent << "RadialResolution: " << this->RadialResolution << "\n";
}