20 #include <vtkBMPReader.h>
21 #include <vtkJPEGReader.h>
22 #include <vtkPNGReader.h>
23 #include <vtkPNMReader.h>
24 #include <vtkQImageToImageSource.h>
25 #include <vtkSmartPointer.h>
26 #include <vtkTIFFReader.h>
27 #include <vtkTexture.h>
33 vtkTexture* vtk_tex) {
39 if (!qimage.isNull()) {
42 qimageToImageSource->SetQImage(&qimage);
43 qimageToImageSource->Update();
44 vtk_tex->SetInputConnection(qimageToImageSource->GetOutputPort());
48 if (tex_mat.tex_file.empty()) {
52 std::string full_path = tex_mat.tex_file;
54 std::string parent_dir =
57 std::string upper_filename =
59 std::string real_name;
65 "[TextureLoader::LoadFromPCLMaterial] Parent directory "
66 "'%s' doesn't exist!",
73 "[TextureLoader::LoadFromPCLMaterial] Parent '%s' is "
79 std::vector<std::string> paths_vector;
81 parent_dir, paths_vector);
83 for (
const auto&
path : paths_vector) {
92 if (real_name.empty()) {
94 "[TextureLoader::LoadFromPCLMaterial] Can not find "
96 tex_mat.tex_file.c_str());
99 }
catch (
const std::exception& ex) {
101 "[TextureLoader::LoadFromPCLMaterial] Error %s when "
102 "looking for file %s!",
103 ex.what(), tex_mat.tex_file.c_str());
107 full_path = real_name;
110 std::string extension =
114 if ((extension ==
"jpg") || (extension ==
"jpeg")) {
117 jpeg_reader->SetFileName(full_path.c_str());
118 jpeg_reader->Update();
119 vtk_tex->SetInputConnection(jpeg_reader->GetOutputPort());
120 }
else if (extension ==
"bmp") {
123 bmp_reader->SetFileName(full_path.c_str());
124 bmp_reader->Update();
125 vtk_tex->SetInputConnection(bmp_reader->GetOutputPort());
126 }
else if (extension ==
"pnm") {
129 pnm_reader->SetFileName(full_path.c_str());
130 pnm_reader->Update();
131 vtk_tex->SetInputConnection(pnm_reader->GetOutputPort());
132 }
else if (extension ==
"png") {
135 png_reader->SetFileName(full_path.c_str());
136 png_reader->Update();
137 vtk_tex->SetInputConnection(png_reader->GetOutputPort());
138 }
else if ((extension ==
"tiff") || (extension ==
"tif")) {
141 tiff_reader->SetFileName(full_path.c_str());
142 tiff_reader->Update();
143 vtk_tex->SetInputConnection(tiff_reader->GetOutputPort());
146 "[TextureLoader::LoadFromPCLMaterial] Unhandled image %s "
147 "(extension: '%s') for material %s!",
148 full_path.c_str(), extension.c_str(), tex_mat.tex_name.c_str());
156 vtkTexture* vtk_tex) {
157 if (!material || !vtk_tex) {
163 QString tex_file = material->getTextureFilename(TexType::DIFFUSE);
164 if (tex_file.isEmpty()) {
166 tex_file = material->getTextureFilename();
170 if (!qimage.isNull()) {
173 qimageToImageSource->SetQImage(&qimage);
174 qimageToImageSource->Update();
175 vtk_tex->SetInputConnection(qimageToImageSource->GetOutputPort());
179 if (tex_file.isEmpty()) {
185 std::string parent_dir =
189 std::string real_name;
195 "[TextureLoader::LoadFromCCMaterial] Parent directory "
196 "'%s' doesn't exist!",
203 "[TextureLoader::LoadFromCCMaterial] Parent '%s' is "
210 std::vector<std::string> paths_vector;
212 parent_dir, paths_vector);
214 for (
const auto&
path : paths_vector) {
223 if (real_name.empty()) {
225 "[TextureLoader::LoadFromCCMaterial] Can not find "
230 }
catch (
const std::exception& ex) {
232 "[TextureLoader::LoadFromCCMaterial] Error %s when "
233 "looking for file %s!",
234 ex.what(), full_path.c_str());
238 full_path = real_name;
241 std::string extension =
245 if ((extension ==
"jpg") || (extension ==
"jpeg")) {
248 jpeg_reader->SetFileName(full_path.c_str());
249 jpeg_reader->Update();
250 vtk_tex->SetInputConnection(jpeg_reader->GetOutputPort());
251 }
else if (extension ==
"bmp") {
254 bmp_reader->SetFileName(full_path.c_str());
255 bmp_reader->Update();
256 vtk_tex->SetInputConnection(bmp_reader->GetOutputPort());
257 }
else if (extension ==
"pnm") {
260 pnm_reader->SetFileName(full_path.c_str());
261 pnm_reader->Update();
262 vtk_tex->SetInputConnection(pnm_reader->GetOutputPort());
263 }
else if (extension ==
"png") {
266 png_reader->SetFileName(full_path.c_str());
267 png_reader->Update();
268 vtk_tex->SetInputConnection(png_reader->GetOutputPort());
269 }
else if ((extension ==
"tiff") || (extension ==
"tif")) {
272 tiff_reader->SetFileName(full_path.c_str());
273 tiff_reader->Update();
274 vtk_tex->SetInputConnection(tiff_reader->GetOutputPort());
277 "[TextureLoader::LoadFromCCMaterial] Unhandled image %s "
278 "(extension: '%s') for material %s!",
279 full_path.c_str(), extension.c_str(),
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
static int LoadFromPCLMaterial(const pcl::TexMaterial &tex_mat, vtkTexture *vtk_tex)
Load texture from pcl::TexMaterial.
static int LoadFromCCMaterial(ccMaterial::CShared material, vtkTexture *vtk_tex)
Load texture from ccMaterial.
TextureMapType
Texture map types for PBR materials.
QSharedPointer< const ccMaterial > CShared
Const + Shared type.
static QImage GetTexture(const QString &absoluteFilename)
Returns the texture image associated to a given name.
static const std::string path
bool ListFilesInDirectory(const std::string &directory, std::vector< std::string > &filenames)
bool IsDirectory(const std::string &directory)
std::string GetFileParentDirectory(const std::string &filename)
bool DirectoryExists(const std::string &directory)
std::string GetFileExtensionInLowerCase(const std::string &filename)
bool FileExists(const std::string &filename)
bool IsFile(const std::string &filename)
std::string ToUpper(const std::string &s)
Convert string to the upper case.