This example shows how to rendering a vector field defined on a surface mesh.
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26 
   27#include <easy3d/viewer/viewer.h>
   28#include <easy3d/core/surface_mesh.h>
   29#include <easy3d/renderer/drawable_lines.h>
   30#include <easy3d/renderer/renderer.h>
   31#include <easy3d/util/resource.h>
   32#include <easy3d/util/initializer.h>
   33
   38 
   40 
   41 
   42int main(int argc, char **argv) {
   43    
   45 
   46    
   47    
   48    Viewer viewer(EXAMPLE_TITLE);
 
   49 
   50    
   52    auto mesh = 
dynamic_cast<SurfaceMesh *
>(viewer.add_model(file_name, 
true));
 
   53    if (!mesh) {
   54        LOG(ERROR) << "failed to load model. Please make sure the file exists and format is correct.";
   55        return EXIT_FAILURE;
   56    }
   57 
   58    
   59    
   60    const Box3 &box = mesh->bounding_box();
 
   62 
   63    
   64    mesh->update_face_normals();
   65    auto normals = mesh->get_face_property<
vec3>(
"f:normal");
 
   66 
   67    
   68    std::vector<vec3> points;
   69    for (auto f : mesh->faces()) {
   71        int count = 0;
   72        for (auto v : mesh->vertices(f)) {
   73            center += mesh->position(v);
   74            ++count;
   75        }
   76 
   77        const vec3 s = center / count;
 
   79        points.push_back(s);
   80        points.push_back(t);
   81    }
   82 
   83    
   84    auto drawable = mesh->renderer()->add_lines_drawable("normals");
   85    
   86    drawable->update_vertex_buffer(points);
   87 
   88    
   89    drawable->set_uniform_coloring(
vec4(0.0f, 1.0f, 0.0f, 1.0f));
 
   90 
   91    
   92    drawable->set_line_width(3.0f);
   93 
   94    
   95    mesh->renderer()->get_lines_drawable("edges")->set_visible(true);
   96 
   97    
   98    return viewer.run();
   99}
  100 
const Point & min_point() const
Return the coordinates of the min corner (const version).
Definition box.h:106
const Point & max_point() const
Return the coordinates of the max corner (const version).
Definition box.h:117
A halfedge data structure for polygonal meshes of 2-manifold.
Definition surface_mesh.h:51
The built-in Easy3D viewer.
Definition viewer.h:63
std::string directory()
Returns the resource directory (containing color maps, shaders, textures, fonts, etc....
Definition collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
void initialize(bool info_to_stdout, bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition initializer.cpp:39
T length(const Vec< N, T > &v)
Computes the length/magnitude of a vector.
Definition vec.h:289
GenericBox< 3, float > Box3
A 3D axis-aligned bounding box of float type.
Definition types.h:108
Vec< 4, float > vec4
A 4D point/vector of float type.
Definition types.h:46
FT norm(const Matrix< FT > &)
utilities
Definition matrix.h:1455