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
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkImageNoiseSource.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 "vtkImageNoiseSource.h"
#include "vtkImageData.h"
#include "vtkImageProgressIterator.h"
#include "vtkMath.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkStreamingDemandDrivenPipeline.h"
vtkStandardNewMacro(vtkImageNoiseSource);
//----------------------------------------------------------------------------
vtkImageNoiseSource::vtkImageNoiseSource()
{
this->Minimum = 0.0;
this->Maximum = 10.0;
this->WholeExtent[0] = 0; this->WholeExtent[1] = 255;
this->WholeExtent[2] = 0; this->WholeExtent[3] = 255;
this->WholeExtent[4] = 0; this->WholeExtent[5] = 0;
this->SetNumberOfInputPorts(0);
}
//----------------------------------------------------------------------------
void vtkImageNoiseSource::SetWholeExtent(int xMin, int xMax,
int yMin, int yMax,
int zMin, int zMax)
{
int modified = 0;
if (this->WholeExtent[0] != xMin)
{
modified = 1;
this->WholeExtent[0] = xMin ;
}
if (this->WholeExtent[1] != xMax)
{
modified = 1;
this->WholeExtent[1] = xMax ;
}
if (this->WholeExtent[2] != yMin)
{
modified = 1;
this->WholeExtent[2] = yMin ;
}
if (this->WholeExtent[3] != yMax)
{
modified = 1;
this->WholeExtent[3] = yMax ;
}
if (this->WholeExtent[4] != zMin)
{
modified = 1;
this->WholeExtent[4] = zMin ;
}
if (this->WholeExtent[5] != zMax)
{
modified = 1;
this->WholeExtent[5] = zMax ;
}
if (modified)
{
this->Modified();
}
}
//----------------------------------------------------------------------------
int vtkImageNoiseSource::RequestInformation (
vtkInformation * vtkNotUsed(request),
vtkInformationVector** vtkNotUsed( inputVector ),
vtkInformationVector *outputVector)
{
// get the info objects
vtkInformation* outInfo = outputVector->GetInformationObject(0);
outInfo->Set(vtkDataObject::SPACING(), 1.0, 1.0, 1.0);
outInfo->Set(vtkDataObject::ORIGIN(), 0.0, 0.0, 0.0);
outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),
this->WholeExtent,6);
vtkDataObject::SetPointDataActiveScalarInfo(outInfo, VTK_DOUBLE, 1);
return 1;
}
void vtkImageNoiseSource::ExecuteDataWithInformation(vtkDataObject *output,
vtkInformation *outInfo)
{
vtkImageData *data = this->AllocateOutputData(output, outInfo);
if (data->GetScalarType() != VTK_DOUBLE)
{
vtkErrorMacro("Execute: This source only outputs doubles");
}
vtkImageProgressIterator<double> outIt(data, data->GetExtent(), this, 0);
// Loop through ouput pixels
while (!outIt.IsAtEnd())
{
double* outSI = outIt.BeginSpan();
double* outSIEnd = outIt.EndSpan();
while (outSI != outSIEnd)
{
// now process the components
*outSI = this->Minimum +
(this->Maximum - this->Minimum) * vtkMath::Random();
outSI++;
}
outIt.NextSpan();
}
}
void vtkImageNoiseSource::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Minimum: " << this->Minimum << "\n";
os << indent << "Maximum: " << this->Maximum << "\n";
}
|