Пример #1
0
	void DiagonalGMM::weightsUpdated()
	{
		//normalize weights
		double maxWeight=weights.maxCoeff();
		double sum=weights.sum();
		if (validFloat(maxWeight/sum))
			weights/=sum;

		//update the component sampling
		for (int i=0; i<nComponents; i++)
		{
			sampler->setDensity(i,weights[i]);
		}
	}
Пример #2
0
bool Parser::readFloat(float &dDato, const char cStopChar)
{
	std::string strTemp("");
	
	// Leemos el contenido en una cadena.
	readContent(strTemp, cStopChar);
	
	// Comprobamos que la cadena contenga un numero válido para pasarselo
	// a atof() con total seguridad.	
	if(validFloat(strTemp)) {
		dDato = atof(strTemp.c_str());
		return true;
	}
	else {
		m_nError = 3; 
		return false;
	}
}
Пример #3
0
bool TableCursorKey::putField(int i, double d) {
  DbFieldType keyType = m_keydef.getFieldDef(i).getType();
  int c = rangecmp(d,keyType);
  if(c == 0) {
    if(isIntegerType(keyType)) {
      if(isInteger(d))
        putNumberInKey(i,d);
      else {
        switch(m_relop) {
        case RELOP_EQ:
          m_key.init();
          m_fieldCount = 0;
          m_relop      = RELOP_FALSE;
          return true;
        case RELOP_GE:
        case RELOP_GT:
          putNumberInKey(i,roundup(d));
          m_relop      = RELOP_GE;
          m_fieldCount = i + 1;
          return true;
        case RELOP_LE:
        case RELOP_LT:
          putNumberInKey(i,floor(d));
          m_relop      = RELOP_LE;
          m_fieldCount = i + 1;
          return true;
        }
      }
    } else if(keyType == DBTYPE_FLOAT || keyType == DBTYPE_FLOATN) {
      if(validFloat(d)) {
        putNumberInKey(i,d);
      } else {
        switch(m_relop) {
        case RELOP_EQ:
          m_key.init();
          m_fieldCount = 0;
          m_relop      = RELOP_FALSE;
          return true;
        case RELOP_GE:
        case RELOP_GT:
          putNumberInKey(i,roundUpToNearestFloat(d));
          m_relop      = RELOP_GE;
          m_fieldCount = i + 1;
          return true;
        case RELOP_LE:
        case RELOP_LT:
          putNumberInKey(i,roundDownToNearestFloat(d));
          m_relop      = RELOP_LE;
          m_fieldCount = i + 1;
          return true;
        }
      }
    } else {
      putNumberInKey(i,d);
    }
  } else if(c < 0) {
    switch(m_relop) {
    case RELOP_EQ:
      m_key.init();
      m_fieldCount = 0;
      m_relop      = RELOP_FALSE;
      return true;
    case RELOP_GE:
    case RELOP_GT:
      m_fieldCount = i;
      return true;
    case RELOP_LE:
    case RELOP_LT:
      m_relop      = RELOP_LT;
      m_fieldCount = i;
      return true;
    }
  } else { // c > 0
    switch(m_relop) {
    case RELOP_EQ:
      m_key.init();
      m_fieldCount = 0;
      m_relop      = RELOP_FALSE;
      return true;
    case RELOP_GE:
    case RELOP_GT:
      m_relop      = RELOP_GT;
      m_fieldCount = i;
      return true;
    case RELOP_LE:
    case RELOP_LT:
      m_fieldCount = i;
      return true;
    }
  }
  return false;
}
Пример #4
0
bool Parser::processMeshFile(Shape *pShape, std::vector<MeshTriangle *> *MTList)
{	
	std::string 	strEtiqueta, strFile, strLine, strType;
	std::ifstream 	fsFile;
	
	Point			v;	// Vertice
	Vec3			n;	// Normal
	Vec2			t;	// Textura
	
	Mesh			*pMesh = dynamic_cast<Mesh *> (pShape);
		
	int				nVertex, nNormals, nTextures, nFaces;
	
	// Para el log
	nVertex = nNormals = nTextures = nFaces = 0;
	
	if(!readContent(strFile, '<'))
        return false;
        
	if(!readToken(strEtiqueta))
		return false;
		
	if(strEtiqueta != "/file")
		return false;
		
	// Abrir fichero
	fsFile.open(strFile.c_str());
	
	// Leemos el fichero linea a linea
	while(std::getline(fsFile, strLine)){
		if((strLine[0] == 'v') && (strLine[1] == ' ')) { // Vertice
			// Procesar vertice
						
			int i = 1; // Posicion en la linea
			
			// Evitamos los espacios antes del primer numero, si los hay
			while(strLine[i] == ' ') i++; 
			
			for(int j = 0; j < 3; j++) { // Tres veces para tres float
				std::string strTemp("");
						
				while(1) { // Hasta que no encontremos un espacio
					if((strLine[i] != ' ') && (i < (strLine.length() -1))) {
						strTemp = strTemp + strLine[i];
						i++; // Siguiente caracter
					}
					else
					{
						i++; 	// Saltamos el espacio en blanco
						break;
					}
				}
				
				if(strTemp.length() > 0) {
					if(validFloat(strTemp))
						v.e[j] = atof(strTemp.c_str());
					else {
						// Lanzar error
					}
				}
			}
			
			pMesh->addVertex(v);
            nVertex++;
		}
		else if((strLine[0] == 'v') && (strLine[1] == 'n')) { // Normal
			// Procesar normal
							
			int i = 3; // Posicion en la linea
			for(int j = 0; j < 3; j++) { // Tres veces para tres float
				std::string strTemp("");
				
				while(1) { // Hasta que no encontremos un espacio
					if((strLine[i] != ' ') && (i < (strLine.length() -1))) {
						strTemp = strTemp + strLine[i];
						i++; // Siguiente caracter
					}
					else
					{
						i++; 	// Saltamos el espacio en blanco
						break;
					}
				}
				
				if(strTemp.length() > 0) {
					if(validFloat(strTemp))
						n.e[j] = atof(strTemp.c_str());
					else {
						// Lanzar error
					}
				}
			}
			
			pMesh->addNormal(n);
            nNormals++;
		}
		else if((strLine[0] == 'v') && (strLine[1] == 't')) { // Texture
			// Procesar textura
			
			int i = 3; // Posicion en la linea
			for(int j = 0; j < 2; j++) { // Dos veces para Dos float
				std::string strTemp("");
				
				while(1) { // Hasta que no encontremos un espacio
					if((strLine[i] != ' ') && (i < (strLine.length() -1))) {
						strTemp = strTemp + strLine[i];
						i++; // Siguiente caracter
					}
					else
					{
						i++; 	// Saltamos el espacio en blanco
						break;
					}
				}
				
				if(strTemp.length() > 0) {
					if(validFloat(strTemp))
						t.e[j] = atof(strTemp.c_str());
					else {
						// Lanzar error
					}
				}
			}			
			
            pMesh->addTexture(t);
            nTextures++;
		}
		else if((strLine[0] == 'f') && (strLine[1] == ' ')) { // Face
			// Procesar face		
			
			MeshFace mfFace(-1);			
			
			int i = 2, nBlock = 0;
			while(nBlock < 3) {
				int nNumber = 0; 			// Primer numero del bloque
				std::string strTemp(""); 	// Temporal para almacenar numeros
				
				while(nNumber < 3) { // Repetir hasta el tercer numero
					if(strLine[i] == '/') { // Fin de numero, excepto el ultimo del bloque
						// Si la cadena temporal tiene un entero valido
						if((strTemp.length() > 0) && validInt(strTemp)) { 
							switch(nNumber) { // Veamos que posicion tenemos
								case 0: // Vertice
									mfFace.nVIndex[nBlock] = atoi(strTemp.c_str()) - 1;									
									break;
								case 1: // Textura
									mfFace.nTIndex[nBlock] = atoi(strTemp.c_str()) - 1;
									break;
							}
						}
						// Si la cadena está vacía o el numero no es valido
						// no almacenamos nada. El valor está por defecto a -1,
						// con lo que el render sabrá qué hacer en caso de
						// encontrarlo.						
						
						strTemp.clear(); 	// Limpiamos la cadena
						nNumber++;			// Siguiente numero		
						i++;				// Avanzamos en la linea
					}
					else if(strLine[i] == ' ') { // Fin de bloque
						// Almacenamos el numero, si lo hay
						if((strTemp.length() > 0) && validInt(strTemp)) {
							switch(nNumber) {
								case 0: // Vertice
									mfFace.nVIndex[nBlock] = atoi(strTemp.c_str()) - 1;									
									break;
								case 1: // Textura
									mfFace.nTIndex[nBlock] = atoi(strTemp.c_str()) - 1;
									break;
								case 2: // Normal
									mfFace.nNIndex[nBlock] = atoi(strTemp.c_str()) - 1;
									break;
							}
						}
									
						nNumber = 3;	// Salimos del while
						nBlock++;		// Nuevo bloque
						i++;			// Avanzamos por la cadena
					}
					else if(i == (strLine.length() - 1)) { // Final de linea
						// Almacenamos el numero, si lo hay
						if((strTemp.length() > 0) && validInt(strTemp)) {
							switch(nNumber) {
								case 0: // Vertice
									mfFace.nVIndex[nBlock] = atoi(strTemp.c_str()) - 1;									
									break;
								case 1: // Textura
									mfFace.nTIndex[nBlock] = atoi(strTemp.c_str()) - 1;
									break;
								case 2: // Normal
									mfFace.nNIndex[nBlock] = atoi(strTemp.c_str()) - 1;
									break;
							}
						}
						
						nNumber = 3;
						nBlock = 3; 	// Salimos de ambos while
					}
					else { // Metemos el caracter en la cadena temporal, y seguimos
						strTemp = strTemp + strLine[i];
						i++;
					}
				}
			}
			
			// Creamos el nuevo triangulo.
			MeshTriangle *pNewT = new MeshTriangle(mfFace, pMesh);
			// Lo añadimos a la lista
			MTList->push_back(pNewT);
			
			// Incrementamos el numero de triangulos en la malla
			pMesh->increaseTriangleCount();
			
			nFaces++;		
		}
	}
	fsFile.close();
	
	return true;
}