Click here to Skip to main content
15,893,487 members
Articles / Programming Languages / C#

Scalar Data Visualization: Part 3

Rate me:
Please Sign up or sign in to vote.
4.69/5 (18 votes)
5 Jan 2007BSD4 min read 46.8K   907   34  
This article will descirbe in more detail the flooded contouring section.
//-----------------------------------------------------------------------------
// File: ScoOteRColorPalet.cs
//
// DemolitiOn is My MissiOn
//
// Copyright (c) Ibrahim Hamed. All rights reserved.
//-----------------------------------------------------------------------------

using System;
using System.Drawing;
using System.Collections.Generic;
using System.Text;

namespace ScoOteRLoAdeR
{
	class ScoOteRColorPalet
	{
		private static Color[] palet;
		private static double Step;
		private static double Min;
		public static void SetPalet()
		{
			palet = new Color[120];
			//palet[0] = Color.DarkBlue;
			//palet[1] = Color.Blue;
			//palet[2] = Color.DodgerBlue;
			//palet[3] = Color.LightGreen;
			//palet[4] = Color.DarkGreen;
			//palet[5] = Color.YellowGreen;
			//palet[6] = Color.Yellow;
			//palet[7] = Color.Red;
			//palet[8] = Color.DarkRed;

			float m = 0;
			
			// red to yellow
			for (int i = 0; i < 30; i++)
			{
				m = m + 0.03f;
				palet[i] = Color.FromArgb(255, (int)(m * 255), 0);
			}

			m = 1;
			//yellow to green
			for (int i = 30; i < 60; i++)
			{
				m = m - 0.03f;
				palet[i] = Color.FromArgb((int)(m * 255), 255, 0);
			}
			m = 0;
			//green to cyan
			for (int i = 60; i < 90; i++)
			{
				m = m + 0.03f;
				palet[i] = Color.FromArgb(0, 255, (int)(m * 255));
			}
			m = 1;

			for (int i = 90; i < 120; i++)
			{
				m = m - 0.03f;
				palet[i] = Color.FromArgb(0, (int)(m * 255), 255);
			}

		}
		public static void SetBound(double Max, double MiN)
		{
			Step = (Max - MiN) / 119;
			Min = MiN;
			//Step = (Max - MiN) / 4;
		}
		public static int GetColor(double Value)
		{
			return (Step == 0)?palet[0].ToArgb():palet[119-(int)((Value - Min) / Step)].ToArgb();
			//int region = (int)(Value / Step);
			//switch (region)
			//{
			//    case 0:
			//        return Color.FromArgb(0, (int)(Math.Min(1, Math.Abs(((Value - Min) / Step))) * 255), 255).ToArgb();//(0, 0, 255 - (int)(Math.Abs(((Value - Min) / Step)) * 128)).ToArgb();
			//        break;
			//    case 1:
			//        return Color.FromArgb(0, 255, (int)(Math.Min(1, Math.Abs((( Step - (Value - (Min + Step)))) / Step)) * 255)).ToArgb();//(0, (int)(Math.Abs(((Value - (Min + Step)) / Step)) * 128), 128).ToArgb();
			//        break;
			//    case 2:
			//        return Color.FromArgb((int)(Math.Min(1, Math.Abs((((Value - (Min + Step * 2))) / Step))) * 255), 255, 0).ToArgb();//((int)(Math.Abs((((Value - (Min + Step * 2))) / Step)) * 128), 128, 0).ToArgb();
			//        break;
			//    default:
			//        return Color.FromArgb(255, (int)(Math.Min(1, Math.Abs(((Step - ((Value - (Min + Step * 3)))) / Step))) * 255), 0).ToArgb();//(127 + (int)(Math.Abs((((Value - (Min + Step * 3))) / Step)) * 128), 0, 0).ToArgb();
			//        break;
			//}
			//return 0;
		}
		public static Color[] Palet
		{
			get { return palet; }
		}
		public static double MIN
		{
			get { return Min; }
		}
		public static double STEP
		{
			get { return Step; }
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Other
Egypt Egypt
Nvidia Registered game developer.
Teaching Assistant,
Faculty of computer and information sciences,
Ain Shams University.
SmartLabZ QT Developer.
Have an experience of more than 2 years in c++(QT/MFC/ATL/Win32),c#, GDI,DirectX

Comments and Discussions