示例#1
0
void  Box::create(Vector3 origin, float length, float depth, float width)
{
	this->center = origin;
	this->sizeX = length;
	this->sizeY = depth;
	this->sizeZ = width;

 	Vector3 V0(origin.x()-(length/2), origin.y()-(depth/2), origin.z()-(width/2));
 	Vector3 V1(origin.x()+(length/2), origin.y()-(depth/2), origin.z()-(width/2));
 	Vector3 V2(origin.x()+(length/2), origin.y()+(depth/2), origin.z()-(width/2));
	Vector3 V3(origin.x()-(length/2), origin.y()+(depth/2), origin.z()-(width/2));
	Vector3 V4(origin.x()-(length/2), origin.y()-(depth/2), origin.z()+(width/2));
	Vector3 V5(origin.x()+(length/2), origin.y()-(depth/2), origin.z()+(width/2));
	Vector3 V6(origin.x()+(length/2), origin.y()+(depth/2), origin.z()+(width/2));
	Vector3 V7(origin.x()-(length/2), origin.y()+(depth/2), origin.z()+(width/2));

	vector<Quadrilateral> Q;
	Q.push_back(Quadrilateral(V0,V1,V5,V4));
	Q.push_back(Quadrilateral(V2,V3,V7,V6));
	Q.push_back(Quadrilateral(V0,V4,V7,V3));
	Q.push_back(Quadrilateral(V5,V1,V2,V6));
	Q.push_back(Quadrilateral(V1,V0,V3,V2));
	Q.push_back(Quadrilateral(V4,V5,V6,V7));
        setFaces(Q);

	calculateMinMax();
}
示例#2
0
	void Tetra::setVertices() {	
		//VERTICES
		//point 1
		points[0].x = x;
		points[0].y = y;
		points[0].z = z+(h/2.0f); 
		//point 2
		points[1].x = x-(w/2.0f); 
		points[1].y = y+(d/2.0f);
		points[1].z = z-(h/2.0f); 
		//point 3
		points[2].x = x+(w/2.0f); 
		points[2].y = y+(d/2.0f);
		points[2].z = z-(h/2.0f); 
		//point 4
		points[3].x = x; 
		points[3].y = y-(d/2.0f);
		points[3].z = z-(h/2.0f); 
		
		
		//COLORS
		//point 1
		pointColors[0].r = red;
		pointColors[0].g = green;
		pointColors[0].b = blue; 
		
		applyGradient();
		
		//point 2
		pointColors[1].r = red+redShift;
		pointColors[1].g = green+greenShift;
		pointColors[1].b = blue+blueShift; 
		//point 3
		pointColors[2].r = red+redShift;
		pointColors[2].g = green+greenShift;
		pointColors[2].b = blue+blueShift; 
		//point 4
		pointColors[3].r = red+redShift;
		pointColors[3].g = green+greenShift;
		pointColors[3].b = blue+blueShift; 
		
		
		setFaces();
	}
示例#3
0
void Foam::writeFaceSet
(
    const bool binary,
    const vtkMesh& vMesh,
    const faceSet& set,
    const fileName& fileName
)
{
    const faceList& faces = vMesh.mesh().faces();

    std::ofstream ostr(fileName.c_str());

    writeFuns::writeHeader
    (
        ostr,
        binary,
        set.name()
    );

    ostr<< "DATASET POLYDATA" << std::endl;

    //------------------------------------------------------------------
    //
    // Write topology
    //
    //------------------------------------------------------------------


    // Construct primitivePatch of faces in faceSet.

    faceList setFaces(set.size());
    labelList setFaceLabels(set.size());
    label setFacei = 0;

    forAllConstIter(faceSet, set, iter)
    {
        setFaceLabels[setFacei] = iter.key();
        setFaces[setFacei] = faces[iter.key()];
        setFacei++;
    }
// cubo //////////////////////////////////////////////////////////////
//    v6----- v5
//   /|      /|
//  v1------v0|
//  | |     | |
//  | |v7---|-|v4
//  |/      |/
//  v2------v3
Model_Cube::Model_Cube(float size)
{

    setColor(0,1,0,1);

    vector<_vertex3f> vertices;
    vector<_vertex3i> caras;

	// Vertices
	vertices.push_back(_vertex3f(-size,	-size, 	size));
	vertices.push_back(_vertex3f(size,	-size, 	size));
	vertices.push_back(_vertex3f(size, 	size, 	size));
	vertices.push_back(_vertex3f(-size, 	size, 	size));

    vertices.push_back(_vertex3f(-size,	-size,	 -size));
    vertices.push_back(_vertex3f(size,	-size,	 -size));
    vertices.push_back(_vertex3f(size,	 size,	 -size));
    vertices.push_back(_vertex3f(-size,	 size,	 -size));

    // Caras
    caras.push_back(_vertex3i(0, 1, 4));
    caras.push_back(_vertex3i(1, 5, 4));
    caras.push_back(_vertex3i(1, 2, 5));
    caras.push_back(_vertex3i(2, 6, 5));
    caras.push_back(_vertex3i(2, 3, 6));
    caras.push_back(_vertex3i(3, 7, 6));
    caras.push_back(_vertex3i(3, 0, 7));
    caras.push_back(_vertex3i(0, 4, 7));
    caras.push_back(_vertex3i(4, 5, 7));
    caras.push_back(_vertex3i(5, 6, 7));
    caras.push_back(_vertex3i(3, 2, 0));
    caras.push_back(_vertex3i(2, 1, 0));

    setVertices(vertices);
    setFaces(caras);

}
// piramide /////////////////////////////////////////////
//     /\.
//    / |\/.
//   /  | \/ .
//  /   |  \/./
// /____|___\/
Model_Pyramid::Model_Pyramid(float size)
{
    vector<_vertex3f> vertices;
    vector<_vertex3i> caras;

	// Vertices
	vertices.push_back(_vertex3f(-size,	-size, 	size));
	vertices.push_back(_vertex3f(size,	-size, 	size));
	vertices.push_back(_vertex3f(size, 	size, 	size));
	vertices.push_back(_vertex3f(-size, 	size, 	size));
	vertices.push_back(_vertex3f(0,	0,	 size*3)); // punta de la piramide

	// Caras
	caras.push_back(_vertex3i(1, 0, 3));
	caras.push_back(_vertex3i(1, 3, 2));
	caras.push_back(_vertex3i(0, 1, 4));
	caras.push_back(_vertex3i(0, 4, 3));
	caras.push_back(_vertex3i(3, 4, 2));
	caras.push_back(_vertex3i(1, 2, 4));

	setVertices(vertices);
    setFaces(caras);

}
void Model_Revolution::generarPorPerfil(vector<_vertex3f> perfil, int steps)
{
    double angle;
    vector<_vertex3i> caras;
    vector<_vertex3f> vertices(perfil);

    angle = (2.0*M_PI) / steps;

    // Generamos la parte principal

    for (int step = 0; step < steps; step++)
    {
        vector<_vertex3f> siguientePerfil(perfil.size());
        // Generamos los puntos rodaso
        for (unsigned int k = 0; k < perfil.size(); k++)
            siguientePerfil[k] = rotateY(perfil[k], angle);

        // Añadimos los vertices al final del vector
        vertices.insert(vertices.end(), siguientePerfil.begin(), siguientePerfil.end() );

        // Generamos las caras
        unsigned int inicioPerfil, finPerfil;
        inicioPerfil = step * perfil.size();
        finPerfil = inicioPerfil + perfil.size();

        for (unsigned int i = inicioPerfil+1, k = finPerfil+1; i < finPerfil; i++, k++)
        {
            caras.push_back(_vertex3i(i-1, k-1, k));
            caras.push_back(_vertex3i(i-1, k,   i));
        }

        perfil = siguientePerfil;

    }

    // Generamos las tapas

    // Generamos la tapa de abajo
    if (vertices.front().x)
    {
        // Agregamos el punto central, aunque no es necesario porque solo pintamos las caras
        _vertex3f puntoCentral(0.0, vertices.front().y, 0.0);
        vertices.push_back(puntoCentral);

        for (int step = 0; step < steps; step++)
        {
            int perfilactual = step * perfil.size();
            int siguientePerfil = perfilactual + perfil.size();
            caras.push_back(_vertex3i(vertices.size()-1, siguientePerfil, perfilactual));

        }

    }

    // Generamos la tapa de arriba
    if (vertices[perfil.size() - 1].x)
    {

        // Agregamos el punto central, aunque no es necesario porque solo pintamos las caras
        _vertex3f puntoCentral(0.0, vertices[perfil.size() - 1].y, 0.0);
        vertices.push_back(puntoCentral);

        for (int step = 0; step < steps; step++)
        {
            int perfilactual = (step+1) * perfil.size() -1;
            int siguientePerfil = perfilactual + perfil.size();
            caras.push_back(_vertex3i(vertices.size()-1, perfilactual,siguientePerfil)); // Hay que ponerlos al revés que en la otra tapa para que calcule bien las normales

        }

    }

    setVertices(vertices);
    setFaces(caras);

    // Calcular coordenadas de textura
    calcular_coord_textura(steps, perfil.size());

}
示例#7
0
	void Room::setVertices() {		
		
		setFaces();
	}
示例#8
0
	/*Cube::~Cube() {
		Shape::~Shape();
	}*/
	void Cube::setVertices() {	
		//VERTICES
		//point 1
		points[0].x = x-(w/2.0f);
		points[0].y = y+(d/2);
		points[0].z = z+(h/2.0f); 
		//point 2
		points[1].x = x-(w/2.0f); 
		points[1].y = y+(d/2); 
		points[1].z = z-(h/2);
		//point 3
		points[2].x = x+(w/2.0f); 
		points[2].y = y+(d/2.0f);
		points[2].z = z-(h/2.0f); 
		//point 4
		points[3].x = x+(w/2.0f); 
		points[3].y = y+(d/2.0f);
		points[3].z = z+(h/2.0f);
		
		//point 5
		points[4].x = x+(w/2.0f);
		points[4].y = y-(d/2.0f);
		points[4].z = z+(h/2.0f); 
		//point 6
		points[5].x = x+(w/2.0f); 
		points[5].y = y-(d/2.0f);
		points[5].z = z-(h/2.0f); 
		//point 7
		points[6].x = x-(w/2.0f); 
		points[6].y = y-(d/2.0f);
		points[6].z = z-(h/2.0f); 
		//point 8
		points[7].x = x-(w/2.0f); 
		points[7].y = y-(d/2.0f);
		points[7].z = z+(h/2.0f); 

		//COLORS
		//point 1
		pointColors[0].r = red;
		pointColors[0].g = green;
		pointColors[0].b = blue; 
		//point 2
		pointColors[1].r = red;
		pointColors[1].g = green;
		pointColors[1].b = blue; 
		//point 5
		pointColors[4].r = red+redShift;
		pointColors[4].g = green+greenShift;
		pointColors[4].b = blue+blueShift; 
		//point 6
		pointColors[5].r = red+redShift;
		pointColors[5].g = green+greenShift;
		pointColors[5].b = blue+blueShift; 
		
		applyGradient();
		
		//point 3
		pointColors[2].r = red;
		pointColors[2].g = green;
		pointColors[2].b = blue; 
		//point 4
		pointColors[3].r = red;
		pointColors[3].g = green;
		pointColors[3].b = blue;
		//point 7
		pointColors[6].r = red+redShift;
		pointColors[6].g = green+greenShift;
		pointColors[6].b = blue+blueShift; 
		//point 8
		pointColors[7].r = red+redShift;
		pointColors[7].g = green+greenShift;
		pointColors[7].b = blue+blueShift; 
		
		//now assemble faces
		setFaces();
	}
void faceSet::sync(const polyMesh& mesh)
{
    const polyBoundaryMesh& patches = mesh.boundaryMesh();

    label nAdded = 0;

    if (Pstream::parRun())
    {
        // Send faces in set that are on a processorPatch. Send as patch face
        // indices.
        forAll(patches, patchI)
        {
            const polyPatch& pp = patches[patchI];

            if (isType<processorPolyPatch>(pp))
            {
                const processorPolyPatch& procPatch =
                    refCast<const processorPolyPatch>(pp);

                // Convert faceSet locally to labelList.
                DynamicList<label> setFaces(pp.size());

                forAll(pp, i)
                {
                    if (found(pp.start() + i))
                    {
                        setFaces.append(i);
                    }
                }
                setFaces.shrink();

                OPstream toNeighbour
                (
                    Pstream::blocking,
                    procPatch.neighbProcNo()
                );

                toNeighbour << setFaces;
            }
        }

        // Receive 
        forAll(patches, patchI)
        {
            const polyPatch& pp = patches[patchI];

            if (isType<processorPolyPatch>(pp))
            {
                const processorPolyPatch& procPatch =
                    refCast<const processorPolyPatch>(pp);

                IPstream fromNeighbour
                (
                    Pstream::blocking,
                    procPatch.neighbProcNo()
                );

                labelList setFaces(fromNeighbour);

                forAll(setFaces, i)
                {
                    if (insert(pp.start() + setFaces[i]))
                    {
                        nAdded++;
                    }
                }
            }
        }
    }

    // Couple cyclic patches
    forAll (patches, patchI)
    {
        const polyPatch& pp = patches[patchI];

        if (typeid(pp) == typeid(cyclicPolyPatch))
        {
            const cyclicPolyPatch& cycPatch =
                refCast<const cyclicPolyPatch>(pp);

            forAll (cycPatch, i)
            {
                label thisFaceI = cycPatch.start() + i;
                label otherFaceI = cycPatch.transformGlobalFace(thisFaceI);

                if (found(thisFaceI))
                {
                    if (insert(otherFaceI))
                    {
                        nAdded++;
                    }
                }
                else if (found(otherFaceI))
                {
                    if (insert(thisFaceI))
                    {
                        nAdded++;
                    }
                }
            }
        }
    }