当前位置: 首页>>代码示例>>C++>>正文


C++ Program类代码示例

本文整理汇总了C++中Program的典型用法代码示例。如果您正苦于以下问题:C++ Program类的具体用法?C++ Program怎么用?C++ Program使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Program类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: make

	static Program make(void)
	{
		Program result;

		VertexShader vs;
		vs.Source(
			"#version 330\n"
			"#define side 128\n"

			"uniform mat4 ProjectionMatrix, CameraMatrix, LightProjMatrix, LightMatrix;"
			"uniform vec3 CameraPos, LightPos;"
			"uniform float Fade;"
			"uniform sampler2D Offsets;"
			"uniform sampler2D Heights;"

			"in vec4 Position;"
			"in vec3 Normal;"

			"out vec4 vertShadowCoord;"
			"out vec3 vertViewDir;"
			"out vec3 vertLightDir;"
			"out vec3 vertNormal;"
			"out float vertLight;"

			"void main(void)"
			"{"
			"	ivec2 Coord = ivec2(gl_InstanceID%side, gl_InstanceID/side);"
			"	vec2 Offs = texelFetch(Offsets, Coord, 0).xy;"
			"	float Depth = texelFetch(Heights, Coord, 0).r;"
			"	float Height = 1.0-Depth;"
			"	gl_Position = Position;"
			"	gl_Position.xz += Offs;"
			"	float l = (1.0-dot(Normal, vec3(0,1,0))*0.5)*0.8;"
			"	vertLight = (1.0-gl_Position.y*l)*sign(Height)*Fade;"
			"	gl_Position.y  *= max(Height*Fade*side/2, 0.5);"
			"	vertViewDir = CameraPos - gl_Position.xyz;"
			"	vertLightDir = LightPos - gl_Position.xyz;"
			"	vertShadowCoord = LightProjMatrix * LightMatrix * gl_Position;"
			"	gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
			"	vertNormal = Normal;"
			"}"
		).Compile();

		FragmentShader fs;
		fs.Source(
			"#version 330\n"
			"uniform sampler2DShadow Shadows;"

			"const vec3 LightDir = normalize(vec3(1, 0.3, 1));"
			"const vec3 BarColor = vec3(0.4, 0.4, 0.4);"

			"in vec4 vertShadowCoord;"
			"in vec3 vertViewDir;"
			"in vec3 vertLightDir;"
			"in vec3 vertNormal;"
			"in float vertLight;"

			"out vec3 fragColor;"

			"void main(void)"
			"{"
			"	vec3 Normal = normalize(vertNormal);"
			"	vec3 ViewDir = normalize(vertViewDir);"
			"	vec3 LightDir = normalize(vertLightDir);"
			"	vec3 LightRefl = reflect(-LightDir, Normal);"
			"	vec3 ShadowCoord = (vertShadowCoord.xyz/vertShadowCoord.w)*0.5 + 0.5;"
			"	float shdw = texture(Shadows, ShadowCoord);"
			"	float ambi = 0.15;"
			"	float diff = pow(max(dot(Normal, LightDir)+0.1, 0.0),2.0)*0.9;"
			"	float spec = pow(max(dot(ViewDir, LightRefl), 0.0), 32.0)*0.4;"
			"	float emis = pow(vertLight, 2.0)*0.7;"
			"	fragColor = "
			"		BarColor * (diff*shdw+ambi)+"
			"		vec3(1.0, 1.0, 1.0)*spec*shdw+"
			"		vec3(0.1, 1.0, 0.3)*emis;"
			"}"
		).Compile();

		result.AttachShader(vs).AttachShader(fs);
		result.Link().Validate().Use();
		return std::move(result);
	}
开发者ID:Extrunder,项目名称:oglplus,代码行数:82,代码来源:030_pin_display.cpp

示例2: switch

//-----------------------------------------------------------------------
bool FFPTexturing::resolveUniformParams(TextureUnitParams* textureUnitParams, ProgramSet* programSet)
{
	Program* vsProgram = programSet->getCpuVertexProgram();
	Program* psProgram = programSet->getCpuFragmentProgram();
	
	
	// Resolve texture sampler parameter.		
	textureUnitParams->mTextureSampler = psProgram->resolveParameter(textureUnitParams->mTextureSamplerType, textureUnitParams->mTextureSamplerIndex, (uint16)GPV_GLOBAL, "gTextureSampler");
	if (textureUnitParams->mTextureSampler.get() == NULL)
		return false;
	
		
	// Resolve texture matrix parameter.
	if (needsTextureMatrix(textureUnitParams->mTextureUnitState))
	{				
		textureUnitParams->mTextureMatrix = vsProgram->resolveAutoParameterInt(GpuProgramParameters::ACT_TEXTURE_MATRIX, textureUnitParams->mTextureSamplerIndex);
		if (textureUnitParams->mTextureMatrix.get() == NULL)
			return false;
	}

	switch (textureUnitParams->mTexCoordCalcMethod)
	{
	case TEXCALC_NONE:								
		break;

	// Resolve World + View matrices.
	case TEXCALC_ENVIRONMENT_MAP:
	case TEXCALC_ENVIRONMENT_MAP_PLANAR:	
	case TEXCALC_ENVIRONMENT_MAP_NORMAL:
		
		mWorldITMatrix = vsProgram->resolveAutoParameterInt(GpuProgramParameters::ACT_INVERSE_TRANSPOSE_WORLD_MATRIX, 0);
		if (mWorldITMatrix.get() == NULL)		
			return false;	
		
		mViewMatrix = vsProgram->resolveAutoParameterInt(GpuProgramParameters::ACT_VIEW_MATRIX, 0);
		if (mViewMatrix.get() == NULL)		
			return false;				
		
		break;

	case TEXCALC_ENVIRONMENT_MAP_REFLECTION:
		mWorldMatrix = vsProgram->resolveAutoParameterInt(GpuProgramParameters::ACT_WORLD_MATRIX, 0);
		if (mWorldMatrix.get() == NULL)		
			return false;	

		mWorldITMatrix = vsProgram->resolveAutoParameterInt(GpuProgramParameters::ACT_INVERSE_TRANSPOSE_WORLD_MATRIX, 0);
		if (mWorldITMatrix.get() == NULL)		
			return false;	

		mViewMatrix = vsProgram->resolveAutoParameterInt(GpuProgramParameters::ACT_VIEW_MATRIX, 0);
		if (mViewMatrix.get() == NULL)		
			return false;	

		break;


	case TEXCALC_PROJECTIVE_TEXTURE:

		mWorldMatrix = vsProgram->resolveAutoParameterInt(GpuProgramParameters::ACT_WORLD_MATRIX, 0);
		if (mWorldMatrix.get() == NULL)		
			return false;	

		textureUnitParams->mTextureViewProjImageMatrix = vsProgram->resolveParameter(GCT_MATRIX_4X4, -1, (uint16)GPV_LIGHTS, "gTexViewProjImageMatrix");
		if (textureUnitParams->mTextureViewProjImageMatrix.get() == NULL)		
			return false;	

		const TextureUnitState::EffectMap&		effectMap = textureUnitParams->mTextureUnitState->getEffects();	
		TextureUnitState::EffectMap::const_iterator	effi;

		for (effi = effectMap.begin(); effi != effectMap.end(); ++effi)
		{
			if (effi->second.type == TextureUnitState::ET_PROJECTIVE_TEXTURE)
			{
				textureUnitParams->mTextureProjector = effi->second.frustum;
				break;
			}
		}

		

		if (textureUnitParams->mTextureProjector == NULL)		
			return false;	

		break;
	}

	return true;
}
开发者ID:gbruce,项目名称:ogre3d_trunk,代码行数:89,代码来源:OgreShaderFFPTexturing.cpp

示例3: Execute

	bool Execute(const AnyString& commandLine, uint timeout)
	{
		Program program;
		program.commandLine(commandLine);
		return (program.execute(timeout)) ? (0 == program.wait()) : false;
	}
开发者ID:libyuni,项目名称:libyuni,代码行数:6,代码来源:program.cpp

示例4: TorusExample


//.........这里部分代码省略.........
            "			geomLight = LightPos-tpos+pofs;"
            "			gl_Position = "
            "				ProjectionMatrix *"
            "				CameraMatrix *"
            "				vec4(tpos + pofs, 1.0);"
            "			EmitVertex();"
            "		}"
            "		EndPrimitive();"
            "	}"

            "	geomGlow = 0.0;"
            "	geomTop = 1;"
            "	for(int i=0; i!=3; ++i)"
            "	{"
            "		geomLight = LightPos - (pos[i]+pofs);"
            "		geomNormal = vertNormal[i];"
            "		gl_Position = "
            "			ProjectionMatrix *"
            "			CameraMatrix *"
            "			vec4(pos[i] + pofs, 1.0);"
            "		EmitVertex();"
            "	}"
            "	EndPrimitive();"
            "}"
        );
        gs.Compile();

        transf_prog.AttachShader(vs);
        transf_prog.AttachShader(gs);
        transf_prog.MakeSeparable();
        transf_prog.Link();
        transf_prog.Use();

        ProgramUniform<Vec3f>(transf_prog, "LightPos").Set(4, 4, -8);

        torus.Bind();
        verts.Bind(Buffer::Target::Array);
        {
            std::vector<GLfloat> data;
            GLuint n_per_vertex = make_torus.Positions(data);
            Buffer::Data(Buffer::Target::Array, data);

            VertexAttribArray attr(transf_prog, "Position");
            attr.Setup<GLfloat>(n_per_vertex);
            attr.Enable();
        }

        normals.Bind(Buffer::Target::Array);
        {
            std::vector<GLfloat> data;
            GLuint n_per_vertex = make_torus.Normals(data);
            Buffer::Data(Buffer::Target::Array, data);

            VertexAttribArray attr(transf_prog, "Normal");
            attr.Setup<GLfloat>(n_per_vertex);
            attr.Enable();
        }

        texcoords.Bind(Buffer::Target::Array);
        {
            std::vector<GLfloat> data;
            GLuint n_per_vertex = make_torus.TexCoordinates(data);
            Buffer::Data(Buffer::Target::Array, data);

            VertexAttribArray attr(transf_prog, "TexCoord");
            attr.Setup<GLfloat>(n_per_vertex);
开发者ID:GLDRorg,项目名称:oglplus,代码行数:67,代码来源:024_extruded_torus.cpp

示例5: parseInstructions

Program parseInstructions(const vector<string>& instructionsInText)
{
	regex cpyRgx("cpy ([a-d]|[+-]?\\d+) ([a-d])");
	regex incRgx("inc ([a-d])");
	regex decRgx("dec ([a-d])");
	regex jnzRgx("jnz ([a-d]|[+-]?\\d+) ([a-d]|[+-]?\\d+)");
	regex tglRgx("tgl ([a-z])");
	regex tglOut("out ([a-z])");

	Program p;
	for (const auto& i : instructionsInText)
	{
		Instruction instr;

		smatch m;
		if (regex_match(i, m, cpyRgx))
		{
			auto m1 = m[1].str();
			auto m2 = m[2].str();
			instr.op = Opcode::cpy;
			instr.x = parseOperand(m1);
			instr.y = parseOperand(m2);
		} else if (regex_match(i, m, incRgx))
		{
			auto m1 = m[1].str();
			instr.op = Opcode::inc;
			instr.x = parseOperand(m1);
		} else if (regex_match(i, m, decRgx))
		{
			auto m1 = m[1].str();
			instr.op = Opcode::dec;
			instr.x = parseOperand(m1);
		}
		else if (regex_match(i, m, jnzRgx))
		{
			auto m1 = m[1].str();
			auto m2 = m[2].str();
			instr.op = Opcode::jnz;
			instr.x = parseOperand(m1);
			instr.y = parseOperand(m2);
		}
		else if(regex_match(i, m, tglRgx))
		{
			auto m1 = m[1].str();
			instr.op = Opcode::tgl;
			instr.x = parseOperand(m1);
		}
		else if(regex_match(i, m, tglOut))
		{
			auto m1 = m[1].str();
			instr.op = Opcode::out;
			instr.x = parseOperand(m1);
		}
		else
		{
			assert(0);
			throw runtime_error("Invalid instruction");
		}
		p.push_back(move(instr));
	}
	return p;
}
开发者ID:Jassob,项目名称:advent_of_code_2016,代码行数:62,代码来源:Day25.cpp

示例6: importData

extern void ImportSoftware::importData()
{
    QStringList args;
    args << "-listsoftware";
    Program process;
    process.setArguments(args);
    QXmlStreamReader xml;
    xml.setDevice(&process);
    if(process.open(QIODevice::ReadOnly)){
        QMap<QString,QString> map;
        QString machine;
        while(!process.state()==QProcess::NotRunning){
            if (process.atEnd())
                process.waitForReadyRead();
            xml.readNextStartElement();
            if(xml.isStartElement()){
                if(xml.name()=="softwarelist")
                    machine=xml.attributes().value("name").toString();
                else if(xml.name()=="software"){
                    map.insert("machine",machine);
                    QXmlStreamAttributes attributes=xml.attributes();
                    foreach(QXmlStreamAttribute attribute,attributes.toList())
                        map.insert(attribute.name().toString(),attribute.value().toString());
                }
                else if(xml.name()=="description"){
                    QString description=xml.readElementText();
                    if(description.contains("(")){
                        int index=description.indexOf("(");
                        map.insert("version",description.mid(index+1,description.size()-index-2));
                        description.truncate(index-1);
                    }
                    if(description.contains(" / ")){
                        int index=description.indexOf(" / ");
                        description.truncate(index);
                    }
                    if(description.contains(" - ")){
                        int index=description.indexOf(" - ");
                        map.insert("subtitle",description.mid(index+3));
                        description.truncate(index);
                    }
                    else if(description.contains(": ")){
                        int index=description.indexOf(": ");
                        map.insert("subtitle",description.mid(index+2));
                        description.truncate(index);
                    }
                    map.insert("title",description);
                }
                else if(xml.name()=="year"){
                    map.insert("year",xml.readElementText());
                }
                else if(xml.name()=="publisher"){
                    map.insert("developer",xml.readElementText());
                }
            }
            else if(xml.isEndElement() && xml.name()=="software"){
                dataTable.append(map);
                map.clear();
            }
        }
    }
}
开发者ID:RalfVB,项目名称:SQEW-OS,代码行数:61,代码来源:importsoftware.cpp

示例7: main

int main(void)
{
    GLFWwindow* window;

    // Initialize the library
    if (!glfwInit())
        return -1;

    // Activate supersampling
    glfwWindowHint(GLFW_SAMPLES, 8);

    // Ensure that we get at least a 3.2 context
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);

    // On apple we have to load a core profile with forward compatibility
#ifdef __APPLE__
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif

    // Create a windowed mode window and its OpenGL context
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    // Make the window's context current
    glfwMakeContextCurrent(window);

    #ifndef __APPLE__
      glewExperimental = true;
      GLenum err = glewInit();
      if(GLEW_OK != err)
      {
        /* Problem: glewInit failed, something is seriously wrong. */
       fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
      }
      glGetError(); // pull and savely ignonre unhandled errors like GL_INVALID_ENUM
      fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
    #endif

    int major, minor, rev;
    major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
    minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
    rev = glfwGetWindowAttrib(window, GLFW_CONTEXT_REVISION);
    printf("OpenGL version recieved: %d.%d.%d\n", major, minor, rev);
    printf("Supported OpenGL is %s\n", (const char*)glGetString(GL_VERSION));
    printf("Supported GLSL is %s\n", (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));

    // Initialize the VAO
    // A Vertex Array Object (or VAO) is an object that describes how the vertex
    // attributes are stored in a Vertex Buffer Object (or VBO). This means that
    // the VAO is not the actual object storing the vertex data,
    // but the descriptor of the vertex data.
    VertexArrayObject VAO;
    VAO.init();
    VAO.bind();

    // Initialize the VBO with the vertices data
    // A VBO is a data container that lives in the GPU memory
    VBO.init();

    V.resize(2,6);
    V <<
    0,  0.5, -0.5, 0.1,  0.6, -0.4,
    0.5, -0.5, -0.5, 0.6, -0.4, -0.4;
    VBO.update(V);

    // Initialize the OpenGL Program
    // A program controls the OpenGL pipeline and it must contains
    // at least a vertex shader and a fragment shader to be valid
    Program program;
    const GLchar* vertex_shader =
            "#version 150 core\n"
                    "in vec2 position;"
                    "void main()"
                    "{"
                    "    gl_Position = vec4(position, 0.0, 1.0);"
                    "}";
    const GLchar* fragment_shader =
            "#version 150 core\n"
                    "out vec4 outColor;"
                    "uniform vec4 triangleColor;"
                    "void main()"
                    "{"
                    "    outColor = vec4(triangleColor);"
                    "}";

    // Compile the two shaders and upload the binary to the GPU
    // Note that we have to explicitly specify that the output "slot" called outColor
    // is the one that we want in the fragment buffer (and thus on screen)
    program.init(vertex_shader,fragment_shader,"outColor");
    program.bind();

    // The vertex shader wants the position of the vertices as an input.
    // The following line connects the VBO we defined above with the position "slot"
    // in the vertex shader
//.........这里部分代码省略.........
开发者ID:danielepanozzo,项目名称:cg,代码行数:101,代码来源:main_blending.cpp

示例8: critsec

PVR_ERROR DVBLinkClient::GetEPGForChannel(ADDON_HANDLE handle, const PVR_CHANNEL& channel, time_t iStart, time_t iEnd)
{
  PVR_ERROR result = PVR_ERROR_FAILED;
  PLATFORM::CLockObject critsec(m_mutex);
  Channel * c = m_channelMap[channel.iUniqueId];
  EpgSearchResult epgSearchResult;

  if (DoEPGSearch(epgSearchResult,c->GetID(), iStart, iEnd))
  {
    for (std::vector<ChannelEpgData*>::iterator it = epgSearchResult.begin(); it < epgSearchResult.end(); it++) 
    {
      ChannelEpgData* channelEpgData = (ChannelEpgData*)*it;
      EpgData& epgData = channelEpgData->GetEpgData();
      for (std::vector<Program*>::iterator pIt = epgData.begin(); pIt < epgData.end(); pIt++) 
      {
        Program* p = (Program*)*pIt;
        EPG_TAG broadcast;
        memset(&broadcast, 0, sizeof(EPG_TAG));

        broadcast.iUniqueBroadcastId = p->GetStartTime();
        broadcast.strTitle = p->GetTitle().c_str();
        broadcast.iChannelNumber      = channel.iChannelNumber;
        broadcast.startTime           = p->GetStartTime();
        broadcast.endTime             = p->GetStartTime() + p->GetDuration();
        broadcast.strPlot             = p->ShortDescription.c_str();
        broadcast.strCast             = p->Actors.c_str();
        broadcast.strDirector         = p->Directors.c_str();
        broadcast.strWriter           = p->Writers.c_str();
        broadcast.iYear               = p->Year;
        broadcast.strIconPath         = p->Image.c_str();
        broadcast.iGenreType          = 0;
        broadcast.iGenreSubType       = 0;
        broadcast.strGenreDescription = "";
        broadcast.firstAired          = 0;
        broadcast.iParentalRating     = 0;
        broadcast.iStarRating         = p->Rating;
        broadcast.bNotify             = false;
        broadcast.iSeriesNumber       = p->SeasonNumber;
        broadcast.iEpisodeNumber      = p->EpisodeNumber;
        broadcast.iEpisodePartNumber  = 0;
        broadcast.strEpisodeName      = p->SubTitle.c_str();
        broadcast.strIMDBNumber       = NULL; // unused
        broadcast.strOriginalTitle    = NULL; // unused
        broadcast.strPlotOutline      = NULL;

        int genre_type, genre_subtype;
        SetEPGGenre(*p, genre_type, genre_subtype);
        broadcast.iGenreType = genre_type;
        if (genre_type == EPG_GENRE_USE_STRING)
          broadcast.strGenreDescription = p->Keywords.c_str();
        else
          broadcast.iGenreSubType = genre_subtype;

        broadcast.iFlags              = EPG_TAG_FLAG_UNDEFINED;
        
        PVR->TransferEpgEntry(handle, &broadcast);
      }
    }
    result = PVR_ERROR_NO_ERROR;
  }
  else
  {
    XBMC->Log(LOG_NOTICE, "Not EPG data found for channel : %s with id : %i", channel.strChannelName, channel.iUniqueId);
  }
  return result;
}
开发者ID:MrMC,项目名称:pvr.dvblink,代码行数:66,代码来源:DVBLinkClient.cpp

示例9: qp

//Está un poco fuzzy, habrá que estructurarlo y tal, pero correcto
void SVMachine::quadraticSolution() {
	int n = C_trainingSet.size();
	int m = 1; // Entiendo que es el numero de restricciones
	Program qp (CGAL::EQUAL);

	// Obtengo la X
//	Utils::scalation(C_trainingSet); // Escalado de parámetros

	std::cout << "n vale: " << n << std::endl;
	std::cout << "nFeatures vale: " << C_nFeatures << std::endl;
	C_X = arma::mat(n, C_nFeatures);

	for(int i = 0; i < n; i++){
		for(int j = 0; j < C_nFeatures; j++){
			C_X(i,j) = C_trainingSet[i].getInput()[j];
		}
	}
	std::cout << "X vale: " << std::endl << C_X;

	// Obtengo la Y
	C_y = arma::mat(n, 1);

	std::cout << "n vale: " << n << std::endl;
	for(int i = 0; i < n; i++){
		C_y(i) = C_trainingSet[i].getResult()[0];
	}

	std::cout << "Y vale: " << std::endl << C_y;
	// Seteo la restriccion
	for(int i = 0; i < n; i++){
		qp.set_a(i,0,ET(C_y.at(i)));
		qp.set_l(i,true,ET(0));
		qp.set_u(i,false);
		qp.set_c(i,ET(-1));
//		std::cout << "y(" << i << "): " << y.at(i) << std::endl;
	}

	qp.set_b(0,ET(0));
	qp.set_r(0,CGAL::EQUAL);
	qp.set_c0(ET(0));

	// Seteo la symmetric positive-semidefinite matrix
	for(int i = 0; i < n; i++){
		for(int j = 0; j<=i; j++){
			ET ip = C_kernel->K(C_X.row(i).t(),C_X.row(j).t());
//			std::cout << "El kernel para " << i << "," << j << " nos dice que el innerproduct es: " << ip << std::endl;
			ET daux = ip*ET(C_y.at(i))*ET(C_y.at(j));
			std::cout << "El producto de " << i << "," << j << ": " << daux << std::endl;
			qp.set_d(i,j,daux);
//			std::cout << "La matriz auxiliar vale:" <<  daux << std::endl;
		}
	}

	 // solve the program, using ET as the exact type
	Solution s = CGAL::solve_quadratic_program(qp, ET());
	// print basic constraint indices (we know that there is only one: 1)
	std::cout << "Y la solución es: " << s << std::endl;
//	arma::mat W = arma::mat(n,1);

	C_SupportVectors = arma::mat(n,1);

	ET sumaB(0.0);

	if(s.is_optimal()) { // we know that, don't we?
		int i = 0;
		for (Solution::Variable_value_iterator it = s.variable_values_begin(); it != s.variable_values_end(); ++it){
			C_SupportVectors(i) = CGAL::to_double(*it);
			if(C_SupportVectors.at(i) != 0.0){
				C_m = i; // Esto lo hago para obtener un sv que me resuelva la b
			}
			i++;
		}
		// Calculo la b
		for(int i=0; i<n; i++)
			if(C_SupportVectors.at(i) != 0.0)
				sumaB += ET(C_SupportVectors.at(i))*ET(C_y.at(i))*C_kernel->K(C_X.row(i).t(), C_X.row(C_m).t());
		C_b = ET(C_y(C_m)) - sumaB;
		std::cout << "Y el valor de b es: "<< C_b << std::endl;
	} else std::cout << "No es optima, vete tu a saber por qué...\n";

//	int pausa; std::cin >> pausa;
}
开发者ID:aydevosotros,项目名称:BrokerBot,代码行数:83,代码来源:SVMachine.cpp

示例10: ANIMCreateVirtualSphere

/***************************************************************
* Function: ANIMCreateVirtualSphere()
*
***************************************************************/
void ANIMCreateVirtualSphere(osg::PositionAttitudeTransform** xformScaleFwd, 
			     osg::PositionAttitudeTransform** xformScaleBwd)
{
    // create sphere geometry
    *xformScaleFwd = new PositionAttitudeTransform;
    *xformScaleBwd = new PositionAttitudeTransform;
    Geode* sphereGeode = new Geode();
    Sphere* virtualSphere = new Sphere();
    Drawable* sphereDrawable = new ShapeDrawable(virtualSphere);

    virtualSphere->setRadius(ANIM_VIRTUAL_SPHERE_RADIUS);
    sphereGeode->addDrawable(sphereDrawable);
    (*xformScaleFwd)->addChild(sphereGeode);
    (*xformScaleBwd)->addChild(sphereGeode);

    osg::StateSet* stateset;   

    // highlights
/*    Sphere* highlightSphere = new Sphere();
    ShapeDrawable* highlightDrawable = new ShapeDrawable(highlightSphere);
    Geode* highlightGeode = new Geode();
    highlightSphere->setRadius(ANIM_VIRTUAL_SPHERE_RADIUS * 1.3);
    highlightDrawable->setColor(osg::Vec4(0,0,1,0.3));
    highlightGeode->addDrawable(highlightDrawable);
    (*xformScaleFwd)->addChild(highlightGeode);
    (*xformScaleBwd)->addChild(highlightGeode);

    stateset = highlightDrawable->getOrCreateStateSet();
    stateset->setMode(GL_BLEND, StateAttribute::ON);
    stateset->setMode(GL_CULL_FACE, StateAttribute::ON);
    stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
    stateset->setRenderingHint(StateSet::TRANSPARENT_BIN);
*/

    // set up the forward / backward scale animation path
    AnimationPath* animationPathScaleFwd = new AnimationPath;
    AnimationPath* animationPathScaleBwd = new AnimationPath;
    animationPathScaleFwd->setLoopMode(AnimationPath::NO_LOOPING);
    animationPathScaleBwd->setLoopMode(AnimationPath::NO_LOOPING);

    osg::Vec3 pos(-1.5, 0, 0);

    Vec3 scaleFwd, scaleBwd;
    float step = 1.f / ANIM_VIRTUAL_SPHERE_NUM_SAMPS;
    for (int i = 0; i < ANIM_VIRTUAL_SPHERE_NUM_SAMPS + 1; i++)
    {
        float val = i * step;
        scaleFwd = Vec3(val, val, val);
        scaleBwd = Vec3(1-val, 1-val, 1-val);
        animationPathScaleFwd->insert(val, AnimationPath::ControlPoint(pos, Quat(), scaleFwd));
        animationPathScaleBwd->insert(val, AnimationPath::ControlPoint(pos, Quat(), scaleBwd));
    }

    AnimationPathCallback *animCallbackFwd = new AnimationPathCallback(animationPathScaleFwd,
						0.0, 1.f / ANIM_VIRTUAL_SPHERE_LAPSE_TIME);
    AnimationPathCallback *animCallbackBwd = new AnimationPathCallback(animationPathScaleBwd,
						0.0, 1.f / ANIM_VIRTUAL_SPHERE_LAPSE_TIME);
    (*xformScaleFwd)->setUpdateCallback(animCallbackFwd);
    (*xformScaleBwd)->setUpdateCallback(animCallbackBwd);

    /* apply shaders to geode stateset */
    stateset = new StateSet();
    stateset->setMode(GL_BLEND, StateAttribute::OVERRIDE | StateAttribute::ON );
    stateset->setRenderingHint(StateSet::TRANSPARENT_BIN);
    //sphereGeode->setStateSet(stateset);
    sphereDrawable->setStateSet(stateset);

    Program* shaderProg = new Program;
    stateset->setAttribute(shaderProg);
    shaderProg->addShader(Shader::readShaderFile(Shader::VERTEX, ANIMDataDir() + "Shaders/VirtualSphere.vert"));
    shaderProg->addShader(Shader::readShaderFile(Shader::FRAGMENT, ANIMDataDir() + "Shaders/VirtualSphere.frag"));

    Image* envMap = osgDB::readImageFile(ANIMDataDir() + "Textures/EnvMap.JPG");
    Texture2D* envTex = new Texture2D(envMap);
    stateset->setTextureAttributeAndModes(0, envTex, StateAttribute::ON);

    Uniform* envMapSampler = new Uniform("EnvMap", 0);
    stateset->addUniform(envMapSampler);

    Uniform* baseColorUniform = new Uniform("BaseColor", Vec3(0.2, 1.0, 0.2));
    stateset->addUniform(baseColorUniform);

    Uniform* lightPosUniform = new Uniform("LightPos", Vec4(1.0, 0.0, 0.2, 0.0));
    stateset->addUniform(lightPosUniform);

}
开发者ID:cehughes,项目名称:calvr_plugins,代码行数:90,代码来源:ANIMVirtualSphere.cpp

示例11: Program

Program* ProgramManager::CreateFromDescriptor( ProgramDescriptor* descriptor )
{
	int id;
	string name;
	string description;

	DescriptorsUtil::GetIntProperty( descriptor->Properties, "Id", &id );
	DescriptorsUtil::GetStringProperty( descriptor->Properties, "Name", &name );
	DescriptorsUtil::GetStringProperty( descriptor->Properties, "Description",
			&description );

	Program* program = new Program( id, name, description );
	string deviceType;
	// ------ Initialize Devices:
	list<DeviceDescriptor>::iterator deviceIt;
	for ( deviceIt = descriptor->Devices.begin(); deviceIt
			!= descriptor->Devices.end(); deviceIt++ )
	{
		BaseDevice* device = DeviceManager::Instance()->CreateFromDescriptor(
				*deviceIt );

		if( device == NULL )
			return NULL;

		program->AddDevice( device );
	}
	// ------- Initialize Wires:
	list<WireDescriptor>::iterator wireIt;
	list<WireConnectionPointDescriptor>::iterator cpIt; //connectionPointsIt

	for ( wireIt = descriptor->Wires.begin(); wireIt != descriptor->Wires.end(); wireIt++ )
	{
		Wire* wire = new Wire();

		for ( cpIt = ( *wireIt ).WireConnectionPoints.begin(); cpIt
				!= ( *wireIt ).WireConnectionPoints.end(); cpIt++ )
		{
			BaseDevice* device = program->GetDevice(
					( *cpIt ).DeviceDescriptorId );
			ConnectionPoint* cp = device->GetConnectionPoint(
					( *cpIt ).ConnectionPointDescriptorId );

			wire->Attach( cp );
		}

		program->AddWire( wire );
	}

	// ------ Initialize the program's Power Wire:
	list<WireConnectionPointDescriptor>* stratupPoints =
			&descriptor->PowerWire.WireConnectionPoints;
	for ( cpIt = stratupPoints->begin(); cpIt != stratupPoints->end(); cpIt++ )
	{
		int* startUpValue = new int( 1 );

		BaseDevice* device = program->GetDevice( ( *cpIt ).DeviceDescriptorId );
		ConnectionPoint* cp = device->GetConnectionPoint(
				( *cpIt ).ConnectionPointDescriptorId );

		InConnectionPoint* inConnectionPoint = (InConnectionPoint*) cp;
		inConnectionPoint->SetValue( startUpValue );

		program->PowerWire()->Attach( inConnectionPoint );
	}

	return program;
}
开发者ID:bobi-rakova,项目名称:Agilart-Run-Time,代码行数:67,代码来源:ProgramManager.cpp

示例12: breed

int FullTree::breed(System* system, Population* src, vector<Program>* newpop, int index)
{
	Program* newp;
	newpop->push_back(Program(system));
	newp=&newpop->back();

	newp->functions.assign(system->adf.begin(), system->adf.end());

	newp->branch.push_back(vector<TreeNode>());

	// Push the main program branch on
	fulltree(system, system->returntype, TreeNodeIter(&newp->branch[0], 0), (maxdepth<=mindepth?0:(rand()%(maxdepth-mindepth+1)))+mindepth);

	// Need to add ADF branches
	for (int i=0;i<system->adf.size();++i)
		newp->branch.push_back(vector<TreeNode>());

	ADF* curfunc;
	for (int i=system->adf.size()-1;i>=0;--i)
	{
		curfunc = (ADF*)(system->adf[i]);

		// Remove current function from list
		if (system->recursiveDepth<=0)
		{
#ifdef DEBUG
			if (system->functions[curfunc->arg_type[0]].back()!=curfunc)
				throw runtime_error("Function being popped off of system does not match last adf entry");
#endif
			system->functions[curfunc->arg_type[0]].pop_back();
		}
		// Push function arguments
		for (int j=1;j<curfunc->arg_type.size();++j)
			system->functions[curfunc->arg_type[j]].push_back(curfunc->args[j-1]);

		// Generate tree
		fulltree(system, curfunc->arg_type[0], TreeNodeIter(&newp->branch[i+1], 0), (maxdepth<=mindepth?0:(rand()%(maxdepth-mindepth+1)))+mindepth);

		// Pop function arguments
		for (int j=curfunc->arg_type.size()-1;j>=1;--j)
		{
			system->functions[curfunc->arg_type[j]].pop_back();
		}
	}
	
	if (system->recursiveDepth<=0)
	{
		for (int i=0;i<system->adf.size();++i)
		{
			curfunc = (ADF*)system->adf[i];
			system->functions[curfunc->arg_type[0]].push_back(curfunc);
		}
	}

#ifdef DEBUG
	if (!newp->checkConsistency())
	{
		throw runtime_error("Invalid produced program");
	}
#endif

	return 1;
}
开发者ID:,项目名称:,代码行数:63,代码来源:

示例13: program_2

void program_2(int a, int b) {
    Program qp (CGAL::SMALLER, false, 0, true, 0);
    const int X = 0;
    const int Y = 1;
    const int Z = 2;
    
    qp.set_l(Z, 0);
    qp.set_u(Z, false);

    // minimize a*x^2 + b*y + z^4
    qp.set_d(X, X, 2*a);
    qp.set_d(Z, Z, 2*1);        // by convention: we multiply value by 2.

    qp.set_c(Y, b);

    qp.set_a(X, 0, 1);
    qp.set_a(Y, 0, 1);
    qp.set_b(0, -4);
    qp.set_r(0, CGAL::LARGER);

    qp.set_a(X, 1, 4);
    qp.set_a(Y, 1, 2);
    qp.set_a(Z, 1, 1);
    qp.set_b(1, -1*a*b);
    qp.set_r(1, CGAL::LARGER);

    qp.set_a(X, 2, -1);
    qp.set_a(Y, 2, 1);
    qp.set_b(2, -1);
    qp.set_r(2, CGAL::LARGER);

    qp.set_a(Z, 3, 1);
    qp.set_b(3, 0);
    qp.set_r(3, CGAL::LARGER);

    Solution s = CGAL::solve_quadratic_program(qp, ET());
    assert(s.solves_quadratic_program(qp));
    
    if(s.is_optimal()) {
        double result = ceil(CGAL::to_double(s.objective_value()));        
        cout << result << "\n";
    }
    else if(s.is_unbounded()) 
        cout << "unbounded\n";
    else if(s.is_infeasible()) 
        cout << "no\n";
}
开发者ID:bengro,项目名称:AlgoLab13,代码行数:47,代码来源:MaximizeIt1.cpp

示例14: lightPos

    PoolTilesExample()
      : make_plane(
          Vec3f(), Vec3f(7.0f, 0.0f, 0.0f), Vec3f(0.0f, 0.0f, -7.0f), 48, 48)
      , plane_instr(make_plane.Instructions())
      , plane_indices(make_plane.Indices())
      , make_shape()
      , shape_instr(make_shape.Instructions())
      , shape_indices(make_shape.Indices())
      , plane_vs(ObjectDesc("Plane vertex"))
      , shape_vs(ObjectDesc("Shape vertex"))
      , plane_fs(ObjectDesc("Plane fragment"))
      , shape_fs(ObjectDesc("Shape fragment"))
      , plane_camera_matrix(plane_prog, "CameraMatrix")
      , shape_camera_matrix(shape_prog, "CameraMatrix")
      , plane_camera_position(plane_prog, "CameraPosition")
      , width(800)
      , height(600)
      , refl_tex_side(width > height ? height : width)
      , tile_tex_side(64) {
        gl.RequireAtLeast(LimitQuery::MaxCombinedTextureImageUnits, 5);

        plane_vs.Source(
          "#version 140\n"
          "uniform vec3 LightPosition;"
          "uniform vec3 CameraPosition;"
          "uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
          "in vec4 Position;"
          "in vec2 TexCoord;"
          "out vec3 vertLightDir;"
          "out vec3 vertViewDir;"
          "out vec4 vertReflTexCoord;"
          "out vec2 vertTileTexCoord;"
          "void main()"
          "{"
          "	gl_Position = ModelMatrix* Position;"
          "	vertLightDir = normalize(LightPosition - gl_Position.xyz);"
          "	vertViewDir = normalize(CameraPosition - gl_Position.xyz);"
          "	gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
          "	vertReflTexCoord = gl_Position;"
          "	vertTileTexCoord = TexCoord;"
          "}");
        plane_vs.Compile();

        plane_fs.Source(
          "#version 140\n"
          "uniform sampler2D RandTex, PictTex, TileTex, NormTex;"
          "uniform sampler2D ReflectTex;"
          "uniform uint TileCount;"
          "uniform float Aspect;"
          "in vec3 vertLightDir;"
          "in vec3 vertViewDir;"
          "in vec4 vertReflTexCoord;"
          "in vec2 vertTileTexCoord;"
          "out vec4 fragColor;"
          "void main()"
          "{"
          "	vec3 Normal = texture("
          "		NormTex, "
          "		vertTileTexCoord * TileCount"
          "	).rgb;"
          "	vec3 LightRefl = reflect("
          "		-normalize(vertLightDir),"
          "		normalize(Normal)"
          "	);"
          "	float Diffuse = max(dot("
          "		Normal, "
          "		vertLightDir"
          "	), 0.0);"
          "	float Specular = max(dot("
          "		LightRefl,"
          "		vertViewDir"
          "	), 0.0);"
          "	float PlasterLight = 0.3 + max(Diffuse, 0.0);"
          "	float TileLight = 0.3 + pow(Diffuse, 2.0)*0.9 + pow(Specular, "
          "4.0)*2.5;"
          "	vec2 ReflCoord = vertReflTexCoord.xy;"
          "	ReflCoord /= vertReflTexCoord.w;"
          "	ReflCoord *= 0.5;"
          "	ReflCoord += vec2(Aspect*0.5, 0.5);"
          "	ReflCoord += vec2(Normal.x, Normal.z)*0.5;"
          "	vec3 ReflColor = texture("
          "		ReflectTex, "
          "		ReflCoord"
          "	).rgb;"
          "	vec3 TileProps = texture("
          "		TileTex, "
          "		vertTileTexCoord * TileCount"
          "	).rgb;"
          "	float Pict = texture(PictTex, vertTileTexCoord).r;"
          "	float Rand = texture(RandTex, vertTileTexCoord).r;"
          "	float LightVsDark = "
          "		mix( 0.1, 0.9, Pict)+"
          "		mix(-0.1, 0.1, Rand);"
          "	vec3 TileColor = mix("
          "		vec3(0.1, 0.1, 0.5),"
          "		vec3(0.4, 0.4, 0.9),"
          "		LightVsDark "
          "	);"
          "	vec3 PlasterColor = vec3(0.9, 0.9, 0.9);"
          "	fragColor = vec4("
//.........这里部分代码省略.........
开发者ID:matus-chochlik,项目名称:oglplus,代码行数:101,代码来源:030_pool_tiles.cpp

示例15: vert

    TessellationExample(void)
        : prog()
        , projection_matrix(prog, "ProjectionMatrix")
        , camera_matrix(prog, "CameraMatrix")
    {
        VertexShader vert(ObjectDesc("Vertex"));
        vert.Source(StrLit(
                        "#version 330\n"
                        "uniform mat4 CameraMatrix;"

                        "in vec4 Position;"
                        "out vec4 vertPosition;"

                        "void main(void)"
                        "{"
                        "	vertPosition = CameraMatrix * Position;"
                        "}"
                    ));
        vert.Compile();
        prog << vert;

        TessControlShader teco(ObjectDesc("TessControl"));
        teco.Source(StrLit(
                        "#version 330\n"
                        "#extension ARB_tessellation_shader: enable\n"
                        "layout(vertices = 16) out;"

                        "in vec4 vertPosition[];"
                        "patch out vec3 tecoPosition[16];"

                        "void main(void)"
                        "{"
                        "	if(gl_InvocationID == 0)"
                        "	{"
                        "		int tl = 1-int(100.0 / vertPosition[gl_InvocationID].z);"
                        "		gl_TessLevelInner[0] = tl;"
                        "		gl_TessLevelInner[1] = tl;"
                        "		gl_TessLevelOuter[0] = tl;"
                        "		gl_TessLevelOuter[1] = tl;"
                        "		gl_TessLevelOuter[2] = tl;"
                        "		gl_TessLevelOuter[3] = tl;"
                        "	}"
                        "	tecoPosition[gl_InvocationID] = "
                        "		vertPosition[gl_InvocationID].xyz;"
                        "}"
                    ));
        teco.Compile();
        prog << teco;

        TessEvaluationShader teev(ObjectDesc("TessEvaluation"));
        teev.Source(StrLit(
                        "#version 330\n"
                        "#extension ARB_tessellation_shader: enable\n"
                        "layout(quads, equal_spacing, ccw) in;"
                        "uniform mat4 ProjectionMatrix;"
                        "patch in vec3 tecoPosition[16];"

                        "const mat4 B = mat4("
                        "	-1, 3,-3, 1,"
                        "	 3,-6, 3, 0,"
                        "	-3, 3, 0, 0,"
                        "	 1, 0, 0, 0 "
                        ");"

                        "mat4 Px, Py, Pz;"

                        "void main(void)"
                        "{"
                        "	float u = gl_TessCoord.x, v = gl_TessCoord.y;"

                        "	for(int j=0; j!=4; ++j)"
                        "	for(int i=0; i!=4; ++i)"
                        "	{"
                        "		int k = j*4+i;"
                        "		Px[j][i] = tecoPosition[k].x;"
                        "		Py[j][i] = tecoPosition[k].y;"
                        "		Pz[j][i] = tecoPosition[k].z;"
                        "	}"

                        "	mat4 Cx = B * Px * B;"
                        "	mat4 Cy = B * Py * B;"
                        "	mat4 Cz = B * Pz * B;"

                        "	vec4 up = vec4(u*u*u, u*u, u, 1);"
                        "	vec4 vp = vec4(v*v*v, v*v, v, 1);"

                        "	vec4 tempPosition = vec4(dot(Cx * vp, up), dot(Cy * vp, up), dot(Cz * vp, up), 1.0);"

                        "	gl_Position = ProjectionMatrix * tempPosition;"
                        "}"
                    ));
        teev.Compile();
        prog << teev;

        FragmentShader frag(ObjectDesc("Fragment"));
        frag.Source(StrLit(
                        "#version 330\n"
                        "out vec3 fragColor;"
                        "void main(void)"
                        "{"
//.........这里部分代码省略.........
开发者ID:BrainlessLabsInc,项目名称:oglplus,代码行数:101,代码来源:019_bpatch_tess.cpp


注:本文中的Program类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。