コード例 #1
0
ファイル: Minggu4.c プロジェクト: fauzannaufan/Grafika06
void DrawCircle(int r, int g, int b, int x0, int y0, int radius, char *fbp) {

	int x = radius;
	int y = 0;
	int decision = 1 - x;
	while (y <= x) {
		tes(r,g,b, x + x0,  y + y0,fbp); // Octant 1
		tes(r,g,b, y + x0,  x + y0,fbp); // Octant 2
		tes(r,g,b,-x + x0,  y + y0,fbp); // Octant 4
		tes(r,g,b,-y + x0,  x + y0,fbp); // Octant 3
		tes(r,g,b,-x + x0, -y + y0,fbp); // Octant 5
		tes(r,g,b,-y + x0, -x + y0,fbp); // Octant 6
		tes(r,g,b, x + x0, -y + y0,fbp); // Octant 7
		tes(r,g,b, y + x0, -x + y0,fbp); // Octant 8
		y++;
		if (decision<=0) {
			decision += 2*y + 1;
		} else {
			x--;
			decision += 2*(y-x) + 1;

		}
	}

}
コード例 #2
0
ファイル: Minggu4.c プロジェクト: fauzannaufan/Grafika06
void printLine(int x0, int y0, int x1, int y1, int r, int g, int b, char *fbp) {

  int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
  int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1;
  int err = (dx>dy ? dx : -dy)/2, e2;

  for(;;){
	tes(r,g,b,x0,y0,fbp);
    if (x0==x1 && y0==y1) break;
    e2 = err;
    if (e2 >-dx) { err -= dy; x0 += sx; }
    if (e2 < dy) { err += dx; y0 += sy; }
  }
}
コード例 #3
0
ファイル: Minggu4.c プロジェクト: fauzannaufan/Grafika06
/*
void printLine(int xi, int yi, int xt, int yt, int r, int g, int b, char *fbp) {
	int x0,xl,y0,yl;
	float deltax = xt-xi;
	float deltay = yt-yi;
	float error = 0;
	float deltaerr;
    int x,y;
	if (deltax!=0) {
		if (deltax>=0) {
			x0=xi;xl=xt;y0=yi;yl=yt;
		} else {
			x0=xt;xl=xi;y0=yt;yl=yi;
		}
		y = y0;
		deltaerr = abs(deltay/deltax);
		for (x=x0; x<xl; x++) {
			tes(r,g,b,x,y,fbp);
		//printf("%d %d %f\n",x,y,error);
			error += deltaerr;
			while (error >= 0.5) {
				tes(r,g,b,x,y,fbp);
		//printf("%d %d %f\n",x,y,error);
				if (yl>y0,fbp)
					y += 1;
				else if (yl<y0,fbp)
					y -= 1;
				error -= 1;
			}
		}
	} else {
		if (deltay>=0) {
			y0=yi;yl=yt;x0=xi;xl=xt;
		} else {
			y0=yt;yl=yi;x0=xi;xl=xt;
		}
		x=x0;
		for (y=y0;y<yl;y++) {
			tes(r,g,b,x,y,fbp);
		}
	}

}
*/
void printPayung(int x0, int y0, int size, char *fbp) {
		int x,y;
		int t = x0+size;
		int titikPusat = x0 + size;
		int titikBawahY = y0 + size*2;
		int h = (y0 % (size / 1)) - (size/2);

		//size div 8

		if (h > (size/4)){
			h = size/4 - (h-size/4);
		}

		//payung
	    for (y = y0; y < y0+(size*2); y++) {
        	for (x = x0; x < x0+(size*2); x++) {
				if (((x-x0-size)*(x-x0-size))+((y-y0-size)*(y-y0-size)) <= (size*size)){
					int h2 = ((x-titikPusat)*h/(x0-titikPusat));
					if (y <= (y0 + size + h2)){
						tes(100,100,100, x,y, fbp);
					}
				}
	        }
	    }
	    //pilot
	    int xPilot, yPilot;
	    xPilot = titikPusat + h;
	    yPilot = titikBawahY + h;
	    for(x = (xPilot-7); x<=(xPilot+7); x++){
			for(y = titikBawahY; y<=titikBawahY+50; y++){
				tes(100,100,100,x,y,fbp);
			}
		}
		printLine(xPilot, titikBawahY, x0, y0+size+h, 100, 100, 100, fbp);
		printLine(xPilot, titikBawahY, x0+size*2, y0+size-h, 100, 100, 100, fbp);
	}
コード例 #4
0
ファイル: axprocess.cpp プロジェクト: DDMAL/aruspix
bool AxProcess::HasEnded( )
{
	wxString msg;

	// redirect in now disabled (see constructor)
	// nothing will happen
	wxTextInputStream tis(*GetInputStream());
	wxTextInputStream tes(*GetErrorStream());
	
	// we don't know where Error is going to be output
    while ( IsInputAvailable() )
	{
		msg = tis.ReadLine();
		if ( msg.StartsWith("$ Success!") )
		{
			return true;
		}
		else if ( msg.StartsWith("$ Error: ") )
		{
			m_status = 255;
			return true;
		}
		if ( !msg.IsEmpty() && m_log )
			m_log->WriteString( msg + "\n" );
	}
    while ( IsErrorAvailable() )
	{
		msg = tes.ReadLine();
		if ( msg.StartsWith("$ Error: ") )
		{
			m_status = 255;
			return true;
		}
		if ( !msg.IsEmpty() && m_log )
			m_log->WriteString( msg + "\n" );
    }


    return false;
}
コード例 #5
0
ファイル: Minggu4.c プロジェクト: fauzannaufan/Grafika06
void floodFill(int x, int y, int or, int og, int ob, int nr, int ng, int nb, char *fbp)
{
	int location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
                        (y+vinfo.yoffset) * finfo.line_length;
	int r = *(fbp + location);
	int g = *(fbp + location + 1);
	int b = *(fbp + location + 2);
	int newmatch = r==nr && b==nb && g==ng;
	int oldmatch = r==or && b==ob && g==og;
	//printf("%d %d %d\n",r,g,b);
	//printf("old : %d |%d %d %d\n",oldmatch,or,og,ob);
	//printf("new : %d |%d %d %d\n",newmatch,nr,ng,ng);
	//printf("RES : %d\n",oldmatch && !newmatch);
    if (!oldmatch && !newmatch)
    {
        tes(nr,ng,nb,x,y,fbp);
		floodFill(x+1,y,or,og,ob,nr,ng,nb,fbp);
		floodFill(x-1,y,or,og,ob,nr,ng,nb,fbp);
		floodFill(x,y+1,or,og,ob,nr,ng,nb,fbp);
		floodFill(x,y-1,or,og,ob,nr,ng,nb,fbp);
    }
}
コード例 #6
0
ファイル: Minggu4.c プロジェクト: fauzannaufan/Grafika06
int main(int argc, char* argv[])
 {
     int fbfd = 0;
     long int screensize = 0;
     char *fbp = 0;
     int x = 0, y = 0;
     long int location = 0;

     // Open the file for reading and writing
     fbfd = open("/dev/fb0", O_RDWR);
     if (fbfd == -1) {
         perror("Error: cannot open framebuffer device");
         exit(1);
     }
     printf("The framebuffer device was opened successfully.\n");

     // Get fixed screen information
     if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) {
         perror("Error reading fixed information");
         exit(2);
     }

     // Get variable screen information
     if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
         perror("Error reading variable information");
         exit(3);
     }

     printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);

     // Figure out the size of the screen in bytes
     screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;

     // Map the device to memory
     fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,
                        fbfd, 0);
     if ((int)fbp == -1) {
         perror("Error: failed to map framebuffer device to memory");
         exit(4);
     }
     printf("The framebuffer device was mapped to memory successfully.\n");

     x = 700; y = 350;       // Where we are going to put the pixel

     // Figure out where in memory to put the pixel

	int i,j,k,l;


	int rot = 0;
	for (i = 1; i<=5;i++) {
		for (l=0;l<5;l++)  {
			for (j=0;j<1200;j++) {
				for (k=0;k<700;k++) {
					tes(0,0,0,j,k,fbp);
				}
			}
			printplane(x,y,fbp,i);
			printbaling(x,y,rot,i,fbp);
			usleep(16000);
			rot++;
		}

	}
	for (i=5; i<20;i++) {
		printledak(x,y,i,fbp);
			usleep(16000);
	}
		for (l=0;l<5;l++)  {
			for (j=0;j<1200;j++) {
				for (k=0;k<700;k++) {
					tes(0,0,0,j,k,fbp);
				}
			}
		}
	int z = 150;
    while (z < 700) {
		for (l=0;l<5;l++)  {
			for (j=0;j<1200;j++) {
				for (k=0;k<700;k++) {
					tes(0,0,0,j,k,fbp);
				}
			}
		}
		printPayung(700, z, 100, fbp);
		z = z+5;
		usleep(16000);
	}
/*
	for (i=40; i>=5;i--) {
		printledak(x,y,i,fbp);
			usleep(16000);
		for (l=0;l<5;l++)  {
			for (j=0;j<1200;j++) {
				for (k=0;k<700;k++) {
					tes(0,0,0,j,k,fbp);
				}
			}
		}
	}*/

//printledak(700,500,i,fbp);
		//DrawCircle(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),x,y,5,fbp);
		//floodFill(x,y,0,0,0,atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),fbp);
     munmap(fbp, screensize);
     close(fbfd);
     return 0;
}
コード例 #7
0
void MainDialog::calculate() {
    //get data
    std::vector<double> data;
    QLocale c(QLocale::system());
    for(int i=0; i<table->rowCount(); i++) {
        if(!table->item(i, 0)) {
            //item has never been set
            warn("Fill out all the data cells");
            return;
        } else if(table->item(i, 0)->text().isEmpty()) {
            //item has been set but has been emptied again
            warn("Fill out all the data cells");
            return;
        } else {
            //item is good
            bool check;
            double tmp = c.toDouble(table->item(i, 0)->text(), &check);
            if(!check) {
                warn("Conversion error!");
                return;
            }
            data.push_back(tmp);
        }
    }
    bool check;
    double alpha = c.toDouble(alphaDSpin->text(), &check);
    if(!check) {
        warn("Error converting alpha's value to double");
        return;
    }
    double beta = c.toDouble(betaDSpin->text(), &check);
    if(!check) {
        warn("Error converting beta's value to double");
        return;
    }
    double gamma = c.toDouble(gammaDSpin->text(), &check);
    if(!check) {
        warn("Error converting gamma's value to double");
        return;
    }
    double s0 = c.toDouble(sDSpin->text(), &check);
    if(!check) {
        warn("Error converting S0's value to double");
        return;
    }
    double g0 = c.toDouble(gDSpin->text(), &check);
    if(!check) {
        warn("Error converting G0's value to double");
        return;
    }
    int forecast_count = c.toInt(fcountSpin->text(), &check);
    if(!check) {
        warn("Error converting the number of forecasts to int");
        return;
    }
    int frequency = c.toInt(freqSpin->text(), &check);
    if(!check) {
        warn("Error converting frequency's value to int");
        return;
    }
    //call calculators
    if(_method == 1) {
        single_es es;
        es.seq_update(data, alpha);
        QString str;
        ses_forecast_summary(str, data, es);
        resultText->setPlainText(str);
    } else if(_method ==2) {
        double_es d(data, s0, g0);
        d.seq_update(alpha, beta);
        d.evaluate();
        d.future_forecast(forecast_count);
        QString str, debug;
        //des_update_summary(str, d);
        des_forecast_summary(str, debug, d);
        resultText->setPlainText(str);
        debugText->setPlainText(debug);
    } else {
        if(data.size()/frequency < 2) {
            warn("There aren't enough data points for the selected frequency value");
            return;
        }
        triple_es tes(data, frequency, alpha, beta, gamma);
        QString str, dstr;
        tes_initiate_summary(str, dstr, tes);
        tes.initial_forecast();
        tes.periodic_update();
        tes.evaluate();
        tes.future_forecast(forecast_count);
        tes_forecast_summary(str, dstr, tes);
        resultText->setPlainText(str);
        debugText->setPlainText(dstr);
    }
    //output the results
}
コード例 #8
0
    void initialize() override
	{
		OpenGLWindow::initialize();

		//load shaders
		{
			QOpenGLShader vs(QOpenGLShader::Vertex);
				vs.compileSourceFile("TessellationTerrain/main.vs.glsl");
				mProgram.addShader(&vs);

			QOpenGLShader tcs(QOpenGLShader::TessellationControl);
				tcs.compileSourceFile("TessellationTerrain/main.tcs.glsl");
				mProgram.addShader(&tcs);

			QOpenGLShader tes(QOpenGLShader::TessellationEvaluation);
				tes.compileSourceFile("TessellationTerrain/main.tes.glsl");
				mProgram.addShader(&tes);

			QOpenGLShader fs(QOpenGLShader::Fragment);
				fs.compileSourceFile("TessellationTerrain/main.fs.glsl");
				mProgram.addShader(&fs);

			if (!mProgram.link())
				qFatal("Error linking shaders");
		}

		//grab uniform locations
		{
			mUniforms.mvMatrix = mProgram.uniformLocation("mvMatrix");
			mUniforms.mvpMatrix = mProgram.uniformLocation("mvpMatrix");
			mUniforms.projMatrix = mProgram.uniformLocation("projMatrix");
			mUniforms.dmapDepth = mProgram.uniformLocation("dmapDepth");
		}

		mVao.bind();
		glPatchParameteri(GL_PATCH_VERTICES, 4);
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

		//build displacment map
		{
			QVector<GLubyte> displacmentMap;
			displacmentMap.reserve(mSize*mSize);

			std::srand(35456);
		
			for (int i=0; i<mSize*mSize; i++)
				displacmentMap.append(randInt(0, 255));

			glGenTextures(1, &tex);
			glBindTexture(GL_TEXTURE_2D, tex);
			glTexStorage2D(GL_TEXTURE_2D, 1, GL_R8, mSize, mSize);
			glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mSize, mSize, GL_R, GL_UNSIGNED_BYTE, &displacmentMap[0]);
		}

		//load terrain texture
		{
			glActiveTexture(GL_TEXTURE1);
			mTerrainTexture = QSharedPointer<QOpenGLTexture>(new QOpenGLTexture(QImage("./Common/dirt.png").mirrored()));
			mTerrainTexture->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
			mTerrainTexture->setMagnificationFilter(QOpenGLTexture::Linear);
		}
	}
コード例 #9
0
int main()
{
	time_t start_time = time(NULL);
	std::string data_path("D:/Zmisc/Github/NLP/Naive-Bayes-Document-Classifier-master/trial/reuters_modified/"); //change this path according to your local data path
	std::ifstream file_cate((data_path+std::string("cats.txt")).c_str());
	//if file can't be opened, we exit
	if(!file_cate.good())
	{
		std::cerr << "Can't open cats.txt to read.\n";
		//exit(1); which is the same as 
		return EXIT_FAILURE;
	}
	
	
	std::string line;
	std::string token;
	std::string word1;
	std::string word2;
	std::string file_name;
	std::string min_cat;
	std::string train("training");
	std::string tes("test");
	
	//using the tree map implementation with O(log n) time for insertion, search, deletion etc 
	//because there are no hash table implementations in c++ stl
	
	std::map<std::string,std::string > test_map; //test file to category map
	std::map<std::string,std::string > train_map; //train file to category map
	std::map<std::string,std::string >::iterator fi_itr;
	std::map<std::string,std::string >::const_iterator cfi_itr;
	
	std::map<std::string,int > cate_num_docs_map;
	std::map<std::string,int > cate_num_docs_test_map;
	std::map<std::string,int >::iterator itr;
	std::map<std::string,int >::const_iterator citr;
	
	std::set<std::string> words_set; 
	std::set<std::string>::iterator set_itr;
	std::set<std::string>::const_iterator cset_itr;
	
	
	std::map<std::string, std::map<std::string,unsigned int> > word_cates_num_map;
	std::map<std::string, std::map<std::string,unsigned int> >::iterator big_itr;
	std::map<std::string, std::map<std::string,unsigned int> >::const_iterator cbig_itr;
	std::map<std::string,unsigned int>::iterator small_itr;
	std::map<std::string,unsigned int>::const_iterator csmall_itr;
//Create a map with a word as the key and a map as the value
// in the inner map the category as key and number of documents in that category where it occurs as value
	
	std::map<std::string, std::vector<unsigned int> > cates_results;
	std::map<std::string, std::vector<unsigned int> >::iterator res_itr;
	std::map<std::string, std::vector<unsigned int> >::const_iterator cres_itr;

	
	unsigned int len_train;
	unsigned int counter;
	unsigned int error_counter;
	unsigned int len_test;
	int nct;
	double time_diff;
	double minimum_neg_log_prob;
	double neg_log_prob;
	double ratio;
	
	
	
	
	//Format of each line of categs file - filename cate1 cate 2(if any) cate3(if any)
	while(getline(file_cate,line))
	{
		counter = 0;
		std::istringstream iss(line);
		while(iss >> token)
		{
			++counter;
			if(counter==1)
				word1 = token;
			else if(counter==2)
				word2 = token;
		}
			
		if(counter>2) //we only consider files which are in 1 category
			continue;
			
		if(word1.compare(0,4,tes)==0)
		{
			file_name = word1.substr(5);
			test_map[file_name] = word2;
			++cate_num_docs_test_map[word2];
		}
			
		
		
		else if(word1.compare(0,8,train)==0)
		{
			file_name = word1.substr(9);
			train_map[file_name] = word2;
			++cate_num_docs_map[word2];
		}

	}
	
	file_cate.close();
	
	
	
	//Removing categories with less than 21 files in either the training set or test set
	prune_rare_categories(cate_num_docs_map,cate_num_docs_test_map);
	
	
	for(cfi_itr = train_map.begin();cfi_itr!=train_map.end();++cfi_itr)
	{
		itr = cate_num_docs_map.find(cfi_itr->second);
		
		//File belongs to a low category
		if(itr==cate_num_docs_map.end())
			continue;
	
		file_name = data_path+std::string("training/")+cfi_itr->first;
		std::ifstream file_obj(file_name.c_str());
		//if file can't be opened, we exit
		if(!file_obj.good())
		{
			std::cerr << "Can't open training file to read.\n";
			//exit(1); which is the same as 
			return EXIT_FAILURE;
		}
		
		words_set.clear();
		while(file_obj >> token)
			words_set.insert(token);
		
		for(cset_itr = words_set.begin();cset_itr!=words_set.end();++cset_itr)
		{
			big_itr = word_cates_num_map.find(*cset_itr);	
			++word_cates_num_map[*cset_itr][cfi_itr->second];
		}
		file_obj.close();
		++len_train;
	}
	
	time_diff = difftime(time(NULL),start_time);
	std::cout << "The Classifier is trained and it took "<< time_diff << " seconds.\n" ;

	start_time = time(NULL);
	
	//Initialize cates_results
	for(citr=cate_num_docs_map.begin();citr!=cate_num_docs_map.end();++citr)		
	{
		cates_results[citr->first].push_back(0);
		cates_results[citr->first].push_back(0);
		cates_results[citr->first].push_back(0);
		cates_results[citr->first].push_back(0);
	}
	
	for(cfi_itr = test_map.begin();cfi_itr!=test_map.end();++cfi_itr)
	{
		itr = cate_num_docs_map.find(cfi_itr->second);
		
		//File belongs to a low category
		if(itr==cate_num_docs_map.end())
			continue;
		
		
		file_name = data_path+std::string("test/")+cfi_itr->first;
		std::ifstream file_obj(file_name.c_str());
		//if file can't be opened, we exit
		if(!file_obj.good())
		{
			std::cerr << "Can't open test file to read.\n";
			//exit(1); which is the same as 
			return EXIT_FAILURE;
		}
		
		words_set.clear();
		while(file_obj >> token)
			words_set.insert(token);
	
		minimum_neg_log_prob=1000000000;
		min_cat = "";
	
		for(citr=cate_num_docs_map.begin();citr!=cate_num_docs_map.end();++citr)		
		{
			neg_log_prob = -log(citr->second/(len_train*1.0));
			for(cbig_itr = word_cates_num_map.begin(); cbig_itr!=word_cates_num_map.end();++cbig_itr)
			{
				set_itr = words_set.find(cbig_itr->first);
				nct = word_cates_num_map[cbig_itr->first][citr->first];
				ratio = (nct+1)/(citr->second+2.0);
				if(set_itr!=words_set.end())
					neg_log_prob-= log(ratio);
				else
					neg_log_prob-=log(1-ratio);
			}
		
			if(minimum_neg_log_prob>neg_log_prob)
			{
				min_cat = citr->first;
				minimum_neg_log_prob = neg_log_prob;
			}
		}
		file_obj.close();
		++len_test;
		
		if(min_cat!=cfi_itr->second)
			++error_counter;
		
		for(cres_itr = cates_results.begin();cres_itr!=cates_results.end();++cres_itr)
		{
			word2 = cres_itr->first;
			if(word2==min_cat)
			{
				if(word2==cfi_itr->second)
					++cates_results[word2][0];
				else
					++cates_results[word2][1];
			}
			else
			{
				if(word2==cfi_itr->second)
					++cates_results[word2][2];
				else
					++cates_results[word2][3];
			}
		}
	}

	std::cout << "The fraction of errors is " << error_counter/(len_test*1.0) << "\n";
	
	//Evaluation by finer measures
	f_measure(cates_results);
	
	time_diff = difftime(time(NULL),start_time);
	std::cout << "The Classifier has run and it took "<< time_diff << " seconds.\n" ;	
	return 0;
}