Exemple #1
0
void 
CurveData::process()
{

    typedef data::Single<Selection *> SingleSelectionPtr;
    typedef data::Single<Graph *>     SingleGraphPtr;


#ifdef DEBUG_CURVEDATA
    cout << "CurveData::process()" << endl;
    // cout << "   " << expression << endl;
#endif

    if (this->expression.compare("") == 0)
    {

#ifdef DEBUG_CURVEDATA
	cout << "   curve has no expression" << endl;
#endif

	this->getOutputPort("curve")->setData(NULL);
	return;
    }

#ifdef DEBUG_CURVEDATA
    cout << "   curve expression is " << this->expression << endl;
#endif

    bvdata::File* speciesFile;
    if (!data::Single<bvdata::File*>::getInputValue(this,"file",speciesFile))
    {
#ifdef DEBUG_TAGCLOUDDATA
	cout << "   could not retrieve species file" << endl;
#endif

	getOutputPort("curve")->setData(NULL,true);
	return;
    }

    bool integrate_all = false;

    Selection *selection = NULL;
    if (!SingleSelectionPtr::getInputValue(this,"selection",selection))
	integrate_all = true;


#ifdef DEBUG_CURVEDATA
    cout << "   integrate_all: " << integrate_all << endl;
#endif

    // cout << "   screen window.....OK" << endl;
    bvdata::Repository *repo = Global::instance()->getRepository();

    //find out the sum ranges   
    ViewRect world_window = speciesFile->getProbSDQuad();//repo->getDefaultLonLatQuad();
    int xMin, xMax, yMin, yMax;

    double denominator = 1.0;

    double cells_per_area_unit = (speciesFile->xcells * speciesFile->ycells) / 
	(speciesFile->quad.w * speciesFile->quad.h);

    if (integrate_all)
    {
	xMin = 0; yMin = 0;
	xMax = x_samples-1; yMax = y_samples-1;

#ifdef DEBUG_CURVEDATA
    cout << "   this->x_samples: " << x_samples << endl;
    cout << "   this->y_samples: " << y_samples << endl;
#endif

        if (ColorConstants::NORMALIZE_CURVES)
        {
	    denominator = cells_per_area_unit * (speciesFile->quad.w * speciesFile->quad.h) *
		Global::instance()->estimateUSAreaCoefficientAtRectangle(
		    speciesFile->quad.x,
		    speciesFile->quad.y,
		    speciesFile->quad.w,
		    speciesFile->quad.h);
        }

    }
    else {

	ViewRect selection_window = selection->getSelectionWindow();

	xMin = ((selection_window.x - world_window.x)/(world_window.w)) * x_samples;
	if(xMin  < 0) xMin = 0;
	if(xMin  >= x_samples) xMin = x_samples - 1;
    
	xMax = ((selection_window.x + 
		 selection_window.w - world_window.x)/(world_window.w)) * x_samples;
	if(xMax  < 0) xMax = 0;
	if(xMax  >= x_samples) xMax = x_samples - 1;

	yMin = ((selection_window.y - world_window.y)/(world_window.h)) * y_samples;
	if(yMin  < 0) yMin = 0;
	if(yMin  >= y_samples) yMin = y_samples - 1;
    
	yMax = ((selection_window.y + 
		 selection_window.h - world_window.y)/(world_window.h)) * y_samples;
	if(yMax  < 0) yMax = 0;
	if(yMax  >= y_samples) yMax = y_samples - 1;


	// TODO need to have this rectangle right
        if (ColorConstants::NORMALIZE_CURVES)
        {
	    denominator = cells_per_area_unit * (selection_window.w * selection_window.h) *
		Global::instance()->estimateUSAreaCoefficientAtRectangle(selection_window.x,
									 selection_window.y,
									 selection_window.w,
									 selection_window.h);
	}
    }

#ifdef DEBUG_CURVEDATA
	cout << "   xMin, xMax, yMin, yMax: " 
	     << xMin << ", " << xMax << ", " 
	     << yMin << ", " << yMax << endl;
	// cout << "   " << expression << endl;
#endif


    //R query
    vector<float> curve = speciesFile->getVariableCurve("p", xMin+1, xMax+1, yMin+1, yMax+1);

    vector<float>::iterator it;

    Color black(0,0,0);
    this->graph.curve.clear();
    this->graph.color = (selection != NULL ? selection->getColor() : black);

    float sum = 0;
    for (int i=0;i<curve.size();i++)
    {
	if (denominator > 0.0)
	    this->graph.curve.push_back(curve[i]/denominator);
	else
	    this->graph.curve.push_back(0.0);
	sum += curve[i];
    }

#ifdef DEBUG_CURVEDATA
    cout << "   Sum = " << sum << endl;
#endif

    
    this->getOutputPort("curve")->setData(new SingleGraphPtr(&this->graph),true);
}
Exemple #2
0
void 
MapSelectionsRenderer::process()
{
#ifdef DEBUG_MAPSELECTIONSRENDERER
    cout << "MapSelectionsRenderer::process()" << endl;
#endif
    // cout << "MapSelectionsRenderer::process()" << endl;
    typedef data::Single<Selection *> SingleSelectionPtr;


    ViewRect screen_window;
    if (!data::SingleViewRect::getInputValue(this,"screen_window",screen_window))
	return;

#ifdef DEBUG_MAPSELECTIONSRENDERER
    cout << "   screen window.....OK" << endl;
#endif

    ViewRect world_window;
    if (!data::SingleViewRect::getInputValue(this,"world_window",world_window))
	return;

#ifdef DEBUG_MAPSELECTIONSRENDERER
    cout << "   world window.....OK" << endl;
#endif

    vector<Selection *> selections;
    vector<Data *> vec_data = this->getInputPort("selections")->getAllData();
    for (int i=0;i<vec_data.size();i++)
    {
	SingleSelectionPtr* data = dynamic_cast<SingleSelectionPtr*>(vec_data.at(i));  
	if (data != NULL)
	    selections.push_back(data->value);
    }
    
#ifdef DEBUG_MAPSELECTIONSRENDERER
    cout << "   number of selections " << selections.size() << endl;
#endif

    Global *global = Global::instance();

    if (global->usa_states == NULL)
    {
	cout << "   usa states not loaded... returning without rendering" << endl;
    }

    ScreenWorldTransform swt(screen_window, world_window);
    ViewRect adj_screen_window = swt.getAdjustedScreenWindow();

    RenderSystem *renderSystem = global->getRenderSystem();
    renderSystem->startViewport(adj_screen_window, 
				world_window,
				screen_window);


    for (int i=0;i<selections.size();i++)
    {
	Selection *sel = selections[i];
	ViewRect sw = sel->getSelectionWindow();

	Color c = sel->getColor();
	renderSystem->setColor(c.r,c.g,c.b, ColorConstants::SEL_TRANSPARENCY);
	renderSystem->drawQuad(sw.x,sw.y,sw.w,sw.h);

	renderSystem->setColor(sel->getColor());
	renderSystem->drawQuad(sw.x,sw.y,sw.w,sw.h,GL_LINE_LOOP);
    }

    renderSystem->endViewport();

}