Example #1
0
    colormap read_colormap_from_string(const std::string &spec, const size_t steps) {
        std::istringstream iss(spec);
        std::vector<std::string> tokens{std::istream_iterator<std::string>{iss},
                                        std::istream_iterator<std::string>{}};
        auto it = default_colormaps.find(tokens[0]);
        if (it != default_colormaps.end()) {
            return colormap(it->second, steps);
        }

        // default
        return colormap(&colormap_basic_hot, steps);
    }
Example #2
0
	void depthFirstVisit( Visitor& vis, const vertex_descriptor& vroot )
	{
		std::vector<boost::default_color_type > colormap( boost::num_vertices( _graph ), boost::white_color );
		BOOST_FOREACH( const vertex_descriptor &vd, getVertices() )
		{
			vis.initialize_vertex( vd, _graph );
		}
Example #3
0
void FrameView::appendFrame (unsigned long long from, unsigned long long to)
{
	//qDebug("frame: dt=%f", to - from);


	QwtInterval interval(0.0f, 500.0f);
	QwtLinearColorMap colormap(Qt::darkCyan, Qt::red);
	colormap.addColorStop(0.1, Qt::cyan);
	colormap.addColorStop(0.6, Qt::green);
	colormap.addColorStop(0.8, Qt::yellow);
	colormap.addColorStop(0.95, Qt::red);

	QColor const c = colormap.color(interval, to - from);

	m_bars->m_values.push_back(to - from);
	m_bars->m_begins.push_back(from);
	m_bars->m_ends.push_back(to);
	m_bars->m_colors.push_back(c);
	m_bars->m_strvalues.push_back(QString("%1").arg(m_bars->m_values.size()));

	m_bars->setSamples(m_bars->m_values);

	m_bars->itemChanged();
	m_bars->legendChanged();
}
Example #4
0
void CapturedImage::create(Camera *cam)
{
    QVector<QRgb> colormap(256);

    for(int i=0; i<256; i++)
    {
        colormap[i]=(0xFF000000 | (((unsigned char)(i))<<16) | (((unsigned char)(i))<<8) | ((unsigned char)(i)));
    }

    width=cam->getSizeWidth();
    height=cam->getSizeHeight();
    pixel_size=cam->getPixelByteSize();

    qDebug()<<"Creata CapturedImage: "<<width<<"x"<<height<<"x"<<pixel_size*8;

    long size = width*height*pixel_size;

    unsigned char *data=new unsigned char[size];
    qimage=new QImage((const unsigned char *)data, width, height, QImage::Format_Indexed8);
    qimage->setColorTable(colormap);
    delete [] data;

    buffer.SetBuffer(qimage->bits(), size);

    created=true;
}
Example #5
0
void evtime() {
  vector<int> runs;
  vector<int> marks;
  vector<int> mcols;
  runs.push_back(13893);
  marks.push_back(2);
  mcols.push_back(2);
  runs.push_back(14009);
  marks.push_back(24);
  mcols.push_back(4);
  runs.push_back(14085);
  marks.push_back(25);
  mcols.push_back(3);
  runs.push_back(14234);
  marks.push_back(5);
  mcols.push_back(3);
  runs.push_back(14434);
  marks.push_back(28);
  mcols.push_back(3);
  string pre = "run";
  string suf = "evt.root";
  double tmax = 160;
  double emax = 180;
  new TCanvas;
  TH1* ph = new TH2F("hevtime", "Event vs. time; Time [sec]; Event",
                     tmax, 0, tmax, emax, 0, emax);
  ph->SetStats(0);
  ph->Draw("axis");
  TLegend* pleg = new TLegend(0.65,0.15,0.85,0.37);
  pleg->SetBorderSize(0);
  for ( unsigned int isam=0; isam<runs.size(); ++isam ) {
    int run = runs[isam];
    int icol = dsindex(run);
    int col = colormap(icol);
    ostringstream ssrun;
    ssrun << run;
    string srun = ssrun.str();
    ostringstream sst0;
    sst0 << t0map(run);
    string fname = pre + srun + suf;
    TFile* pfile = TFile::Open(fname.c_str(), "READ");
    TTree* ptree = dynamic_cast<TTree*>(pfile->Get("DXDisplay/EventTree"));
    ptree->SetMarkerStyle(marks[isam]);
    ptree->SetMarkerColor(col);
cout << run << " " << col << " " << sst0.str() <<  endl;
    if ( ptree == 0 ) {
      cout << "Tree not found" << endl;
      pfile->ls();
      return;
    }
    string sarg = "event:tlo-";
    sarg += sst0.str();
    sarg += ">>hevtime";
    ptree->Draw(sarg.c_str(), "", "same");
    pleg->AddEntry(ptree, srun.c_str(), "p");
  }
  pleg->Draw();
}
Example #6
0
/*!
  Create pixel values for grayscale, red and jet colormaps.

  \param color the value of color
  \return a QRgb which is a pixel representation using Qt Toolkit 4.0
*/
QRgb ImageB::getPixelRGB( int color )
{
   const int gray=0, jet=1, pink=2;
   QRgb value;

   if (has_colormap != 1)
   {
     colormap = imgproc.createColorMap();
     has_colormap = 1;
   }
 
   if (color > 255)
     {
       //cout << "Color Out of Range:" << color << endl;
       color = 255;
     }
   
   switch ( curr_colormap )
   {
     case gray:
       value = qRgb(color,color,color);
       break;
    
     case jet:
       //transporta pra jet
       color = (int) round( (color*63)/255 ); //seta proporcional a 63, pois o vetor jet tem no máximo 63 cores
       if (color <= 0) color =1;
      
       if (color > 63) //garante valores entre 1 e 63
           color = 63;
          

       value = qRgb( (int)colormap(color,1), (int) colormap(color,2), (int) colormap(color,3) );
       break;
     
     case pink:
       value = qRgb((int) round((color*80)/100),0,(int) round((color*20)/100));
       break;
     
     default:
       value = qRgb(0,0,0);
   }
 
  return value;
}
Example #7
0
    //_____________________________________________________
    gboolean ArgbHelper::styleSetHook( GSignalInvocationHint*, guint, const GValue* params, gpointer )
    {

        // get widget from params
        GtkWidget* widget( GTK_WIDGET( g_value_get_object( params ) ) );

        // check type
        if( !GTK_IS_WIDGET( widget ) ) return FALSE;
        if( !GTK_IS_WINDOW( widget ) ) return TRUE;

        // make sure widget has not been realized already
        #if GTK_CHECK_VERSION(2, 20, 0)
        if( gtk_widget_get_realized( widget ) ) return TRUE;
        #else
        if( GTK_WIDGET_REALIZED( widget ) ) return TRUE;
        #endif

        // screen
        GdkScreen* screen = gdk_screen_get_default();
        if( !screen ) return TRUE;

        // colormap
        GdkColormap* colormap(gdk_screen_get_rgba_colormap( screen ) );
        if( !colormap ) return TRUE;

        // hint
        GtkWindow* window( GTK_WINDOW( widget ) );
        GdkWindowTypeHint hint = gtk_window_get_type_hint( window );
        if(
            hint == GDK_WINDOW_TYPE_HINT_MENU ||
            hint == GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU ||
            hint == GDK_WINDOW_TYPE_HINT_POPUP_MENU ||
            hint == GDK_WINDOW_TYPE_HINT_TOOLTIP ||
            hint == GDK_WINDOW_TYPE_HINT_COMBO
            )
        {

            #if OXYGEN_DEBUG
            std::cerr << "Oxygen::ArgbHelper::styleSetHook - "
                << widget << " (" << G_OBJECT_TYPE_NAME( widget ) << ")"
                << " hint: " << Gtk::TypeNames::windowTypeHint( hint )
                << std::endl;
            #endif

            // assign argb colormap to widget
            gtk_widget_set_colormap( widget, colormap );

        }

        return TRUE;

    }
Example #8
0
std::vector<colormap> loadColorMapping(const resource_configuration& resconf)
{
	Json::Reader reader;
	Json::Value root;

	std::ifstream input(color_mapping_file, std::ifstream::binary);
	bool parsingSuccessful = reader.parse(input, root, false);
	if (!parsingSuccessful) {
		throw std::runtime_error(reader.getFormatedErrorMessages());
	}

	std::vector<colormap> ret;

	auto members = root.getMemberNames();

	for(const auto& membername : members) {
		const auto& member = root[membername];
		std::vector<color> colors;
		if(!member[0u].isArray()) {
			int r = member[0u].asInt();
			int g = member[1u].asInt();
			int b = member[2u].asInt();
			colors.push_back(color(r, g, b));
		} else {
			for(const auto& col : member) {
				int r = col[0u].asInt();
				int g = col[1u].asInt();
				int b = col[2u].asInt();
				colors.push_back(color(r, g, b));
			}
		}

		bool found = false;
		for(int i = 0; i < num_terrain_types; i++) {
			if(resconf.resource_name[i] == membername) {
				for(const auto& col : colors) {
					ret.push_back(colormap(col, i));
				}
				found = true;
				break;
			}
		}

		if(!found) {
			printf("Warning: invalid terrain name \"%s\"\n", membername.c_str());
		}
	}

	return ret;
}
Example #9
0
QX11InfoData* QX11Info::getX11Data(bool def) const
{
    QX11InfoData* res = 0;
    if (def) {
        res = new QX11InfoData;
        res->ref = 0;
        res->screen = appScreen();
        res->depth = appDepth();
        res->cells = appCells();
        res->colormap = colormap();
        res->defaultColormap = appDefaultColormap();
        res->visual = (Visual*) appVisual();
        res->defaultVisual = appDefaultVisual();
    } else if (x11data) {
        res = new QX11InfoData;
        *res = *x11data;
        res->ref = 0;
    }
    return res;
}
Volume3d::Volume3d(vtkSmartPointer<vtkImageData> data)
 : mMaterial(MaterialSharedPtr(new Material(vertexShader, fragmentShader))),
   mBackFaceMaterial(MaterialSharedPtr(new Material(backFaceVertexShader, backFaceFragmentShader))),
   mBound(false),
   mVertexAttrib(-1), mBFVertexAttrib(-1),
   mProjectionUniform(-1), mModelViewUniform(-1), mDimensionsUniform(-1), mClipPlaneUniform(-1), mSpacingUniform(-1), mScreenSizeUniform(-1),
   mBFProjectionUniform(-1), mBFModelViewUniform(-1), mBFDimensionsUniform(-1), mBFSpacingUniform(-1),
   mTextureHandle(0), mBackFaceTextureHandle(0),
   mFrameBuffer(0)
{
	android_assert(data);

	clearClipPlane();

	// Check if the data dimension is 3
	int dim = data->GetDataDimension();
	LOGD("dimension = %d", dim);
	if (dim != 3) {
		throw std::runtime_error(
			"Volume: data is not 3D (dimension = " + Utility::toString(dim) + ")"
		);
	}

	if (!data->GetPointData() || !data->GetPointData()->GetScalars())
		throw std::runtime_error("IsoSurface: unsupported data");

	data->GetDimensions(mDimensions);
	LOGD("dimensions %d %d %d", mDimensions[0], mDimensions[1], mDimensions[2]);

	double spacing[3];
	data->GetSpacing(spacing);
	LOGD("spacing %f %f %f", spacing[0], spacing[1], spacing[2]);
	mSpacing = Vector3(spacing[0], spacing[1], spacing[2]);//.normalized();

	data->GetPointData()->GetScalars()->GetRange(mRange);
	LOGD("range min=%f max=%f", mRange[0], mRange[1]);

	vtkDataArray* scalars = data->GetPointData()->GetScalars();
	android_assert(scalars);

	unsigned int num = scalars->GetNumberOfTuples();
	android_assert(num == static_cast<unsigned>(mDimensions[0]*mDimensions[1]*mDimensions[2]));
	mTexture.resize(num*4);

	for (unsigned int i = 0; i < num; ++i) {
		double value = scalars->GetComponent(i, 0);
		double norm = (value-mRange[0]) / (mRange[1]-mRange[0]);
		float r, g, b;
		colormap(norm, r, g, b);
		mTexture[i*4+0] = r*255;
		mTexture[i*4+1] = g*255;
		mTexture[i*4+2] = b*255;
		mTexture[i*4+3] = (0.03+0.3*norm)*255;
		// mTexture[i*4+3] = (0.03+0.97*norm)*255;
		// mTexture[i*4+3] = 0.3*norm*255;
		// mTexture[i*4+3] = (0.3+0.7*norm)*255;
		// mTexture[i*4+3] = (0.1+0.7*norm)*255;
		// mTexture[i*4+3] = norm*255;
	}

	LOGD("loading finished");
}
Example #11
0
 double blue(double value)
 {
   double colors[] = PALETTE_BLUE;
   return colormap(value, colors, PALETTE_LENGTH);
 }
Example #12
0
 double green(double value)
 {
   double colors[] = PALETTE_GREEN;
   return colormap(value, colors, PALETTE_LENGTH);
 }
Example #13
0
 double red(double value)
 {
   double colors[] = PALETTE_RED;
   return colormap(value, colors, PALETTE_LENGTH);
 }
Example #14
0
void MapTopo(struct elmapheaderV101 *map, struct Window *win, short MapAsSFC,
	short MakeWater, short Visible, double *Elev)
{
 short eco = 0, understory = 0, notsnow = 0, NoAlias = 0, VolumeTexture = 0,
	 Texture, QInterp = 1, ElInterp = 1, i, j, k, l, sum, Mode;
 long NewSubPixArraySize, SubPixWidth, SubPixHeight, MinX, MaxX, StartY, EndY,
	 colval, x, y, zip, WtAvg;
/* changed from float to double 10/19/95 */
 double AAX[3], AAY[3], Xoffset, dist;
 double ecoline, snowline, m, h, d;
 struct QCvalues QC;
 UBYTE *PixPtr;
 struct ColorComponents CC[4];

 double fred, fgrn, fblu;
 short PolyMinXPt, PolyMaxXPt, Tex, MinPt, MidPt, MaxPt, MinQPt, MaxQPt;
 double ElX, ElY, LatX, LatY, LonX, LonY, QX, QY,
	 ElStart, LatStart, LonStart, QStart, ElPt, LatPt, LonPt, QPt,
	Temp, X5, Y5, Y4, X3, El3, EloQY;

/* initialize */

 Reflections = 0; /* enabled in WaterEco_Set() */
 treedraw = undertreedraw = 0;	/* enabled in ecoset() */

 if (OldLightingModel)
  {
  h = sunlong - facelong * PiOver180 - diplong;
  if (h > Pi) h -= TwoPi;
  else if (h < -Pi) h += TwoPi;
  d = sunlat - facelat * PiOver180 - diplat;
  if (d > Pi) d -= TwoPi;
  else if (d < -Pi) d += TwoPi;
  sunangle = sqrt(h * h + d * d) * .7071;
  if (sunangle > HalfPi) sunangle = HalfPi;
  sunfactor = 1.0 - cos(sunangle);
  sunshade = sunfactor * PARC_RNDR_MOTION(22);
  sunshade += ((1.0 - sunshade) * cloudcover);
  } /* if */

/* compute fade and fog factors */

 fade = (qqq - PARC_RNDR_MOTION(20)) / PARC_RNDR_MOTION(21);
 if (fade > 1.0) fade = 1.0;
 else if (fade < 0.0) fade = 0.0;
 if (fogrange == 0.0) fog = 0.0;
 else
  {
  fog = (el - PARC_RNDR_MOTION(23)) / fogrange;
  if (fog > 1.0) fog = 1.0;
  else if (fog < 0.0) fog = 0.0;
  } /* else */

/* if surface */

 if (MapAsSFC)
  {
  short range;
  double gradfact;

  if (settings.reliefshade || (render & 0x01))
   {
   FloatCol = 8.0 + 7.99 * sunfactor + ROUNDING_KLUDGE;
   ColMax = COL_SFC_MAX;
   } /* if shading by sun angle */
  if ((! settings.reliefshade) || (render & 0x01))
   {
   if (el < settings.surfel[1])
    {
    gradfact = ((double)settings.surfel[1] - el)
	 / (settings.surfel[1] - settings.surfel[0]);
    range = 0;
    } /* low gradient */
   else if (el >= settings.surfel[1] && el < settings.surfel[2])
    {
    gradfact = ((double)settings.surfel[2] - el)
	 / (settings.surfel[2] - settings.surfel[1]);
    range = 1;
    } /* else if middle gradient */
   else
    {
    gradfact = ((double)settings.surfel[3] - el)
	 / (settings.surfel[3] - settings.surfel[2]);
    range = 2;
    } /* else upper gradient */
   if (gradfact > 1.0) gradfact = 1.0;
   else if (gradfact < 0.0) gradfact = 0.0;
   FloatCol = 8.0 + 7.99 * gradfact + ROUNDING_KLUDGE;
   ColMax = COL_SFC_MAX;
   } /* if */

  if (render & 0x01)
   {
   switch (range)
    {
    case 0:
     {
     CC[0].Red = PARC_RNDR_COLOR(7, 0);
     CC[0].Red += (PARC_RNDR_COLOR(6, 0) - CC[0].Red) * gradfact;
     CC[0].Grn = PARC_RNDR_COLOR(7, 1);
     CC[0].Grn += (PARC_RNDR_COLOR(6, 1) - CC[0].Grn) * gradfact;
     CC[0].Blu = PARC_RNDR_COLOR(7, 2);
     CC[0].Blu += (PARC_RNDR_COLOR(6, 2) - CC[0].Blu) * gradfact;
     break;
     } /* low range */
    case 1:
     {
     CC[0].Red = PARC_RNDR_COLOR(8, 0);
     CC[0].Red += (PARC_RNDR_COLOR(7, 0) - CC[0].Red) * gradfact;
     CC[0].Grn = PARC_RNDR_COLOR(8, 1);
     CC[0].Grn += (PARC_RNDR_COLOR(7, 1) - CC[0].Grn) * gradfact;
     CC[0].Blu = PARC_RNDR_COLOR(8, 2);
     CC[0].Blu += (PARC_RNDR_COLOR(7, 2) - CC[0].Blu) * gradfact;
     break;
     } /* middle range */
    case 2:
     {
     CC[0].Red = PARC_RNDR_COLOR(9, 0);
     CC[0].Red += (PARC_RNDR_COLOR(8, 0) - CC[0].Red) * gradfact;
     CC[0].Grn = PARC_RNDR_COLOR(9, 1);
     CC[0].Grn += (PARC_RNDR_COLOR(8, 1) - CC[0].Grn) * gradfact;
     CC[0].Blu = PARC_RNDR_COLOR(9, 2);
     CC[0].Blu += (PARC_RNDR_COLOR(8, 2) - CC[0].Blu) * gradfact;
     break;
     } /* high range */
    } /* switch color range */
   CC[0].Red -= CC[0].Red * sunshade;
   CC[0].Grn -= CC[0].Grn * sunshade;
   CC[0].Blu -= CC[0].Blu * sunshade;
   } /* if render to RGB */

  eco = understory = 50;

  goto EndDrawFace;
  } /* if surface */

/* compute the shading factors for normal (not water) ecosystems */

 relfactor = relel + 100.0 * random;

/* see if there is snow on the ground */

 snowline = PARC_RNDRLN_ECO(1) +
	diplong * PARC_SKLN_ECO(1) + diplat * PARC_SKLT_ECO(1)
        + PARC_RNDRRE_ECO(1) * relfactor;
 if (settings.worldmap)
  snowline -= ((abs(facelat) - abs(settings.globreflat)) * settings.globecograd);
 if (settings.flatteneco)
  snowline += ( (PARC_RNDR_MOTION(13) - snowline) * PARC_RNDR_MOTION(12) );

 if (el >= snowline)
  {
  if (slope >= PARC_MNSL_ECO(1) && slope <= PARC_MXSL_ECO(1))
   {
   if (relfactor >= PARC_RNDRNR_ECO(1)
		&& relfactor <= PARC_RNDRXR_ECO(1))
    {
    FloatCol = 1.0 + 4.99 * sunfactor;
    ColMax = COL_SNOW_MAX;
    CC[0].Red  = PARC_MCOL_ECO(1, 0);
    CC[0].Red -= pow(sunshade, 3.3) * CC[0].Red * PARC_RNDR_MOTION(22);
    CC[0].Grn  = PARC_MCOL_ECO(1, 1);
    CC[0].Grn -= pow(sunshade, 3.4) * CC[0].Grn * PARC_RNDR_MOTION(22);
    CC[0].Blu  = PARC_MCOL_ECO(1, 2);
    CC[0].Blu -= pow(sunshade, 3.8) * CC[0].Blu * PARC_RNDR_MOTION(22);
    } /* if relel matchup */
   else notsnow = 1;
   } /* if slope matchup */
  else notsnow = 1;
  } /* if el > snowline */
 else notsnow = 1;

/* We'll add some randomness to our colors for other than snow.
** Since "random" varies from -.1 to +.1, this will give us a variation of
** ±20 */

 switch (dir)
  {
  case 0:
   redrand = random * 200.0;
   greenrand = random * 200.0;
   bluerand = 0;
   break;
  case 1:
   redrand = 0;
   greenrand = random * 200.0;
   bluerand = random * 200.0;
   break;
  case 2:
   redrand = random * 200.0;
   greenrand = 0;
   bluerand = random * 200.0;
   break;
  case 3:
   redrand = 0;
   greenrand = random * 200.0;
   bluerand = 0;
   break;
  } /* switch */

/* if below water level, make it wet */

 if (MakeWater || el <= SeaLevel)
  {
  eco = WaterEco_Set(MakeWater, CC);
  understory = PAR_UNDER_ECO(eco);
  ecocount[eco] ++;
  goto EndDrawFace;
  } /* if make water */

/* Do the colormap thing. If it finds a result >= 0, we're outa here! */

 if (cmap)
  {
  if ((eco = colormap(map, notsnow, CC, &understory)) >= 0)
   {
   ecocount[eco] ++;
   goto EndDrawFace;
   }
  } /* if cmap */

/* We now know whether there is snow on the ground and that this is not
** a color-mapped polygon. Now search for an ecosystem match between
** the physical terrain conditions and the ecosystem parameter list */

 for (eco=12; eco<ECOPARAMS; eco++)
  {
  ecoline = PARC_RNDRLN_ECO(eco) +
	diplong * PARC_SKLN_ECO(eco) + diplat * PARC_SKLT_ECO(eco)
        + PARC_RNDRRE_ECO(eco) * relfactor;
  if (settings.worldmap)
   ecoline -= ((abs(facelat) - abs(settings.globreflat)) * settings.globecograd);
  if (settings.flatteneco)
   ecoline += ( (PARC_RNDR_MOTION(13) - ecoline) * PARC_RNDR_MOTION(12) );

  if (el <= ecoline)
   {
   if (slope >= PARC_MNSL_ECO(eco) && slope <= PARC_MXSL_ECO(eco))
    {
    if (relfactor >= PARC_RNDRNR_ECO(eco) &&
		relfactor <= PARC_RNDRXR_ECO(eco))
     {
     understory = ecoset(eco, notsnow, CC);
     break;
     } /* if relel matchup */
    } /* if slope matchup */
   } /* if elevation matchup */
  } /* for eco=12... */

 if (eco >= ECOPARAMS)
  {
  Log(WNG_ILL_VAL, "Ecosystem out of range.");
  eco = settings.defaulteco;
  understory = ecoset(eco, notsnow, CC);
  } /* if */
 ecocount[eco] ++;

/* Now hopefully, we have colors in all the CC arrays we need:
** CC[0] = the color of the bare ground (the understory's understory color
**  unless there is snow).
** CC[1] = the understory texture color (only used if "undertreedraw"
**  is 1 or more. It could be trees or rock texture, grass or whatever.
** CC[2] = the overstory color if there are trees or textures in the overstory.
**  If the understory and overstory are the same ecosystem, this one will not
**  be drawn since it would be rather redundant.
** We will now draw the plain polygon, unadorned by any bitmapped textures.
**  If the ecosystem understory class is strata rock then the polygons will
**  be given the strata treatment.
*/

EndDrawFace:

 if (Visible)
  {
  if (render & 0x100)
   {
   long ct;

   QC.compval1 = (long)(min(el, 32767.0)) * 65536 + eco * 256 + understory;
   ct = aspect < 0.0 ? 0: aspect * PiUnder180 - 90.0;
   if (ct < 0) ct  += 360;
   QC.compval2 = ((long)relfactor + 1000) * 65536 + ct;
   QC.compval3 = (short)(slope * PiUnder180) * 256 + (short)(sunangle * PiUnder180);
   } /* if render to QC buffer */

  if (render & 0x01)
   {
   CC[3].Red = sunshade * PARC_RNDR_COLOR(1, 0);	/* ambient pre-calc */
   CC[3].Grn = sunshade * PARC_RNDR_COLOR(1, 1);
   CC[3].Blu = sunshade * PARC_RNDR_COLOR(1, 2);
/* This is now done on a pixel basis to facilitate texture mapping
   CC[0].Red += sunshade * PARC_RNDR_COLOR(1, 0);	/* ambient */
   CC[0].Grn += sunshade * PARC_RNDR_COLOR(1, 1);
   CC[0].Blu += sunshade * PARC_RNDR_COLOR(1, 2);
   CC[0].Red += (PARC_RNDR_COLOR(2, 0) - CC[0].Red) * fade;
   CC[0].Red += (PARC_RNDR_COLOR(2, 0) - CC[0].Red) * fog;
   CC[0].Red *= redsun; 
   CC[0].Grn += (PARC_RNDR_COLOR(2, 1) - CC[0].Grn) * fade;
   CC[0].Grn += (PARC_RNDR_COLOR(2, 1) - CC[0].Grn) * fog;
   CC[0].Grn *= greensun;
   CC[0].Blu += (PARC_RNDR_COLOR(2, 2) - CC[0].Blu) * fade;
   CC[0].Blu += (PARC_RNDR_COLOR(2, 2) - CC[0].Blu) * fog;
   CC[0].Blu *= bluesun;
   if (CC[0].Red > 255) red = 255;
   else red = (CC[0].Red < 0) ? 0: CC[0].Red;
   if (CC[0].Grn > 255) green = 255;
   else  green = CC[0].Grn < 0 ? 0: CC[0].Grn;
   if (CC[0].Blu > 255) blue = 255;
   else blue = CC[0].Blu < 0 ? 0: CC[0].Blu;
*/
   } /* if render to RGB */

/* determine which poly corner is largest and smallest along x axis */

/* temporary switch - should also be enabled in settings editor */

  Texture = PAR_TYPE_ECO(PAR_UNDER_ECO(understory));
  if (! MapAsSFC)
   {
   if (((Texture & 0x00ff) >= 100)
   	&& ((Texture & 0x00ff) < 150)
	&& (PARC_RNDRDN_ECO(PAR_UNDER_ECO(understory)) > treerand2 * 100.0))	/* if procedural texture */
    VolumeTexture = 1;
   }

  if (polyx[b][2] > polyx[b][0])
   {
   if (polyx[b][2] > polyx[b][1])
    {
    PolyMaxXPt = 2;
    PolyMinXPt = polyx[b][1] < polyx[b][0] ? 1: 0;
    } /* if */
   else
    {
    PolyMaxXPt = 1;
    PolyMinXPt = polyx[b][2] < polyx[b][0] ? 2: 0;
    } /* else */
   } /* if */
  else
   {
   if (polyx[b][0] > polyx[b][1])
    {
    PolyMaxXPt = 0;
    PolyMinXPt = polyx[b][2] < polyx[b][1] ? 2: 1;
    } /* if */
   else
    {
    PolyMaxXPt = 1;
    PolyMinXPt = polyx[b][2] < polyx[b][0] ? 2: 0;
    } /* else */
   } /* else */

  if (polyy[b][0] < 0.0) yy[0] --;
  if (polyy[b][1] < 0.0) yy[1] --;
  if (polyy[b][2] < 0.0) yy[2] --;
  if (polyx[b][0] < 0.0) xx[0] --;
  if (polyx[b][1] < 0.0) xx[1] --;
  if (polyx[b][2] < 0.0) xx[2] --;

  MinX = xx[PolyMinXPt];
  MaxX = xx[PolyMaxXPt];

  if (MaxX < 0 || MinX > wide || yy[0] > high || yy[2] < 0)
   goto DrawTrees;

  SubPixWidth = 10 * (1 + MaxX - MinX);
  SubPixHeight = 10 * (1 + yy[2] - yy[0]);
  NewSubPixArraySize = SubPixWidth * SubPixHeight;
  if (NewSubPixArraySize > SubPixArraySize)
   {
   free_Memory(SubPix, SubPixArraySize);
   SubPixArraySize = 0;
   if ((SubPix = get_Memory(NewSubPixArraySize, MEMF_CLEAR)) == NULL)
    {
    NoAlias = 1;
    }
   else
    {
    SubPixArraySize = NewSubPixArraySize;
    }
   } /* if need larger array */
  else
   {
   memset(SubPix, 0, NewSubPixArraySize);
   } /* else clear as much of array as needed */
  if (EdgeSize < SubPixHeight * sizeof (short))
   {
   free_Memory(Edge1, EdgeSize);
   free_Memory(Edge2, EdgeSize);
   EdgeSize = 0;
   Edge1 = (short *)get_Memory(SubPixHeight * sizeof (short), MEMF_CLEAR);
   Edge2 = (short *)get_Memory(SubPixHeight * sizeof (short), MEMF_CLEAR);
   if (! Edge1 || ! Edge2)
    {
    NoAlias = 1;
    }
   else
    {
    EdgeSize = SubPixHeight * sizeof (short);
    }
   } /* if need new edge arrays */

  if (! NoAlias)
   {
   AAX[0] = 10.0 * (polyx[b][0] - MinX);
   AAX[1] = 10.0 * (polyx[b][1] - MinX);
   AAY[0] = 10.0 * (polyy[b][0] - yy[0]);
   AAY[1] = 10.0 * (polyy[b][1] - yy[0]);
   AAY[2] = 10.0 * (polyy[b][2] - yy[0]);

   if (polyy[b][0] == polyy[b][2]) m = 0.0;
   else m = (polyx[b][2] - polyx[b][0]) / (polyy[b][2] - polyy[b][0]);
   StartY = AAY[0] - (int)AAY[0] < .5 ? (int)AAY[0]: 1 + (int)AAY[0];
   EndY =   AAY[2] - (int)AAY[2] > .5 ? (int)AAY[2]: (int)AAY[2] - 1;
   Xoffset = AAX[0] + (StartY + .5 - AAY[0]) * m;

   for (y=StartY; y<=EndY; y++)
    {
    Edge1[y] = (int)Xoffset;
    Xoffset += m;
    }

   if (polyy[b][0] == polyy[b][1]) m = 0.0;
   else m = (polyx[b][1] - polyx[b][0]) / (polyy[b][1] - polyy[b][0]);
   EndY =   AAY[1] - (int)AAY[1] > .5 ? (int)AAY[1]: (int)AAY[1] - 1;
   Xoffset = AAX[0] + (StartY + .5 - AAY[0]) * m;

   for (y=StartY; y<=EndY; y++)
    {
    Edge2[y] = (int)Xoffset;
    Xoffset += m;
    }

   PixPtr = &SubPix[StartY * SubPixWidth];
   for (y=StartY; y<=EndY; y++)
    {
    if (Edge2[y] >= Edge1[y])
     {
     for (x=Edge1[y]; x<=Edge2[y]; x++)
      {
      PixPtr[x] = 0x01;
      }
     }
    else
     {
     for (x=Edge2[y]; x<=Edge1[y]; x++)
      {
      PixPtr[x] = 0x01;
      }
     }
    PixPtr += SubPixWidth;
    }

   if (polyy[b][2] == polyy[b][1]) m = 0.0;
   else m = (polyx[b][2] - polyx[b][1]) / (polyy[b][2] - polyy[b][1]);
   StartY = AAY[1] - (int)AAY[1] < .5 ? (int)AAY[1]: 1 + (int)AAY[1];
   EndY =   AAY[2] - (int)AAY[2] > .5 ? (int)AAY[2]: (int)AAY[2] - 1;
   Xoffset = AAX[1] + (StartY + .5 - AAY[1]) * m;

   for (y=StartY; y<=EndY; y++)
    {
    Edge2[y] = (int)Xoffset;
    Xoffset += m;
    }

   PixPtr = &SubPix[StartY * SubPixWidth];
   for (y=StartY; y<=EndY; y++)
    {
    if (Edge2[y] >= Edge1[y])
     {
     for (x=Edge1[y]; x<=Edge2[y]; x++)
      {
      PixPtr[x] = 0x01;
      }
     }
    else
     {
     for (x=Edge2[y]; x<=Edge1[y]; x++)
      {
      PixPtr[x] = 0x01;
      }
     }
    PixPtr += SubPixWidth;
    }

/* figure x and y gradients across polygon for lat, lon, Z and elev */

/* latitude */

   if (polylat[b][2] > polylat[b][0])
    {
    if (polylat[b][2] > polylat[b][1])
     {
     MaxPt = 2;
     MinPt = polylat[b][1] < polylat[b][0] ? 1: 0;
     MidPt = MinPt == 1 ? 0: 1;
     } /* if */
    else
     {
     MaxPt = 1;
     MinPt = polylat[b][2] < polylat[b][0] ? 2: 0;
     MidPt = MinPt == 2 ? 0: 2;
     } /* else */
    } /* if */
   else
    {
    if (polylat[b][0] > polylat[b][1])
     {
     MaxPt = 0;
     MinPt = polylat[b][2] < polylat[b][1] ? 2: 1;
     MidPt = MinPt == 2 ? 1: 2;
     } /* if */
    else
     {
     MaxPt = 1;
     MinPt = polylat[b][2] < polylat[b][0] ? 2: 0;
     MidPt = MinPt == 2 ? 0: 2;
     } /* else */
    } /* else */

   if (polylat[b][MaxPt] == polylat[b][MinPt])
    {
    LatX = 0.0;
    LatY = 0.0;
    } /* that was easy */
   else
    {
    Temp = (polylat[b][MidPt] - polylat[b][MinPt]) /
	(polylat[b][MaxPt] - polylat[b][MinPt]);
    X5 = Temp * (polyx[b][MaxPt] - polyx[b][MinPt]) + polyx[b][MinPt];
    Y5 = Temp * (polyy[b][MaxPt] - polyy[b][MinPt]) + polyy[b][MinPt];
    if (polyy[b][MaxPt] == polyy[b][MinPt])
     {
     LatY = LatX = 0.0;
     LatStart = facelat;
     goto StartLon;
/*    X3 = Y4 = infinity;*/
     } /* if */
    X3 = polyx[b][MinPt] + (polyy[b][MidPt] - polyy[b][MinPt]) *
	(polyx[b][MaxPt] - polyx[b][MinPt]) /
	(polyy[b][MaxPt] - polyy[b][MinPt]);
    if (X5 == polyx[b][MidPt])
     {
     LatY = LatX = 0.0;
     LatStart = facelat;
     goto StartLon;
/*    Y4 = infinity;*/
     } /* if */
    Y4 = polyy[b][MidPt] + (X3 - polyx[b][MidPt]) *
	(Y5 - polyy[b][MidPt]) / (X5 - polyx[b][MidPt]);
    if (polyx[b][MaxPt] != polyx[b][MinPt])
     El3 = polylat[b][MinPt] + (X3 - polyx[b][MinPt]) *
	(polylat[b][MaxPt] - polylat[b][MinPt]) /
	(polyx[b][MaxPt] - polyx[b][MinPt]);
    else if (polyy[b][MaxPt] != polyy[b][MinPt])
     El3 = polylat[b][MinPt] + (polyy[b][MidPt] - polyy[b][MinPt]) *
	(polylat[b][MaxPt] - polylat[b][MinPt]) /
	(polyy[b][MaxPt] - polyy[b][MinPt]);
    else
     {
     LatY = LatX = 0.0;
     LatStart = facelat;
     goto StartLon;
     } /* else */

    if (X3 != polyx[b][MidPt] && Y4 != polyy[b][MidPt])
     {
     LatX = (El3 - polylat[b][MidPt]) / (X3 - polyx[b][MidPt]);
     LatY = (El3 - polylat[b][MidPt]) / (polyy[b][MidPt] - Y4);
     } /* if */
    else
     {
     LatY = LatX = 0.0;
     LatStart = facelat;
     goto StartLon;
     } /* else */
    } /* else not so easy */
   LatStart = polylat[b][MidPt] + (polyx[b][PolyMinXPt] - polyx[b][MidPt])
	 * LatX;
   LatStart += (polyy[b][0] - polyy[b][MidPt]) * LatY;

/* longitude */

StartLon:

   if (polylon[b][2] > polylon[b][0])
    {
    if (polylon[b][2] > polylon[b][1])
     {
     MaxPt = 2;
     MinPt = polylon[b][1] < polylon[b][0] ? 1: 0;
     MidPt = MinPt == 1 ? 0: 1;
     } /* if */
    else
     {
     MaxPt = 1;
     MinPt = polylon[b][2] < polylon[b][0] ? 2: 0;
     MidPt = MinPt == 2 ? 0: 2;
     } /* else */
    } /* if */
   else
    {
    if (polylon[b][0] > polylon[b][1])
     {
     MaxPt = 0;
     MinPt = polylon[b][2] < polylon[b][1] ? 2: 1;
     MidPt = MinPt == 2 ? 1: 2;
     } /* if */
    else
     {
     MaxPt = 1;
     MinPt = polylon[b][2] < polylon[b][0] ? 2: 0;
     MidPt = MinPt == 2 ? 0: 2;
     } /* else */
    } /* else */

   if (polylon[b][MaxPt] == polylon[b][MinPt])
    {
    LonX = 0.0;
    LonY = 0.0;
    } /* that was easy */
   else
    {
    Temp = (polylon[b][MidPt] - polylon[b][MinPt]) /
	(polylon[b][MaxPt] - polylon[b][MinPt]);
    X5 = Temp * (polyx[b][MaxPt] - polyx[b][MinPt]) + polyx[b][MinPt];
    Y5 = Temp * (polyy[b][MaxPt] - polyy[b][MinPt]) + polyy[b][MinPt];
    if (polyy[b][MaxPt] == polyy[b][MinPt])
     {
     LonY = LonX = 0.0;
     LonStart = facelong;
     goto StartZ;
/*    X3 = Y4 = infinity;*/
     } /* if */
    X3 = polyx[b][MinPt] + (polyy[b][MidPt] - polyy[b][MinPt]) *
	(polyx[b][MaxPt] - polyx[b][MinPt]) /
	(polyy[b][MaxPt] - polyy[b][MinPt]);
    if (X5 == polyx[b][MidPt])
     {
     LonY = LonX = 0.0;
     LonStart = facelong;
     goto StartZ;
/*    Y4 = infinity;*/
     } /* if */
    Y4 = polyy[b][MidPt] + (X3 - polyx[b][MidPt]) *
	(Y5 - polyy[b][MidPt]) / (X5 - polyx[b][MidPt]);
    if (polyx[b][MaxPt] != polyx[b][MinPt])
     El3 = polylon[b][MinPt] + (X3 - polyx[b][MinPt]) *
	(polylon[b][MaxPt] - polylon[b][MinPt]) /
	(polyx[b][MaxPt] - polyx[b][MinPt]);
    else if (polyy[b][MaxPt] != polyy[b][MinPt])
     El3 = polylon[b][MinPt] + (polyy[b][MidPt] - polyy[b][MinPt]) *
	(polylon[b][MaxPt] - polylon[b][MinPt]) /
	(polyy[b][MaxPt] - polyy[b][MinPt]);
    else
     {
     LonY = LonX = 0.0;
     LonStart = facelong;
     goto StartZ;
     } /* else */

    if (X3 != polyx[b][MidPt] && Y4 != polyy[b][MidPt])
     {
     LonX = (El3 - polylon[b][MidPt]) / (X3 - polyx[b][MidPt]);
     LonY = (El3 - polylon[b][MidPt]) / (polyy[b][MidPt] - Y4);
     } /* if */
    else
     {
     LonY = LonX = 0.0;
     LonStart = facelong;
     goto StartZ;
     } /* else */
    } /* else not so easy */
   LonStart = polylon[b][MidPt] + (polyx[b][PolyMinXPt] - polyx[b][MidPt])
	* LonX;
   LonStart += (polyy[b][0] - polyy[b][MidPt]) * LonY;

StartZ:

/* z buffer */

   if (polyq[b][2] > polyq[b][0])
    {
    if (polyq[b][2] > polyq[b][1])
     {
     MaxQPt = 2;
     MinQPt = polyq[b][1] < polyq[b][0] ? 1: 0;
     MidPt = MinQPt == 1 ? 0: 1;
     } /* if */
    else
     {
     MaxQPt = 1;
     MinQPt = polyq[b][2] < polyq[b][0] ? 2: 0;
     MidPt = MinQPt == 2 ? 0: 2;
     } /* else */
    } /* if */
   else
    {
    if (polyq[b][0] > polyq[b][1])
     {
     MaxQPt = 0;
     MinQPt = polyq[b][2] < polyq[b][1] ? 2: 1;
     MidPt = MinQPt == 2 ? 1: 2;
     } /* if */
    else
     {
     MaxQPt = 1;
     MinQPt = polyq[b][2] < polyq[b][0] ? 2: 0;
     MidPt = MinQPt == 2 ? 0: 2;
     } /* else */
    } /* else */

   if (polyq[b][MaxQPt] == polyq[b][MinQPt])
    {
    QX = 0.0;
    QY = 0.0;
    } /* that was easy */
   else
    {
    Temp = (polyq[b][MidPt] - polyq[b][MinQPt]) /
	(polyq[b][MaxQPt] - polyq[b][MinQPt]);
    X5 = Temp * (polyx[b][MaxQPt] - polyx[b][MinQPt]) + polyx[b][MinQPt];
    Y5 = Temp * (polyy[b][MaxQPt] - polyy[b][MinQPt]) + polyy[b][MinQPt];
    if (polyy[b][MaxQPt] == polyy[b][MinQPt])
     {
     QInterp = 0;
     QY = QX = 0.0;
     QStart = qqq;
     goto StartEl;
/*    X3 = Y4 = infinity;*/
     } /* if */
    X3 = polyx[b][MinQPt] + (polyy[b][MidPt] - polyy[b][MinQPt]) *
	(polyx[b][MaxQPt] - polyx[b][MinQPt]) /
	(polyy[b][MaxQPt] - polyy[b][MinQPt]);
    if (X5 == polyx[b][MidPt])
     {
     QInterp = 0;
     QY = QX = 0.0;
     QStart = qqq;
     goto StartEl;
/*    Y4 = infinity;*/
     } /* if */
    Y4 = polyy[b][MidPt] + (X3 - polyx[b][MidPt]) *
	(Y5 - polyy[b][MidPt]) / (X5 - polyx[b][MidPt]);
    if (polyx[b][MaxQPt] != polyx[b][MinQPt])
     El3 = polyq[b][MinQPt] + (X3 - polyx[b][MinQPt]) *
	(polyq[b][MaxQPt] - polyq[b][MinQPt]) /
	(polyx[b][MaxQPt] - polyx[b][MinQPt]);
    else if (polyy[b][MaxQPt] != polyy[b][MinQPt])
     El3 = polyq[b][MinQPt] + (polyy[b][MidPt] - polyy[b][MinQPt]) *
	(polyq[b][MaxQPt] - polyq[b][MinQPt]) /
	(polyy[b][MaxQPt] - polyy[b][MinQPt]);
    else
     {
     QInterp = 0;
     QY = QX = 0.0;
     QStart = qqq;
     goto StartEl;
     } /* else */

    if (X3 != polyx[b][MidPt] && Y4 != polyy[b][MidPt])
     {
     QX = (El3 - polyq[b][MidPt]) / (X3 - polyx[b][MidPt]);
     QY = (El3 - polyq[b][MidPt]) / (polyy[b][MidPt] - Y4);
     } /* if */
    else
     {
     QInterp = 0;
     QY = QX = 0.0;
     QStart = qqq;
     goto StartEl;
     } /* else */
    } /* else not so easy */
   QStart = polyq[b][MidPt] + (polyx[b][PolyMinXPt] - polyx[b][MidPt])
	* QX;
   QStart += (polyy[b][0] - polyy[b][MidPt]) * QY;

/* elevation */

StartEl:

   if (Elev[2] > Elev[0])
    {
    if (Elev[2] > Elev[1])
     {
     MaxPt = 2;
     MinPt = Elev[1] < Elev[0] ? 1: 0;
     MidPt = MinPt == 1 ? 0: 1;
     } /* if */
    else
     {
     MaxPt = 1;
     MinPt = Elev[2] < Elev[0] ? 2: 0;
     MidPt = MinPt == 2 ? 0: 2;
     } /* else */
    } /* if */
   else
    {
    if (Elev[0] > Elev[1])
     {
     MaxPt = 0;
     MinPt = Elev[2] < Elev[1] ? 2: 1;
     MidPt = MinPt == 2 ? 1: 2;
     } /* if */
    else
     {
     MaxPt = 1;
     MinPt = Elev[2] < Elev[0] ? 2: 0;
     MidPt = MinPt == 2 ? 0: 2;
     } /* else */
    } /* else */

   if (Elev[MaxPt] == Elev[MinPt])
    {
    ElX = 0.0;
    ElY = 0.0;
    } /* that was easy */
   else
    {
    Temp = (Elev[MidPt] - Elev[MinPt]) /
	(Elev[MaxPt] - Elev[MinPt]);
    X5 = Temp * (polyx[b][MaxPt] - polyx[b][MinPt]) + polyx[b][MinPt];
    Y5 = Temp * (polyy[b][MaxPt] - polyy[b][MinPt]) + polyy[b][MinPt];
    if (polyy[b][MaxPt] == polyy[b][MinPt])
     {
     ElInterp = 0;
     ElY = ElX = 0.0;
     ElStart = el;
     goto StartDraw;
/*    X3 = Y4 = infinity;*/
     } /* if */
    X3 = polyx[b][MinPt] + (polyy[b][MidPt] - polyy[b][MinPt]) *
	(polyx[b][MaxPt] - polyx[b][MinPt]) /
	(polyy[b][MaxPt] - polyy[b][MinPt]);
    if (X5 == polyx[b][MidPt])
     {
     ElInterp = 0;
     ElY = ElX = 0.0;
     ElStart = el;
     goto StartDraw;
/*    Y4 = infinity;*/
     } /* if */
    Y4 = polyy[b][MidPt] + (X3 - polyx[b][MidPt]) *
	(Y5 - polyy[b][MidPt]) / (X5 - polyx[b][MidPt]);
    if (polyx[b][MaxPt] != polyx[b][MinPt])
     El3 = Elev[MinPt] + (X3 - polyx[b][MinPt]) *
	(Elev[MaxPt] - Elev[MinPt]) /
	(polyx[b][MaxPt] - polyx[b][MinPt]);
    else if (polyy[b][MaxPt] != polyy[b][MinPt])
     El3 = Elev[MinPt] + (polyy[b][MidPt] - polyy[b][MinPt]) *
	(Elev[MaxPt] - Elev[MinPt]) /
	(polyy[b][MaxPt] - polyy[b][MinPt]);
    else
     {
     ElInterp = 0;
     ElY = ElX = 0.0;
     ElStart = el;
     goto StartDraw;
     } /* else */

    if (X3 != polyx[b][MidPt] && Y4 != polyy[b][MidPt])
     {
     ElX = (El3 - Elev[MidPt]) / (X3 - polyx[b][MidPt]);
     ElY = (El3 - Elev[MidPt]) / (polyy[b][MidPt] - Y4);
     } /* if */
    else
     {
     ElInterp = 0;
     ElY = ElX = 0.0;
     ElStart = el;
     goto StartDraw;
     } /* else */
    } /* else not so easy */
   ElStart = Elev[MidPt] + (polyx[b][PolyMinXPt] - polyx[b][MidPt]) * ElX;
   ElStart += (polyy[b][0] - polyy[b][MidPt]) * ElY;

StartDraw:

   if (QY != 0.0)
    EloQY = .001 * ElY / QY;
   else
    EloQY = 0.0;

   for (y=yy[0], k=0; y<=yy[2]; y++,k++,QStart+=QY,ElStart+=ElY,LatStart+=LatY,LonStart+=LonY)
    {
    if (y < 0) continue;
    if (y > oshigh) break;
    zip = scrnrowzip[y] + MinX;

    for (x=MinX, l=0, QPt=QStart, ElPt=ElStart, LatPt=LatStart, LonPt=LonStart;
	 x<=MaxX; x++, l++, zip++, QPt+=QX, ElPt+=ElX, LatPt+=LatX, LonPt+=LonX)
     {
     if (x < 0)
      continue;
     if (x > wide)
      break;
     dist = *(zbuf + zip);

     if (! QInterp)
      QPt = qqq;
     else
      {
      if (QPt < polyq[b][MinQPt])
       QPt = polyq[b][MinQPt];
      else if (QPt > polyq[b][MaxQPt])
       QPt = polyq[b][MaxQPt];
      } /* else */

     if (! ElInterp)
      ElPt = el;
     else
      {
      if (ElPt < Elev[MinPt])
       ElPt = Elev[MinPt];
      else if (ElPt > Elev[MaxPt])
       ElPt = Elev[MaxPt];
      } /* else */

     if (QPt <= dist + PtrnOffset || (unsigned int)bytemap[zip] < 100)
      {
      sum = 0;
      PixPtr = &SubPix[k * 10 * SubPixWidth + l * 10];
      for (i=0; i<10; i++)
       {
       for (j=0; j<10; j++)
        {
        sum += (unsigned int)PixPtr[j];
        } /* for j=0... */
       PixPtr += SubPixWidth;
       } /* for i=0... */
      if (sum)
       {
       if (render & 0x01)
        {
        /* changed this from ptrnoffset to HalfPtrnOffset 1/2/96 to elliminate
        spider webs */
        if (bytemap[zip] 
		 && (QPt >= dist || ((sum < 100) && (dist - QPt < HalfPtrnOffset))))
         Mode = MODE_AVERAGE;
        else
         Mode = MODE_REPLACE;

        if (VolumeTexture)
         {
         if (Texture & 0x0200)		/* if strata colors */
          {
          Tex = ComputeTextureColor(ElPt, LatPt, LonPt, ElY, &CC[0]);
          CC[0].Red -= sunshade * CC[0].Red;			/* shading */
          CC[0].Grn -= sunshade * CC[0].Grn;
          CC[0].Blu -= sunshade * CC[0].Blu;
	  } /* if */
         else if (Texture & 0x0100)		/* if plain strata */
          {
          Tex = ComputeTexture(ElPt, LatPt, LonPt, ElY);
	  } /* else if */
         else Tex = 255;
/* This is a test - replace with optional fracture texture
         Tex *= ((355 - MakeNoise(NoiseMap, 200, LatPt * 480.0, LonPt * 480.0)) / 255.0);
         if (Tex > 255)
          Tex = 255;
*/
	 } /* if strata */
/*
        else if (NoiseTexture)
         {
         Tex = ((255 - MakeNoise(NoiseMap, 75, LatPt * 480.0, LonPt * 480.0)) / 255.0);
 /*        Tex = ComputeBumpMapTexture(LatPt, LonPt);*/
	 } /* else no strata */
*/
        else
         Tex = 255;

        fred = (Tex * CC[0].Red) / 255.;
        fgrn = (Tex * CC[0].Grn) / 255.;
        fblu = (Tex * CC[0].Blu) / 255.;
        fred += CC[3].Red; /* sunshade * PARC_RNDR_COLOR(1, 0);	ambient */
        fgrn += CC[3].Grn; /* sunshade * PARC_RNDR_COLOR(1, 1); */
        fblu += CC[3].Blu; /* sunshade * PARC_RNDR_COLOR(1, 2); */
        fred += (PARC_RNDR_COLOR(2, 0) - fred) * fade;
        fgrn += (PARC_RNDR_COLOR(2, 1) - fgrn) * fade;
        fblu += (PARC_RNDR_COLOR(2, 2) - fblu) * fade;
        fred += (PARC_RNDR_COLOR(2, 0) - fred) * fog;
        fgrn += (PARC_RNDR_COLOR(2, 1) - fgrn) * fog;
        fblu += (PARC_RNDR_COLOR(2, 2) - fblu) * fog;
        fred *= redsun; 
        fgrn *= greensun;
        fblu *= bluesun;
        if (fred > 255.) fred = 255.;
        else if (fred < 0.) fred = 0.;
        if (fgrn > 255.) fgrn = 255.;
        else  if (fgrn < 0.) fgrn = 0.;
        if (fblu > 255.) fblu = 255.;
        else if (fblu < 0.) fblu = 0.;

        if (Mode)
         {
         if ((unsigned int)bytemap[zip] >= 110)
          continue;	/* added 9/25/95 */
         WtAvg = (unsigned int)bytemap[zip] + sum >= 110 ? 110:
		(unsigned int)bytemap[zip] + sum; /* changed 9/25/95 */
         sum = WtAvg - bytemap[zip];	/* added 9/25/95 */
         colval = (*(bitmap[0] + zip) * (unsigned int)bytemap[zip] + fred * sum)
		 / WtAvg;
         *(bitmap[0] + zip) = (UBYTE)colval;
         colval = (*(bitmap[1] + zip) * (unsigned int)bytemap[zip] + fgrn * sum)
		 / WtAvg;
         *(bitmap[1] + zip) = (UBYTE)colval;
         colval = (*(bitmap[2] + zip) * (unsigned int)bytemap[zip] + fblu * sum)
		 / WtAvg;
         *(bitmap[2] + zip) = (UBYTE)colval;
	 } /* if already a value */
        else
         {
         *(bitmap[0] + zip) = (UBYTE)fred;
         *(bitmap[1] + zip) = (UBYTE)fgrn;
         *(bitmap[2] + zip) = (UBYTE)fblu;
	 } /* else first value */
        } /* if render to bitmaps */

       if (QPt < dist)
        {
        if (render & 0x10)
         {
         if (render & 0x01)
          {
          ScreenPixelPlot(win, bitmap, x + drawoffsetX, y + drawoffsetY, zip);
	  } /* if render to bitmaps */
         else
          {
          NoRGBScreenPixelPlot(win, FloatCol, ColMax, x + drawoffsetX, y + drawoffsetY);
	  } /* else no bitmaps */
         } /* if render to screen */
        if (render & 0x100)
         {
         *(QCmap[0] + zip) = QC.compval1;
         *(QCmap[1] + zip) = QC.compval2;
         *(QCmap[2] + zip) = QC.compval3;
         *(QCcoords[0] + zip) = facelat;
         *(QCcoords[1] + zip) = facelong;
         } /* if render & 0x100 */
        *(zbuf + zip) = QPt;
        if (Reflections && ReflectionMap)
          ReflectionMap[zip] = Reflections;
        if (ElevationMap)
         ElevationMap[zip] = ElPt;
        if (SlopeMap)
         SlopeMap[zip] = EloQY;
        } /* if lower QPt value */
       bytemap[zip] += sum;
       } /* if at least one point */
      } /* if QPt */
     } /* for x=... */
/**
@brief Markers publication for the visualization of the calibration ressult on rviz
@param[in] clouds ball center acquisitions in all sensors
@param[in] lasers position of the sensors
@return vector<visualization_msgs::Marker>
*/
vector<visualization_msgs::Marker> createTargetMarkers(vector<pcl::PointCloud<pcl::PointXYZ> > clouds, vector<geometry_msgs::Pose> lasers, vector<string> deviceNames,
                                                       const vector<double>& RPY, const vector<double>& translation )
{
  tf::Transform t_rpy;
  tf::Quaternion q;

  if (translation.empty() && RPY.empty()) //user does not want to translate/rotate clouds and sensors.
  {
    t_rpy.setOrigin( tf::Vector3 (tfScalar(0), tfScalar(0), tfScalar(0)) ); // no translation is done
    q = tf::createQuaternionFromRPY(0.0, 0.0, 0.0 ); // no rotation
  	t_rpy.setRotation( q );
  }
  else if (translation.empty()) // only rotation given by the user, no translation
  {
    t_rpy.setOrigin( tf::Vector3 (tfScalar(0), tfScalar(0), tfScalar(0)) ); // no translation
    q = tf::createQuaternionFromRPY( RPY[0], RPY[1], RPY[2] ); // quaternion computation from given angles
  	t_rpy.setRotation( q );
  }
  else // rotation and translation given by the user
  {
  	t_rpy.setOrigin( tf::Vector3 (tfScalar(translation[0]), tfScalar(translation[1]), tfScalar(translation[2])) ); // translation given by the user
  	q = tf::createQuaternionFromRPY( RPY[0], RPY[1], RPY[2] ); // quaternion computation from given angles
  	t_rpy.setRotation( q );
  }

  static Markers marker_list;
	int nLasers=lasers.size();
	std::cout << "number of lasers: " << nLasers << std::endl;

	//Reduce the elements status, ADD to REMOVE and REMOVE to delete
	marker_list.decrement();

	// Create a colormap
	class_colormap colormap("hsv", nLasers, 1, false);

	visualization_msgs::Marker marker_centers;
	visualization_msgs::Marker marker_lasers[nLasers*5]; // *5 to make space for Y, Z axis and square that represents the laser

	marker_centers.header.frame_id = "/my_frame3";
	marker_centers.header.stamp = ros::Time::now();

	marker_centers.ns = "centers";
	marker_centers.id = 0;
	marker_centers.action = visualization_msgs::Marker::ADD;

	marker_centers.type = visualization_msgs::Marker::SPHERE_LIST;

	marker_centers.scale.x = 0.08;
	marker_centers.scale.y = 0.08;
	marker_centers.scale.z = 0.08;

  marker_centers.pose.orientation.x=q[0];
	marker_centers.pose.orientation.y=q[1];
	marker_centers.pose.orientation.z=q[2];
	marker_centers.pose.orientation.w=q[3];


	marker_lasers[0].color.a=1;
	marker_lasers[0].color.g=1;
	marker_lasers[1].color.b=1;
	marker_lasers[1].color.a=1;
	marker_lasers[2].color.r=1;
	marker_lasers[2].color.a=1;

	for(int n=0; n<clouds.size(); n++)
	{
		pcl::PointCloud<pcl::PointXYZ> cloud = clouds[n];
		std_msgs::ColorRGBA color;
		color = colormap.color(n);

		for ( int i = 0; i< cloud.points.size(); i++)
		{
			geometry_msgs::Point pt;
			pt.x= cloud.points[i].x;
			pt.y= cloud.points[i].y;
			pt.z= cloud.points[i].z;

			marker_centers.points.push_back(pt);
			marker_centers.colors.push_back(color);


		}         //end for
		marker_list.update(marker_centers);
	}

	//position and orientation of laser
	int counter = 0;
	for(int n=0; n<lasers.size(); n++)
	{
    std::cout << "laser "<< n << std::endl;
		geometry_msgs::Pose laser = lasers[n];
		tf::Transform t_laser;
		t_laser.setOrigin( tf::Vector3(laser.position.x, laser.position.y, laser.position.z) );
		tf::Quaternion q_laser(laser.orientation.x, laser.orientation.y, laser.orientation.z, laser.orientation.w);
		t_laser.setRotation(q_laser);
    std::cout << "laser transform" << std::endl;

		for (int k=0; k<5; k++)
		{
			marker_lasers[counter].header.frame_id = "/my_frame3";
			marker_lasers[counter].header.stamp = ros::Time::now();

			std::stringstream ss;
			ss << "Laser " << n << "Marker: " << k;

			marker_lasers[counter].ns = ss.str();
			marker_lasers[counter].action = visualization_msgs::Marker::ADD;

			std_msgs::ColorRGBA color;

			if (k<3)
			{
				marker_lasers[counter].type = visualization_msgs::Marker::ARROW;

				marker_lasers[counter].scale.x = 0.5;
				marker_lasers[counter].scale.y = 0.05;
				marker_lasers[counter].scale.z = 0.05;

				color.r = 0;
				color.g = 0;
				color.b = 0;
				color.a = 1;
			}
			else if (k == 3)
			{
				marker_lasers[counter].type = visualization_msgs::Marker::CUBE;
				marker_lasers[counter].scale.x = 0.15;
				marker_lasers[counter].scale.y = 0.15;
				marker_lasers[counter].scale.z = 0.15;

			}
			else
			{
				marker_lasers[counter].type = visualization_msgs::Marker::TEXT_VIEW_FACING;
				marker_lasers[counter].text = deviceNames[n];
				marker_lasers[counter].scale.x = 0.15;
				marker_lasers[counter].scale.y = 0.15;
				marker_lasers[counter].scale.z = 0.15;
				std::cout << deviceNames[n] << std::endl;
			}

			tf::Transform t_aux;
			tf::Quaternion q_aux;
			t_aux.setOrigin( tf::Vector3 (tfScalar(0), tfScalar(0), tfScalar(0)) ); // no translation is done

			switch (k) {
			case 0:
			{
				q_aux = tf::createQuaternionFromRPY(0.0, 0.0, 0.0 ); // no rotation->this is the X axis
				color.r = 1.0;
				//std::cout << "2 " << k << " " << q[0] << " " << q[1] << " " << q[2] << " " << q[3] << " " << color << std::endl;
				break;
			}
			case 1:
			{
				q_aux = tf::createQuaternionFromRPY( 0.0, 0.0, M_PI/2 ); // rotation to get Y axis from X
				color.g = 1.0;
				//std::cout << "2 " << k << " " << q[0] << " " << q[1] << " " << q[2] << " " << q[3] << " " << color << std::endl;
				break;
			}
			case 2:
			{
				q_aux = tf::createQuaternionFromRPY( 0.0, -M_PI/2, 0.0); // rotation to get Z axis from X
				color.b = 1.0;
				//std::cout << "2 " << k << " " << q[0] << " " << q[1] << " " << q[2] << " " << q[3] << " " << color << std::endl;
				break;
			}
			case 3:
			{
				q_aux = tf::createQuaternionFromRPY( 0.0, 0.0, 0.0); // no rotation->this is the square at the axes origin that represents the sensor
				color = colormap.color(n);
				//std::cout << "2 " << k << " " << q[0] << " " << q[1] << " " << q[2] << " " << q[3] << " " << color << std::endl;
				break;
			}
			default:
			{
				std::cout << "text" << std::endl;
				q_aux = tf::createQuaternionFromRPY( 0.0, 0.0, 0.0);  // no rotation->this is the square at the axes origin that represents the sensor
				color.r = 1.0;
				color.g = 1.0;
				color.b = 1.0;
				color.a = 1.0;
			}
			}

			t_aux.setRotation( q_aux );

			tf::Transform transform_laser = t_rpy * t_laser * t_aux;
			tf::Quaternion rotation_laser = transform_laser.getRotation();
			tf::Vector3 translation_laser = transform_laser.getOrigin();
      std::cout << "Transformation" << std::endl;
			std::cout << "translation " << translation_laser[0] << " " << translation_laser[1] << " " << translation_laser[2] << std::endl;
			std::cout << "rotation " << rotation_laser[0] << " " << rotation_laser[1] << " " << rotation_laser[2] << " " << rotation_laser[3] << std::endl;

			marker_lasers[counter].pose.position.y=translation_laser[1];
			if (k!=4)
			{
				marker_lasers[counter].pose.position.x=translation_laser[0];
				marker_lasers[counter].pose.position.z=translation_laser[2];
        std::cout << "k!4" << std::endl;
			}
			else
			{
				marker_lasers[counter].pose.position.x=translation_laser[0]+0.15;
				marker_lasers[counter].pose.position.z=translation_laser[2]+0.25;
        std::cout << "text" << std::endl;
			}

			marker_lasers[counter].pose.orientation.x=rotation_laser[0];
			marker_lasers[counter].pose.orientation.y=rotation_laser[1];
			marker_lasers[counter].pose.orientation.z=rotation_laser[2];
			marker_lasers[counter].pose.orientation.w=rotation_laser[3];
      std::cout << "pose" << std::endl;

			marker_lasers[counter].color=color;
      std::cout << "color" << std::endl;

			marker_list.update(marker_lasers[counter]);
      std::cout << "update" << std::endl;
			counter++;
		}
	}
  std::cout << "clean" << std::endl;
	//Remove markers that should not be transmitted
	marker_list.clean();
  std::cout << "finished" << std::endl;
	//Clean the marker_vector and put new markers in it;
	return marker_list.getOutgoingMarkers();

} //end function
/**
@brief Markers publication for the visualization of the calibration ressult on rviz
@param[in] clouds ball center acquisitions in all sensors
@param[in] lasers position of the sensors
@return vector<visualization_msgs::Marker>
*/
vector<visualization_msgs::Marker> createTargetMarkers(vector<pcl::PointCloud<pcl::PointXYZ> > clouds, vector<geometry_msgs::Pose> lasers,
                                                       const vector<double>& RPY, const vector<double>& translation )
{
  tf::Transform t_rpy;
  tf::Quaternion q;

  if (translation.empty() && RPY.empty()) //user does not want to translate/rotate clouds and sensors.
  {
    t_rpy.setOrigin( tf::Vector3 (tfScalar(0), tfScalar(0), tfScalar(0)) ); // no translation is done
    q = tf::createQuaternionFromRPY(0.0, 0.0, 0.0 ); // no rotation
  	t_rpy.setRotation( q );
  }
  else if (translation.empty()) // only rotation given by the user, no translation
  {
    t_rpy.setOrigin( tf::Vector3 (tfScalar(0), tfScalar(0), tfScalar(0)) ); // no translation
    q = tf::createQuaternionFromRPY( RPY[0], RPY[1], RPY[2] ); // quaternion computation from given angles
  	t_rpy.setRotation( q );
  }
  else // rotation and translation given by the user
  {
  	t_rpy.setOrigin( tf::Vector3 (tfScalar(translation[0]), tfScalar(translation[1]), tfScalar(translation[2])) ); // translation given by the user
  	q = tf::createQuaternionFromRPY( RPY[0], RPY[1], RPY[2] ); // quaternion computation from given angles
  	t_rpy.setRotation( q );
  }

	static Markers marker_list;
	int nLasers=lasers.size();

	//Reduce the elements status, ADD to REMOVE and REMOVE to delete
	marker_list.decrement();

	// Create a colormap
	class_colormap colormap("hsv",10, 1, false);

	visualization_msgs::Marker marker_centers;
	visualization_msgs::Marker marker_lasers[nLasers];

	marker_centers.header.frame_id = "/my_frame3";
	marker_centers.header.stamp = ros::Time::now();

	marker_centers.ns = "centers";
	marker_centers.action = visualization_msgs::Marker::ADD;

	marker_centers.type = visualization_msgs::Marker::SPHERE_LIST;

	marker_centers.scale.x = 0.08;
	marker_centers.scale.y = 0.08;
	marker_centers.scale.z = 0.08;

	marker_centers.pose.orientation.x=q[0];
	marker_centers.pose.orientation.y=q[1];
	marker_centers.pose.orientation.z=q[2];
	marker_centers.pose.orientation.w=q[3];

	/*marker_centers.color.b=1;
	   marker_centers.color.a=1;*/
	marker_lasers[0].color.a=1;
	marker_lasers[0].color.g=1;
	marker_lasers[1].color.b=1;
	marker_lasers[1].color.a=1;
	marker_lasers[2].color.r=1;
	marker_lasers[2].color.a=1;

	for(int n=0; n<clouds.size(); n++)
	{
		{
			pcl::PointCloud<pcl::PointXYZ> cloud = clouds[n];
			std_msgs::ColorRGBA color;
			color = colormap.color(n);

			for ( int i = 0; i< cloud.points.size(); i++)
			{
				geometry_msgs::Point pt;
				pt.x= cloud.points[i].x;
				pt.y= cloud.points[i].y;
				pt.z= cloud.points[i].z;

				marker_centers.points.push_back(pt);
				marker_centers.colors.push_back(color);


			} //end for
			marker_list.update(marker_centers);
		}
	}

	//position and orientation of laser
	for(int n=0; n<lasers.size(); n++)
	{
		{
			marker_lasers[n].header.frame_id = "/my_frame3";
			marker_lasers[n].header.stamp = ros::Time::now();

			std::stringstream ss;
			ss << "Laser " << n;

			marker_lasers[n].ns = ss.str();
			marker_lasers[n].action = visualization_msgs::Marker::ADD;

			marker_lasers[n].type = visualization_msgs::Marker::ARROW;

			marker_lasers[n].scale.x = 0.2;
			marker_lasers[n].scale.y = 0.1;
			marker_lasers[n].scale.z = 0.1;

			geometry_msgs::Pose laser = lasers[n];
			std_msgs::ColorRGBA color;

			color = colormap.color(n);

			tf::Transform t_laser;
			t_laser.setOrigin( tf::Vector3(laser.position.x, laser.position.y, laser.position.z) );
			tf::Quaternion q_laser(laser.orientation.x, laser.orientation.y, laser.orientation.z, laser.orientation.w);
			t_laser.setRotation(q_laser);

			t_laser= t_rpy * t_laser;
			q_laser = t_laser.getRotation();
			tf::Vector3 trans_laser = t_laser.getOrigin();

			marker_lasers[n].pose.position.x=trans_laser[0];
			marker_lasers[n].pose.position.y=trans_laser[1];
			marker_lasers[n].pose.position.z=trans_laser[2];

			marker_lasers[n].pose.orientation.x=q_laser[0];
			marker_lasers[n].pose.orientation.y=q_laser[1];
			marker_lasers[n].pose.orientation.z=q_laser[2];
			marker_lasers[n].pose.orientation.w=q_laser[3];

			marker_lasers[n].color=color;

			marker_list.update(marker_lasers[n]);
		}
	}

	//Remove markers that should not be transmitted
	marker_list.clean();

	//Clean the marker_vector and put new markers in it;
	return marker_list.getOutgoingMarkers();

} //end function
Example #17
0
void
Visualization::draw_pyramid_level_flow(const VisualOdometry* odom, int level_num)
{
  const OdometryFrame* ref_frame = odom->getReferenceFrame();
  const OdometryFrame* target_frame = odom->getTargetFrame();
  const PyramidLevel* ref_level = ref_frame->getLevel(level_num);
  const PyramidLevel* target_level = target_frame->getLevel(level_num);

  int width = ref_level->getWidth();
  int height = ref_level->getHeight();

  const MotionEstimator* estimator = odom->getMotionEstimator();
  const FeatureMatch* matches = estimator->getMatches();
  int num_matches = estimator->getNumMatches();

  // current image
  bot_lcmgl_color3f(_lcmgl, 1, 1, 1);
  const uint8_t* target_gray = target_level->getGrayscaleImage();
  int target_gray_stride = target_level->getGrayscaleImageStride();
  int gray_texid = bot_lcmgl_texture2d(_lcmgl, target_gray, width, height,
                                       target_gray_stride, BOT_LCMGL_LUMINANCE,
                                       BOT_LCMGL_UNSIGNED_BYTE,
                                       BOT_LCMGL_COMPRESS_NONE);
  bot_lcmgl_texture_draw_quad(_lcmgl, gray_texid,
      0     , 0      , 0   ,
      0     , height , 0   ,
      width , height , 0   ,
      width , 0      , 0);

  float rgb[3];

#if 0
  // draw target features
  bot_lcmgl_color3f(_lcmgl, 0, 1, 0);
  bot_lcmgl_point_size(_lcmgl, 3.0f);
  bot_lcmgl_begin(_lcmgl, GL_POINTS);
  for(int i=0, nfeatures=target_level->getNumKeypoints(); i<nfeatures; ++i) {
    const KeypointData& kpdata(*target_level->getKeypointData(i));
    colormap(kpdata.xyz.z(), rgb);
    bot_lcmgl_color3f(_lcmgl, rgb[0], rgb[1], rgb[2]);
    bot_lcmgl_vertex2f(_lcmgl, kpdata.kp.u, kpdata.kp.v);
  }
  bot_lcmgl_end(_lcmgl);
#endif

#if 0
  // draw 9x9 boxes around keypoints
  bot_lcmgl_line_width(_lcmgl, 1.0);
  bot_lcmgl_color3f(_lcmgl, .5, .5, 1);
  bot_lcmgl_begin(_lcmgl, GL_LINES);
  for(int i=0, num_kp=target_level->getNumKeypoints();
      i < num_kp;
      ++i) {
    const KeypointData& kpdata(*target_level->getKeypointData(i));
    colormap(kpdata.xyz.z(), rgb);
    bot_lcmgl_color3f(_lcmgl, rgb[0], rgb[1], rgb[2]);

    bot_lcmgl_vertex2f(_lcmgl, kpdata.kp.u-4, kp.v-4);
    bot_lcmgl_vertex2f(_lcmgl, kpdata.kp.u-4, kp.v+4);

    bot_lcmgl_vertex2f(_lcmgl, kpdata.kp.u-4, kp.v+4);
    bot_lcmgl_vertex2f(_lcmgl, kpdata.kp.u+4, kp.v+4);

    bot_lcmgl_vertex2f(_lcmgl, kpdata.kp.u+4, kp.v+4);
    bot_lcmgl_vertex2f(_lcmgl, kpdata.kp.u+4, kp.v-4);

    bot_lcmgl_vertex2f(_lcmgl, kpdata.kp.u+4, kp.v-4);
    bot_lcmgl_vertex2f(_lcmgl, kpdata.kp.u-4, kp.v-4);
  }
  bot_lcmgl_end(_lcmgl);
#endif

#if 1
  // draw inliers
  bot_lcmgl_point_size(_lcmgl, 4.0f);
  bot_lcmgl_begin(_lcmgl, GL_POINTS);
  for (int i=0; i<num_matches; i++) {
    const FeatureMatch& match = matches[i];
    if (!match.inlier ||
        match.target_keypoint->pyramid_level != level_num)
      continue;
    int cur_x = match.target_keypoint->kp.u;
    int cur_y = match.target_keypoint->kp.v;
    colormap(match.target_keypoint->xyz(2), rgb);
    bot_lcmgl_color3f(_lcmgl, rgb[0], rgb[1], rgb[2]);
    bot_lcmgl_vertex2f(_lcmgl, cur_x, cur_y);
  }
  bot_lcmgl_end(_lcmgl);
#endif

#if 1
  // draw ref-to-target 'flow'
  //bot_lcmgl_color3f(_lcmgl, 0, 1, 0);
  bot_lcmgl_line_width(_lcmgl, 2.0f);
  bot_lcmgl_begin(_lcmgl, GL_LINES);
  for (int i=0; i<num_matches; i++) {
    const FeatureMatch& match = matches[i];
    if (!match.inlier ||
        match.target_keypoint->pyramid_level != level_num)
      continue;
    int cur_x = match.target_keypoint->kp.u;
    int cur_y = match.target_keypoint->kp.v;
    int prev_x = match.ref_keypoint->kp.u;
    int prev_y = match.ref_keypoint->kp.v;
    colormap(match.target_keypoint->xyz(2), rgb);
    bot_lcmgl_color3f(_lcmgl, rgb[0], rgb[1], rgb[2]);
    bot_lcmgl_vertex2f(_lcmgl, cur_x, cur_y);
    bot_lcmgl_vertex2f(_lcmgl, prev_x, prev_y);
  }
  bot_lcmgl_end(_lcmgl);
#endif

  if (level_num == 0) {
    //draw the ESM homography estimate
    bot_lcmgl_line_width(_lcmgl, 2.0);
    bot_lcmgl_color3f(_lcmgl, 1, 1, 0);
    bot_lcmgl_begin(_lcmgl, GL_LINE_STRIP);
    const Eigen::Matrix3d & H = odom->getInitialHomography();
    Eigen::MatrixXd vertices(5, 3);
    vertices <<
        0     , 0      , 1,
        width , 0      , 1,
        width , height , 1,
        0     , height , 1,
        0     , 0      , 1;
    Eigen::MatrixXd warpedPoints = H*vertices.transpose();
    warpedPoints.row(0) = warpedPoints.row(0).array()/warpedPoints.row(2).array();
    warpedPoints.row(1) = warpedPoints.row(1).array()/warpedPoints.row(2).array();
    for (int i=0;i<warpedPoints.cols();i++) {
      bot_lcmgl_vertex2f(_lcmgl, warpedPoints(0, i) ,warpedPoints(1, i));
    }
    bot_lcmgl_end(_lcmgl);
  }

}
Example #18
0
RedirectedXCompositeWindow::RedirectedXCompositeWindow(WebPageProxy& webPage, const IntSize& initialSize, std::function<void()>&& damageNotify)
    : m_webPage(webPage)
    , m_display(GDK_DISPLAY_XDISPLAY(gdk_window_get_display(gtk_widget_get_parent_window(webPage.viewWidget()))))
    , m_size(initialSize)
{
    m_size.scale(m_webPage.deviceScaleFactor());

    ASSERT(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native() == m_display);
    Screen* screen = DefaultScreenOfDisplay(m_display);

    GdkVisual* visual = gdk_window_get_visual(gtk_widget_get_parent_window(webPage.viewWidget()));
    XUniqueColormap colormap(XCreateColormap(m_display, RootWindowOfScreen(screen), GDK_VISUAL_XVISUAL(visual), AllocNone));

    // This is based on code from Chromium: src/content/common/gpu/image_transport_surface_linux.cc
    XSetWindowAttributes windowAttributes;
    windowAttributes.override_redirect = True;
    windowAttributes.colormap = colormap.get();

    // CWBorderPixel must be present when the depth doesn't match the parent's one.
    // See http://cgit.freedesktop.org/xorg/xserver/tree/dix/window.c?id=xorg-server-1.16.0#n703.
    windowAttributes.border_pixel = 0;

    m_parentWindow = XCreateWindow(m_display,
        RootWindowOfScreen(screen),
        WidthOfScreen(screen) + 1, 0, 1, 1,
        0,
        gdk_visual_get_depth(visual),
        InputOutput,
        GDK_VISUAL_XVISUAL(visual),
        CWOverrideRedirect | CWColormap | CWBorderPixel,
        &windowAttributes);
    XMapWindow(m_display, m_parentWindow.get());

    windowAttributes.event_mask = StructureNotifyMask;
    windowAttributes.override_redirect = False;
    // Create the window of at last 1x1 since X doesn't allow to create empty windows.
    m_window = XCreateWindow(m_display,
        m_parentWindow.get(),
        0, 0,
        std::max(1, m_size.width()),
        std::max(1, m_size.height()),
        0,
        CopyFromParent,
        InputOutput,
        CopyFromParent,
        CWEventMask,
        &windowAttributes);
    XMapWindow(m_display, m_window.get());

    xDamageNotifier().add(m_window.get(), WTFMove(damageNotify));

    while (1) {
        XEvent event;
        XWindowEvent(m_display, m_window.get(), StructureNotifyMask, &event);
        if (event.type == MapNotify && event.xmap.window == m_window.get())
            break;
    }
    XSelectInput(m_display, m_window.get(), NoEventMask);
    XCompositeRedirectWindow(m_display, m_window.get(), CompositeRedirectManual);
    if (!m_size.isEmpty())
        createNewPixampAndPixampSurface();
    m_damage = XDamageCreate(m_display, m_window.get(), XDamageReportNonEmpty);
}
Example #19
0
void PltWin::drawIt(QPainter *p)
{
  QString txt;
  double x, y, x0, y0, x1, y1, x2, y2, xprev, yprev, shift, ubmin, ubmax, ub, alpha;
  int n, layer, lay, prev_layer, circDia, i, j, at, ichain, a, istart, iend, icurr, xs, ys;
  int idx, nmax;
  bool dum;

  QPen *pen = new QPen();
  QBrush *brush = new QBrush();
  QBrush *brush_unrld = new QBrush();

  // antialiasing of primitives if ANTIALIASE is set to true
  if (!paintEPS) p->setRenderHint(QPainter::Antialiasing, ANTIALIASE);

  // plot the grain boundary line
  if (isGBfile && showGB) {
    x0 = ZFact*xyzMin(1) - xPan - (ZFact-1)*xyzCen(1);
    x1 = ZFact*xyzMax(1) - xPan - (ZFact-1)*xyzCen(1);
    y  = ZFact*gbYcoor - yPan - (ZFact-1)*xyzCen(2);
    DrawLine(p, x0, y, x1, y);
  }

  if (AtomPos==COMPOSITE) {
    if (!paintEPS) {
      brush_unrld->setColor( Qt::lightGray );
      brush_unrld->setStyle( Qt::SolidPattern );
    }
  }

  // plotting of atomic arrangement in the initial configuration
  prev_layer = -1;
  x0 = y0 = x1 = y1 = 0;

  // need to construct the neighbor list in the relaxed configuration
  if (plotType == PLOT_ATOM_NEIGHBORS) {    
    if (AtomPos == UNRELAXED && NeighListInit.data == NULL)
      InitNeighborList(this, NeighListInit, numNeighInit);
    
    if ((AtomPos == RELAXED || AtomPos == COMPOSITE) && NeighListRel.data == NULL)
      RelNeighborList(this, rcut, NeighListRel, numNeighRel);

    if (AtomPos == UNRELAXED) {
      nmax = -1;
      for (at=1; at<=NInit; at++) {
	n = numNeighInit(at);
	if (n > nmax) nmax = n;
      }
      colormap(nmax+1, cmap);
    }

    if (AtomPos == RELAXED) {
      nmax = -1;
      for (at=1; at<=NRel; at++) {
	n = numNeighRel(at);
	if (n > nmax) nmax = n;
      }
      colormap(nmax+1, cmap);
    }
  }

  if (plotType == PLOT_ATOM_TYPES) {
    nmax = -1;
    for (at=1; at<=NInit; at++) {
      n = atomType(at);
      if (n > nmax) nmax = n;
    }
    colormap(nmax, cmap);
  }
  
  //
  //  Plot the atomic configuration such that the atoms in the front (in the top layer) are plotted
  //  at the end.
  //

  for (i=1; i<=NInit; i++) {
    at = aorder(i);
    if (!zLayerSel(zLayer(at)))
      continue;    

    layer = zLayer(at);
    circDia = zDiamLayer(layer);
    
    switch(plotType) {
      case PLOT_ATOM_LAYERS:
	layer = zLayer(at);

	if (!paintEPS && layer != prev_layer) {
	  pen->setColor(zColorLayer(layer, 1));
	  pen->setWidth(zLineThickLayer(layer));
	  p->setPen(*pen);
	  
	  brush->setColor(zColorLayer(layer, 2));
	  brush->setStyle(Qt::SolidPattern);
	  p->setBrush(*brush);
	}
	break;
	
      case PLOT_ATOM_TYPES:
	lay = layer;
	layer = atomType(at);
	
	if (!paintEPS && layer != prev_layer) {
	  pen->setColor(Qt::black);
	  pen->setWidth(zLineThickLayer(lay));
	  p->setPen(*pen);
	  
	  if (layer == 0) {
	    brush->setColor(Qt::lightGray);
	  } else {
	    brush->setColor(cmap[layer-1]);
	  }
	  brush->setStyle(Qt::SolidPattern);
	  p->setBrush(*brush);
	}
	break;

      case PLOT_ATOM_NEIGHBORS:
	lay = layer;
	if (AtomPos == UNRELAXED)
	  layer = numNeighInit(at);
	else if (AtomPos == RELAXED || AtomPos == COMPOSITE)	  
	  layer = numNeighRel(at);

	if (!paintEPS && layer != prev_layer) {
	  pen->setColor(Qt::black);
	  pen->setWidth(zLineThickLayer(lay));
	  p->setPen(*pen);
	  
	  if (layer == 0)
	    brush->setColor(Qt::lightGray);
	  else {
	    brush->setColor(QColor(cmap[layer]));
	  }
	  brush->setStyle(Qt::SolidPattern);
	  p->setBrush(*brush);
	}
	break;
    }
    
    if (layer != prev_layer) prev_layer = layer;

    switch(AtomPos) {
      case UNRELAXED:
        x = ZFact*xyzInit(at,1) - xPan - (ZFact-1)*xyzCen(1);
	y = ZFact*xyzInit(at,2) - yPan - (ZFact-1)*xyzCen(2);
	DrawAtom(p, at, x, y, circDia);	
        break;

      case RELAXED:
	x = ZFact*(xyzInit(at,1) + AtomDispScale*aDisp(at,1)) - xPan - (ZFact-1)*xyzCen(1);
        y = ZFact*(xyzInit(at,2) + AtomDispScale*aDisp(at,2)) - yPan - (ZFact-1)*xyzCen(2);
        DrawAtom(p, at, x, y, circDia);
	break;

      case COMPOSITE:
	if (!paintEPS) { p->setBrush( *brush_unrld ); }
	x = ZFact*xyzInit(at,1) - xPan - (ZFact-1)*xyzCen(1);
	y = ZFact*xyzInit(at,2) - yPan - (ZFact-1)*xyzCen(2);
        DrawAtom(p, -1, x, y, circDia);
        if (!paintEPS) { p->setBrush( *brush ); }
	x = ZFact*(xyzInit(at,1) + AtomDispScale*aDisp(at,1)) - xPan - (ZFact-1)*xyzCen(1);
	y = ZFact*(xyzInit(at,2) + AtomDispScale*aDisp(at,2)) - yPan - (ZFact-1)*xyzCen(2); 
        DrawAtom(p, at, x, y, circDia);
	break;
    }

    if (x < x0) x0 = x;
    if (x > x1) x1 = x;
    if (y < y0) y0 = y;
    if (y > y1) y1 = y;

    // atom numbers
    if (AtomNumbers) {
      txt.sprintf("%d", at);
      shift = circDia/(2.0*factor);
      DrawText(p, x+shift, y+shift, txt);
    }
  }

  // plot the inert atoms
  if (InertAtoms) {
    if (!paintEPS) {
      pen->setColor(Qt::black);
      pen->setWidth(zLineThickLayer(layer));
      p->setPen(*pen);
      
      brush->setColor(Qt::black);
      brush->setStyle(Qt::NoBrush);
      p->setBrush( *brush );
    }
            
    for (at=1; at<=NInert; at++) {
      // plot only those atoms which belong to the selected (active) layers
      //      if (!zLayerSel(zLayer(n)))
      //	continue;
      x = ZFact*xyzInert(at,1) - xPan - (ZFact-1)*xyzCen(1);
      y = ZFact*xyzInert(at,2) - yPan - (ZFact-1)*xyzCen(2);
      DrawAtom(p, 0, x, y, circDia);
    }    
  }

  // highlight the atoms picked
  if (!paintEPS && napicked > 0) {
    pen->setColor(Qt::green);
    pen->setWidth(2);
    p->setPen(*pen);    
    brush->setStyle(Qt::NoBrush);
    p->setBrush(*brush);
    
    dum = ATOM_3DSPHERE;
    ATOM_3DSPHERE = false;
    for (n=1; n<=napicked; n++) {
      at = apicked(n);
      x = ZFact*xyzInit(at,1) - xPan - (ZFact-1)*xyzCen(1);
      y = ZFact*xyzInit(at,2) - yPan - (ZFact-1)*xyzCen(2);
      DrawAtom(p, at, x, y, circDia+4);
      if (n > 1) DrawLine(p, xprev, yprev, x, y);
      xprev = x;
      yprev = y;
    }
    ATOM_3DSPHERE = dum;
  }

  // highlight the atoms in selected chains
  if (!paintEPS && nchain > 0) {
    pen->setColor(Qt::green);
    pen->setWidth(2);
    p->setPen(*pen);

    for (ichain=1; ichain<=nchain; ichain++) {
      for (i=1; i<=nachain(ichain); i++) {
	a = achain(ichain,i);
	x = ZFact*xyzInit(a,1) - xPan - (ZFact-1)*xyzCen(1);
	y = ZFact*xyzInit(a,2) - yPan - (ZFact-1)*xyzCen(2);	
	if (i>1) DrawLine(p, x0, y0, x, y);       
	x0 = x;
	y0 = y;

      }
    }

    if (!paintEPS && nchain >= 2) {
      QPen *pen2 = new QPen();
      pen2->setColor(Qt::green);
      pen2->setStyle(Qt::DashLine);
      p->setPen(*pen2);

      for (i=1; i<nchain; i+=2) {
	x1 = ZFact*dposchain(i,1) - xPan - (ZFact-1)*xyzCen(1);
	y1 = ZFact*dposchain(i,2) - yPan - (ZFact-1)*xyzCen(2);
	x2 = ZFact*dposchain(i+1,1) - xPan - (ZFact-1)*xyzCen(1);
	y2 = ZFact*dposchain(i+1,2) - yPan - (ZFact-1)*xyzCen(2);
	DrawLine(p, x1, y1, x2, y2);
      }
    }
  }

  // plotting the coordinate system centered at the initial position of
  // the dislocation line
  if (PlaneTraces) DrawPlaneTraces(p, x0, y0, x1, y1);

  // plotting of arrows
  if (arrNeighNum > 0) {
    if (!paintEPS) {
      pen->setColor(Qt::black);
      pen->setWidth(thicknessArrow);
      p->setPen(*pen); 
      p->setBrush(Qt::black);
    }
    
    switch(DispComponent) {
      case EDGE:
	plotEdgeComponent(p);
	break;
	
      case SCREW:
	plotScrewComponent(p);
	break;
      
      case PROJ:
	plotScrewComponent(p);   // plotted the same way as screw components
	break;
      
      case DIFF_EDGE:
      case DIFF_SCREW:
	plotDifference(p);
	break;
    }
  }
  
  // position of dislocation center
  if (DisloCenter) {
    DrawLine(p, xCore, y0, xCore, y1);    
    DrawLine(p, x0, yCore, x1, yCore);    
  }

  // small inset to show the active Z-layers
  if (!paintEPS && showZLayers)
    ShowActiveZLayers(p);

  // show color map
  if (!paintEPS && (plotType == PLOT_ATOM_TYPES || plotType == PLOT_ATOM_NEIGHBORS))
    ShowColorMap(p);

  // lines showing the division of the block into cells (for the linked neighbor list)
  if (showNeighCells) {
    if (!paintEPS) {
      pen->setColor(Qt::black);
      p->setPen(*pen);
    }

    for (i=0; i<=ncell(1); i++) {
      x = ZFact*(xyzMin(1)+i*cellsize(1)) - xPan - (ZFact-1)*xyzCen(1);
      y0 = ZFact*xyzMin(2) - yPan - (ZFact-1)*xyzCen(2);
      y1 = ZFact*xyzMax(2) - yPan - (ZFact-1)*xyzCen(2);
      DrawLine(p, x, y0, x, y1);    
      
      for (j=0; j<=ncell(2); j++) {
	y = ZFact*(xyzMin(2)+j*cellsize(2)) - yPan - (ZFact-1)*xyzCen(2);
	x0 = ZFact*xyzMin(1) - xPan - (ZFact-1)*xyzCen(1);
	x1 = ZFact*xyzMax(1) - xPan - (ZFact-1)*xyzCen(1);
	DrawLine(p, x0, y, x1, y);
      }
    }
  }

  // coordinate system of the block
  if (!paintEPS && showCSys)
    ShowCSys(p);

  // show the polygon that encompasses the dislocation center
  if (!paintEPS && ndpoly > 0) {
    pen->setColor(Qt::green);
    p->setPen(*pen);

    for (n=1; n<=ndpoly; n++) {
      x1 = ZFact*dpoly(n,1) - xPan - (ZFact-1)*xyzCen(1);
      y1 = ZFact*dpoly(n,2) - yPan - (ZFact-1)*xyzCen(2);
      if (n<ndpoly) {
	x2 = ZFact*dpoly(n+1,1) - xPan - (ZFact-1)*xyzCen(1);
	y2 = ZFact*dpoly(n+1,2) - yPan - (ZFact-1)*xyzCen(2);
      } else {
	x2 = ZFact*dpoly(1,1) - xPan - (ZFact-1)*xyzCen(1);
	y2 = ZFact*dpoly(1,2) - yPan - (ZFact-1)*xyzCen(2);
      }
      DrawLine(p, x1, y1, x2, y2);
    }
  }

  if (!paintEPS && ndpath > 0) {
    pen->setColor(Qt::green);
    p->setPen(*pen);
    brush->setColor(Qt::green);
    brush->setStyle(Qt::NoBrush);
    p->setBrush(*brush);

    for (n=1; n<ndpath; n++) {
      x1 = ZFact*dpath(n,1) - xPan - (ZFact-1)*xyzCen(1);
      y1 = ZFact*dpath(n,2) - yPan - (ZFact-1)*xyzCen(2);
      x2 = ZFact*dpath(n+1,1) - xPan - (ZFact-1)*xyzCen(1);
      y2 = ZFact*dpath(n+1,2) - yPan - (ZFact-1)*xyzCen(2);
      DrawLine(p, x1, y1, x2, y2);
      if (n==1) {
	xyWorldToScreen(x1, y1, xs, ys);
	xs -= 2;
	ys -= 2;
	p->drawEllipse(xs, ys, 4, 4);
      }
      xyWorldToScreen(x2, y2, xs, ys);
      xs -= 2;
      ys -= 2;
      p->drawEllipse(xs, ys, 4, 4);
    }
  }
}
Example #20
0
void CreateMarkers(vector<visualization_msgs::Marker>& marker_vector,mtt::TargetList& target_msg,vector<t_listPtr>& list)
{
    static map<pair<string,int>, pair<visualization_msgs::Marker,int> > marker_map;
    map<pair<string,int>, pair<visualization_msgs::Marker,int> >::iterator it;


    //limpar o vector todo
    marker_vector.clear();
    //colocar todos os elementos em processo de elemincação
    for(it=marker_map.begin(); it!=marker_map.end(); it++)
        it->second.second--;


    std_msgs::ColorRGBA color;
    class_colormap colormap("hsv",10, 1, false);

    visualization_msgs::Marker marker;

    marker.header.frame_id = pointData.header.frame_id;//target_msg.header.frame_id;
    // 	cout<<"fid:"<<target_msg.header.frame_id<<endl;

    marker.header.stamp = ros::Time::now();
    marker.ns = "ids";
    marker.action = visualization_msgs::Marker::ADD;

    marker.pose.position.z=0.3;

    marker.type = visualization_msgs::Marker::TEXT_VIEW_FACING;

    marker.scale.x = 0.2;
    marker.scale.y = 0.2;
    marker.scale.z = 0.2;

    marker.color.r=0;
    marker.color.g=0;
    marker.color.b=0;
    marker.color.a=1;

    marker.id=0;

    for(uint i=0; i<list.size(); i++)
    {
        if(list[i]->shape.lines.size()!=0)
        {
            marker.pose.position.x=list[i]->position.estimated_x;
            marker.pose.position.y=list[i]->position.estimated_y;

            marker.text = boost::lexical_cast<string>(list[i]->id);

            marker.id++;

            marker_map[make_pair(marker.ns,marker.id) ] = make_pair(marker,1);//isto substitui ou cria o novo marker no map
        }
    }

    marker.pose.position.x=0;
    marker.pose.position.y=0;

    marker.text = "origin";

    marker.id++;

    marker_map[make_pair(marker.ns,marker.id) ] = make_pair(marker,1);//isto substitui ou cria o novo marker no map


    // Markers for Line objects
    marker.type = visualization_msgs::Marker::LINE_STRIP;
    marker.ns = "objects";

    marker.pose.position.x=0;
    marker.pose.position.y=0;
    marker.pose.position.z=0;

    marker.scale.x = 0.02;
    marker.scale.y = 0.1;
    marker.scale.z = 0.1;

    for(uint i=0; i<list.size(); i++)
    {
        marker.color = colormap.color(list[i]->id);

        geometry_msgs::Point p;
        p.z = 0.1;

        marker.points.clear();

        uint l;
        for(l=0; l<list[i]->shape.lines.size(); l++)
        {
            p.x = list[i]->shape.lines[l]->xi;
            p.y = list[i]->shape.lines[l]->yi;

            marker.points.push_back(p);
        }

        p.x = list[i]->shape.lines[l-1]->xf;
        p.y = list[i]->shape.lines[l-1]->yf;

        marker.points.push_back(p);

        marker.id++;

        marker_map[make_pair(marker.ns,marker.id) ] = make_pair(marker,1);//isto substitui ou cria o novo marker no map
    }


    //para o map todo envio tudo, e meto tudo a false
    //envio todo e tudo o que ainda estiver a false vai com operaração de delete
    for(it=marker_map.begin(); it!=marker_map.end(); it++)
    {
        if( it->second.second==0 )//se for falso é para apagar
            it->second.first.action = visualization_msgs::Marker::DELETE;
        else if(it->second.second<=-1)//já foi apagado
        {
            /**
            \todo This should be erased but it is not working now
            marker_map.erase(it);
            */
            continue;
        }

        marker_vector.push_back(it->second.first);
    }
}
Example #21
0
File: main.c Project: damora/ivr
int initvolluts()
{
#ifdef MPI
    int comsize, rank;
    int indx;
    int *rhsizes;
    int *globalhist;
    int *roffsets;
    int *rhists = NULL;
    float *rminvalues;
    float *rmaxvalues;
#endif
    int *hist = NULL;
    int hsize;
    float minvalue, maxvalue;

    /////////////////////////////// compute global color table ///////////////////////////////////////
    // compute local histogram and create a colormap from all local histograms
    hsize = histogram(&hist, volume.data.f, &minvalue, &maxvalue, volume.localdims.w, volume.localdims.h, volume.localdims.d);

    // broadcast hist, minvalue, maxvalue
#ifdef MPI
    //  MPI_Comm_size(comm, &comsize);
    // MPI_Comm_rank(comm, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &comsize);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    rminvalues = (float *) malloc(sizeof(float) * comsize);
    rmaxvalues = (float *) malloc(sizeof(float) * comsize);
    assert (rminvalues != NULL && rmaxvalues != NULL);

    rhsizes = (int *) malloc(sizeof(int) * comsize);
    assert (rhsizes != NULL);

    // allgatherv parameters
    roffsets = (int *) malloc(sizeof(int) * comsize);
    assert (roffsets != NULL);

    //MPI_Allgather( &minvalue, 1, MPI_FLOAT, rminvalues, 1, MPI_FLOAT, comm);
    MPI_Allgather( &minvalue, 1, MPI_FLOAT, rminvalues, 1, MPI_FLOAT, MPI_COMM_WORLD);
    //MPI_Allgather( &maxvalue, 1, MPI_FLOAT, rmaxvalues, 1, MPI_FLOAT, comm);
    MPI_Allgather( &maxvalue, 1, MPI_FLOAT, rmaxvalues, 1, MPI_FLOAT, MPI_COMM_WORLD);
    //MPI_Allgather( &hsize, 1, MPI_INT, rhsizes, 1, MPI_INT, comm);
    MPI_Allgather( &hsize, 1, MPI_INT, rhsizes, 1, MPI_INT, MPI_COMM_WORLD);

    int d = 0;
    for (int i=0; i<comsize; i++) {
        roffsets[i] = d;
        d += rhsizes[i];
    }
    rhists = (int *) malloc(sizeof(int) * d);
    assert (rhists != NULL);

    //MPI_Allgatherv(hist, hsize,  MPI_INT, rhists, rhsizes, roffsets, MPI_INT, comm);
    MPI_Allgatherv(hist, hsize,  MPI_INT, rhists, rhsizes, roffsets, MPI_INT, MPI_COMM_WORLD);

    float tmpmin = MAXFLOAT;
    float tmpmax =  -MAXFLOAT;
    for (int i=0; i<comsize; i++) {
        minvalue = fmin(tmpmin, rminvalues[i]);
        maxvalue = fmax(tmpmax, rmaxvalues[i]);
        tmpmin = minvalue;
        tmpmax = maxvalue;
    }

    PRINTDEBUG("%3d:  MINMAX- %f, %f\n", rank, minvalue, maxvalue);

    hsize = (int) ((maxvalue - minvalue) + 1);
    globalhist =  (int *) malloc(sizeof(int) * hsize);
    assert(globalhist != NULL);

    for (int j=0; j<hsize; j++) globalhist[j] = 0;
    int rindx;


    for (int i=0; i<comsize; i++) {
        rindx = roffsets[i];	// get offset into individual histogram arrays
        indx = rminvalues[i] - minvalue;
        for (int j=0; j<rhsizes[i]; j++) {
            globalhist[indx+j] += rhists[rindx+j];
        }
    }

    lut = (color4f *) malloc(hsize * sizeof(color4f));
    maxlutindx = hsize - 1;
    assert (lut != NULL);

    colormap(lut, globalhist, hsize, minvalue, maxvalue);

    // free all the temp stuff
    free(rminvalues);
    free(rmaxvalues);
    free(rhsizes);
    free(rhists);
    free(roffsets);
    free(globalhist);

#else
    lut = (color4f *) malloc(hsize * sizeof(color4f));
    assert (lut != NULL);

    colormap(lut, hist, hsize, minvalue, maxvalue);
#endif

    lutoffset = (int) (minvalue + 0.5);

#ifdef GRAD
    /////////////////////////////// compute subvolume gradient	//////////////////////////////////////
    // local gradients are sufficient, i.e. a subvol does not need gradient values from another subvol
    // compute gradient and store with rest of volume data
    int n = volume.localdims.w;
    int m = volume.localdims.h;
    int p = volume.localdims.d;

    long long localsize = n * m * p;
    // allocate gradient storage
    volume.gradient = (vector4f *) malloc(localsize * sizeof(vector4f));
    assert (volume.gradient != NULL);

    // local gradients are sufficient, i.e. a subvol does not need gradient values from another subvol
    gradient3d(volume.gradient, volume.data.f, n, m,  p);
#endif

    free(hist);
    return 0;
}