MEPP2 Project
texture_image_demo_filter.hpp
Go to the documentation of this file.
1 // Copyright (c) 2012-2022 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 #pragma once
12 
15 #include "FEVV/Types/Material.h"
16 
20 template< typename HalfedgeGraph,
21  typename MaterialMap,
22  typename GeometryTraits = FEVV::Geometry_traits< HalfedgeGraph > >
23 void
24 texture_image_demo_filter(const HalfedgeGraph &/*g*/,
25  MaterialMap &mtl_pm,
26  const GeometryTraits &/*gt*/)
27 {
28  // loop over materials
29  auto it = mtl_pm.storage_begin();
30  auto it_end = mtl_pm.storage_end();
31  for(; it != it_end; ++it)
32  {
33  auto material = *it;
34  std::cout << "processing material '" << material.name << "'" << std::endl;
35 
36  // loop over texture images
37  for(const auto &texture_filename : { material.ambient_texture_filename,
38  material.diffuse_texture_filename,
39  material.specular_texture_filename,
40  material.emissive_texture_filename,
41  material.transparency_texture_filename,
42  material.normal_map_filename,
43  material.metallic_map_filename,
44  material.roughness_map_filename })
45  {
46  if(texture_filename.empty())
47  continue;
48 
49  // retrieve texture image
50 
51  auto &cimg = *(material.images.at(texture_filename));
52 
53  // texture image must have at least 3 channels
54 
55  if(cimg.spectrum() < 3)
56  {
57  std::cout << " skipping non RGB texture '" << texture_filename << "'"
58  << std::endl;
59  continue;
60  }
61 
62  // cycle channels (R->G, G->B, B->R)
63 
64  std::cout << " processing texture '" << texture_filename << "'"
65  << std::endl;
66 
67  // loop over pixels
68  // inefficient but instructive implementation
69  for(int row = 0; row < cimg.height(); row++)
70  {
71  for(int col = 0; col < cimg.width(); col++)
72  {
73  auto R = cimg(col, row, 0, 0); // cimg(x, y, z, channel)
74  auto G = cimg(col, row, 0, 1);
75  auto B = cimg(col, row, 0, 2);
76 
77  cimg(col, row, 0, 0) = B;
78  cimg(col, row, 0, 1) = R;
79  cimg(col, row, 0, 2) = G;
80  }
81  }
82  }
83  }
84 }
85 
86 
87 // Helper function to simplify (syntactic sugar) the call to the filter
88 template< typename HalfedgeGraph,
89  typename MaterialMap,
90  typename GeometryTraits = FEVV::Geometry_traits< HalfedgeGraph > >
91 void
92 texture_image_demo_filter(const HalfedgeGraph &g,
93  MaterialMap &mtl_pm)
94 {
95  GeometryTraits gt(g);
96  texture_image_demo_filter(g, mtl_pm, gt);
97 }
98 
G
Mesh G
Definition: test_complying_concepts_aif.cpp:22
FEVV::Geometry_traits< HalfedgeGraph >
Material.h
Geometry_traits.h
FEVV::DataStructures::AIF::AIFMesh
This class represents an AIF structure. AIF structure can deal with both manifold and non-manifold su...
Definition: AIFMesh.hpp:47
texture_image_demo_filter
void texture_image_demo_filter(const HalfedgeGraph &, MaterialMap &mtl_pm, const GeometryTraits &)
Definition: texture_image_demo_filter.hpp:24
properties.h