예제 #1
0
void KMLNetOutput::createKML(const std::string& fileWithNodes, const std::string& kmlFileName){

	std::cout << "KML will be written to: " << kmlFileName << std::endl;
	int nbNodes = net_->getNbNodes();
	std::vector<FPType> xCoord(nbNodes, 0);
	std::vector<FPType> yCoord(nbNodes, 0);
	std::vector<int> nodeID(nbNodes, 0);
	
	readCoord(fileWithNodes, xCoord, yCoord, nodeID);

	FileWriter writeKml(kmlFileName);
	writeKml.writeLine(createKmlHeader());
	
	for (StarLink* link = net_->beginOnlyLink(); link != NULL; link = net_->getNextOnlyLink()) {
		if (shouldCreatePlacemark(link)) {
			int tail = link->getNodeFromIndex();
			int head = link->getNodeToIndex();
			FPType x1 = xCoord[tail];
			FPType y1 = yCoord[tail];
			FPType x2 = xCoord[head];
			FPType y2 = yCoord[head];
			if (x1 == 0 && y1 == 0) std::cout << "Missing node coordinate: " << link->getNodeFrom() << 
								" link: " << link->toString() << std::endl; 
			if (x2 == 0 && y2 == 0) std::cout << "Missing node coordinate: " << link->getNodeTo() << 
								" link: " << link->toString() << std::endl;
			if (x1 != 0 && y1 != 0 && x2 != 0 && y2 != 0) 
				writeKml.writeLine(createPlacemark(x1, y1, x2, y2, link)); 
		}
	}

	writeKml.writeLine(createKmlFooter());
};
예제 #2
0
void GerberReader::parseLine(char *line)
{
    if(mCoord == COORD_RELATIVE) {
        mReadX = 0.0f;
        mReadY = 0.0f;
    }
    int tmp;
    bool needD = false;
    while (*line && *line!='*' && *line!='\r' && *line!='\n') {
        switch(*line) {
        case '(': // comment
            while(*line!=')') {
                line++;
                if(*line==0 || *line=='\r' || *line=='\n')
                    goto gofromwhile;
            }
            break;
        case ';':  // comment
            goto gofromwhile;
        case 'M':
        case 'm': // ignore
            line = Readers::readArgi(line+1, &tmp)-1;
            break;
        case 'g':
        case 'G':
            line = Readers::readArgi(line+1, &tmp)-1;
            switch(tmp) {
            case 1: // linear inrterpolation
                mInterpolation = INTERPOLATION_LINEAR;
                break;
            case 2: // round clock wise interpolastion
                mInterpolation = INTERPOLATION_ROUND_CW;
                break;
            case 3: // round couter clock wise interpolation
                mInterpolation = INTERPOLATION_ROUND_CCW;
                break;
            case 4: // comment
                goto gofromwhile;
            case 36:
            case 37: // polygons
                mWarnings = "Unimplemented commands G36/G37(Polygons).";
                break;
            case 54: // choose aperture Dxx
                break;
            case 70: // inch
                mUnits = UNITS_INC;
                break;
            case 71: // mm
                mUnits = UNITS_MM;
                break;
            case 75: // full round
                mInterpolation = INTERPOLATION_FULLROUND;
                break;
            case 90: // absolute coordinats
                mCoord = COORD_ABSOLUTE;
                break;
            case 91: // relative coordinats
                mCoord = COORD_RELATIVE;
                break;

            }
            break;
        case '%':
            if(line[1]=='M' && line[2]=='O' && line[3]=='I' && line[4]=='N') {// units
                mUnits = UNITS_INC;
                line++;
            } else if(line[1]=='M' && line[2]=='O' && line[3]=='M' && line[4]=='M') {// unts
                mUnits = UNITS_MM;
                line++;
            } else if(line[1]=='F' && line[2]=='S') { // gerber's properties
                line+=2;
                while(*line!='*') {
                    line++;
                    if(*line==0 || *line=='\r' || *line=='\n')
                        goto gofromwhile;
                    if(*line == 'L')
                        mZeroMode = ZM_LEADZERO;
                    else if (*line == 'T')
                        mZeroMode = ZM_POSTZERO;
                    else if (*line == 'D')
                        mZeroMode = ZM_DOTTED;
                    else if (*line == 'A')
                        mCoord = COORD_ABSOLUTE;
                    else if (*line == 'I')
                        mCoord = COORD_RELATIVE;
                    else if (*line == 'X')
                        line = Readers::readArgi(line+1, &mXFormat)-1;
                    else if (*line == 'Y')
                        line = Readers::readArgi(line+1, &mYFormat)-1;
                }
            } else if(line[1]=='A' && line[2]=='D' && line[3]=='D') { // appertures
                line+=3;
                int dnum=-1;
                line = Readers::readArgi(line+1, &dnum);
                if(dnum!=-1) {
                    Apperture *a = new Apperture;
                    a->sh = SHAPE_RECT; // always make square, even if something tricky inside
                    if(mAppertures[dnum]!=0)
                        delete mAppertures[dnum];
                    mAppertures[dnum] = a;
                    if(*line++=='C')
                        a->sh = SHAPE_ROUND;
                    line++; // ignore ';'
                    float f = -1.0f;
                    line = Readers::readArgf(line, &f);
                    if(mUnits == UNITS_INC)
                        f *= 25.4f;
                    a->x = f;
                    if(*line++=='X') {
                        line = Readers::readArgf(line, &f);
                        if(mUnits == UNITS_INC)
                            f *= 25.4f;
                        a->y = f;
                    } else {
                        a->y = a->x;
                    }
                }
            }

            while(*line!='%') {
                line++;
                if(*line==0 || *line=='\r' || *line=='\n')
                    goto gofromwhile;
            }
            break;
        case 'd':
        case 'D':
            line = Readers::readArgi(line+1, &lastD)-1;
            doD();
            needD = false;
            break;
        case 'x':
        case 'X':
            line = readCoord(line+1, mXFormat, mX, &mReadX)-1;
            needD = true;
            break;
        case 'y':
        case 'Y':
            line = readCoord(line+1, mYFormat, mY, &mReadY)-1;
            needD = true;
            break;
        }

        line++;
    }
    if(needD)
        doD();
gofromwhile:
    return;
}
예제 #3
0
Model::Model(char* objPath, GLfloat* diffuseColor, GLfloat* specularColor, GLfloat* emissiveColor, GLfloat* shininess)
{
	// Cria o stream que lerá o objeto
	fstream reader = fstream();

	// Abre o arquivo no modo de leitura
	reader.open(objPath, fstream::in);

	// Verifica se o arquivo foi aberto corretamente
	if (!reader.is_open())
	{
		throw ("Failed to load");
	}

	// Salva os dados do material do modelo
	if (verifyRGB(diffuseColor) && verifyRGB(specularColor) && verifyRGB(emissiveColor))
	{
		Model::diffuseColor = diffuseColor;
		Model::specularColor = specularColor;
		Model::emissiveColor = emissiveColor;
	}

	// Salva dado sobre o brilho do modelo
	if (verifyShininess(shininess))
	{
		Model::shininess = shininess;
	}

	// Buffer que salva cada linha
	char buff[256];

	// Varre enquanto não chega ao fim do arquivo
	while (!reader.eof())
	{
		// Obtem uma linha do stream
		reader.getline(buff, sizeof(buff));

		if (strlen(buff) >= 2 && strncmp("v ", buff, 2) == 0) // Verifica se é uma linha de vertice
		{
			// Salva o ponto criado no vetor de vertices
			vertices.push_back(readPoint(buff));
		}
		else if (strlen(buff) >= 3 && strncmp("vn ", buff, 3) == 0) // Verifica se é uma linha de normal
		{
			// Salva o ponto criado no vetor de normais
			normals.push_back(readPoint(buff));
		}
		else if (strlen(buff) >= 3 && strncmp("vt ", buff, 3) == 0) // Verifica se é uma linha de testura
		{
			// Salva o ponto criado no vetor de normais
			textures.push_back(readCoord(buff));
		}
		else if (strlen(buff) >= 2 && strncmp("f ", buff, 2) == 0) // Verifica se é uma linha de face
		{
			// Salva a face criada no vetor de faces da classe
			faces.push_back(readFace(buff, vertices, normals, textures));
		}
	}

	// Verifica se existem faces no modelo
	if (faces.size() == 0)
	{
		throw ("Invalid obj");
	}

	// Verifica se existem normais no modelo, se não, calcula normais
	if (faces[0].normals.size() == 0)
	{
		// Calucla as normais dos vertices
		calculateVerticesNormals();
	}
}