void TransferFunctionEditor::loadState(Value& in)
{
	transferFunction.loadState(in);
	
	setRange(transferFunction.GetMin(), transferFunction.GetMax());

  transferFunctionAlphaScalingSlider.setValue(int(transferFunction.GetScale() * (transferFunctionAlphaScalingSlider.minimum() + transferFunctionAlphaScalingSlider.maximum())));

	QVector<QPointF> points;
	for (int i = 0; i < transferFunction.GetAlphas().size(); i++)
		points.push_back(QPointF(transferFunction.GetAlphas()[i].x, transferFunction.GetAlphas()[i].y));

  transferFunctionAlphaWidget.setPoints(points);

	if (in.HasMember("Colormap"))
	{
		ColorMap cmap;
		cmap.loadState(in["Colormap"]);

		int colorMapIndex;
		for(colorMapIndex = 0; colorMapIndex < colorMaps.size(); colorMapIndex++)
			if (colorMaps[colorMapIndex].getName() == cmap.getName())
				break;

		if (colorMapIndex == colorMaps.size())
			addColorMap(VColorMap(cmap));

		colorMapComboBox.setCurrentIndex(colorMapIndex);
	}

}
static PyObject *
cmap_pylookup(PyObject *self, PyObject *args)
{
    PyObject *pyobj, *pyret;
    double d;
    rgba_t color;
    ColorMap *cmap;

    if(!PyArg_ParseTuple(args,"Od", &pyobj, &d))
    {
	return NULL;
    }

    cmap = (ColorMap *)PyCObject_AsVoidPtr(pyobj);
    if(!cmap)
    {
	return NULL;
    }

    color = cmap->lookup(d);
    
    pyret = Py_BuildValue("iiii",color.r,color.g,color.b,color.a);

    return pyret;
}
void ConfigurationParser::readMap()
{
    Q_ASSERT(isStartElement()
              && name() == "map");

    while(!atEnd()) {
        readNext();

        if(isEndElement())
            break;

        if(isStartElement()) {
            if(name() == "geometry") {
                readGeometry();
            }
            else if (name() == "layer") {
                DataLayer *layer = readLayer();
                if(layer) {
                    m_layers.insert(layer->name(), layer);
                }
            }
            else if (name() == "colorMap") {
                ColorMap colorMap = ColorMap::readColorMap(this);
                m_colorMaps.insert(colorMap.name(), colorMap);
            }
            else {
                readUnknownElement();
            }
        }
    }
}
static PyObject *
cmap_pylookup_with_flags(PyObject *self, PyObject *args)
{
    PyObject *pyobj, *pyret;
    double d;
    rgba_t color;
    ColorMap *cmap;
    int inside;
    int solid;

    if(!PyArg_ParseTuple(args,"Odii", &pyobj, &d, &solid, &inside))
    {
	return NULL;
    }

    cmap = (ColorMap *)PyCObject_AsVoidPtr(pyobj);
    if(!cmap)
    {
	return NULL;
    }

    color = cmap->lookup_with_transfer(d,solid,inside);
    
    pyret = Py_BuildValue("iiii",color.r,color.g,color.b,color.a);

    return pyret;
}
Example #5
0
void addXmlColors(
	TiXmlElement *rootElement,
	const ColorMap &colors,
	bool /*old*/)
{
	TiXmlElement *colorsElement = new TiXmlElement("Colors");

	for (ColorMap::const_iterator it = colors.begin(); it != colors.end(); it++)
	{
		unsigned int ldrawNum = it->first;
		const Color &color = it->second;
		TiXmlElement *colorElement = new TiXmlElement("Color");
		char numberBuf[128];

		sprintf(numberBuf, "%d", ldrawNum);
		addElement(colorElement, "LDrawNumber", numberBuf);
		addElement(colorElement, "POVName", color.lgeoName);
		//if (old)
		//{
		//	addElement(colorElement, "POVVersion", "3.0");
		//}
		addElement(colorElement, "Dependency", "LGColors");
		if (color.transparent)
		{
			addElement(colorElement, "IoR", "lg_ior");
		}
		colorsElement->LinkEndChild(colorElement);
	}
	rootElement->LinkEndChild(colorsElement);
}
Example #6
0
 static const Color *create_named_color(std::string str){
   toLowerI(str);
   static ColorMap cm;
   ColorMap::iterator it = cm.find(str);
   if(it != cm.end()) return  &it->second;
   else return 0;
 }
int Color(ColorVector& colors) {
  int maxColorUsed = 0;

  //Reset all the colors
  for(ColorVertex* cVertex:  adjacencyList) {
    cVertex->setColor(-1);
  }

  for(ColorVertex* cVertex:  adjacencyList) {
    ColorMap cmap;
    for(Edge* edge: cVertex->edges) {
      cmap[((ColorVertex *)(edge->getVertex()))->getColor()] = true;
    }
    for(color_t color: colors) {
      if(cmap.find(color) == cmap.end()) {
        cout << color << endl;
        cVertex->setColor(color);
        if(color > maxColorUsed) {
          maxColorUsed = color;
        }
        break;
      }
    }
  }
  return maxColorUsed;
}
Example #8
0
ColorMap::ColorMap(const ColorMap &o)
{
    init(o.getCols(),o.getRows());

    for(int row=0; row<rows; row++)
        for(int col=0; col<cols; col++)
            c[row][col] = o.get(row,col);
}
Example #9
0
ColorMap ColorMap::createSequential(const tgt::Color& base) {
    ColorMap cm;
    cm.colors_.clear();
    cm.addColorLast(tgt::Color(1.f, 1.f, 1.f, 1.f));
    cm.addColorLast(base);
    cm.setName("Sequential");
    return cm;
}
Example #10
0
// ----------------------------------------------------------------------------
//
bool RGBWA::getColorByName( LPCSTR color_name, RGBWA& rgb ) {
    ColorMap::iterator it = predefinedColors.find( color_name );
    if ( it == predefinedColors.end() )
        return false;

    rgb = (*it).second;
    return true;
}
Example #11
0
ColorMap ColorMap::createGermany() {
    ColorMap cm;
    cm.colors_.clear();
    cm.addColorLast(tgt::Color(0.f, 0.f, 0.f, 1.f));
    cm.addColorLast(tgt::Color(1.f, 0.f, 0.f, 1.f));
    cm.addColorLast(tgt::Color(1.f, 0.8f, 0.f, 1.f));
    cm.setName("Germany");
    return cm;
}
Example #12
0
ColorMap ColorMap::createColdHot() {
    ColorMap cm;
    cm.colors_.clear();
    cm.addColorLast(tgt::Color(0.f, 0.f, 1.f, 1.f));
    cm.addColorLast(tgt::Color(1.f, 1.f, 1.f, 1.f));
    cm.addColorLast(tgt::Color(1.f, 0.f, 0.f, 1.f));
    cm.setName("Cold Hot");
    return cm;
}
static void MakeColorMap (ColorMap& cmap)
{
  cmap.Load("copper-256"); 			       // load a default colormap
  if (! cmap) Matpack.Error("Can't load colormap");
  cmap.Reverse();					      // reverse ordering
  int i, n = cmap.Size();				   // change colormap now
  for (i = 0;  i < 20; i++) cmap[i] = ColorB(0,100+2*i,160+2*i);         // water
  for (i = 20; i < 80; i++) cmap[i] = ColorB(2*i+20,2*i+20,i/2+10);   // mangrove
  for (i = 1;  i < 60; i++) cmap[n-i] = ColorB(255-i,250-i,250-2*i);      // snow
}
Example #14
0
ColorMap ColorMap::createSpectral() {
    ColorMap cm;
    cm.colors_.clear();
    cm.addColorLast(tgt::Color(1.f, 0.f, 0.f, 1.f));
    cm.addColorLast(tgt::Color(1.f, 1.f, 0.f, 1.f));
    cm.addColorLast(tgt::Color(0.f, 1.f, 0.f, 1.f));
    cm.addColorLast(tgt::Color(0.f, 0.f, 1.f, 1.f));
    cm.setName("Spectral");
    return cm;
}
Example #15
0
bool EdgeColoringTest<DefaultStructs>::test(const Graph &graph, const ColorMap &colors)
{
	typedef typename Graph::PVertex Vert;
	typedef typename Graph::PEdge Edge;
	const EdgeDirection Mask = EdDirIn|EdDirOut|EdUndir;
	int degree = graph.Delta(Mask);
	int LOCALARRAY(kolory, degree+1);
	int lenKolory = 0;
	for(Vert vv = graph.getVert(); vv; vv = graph.getVertNext(vv)) {
		lenKolory = 0;
		for(Edge ee = graph.getEdge(vv, Mask); ee;
			ee = graph.getEdgeNext(vv, ee, Mask))
		{
			if(!colors.hasKey(ee)) return false;
			int col = colors[ee];
			if(col<0) return false;
			kolory[lenKolory++] = col;
		}
		DefaultStructs::sort(kolory, kolory+lenKolory);
		int tmpLen = std::unique(kolory, kolory+lenKolory)-kolory;
		if(tmpLen!=lenKolory)
			return false;
	}
	return true;
}
Example #16
0
void PngFile::Save(const Image2D &image, const ColorMap &colorMap) throw(IOException)
{
	long double normalizeFactor = image.GetMaxMinNormalizationFactor();
	
	png_bytep *row_pointers = RowPointers();
	
	for(unsigned long y=0;y<image.Height();++y) {
		for(unsigned long x=0;x<image.Width();++x) {
			int xa = x * PixelSize();
			row_pointers[y][xa]=colorMap.ValueToColorR(image.Value(x, y) * normalizeFactor);
			row_pointers[y][xa+1]=colorMap.ValueToColorG(image.Value(x, y) * normalizeFactor);
			row_pointers[y][xa+2]=colorMap.ValueToColorB(image.Value(x, y) * normalizeFactor);
			row_pointers[y][xa+3]=colorMap.ValueToColorA(image.Value(x, y) * normalizeFactor);
		}
	}
}
Example #17
0
    void parallel_bfs_helper
      (DistributedGraph& g,
       typename graph_traits<DistributedGraph>::vertex_descriptor s,
       ColorMap color,
       BFSVisitor vis,
       pdalboost::param_not_found,
       VertexIndexMap vertex_index)
    {
      using pdalboost::graph::parallel::process_group;

      typedef graph_traits<DistributedGraph> Traits;
      typedef typename Traits::vertex_descriptor Vertex;
      typedef typename pdalboost::graph::parallel::process_group_type<DistributedGraph>::type 
        process_group_type;

      set_property_map_role(vertex_color, color);
      color.set_consistency_model(0);

      // Buffer default
      typedef typename property_map<DistributedGraph, vertex_owner_t>
        ::const_type vertex_owner_map;
      typedef pdalboost::graph::distributed::distributed_queue<
                process_group_type, vertex_owner_map, queue<Vertex>, 
                detail::darken_and_push<ColorMap> > queue_t;
      queue_t Q(process_group(g),
                get(vertex_owner, g),
                detail::darken_and_push<ColorMap>(color));
      breadth_first_search(g, s, Q, vis, color);
    }
Example #18
0
  void VGImage::rectangles(const Bitmap &bitmap)
  {
    double bw=bitmap.x2-bitmap.x1;
    double bh=bitmap.y2-bitmap.y1;

    Bitmap::CMType which;
    int w = 0, h = 0;
    InterpolatedColorMap icm;
    ColorMap cm;

    if(bitmap.getICM(&icm))
    {
      which = Bitmap::ICM;
      w = icm.getCols();
      h = icm.getRows();
    }
    else if(bitmap.getCM(&cm))
    {
      which = Bitmap::CM;
      w = cm.getCols();
      h = cm.getRows();
    }

    double dx=bw/w;
    double dy=bh/h;

    StrokeStyle ssb(Color::CLEAR);

    // In the future, this could create bigger boxes if adjacent rectangles
    // would be the same color.

    for(int r=(ll?0:h-1); (ll?r<h:r>=0); r+=(ll?1:-1))
    {
      for(int c=0; c<w; c++)
      {
        double x1=bitmap.x1+c*dx;
        double y1=bitmap.y1+(ll?r:h-r-1)*dy;
        Rectangle rect(x1,y1,x1+dx,y1+dy,ssb); 
        if(which==Bitmap::CM)
          rect.setFillColor(cm.get(r,c)); 
        else
          rect.setFillColor(icm.get(r,c));             
        rectangle(rect); 
      }
    }
  }
Example #19
0
void SimpleVolumeGenerator::generate( const FileLoader &loader,
				      const FieldSelector &selector,
				      CoordinateAdjuster &adjuster,
				      const ColorMap &colormap
) {
  
  if( selector.getFieldNum() < 4 ) {
    throw std::runtime_error("SimpleVolumeGenerator::4 indeces is needed at least.");
  }
  
  volume_->clear();

  // setting coordinates range
  const FileLoader::DataType &max_range = loader.getMaxRange();
  const FileLoader::DataType &min_range = loader.getMinRange();

  const double min_x = selector.getField( min_range, 0);
  const double min_y = selector.getField( min_range, 1);
  const double min_z = selector.getField( min_range, 2);
  
  const double dist_x = selector.getField( max_range, 0) - min_x;
  const double dist_y = selector.getField( max_range, 1) - min_y;
  const double dist_z = selector.getField( max_range, 2) - min_z;
  const double dist = std::max( dist_x, std::max( dist_y, dist_z ) );

  const double max_x = min_x + dist;
  const double max_y = min_y + dist;
  const double max_z = min_z + dist;

  adjuster.setRangeX( max_x, min_x );
  adjuster.setRangeY( max_y, min_y );
  adjuster.setRangeZ( max_z, min_z );

  // setting volume data
  for( FileLoader::DataContainerType::const_iterator it = loader.begin();
       it != loader.end();
       ++it ) {
    const FileLoader::DataType &data = *it;

    const double raw_x = selector.getField( data, 0 );
    const double raw_y = selector.getField( data, 1 );
    const double raw_z = selector.getField( data, 2 );
    
    const double x = adjuster.x(raw_x) * ( getVolume()->sizex() );
    const double y = adjuster.y(raw_y) * ( getVolume()->sizey() );
    const double z = adjuster.z(raw_z) * ( getVolume()->sizez() );
    
    double r, g, b, a;
    colormap.getColor( adjuster.x(raw_x), &r, &g, &b, &a );
    
    setVolumeElement
      ( 
       x, y, z,
       r * 255, g * 255, b * 255, a * 255);
  }
  
}
Example #20
0
void MpSurfacePrism (Scene &S, const Matrix &Z, int nsegments,
                     double wx, double wy, 
                     const ColorMap &cmap,double cmin, double cmax)
{
  // nothing that can be drawn
  if ( Z.Empty() ) return;

  // 4-segments faster special case
  if (nsegments == 4) {
    MpSurfacePrism4(S,Z,wx,wy,cmap,cmin,cmax);
    return;
  }

  // find the extrema
  double zmin = Min(Z);

  // check for valid nsegments values
  MpForceRange(nsegments, 3, MaxVertices);

  // check if a colormap should be used
  double dz,cscale = 0;
  bool usecolormap;
  int ncmap = cmap.Size()-1;
  if (cmap) { 
    usecolormap = true;
    dz = cmax - cmin; 
    cscale = (dz == 0.0) ? 0 : ncmap/dz;
  } else
    usecolormap = false;

  // add prism
  for (int x = Z.Rlo(); x <= Z.Rhi(); x++)
    for (int y = Z.Clo(); y <= Z.Chi(); y++) {

      double z = Z(x,y), 
             height = 0.5 * (z - zmin);
      Trafo T = trans(y,height+zmin,x)
                * scale(wy,height,wx)
                * rot(Trafo::XAxis,M_PI/2);

      // coloring
      const ColorB *color;
      if (usecolormap) { 
        int c = int((z-cmin)*cscale);
        if (c > ncmap) 
          c = ncmap;
        else if (c < 0) 
          c = 0;
        color = &cmap[c];
      } else
        color = (ColorB*)NULL;

      cylinder(S,nsegments,T,color);
  }
}
void MpDensityPlot::Draw (Scene& scene, const Matrix& z,
                          const ColorMap &cmap, double cmin, double cmax,
                          int mode)
{
  if (! scene.IsOpen()) 
    Matpack.Error("MpDensityPlot: scene is not open");

  int outlined = (mode & MpDensityPlot::Outlined) ? (Fill | Outline) : Fill;

  ColorB BlendFrom(0,0,0), BlendTo(255,255,255); // black to white
        
  // scale factor for color mapping
  int ncmap;
  double cscale = 0, 
         dz = cmax - cmin;
  if (cmap) {
    ncmap = cmap.Size()-1;
    cscale = (dz == 0.0) ? 0.0 : ncmap/dz;
  } else 
    ncmap = 0;
    
  // plot all density cells 
  for (int x = z.Clo(); x <= z.Chi(); ++x) {

    double dx1 = (x != z.Clo()) ? 0.5 : 0,
           dx2 = (x != z.Chi()) ? 0.5 : 0;
        
    for (int y = z.Rlo(); y <= z.Rhi(); ++y) {
                
      // calculate color
      long color;
      if (ncmap) {
        int c = int((z[y][x]-cmin)*cscale);
        MpForceRange(c,0,ncmap);
        color = scene.NewColor(cmap[c]);
              
      } else {    
        // linear map to color range black - white
        double intens = (dz == 0.0) ? 0.0 : (z[y][x] - cmin)/dz;
        MpForceRange(intens,0.0,1.0);
        color = scene.NewColor(((1.0-intens)*BlendFrom.red+intens*BlendTo.red)/255.0,
                               ((1.0-intens)*BlendFrom.green+intens*BlendTo.green)/255.0,
                               ((1.0-intens)*BlendFrom.blue+intens*BlendTo.blue)/255.0, RGB);
      }
            
      // draw squares
      double dy1 = (y != z.Rlo()) ? 0.5 : 0,
             dy2 = (y != z.Rhi()) ? 0.5 : 0;
      double px[4] = {y-dy1,y+dy2,y+dy2,y-dy1},
             py[4] = {x-dx1,x-dx1,x+dx2,x+dx2};
      scene.Polygon(4,px,py,color,outlined);
    }
  }
}
Example #22
0
void FDTD2DTMz::runSimulation() {
    Gifanimate gifanimate;
    ColorMap colorMap;
    int time;
    int xgridpoint;
    int ygridpoint;
    for (time = 0; time < MAXTIME; time++){
        emField2DTMz.updateMagneticField();
        emField2DTMz.updateElectricField();
        rickerWaveletSource.addRickerWaveletSource(STRUCTURE_SIZE_X / 2, STRUCTURE_SIZE_Y / 2, time, 0.0, emField2DTMz);
        if (time == 30){
            for (ygridpoint = 0; ygridpoint < STRUCTURE_SIZE_Y; ygridpoint++){
                    for (xgridpoint = 0; xgridpoint < STRUCTURE_SIZE_X; xgridpoint++){
                    waterFallVector[xgridpoint][ygridpoint] = emField2DTMz.get2DEz()[xgridpoint][ygridpoint];
                }
            }
            colorMap.drawchart(waterFallVector, time/10);
        }
    }
}
Example #23
0
int SeqEdgeColoringPar<DefaultStructs>::greedyInter(const Graph &graph, ColorMap &colors,
	EInIter beg, EInIter end, int maxCol)
{
	if (DefaultStructs::ReserveOutAssocCont) colors.reserve(graph.getEdgeNo(EdDirIn|EdDirOut|EdUndir));
	int locMax = -1;
	while(beg != end) {
		int col = greedyInter(graph, colors, *beg++, maxCol);
		if(col > maxCol) maxCol = col;
		if(col > locMax) locMax = col;
	}
	return locMax;
}
Example #24
0
 inline void
 parallel_bfs_helper
   (DistributedGraph& g,
    typename graph_traits<DistributedGraph>::vertex_descriptor s,
    ColorMap color,
    BFSVisitor vis,
    BufferRef Q,
    VertexIndexMap)
 {
   set_property_map_role(vertex_color, color);
   color.set_consistency_model(0);
   breadth_first_search(g, s, Q.ref, vis, color);
 }
Example #25
0
int SeqEdgeColoringPar<DefaultStructs>::greedy(const Graph &graph, ColorMap &colors,
	typename Graph::PEdge edge)
{
	if(colors.hasKey(edge) && colors[edge]>=0)
		return -1;

	typedef typename Graph::PVertex Vert;
	typedef typename Graph::PEdge Edge;
	const EdgeDirection Mask = EdDirIn|EdDirOut|EdUndir;

	Vert v1 = graph.getEdgeEnd1(edge);
	Vert v2 = graph.getEdgeEnd2(edge);

	int deg = graph.deg(v1, Mask)+graph.deg(v2, Mask);
	bool LOCALARRAY(neighCol, deg);
	for(int i = 0; i < deg; i++) neighCol[i] = false;

	for(Edge ee = graph.getEdge(v1, Mask); ee;
		ee = graph.getEdgeNext(v1, ee, Mask))
	{
		if(!colors.hasKey(ee)) continue;
		int col = colors[ee];
		if(col>=0 && col<deg)
			neighCol[ col ] = true;
	}

	for(Edge ee = graph.getEdge(v2, Mask); ee;
		ee = graph.getEdgeNext(v2, ee, Mask))
	{
		if(!colors.hasKey(ee)) continue;
		int col = colors[ee];
		if(col>=0 && col<deg)
			neighCol[ col ] = true;
	}

	int col = 0;
	while( neighCol[col] ) col++;
	return colors[ edge ] = col;
}
Example #26
0
int SeqEdgeColoringPar<DefaultStructs>::greedy(const Graph &graph, ColorMap &colors)
{
	colors.reserve(graph.getEdgeNo(EdDirIn|EdDirOut|EdUndir));
	const EdgeDirection Mask = EdDirIn|EdDirOut|EdUndir;
	int locMax = -1;
	for(typename Graph::PEdge ee = graph.getEdge(Mask); ee;
		ee = graph.getEdgeNext(ee, Mask))
	{
		int col = greedy(graph, colors, ee);
		if(col > locMax) locMax = col;
	}
	return locMax;
}
Example #27
0
ColorMap ColorMap::createTango() {
    ColorMap cm;
    cm.colors_.clear();
    cm.addColorLast(tgt::Color(.7656, .625, 0, 1));      //Butter
    cm.addColorLast(tgt::Color(.6172, .6016, .0234, 1)); // Chameleon
    cm.addColorLast(tgt::Color( .125, .2891, .5273, 1)); // Sky Blue
    cm.addColorLast(tgt::Color(.3594,  .207, .3984, 1)); // Plum
    cm.addColorLast(tgt::Color(.6406, 0, 0, 1));         // Scarlet Red
    cm.addColorLast(tgt::Color(.5586, .3477, .0078, 1)); // Chocolate
    cm.setName("Tango");
    return cm;
}
static PyObject *
pycmap_set_solid(PyObject *self, PyObject *args)
{
    PyObject *pycmap;
    int which,r,g,b,a;
    ColorMap *cmap;

    if(!PyArg_ParseTuple(args,"Oiiiii",&pycmap,&which,&r,&g,&b,&a))
    {
	return NULL;
    }

    cmap = (ColorMap *)PyCObject_AsVoidPtr(pycmap);
    if(!cmap)
    {
	return NULL;
    }

    cmap->set_solid(which,r,g,b,a);

    Py_INCREF(Py_None);
    return Py_None;
}
Example #29
0
int EdgeColoringTest<DefaultStructs>::maxColor(const Graph &graph, const ColorMap &colors)
{
	typedef typename Graph::PEdge Edge;
	const EdgeDirection Mask = EdDirIn|EdDirOut|EdUndir;
	int col = -1;
	for(Edge ee = graph.getEdge(Mask); ee;
		ee = graph.getEdgeNext(ee, Mask) )
	{
		if(!colors.hasKey(ee)) continue;
		int tmp = colors[ee];
		if(tmp>col) col = tmp;
	}
	return col;
}
static PyObject *
pycmap_set_transfer(PyObject *self, PyObject *args)
{
    PyObject *pycmap;
    int which;
    e_transferType transfer;
    ColorMap *cmap;

    if(!PyArg_ParseTuple(args,"Oii",&pycmap,&which,&transfer))
    {
	return NULL;
    }

    cmap = (ColorMap *)PyCObject_AsVoidPtr(pycmap);
    if(!cmap)
    {
	return NULL;
    }

    cmap->set_transfer(which,transfer);

    Py_INCREF(Py_None);
    return Py_None;
}