| 355 | } |
| 356 | |
| 357 | void vtkBYUReader::ReadTextureFile(int numPts, vtkInformation* outInfo) |
| 358 | { |
| 359 | FILE* textureFp; |
| 360 | int i; |
| 361 | float t[2]; |
| 362 | vtkFloatArray* newTCoords; |
| 363 | vtkPolyData* output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT())); |
| 364 | |
| 365 | if (this->ReadTexture && this->TextureFileName) |
| 366 | { |
| 367 | if (!(textureFp = vtksys::SystemTools::Fopen(this->TextureFileName, "r"))) |
| 368 | { |
| 369 | vtkErrorMacro(<< "Couldn't open texture file"); |
| 370 | return; |
| 371 | } |
| 372 | } |
| 373 | else |
| 374 | { |
| 375 | return; |
| 376 | } |
| 377 | // |
| 378 | // Allocate and read data |
| 379 | // |
| 380 | newTCoords = vtkFloatArray::New(); |
| 381 | newTCoords->SetNumberOfComponents(3); |
| 382 | newTCoords->SetNumberOfTuples(numPts); |
| 383 | |
| 384 | for (i = 0; i < numPts; i++) |
| 385 | { |
| 386 | auto resultTCoord = vtk::scan<float, float>(textureFp, "{:e} {:e}"); |
| 387 | if (!resultTCoord) |
| 388 | { |
| 389 | vtkErrorMacro(<< "Error reading texture file: " << this->TextureFileName |
| 390 | << "Message: " << resultTCoord.error().msg()); |
| 391 | fclose(textureFp); |
| 392 | return; |
| 393 | } |
| 394 | std::tie(t[0], t[1]) = resultTCoord->values(); |
| 395 | newTCoords->SetTypedTuple(i, t); |
| 396 | } |
| 397 | |
| 398 | fclose(textureFp); |
| 399 | vtkDebugMacro(<< "Read " << numPts << " texture coordinates"); |
| 400 | |
| 401 | output->GetPointData()->SetTCoords(newTCoords); |
| 402 | newTCoords->Delete(); |
| 403 | } |
| 404 | |
| 405 | //------------------------------------------------------------------------------ |
| 406 | // This source does not know how to generate pieces yet. |
no test coverage detected