35 vtkInformationVector** inputVector,
36 vtkInformationVector* outputVector)
42 ERR(
"VtkTextureOnSurfaceFilter::RequestData() - No texture specified.");
46 vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
48 vtkPolyData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
51 this->
GetTexture()->GetInput()->GetDimensions(dims);
52 std::size_t imgWidth = dims[0];
53 std::size_t imgHeight = dims[1];
55 std::pair<int, int> min(
static_cast<int>(
_origin.first),
56 static_cast<int>(
_origin.second));
57 std::pair<int, int> max(
62 vtkPoints* points = input->GetPoints();
63 vtkSmartPointer<vtkFloatArray> textureCoordinates =
64 vtkSmartPointer<vtkFloatArray>::New();
65 textureCoordinates->SetNumberOfComponents(2);
66 std::size_t nPoints = points->GetNumberOfPoints();
67 textureCoordinates->SetNumberOfTuples(nPoints);
68 textureCoordinates->SetName(
"textureCoords");
97 int const range[2] = {max.first - min.first, max.second - min.second};
101 for (std::size_t i = 0; i < nPoints; i++)
103 points->GetPoint(i, coords);
105 textureCoordinates->SetTuple2(i,
106 (coords[0] - min.first) / range[0],
107 (coords[1] - min.second) / range[1]);
111 vtkInformation* outInfo = outputVector->GetInformationObject(0);
112 vtkPolyData* output =
113 vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
114 output->CopyStructure(input);
115 output->GetPointData()->PassData(input->GetPointData());
116 output->GetCellData()->PassData(input->GetCellData());
117 output->GetPointData()->SetTCoords(textureCoordinates);
127 img->GetOutput()->GetPointData()->GetScalars()->GetRange(range);
128 vtkSmartPointer<vtkImageShiftScale> scale =
129 vtkSmartPointer<vtkImageShiftScale>::New();
130 scale->SetInputConnection(img->GetOutputPort());
131 scale->SetShift(-range[0]);
132 scale->SetScale(255.0 / (range[1] - range[0]));
133 scale->SetOutputScalarTypeToUnsignedChar();
137 vtkTexture* texture = vtkTexture::New();
138 texture->InterpolateOff();
139 texture->RepeatOff();
141 texture->SetInputData(scale->GetOutput());
144 double* origin = img->GetOutput()->GetOrigin();
145 _origin = {origin[0], origin[1]};
vtkStandardNewMacro(VtkTextureOnSurfaceFilter)
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.