23#ifndef VCL_ALGORITHMS_MESH_UPDATE_COLOR_H
24#define VCL_ALGORITHMS_MESH_UPDATE_COLOR_H
26#include <vclib/algorithms/mesh/stat.h>
27#include <vclib/math/perlin_noise.h>
28#include <vclib/mesh/requirements.h>
29#include <vclib/space/core/color.h>
30#include <vclib/views/mesh.h>
44template<u
int ELEM_ID, FaceMeshConcept MeshType>
45void setPerElemColorFromVertexColor(MeshType& m)
47 requirePerVertexColor(m);
48 requirePerElementComponent<ELEM_ID, CompId::COLOR>(m);
50 using VertexType = MeshType::VertexType;
52 for (
auto& f : m.template elements<ELEM_ID>()) {
53 Point4<uint> avg(0, 0, 0, 0);
54 for (
const VertexType* v : f.
vertices()) {
55 avg += v->color().template cast<uint>();
57 avg /= f.vertexNumber();
58 f.color() = avg.cast<uint8_t>();
81template<MeshConcept MeshType>
84 Color c = Color::White,
87 requirePerVertexColor(
m);
90 std::ranges::fill(
m.vertices() | views::selected | views::colors, c);
93 std::ranges::fill(
m.vertices() | views::colors, c);
115template<FaceMeshConcept MeshType>
118 Color c = Color::White,
124 std::ranges::fill(
m.faces() | views::selected | views::colors, c);
127 std::ranges::fill(
m.faces() | views::colors, c);
149template<EdgeMeshConcept MeshType>
152 Color c = Color::White,
158 std::ranges::fill(
m.edges() | views::selected | views::colors, c);
161 std::ranges::fill(
m.edges() | views::colors, c);
176template<HasColor MeshType>
198template<FaceMeshConcept MeshType>
201 requirePerVertexColor(
m);
204 using VertexType = MeshType::VertexType;
205 using FaceType = MeshType::FaceType;
207 std::vector<detail::ColorAvgInfo>
csi(
m.vertexContainerSize());
209 for (
const FaceType& f :
m.faces()) {
210 for (
const VertexType* v : f.vertices()) {
211 csi[
m.index(v)].c += v->color();
212 csi[
m.index(v)].cnt++;
216 for (VertexType& v :
m.vertices()) {
217 v.color() =
csi[
m.index(v)].c /
csi[
m.index(v)].cnt;
237template<FaceMeshConcept MeshType>
240 detail::setPerElemColorFromVertexColor<ElemId::FACE>(
m);
259template<EdgeMeshConcept MeshType>
262 detail::setPerElemColorFromVertexColor<ElemId::EDGE>(
m);
289template<MeshConcept MeshType>
293 typename MeshType::VertexType::QualityType
minQuality = 0,
294 typename MeshType::VertexType::QualityType
maxQuality = 0)
296 requirePerVertexColor(
m);
297 requirePerVertexQuality(
m);
299 using VertexType = MeshType::VertexType;
300 using QualityType = VertexType::QualityType;
303 std::pair<QualityType, QualityType>
pair = vertexQualityMinMax(
m);
307 for (VertexType& v :
m.vertices()) {
337template<FaceMeshConcept MeshType>
341 typename MeshType::FaceType::QualityType
minQuality = 0,
342 typename MeshType::FaceType::QualityType
maxQuality = 0)
347 using FaceType = MeshType::FaceType;
348 using QualityType = FaceType::QualityType;
351 std::pair<QualityType, QualityType>
pair = faceQualityMinMax(
m);
356 for (FaceType& f :
m.faces()) {
387template<FaceMeshConcept MeshType>
394 requirePerVertexColor(
m);
396 using FaceType = MeshType::FaceType;
402 for (FaceType& f :
m.faces()) {
403 for (uint
i = 0;
i < f.vertexNumber(); ++
i) {
404 if (f.edgeOnBorder(
i)) {
446template<FaceMeshConcept MeshType>
479template<FaceMeshConcept MeshType>
513template<FaceMeshConcept MeshType>
521 using FaceType = MeshType::FaceType;
526 std::vector<Color>
vc = colorScattering(
nColors);
528 for (FaceType& f :
m.faces()) {
534 for (uint
i = 0;
i < f.vertexNumber(); ++
i) {
536 assert(f.adjFace(
i) !=
nullptr);
537 f.adjFace(
i)->color = f.color();
566template<MeshConcept MeshType, Po
intConcept Po
intType>
570 PointType offset = PointType(0, 0, 0),
573 requirePerVertexColor(
m);
575 using VertexType = MeshType::VertexType;
579 for (VertexType& v :
m.vertices()) {
581 p[0] = (v.coord() /
period[0]) + offset;
582 p[1] = (v.coord() /
period[1]) + offset;
583 p[2] = (v.coord() /
period[2]) + offset;
585 127 + 128.0 * perlinNoise(
p[0][0],
p[0][1],
p[0][2]),
586 127 + 128.0 * perlinNoise(
p[1][0],
p[1][1],
p[1][2]),
587 127 + 128.0 * perlinNoise(
p[2][0],
p[2][1],
p[2][2]),
611template<MeshConcept MeshType, Po
intConcept Po
intType>
615 PointType offset = PointType(0, 0, 0),
620 requirePerVertexColor(
m);
622 using VertexType = MeshType::VertexType;
624 for (VertexType& v :
m.vertices()) {
626 PointType
p = v.coord() /
period + offset;
628 double factor = (perlinNoise(
p[0],
p[1],
p[2]) + 1.0) / 2.0;
The Color class represents a 32 bit color.
Definition color.h:48
ColorMap
List of Color Maps supported by the vcl::Color.
Definition color.h:123
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
Concept that checks if a Mesh has the per Face AdjacentFaces component.
Definition per_face.h:79
std::vector< std::set< uint > > connectedComponents(const MeshType &m)
Computes the connected components of the input mesh based on its topology.
Definition clean.h:650
void requirePerEdgeColor(const MeshType &m)
This function asserts that a Mesh has a EdgeContainer, the Edge has a Color Component,...
Definition edge_requirements.h:548
bool isPerFaceAdjacentFacesAvailable(const MeshType &m)
Returns true if the AdjacentFaces component is available (enabled) in the Face element of the input m...
Definition face_requirements.h:153
void requirePerFaceQuality(const MeshType &m)
This function asserts that a Mesh has a FaceContainer, the Face has a Quality Component,...
Definition face_requirements.h:875
void requirePerFaceColor(const MeshType &m)
This function asserts that a Mesh has a FaceContainer, the Face has a Color Component,...
Definition face_requirements.h:734
void setPerVertexColorFromFaceColor(MeshType &m)
Sets the vertex colors from its incident face colors, computing a plain average of the face colors.
Definition color.h:199
void setPerFaceColorScattering(MeshType &m, uint nColors=50, bool checkFauxEdges=true)
This function colors each face of the mesh using a given number of scattering colors (default number ...
Definition color.h:514
void setPerVertexColorPerlinNoise(MeshType &m, PointType period, PointType offset=PointType(0, 0, 0), bool onSelected=false)
Set the vertex color according to a perlin noise computed on the vertex coordinates.
Definition color.h:567
void setPerVertexPerlinColor(MeshType &m, double period, PointType offset=PointType(0, 0, 0), Color color1=Color::Black, Color color2=Color::White, bool onSelected=false)
Simple Perlin color mixing. color1 and color2 are mixed according the perlin noise function,...
Definition color.h:612
void setPerFaceColor(MeshType &m, Color c=Color::White, bool onlySelected=false)
Sets the color of the faces. If the onlySelected flag is set to true, only the color of the selected ...
Definition color.h:116
void setPerVertexColorFromQuality(MeshType &m, Color::ColorMap colorMap=Color::ColorMap::RedBlue, typename MeshType::VertexType::QualityType minQuality=0, typename MeshType::VertexType::QualityType maxQuality=0)
Sets the vertex colors from the quality values by computing a shading in the given color map (default...
Definition color.h:290
void setPerFaceColorFromQuality(MeshType &m, Color::ColorMap colorMap=Color::ColorMap::RedBlue, typename MeshType::FaceType::QualityType minQuality=0, typename MeshType::FaceType::QualityType maxQuality=0)
Sets the face colors from the quality values by computing a shading in the given color map (default i...
Definition color.h:338
void setPerFaceColorFromVertexColor(MeshType &m)
Sets the face colors from its incident vertex colors, computing a plain average of the vertex colors.
Definition color.h:238
void setPerEdgeColorFromVertexColor(MeshType &m)
Sets the edge colors from its incident vertex colors, computing a plain average of the vertex colors.
Definition color.h:260
void setPerVertexColor(MeshType &m, Color c=Color::White, bool onlySelected=false)
Sets the color of the vertices. If the onlySelected flag is set to true, only the color of the select...
Definition color.h:82
void setMeshColor(MeshType &m, Color c=Color::White)
Sets the color component of a mesh.
Definition color.h:177
void setPerVertexColorFromFaceBorderFlag(MeshType &m, Color borderColor=Color::Blue, Color internalColor=Color::White, Color mixColor=Color::Cyan)
Color the vertices of the mesh that are on border, using the border flags of the faces.
Definition color.h:388
void setPerFaceColorFromConnectedComponents(MeshType &m, const std::vector< std::set< uint > > &connectedComponents)
Given an already computed vector of sets of connected components (see vcl::connectedComponents(m) in ...
Definition color.h:447
void setPerEdgeColor(MeshType &m, Color c=Color::White, bool onlySelected=false)
Sets the color of the edges. If the onlySelected flag is set to true, only the color of the selected ...
Definition color.h:150
constexpr detail::VerticesView vertices
A view that allows to iterate over the Vertex elements of an object.
Definition vertex.h:60