int main() {
    int n = 10000000;
    int *testData = new int[n];
    for (int i = 0; i < n; ++i) {
        testData[i] = rand() % INT32_MAX;
    }
    double time1 = testHeap(testData, n, false);
    std::cout << "Without heapify :" << time1 << " s " << std::endl;
    double time2 = testHeap(testData, n, true);
    std::cout << "With heapify :" << time2 << " s " << std::endl;
    return 0;
}
Exemplo n.º 2
0
ILboolean testDetermineTypeFromContent(TCHAR* fn)
{
	testHeap();
	ilInit();
	testHeap();
	ILuint handle = ilGenImage();
	testHeap();
	ilBindImage(handle);
	testHeap();
	//printf("Loading " PathCharMod "\n", sourceFN);
	FILE* f = _wfopen(fn, L"rb");
	bool loaded = false;
	ILenum type = IL_TYPE_UNKNOWN;

	if (f != NULL) {
		fseek(f, 0, SEEK_END);
		myDataSize = ftell(f);
		if (myDataSize > 0) {
			fseek(f, 0, SEEK_SET);
			myData = new BYTE[myDataSize];
			size_t read = fread(myData, 1, myDataSize, f);
			myReadPos = 0;
			if (read == myDataSize) {
				//loaded = ilLoadL(IL_TYPE_UNKNOWN, lump, read);
				ilSetRead(myOpenProc, myCloseProc, myEofProc, myGetcProc, myReadProc, mySeekProc, myTellProc);
				type = ilDetermineTypeFuncs();
				if (type == IL_TYPE_UNKNOWN) {
					printf("testDetermineTypeFromContent: Failed to determine type of " PathCharMod "\n", fn);
					++errors;
				}
			} else {
				printf("testDetermineTypeFromContent: Failed to read " PathCharMod "\n", fn);
				++errors;
			}
			delete myData;
		}
		fclose(f);
	} else {
		printf("testDetermineTypeFromContent: Failed to open %S\n", fn);
		++errors;
	}

	testHeap();
	ilDeleteImage(handle);

	if (type == IL_TYPE_UNKNOWN) {
		++errors;
		return IL_FALSE;
	} else
		return IL_TRUE;
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
    int size;
    int version;
    CMEM_BlockAttrs attrs;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s <Number of bytes to allocate>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    size = atoi(argv[1]);

    /* First initialize the CMEM module */
    if (CMEM_init() == -1) {
        fprintf(stderr, "Failed to initialize CMEM\n");
        exit(EXIT_FAILURE);
    }

    printf("CMEM initialized.\n");

    version = CMEM_getVersion();
    if (version == -1) {
        fprintf(stderr, "Failed to retrieve CMEM version\n");
    }
    printf("CMEM version = 0x%x\n", version);

    if (CMEM_getBlockAttrs(0, &attrs) == -1) {
        fprintf(stderr, "Failed to retrieve CMEM memory block 0 bounds\n");
    }
    printf("CMEM memory block 0: phys start = 0x%lx, size = 0x%x\n",
           attrs.phys_base, attrs.size);

    if (CMEM_getBlockAttrs(1, &attrs) == -1) {
        fprintf(stderr, "Failed to retrieve CMEM memory block 1 bounds\n");
    }
    printf("CMEM memory block 1: phys start = 0x%lx, size = 0x%x\n",
           attrs.phys_base, attrs.size);

    testHeap(size, 0);
    testHeap(size, 1);

    testCache(size, 0);
    testCache(size, 1);

    if (CMEM_exit() < 0) {
        fprintf(stderr, "Failed to finalize the CMEM module\n");
    }

    exit(EXIT_SUCCESS);
}
Exemplo n.º 4
0
void test_ilLoad(wchar_t* sourceFN, wchar_t* targetFN)
{
	testHeap();
	ilInit();
	testHeap();
	ILuint handle = ilGenImage();
	testHeap();
	ilBindImage(handle);
	testHeap();
	//printf("Loading " PathCharMod "\n", sourceFN);
	ilResetRead();
	ILenum sourceType = ilDetermineType(sourceFN);
	if (!ilLoad(sourceType, sourceFN)) {
		printf("test_ilLoad: Failed to load %S\n", sourceFN);
		++errors;
		return;
	}
	testHeap();
	//ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
	//ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE);
	//iluScale(150, 150, 1);
	testHeap();
	DeleteFile(targetFN);
	//printf("Saving " PathCharMod "\n", targetFN);
	if (!ilSaveImage(targetFN)) {
		printf("test_ilLoad: Failed to save " PathCharMod "\n", targetFN);
		++errors;
	}
	testHeap();
	ilDeleteImage(handle);
}
Exemplo n.º 5
0
void test_ilLoadFuncs(wchar_t* sourceFN, wchar_t* targetFN)
{
	testHeap();
	ilInit();
	testHeap();
	ILuint handle = ilGenImage();
	testHeap();
	ilBindImage(handle);
	testHeap();
	//printf("Loading " PathCharMod "\n", sourceFN);
	FILE* f = _wfopen(sourceFN, L"rb");
	bool loaded = false;

	if (f != NULL) {
		fseek(f, 0, SEEK_END);
		myDataSize = ftell(f);
		if (myDataSize > 0) {
			fseek(f, 0, SEEK_SET);
			myData = new BYTE[myDataSize];
			size_t read = fread(myData, 1, myDataSize, f);
			myReadPos = 0;
			if (read == myDataSize) {
				//loaded = ilLoadL(IL_TYPE_UNKNOWN, lump, read);
				ilSetRead(myOpenProc, myCloseProc, myEofProc, myGetcProc, myReadProc, mySeekProc, myTellProc);
				loaded = ilLoadFuncs(IL_TYPE_UNKNOWN);
				if (!loaded) {
					printf("test_ilLoadFuncs: Failed to load " PathCharMod "\n", sourceFN);
					++errors;
				}
			} else {
				printf("test_ilLoadFuncs: Failed to read " PathCharMod "\n", sourceFN);
				++errors;
			}
			delete myData;
		}
		fclose(f);
	} else {
		printf("test_ilLoadFuncs: Failed to open %S\n", sourceFN);
		++errors;
	}

	testHeap();
	//ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
	//ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE);
	//iluScale(150, 150, 1);
	testHeap();
	DeleteFile(targetFN);
	//printf("Saving " PathCharMod "\n", targetFN);
	if (loaded)
		if(!ilSaveImage(targetFN)) {
			printf("Failed to save " PathCharMod " after ilLoadFuncs\n", targetFN);
			++errors;
		}
	testHeap();
	ilDeleteImage(handle);
}
Exemplo n.º 6
0
void test_ilLoadL(wchar_t* sourceFN, wchar_t* targetFN)
{
	testHeap();
	ilInit();
	testHeap();
	ILuint handle = ilGenImage();
	testHeap();
	ilBindImage(handle);
	testHeap();
	//printf("Loading " PathCharMod "\n", sourceFN);
	FILE* f = _wfopen(sourceFN, L"rb");
	bool loaded = false;

	if (f != NULL) {
		fseek(f, 0, SEEK_END);
		INT64 size = ftell(f);
		if (size > 0) {
			fseek(f, 0, SEEK_SET);
			char* lump = new char[size];
			size_t read = fread(lump, 1, size, f);
			if (read == size) {
				loaded = ilLoadL(IL_TYPE_UNKNOWN, lump, read);
				if (!loaded) {
					printf("test_ilLoadL: Failed to load " PathCharMod "\n", sourceFN);
					++errors;
				}
			} else {
				printf("test_ilLoadL: Failed to read " PathCharMod "\n", sourceFN);
				++errors;
			}
			delete lump;
		}
		fclose(f);
	} else {
		printf("test_ilLoadL: Failed to load %S\n", sourceFN);
		++errors;
	}

	testHeap();
	//ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
	//ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE);
	//iluScale(150, 150, 1);
	testHeap();
	DeleteFile(targetFN);
	//printf("Saving " PathCharMod "\n", targetFN);
	if (loaded)
		if (!ilSaveImage(targetFN)) {
			printf("test_ilLoadL: Failed to save " PathCharMod "\n", targetFN);
			++errors;
		}
	testHeap();
	ilDeleteImage(handle);
}
Exemplo n.º 7
0
int main(int argc, char* argv[])
{
    if(argc < 3)
    {
        printf("usage: ./memory 100 10");
        return 0;
    }
    testStack(atoi(argv[1]),atoi(argv[2]));
    printf("finish function stack test\n");
    int* pt = testHeap(atoi(argv[1]),atoi(argv[2]));
    printf("finish function heap test\n");
    getchar();
    int* pt1 = testHeap(atoi(argv[1]),atoi(argv[2]));
    printf("finish function heap test\n");
    getchar();
    delete [] pt;
    printf("delete pt heap memory\n");
    getchar();
    delete [] pt1;
    printf("delete pt1 heap memory\n");
    getchar();
    return 0;
}
Exemplo n.º 8
0
void test_ilLoadF(wchar_t* sourceFN, wchar_t* targetFN)
{
	testHeap();
	ilInit();
	testHeap();
	ILuint handle = ilGenImage();
	testHeap();
	ilBindImage(handle);
	testHeap();
	//printf("Loading " PathCharMod "\n", sourceFN);
	bool loaded = false;

	//FILE* f = _wfopen(sourceFN, L"rb");
	FILE * f;
	char buf[10];
	_wfopen_s(&f, sourceFN, L"rb");
	fread(buf, 1, 10, f);
	fseek(f, 0, IL_SEEK_SET);
	if (f != NULL) {
		loaded = ilLoadF(IL_TYPE_UNKNOWN, f);
		if(!loaded) {
			printf("test_ilLoadF: Failed to load %S\n", sourceFN);
			++errors;
		}
	} else {
		printf("test_ilLoadF: Failed to open %S\n", sourceFN);
		++errors;
	}

	fclose(f);
	testHeap();
	//ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
	//ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE);
	//iluScale(150, 150, 1);
	testHeap();
	DeleteFile(targetFN);
	//printf("Saving " PathCharMod "\n", targetFN);

	if (loaded)
		if (!ilSaveImage(targetFN)) {
			printf ("test_ilLoadF: Failed to save %S\n", targetFN);
			++errors;
		}

	testHeap();
	ilDeleteImage(handle);
}
Exemplo n.º 9
0
void testSavers(const TCHAR* sourceFN, const TCHAR* targetFN)
{
	testHeap();
	ilInit();
	testHeap();
	ILuint handle = ilGenImage();
	testHeap();
	ilBindImage(handle);
	testHeap();
	if (!ilLoadImage(sourceFN)) {
		printf("Failed to load %S using ilLoadImage\n", sourceFN);
		++errors;
		return;
	}
	testHeap();

	// gif, ico: no save support...
	// todo: psd, pcx, tga, tif
	testSavers2(IL_BMP, targetFN, L"bmp");
	testSavers2(IL_JPG, targetFN, L"jpg");
	testSavers2(IL_PNG, targetFN, L"png");
	testSavers2(IL_PSD, targetFN, L"psd");
	testSavers2(IL_PCX, targetFN, L"pcx");
	testSavers2(IL_TGA, targetFN, L"tga");
	testSavers2(IL_TIF, targetFN, L"tif");
	testSavers2(IL_TGA, targetFN, L"tga");
	testSavers2(IL_PCX, targetFN, L"pcx");
	testSavers2(IL_PNM, targetFN, L"pnm");
	testSavers2(IL_SGI, targetFN, L"sgi");
	testSavers2(IL_WBMP, targetFN, L"wbmp");
	testSavers2(IL_MNG, targetFN, L"mng");
	testSavers2(IL_VTF, targetFN, L"vtf");

	testHeap();
	ilDeleteImage(handle);
}
Exemplo n.º 10
0
int main(){
  testHeap();

  return 0;
}
void ApexQuadricSimplifier::collapseEdge(QuadricEdge& edge)
{
	uint32_t vNr0 = edge.vertexNr[0];
	uint32_t vNr1 = edge.vertexNr[1];
	QuadricVertex* qv0 = mVertices[vNr0];
	QuadricVertex* qv1 = mVertices[vNr1];

	PX_ASSERT(qv0->bDeleted == 0);
	PX_ASSERT(qv1->bDeleted == 0);

	//FILE* f = NULL;
	//fopen_s(&f, "c:\\collapse.txt", "a");
	//fprintf_s(f, "Collapse Vertex %d -> %d\n", vNr1, vNr0);

	// contract edge to the vertex0
	qv0->pos = qv0->pos * (1.0f - edge.ratio) + qv1->pos * edge.ratio;
	qv0->q += qv1->q;

	// merge the edges
	for (uint32_t i = 0; i < qv1->mEdges.size(); i++)
	{
		QuadricEdge& ei = mEdges[qv1->mEdges[i]];
		uint32_t vi = ei.otherVertex(vNr1);
		if (vi == vNr0)
		{
			continue;
		}

		// test whether we already have this neighbor
		bool found = false;
		for (uint32_t j = 0; j < qv0->mEdges.size(); j++)
		{
			QuadricEdge& ej = mEdges[qv0->mEdges[j]];
			if (ej.otherVertex(vNr0) == vi)
			{
				found = true;
				break;
			}
		}
		if (found)
		{
			mVertices[vi]->removeEdge((int32_t)qv1->mEdges[i]);
			ei.deleted = true;
			if (ei.heapPos >= 0)
			{
				heapRemove((uint32_t)ei.heapPos, false);
			}
#if TESTING
			testHeap();
#endif
		}
		else
		{
			ei.replaceVertex(vNr1, vNr0);
			qv0->mEdges.pushBack(qv1->mEdges[i]);
		}
	}
	// remove common edge and update adjacent edges
	for (int32_t i = (int32_t)qv0->mEdges.size() - 1; i >= 0; i--)
	{
		QuadricEdge& ei = mEdges[qv0->mEdges[(uint32_t)i]];
		if (ei.otherVertex(vNr0) == vNr1)
		{
			qv0->mEdges.replaceWithLast((uint32_t)i);
		}
		else
		{
			computeCost(ei);
			if (ei.heapPos >= 0)
			{
				heapUpdate((uint32_t)ei.heapPos);
			}
#if TESTING
			testHeap();
#endif
		}
	}

	// delete collapsed triangles
	for (int32_t i = (int32_t)qv0->mTriangles.size() - 1; i >= 0; i--)
	{
		uint32_t triangleIndex = qv0->mTriangles[(uint32_t)i];
		QuadricTriangle& t = mTriangles[triangleIndex];
		if (!t.deleted && t.containsVertex(vNr1))
		{
			mNumDeletedTriangles++;
			t.deleted = true;
			//fprintf_s(f, "Delete Triangle %d\n", triangleIndex);

			PX_ASSERT(t.containsVertex(vNr0));

			for (uint32_t j = 0; j < 3; j++)
			{
				mVertices[t.vertexNr[j]]->removeTriangle((int32_t)triangleIndex);
				//fprintf_s(f, "  v %d\n", t.vertexNr[j]);
			}
		}
	}
	// update triangles
	for (uint32_t i = 0; i < qv1->mTriangles.size(); i++)
	{
		QuadricTriangle& t = mTriangles[qv1->mTriangles[i]];
		if (t.deleted)
		{
			continue;
		}
		if (t.containsVertex(vNr1))
		{
			qv0->mTriangles.pushBack(qv1->mTriangles[i]);
		}
		t.replaceVertex(vNr1, vNr0);
	}

	mNumDeletedVertices += qv1->bDeleted == 1 ? 0 : 1;
	qv1->bDeleted = 1;
	edge.deleted = true;
	//fclose(f);

#if TESTING
	testMesh();
	testHeap();
#endif
}
uint32_t ApexQuadricSimplifier::simplify(uint32_t subdivision, int32_t maxSteps, float maxError, IProgressListener* progressListener)
{
	float maxLength = 0.0f;

	uint32_t nbCollapsed = 0;

	if (subdivision > 0)
	{
		maxLength = (mBounds.minimum - mBounds.maximum).magnitude() / subdivision;
	}

	uint32_t progressCounter = 0;
	uint32_t maximum = maxSteps >= 0 ? maxSteps : mHeap.size();

	HierarchicalProgressListener progress(100, progressListener);
	progress.setSubtaskWork(90, "Isomesh simplicifaction");
#if TESTING
	testHeap();
#endif

	while (maxSteps == -1 || (maxSteps-- > 0))
	{

		if ((++progressCounter & 0xff) == 0)
		{
			const int32_t percent = (int32_t)(100 * progressCounter / maximum);
			progress.setProgress(percent);
		}

		bool edgeFound = false;
		QuadricEdge* e = NULL;
		while (mHeap.size() - mNumDeletedHeapElements > 1)
		{
			e = mHeap[1];

			if (maxError >= 0 && e->cost > maxError)
			{
				// get me out of here
				edgeFound = false;
				break;
			}

			if (legalCollapse(*e, maxLength))
			{
				heapRemove(1, false);
#if TESTING
				testHeap();
#endif
				edgeFound = true;
				break;
			}
			uint32_t vNr0 = e->vertexNr[0];
			uint32_t vNr1 = e->vertexNr[1];
			QuadricVertex* qv0 = mVertices[vNr0];
			QuadricVertex* qv1 = mVertices[vNr1];
			heapRemove(1, qv0->bDeleted == 0 && qv1->bDeleted == 0);
#if TESTING
			testHeap();
#endif
		}

		if (!edgeFound)
		{
			break;
		}

		collapseEdge(*e);
		nbCollapsed++;
	}

	progress.completeSubtask();
	progress.setSubtaskWork(10, "Heap rebuilding");

	progressCounter = mNumDeletedHeapElements;
	while (mNumDeletedHeapElements > 0)
	{
		if ((mNumDeletedHeapElements & 0x7f) == 0)
		{
			const int32_t percent =  (int32_t)(100 * (progressCounter - mNumDeletedHeapElements) / progressCounter);
			progress.setProgress(percent);
		}
#if TESTING
		testHeap();
#endif
		mNumDeletedHeapElements--;
		heapUpdate(mHeap.size() - 1 - mNumDeletedHeapElements);
	}

	progress.completeSubtask();
#if TESTING
	testHeap();
#endif
	return nbCollapsed;
}
Exemplo n.º 13
0
int main(int argc, char *argv[])
{
    size_t size;
    int version;
    CMEM_BlockAttrs attrs;
    int i;
    int c;
    
    non_interactive_flag = FALSE;

    while ((c = getopt(argc, argv, "n")) != -1) {
	switch (c) {
	case 'n':
	    non_interactive_flag = TRUE; 	
	    break;

	default:
	    fprintf(stderr, "Usage: %s [-n] <Number of bytes to allocate>\n",
		    argv[0]);
	    fprintf(stderr,
                    "    -n: non-interactive mode (no ENTER prompts)\n");
	    exit(EXIT_FAILURE);
	}
    }

    if ((argc - optind + 1) != 2) {
	fprintf(stderr, "Usage: %s [-n] <Number of bytes to allocate>\n",
	        argv[0]);
	fprintf(stderr, "    -n: non-interactive mode (no ENTER prompts)\n");
	exit(EXIT_FAILURE);
    }

    errno = 0;
    size = strtol(argv[optind], NULL, 0);

    if (errno) {
	fprintf(stderr, "Bad argument ('%s'), strtol() set errno %d\n",
	        argv[optind], errno);
        exit(EXIT_FAILURE);
    }

    /* First initialize the CMEM module */
    if (CMEM_init() == -1) {
        fprintf(stderr, "Failed to initialize CMEM\n");
        exit(EXIT_FAILURE);
    }

    printf("CMEM initialized.\n");

    version = CMEM_getVersion();
    if (version == -1) {
	fprintf(stderr, "Failed to retrieve CMEM version\n");
        exit(EXIT_FAILURE);
    }
    printf("CMEM version = 0x%x\n", version);

    testMap(size);
    testAllocPhys(size);

    testCMA(size);

    if (CMEM_getNumBlocks(&nblocks)) {
	fprintf(stderr, "Failed to retrieve number of blocks\n");
        exit(EXIT_FAILURE);
    }
    printf("\n# of CMEM blocks (doesn't include possible CMA global 'block'): %d\n", nblocks);

    if (nblocks) {
	for (i = 0; i < nblocks; i++) {
	    if (CMEM_getBlockAttrs(i, &attrs) == -1) {
		fprintf(stderr, "Failed to retrieve CMEM memory block %d bounds\n", i);
	    }
	    else {
		printf("CMEM memory block %d: phys start = %#llx, size = %#llx\n",
		       i, (unsigned long long)attrs.phys_base, attrs.size);
	    }

	    testHeap(size, i);
	    testHeap(size, i);
	    testPools(size, i);
	    testPools(size, i);
	    testCache(size, i);
	}
    }
    else {
	printf("    no physical block found, not performing block-based testing\n");
    }

    /* block 'nblocks' is the special CMEM CMA "block" */
    testPools(size, CMEM_CMABLOCKID);

    printf("\nexiting...\n");
    if (CMEM_exit() < 0) {
        fprintf(stderr, "Failed to finalize the CMEM module\n");
    }
    printf("...test done\n");

    exit(EXIT_SUCCESS);
}