46 vtkInformationVector** inputVector,
47 vtkInformationVector* outputVector)
53 ERR(
"VtkTextureOnSurfaceFilter::RequestData() - No texture specified.");
57 vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
59 vtkPolyData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
62 this->
GetTexture()->GetInput()->GetDimensions(dims);
63 std::size_t imgWidth = dims[0];
64 std::size_t imgHeight = dims[1];
66 std::pair<int, int> min(
static_cast<int>(
_origin.first),
67 static_cast<int>(
_origin.second));
68 std::pair<int, int> max(
73 vtkPoints* points = input->GetPoints();
74 vtkSmartPointer<vtkFloatArray> textureCoordinates =
75 vtkSmartPointer<vtkFloatArray>::New();
76 textureCoordinates->SetNumberOfComponents(2);
77 std::size_t nPoints = points->GetNumberOfPoints();
78 textureCoordinates->SetNumberOfTuples(nPoints);
79 textureCoordinates->SetName(
"textureCoords");
108 int const range[2] = {max.first - min.first, max.second - min.second};
112 for (std::size_t i = 0; i < nPoints; i++)
114 points->GetPoint(i, coords);
116 textureCoordinates->SetTuple2(i,
117 (coords[0] - min.first) / range[0],
118 (coords[1] - min.second) / range[1]);
122 vtkInformation* outInfo = outputVector->GetInformationObject(0);
123 vtkPolyData* output =
124 vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
125 output->CopyStructure(input);
126 output->GetPointData()->PassData(input->GetPointData());
127 output->GetCellData()->PassData(input->GetCellData());
128 output->GetPointData()->SetTCoords(textureCoordinates);
138 img->GetOutput()->GetPointData()->GetScalars()->GetRange(range);
139 vtkSmartPointer<vtkImageShiftScale> scale =
140 vtkSmartPointer<vtkImageShiftScale>::New();
141 scale->SetInputConnection(img->GetOutputPort());
142 scale->SetShift(-range[0]);
143 scale->SetScale(255.0 / (range[1] - range[0]));
144 scale->SetOutputScalarTypeToUnsignedChar();
148 vtkTexture* texture = vtkTexture::New();
149 texture->InterpolateOff();
150 texture->RepeatOff();
152 texture->SetInputData(scale->GetOutput());
155 double* origin = img->GetOutput()->GetOrigin();
156 _origin = {origin[0], origin[1]};
vtkStandardNewMacro(VtkTextureOnSurfaceFilter)
Definition of the VtkTextureOnSurfaceFilter class.
Filter class for assigning a texture to a surface.
std::pair< double, double > _origin
~VtkTextureOnSurfaceFilter() override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
void PrintSelf(ostream &os, vtkIndent indent) override
Prints the object data to an output stream.
void SetUserProperty(QString name, QVariant value) override
Sets a user property. This should be implemented by subclasses.
VtkTextureOnSurfaceFilter()
void SetRaster(vtkImageAlgorithm *img)
Sets the raster/image to be used as a texture map.