Nirkin Face Swap  0.9.0
Face swap.
face_renderer.h
1 #ifndef FACE_SWAP_FACE_RENDERER_H
2 #define FACE_SWAP_FACE_RENDERER_H
3 
4 #include "face_swap/basel_3dmm.h"
5 #include <opencv2/core.hpp>
6 
7 namespace face_swap
8 {
12  {
13  public:
14 
17  FaceRenderer();
18 
21  ~FaceRenderer();
22 
28  void init(int width, int height, bool force = false);
29 
32  void clear();
33 
36  void clearFrameBuffer();
37 
40  void clearMesh();
41 
46  void setViewport(int width, int height);
47 
53  void setProjection(float f, float z_near = 10, float z_far= 10000);
54 
57  void setMesh(const Mesh& mesh);
58 
63  void render(const cv::Mat& vecR, const cv::Mat& vecT);
64 
67  void getFrameBuffer(cv::Mat& img);
68 
71  void getDepthBuffer(cv::Mat& depth);
72 
78  void setLight(const cv::Mat& pos_dir, const cv::Mat& ambient, const cv::Mat& diffuse);
79 
82  void clearLight();
83 
84  private:
85  void drawMesh();
86 
87  private:
88  int m_width = 0, m_height = 0;
89  int m_tex_width = 0, m_tex_height = 0;
90  unsigned int m_dynamic_tex_id = 0;
91  unsigned int m_fbo = 0;
92  unsigned int m_depth_rb = 0;
93 
94  // Mesh
95  unsigned int m_mesh_vert_id = 0;
96  unsigned int m_mesh_uv_id = 0;
97  unsigned int m_mesh_faces_id = 0;
98  unsigned int m_mesh_total_faces = 0;
99  unsigned int m_mesh_total_vertices = 0;
100  unsigned int m_mesh_tex_id = 0;
101  unsigned int m_mesh_tex_width = 0;
102  unsigned int m_mesh_tex_height = 0;
103  unsigned int m_mesh_normals_id = 0;
104  };
105 
106 } // namespace face_swap
107 
108 #endif //FACE_SWAP_FACE_RENDERER_H
109 
void setMesh(const Mesh &mesh)
Set mesh to render.
void setProjection(float f, float z_near=10, float z_far=10000)
Set projection.
void clearLight()
Clear previously set light.
void init(int width, int height, bool force=false)
Initialize buffers and viewport.
void getFrameBuffer(cv::Mat &img)
Get frame buffer (should be called after render).
void clearFrameBuffer()
Clear the frame buffer.
Simple renderer for rendering textured face meshes.
Definition: face_renderer.h:11
void setLight(const cv::Mat &pos_dir, const cv::Mat &ambient, const cv::Mat &diffuse)
Set light position and color.
Represents a 3D renderable shape.
Definition: basel_3dmm.h:13
Definition: basel_3dmm.h:9
void clear()
Clear all allocated data.
void clearMesh()
Clear the mesh.
void getDepthBuffer(cv::Mat &depth)
Get depth buffer (should be called after render).
~FaceRenderer()
Destrcutor.
void render(const cv::Mat &vecR, const cv::Mat &vecT)
Render with the specified pose.
FaceRenderer()
Create an instance of FaceRenderer.
void setViewport(int width, int height)
Set viewport resolution.