Currender: A CPU renderer for computer vision
Currender is a CPU raytracing/rasterization based rendering library written in C++. With 3D triangular mesh and camera parameters, you can easily render color, depth, normal, mask and face id images.
color | depth |
---|---|
normal | mask | face id |
---|---|---|
Currender is primarily designed for people who are involved in computer vision. Pros and cons against popular OpenGL based rendering are listed below.
You can choose Raytracer or Rasterizer as rendering algorithm.
Raytracer
Rasterizer
This is the main function of minimum_example.cc
to show simple usage of API.
int main() {
// make an inclined cube mesh with vertex color
auto mesh = MakeExampleCube();
// initialize renderer enabling vertex color rendering and lambertian shading
currender::RendererOption option;
option.diffuse_color = currender::DiffuseColor::kVertex;
option.diffuse_shading = currender::DiffuseShading::kLambertian;
// select Rasterizer or Raytracer
#ifdef USE_RASTERIZER
std::unique_ptr<currender::Renderer> renderer =
std::make_unique<currender::Rasterizer>(option);
#else
std::unique_ptr<currender::Renderer> renderer =
std::make_unique<currender::Raytracer>(option);
#endif
// set mesh
renderer->set_mesh(mesh);
// prepare mesh for rendering (e.g. make BVH)
renderer->PrepareMesh();
// make PinholeCamera (perspective camera) at origin.
// its image size is 160 * 120 and its y (vertical) FoV is 50 deg.
int width = 160;
int height = 120;
float fov_y_deg = 50.0f;
Eigen ::Vector2f principal_point, focal_length;
CalcIntrinsics(width, height, fov_y_deg, &principal_point, &focal_length);
auto camera = std::make_shared<currender::PinholeCamera>(
width, height, Eigen::Affine3d::Identity(), principal_point,
focal_length);
// set camera
renderer->set_camera(camera);
// render images
currender::Image3b color;
currender::Image1f depth;
currender::Image3f normal;
currender::Image1b mask;
currender::Image1i face_id;
renderer->Render(&color, &depth, &normal, &mask, &face_id);
// save images
SaveImages(color, depth, normal, mask, face_id);
return 0;
}
examples.cc
shows a varietiy of usage (Bunny image on the top of this document was rendered by examples.cc
).
Expected use cases are the following but not limited to
git submodule update --init --recursive
CMakeLists.txt
.
reconfigure.bat
and rebuild.bat
are command line CMake utilities for Windows 10 and Visual Studio 2017.Tested on
Porting to the other platforms (Android, Mac and iOS) is under planning. Minor modifitation of code and CMakeLists.txt would be required.
Borrowed .obj from Zhou, Kun, et al. "TextureMontage." ACM Transactions on Graphics (TOG) 24.3 (2005): 1148-1155. for testing purposes.