Example #1
0
void GPUImageFilter::parseXML(const char* fname) {
    //load filter description file
    printf("Loading Filter...\n");


    //load and parse xml filter description file
    TiXmlDocument doc(ofToDataPath(fname).c_str());
    if (!doc.LoadFile()) printf("error loading filter description file");


    //get the name of the filter
    TiXmlElement* root_node = doc.RootElement();

    this->name = root_node->Attribute("name");

    printf("Filter Name:%s\n", this->name);


    //get the  shader source file names
    TiXmlElement* node = root_node;

    node = root_node->FirstChildElement("VertexShader");
    const char* vertSrc = node ? node->GetText() : NULL;

    node = root_node->FirstChildElement("GeometryShader");
    const char* geomSrc = node ? node->GetText() : NULL;
    if (geomSrc != NULL) { //We are using a geometry shader
        this->useGeometryShader = true;
    }

    node = root_node->FirstChildElement("FragmentShader");
    const char* fragSrc = node ? node->GetText() : NULL;

    this->shader = new ShaderProgram(vertSrc, geomSrc, ofToDataPath(fragSrc).c_str());


    //get parameters
    //TODO: add type handling
    while( (node = (TiXmlElement*)node->NextSibling("Parameter")) ) {
        const char* name = node->Attribute("name");
        float type = atof(node->Attribute("type"));
        float min = atof(node->Attribute("min"));
        float max = atof(node->Attribute("max"));
        float val = atof(node->GetText());


        parameters["size_cx"] = new FilterParameter("size_cx", (float)res_x, 0, 0, 0 );
        parameters["size_cy"] = new FilterParameter("size_cy", (float)res_y, 0, 0, 0 );
        parameters[std::string(name)] = new FilterParameter(name, val, min, max, (int)type );
    }
}
Example #2
0
bool dSceneGraph::Deserialize (TiXmlElement* rootNode, int revision)
{
	Cleanup();
	int count;
	rootNode->Attribute("count", &count);

	dScene* world = (dScene*) this;
	for (TiXmlElement* element = (TiXmlElement*) rootNode->FirstChild(); element; element = (TiXmlElement*) element->NextSibling()) {
		const char* className = element->Value();
		dNodeInfo* info = dNodeInfo::CreateFromClassName (className, world);
		_ASSERTE (info);
		info->Deserialize(element, revision);
		AddNode (info, NULL);
		info->Release();
	}

	int baseIndex = Minimum()->GetKey();
	int baseIndexCount = baseIndex;
	for (TiXmlElement* element = (TiXmlElement*) rootNode->FirstChild(); element; element = (TiXmlElement*) element->NextSibling()) {
		dTreeNode* myNode = Find (baseIndexCount);
		baseIndexCount ++;
		_ASSERTE (myNode);
		dGraphNode& node = myNode->GetInfo();

		TiXmlElement* parentNodes = (TiXmlElement*) element->FirstChild ("parentNodes");
		if (parentNodes) {
			int count;
			parentNodes->Attribute("count", &count);
			const char* indices = parentNodes->Attribute ("indices");

			const char* ptr = indices;
			for (int i = 0; i < count; i ++) {
				char index[128];
				sscanf (ptr, "%s", index);
				ptr = strstr (ptr, index);
				ptr += strlen (index); 
				int parentIndex = atoi (index);

				dTreeNode* parentNode = Find(parentIndex + baseIndex);
				_ASSERTE (parentNode);
				node.m_parents.Append(parentNode);
			}
		} else {
			_ASSERTE (!m_rootNode);
			m_rootNode = myNode;
		}


		TiXmlElement* childrenNodes = (TiXmlElement*) element->FirstChild ("childrenNodes");
		if (childrenNodes) {
			int count;
			childrenNodes->Attribute("count", &count);
			const char* indices = childrenNodes->Attribute ("indices");

			const char* ptr = indices;
			for (int i = 0; i < count; i ++) {
				char index[128];
				sscanf (ptr, "%s", index);
				ptr = strstr (ptr, index);
				ptr += strlen (index); 
				int childIndex = atoi (index);

				dTreeNode* childNode = Find(childIndex + baseIndex);
				_ASSERTE (childNode);
				node.m_children.Append(childNode);
			}
		}
	}

	return true;
}
TriggersSet::TriggersSet(TiXmlElement* triggersset){

	string purposes;
	while (purposes.size() < arraysize(ontology_vector))
		purposes.append("0");

	// Trigger Tag

	// TriggerAtTime
	if(triggersset->FirstChild(triggerAtTimeTag)){
		for(TiXmlElement * child = static_cast<TiXmlElement*>(triggersset->FirstChild(triggerAtTimeTag)); child;
				child = static_cast<TiXmlElement*>(child->NextSibling(triggerAtTimeTag)) ) {
			trigger[triggerIdTag] = triggerAtTimeTag;

			// read Start parameter
			TiXmlElement * start = static_cast<TiXmlElement*>(child->FirstChild(startTag));
			if (static_cast<TiXmlElement*>(start->FirstChild(startNowTag)))
				trigger[startTag]=startNowTag;
			if (static_cast<TiXmlElement*>(start->FirstChild(dateAndTimeTag)))
				trigger[startTag]=(static_cast<TiXmlElement*>(start->FirstChild(dateAndTimeTag)))->GetText();

			// read MaxDelay parameter
			TiXmlElement * maxdelay = static_cast<TiXmlElement*>(child->FirstChild(maxDelayTag));
			trigger[maxDelayTag]=(static_cast<TiXmlElement*>(maxdelay->FirstChild(durationTag)))->GetText();
			
			triggers.push_back(trigger);
			trigger.clear();
		}
	}

	// TriggerPersonalDataAccessedForPurpose
	if(triggersset->FirstChild(triggerPersonalDataAccessedTag)){
		for(TiXmlElement * child = static_cast<TiXmlElement*>(triggersset->FirstChild(triggerPersonalDataAccessedTag)); child;
				child = static_cast<TiXmlElement*>(child->NextSibling(triggerPersonalDataAccessedTag)) ) {
			trigger[triggerIdTag] = triggerPersonalDataAccessedTag;

			// read Purpose parameters
			for(TiXmlElement * purpose = static_cast<TiXmlElement*>(child->FirstChild(purposeTag)); purpose;
					purpose = static_cast<TiXmlElement*>(child->NextSibling(purposeTag)) ) {
				string p = (static_cast<TiXmlElement*>(child->FirstChild(purposeTag)))->GetText();
				for(unsigned int i = 0; i<arraysize(ontology_vector); i++) {
					if (p.compare(ontology_vector[i]) == 0)
						purposes[i]='1';
				}
			}
			trigger[purposeTag]=purposes;
			for(unsigned int i=0; i<arraysize(ontology_vector); i++)
				purposes[i]='0';

			// read MaxDelay parameter
			TiXmlElement * maxdelay = static_cast<TiXmlElement*>(child->FirstChild(maxDelayTag));
			trigger[maxDelayTag]=(static_cast<TiXmlElement*>(maxdelay->FirstChild(durationTag)))->GetText();
			
			triggers.push_back(trigger);
			trigger.clear();
		}
	}

	// TriggerPersonalDataDeleted
	if(triggersset->FirstChild(triggerPersonalDataDeletedTag)){
		for(TiXmlElement * child = static_cast<TiXmlElement*>(triggersset->FirstChild(triggerPersonalDataDeletedTag)); child;
				child = static_cast<TiXmlElement*>(child->NextSibling(triggerPersonalDataDeletedTag)) ) {
			trigger[triggerIdTag] = triggerPersonalDataDeletedTag;

			// read MaxDelay parameter
			TiXmlElement * maxdelay = static_cast<TiXmlElement*>(child->FirstChild(maxDelayTag));
			trigger[maxDelayTag]=(static_cast<TiXmlElement*>(maxdelay->FirstChild(durationTag)))->GetText();
			
			triggers.push_back(trigger);
			trigger.clear();
		}
	}

	// TriggerDataSubjectAccess
	if(triggersset->FirstChild(triggerDataSubjectAccessTag)){
		for(TiXmlElement * child = static_cast<TiXmlElement*>(triggersset->FirstChild(triggerDataSubjectAccessTag)); child;
				child = static_cast<TiXmlElement*>(child->NextSibling(triggerDataSubjectAccessTag)) ) {
			trigger[triggerIdTag] = triggerDataSubjectAccessTag;

			// read url parameter
			trigger[uriTag] = (static_cast<TiXmlElement*>(child->FirstChild(uriTag)))->GetText();
			
			triggers.push_back(trigger);
			trigger.clear();
		}
	}

}
// Parse the box from the stream
CNCSError CNCSJP2File::CNCSJP2GMLGeoLocationBox::Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream)
{
#ifdef NCS_BUILD_WITH_STDERR_DEBUG_INFO
    fprintf(stderr,"Parsing GML box information\n");
#endif

    CNCSError Error(NCS_SUCCESS);
    m_bValid = false;

    double dRegX = 0.0;
    double dRegY = 0.0;
    double p1[3];
    double p2[3];
    UINT32 nEPSGCode = 0;
    int nResults = 0;
    bool bSRSAttributePresent = false;
    UINT32 nImageWidth = JP2File.m_FileInfo.nSizeX;
    UINT32 nImageHeight = JP2File.m_FileInfo.nSizeY;

    NCSJP2_CHECKIO_BEGIN(Error, Stream);
    char buf[1024 + 1];
    Stream.Read(buf, NCSMin((UINT32)m_nLDBox, sizeof(buf)-1));
    buf[NCSMin((UINT32)m_nLDBox, sizeof(buf)-1)] = '\0';

    TiXmlDocument doc;
    doc.Parse(buf);
    TiXmlHandle docHandle(&doc);
    TiXmlElement *GeoLocation_1 = docHandle.FirstChild("JPEG2000_GeoLocation").FirstChild("gml:RectifiedGrid").Element();//.FirstChild( "Element" ).Child( "Child", 1 ).Element();
    if(GeoLocation_1 && GeoLocation_1->Attribute("gml:id") && !stricmp(GeoLocation_1->Attribute("gml:id"), "JPEG2000_GeoLocation_1")) {
        TiXmlElement *OriginPoint = docHandle.FirstChild("JPEG2000_GeoLocation").FirstChild("gml:RectifiedGrid").FirstChild("gml:origin").FirstChild("gml:Point").Element();
        if(OriginPoint && OriginPoint->Attribute("gml:id") && !stricmp(OriginPoint->Attribute("gml:id"), "JPEG2000_Origin")) {
            const char *pTxt = OriginPoint->Attribute("srsName");
            if(pTxt) {
                nResults += sscanf(pTxt, "epsg:%u", &nEPSGCode);
                bSRSAttributePresent = true;
            }
            TiXmlText *Coords = docHandle.FirstChild("JPEG2000_GeoLocation").FirstChild("gml:RectifiedGrid").FirstChild("gml:origin").FirstChild("gml:Point").FirstChild("gml:coordinates").FirstChild().Text();
            if(Coords) {
                pTxt = Coords->Value();
                if(pTxt) {
                    nResults += sscanf(pTxt, "%lf,%lf", &dRegX, &dRegY);
                }
            }
        }
        TiXmlElement *offsetVector = docHandle.FirstChild("JPEG2000_GeoLocation").FirstChild("gml:RectifiedGrid").FirstChild("gml:offsetVector").Element();
        if(offsetVector && offsetVector->Attribute("gml:id") && !stricmp(offsetVector->Attribute("gml:id"), "p1")) {
            TiXmlText *Coords = docHandle.FirstChild("JPEG2000_GeoLocation").FirstChild("gml:RectifiedGrid").FirstChild("gml:offsetVector").FirstChild().Text();
            if(Coords) {
                const char *pTxt = Coords->Value();
                if(pTxt) {
                    nResults += sscanf(pTxt, "%lf,%lf,%lf", &p1[0], &p1[1], &p1[2]);
                }
            }

            offsetVector = (TiXmlElement*)offsetVector->NextSibling("gml:offsetVector");
            if(offsetVector && offsetVector->Attribute("gml:id") && !stricmp(offsetVector->Attribute("gml:id"), "p2")) {
                TiXmlText *Coords = ((TiXmlElement*)offsetVector->FirstChild())->ToText();
                if(Coords) {
                    const char *pTxt = Coords->Value();
                    if(pTxt) {
                        nResults += sscanf(pTxt, "%lf,%lf,%lf", &p2[0], &p2[1], &p2[2]);
                    }
                }
            }
        }
    }
    NCSJP2_CHECKIO_END();

    if((nResults == 9 && bSRSAttributePresent) || (nResults == 8 && !bSRSAttributePresent)) {
        IEEE8 dRegistrationX = dRegX + nImageHeight * p1[0];
        IEEE8 dRegistrationY = dRegY + nImageHeight * p1[1];

        if(p1[2] == 0.0 && p2[2] == 0.0) {
//				p1[0] = sin(Deg2Rad(dCWRotationDegrees)) * dCellSizeX;
//				p1[1] = cos(Deg2Rad(dCWRotationDegrees)) * dCellSizeY;
//				p2[0] = cos(Deg2Rad(dCWRotationDegrees)) * dCellSizeX;
//				p2[1] = -sin(Deg2Rad(dCWRotationDegrees)) * dCellSizeY;

            double dCWRotationDegrees = Rad2Deg(atan(p1[0] / p2[0]));
            double dCellSizeX = p2[0] / cos(atan(p1[0] / p2[0]));
            double dCellSizeY = p1[1] / cos(atan(p1[0] / p2[0]));

            m_GMLFileInfo.fOriginX = dRegistrationX;
            m_GMLFileInfo.fOriginY = dRegistrationY;
            m_GMLFileInfo.fCellIncrementX = dCellSizeX;
            m_GMLFileInfo.fCellIncrementY = dCellSizeY;
            m_GMLFileInfo.fCWRotationDegrees = dCWRotationDegrees;

            CNCSGDTEPSG& Epsg = *CNCSGDTEPSG::Instance();
            char *pProjection = NULL;
            char *pDatum = NULL;
            NCSFree(m_GMLFileInfo.szProjection);
            NCSFree(m_GMLFileInfo.szDatum);
            if (bSRSAttributePresent && nEPSGCode &&
                    (Epsg.GetProjectionAndDatum(nEPSGCode, &pProjection, &pDatum) == NCS_SUCCESS))
            {
                if(pProjection && pDatum)
                {
                    m_GMLFileInfo.szProjection= NCSStrDup(pProjection);
                    m_GMLFileInfo.szDatum = NCSStrDup(pDatum);
                    NCSFree(pProjection);
                    NCSFree(pDatum);
                }
                else if (nEPSGCode) //EPSG code present but invalid or unrecognised?
                {
                    char szEPSG[32];
                    *szEPSG = '\0';
                    sprintf(szEPSG,"epsg:%u",nEPSGCode);
                    m_GMLFileInfo.szProjection = NCSStrDup(szEPSG);
                    m_GMLFileInfo.szDatum = NCSStrDup(szEPSG);
                }
            }
            else
            {
                m_GMLFileInfo.szDatum = NCSStrDup("RAW");
                m_GMLFileInfo.szProjection = NCSStrDup("RAW");
            }
            if(stricmp(m_GMLFileInfo.szProjection, "GEODETIC") == 0)
                m_GMLFileInfo.eCellSizeUnits = ECW_CELL_UNITS_DEGREES;
            else
                m_GMLFileInfo.eCellSizeUnits = ECW_CELL_UNITS_METERS;
        }
        else return NCS_JP2_GEODATA_READ_ERROR;
    }
    else return NCS_JP2_GEODATA_READ_ERROR;
    m_bValid = true;
    NCSStandardizeFileInfoEx(&m_GMLFileInfo);

    return NCS_SUCCESS;
}