Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
vtkOdfSource.cxx
Go to the documentation of this file.
1 #include "vtkOdfSource.h"
2 
3 #include "vtkCellArray.h"
4 #include "vtkInformation.h"
5 #include "vtkInformationVector.h"
6 #include "vtkPoints.h"
7 #include "vtkStreamingDemandDrivenPipeline.h"
8 #include "vtkObjectFactory.h"
9 #include "vtkDoubleArray.h"
10 #include "vtkCellData.h"
11 
12 #include <limits>
13 
15 
17 {
18  Scale = 1;
19  this->SetNumberOfInputPorts(0);
20 }
21 
22 //----------------------------------------------------------------------------
24  vtkInformation *vtkNotUsed(request),
25  vtkInformationVector **vtkNotUsed(inputVector),
26  vtkInformationVector *outputVector)
27 {
28  vtkPolyData* TemplateOdf = OdfType::GetBaseMesh();
29  // get the info object
30  vtkInformation *outInfo = outputVector->GetInformationObject(0);
31 
32  // get the ouptut
33  vtkPolyData *output = vtkPolyData::SafeDownCast(
34  outInfo->Get(vtkDataObject::DATA_OBJECT()));
35 
36  OdfType colorOdf;
37  switch(Normalization)
38  {
39  case mitk::ODFN_MINMAX:
41  colorOdf = Odf;
42  break;
43  case mitk::ODFN_MAX:
44  Odf = Odf.MaxNormalize();
45  colorOdf = Odf;
46  break;
47  case mitk::ODFN_NONE:
48  colorOdf = Odf.MaxNormalize();
49  break;
50  default:
52  colorOdf = Odf;
53  }
54 
55 
56  vtkIdType cellId = 0;
57  vtkIdType npts; vtkIdType *pts;
58  vtkPoints *newPoints;
59  vtkCellArray* polys = TemplateOdf->GetPolys();
60  output->SetPolys(polys);
61  vtkDoubleArray* colors = vtkDoubleArray::New();
62  int numCells = polys->GetNumberOfCells();
63  colors->Allocate(numCells);
64  polys->InitTraversal();
65  newPoints = vtkPoints::New();
66  int numPoints = TemplateOdf->GetPoints()->GetNumberOfPoints();
67  newPoints->Allocate(numPoints);
68 
69  while(polys->GetNextCell(npts,pts))
70  {
71  double val = 0;
72  for(int i=0; i<npts; i++)
73  {
74  vtkIdType pointId = pts[i];
75  val += colorOdf.GetElement(pointId);
76  }
77  val /= npts;
78  colors->SetComponent(0,cellId++, 1-val);
79  }
80 
81  for(int j=0; j<numPoints; j++){
82  double p[3];
83  TemplateOdf->GetPoints()->GetPoint(j,p);
84  double val = Odf.GetElement(j);
85  p[0] *= val*Scale*AdditionalScale*0.5;
86  p[1] *= val*Scale*AdditionalScale*0.5;
87  p[2] *= val*Scale*AdditionalScale*0.5;
88  newPoints->InsertNextPoint(p);
89  }
90  output->SetPoints(newPoints);
91  output->GetCellData()->SetScalars(colors);
92  colors->Delete();
93  newPoints->Delete();
94  return 1;
95 }
96 
97 //----------------------------------------------------------------------------
98 void vtkOdfSource::PrintSelf(ostream& os, vtkIndent indent)
99 {
100  this->Superclass::PrintSelf(os,indent);
101 }
102 
103 //----------------------------------------------------------------------------
105  vtkInformation *vtkNotUsed(request),
106  vtkInformationVector **vtkNotUsed(inputVector),
107  vtkInformationVector *outputVector)
108 {
109  // get the info object
110  vtkInformation *outInfo = outputVector->GetInformationObject(0);
111 
112  outInfo->Set(vtkAlgorithm::CAN_HANDLE_PIECE_REQUEST(),0);
113 
114  return 1;
115 }
double AdditionalScale
Definition: vtkOdfSource.h:61
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
double Scale
Definition: vtkOdfSource.h:60
void PrintSelf(ostream &os, vtkIndent indent) override
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
vtkStandardNewMacro(vtkOdfSource)
OdfType Odf
Definition: vtkOdfSource.h:59
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.