Added all the missing component exceptions for colors

This commit is contained in:
Paolo Cignoni 2012-11-09 10:52:35 +00:00
parent 63faedbb88
commit 6b48acfa9f
1 changed files with 30 additions and 1 deletions

View File

@ -75,6 +75,8 @@ public:
*/ */
static int PerVertexConstant(MeshType &m, Color4b vs=Color4b::White,bool selected=false) static int PerVertexConstant(MeshType &m, Color4b vs=Color4b::White,bool selected=false)
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
int cnt=0; int cnt=0;
for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
if(!(*vi).IsD()){ if(!(*vi).IsD()){
@ -91,6 +93,7 @@ public:
*/ */
static int PerFaceConstant(MeshType &m, Color4b vs=Color4b::White,bool selected=false) static int PerFaceConstant(MeshType &m, Color4b vs=Color4b::White,bool selected=false)
{ {
if(!HasPerFaceColor(m)) throw MissingComponentException("PerFaceColor");
int cnt=0; int cnt=0;
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD()){ if(!(*fi).IsD()){
@ -110,6 +113,9 @@ public:
*/ */
static void PerVertexFromFace( MeshType &m) static void PerVertexFromFace( MeshType &m)
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
if(!HasPerFaceColor(m)) throw MissingComponentException("PerFaceColor");
ColorAvgInfo csi; ColorAvgInfo csi;
csi.r=0; csi.g=0; csi.b=0; csi.cnt=0; csi.r=0; csi.g=0; csi.b=0; csi.cnt=0;
SimpleTempData<typename MeshType::VertContainer, ColorAvgInfo> TD(m.vert,csi); SimpleTempData<typename MeshType::VertContainer, ColorAvgInfo> TD(m.vert,csi);
@ -142,6 +148,9 @@ public:
*/ */
static void PerFaceFromVertex( MeshType &m) static void PerFaceFromVertex( MeshType &m)
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
if(!HasPerFaceColor(m)) throw MissingComponentException("PerFaceColor");
FaceIterator fi; FaceIterator fi;
for(fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD()) for(fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD())
{ {
@ -159,6 +168,7 @@ public:
static void PerVertexQualityRamp(MeshType &m, float minq=0, float maxq=0) static void PerVertexQualityRamp(MeshType &m, float minq=0, float maxq=0)
{ {
if(!HasPerVertexQuality(m)) throw MissingComponentException("PerVertexQuality"); if(!HasPerVertexQuality(m)) throw MissingComponentException("PerVertexQuality");
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
if(minq==maxq) if(minq==maxq)
{ {
@ -177,6 +187,7 @@ public:
*/ */
static void PerFaceQualityRamp(MeshType &m, float minq=0, float maxq=0, bool selected=false) static void PerFaceQualityRamp(MeshType &m, float minq=0, float maxq=0, bool selected=false)
{ {
if(!HasPerFaceColor(m)) throw MissingComponentException("PerFaceColor");
if(!HasPerFaceQuality(m)) throw MissingComponentException("PerFaceQuality"); if(!HasPerFaceQuality(m)) throw MissingComponentException("PerFaceQuality");
if(minq==maxq) if(minq==maxq)
@ -196,6 +207,7 @@ public:
*/ */
static void PerVertexQualityGray(MeshType &m, float minq, float maxq) static void PerVertexQualityGray(MeshType &m, float minq, float maxq)
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
if(!HasPerVertexQuality(m)) throw MissingComponentException("PerVertexQuality"); if(!HasPerVertexQuality(m)) throw MissingComponentException("PerVertexQuality");
if(minq==maxq) if(minq==maxq)
{ {
@ -214,6 +226,7 @@ public:
*/ */
static void PerFaceQualityGray(MeshType &m, float minq=0, float maxq=0) static void PerFaceQualityGray(MeshType &m, float minq=0, float maxq=0)
{ {
if(!HasPerFaceColor(m)) throw MissingComponentException("PerFaceColor");
if(!HasPerFaceQuality(m)) throw MissingComponentException("PerFaceQuality"); if(!HasPerFaceQuality(m)) throw MissingComponentException("PerFaceQuality");
if(minq==maxq) if(minq==maxq)
@ -239,6 +252,7 @@ vcg::tri::UpdateColor<Mesh>::PerVertexBorderFlag(m.cm);
*/ */
static void PerVertexBorderFlag( MeshType &m, Color4b BorderColor=Color4b::Blue, Color4b InternalColor=Color4b::White, Color4b MixColor=Color4b::Cyan) static void PerVertexBorderFlag( MeshType &m, Color4b BorderColor=Color4b::Blue, Color4b InternalColor=Color4b::White, Color4b MixColor=Color4b::Cyan)
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
Color4b BaseColor = Color4b::Green; Color4b BaseColor = Color4b::Green;
VertexConstant(m,BaseColor); VertexConstant(m,BaseColor);
@ -267,6 +281,7 @@ It require FaceFace Adjacency becouse it relies on the output of the ConnecteCom
*/ */
static void PerFaceRandomConnectedComponent( MeshType &m) static void PerFaceRandomConnectedComponent( MeshType &m)
{ {
if(!HasPerFaceColor(m)) throw MissingComponentException("PerFaceColor");
if(!HasFFAdjacency(m)) throw MissingComponentException("FFAdjacency"); if(!HasFFAdjacency(m)) throw MissingComponentException("FFAdjacency");
std::vector< std::pair<int, typename MeshType::FacePointer> > CCV; std::vector< std::pair<int, typename MeshType::FacePointer> > CCV;
@ -288,6 +303,7 @@ Note: The faux bit is used to color polygonal faces uniformly
*/ */
static void PerFaceRandom(MeshType &m) static void PerFaceRandom(MeshType &m)
{ {
if(!HasPerFaceColor(m)) throw MissingComponentException("PerFaceColor");
FaceIterator fi; FaceIterator fi;
Color4b BaseColor = Color4b::Black; Color4b BaseColor = Color4b::Black;
PerFaceConstant(m,BaseColor); PerFaceConstant(m,BaseColor);
@ -315,6 +331,7 @@ Note: The faux bit is used to color polygonal faces uniformly
*/ */
static void PerVertexPerlinNoise(MeshType& m, Point3f period, Point3f offset=Point3f(0,0,0)) static void PerVertexPerlinNoise(MeshType& m, Point3f period, Point3f offset=Point3f(0,0,0))
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
Point3<ScalarType> p[3]; Point3<ScalarType> p[3];
for(VertexIterator vi = m.vert.begin(); vi!=m.vert.end(); ++vi) for(VertexIterator vi = m.vert.begin(); vi!=m.vert.end(); ++vi)
{ {
@ -336,6 +353,7 @@ Note: The faux bit is used to color polygonal faces uniformly
*/ */
static void PerVertexAddNoise(MeshType& m, int noiseBits) static void PerVertexAddNoise(MeshType& m, int noiseBits)
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
if(noiseBits>8) noiseBits = 8; if(noiseBits>8) noiseBits = 8;
if(noiseBits<1) return; if(noiseBits<1) return;
@ -355,6 +373,7 @@ Note: The faux bit is used to color polygonal faces uniformly
*/ */
static int PerVertexThresholding(MeshType &m, float threshold, Color4b c1 = Color4<unsigned char>::Black, Color4b c2 = Color4<unsigned char>::White, const bool ProcessSelected=false) static int PerVertexThresholding(MeshType &m, float threshold, Color4b c1 = Color4<unsigned char>::Black, Color4b c2 = Color4<unsigned char>::White, const bool ProcessSelected=false)
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
int counter=0; int counter=0;
VertexIterator vi; VertexIterator vi;
for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex...
@ -386,6 +405,7 @@ static float ComputeLightness(Color4b c)
*/ */
static int PerVertexBrightness(MeshType &m, float amount, const bool ProcessSelected=false) static int PerVertexBrightness(MeshType &m, float amount, const bool ProcessSelected=false)
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
int counter=0; int counter=0;
VertexIterator vi; VertexIterator vi;
for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex...
@ -410,6 +430,7 @@ static int PerVertexBrightness(MeshType &m, float amount, const bool ProcessSele
*/ */
static int PerVertexContrast(MeshType &m, float factor, const bool ProcessSelected=false) static int PerVertexContrast(MeshType &m, float factor, const bool ProcessSelected=false)
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
int counter=0; int counter=0;
VertexIterator vi; VertexIterator vi;
for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex...
@ -448,6 +469,7 @@ The formula used here is the one of GIMP.
*/ */
static int PerVertexBrightnessContrast(MeshType &m, float brightness, float contrast, const bool ProcessSelected=false) static int PerVertexBrightnessContrast(MeshType &m, float brightness, float contrast, const bool ProcessSelected=false)
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
int counter=0; int counter=0;
VertexIterator vi; VertexIterator vi;
for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex...
@ -486,6 +508,7 @@ static int ValueBrightnessContrast(unsigned char ivalue, float brightness, float
*/ */
static int PerVertexInvert(MeshType &m, const bool ProcessSelected=false) static int PerVertexInvert(MeshType &m, const bool ProcessSelected=false)
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
int counter=0; int counter=0;
for(VertexIterator vi=m.vert.begin(); vi!=m.vert.end(); ++vi) //scan all the vertex... for(VertexIterator vi=m.vert.begin(); vi!=m.vert.end(); ++vi) //scan all the vertex...
{ {
@ -507,6 +530,7 @@ static int PerVertexInvert(MeshType &m, const bool ProcessSelected=false)
*/ */
static int PerVertexGamma(MeshType &m, float gamma, const bool ProcessSelected=false) static int PerVertexGamma(MeshType &m, float gamma, const bool ProcessSelected=false)
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
int counter=0; int counter=0;
VertexIterator vi; VertexIterator vi;
@ -552,6 +576,7 @@ out_min and out_max are the output level for black and white respectively.
*/ */
static int PerVertexLevels(MeshType &m, float gamma, float in_min, float in_max, float out_min, float out_max, unsigned char rgbMask, const bool ProcessSelected=false) static int PerVertexLevels(MeshType &m, float gamma, float in_min, float in_max, float out_min, float out_max, unsigned char rgbMask, const bool ProcessSelected=false)
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
int counter=0; int counter=0;
VertexIterator vi; VertexIterator vi;
for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex...
@ -599,6 +624,7 @@ Colors the mesh. Color is blended to the mesh with the given intensity (0..1 ran
*/ */
static int PerVertexColourisation(MeshType &m, Color4b c, float intensity, const bool ProcessSelected=false) static int PerVertexColourisation(MeshType &m, Color4b c, float intensity, const bool ProcessSelected=false)
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
int counter=0; int counter=0;
VertexIterator vi; VertexIterator vi;
for(vi=m.vert.begin();vi!=m.vert.end();++vi) for(vi=m.vert.begin();vi!=m.vert.end();++vi)
@ -644,6 +670,7 @@ There are three possibilities
*/ */
static int PerVertexDesaturation(MeshType &m, int method, const bool ProcessSelected=false) static int PerVertexDesaturation(MeshType &m, int method, const bool ProcessSelected=false)
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
int counter=0; int counter=0;
VertexIterator vi; VertexIterator vi;
for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex...
@ -699,6 +726,7 @@ Equalize the histogram of colors. It can equalize any combination of rgb channel
*/ */
static int PerVertexEqualize(MeshType &m, unsigned int rgbMask, const bool ProcessSelected=false) static int PerVertexEqualize(MeshType &m, unsigned int rgbMask, const bool ProcessSelected=false)
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
//declares , resets and set up 4 histograms, for Red, Green, Blue and Lightness //declares , resets and set up 4 histograms, for Red, Green, Blue and Lightness
Histogramf Hl, Hr, Hg, Hb; Histogramf Hl, Hr, Hg, Hb;
Hl.Clear(); Hr.Clear(); Hg.Clear(); Hb.Clear(); Hl.Clear(); Hr.Clear(); Hg.Clear(); Hb.Clear();
@ -773,6 +801,7 @@ static int ValueEqualize(int cdfValue, int cdfMin, int cdfMax)
*/ */
static int PerVertexWhiteBalance(MeshType &m, Color4b userColor, const bool ProcessSelected=false) static int PerVertexWhiteBalance(MeshType &m, Color4b userColor, const bool ProcessSelected=false)
{ {
if(!HasPerVertexColor(m)) throw MissingComponentException("PerVertexColor");
Color4b unbalancedWhite= userColor; Color4b unbalancedWhite= userColor;
int counter=0; int counter=0;
VertexIterator vi; VertexIterator vi;