Example #1
0
void YafFile::processLights(TiXmlElement* lights)
{
    float location[4], ambient[4], diffuse[4], specular[4];
    float angle = 0, exponent = 0, direction[3];
    bool enabled;
    string type;
    char* id;
    Light* light;
    TiXmlElement* element = lights->FirstChildElement();
    while(element!=NULL)
    {
        element->QueryBoolAttribute("enabled",&enabled);
        id = (char*)element->Attribute("id");
        read3Float("location", element, location[0], location[1], location[2]);
        read4Float("ambient", element, ambient[0], ambient[1], ambient[2],
                   ambient[3]);
        read4Float("diffuse", element, diffuse[0], diffuse[1], diffuse[2],
                   diffuse[3]);
        read4Float("specular", element, specular[0], specular[1], specular[2],
                   specular[3]);
        if(element->Attribute("angle")!=NULL)
        {
            type="spot";
            element->QueryFloatAttribute("angle", &angle);
            element->QueryFloatAttribute("exponent", &exponent);
            read3Float("direction", element, direction[0], direction[1],
                       direction[2]);
        }
        light = new Light(id,enabled,type,location,ambient,diffuse,specular,angle,exponent,direction);
        this->sceneLights.push_back(light);
        element=element->NextSiblingElement();
    }
}
Example #2
0
void YafFile::processGraph(TiXmlElement* graphElement)
{
    string rootid=graphElement->Attribute("rootid");
    TiXmlElement* nodeElement = graphElement->FirstChildElement("node");
    sceneGraph = new Graph();
    sceneGraph->setRootId(rootid);
    while(nodeElement!=NULL)
    {
        Node* node = new Node(nodeElement->Attribute("id"));
        bool displaylist=false;
        nodeElement->QueryBoolAttribute("displaylist",&displaylist);
        if(displaylist!=NULL)
            node->setDisplayList(displaylist);

        string animID;
        TiXmlElement* animationsN = nodeElement->FirstChildElement("animationref");
        if(animationsN!=NULL)
            animID=animationsN->Attribute("id");


        TiXmlElement* transformations = nodeElement->FirstChildElement("transforms");
        TiXmlElement* transformation=transformations->FirstChildElement();

        while(transformation!=NULL)
        {
            if(transformation->Attribute("axis")!=NULL)
            {
                string axis=transformation->Attribute("axis");
                float angle;
                transformation->QueryFloatAttribute("angle",&angle);
                Transformation* rot = new Rotation(axis,angle);
                node->addTransformation(rot);
            }
            else if (transformation->Attribute("to")!=NULL)
            {
                float translation[3];
                read3Float("to",transformation,translation[0],translation[1],translation[2]);
                Transformation* translationElement = new Translation(translation[0],translation[1],translation[2]);
                node->addTransformation(translationElement);
            }

            else if (transformation->Attribute("factor")!=NULL)
            {
                float factor[3];
                read3Float("factor",transformation,factor[0],factor[1],factor[2]);
                Transformation* scaling = new Scaling(factor[0],factor[1],factor[2]);
                node->addTransformation(scaling);
            }

            transformation = transformation->NextSiblingElement();
        }

        TiXmlElement* appearanceRef = nodeElement->FirstChildElement("appearanceref");
        if(appearanceRef!=NULL)
        {

            node->setNodeAppearance(make_pair(appearanceRef->Attribute("id"),appearances[appearanceRef->Attribute("id")]));
        }
        else
        {
            node->setNodeAppearance(make_pair("",new Appearance()));
        }
        TiXmlElement* children = nodeElement->FirstChildElement("children");
        TiXmlElement* childrenAnalyzer = children->FirstChildElement();
        while(childrenAnalyzer!=NULL)
        {
            if(childrenAnalyzer->Attribute("xy1")!=NULL)
            {
                float xy1[2],xy2[2];
                read2Float("xy1",childrenAnalyzer,xy1[0],xy1[1]);
                read2Float("xy2",childrenAnalyzer,xy2[0],xy2[1]);
                SceneObject* rectangle = new SceneRectangle(xy1[0],xy1[1],xy2[0],xy2[1]);
                node->addObject(rectangle);
            }

            else if(childrenAnalyzer->Attribute("xyz1")!=NULL)
            {
                float xyz1[3],xyz2[3],xyz3[3];
                read3Float("xyz1",childrenAnalyzer,xyz1[0],xyz1[1],xyz1[2]);
                read3Float("xyz2",childrenAnalyzer,xyz2[0],xyz2[1],xyz2[2]);
                read3Float("xyz3",childrenAnalyzer,xyz3[0],xyz3[1],xyz3[2]);
                SceneObject* triangle = new SceneTriangle(xyz1,xyz2,xyz3);
                node->addObject(triangle);
            }

            else if(childrenAnalyzer->Attribute("base")!=NULL)
            {
                float base,top,height;
                int slices,stacks;
                childrenAnalyzer->QueryFloatAttribute("base",&base);
                childrenAnalyzer->QueryFloatAttribute("top",&top);
                childrenAnalyzer->QueryFloatAttribute("height",&height);
                childrenAnalyzer->QueryIntAttribute("slices",&slices);
                childrenAnalyzer->QueryIntAttribute("stacks",&stacks);
                SceneObject* cylinder = new SceneCylinder(base,top,height,slices,stacks);
                node->addObject(cylinder);
            }
            else if(childrenAnalyzer->Attribute("radius")!=NULL)
            {
                float radius;
                int slices,stacks;
                childrenAnalyzer->QueryFloatAttribute("radius",&radius);
                childrenAnalyzer->QueryIntAttribute("slices",&slices);
                childrenAnalyzer->QueryIntAttribute("stacks",&stacks);
                SceneObject* sphere = new SceneSphere(radius,slices,stacks);
                node->addObject(sphere);
            }
            else if(childrenAnalyzer->Attribute("inner")!=NULL)
            {
                float inner,outer;
                int slices,loops;
                childrenAnalyzer->QueryFloatAttribute("inner",&inner);
                childrenAnalyzer->QueryFloatAttribute("outer",&outer);
                childrenAnalyzer->QueryIntAttribute("slices",&slices);
                childrenAnalyzer->QueryIntAttribute("loops",&loops);
                SceneObject* thorus = new SceneTorus(inner,outer,slices,loops);
                node->addObject(thorus);
            }
            else if(childrenAnalyzer->Attribute("parts")!=NULL)
            {
                int parts;
                childrenAnalyzer->QueryIntAttribute("parts",&parts);
                SceneObject* plane = new ScenePlane(parts);
                node->addObject(plane);
            }
            else if(strcmp(childrenAnalyzer->Value(),"patch")==0)
            {
                int order,partsU,partsV;
                float x,y,z;
                string compute;

                childrenAnalyzer->QueryIntAttribute("order",&order);
                childrenAnalyzer->QueryIntAttribute("partsU",&partsU);
                childrenAnalyzer->QueryIntAttribute("partsV",&partsV);
                compute=childrenAnalyzer->Attribute("compute");

                ScenePatch* patch = new ScenePatch(order,partsU,partsV,compute);

                TiXmlElement* points = childrenAnalyzer->FirstChildElement("controlpoint");

                while(points!=NULL)
                {
                    points->QueryFloatAttribute("x",&x);
                    points->QueryFloatAttribute("y",&y);
                    points->QueryFloatAttribute("z",&z);

                    cout<<x<<","<<y<<","<<z<<endl;
                    patch->addCntrPoint(x,y,z);

                    points = points->NextSiblingElement("controlpoint");
                }
                node->addObject(patch);

            }

            else if(strcmp(childrenAnalyzer->Value(),"vehicle")==0)
            {
                SceneObject* vehicle = new SceneVehicle();
                node->addObject(vehicle);
            }

            else if(childrenAnalyzer->Attribute("heightmap")!=NULL)
            {
                string heightMap,textureMap,fragmentShader,vertexShader;
                heightMap=childrenAnalyzer->Attribute("heightmap");
                textureMap=childrenAnalyzer->Attribute("texturemap");
                fragmentShader=childrenAnalyzer->Attribute("fragmentshader");
                vertexShader=childrenAnalyzer->Attribute("vertexshader");

                SceneObject* shader = new SceneShader(heightMap,textureMap,fragmentShader,vertexShader);
                node->addObject(shader);
            }


            else if (childrenAnalyzer->Attribute("id")!=NULL)
            {
                node->addchildId(childrenAnalyzer->Attribute("id"));
            }
            childrenAnalyzer=childrenAnalyzer->NextSiblingElement();
        }
        //set animation
        Animation* anime=animations[animID];

        if(anime!=NULL)
        {
            node->setAnimation(anime);
        }
        sceneGraph->addNode(node);
        nodeElement=nodeElement->NextSiblingElement("node");
    }
    sceneGraph->createSonNodes();
}
Example #3
0
void ClassifierSVM::loadSettings(TiXmlElement* settings){
	string tmp;

	cacheEnabled = true;
	TiXmlElement* pPtr = settings->FirstChildElement("cache");
	if(!pPtr){
		throw "Bad settings file - no cache setting for ClassifierSVM";
	}
	pPtr->QueryBoolAttribute("enabled", &cacheEnabled);

	pPtr = settings->FirstChildElement("svm");
	if(!pPtr){
		throw "Bad settings file - no svm settings";
	}

	int svmType;
	pPtr->QueryStringAttribute("type", &tmp);
	if(tmp == "C_SVC"){
		svmType = C_SVC;
	}
	else if(tmp == "NU_SVC"){
		svmType = NU_SVC;
	}
	else if(tmp == "ONE_CLASS"){
		svmType = ONE_CLASS;
	}
	else{
		throw "Bad settings file - wrong SVM type";
	}

	int kernelType;
	TiXmlElement* svmPtr = pPtr->FirstChildElement("kernelType");
	if(!svmPtr){
		throw "Bad settings file - no kernel type";
	}
	svmPtr->QueryStringAttribute("value", &tmp);
	if(tmp == "LINEAR"){
		kernelType = LINEAR;
	}
	else if(tmp == "POLY"){
		kernelType = POLY;
	}
	else if(tmp == "RBF"){
		kernelType = RBF;
	}
	else if(tmp == "SIGMOID"){
		kernelType = SIGMOID;
	}
	else{
		throw "Bad settings file - wrong kernel type";
	}

	double gamma = 0.5;
	svmPtr = pPtr->FirstChildElement("gamma");
	if(!svmPtr){
		throw "Bad settings file - no gamma value";
	}
	svmPtr->QueryDoubleAttribute("value", &gamma);

	double degree = 2;
	svmPtr = pPtr->FirstChildElement("degree");
	if(!svmPtr){
		throw "Bad settings file - no degree value";
	}
	svmPtr->QueryDoubleAttribute("value", &degree);

	double C = 1;
	svmPtr = pPtr->FirstChildElement("C");
	if(!svmPtr){
		throw "Bad settings file - no C value";
	}
	svmPtr->QueryDoubleAttribute("value", &C);

	svmParams.svm_type = svmType;
	svmParams.kernel_type = kernelType;
	svmParams.gamma = gamma;
	svmParams.degree = degree;
	svmParams.C = C;
}