Go to the documentation of this file.00001 #include "vtkOdfSource.h"
00002
00003 #include "vtkCellArray.h"
00004 #include "vtkInformation.h"
00005 #include "vtkInformationVector.h"
00006 #include "vtkPoints.h"
00007 #include "vtkStreamingDemandDrivenPipeline.h"
00008 #include "vtkObjectFactory.h"
00009 #include "vtkDoubleArray.h"
00010 #include "vtkCellData.h"
00011
00012 #include <limits>
00013
00014 vtkCxxRevisionMacro(vtkOdfSource, "$Revision: 1.1 $");
00015 vtkStandardNewMacro(vtkOdfSource);
00016
00017 vtkOdfSource::vtkOdfSource()
00018 {
00019 this->SetNumberOfInputPorts(0);
00020 }
00021
00022
00023 int vtkOdfSource::RequestData(
00024 vtkInformation *vtkNotUsed(request),
00025 vtkInformationVector **vtkNotUsed(inputVector),
00026 vtkInformationVector *outputVector)
00027 {
00028
00029 vtkInformation *outInfo = outputVector->GetInformationObject(0);
00030
00031
00032 vtkPolyData *output = vtkPolyData::SafeDownCast(
00033 outInfo->Get(vtkDataObject::DATA_OBJECT()));
00034
00035 vtkPoints *newPoints;
00036 newPoints = vtkPoints::New();
00037 int numPoints = TemplateOdf->GetPoints()->GetNumberOfPoints();
00038 newPoints->Allocate(numPoints);
00039 for(int j=0; j<numPoints; j++){
00040 double p[3];
00041 TemplateOdf->GetPoints()->GetPoint(j,p);
00042 if(OdfVals->GetNumberOfComponents())
00043 {
00044 double val = OdfVals->GetComponent(0,j);
00045
00046
00047 p[0] *= val*Scale;
00048 p[1] *= val*Scale;
00049 p[2] *= val*Scale;
00050
00051
00052
00053
00054 }
00055 newPoints->InsertNextPoint(p);
00056 }
00057 output->SetPoints(newPoints);
00058 newPoints->Delete();
00059
00060 vtkCellArray* polys = TemplateOdf->GetPolys();
00061 output->SetPolys(polys);
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 vtkDoubleArray* colors = vtkDoubleArray::New();
00077 int numCells = polys->GetNumberOfCells();
00078 colors->Allocate(numCells);
00079 polys->InitTraversal();
00080 vtkIdType cellId = 0;
00081 vtkIdType npts; vtkIdType *pts;
00082 while(polys->GetNextCell(npts,pts))
00083 {
00084 double val = 0;
00085 for(int i=0; i<npts; i++)
00086 {
00087 vtkIdType pointId = pts[i];
00088 val += OdfVals->GetComponent(0,pointId);
00089 }
00090 val /= npts;
00091 colors->SetComponent(0,cellId++,-(val-0.5)*(1/0.5));
00092 }
00093 output->GetCellData()->SetScalars(colors);
00094 colors->Delete();
00095 return 1;
00096 }
00097
00098
00099 void vtkOdfSource::PrintSelf(ostream& os, vtkIndent indent)
00100 {
00101 this->Superclass::PrintSelf(os,indent);
00102 }
00103
00104
00105 int vtkOdfSource::RequestInformation(
00106 vtkInformation *vtkNotUsed(request),
00107 vtkInformationVector **vtkNotUsed(inputVector),
00108 vtkInformationVector *outputVector)
00109 {
00110
00111 vtkInformation *outInfo = outputVector->GetInformationObject(0);
00112
00113 outInfo->Set(vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES(),
00114 -1);
00115
00116 outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_BOUNDING_BOX(),1,1,1,1,1,1);
00117
00118 return 1;
00119 }