Example #1
0
//-*****************************************************************************
void init( void )
{
    {
        GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
        GLfloat mat_shininess[] = { 100.0 };
        GLfloat mat_front_emission[] = {0.0, 0.0, 0.0, 0.0 };
        GLfloat mat_back_emission[] = {1.0f, 0.0, 0.0, 1.0f };

        glClearColor( 0.0, 0.0, 0.0, 0.0 );
        glMaterialfv( GL_FRONT, GL_EMISSION, mat_front_emission );
        glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular );
        glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess );

        glMaterialfv( GL_BACK, GL_EMISSION, mat_back_emission );
        glMaterialfv( GL_BACK, GL_SPECULAR, mat_specular );
        glMaterialfv( GL_BACK, GL_SHININESS, mat_shininess );

        glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
        glEnable(GL_COLOR_MATERIAL);
    }

    glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE );
    glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_AUTO_NORMAL);
    glEnable(GL_NORMALIZE);

    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

    glDisable(GL_CULL_FACE);

    glShadeModel( GL_SMOOTH );

    g_state.scene.cam.setSize( 800, 600 );
    g_state.scene.cam.lookAt( V3d( 24, 18, 24 ), V3d( 0.0 ) );
    g_state.bMask = 0;
    g_state.showHelp = false;
    g_state.playback = kStopped;
    g_state.scene.pointSize = 3.0f;
    glPointSize( 3.0f );

    init_surface();

    setMaterials( 1.0, false );

    g_state.scene.cam.frame( g_transport->getBounds() );

    std::ostringstream titleStream;
    titleStream << "Archive = " 
                << g_transport->getFileName()
                << " | Frame = "
                << g_transport->getCurrentFrame();
    glutSetWindowTitle( titleStream.str().c_str() );
}
void Mesh::processMesh()
{
	_totalNumberOfIntervalsX = 0;
	_totalNumberOfIntervalsY = 0;
	_totalNumberOfIntervalsZ = 0;

	for (auto i = 0; i < _emountOfIntervalsX.size(); i++)
	{
		_totalNumberOfIntervalsX += _emountOfIntervalsX[i];
	}

	for (auto i = 0; i < _emountOfIntervalsY.size(); i++)
	{
		_totalNumberOfIntervalsY += _emountOfIntervalsY[i];
	}

	for (auto i = 0; i < _emountOfIntervalsZ.size(); i++)
	{
		_totalNumberOfIntervalsZ += _emountOfIntervalsZ[i];
	}

	x.resize((_totalNumberOfIntervalsX + 1)*(_totalNumberOfIntervalsY + 1));
	y.resize((_totalNumberOfIntervalsX + 1)*(_totalNumberOfIntervalsY + 1));
	z.resize(_totalNumberOfIntervalsZ + 1);

	for (auto i = 0; i < y.size(); i++)
	{
		y[i] = -1;
	}

	std::vector<double> resultX;
	std::vector<double> resultY;
	std::vector<double> squareCoordinatesX;
	std::vector<double> squareCoordinatesY;
	squareCoordinatesX.resize(4);
	squareCoordinatesY.resize(4);
	int sizeOfResult;

	int startPosition = 0;
	for (auto i = 0; i < _emountOfReferenceNodesY - 1; i++)
	{
		for (auto j = 0; j < _emountOfReferenceNodesX - 1; j++)
		{
			sizeOfResult = (_emountOfIntervalsX[j] + 1)*(_emountOfIntervalsY[i] + 1);
			resultX.resize(sizeOfResult);
			resultY.resize(sizeOfResult);

			squareCoordinatesX[0] = _referenceNodesX[j + i * (_emountOfReferenceNodesX)];
			squareCoordinatesX[1] = _referenceNodesX[j + 1 + i * (_emountOfReferenceNodesX)];
			squareCoordinatesX[2] = _referenceNodesX[j + (i + 1) * (_emountOfReferenceNodesX)];
			squareCoordinatesX[3] = _referenceNodesX[j + 1 + (i + 1) * (_emountOfReferenceNodesX)];

			squareCoordinatesY[0] = _referenceNodesY[j + i * (_emountOfReferenceNodesX)];
			squareCoordinatesY[1] = _referenceNodesY[j + 1 + i * (_emountOfReferenceNodesX)];
			squareCoordinatesY[2] = _referenceNodesY[j + (i + 1) * (_emountOfReferenceNodesX)];
			squareCoordinatesY[3] = _referenceNodesY[j + 1 + (i + 1) * (_emountOfReferenceNodesX)];

			processSquare(squareCoordinatesX, squareCoordinatesY,
				_coefficientOfExpansionX[j],
				_coefficientOfExpansionY[i],
				_emountOfIntervalsX[j],
				_emountOfIntervalsY[i],
				resultX,
				resultY);

			insertPoints(j,
				i,
				_emountOfIntervalsX[j],
				_emountOfIntervalsY[i],
				resultX,
				resultY,
				x,
				y);

			
		}
		
		// Заполним последнюю ячейку для данного слоя по y.
		// Решил не экономить на этом.
		/*for (auto j = 0; j < _emountOfIntervalsY[i] + 1; j++)
		{
			x[startPosition + j*(_totalNumberOfIntervalsX + 1) + _totalNumberOfIntervalsX] =
				_referenceNodesX[(i + j)*(_emountOfReferenceNodesX)+_emountOfReferenceNodesX - 1];
			y[startPosition + j*(_totalNumberOfIntervalsX + 1) + _totalNumberOfIntervalsX] =
				_referenceNodesY[(i + j)*(_emountOfReferenceNodesX)+_emountOfReferenceNodesX - 1];
		}*/

		startPosition += _emountOfIntervalsY[i] * (_totalNumberOfIntervalsX + 1);
	}

	std::vector<double> pointsToInsert;
	int startPosition1 = 0;
	for (auto i = 0; i < _emountOfLayersZ - 1; i++)
	{
		pointsToInsert = processInterval(_layersZ[i],
			_layersZ[i + 1],
			_coefficientOfExpansionZ[i],
			_emountOfIntervalsZ[i]
			);
		for (auto j = 0; j < pointsToInsert.size() - 1; j++)
		{
			z[startPosition1 + j] = pointsToInsert[j];
		}
		startPosition1 += _emountOfIntervalsZ[i];
	}
	z[z.size() - 1] = _layersZ[_layersZ.size() - 1];

	setMaterials();
	setIndexesOfFiniteElementNodes();
	getListOfEdges();
	getListOfFaces();
}