Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
Vector2Color.h
Go to the documentation of this file.
1/* This file is part of MODEL, the Mechanics Of Defect Evolution Library.
2 *
3 * Copyright (C) 2011 by Giacomo Po <gpo@ucla.edu>.
4 *
5 * model is distributed without any warranty under the
6 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
7 */
8
9#ifndef model_Vector2Color_H_
10#define model_Vector2Color_H_
11
12
13#include <cfloat>
14#include <Eigen/Dense>
15
16namespace model
17{
19 {
20
21 static Eigen::Matrix<int,3,1> v2c(Eigen::Matrix<double,3,1> clrVector)
22 {
23 float clrTol=100.0*FLT_EPSILON;
24 if(clrVector(0)<-clrTol)
25 {// first component not zero but begative, flip color
26 clrVector*=-1.0;
27 }
28 else if(fabs(clrVector(0))<=clrTol)
29 {// first component is zero, use second component
30 if(clrVector(1)<-clrTol)
31 {// second component not zero but begative, flip color
32 clrVector*=-1.0;
33 }
34 else if(fabs(clrVector(1))<=clrTol)
35 {// second component is zero, use third component
36 if(clrVector(2)<-clrTol)
37 {
38 clrVector*=-1.0;
39 }
40 }
41 }
42
43 clrVector = (clrVector + Eigen::Matrix<double,3,1>::Ones(3) * clrVector.norm()).eval();
44 clrVector.normalize();
45 return (clrVector*255).cast<int>();
46 }
47
48 };
49}
50#endif
51
52
53
54
55
56
57
auto eval(const std::shared_ptr< T > &t)
static Eigen::Matrix< int, 3, 1 > v2c(Eigen::Matrix< double, 3, 1 > clrVector)