Beispiel #1
0
int main()
{
	Graph g;
	readG(g);
	printG(g);
	delNode(g, 3);
	printf("Graful dupa stergerea nodului 3\n");
	printG(g);
	return 0;
}
Beispiel #2
0
Agraph_t *freadFile(Expr_t * ex, int fd)
{
    Sfio_t *sp;

    if (fd < 0 || fd >= elementsof(ex->file)
	|| !((sp = ex->file[fd]))) {
	exerror("freadG: %d: invalid descriptor", fd);
	return 0;
    }
    return readG(sp);
}
Beispiel #3
0
void
saveFile(void)
{
	int i, len;
	word *pTable;

	writeFile("dccs", 4);					/* Signature */				
	writeFileShort(numKeys);				/* Number of keys */
	writeFileShort((short)(numKeys * C));	/* Number of vertices */
	writeFileShort(PATLEN);					/* Length of key part of entries */
	writeFileShort(SYMLEN);					/* Length of symbol part of entries */

	/* Write out the tables T1 and T2, with their sig and byte lengths in front */
	writeFile("T1", 2);						/* "Signature" */
	pTable = readT1();
	len = PATLEN * 256;
	writeFileShort(len * sizeof(word));
	for (i=0; i < len; i++)
	{
		writeFileShort(pTable[i]);
	}
	writeFile("T2", 2);
	pTable = readT2();
	writeFileShort(len * sizeof(word));
	for (i=0; i < len; i++)
	{
		writeFileShort(pTable[i]);
	}

	/* Write out g[] */
	writeFile("gg", 2);			  			/* "Signature" */
	pTable = readG();
	len = (short)(numKeys * C);
	writeFileShort(len * sizeof(word));
	for (i=0; i < len; i++)
	{
		writeFileShort(pTable[i]);
	}

	/* Now the hash table itself */
	writeFile("ht ", 2);			  			/* "Signature" */
	writeFileShort(numKeys * (SYMLEN + PATLEN + sizeof(word)));	/* byte len */
	for (i=0; i < numKeys; i++)
	{
		writeFile((char *)&keys[i], SYMLEN + PATLEN);
	}
}
Beispiel #4
0
/* readFile:
 * Read graph from file f.
 * Return 0 on failure
 */
Agraph_t *readFile(char *f)
{
    Agraph_t *gp;
    Sfio_t *fp;

    if (!f) {
	exerror("NULL string passed to readG");
	return 0;
    }
    fp = sfopen(0, f, "r");
    if (!fp) {
	exwarn("Could not open %s for reading in readG", f);
	return 0;
    }
    gp = readG(fp);
    sfclose(fp);

    return gp;
}
Beispiel #5
0
std::vector<Mesh> loadMeshesFromObj(const char *filename, float scale)
{
	printf("Attempting to load mesh->from %s\n", filename);

	std::ifstream filehandle;
	filehandle.open(filename, std::ios::in);

	std::vector<Mesh> meshes;

	if(filehandle.fail())
	{
		printf("Could not open file.\n");
		return meshes;
	}

	std::vector<std::list<sVertexIndex> > existingVertexTable;

	std::vector<sVertexIndex>	vertexTable;
	std::vector<Mesh::sFace>	faceTable;

	std::vector<sVec3> positionTable;
	std::vector<sVec3> normalTable;
	std::vector<sVec2> texcoordTable;

	std::string line;
	std::string name;
	std::string material;
	int sg = 0;
	int count = 0;

	clock_t start, end;
	start = clock();

	printf("Reading data... ");

	while( filehandle.good() && !filehandle.eof() )
	{
		std::getline(filehandle, line);
		if(line[0] == 'v')
		{
			if(line[1] == 't')
				readTexcoord(line, texcoordTable);
			else if(line[1] == 'n')
				readNormal(line, normalTable);
			else
				readPosition(line, positionTable, scale);
		}
		else if(line[0] == 'f')
			readFace(line, vertexTable, existingVertexTable, faceTable, sg);
		else if(line[0] == 's')
			readSG(line, sg);
		else if(line[0] == 'g')
		{
			readG(line, name);
		}
		else if(line[0] == 'u')
		{
			char str[32];
			char mtl[128];
			int success = sscanf(line.c_str(), "%s %s", str, mtl);
			if(success && strcmp(str, "usemtl") == 0)
			{
				if(count > 0)
				{
					meshes.push_back(Mesh());
					fillMesh(	meshes[count-1], name, vertexTable, faceTable,
								positionTable, normalTable, texcoordTable);
					meshes[count-1].material = material;
					vertexTable.clear();
					faceTable.clear();
					existingVertexTable.clear();
				}
				++count;

				if(success > 1)
					material = std::string(mtl);
			}
		}
	}

	if(count > 0)
	{
		meshes.push_back(Mesh());
		fillMesh(	meshes[count-1], name, vertexTable, faceTable,
					positionTable, normalTable, texcoordTable);
		meshes[count-1].material = material;
	}

	printf("done!\n");

	//printf("total vertex count %i\n", vertexTable.size());
	//printf("total face count %i\n", faceTable.size());

    end = clock();
    double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
    printf("Time taken %3.3fs \n", cpu_time_used);

    //printf("meshes.size() = %i\n", meshes.size());

	return meshes;
}