source: trunk/packages/vizservers/nanovis/Color.cpp @ 1452

Last change on this file since 1452 was 434, checked in by mmc, 18 years ago

Added separate controls for outline enable/disable/color, and volume
data enable/disable.

File size: 2.3 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 * Color.cpp: Color class
4 *
5 * ======================================================================
6 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
7 *           Purdue Rendering and Perceptualization Lab (PURPL)
8 *
9 *  Copyright (c) 2004-2006  Purdue Research Foundation
10 *
11 *  See the file "license.terms" for information on usage and
12 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 * ======================================================================
14 */
15
16#include <stdio.h>
17#include <assert.h>
18
19#include "Color.h"
20#include "define.h"
21
22Color::Color() {
23        R=G=B=0.0;
24        next=0;
25}
26
27Color::Color(double r, double g, double b) {
28        R=r;
29        G=g;
30        B=b;
31        next=0;
32}
33
34Color::Color(const Color& c)
35 : R(c.R), G(c.G), B(c.B), next(c.next)
36{
37}
38
39Color&
40Color::operator=(const Color& c)
41{
42    R = c.R;
43    G = c.G;
44    B = c.B;
45    next = c.next;
46    return *this;
47}
48
49void Color::LimitColors(){ //Limits the color to be in range of 0.0 and 1.0
50        if (R>1.0) R=1.0;
51        if (G>1.0) G=1.0;
52        if (B>1.0) B=1.0;
53
54        if (R<0.0) R=0.0;
55        if (G<0.0) G=0.0;
56        if (B<0.0) B=0.0;
57}
58
59Color Color::operator*(double k){
60        return Color(R*k, G*k, B*k);
61}
62
63
64//This is NOT member operator. It's used so we can write (k*V), not only (V*k) (V-vector k-scalar)
65Color operator*(double k, Color &other){
66        return Color(other.R*k, other.G*k, other.B*k);
67}
68
69Color::~Color(){}
70
71Color Color::operator +(Color &other){
72        return Color(this->R+other.R,this->G+other.G,this->B+other.B);
73}
74
75Color Color::operator *(Color &other){
76        return Color(this->R*other.R,this->G*other.G,this->B*other.B);
77}
78
79void Color::GetRGBA(double opacity, unsigned char *result){
80        LimitColors();
81
82        assert(opacity>=0 && opacity <=1);
83
84        result[0] = (unsigned char) (R*255.0);
85        result[1] = (unsigned char) (G*255.0);
86        result[2] = (unsigned char) (B*255.0);
87        result[3] = (unsigned char) (opacity*255.0);
88}
89
90void Color::SetRGBA(unsigned char *color){
91        R = color[0];
92        G = color[1];
93        B = color[2];
94}
95
96void Color::GetRGB(unsigned char *result){
97        result[0] = (unsigned char) (R*255.0);
98        result[1] = (unsigned char) (G*255.0);
99        result[2] = (unsigned char) (B*255.0);
100}
101
102void Color::GetRGB(float *result){
103        result[0] = (float) (R);
104        result[1] = (float) (G);
105        result[2] = (float) (B);
106}
107
Note: See TracBrowser for help on using the repository browser.