Ejemplo n.º 1
0
Host::Host(int useless_int)
{
  nb_triangles_h = DefVal::N_TRIANGLES_HOST;
  host_triangles = generateTriangles(0,nb_triangles_h);
  nb_triangles_p = DefVal::N_TRIANGLES_PARASITE;
  paras_triangles = generateTriangles(1,nb_triangles_p);   
  //printf("Host generation ...\n");
}
Ejemplo n.º 2
0
    void generateLink(unsigned short *buffer, int resolution, bool leftLod, bool rightLod, bool upLod, bool downLod, unsigned char *clipBuffer)
    {
        int startVertex = lodFactor;
        int endVertex = resolution - lodFactor - 1;

        if (!leftLod)
        {
            generateTriangles(buffer, resolution, 0, startVertex, startVertex, endVertex, clipBuffer);

            createFace(buffer, -1, 0, lodFactor * resolution, lodFactor * resolution + lodFactor, clipBuffer);
            createFace(buffer, -1, (resolution - 1 - lodFactor) * resolution, (resolution - 1) * resolution, (resolution - 1 - lodFactor) * resolution + lodFactor, clipBuffer);

            //createFace(buffer, -1, 0, lodFactor * resolution, lodFactor);
            //createFace(buffer, -1, (resolution - 1 - lodFactor) * resolution, (resolution - 1 ) * resolution, (resolution - 1 - lodFactor) * resolution + lodFactor);
        }
        else
            generateHorizontal(buffer, resolution, startVertex, -lodFactor, clipBuffer);

        if (!rightLod)
        {
            generateTriangles(buffer, resolution, endVertex, startVertex, resolution - 1, endVertex, clipBuffer);

            createFace(buffer, -1, resolution - 1, resolution * lodFactor + resolution - 1 - lodFactor, resolution * lodFactor + resolution - 1, clipBuffer);
            createFace(buffer, -1, (resolution - 1 - lodFactor) * resolution + resolution - 1 - lodFactor, (resolution - 1) * resolution + resolution - 1, (resolution - 1 - lodFactor) * resolution + resolution - 1, clipBuffer);

            //createFace(buffer, -1, resolution - 1, resolution * lodFactor + resolution - 1 - lodFactor, resolution * lodFactor + resolution - 1);
            //createFace(buffer, -1, (resolution - 1) * resolution + resolution - 1 - lodFactor, (resolution - 1) * resolution + resolution - 1, (resolution - 1 - lodFactor) * resolution + resolution - 1);
        }
        else
            generateHorizontal(buffer, resolution, endVertex, lodFactor, clipBuffer);

        if (!upLod)
        {
            generateTriangles(buffer, resolution, startVertex, 0, endVertex, startVertex, clipBuffer);

            createFace(buffer, -1, 0, resolution * lodFactor + lodFactor, lodFactor, clipBuffer);
            createFace(buffer, -1, resolution - 1, endVertex, lodFactor * resolution + endVertex, clipBuffer);

            //createFace(buffer, -1, resolution * lodFactor, resolution * lodFactor + lodFactor, lodFactor);
            //createFace(buffer, -1, resolution - 1, endVertex, lodFactor * resolution + endVertex);
        }
        else
            generateVertical(buffer, resolution, startVertex, -lodFactor, clipBuffer);

        if (!downLod)
        {
            generateTriangles(buffer, resolution, startVertex, endVertex, endVertex, resolution - 1, clipBuffer);

            createFace(buffer, -1, (resolution - 1) * resolution, (resolution - 1) * resolution + lodFactor, (resolution - 1 - lodFactor) * resolution + lodFactor, clipBuffer);
            createFace(buffer, -1, (resolution - 1) * resolution + resolution - 1 - lodFactor, (resolution - 1) * resolution + resolution - 1, (resolution - 1 - lodFactor) * resolution + resolution - 1 - lodFactor, clipBuffer);

            //createFace(buffer, -1, (resolution - 1) * resolution, (resolution - 1) * resolution + lodFactor, (resolution - 1 - lodFactor) * resolution + lodFactor);
            //createFace(buffer, -1, (resolution - 1) * resolution + resolution - 1 - lodFactor, (resolution - 1 - lodFactor) * resolution + resolution - 1, (resolution - 1 - lodFactor) * resolution + resolution - 1 - lodFactor);
        }
        else
            generateVertical(buffer, resolution, endVertex, lodFactor, clipBuffer);
    }
Ejemplo n.º 3
0
		void generateCenter(unsigned short *buffer, int resolution, unsigned char *clipBuffer)
		{
			int startVertex = lodFactor;
			int endVertex = resolution - lodFactor - 1;

			generateTriangles(buffer, resolution, startVertex, startVertex, endVertex, endVertex, clipBuffer);
		}
Ejemplo n.º 4
0
int main() {
    
    // generate example data to work with. just 2 layers with a differently sloped line
    int n1 = 3;
    int n2 = 12;

    int l1[n1][2];
    int l2[n2][2];

    int i = 0;

    for(i=0; i<n1; i++) {
        l1[i][0] = i;
        l1[i][1] = i*2;
    }

    for(i=0; i<n2; i++) {
        l2[i][0] = i;
        l2[i][1] = i/2;
    }
    
    // do triangle generation
    int triangles[n1+n2][3][3];
    
    generateTriangles(triangles, l1, n1, 100, l2, n2, 101);

    // print results
    for(i=0; i<n1+n2; i++) {
        printTriangle(triangles[i]);
    }

    return 0;
}
Ejemplo n.º 5
0
void MarchingCubes::drawTriangleBuffer()
{
	//if(dataChanged) generateTriangles();	
	if(dataChangedGlobal)
	{
		trianglesCount = 0;
		for(int i=0; i<DATA_CHANGE_DIV; i++)
		{
			for(int j=0; j<DATA_CHANGE_DIV; j++)
			{
				for(int k=0; k<DATA_CHANGE_DIV; k++)
				{
					if( dataChanged[ i*DATA_CHANGE_DIV*DATA_CHANGE_DIV + j*DATA_CHANGE_DIV + k ] )
					{

						generateTriangles( 
							i*dataChangedWidth, dataChangedWidth, 
							j*dataChangedHeight, dataChangedHeight,
							k*dataChangedDepth, dataChangedDepth );
					}
				}
			}
		}
		dataChangedGlobal = false;
	}
	if( trianglesCount == 0 ) return;

	glEnableClientState( GL_VERTEX_ARRAY );
	glEnableClientState( GL_NORMAL_ARRAY );

	
	glVertexPointer( 3, GL_FLOAT, 0, triangles );
	glNormalPointer( GL_FLOAT, 0, normals );

	GLboolean culling;
	glGetBooleanv( GL_CULL_FACE, &culling );
	if( culling ) glDisable( GL_CULL_FACE );/**/
						
	glMatrixMode(GL_MODELVIEW);	
	glPushMatrix();

		glTranslatef( position.x, position.y, position.z );
		glScalef( scale.x, scale.y, scale.z );
		glDrawArrays( GL_TRIANGLES, 0, trianglesCount );

	glPopMatrix();

	if( culling ) glEnable( GL_CULL_FACE );/**/

	glDisableClientState( GL_VERTEX_ARRAY );
	glDisableClientState( GL_NORMAL_ARRAY );

}
Ejemplo n.º 6
0
		void generateCenters(int resolution, int lodFactor_, int mask, unsigned char *clipBuffer)
		{
			faceAmount = 0;
			lodFactor = lodFactor_;

			int bufferSize = (resolution - lodFactor) * (resolution - lodFactor) * 2;
			indexBuffer.create(bufferSize, false);

			unsigned short *buffer = indexBuffer.lock();
			if(!buffer)
				return;

			int startVertex = 1;
			int endVertex = resolution - 1;
			int delta = (endVertex - startVertex) / lodFactor;

			// ToDo: general version
			assert(mask >= 0);
			assert(mask <= CENTER_BLOCK_AMOUNT);

			if(mask & 1)
			{
				int x = 0;
				int y = 0;

				int x1 = (startVertex + x * delta) / CENTER_BLOCK_SIZE * lodFactor;
				int y1 = (startVertex + y * delta) / CENTER_BLOCK_SIZE * lodFactor;
				int x2 = (startVertex + (x + 1) * delta) / CENTER_BLOCK_SIZE * lodFactor;
				int y2 = (startVertex + (y + 1) * delta) / CENTER_BLOCK_SIZE * lodFactor;

				generateTriangles(buffer, resolution, x1, y1, x2, y2, clipBuffer);
			}
			if(mask & 2)
			{
				int x = 1;
				int y = 0;

				int x1 = (startVertex + x * delta) / CENTER_BLOCK_SIZE * lodFactor;
				int y1 = (startVertex + y * delta) / CENTER_BLOCK_SIZE * lodFactor;
				int x2 = (startVertex + (x + 1) * delta) / CENTER_BLOCK_SIZE * lodFactor;
				int y2 = (startVertex + (y + 1) * delta) / CENTER_BLOCK_SIZE * lodFactor;

				generateTriangles(buffer, resolution, x1, y1, x2, y2, clipBuffer);
			}
			if(mask & 4)
			{
				int x = 0;
				int y = 1;

				int x1 = (startVertex + x * delta) / CENTER_BLOCK_SIZE * lodFactor;
				int y1 = (startVertex + y * delta) / CENTER_BLOCK_SIZE * lodFactor;
				int x2 = (startVertex + (x + 1) * delta) / CENTER_BLOCK_SIZE * lodFactor;
				int y2 = (startVertex + (y + 1) * delta) / CENTER_BLOCK_SIZE * lodFactor;

				generateTriangles(buffer, resolution, x1, y1, x2, y2, clipBuffer);
			}
			if(mask & 8)
			{
				int x = 1;
				int y = 1;

				int x1 = (startVertex + x * delta) / CENTER_BLOCK_SIZE * lodFactor;
				int y1 = (startVertex + y * delta) / CENTER_BLOCK_SIZE * lodFactor;
				int x2 = (startVertex + (x + 1) * delta) / CENTER_BLOCK_SIZE * lodFactor;
				int y2 = (startVertex + (y + 1) * delta) / CENTER_BLOCK_SIZE * lodFactor;

				generateTriangles(buffer, resolution, x1, y1, x2, y2, clipBuffer);
			}

			faceAmount /= 3;
			indexBuffer.unlock();
		}
Ejemplo n.º 7
0
void CAdjacent::calcAdjacent(ushort*idx,uint count){
	reset();
	generateEdges(idx,count);
	generateTriangles(idx,count);
}
Ejemplo n.º 8
0
    void generateCenters(IndexStorage16& storage, int resolution, int lodFactor_, int mask, unsigned char *clipBuffer)
    {
        faceAmount = 0;
        lodFactor = lodFactor_;

        int idxCount = (resolution - lodFactor) * (resolution - lodFactor);

        allocId = storage.alloc(idxCount);
        if (!allocId)
            return;

        uint16_t* buffer = storage.lock(allocId);

        int startVertex = 1;
        int endVertex = resolution - 1;
        int delta = (endVertex - startVertex) / lodFactor;

        // ToDo: general version
        assert(mask >= 0);
        assert(mask <= CENTER_BLOCK_AMOUNT);

        if (mask & 1)
        {
            int x = 0;
            int y = 0;

            int x1 = (startVertex + x * delta) / CENTER_BLOCK_SIZE * lodFactor;
            int y1 = (startVertex + y * delta) / CENTER_BLOCK_SIZE * lodFactor;
            int x2 = (startVertex + (x + 1) * delta) / CENTER_BLOCK_SIZE * lodFactor;
            int y2 = (startVertex + (y + 1) * delta) / CENTER_BLOCK_SIZE * lodFactor;

            generateTriangles(buffer, resolution, x1, y1, x2, y2, clipBuffer);
        }
        if (mask & 2)
        {
            int x = 1;
            int y = 0;

            int x1 = (startVertex + x * delta) / CENTER_BLOCK_SIZE * lodFactor;
            int y1 = (startVertex + y * delta) / CENTER_BLOCK_SIZE * lodFactor;
            int x2 = (startVertex + (x + 1) * delta) / CENTER_BLOCK_SIZE * lodFactor;
            int y2 = (startVertex + (y + 1) * delta) / CENTER_BLOCK_SIZE * lodFactor;

            generateTriangles(buffer, resolution, x1, y1, x2, y2, clipBuffer);
        }
        if (mask & 4)
        {
            int x = 0;
            int y = 1;

            int x1 = (startVertex + x * delta) / CENTER_BLOCK_SIZE * lodFactor;
            int y1 = (startVertex + y * delta) / CENTER_BLOCK_SIZE * lodFactor;
            int x2 = (startVertex + (x + 1) * delta) / CENTER_BLOCK_SIZE * lodFactor;
            int y2 = (startVertex + (y + 1) * delta) / CENTER_BLOCK_SIZE * lodFactor;

            generateTriangles(buffer, resolution, x1, y1, x2, y2, clipBuffer);
        }
        if (mask & 8)
        {
            int x = 1;
            int y = 1;

            int x1 = (startVertex + x * delta) / CENTER_BLOCK_SIZE * lodFactor;
            int y1 = (startVertex + y * delta) / CENTER_BLOCK_SIZE * lodFactor;
            int x2 = (startVertex + (x + 1) * delta) / CENTER_BLOCK_SIZE * lodFactor;
            int y2 = (startVertex + (y + 1) * delta) / CENTER_BLOCK_SIZE * lodFactor;

            generateTriangles(buffer, resolution, x1, y1, x2, y2, clipBuffer);
        }

        storage.unlock();

        faceAmount /= 3;
        baseIndex = storage.baseIndex(allocId);
    }