示例#1
0
文件: csf_file.cpp 项目: ChangerR/xcc
int Ccsf_file::post_open()
{
	if (!is_valid())
		return 1;
	if (vdata().size() != get_size())
		return 0;
	const byte* r = data() + sizeof(t_csf_header);
	for (int i = 0; i < header().count1; i++)
	{
		read_int(r);
		int flags = read_int(r);
		string name = read_string(r);
		if (flags & 1)
		{
			bool has_extra_value = read_int(r) == csf_string_w_id;
			wstring value = read_wstring(r);
			string extra_value;
			if (has_extra_value)
				extra_value = read_string(r);
			set_value(name, value, extra_value);
		}
		else
			set_value(name, wstring(), string());
	}
	return 0;
}
示例#2
0
bool VarDriverXY::loadBGfromFile()
{
	
	// Read in the background state
	// Read the r and v pairs from a file
	double xPos, yPos, zPos, psi, chi, w, h, q, rho;
	int yi = 0;
	vector<real> psiBG, chiBG, wBG, hBG, qBG, rpBG;
	ifstream vdata("./XYZbackground.in");
	vdata.width(14);
	while (vdata >> zPos >> yPos >> xPos >> psi >> chi >> w >> h >> q >> rho)
	{
		if (y.empty()) y.push_back (yPos);
		if (yPos != y.back()) {
			// Assign the initial background fields
			BG[yi][0] =  psiBG;
			BG[yi][1] =  chiBG;
			BG[yi][2] =  wBG;
			BG[yi][3] =  hBG;
			BG[yi][4] =  qBG;
			BG[yi][5] =  rpBG;
			x.clear();
			psiBG.clear(); chiBG.clear(); wBG.clear();
			hBG.clear(); qBG.clear(); rpBG.clear();
			y.push_back (yPos);
			yi++;
		}		
		x.push_back (xPos);
		double height = zPos;
		real rhoBar = rhoBase*exp(-rhoInvScaleHeight*height);
		real qBar = 19.562 - 0.004066*height + 7.8168e-7*height*height;
		real hBar = 3.5e5;
		psiBG.push_back (psi);
		chiBG.push_back (chi);
		wBG.push_back (w);
		hBG.push_back ((h-hBar)*1.e-3);
		qBG.push_back (q-qBar);
		rpBG.push_back ((rho/(1 + q/1000.) - rhoBar)*100.);
	}
	
	// Assign the final strip
	BG[yi][0] =  psiBG;
	BG[yi][1] =  chiBG;
	BG[yi][2] =  wBG;
	BG[yi][3] =  hBG;
	BG[yi][4] =  qBG;
	BG[yi][5] =  rpBG;
		
	// Check that z.size is not bigger than allocated array
	if (y.size() > maxJdim) {
		cerr << "Memory overflow in y direction :" << y.size() << ">\t" << maxJdim << endl;
		return false;
	} else if (!y.size()) {
		cerr << "No heights! Problem reading BG file" << endl;
	}
	
	return true;
	
}	
示例#3
0
void RateStateSimWindow::recalc(void) {
	std::vector<std::vector<realtype> >	results;
	double					time_max = 200, time_step = 0.01;
	RSParams				params(NBLOCKS, NEQ, NPARAMS, time_step, time_max);
	unsigned int			i, npoints;
	double					xi, vi, hi;
	
	std::cerr << param_a << " " << param_b << " " << param_k << " " << param_r << " " << param_w << std::endl;
	for (i=0;i<params.num_blocks();++i) {
		params.param(i, A_PARAM) = RCONST(param_a);
		params.param(i, B_PARAM) = RCONST(param_b);
		params.param(i, K_PARAM) = RCONST(param_k);
		params.param(i, R_PARAM) = RCONST(param_r);
		params.param(i, W_PARAM) = RCONST(param_w);
		params.init_val(i, EQ_X) = RCONST(-10.0);
		params.init_val(i, EQ_V) = RCONST(1.0);
		params.init_val(i, EQ_H) = RCONST(1.0);
	}
	
	run_rate_state_sim(results, params);
	npoints = results.size();
	QVector<QPointF>		xdata(npoints), vdata(npoints), hdata(npoints), fdata(npoints), dp_data(npoints);
	double force_integral=0, old_t=0;
	
	for (i=0;i<results.size();++i) {
		xi = results[i][1];
		vi = results[i][2];
		hi = results[i][3];
		xdata[i] = QPointF(results[i][0], xi);
		vdata[i] = QPointF(results[i][0], vi);
		hdata[i] = QPointF(results[i][0], hi);
		fdata[i] = QPointF(results[i][0], F(0, vi, hi, params));
		dp_data[i] = QPointF(results[i][0], results[i][0]);
		force_integral += (results[i][0]-old_t)*F(0, vi, hi, params);
		old_t = results[i][0];
	}
	force_integral /= (results.size()/(time_step*time_max));
	
	//std::cerr << force_integral << std::endl;
	
	position_data->setData(new QwtPointSeriesData(xdata));
	velocity_data->setData(new QwtPointSeriesData(vdata));
	theta_data->setData(new QwtPointSeriesData(hdata));
	force_data->setData(new QwtPointSeriesData(fdata));
	driver_data->setData(new QwtPointSeriesData(dp_data));
	
	position_plot->replot();
	velocity_plot->replot();
	theta_plot->replot();
	force_plot->replot();
}
示例#4
0
bool loadObj( std::vector<Geometry> &geomList, const std::string &filename, float scale, int flags)
{
    std::ifstream file;
    file.open(filename.c_str(), std::ios::in);

    std::cout<<"loading "<<filename<<std::endl;

    if(file.fail())
    {
        std::cout<<"loadObj failed, could not read "<<std::endl;
        return 1;
    }

    VertexBank vb;

    Geometry g;
    std::string line,param;

    std::vector<vec3> tempVertex;
    std::vector<vec3> tempNormal;
    std::vector<vec2> tempTexCoord;

    tempVertex.reserve(10000);
    tempNormal.reserve(10000);
    tempTexCoord.reserve(10000);
    
    std::vector<std::vector<int> > vertexUsed;
    std::vector<int> texCoordUsed;
    int tempSG = 0;

    std::vector<size_t> vertexRemap;
    std::vector<size_t> normalRemap;
    std::vector<size_t> texCoordRemap;

    std::vector<int> resetVector;
    resetVector.resize(1,-1);

    std::string tempName;

    while( !file.eof() && file.good() )
    {
        std::getline(file,line);

        #ifdef DEBUG
        std::cout<<line<<"\n";
        #endif
        Tokenizer token(line);

        param = token.getToken();
        if(param == "v")
        {
            vec3 vertex;

            vertex.x = scale*toFloat(token.getToken());
            vertex.y = scale*toFloat(token.getToken());
            vertex.z = scale*toFloat(token.getToken());

            //tempVertex.push_back(vertex);
            //vertexUsed.push_back(resetVector);
            vertexRemap.push_back( insertUnique(tempVertex, vertex) );
        }
        else if(param == "f")
        {
            ivec4 vdata(-1), tdata(-1), ndata(-1), fdata(-1);

            for(int i=0; i<(int)token.size()-1; ++i)
            {
                param = token.getToken();
                getIndices(param, vdata[i], tdata[i], ndata[i],
                    hasVertex,
                    hasTexCoord && !(flags & LOADOBJ_IGNORE_TEXCOORDS),
                    hasNormal && !(flags & LOADOBJ_IGNORE_NORMALS) );

                int remappedV = (vdata[i] > -1) ? vdata[i] : -1;
                int remappedN = (ndata[i] > -1) ? ndata[i] : -1;
                int remappedT = (tdata[i] > -1) ? tdata[i] : -1;

                int index;
                //printf("Checking vertex uniqueness \n");
                if(vb.isUnique(remappedV, remappedN, remappedT, index))
                {
                    index = g.getVertexSize();

                    Geometry::sVertex tv;

                    assert( remappedV < (int)tempVertex.size() );
                    tv.position = tempVertex[ remappedV ];

                    if(remappedT > -1)
                    {
                        assert( remappedT < (int)tempTexCoord.size() );
                        tv.texCoord = tempTexCoord[ remappedT ];
                    }
                    if(remappedN > -1)
                    {
                        assert( remappedN < (int)tempNormal.size() );
                        tv.normal = tempNormal[ remappedN ];
                    }

                    g.addVertex(tv);
                }

                assert(index < (int)g.getVertexSize());
                fdata[i] = index;

                // if(tempSG > (int)vertexUsed[vdata[i]].size()-1)
                //     vertexUsed[vdata[i]].resize(tempSG+1,-1);

                // if(vertexUsed[vdata[i]][tempSG] > -1)
                //     fdata[i] = vertexUsed[vdata[i]][tempSG];
                // else
                // {
                //     vertexUsed[vdata[i]][tempSG] = (int)g.vertices.size();

                //     fdata[i] = g.getVertexSize();

                //     Geometry::sVertex tv;
                //     tv.position = tempVertex[vdata[i]];
                //     //tv.nx = tv.ny = tv.nz = tv.s = tv.t = 0.0f;

                //     if(vtdata[i]>-1 && !(flags & LOADOBJ_IGNORE_TEXCOORDS))
                //     {
                //         assert( vtdata[i] < tempTexCoord.size() );
                //         tv.texCoord = tempTexCoord[vtdata[i]];
                //     }
                //     if(ndata[i]>-1 && !(flags & LOADOBJ_IGNORE_NORMALS))
                //     {
                //         assert( ndata[i] < tempNormal.size() );
                //         tv.normal = tempNormal[ndata[i]];
                //     }

                //     g.addVertex(tv);
                // }
            }
            // if its a triangle, just insert.
            // However if its a quad, then insert the two triangles forming the quad.
            uvec3 t;
            t[0] = fdata[0];
            t[1] = fdata[1];
            t[2] = fdata[2];

            g.addTriangle(t);

            if(fdata[3] != -1)
            {
                t[0] = fdata[3];
                t[1] = fdata[0];
                t[2] = fdata[2];

                g.addTriangle(t);
            }
        }
        else if(param == "vt")
        {
            vec2 tc;

            tc.x = toFloat(token.getToken());
            tc.y = toFloat(token.getToken());

            //tempTexCoord.push_back(tc);
            texCoordRemap.push_back( insertUnique(tempTexCoord, tc) );
        }
        else if(param == "vn")
        {
            vec3 normal;

            normal.x = toFloat(token.getToken());
            normal.y = toFloat(token.getToken());
            normal.z = toFloat(token.getToken());

            //tempNormal.push_back(normal);
            normalRemap.push_back( insertUnique(tempNormal, normal) );
        }
        else if(param == "s")
            tempSG = toInt(token.getToken());
        else if(param == "g")
        {
            /*if(first)
                first=false;
            else
            {
                g.process();
                geomList.push_back(g);
            }

            for(unsigned int i=0; i<vertexUsed.size(); ++i)
                vertexUsed[i].clear();
            
            g.clear();
            */
        }

        if(file.eof())
            break;
    }
    file.close();
    printf("tempVertex.size() = %i \n", (int)tempVertex.size());
    printf("tempNormal.size() = %i \n", (int)tempNormal.size());
    printf("tempTexCoord.size() = %i \n", (int)tempTexCoord.size());
    printf("Reading is done, gonna process \n");
    g.process();
    geomList.push_back(g);

    std::cout<<"done reading "<<filename<<std::endl;

    return 0;
}