Esempio n. 1
0
Color colorFromString(string s)
{
	static Color s_cLastCol;
	Color c;
	
	if(s == "random_pastel")	//Some random pastel color (good for parasprites)
	{
		float h, s, v;
		h = randFloat(0.0, 360.0);
		s = randFloat(40.0, 100.0);
		v = 100.0;
		c = HsvToRgb(h,s,v);
		c.r /= 100;
		c.g /= 100;
		c.b /= 100;
		s_cLastCol = c;
		return c;
	}
	else if(s == "last")	//Last color we got from this function
		return s_cLastCol;
	
	s = stripCommas(s);

	//Now, parse
	istringstream iss(s);
	int r, g, b, a;
	if(iss >> r >> g >> b)
	{
		if(!(iss >> a))
			c.from256(r,g,b);
		else
			c.from256(r,g,b,a);
	}
Esempio n. 2
0
void Color::fromHSV(float h, float s, float v, float fa)
{
	a = fa;
	Color c = HsvToRgb(h, s, v);
	r = c.r/100.0;
	g = c.g/100.0;
	b = c.b/100.0;
}
Esempio n. 3
0
void vtkLookupTable2D::HsvToRgb(double h, double s, double v, unsigned char *r, unsigned char *g, unsigned char *b){
	double dr, dg, db;

	HsvToRgb(h, s, v, &dr, &dg, &db);

	*r = (unsigned char)((int)(dr * 255.0));
	*g = (unsigned char)((int)(dg * 255.0));
	*b = (unsigned char)((int)(db * 255.0));
}
Esempio n. 4
0
void vtkLookupTable2D::HsvToRgb(unsigned char h, unsigned char s, unsigned char v, unsigned char *r, unsigned char *g, unsigned char *b){
	double dh, ds, dv, dr, dg, db;
	int ih, is, iv, ir, ig, ib;

	dh = ((double) ((int) h)) / 255.0;
	ds = ((double) ((int) s)) / 255.0;
	dv = ((double) ((int) v)) / 255.0;

	HsvToRgb(dh, ds, dv, &dr, &dg, &db);

	*r = (unsigned char)((int)(dr * 255.0));
	*g = (unsigned char)((int)(dg * 255.0));
	*b = (unsigned char)((int)(db * 255.0));
}
Esempio n. 5
0
void change_value(float val) {

	float tmp = hsv_color.v + val;

	if (tmp > 1.0)
		tmp = 1.;
	if (tmp < 0.)
		tmp = 0.;

	hsv_color.v = tmp;
	rgb_color = HsvToRgb(&hsv_color);

	update_color();
}
Esempio n. 6
0
void change_saturation(float val) {

	float tmp = hsv_color.s + val;

	if (tmp > 1.0)
		tmp = 1.;
	if (tmp < 0.)
		tmp = 0.001;

	hsv_color.s = tmp;
	rgb_color = HsvToRgb(&hsv_color);

	update_color();
}
Esempio n. 7
0
void change_hue(float val) {

	float tmp = hsv_color.h + val;

	if (tmp > 360) {
		tmp -= 360.;
	} else if (tmp < 0) {
		tmp = 360. - fabs(tmp);
	}

	hsv_color.h = tmp;
	rgb_color = HsvToRgb(&hsv_color);
	update_color();
}
Esempio n. 8
0
COLORREF ChangeColorBrightness(COLORREF color, float modifier) {
  float r = static_cast<float>(GetRValue(color)) / 255.0f;
  float g = static_cast<float>(GetGValue(color)) / 255.0f;
  float b = static_cast<float>(GetBValue(color)) / 255.0f;

  float h, s, v;

  RgbToHsv(r, g, b, h, s, v);

  v += modifier;
  if (v < 0.0f) v = 0.0f;
  if (v > 1.0f) v = 1.0f;

  HsvToRgb(r, g, b, h, s, v);

  return RGB(static_cast<BYTE>(r * 255),
             static_cast<BYTE>(g * 255),
             static_cast<BYTE>(b * 255));
}
Esempio n. 9
0
void vtkLookupTable2D::MapScalarsThroughTable2(void *input, unsigned char *output, 
			int inputDataType, int numberOfValues,
			int inputIncrement, int outputIncrement)
{
	vtkDataArray	*secondaryDataArray = NULL;
	bool			bIfUseSecondaryData = false;

	if (m_pvtkPolyDataMapper != NULL){
		std::cout << "vtkLookupTable2D::MapScalarsThroughTable2() called:" << std::endl;
		std::cout << "number of values: " << numberOfValues << std::endl;
		std::cout << "input increment: " << inputIncrement << std::endl;
		std::cout << "outputIncrement: " << outputIncrement << std::endl;

		vtkPolyData *polys = m_pvtkPolyDataMapper->GetInput();
		if (polys != NULL){
			vtkPointData *pdata = polys->GetPointData();
			if (pdata != NULL){
				secondaryDataArray = pdata->GetArray(m_stdstrSecondaryDataName.c_str());
				if ((secondaryDataArray != NULL) && (m_bUseSecondaryDataArray)){
					bIfUseSecondaryData = true;

					if (numberOfValues != secondaryDataArray->GetNumberOfTuples()){
						std::cout << "MapScalarsThroughTable2() secondary data array has the wrong number of tuples" << std::endl;
						bIfUseSecondaryData = false;
					}

					std::cout << "Using secondary data for color saturation" << std::endl;
					std::cout << "Secondary data range: " << m_dSecondaryMin << "  " << m_dSecondaryMax << std::endl;
				}
			}
		}else{
			std::cout << "Polys where NULL" << std::endl;
		}
	} else {
		std::cout << "No color mapping possible, polydata mapper is NULL" << std::endl;
	}

	vtkLookupTable::MapScalarsThroughTable2(input, output, inputDataType, numberOfValues, inputIncrement, outputIncrement);

	int numNaNs = 0;

	double dSecondaryRange = m_dSecondaryMax - m_dSecondaryMin;

	if ((outputIncrement == 4) && m_bUseSecondaryDataArray && bIfUseSecondaryData){
		for (int i=0; i<numberOfValues; i++){
			unsigned char r, g, b, a;
			unsigned char rNew, gNew, bNew, aNew;
			double h, s, v;

			r = output[i * 4 + 0];
			g = output[i * 4 + 1];
			b = output[i * 4 + 2];
			a = output[i * 4 + 3];

			this->RgbToHsv(r, g, b, &h, &s, &v);

			double dataval = secondaryDataArray->GetTuple1(i);
			double fraction = (dataval - m_dSecondaryMin) / dSecondaryRange;

			char dataValAsChar[20];
			sprintf(dataValAsChar, "%lf", fraction);
			if (std::string(dataValAsChar).find("-1.#IND") != std::string::npos){
				fraction = -1.0;
				numNaNs++;
			}

			if (fraction >= 0.0){
				s *= (1.0 - fraction);
				v = 1.0 - fraction;
			} else {
				v = 0.0;
			}

			HsvToRgb(h, s, v, &rNew, &gNew, &bNew);
			aNew = a;

			if (! (i % 100)){
				std::cout << i << "    rgbaold: " << (int) r << " " << (int) g << " " << (int) b << " " << (int) a;
				std::cout << "     rgbanew: " << (int) rNew << " " << (int) gNew << " " << (int) bNew << "    fraction: "  << fraction << std::endl;
			}

			output[i * 4 + 0] = rNew;
			output[i * 4 + 1] = gNew;
			output[i * 4 + 2] = bNew;
			output[i * 4 + 3] = aNew;
		}
	} else {
		std::cout << "output data are not of rgba type" << std::endl;
	}

	std::cout << "Number of NaNs: " << numNaNs << std::endl;
	std::cout << "Number of values: " << numberOfValues << std::endl;
}