std::vector<double> calcQuantifiedMedianSlope(std::vector<std::vector<double> > list_of_values_xystamp_) {
        	std::vector<double> quantifiedMedianXY;
        	std::vector<std::vector<double> > inputXAndQuantifiedList;
        	std::vector<std::vector<double> > inputYAndQuantifiedList;
        	std::vector<double> inputXAndQuantified;
        	std::vector<double> inputYAndQuantified;
        	double medianX = 0;
        	double medianY = 0;
        	int counter = 0;
        	int number_of_elements = list_of_values_xystamp_.size();
        	ROS_INFO("numberofElements = %u", number_of_elements);
        	for (int i=0; i<number_of_elements; i++) {
        		inputXAndQuantified.push_back(list_of_values_xystamp_.at(i).at(0) * (i^2));
        		inputXAndQuantified.push_back(list_of_values_xystamp_.at(i).at(0));
        		inputXAndQuantifiedList.push_back(inputXAndQuantified);
        		inputYAndQuantified.push_back(list_of_values_xystamp_.at(i).at(1) * (i^2));
        		inputYAndQuantified.push_back(list_of_values_xystamp_.at(i).at(1));
        		inputYAndQuantifiedList.push_back(inputYAndQuantified);
        		counter = counter+i;
        	}
        	///SORT
        	std::sort (inputXAndQuantifiedList.begin() , inputXAndQuantifiedList.end(), less_than_key());
        	std::sort (inputYAndQuantifiedList.begin(),  inputYAndQuantifiedList.end(), less_than_key());
//        	DEBUG:
//        	for (int i = 0; i<inputXAndQuantifiedList.size(); i++) {
//        		ROS_INFO("list: %u, %f, %f", i, inputXAndQuantifiedList.at(i).at(0), inputXAndQuantifiedList.at(i).at(1));
//        	}
        	if (number_of_elements&1) {
				//ungerade pivot = (n-1)/2;
				medianX = inputXAndQuantifiedList.at((number_of_elements-1)/2).at(1);
				medianY = inputYAndQuantifiedList.at((number_of_elements-1)/2).at(1);
			}
			else {
				//gerade pivot = n/2 - 1; pivot --> mean of n/2 + n/2 -1
				medianX = (inputXAndQuantifiedList.at(number_of_elements/2).at(1) + inputXAndQuantifiedList.at(number_of_elements/2 - 1).at(1))/2;
				medianY = (inputYAndQuantifiedList.at(number_of_elements/2).at(1) + inputYAndQuantifiedList.at(number_of_elements/2 - 1).at(1))/2;
			}
        	quantifiedMedianXY.push_back(medianX);
        	quantifiedMedianXY.push_back(medianY);
        	return quantifiedMedianXY;
        }
Esempio n. 2
0
 vector<Interval> merge(vector<Interval> &intervals) {
     // Note: The Solution object is instantiated only once and is reused by each test case.
     sort(intervals.begin(), intervals.end(), less_than_key());
     vector<Interval> results;
     int n = intervals.size();
     if(n == 0)
         return results;
     int index = 0;
     results.push_back(intervals[0]);
     for(int i = 1 ; i < n ;i ++){
         if(intervals[i].start <= results[index].end){
             results[index].end = intervals[i].end > results[index].end ? intervals[i].end : results[index].end;
         }
         else{
             results.push_back(Interval(intervals[i].start, intervals[i].end));
             index++;
         }
     }
     return results;
 }
Esempio n. 3
0
//--------------------------------------------------------------
void shadow::setup(ofxSVG *svgShadowTopIn, ofxSVG *svgShadowBackIn){
	//svg.load("illu2.svg");
 
	svgShadowBack = svgShadowBackIn;
	svgShadowTop = svgShadowTopIn; //NOT WORKING

//	svgShadowBack.load("illu2.svg");
	//shader.load("shaders/blur");
	//cam.disableMouseInput();


	blurHShader.load("shaders/basic.vert", "shaders/gaussblur_h5.frag");
	blurVShader.load("shaders/basic.vert", "shaders/gaussblur_v5.frag");

	fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGBA);
	fbo2.allocate(ofGetWidth(), ofGetHeight(), GL_RGBA32F);//32F_ARB

	fbo2.begin();
	ofClear(255, 255, 255, 0);
	fbo2.end();

	vector<ofColor>groupByCol;
	groupByCol.clear();

	vector<vector<ofPath>>pathsShader;


	for (int i = 0; i < svgShadowTop->getNumPath(); i++) {
		ofPath p = svgShadowTop->getPathAt(i);
		p.setPolyWindingMode(OF_POLY_WINDING_ODD);
		ofColor colToDepth = p.getFillColor();

		if (isGray(colToDepth)==false) {	
		}
		else {
			bool colExist = false;

			for (int j = 0;j < groupByCol.size();j++) {
				if (colToDepth == groupByCol[j]) {
					colExist = true;
				}
			}
			if (colExist == false) {
				
				float zPos = ofMap(colToDepth.getBrightness(), 0, 255, 200, 0.0);
				zPosition.push_back(zPos);
			//cout << "zPos Top" << zPos << endl;
				groupByCol.push_back(colToDepth);

				//cout << "color" << colToDepth << endl;
				//vector<ofPath>tP;
				//ofPath pp
				//tP.push_back(pp);
				//pathsShader.push_back(tP);
				maskLayersI.push_back(0);
			}
		}
	}



	ofSetWindowShape(ofGetWidth(), ofGetHeight());
	masker.setup(ofGetWidth(), ofGetHeight());
	maskLayer = masker.newLayer();


	for (int i = 0; i < zPosition.size(); i++) {

	//	maskLayersI[i] = masker.newLayer();
	}


	//cout << "first loop" << endl;
	vector<ofPath>tempP;
	tempP.clear();
	//tempP.assign(1,tp);
	pathsShader.assign(groupByCol.size(), tempP);
	//cout << groupByCol.size() << "group" << endl;

	for (int i = 0; i < svgShadowTop->getNumPath(); i++) {

		ofPath p = svgShadowTop->getPathAt(i);
		p.setPolyWindingMode(OF_POLY_WINDING_ODD);
		ofColor colToDepth = p.getFillColor();

		if (isGray(colToDepth)) {

			for (int j = 0;j < groupByCol.size();j++) {
				if (groupByCol[j] == colToDepth) {
					pathsShader[j].push_back(p);
					//return;
				}
			}
		}
		else {
			///bool colExist = false;

		}

	}

	pathsShaderTopS = pathsShader;
	for (int i = 0; i < pathsShaderTopS.size();i++) {
		for (int j = 0; j < pathsShaderTopS[i].size();j++) {
			//ofPushMatrix();
			//ofTranslate(0, 0, zPosition[1]);//
			pathsShaderTopS[i][j].simplify(3.0);
			//pathsShaderS[i][j].draw();
			//ofPopMatrix();
		}
	}


	//Sorting the order brighter to darker
	struct less_than_key
	{
		inline bool operator() (const vector<ofPath>& struct1, const vector<ofPath>& struct2)
		{
			return (struct1[0].getFillColor().r < struct2[0].getFillColor().r);
		}
	};
	//sort(pathsShader.begin(), pathsShader.end(), less_than_key());
	sort(pathsShaderTopS.begin(), pathsShaderTopS.end(), less_than_key());
	sort(zPosition.begin(), zPosition.end()); 
	//Sorting the order brighter to darker




	for (int i = 0; i < svgShadowBack->getNumPath(); i++) {
		ofPath p = svgShadowBack->getPathAt(i);
		//cout << " back" << p.getFillColor() << endl;
		p.setPolyWindingMode(OF_POLY_WINDING_ODD);
		p.simplify(1.0);
		p.setColor(ofColor(0, 0, 0));
		pathsShaderBackS.push_back(p);
	}


	gui.setup("saved", "settingsShadow.xml");
	//gui.add(posLight.setup("posLight", ofVec3f(0, 0, 0), ofVec3f(0, 0, -1000), ofVec3f(1920 * 4, 1080, 1000.0)));
	//gui.add(lookAtLight.setup("lookAtLight", ofVec3f(0, 0, 0), ofVec3f(0, 0, -1000), ofVec3f(1920 * 4, 1080, 1000.0)));
	//gui.add(rotLight.setup("rotLight", ofVec3f(0, 0, 0), ofVec3f(-180, -180, -180), ofVec3f(180, 180, 180)));
	//gui.add(zWall.setup("zWall", 0, -500, 500));
	//gui.add(scale.setup("scale", 0.4, 0.01, 2.0));

	
	gui.add(blurFactor.setup("m_blurFactor", 4.0f, 0.0, 8.0));
	gui.add(texelSize.setup("m_texelSize", 1.0, 0.0, 10.0));
	gui.loadFromFile("settingsShadow.xml");
	

}
	void ThreadScheduler::enqueue_task(ThreadScheduler::Task t){
		tasks.push_back(t);
		std::sort(tasks.begin(), tasks.end(), less_than_key());
	}