G4DefaultLinearColorMap.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 
00030 #include "G4DefaultLinearColorMap.hh"
00031 
00032 G4DefaultLinearColorMap::G4DefaultLinearColorMap(G4String mName)
00033 :G4VScoreColorMap(mName)
00034 {;}
00035 
00036 G4DefaultLinearColorMap::~G4DefaultLinearColorMap()
00037 {;}
00038 
00039 void G4DefaultLinearColorMap::GetMapColor(G4double val, G4double color[4])
00040 {
00041   G4double value;
00042   if(fMaxVal == fMinVal) 
00043     value = 0.;
00044   else
00045     value = (val-fMinVal)/(fMaxVal-fMinVal);
00046 
00047   if(value > 1.) {value=1.;}
00048   if(value < 0.) {value=0.;}
00049 
00050   // color map
00051   const int NCOLOR = 6;
00052   struct ColorMap {
00053     G4double val;
00054     G4double rgb[4];
00055   } colormap[NCOLOR] = {{0.0, {1., 1., 1., 1.}}, // value, r, g, b, alpha
00056                         {0.2, {0., 0., 1., 1.}},
00057                         {0.4, {0., 1., 1., 1.}},
00058                         {0.6, {0., 1., 0., 1.}},
00059                         {0.8, {1., 1., 0., 1.}},
00060                         {1.0, {1., 0., 0., 1.}}};
00061   
00062   // search
00063   G4int during[2] = {0, 0};
00064   for(int i = 1; i < NCOLOR; i++) {
00065     if(colormap[i].val >= value) {
00066       during[0] = i-1;
00067       during[1] = i;
00068       break;
00069     }
00070   }
00071 
00072   // interpolate
00073   G4double a = std::fabs(value - colormap[during[0]].val);
00074   G4double b = std::fabs(value - colormap[during[1]].val);
00075   for(int i = 0; i < 4; i++) {
00076     color[i] = (b*colormap[during[0]].rgb[i] + a*colormap[during[1]].rgb[i])
00077       /(colormap[during[1]].val - colormap[during[0]].val);
00078   } 
00079 
00080 }
00081 
00082 

Generated on Mon May 27 17:48:00 2013 for Geant4 by  doxygen 1.4.7