示例#1
0
void Curve::readIn(GridData& gdata, Triple** data, unsigned int columns, unsigned int rows)
{
	gdata.setSize(columns,rows);
	
	ParallelEpiped range(Triple(DBL_MAX,DBL_MAX,DBL_MAX),Triple(-DBL_MAX,-DBL_MAX,-DBL_MAX));

	/* fill out the vertex array for the mesh. */
	for (unsigned i = 0; i != columns; ++i){
		for (unsigned j = 0; j != rows; ++j){
			gdata.vertices[i][j][0] = data[i][j].x; 
			gdata.vertices[i][j][1] = data[i][j].y;
			gdata.vertices[i][j][2] = data[i][j].z;

			if (data[i][j].x > range.maxVertex.x)
				range.maxVertex.x = data[i][j].x;
			if (data[i][j].y > range.maxVertex.y)
				range.maxVertex.y = data[i][j].y;
			if (data[i][j].z > range.maxVertex.z)
				range.maxVertex.z = data[i][j].z;
			if (data[i][j].x < range.minVertex.x)
				range.minVertex.x = data[i][j].x;
			if (data[i][j].y < range.minVertex.y)
				range.minVertex.y = data[i][j].y;
			if (data[i][j].z < range.minVertex.z)
				range.minVertex.z = data[i][j].z;
 		}
	}
	gdata.setHull(range);
	emit readInFinished(title()->string());
}
示例#2
0
void Curve::sewPeriodic(GridData& gdata)
{
	// sewing
	Triple n;

	unsigned int columns = gdata.columns();
	unsigned int rows = gdata.rows();

	if (gdata.uperiodic()) {
		for (unsigned i = 0; i != columns; ++i) {
			n = Triple(gdata.normals[i][0][0] + gdata.normals[i][rows-1][0],
				gdata.normals[i][0][1] + gdata.normals[i][rows-1][1],
				gdata.normals[i][0][2] + gdata.normals[i][rows-1][2]);

			n.normalize();        
			gdata.normals[i][0][0] = gdata.normals[i][rows-1][0] = n.x;
			gdata.normals[i][0][1] = gdata.normals[i][rows-1][1] = n.y;
			gdata.normals[i][0][2] = gdata.normals[i][rows-1][2] = n.z;
		}
	}

	if (gdata.vperiodic()) {
		for (unsigned j = 0; j != rows; ++j) {
			n = Triple(gdata.normals[0][j][0] + gdata.normals[columns-1][j][0],
				gdata.normals[0][j][1] + gdata.normals[columns-1][j][1],
				gdata.normals[0][j][2] + gdata.normals[columns-1][j][2]);

			n.normalize();        
			gdata.normals[0][j][0] = gdata.normals[columns-1][j][0] = n.x;
			gdata.normals[0][j][1] = gdata.normals[columns-1][j][1] = n.y;
			gdata.normals[0][j][2] = gdata.normals[columns-1][j][2] = n.z;
		}
	}
}
示例#3
0
void GridPlot::sewPeriodic(GridData& gdata)
{
    // sewing

    Triple n;

    unsigned int columns = gdata.columns();
    unsigned int rows = gdata.rows();

    if (gdata.uperiodic())
    {
        for (unsigned i = 0; i != columns; ++i)
        {
            n = gdata.normals[i][0] + gdata.normals[i][rows-1];
            n.normalize();
            gdata.normals[i][0] = gdata.normals[i][rows-1] = n;
        }
    }
    if (gdata.vperiodic())
    {
        for (unsigned j = 0; j != rows; ++j)
        {
            n = gdata.normals[0][j] + gdata.normals[columns-1][j];
            n.normalize();
            gdata.normals[0][j] = gdata.normals[columns-1][j] = n;
        }
    }
}
示例#4
0
	void writeVolume(GridData &s, AABB &bbox, int channels, Stream *stream) {
		stream->writeChar('V');
		stream->writeChar('O');
		stream->writeChar('L');
		stream->writeChar(3);

		int type = 1;
		stream->writeInt(type);

		stream->writeInt(s.size());
		stream->writeInt(s[0].size());
		stream->writeInt(s[0][0].size());

		stream->writeInt(channels);

		stream->writeSingle(bbox.min.x);
		stream->writeSingle(bbox.min.y);
		stream->writeSingle(bbox.min.z);
		stream->writeSingle(bbox.max.x);
		stream->writeSingle(bbox.max.y);
		stream->writeSingle(bbox.max.z);

		float *data = new float[s.size() * s[0].size() * s[0][0].size() * channels];
		for (int z = 0; z < s[0][0].size(); z++) {
			for (int y = 0; y < s[0].size(); y++) {
				for (int x = 0; x < s.size(); x++) {
					for (int c = 0; c < channels; c++) {
						data[((z * s[0].size() + y) * s.size() + x) * channels + c] = s[x][y][z][c];
					}
				}
			}
		}
		stream->writeSingleArray(data, s.size() * s[0].size() * s[0][0].size() * channels);
		delete[] data;
	}
示例#5
0
void GridPlot::readIn(GridData& gdata, Triple** data, unsigned int columns, unsigned int rows)
{
    gdata.setSize(columns,rows);

    ParallelEpiped range(Triple(DBL_MAX,DBL_MAX,DBL_MAX),Triple(-DBL_MAX,-DBL_MAX,-DBL_MAX));

    /* fill out the vertex array for the mesh. */
    for (unsigned i = 0; i != columns; ++i)
    {
        for (unsigned j = 0; j != rows; ++j)
        {
            Triple& val = data[i][j];

            gdata.vertices[i][j] = val;

            if (val.x > range.maxVertex.x)
                range.maxVertex.x = val.x;
            if (val.y > range.maxVertex.y)
                range.maxVertex.y = val.y;
            if (val.z > range.maxVertex.z)
                range.maxVertex.z = val.z;
            if (val.x < range.minVertex.x)
                range.minVertex.x = val.x;
            if (val.y < range.minVertex.y)
                range.minVertex.y = val.y;
            if (val.z < range.minVertex.z)
                range.minVertex.z = val.z;
        }
    }
    gdata.setHull(range);
}
示例#6
0
void Curve::readIn(GridData& gdata, double** data, unsigned int columns, unsigned int rows,
				   double minx, double maxx, double miny, double maxy)
{
	gdata.setPeriodic(false,false);
	gdata.setSize(columns, rows);
	
	double dx = (maxx - minx) / (gdata.columns() - 1);
	double dy = (maxy - miny) / (gdata.rows() - 1);

	double tmin = DBL_MAX;
	double tmax = -DBL_MAX;

	/* fill out the vertex array for the mesh. */
	for (unsigned i = 0; i != columns; ++i){
		for (unsigned j = 0; j != rows; ++j){
			gdata.vertices[i][j][0] = minx + i*dx;
			gdata.vertices[i][j][1] = miny + j*dy;
			gdata.vertices[i][j][2] = data[i][j];

			double val = data[i][j];
			if (val > tmax)
				tmax = val;
			if (val < tmin)
				tmin = val;
 		}
	}

	ParallelEpiped hull = ParallelEpiped(Triple(gdata.vertices[0][0][0], gdata.vertices[0][0][1], tmin), 
										Triple(gdata.vertices[gdata.columns() - 1][gdata.rows() - 1][0],
											   gdata.vertices[gdata.columns() - 1][gdata.rows() - 1][1], tmax));

	gdata.setHull(hull);
	emit readInFinished(title()->string());
}
示例#7
0
void GridPlot::calcNormals(GridData& gdata)
{
    unsigned int rows = gdata.rows();
    unsigned int columns = gdata.columns();

    // normals
    
    Triple u, v, n;  // for cross product
    Triple vert_ip1j;
    Triple vert_ijp1;
    Triple vert_im1j;
    Triple vert_ijm1;

    for (unsigned i = 0; i < columns; ++i)
    {
        for (unsigned j = 0; j < rows; ++j)
        {
            Triple& n = gdata.normals[i][j];
            n = Triple(0,0,0);

            const Triple& vert_ij = gdata.vertices[i][j];

            if (i<columns-1 && j<rows-1)
            {
                vert_ip1j = gdata.vertices[i+1][j] - vert_ij;
                vert_ijp1 = gdata.vertices[i][j+1] - vert_ij;
                n += normalizedcross(vert_ip1j, vert_ijp1); // right hand system here !
            }

            if (i>0 && j>0)
            {
                vert_im1j = gdata.vertices[i-1][j] - vert_ij;
                vert_ijm1 = gdata.vertices[i][j-1] - vert_ij;
                n += normalizedcross(vert_im1j, vert_ijm1);
            }

            if (i>0 && j<rows-1)
            {
                n += normalizedcross(vert_ijp1, vert_im1j);
            }

            if (i<columns-1 && j>0)
            {
                n += normalizedcross(vert_ijm1, vert_ip1j);
            }

            n.normalize();
        }
    }
}
示例#8
0
	void initS(GridData &s, const Vector3i &res) {
		s.resize(res.x);
		for (int i = 0; i < res.x; i++) {
			s[i].resize(res.y);
			for (int j = 0; j < res.y; j++) {
				s[i][j].resize(res.z);
			}
		}
	}
示例#9
0
void GridPlot::readIn(GridData& gdata, double** data, unsigned int columns, unsigned int rows
                      , double minx, double maxx, double miny, double maxy)
{
    gdata.setPeriodic(false,false);
    gdata.setSize(columns,rows);

    double dx = (maxx - minx) / (gdata.columns() - 1);
    double dy = (maxy - miny) / (gdata.rows() - 1);

    double tmin = DBL_MAX;
    double tmax = -DBL_MAX;

    /* fill out the vertex array for the mesh. */
    for (unsigned i = 0; i != columns; ++i)
    {
        for (unsigned j = 0; j != rows; ++j)
        {
            Triple& gdata_ij = gdata.vertices[i][j];
            double& val = data[i][j];

            gdata_ij.x = minx + i*dx;
            gdata_ij.y = miny + j*dy;
            gdata_ij.z = val;

            if (val > tmax)
                tmax = val;
            if (val < tmin)
                tmin = val;
        }
    }
    ParallelEpiped hull =
            ParallelEpiped(
                Triple(
                    gdata.vertices[0][0].x,
            gdata.vertices[0][0].y,
            tmin
            ),
            Triple(
                gdata.vertices[gdata.columns()-1][gdata.rows()-1].x,
            gdata.vertices[gdata.columns()-1][gdata.rows()-1].y,
            tmax
            )
            );

    gdata.setHull(hull);
}
示例#10
0
void Curve::calcNormals(GridData& gdata)
{
	unsigned int rows = gdata.rows();
	unsigned int columns = gdata.columns();
  
	// normals
	Triple u, v, n;  // for cross product

	for (unsigned i = 0; i != columns; ++i) {
		for (unsigned j = 0; j != rows; ++j) {
			n = Triple(0,0,0);

			if (i<columns-1 && j<rows-1) {
				/*	get two vectors to cross */
				u = Triple(gdata.vertices[i+1][j][0] - gdata.vertices[i][j][0],
					gdata.vertices[i+1][j][1] - gdata.vertices[i][j][1],
					gdata.vertices[i+1][j][2] - gdata.vertices[i][j][2]);

				v = Triple(
				gdata.vertices[i][j+1][0] - gdata.vertices[i][j][0],
				gdata.vertices[i][j+1][1] - gdata.vertices[i][j][1],
				gdata.vertices[i][j+1][2] - gdata.vertices[i][j][2]);

				/* get the normalized cross product */ 
				n += normalizedcross(u,v); // right hand system here !
			}

			if (i>0 && j<rows-1) {
				u = Triple(gdata.vertices[i][j+1][0] - gdata.vertices[i][j][0],
					gdata.vertices[i][j+1][1] - gdata.vertices[i][j][1],
					gdata.vertices[i][j+1][2] - gdata.vertices[i][j][2]);
			  
				v = Triple(gdata.vertices[i-1][j][0] - gdata.vertices[i][j][0],
					gdata.vertices[i-1][j][1] - gdata.vertices[i][j][1],
					gdata.vertices[i-1][j][2] - gdata.vertices[i][j][2]);

				n += normalizedcross(u,v); 
			}

			if (i>0 && j>0) {
				u = Triple(gdata.vertices[i-1][j][0] - gdata.vertices[i][j][0],
					gdata.vertices[i-1][j][1] - gdata.vertices[i][j][1],
					gdata.vertices[i-1][j][2] - gdata.vertices[i][j][2]);

				v = Triple(gdata.vertices[i][j-1][0] - gdata.vertices[i][j][0],
					gdata.vertices[i][j-1][1] - gdata.vertices[i][j][1],
					gdata.vertices[i][j-1][2] - gdata.vertices[i][j][2]);

				n += normalizedcross(u,v);
			}

			if (i<columns-1 && j>0) {
				u = Triple(gdata.vertices[i][j-1][0] - gdata.vertices[i][j][0],
					gdata.vertices[i][j-1][1] - gdata.vertices[i][j][1],
					gdata.vertices[i][j-1][2] - gdata.vertices[i][j][2]);

				v = Triple(gdata.vertices[i+1][j][0] - gdata.vertices[i][j][0],
					gdata.vertices[i+1][j][1] - gdata.vertices[i][j][1],
					gdata.vertices[i+1][j][2] - gdata.vertices[i][j][2]);

				n += normalizedcross(u,v);
			}

			n.normalize();
			gdata.normals[i][j][0] = n.x;
			gdata.normals[i][j][1] = n.y;
			gdata.normals[i][j][2] = n.z;
		} 
	} 
}
示例#11
0
int main(int argc, char *argv[]) 
{
	char *f;
	int dpr = 10;
	GridNMC *gridbase;
	GridList *list;
	gridbase = new GridNMC();
	list = new GridList(gridbase);

	f = argv[1];

// First load the data
	fprintf (stderr, "Archivo %s  Datos %p %d\n", f, gridbase, gridbase->getN()); fflush(stderr);
	list->setList(f);

	if (list->size()<=0)
		return 1;

	fprintf (stderr, "Lista %d\n", list->size());
	

	printf ("latitude = ");
	for (int i=0; i < gridbase->getN(); i++) {
		printf("%g", gridbase->la(i));
		if (i < gridbase->getN()-1)
			printf(", ");
		else 
			printf(" ;\n");
		if (i > 0 && i % dpr==0)
			printf("\n");
	}

	printf ("longitude = ");
	for (int i=0; i < gridbase->getN(); i++) {
		printf("%g", gridbase->lo(i));
		if (i < gridbase->getN()-1)
			printf(", ");
		else 
			printf(" ;\n");
		if (i > 0 && i % dpr==0)
			printf("\n");
	}

	for (int j=0; j < list->size(); j++) 
	{
		GridData *d = list->getData(j);
		fprintf(stderr, "Data %d %g %g %p\n", j, d->getMin(), d->getMax(), d->getData());  
	  
		printf ("temperature =\n");
		for (int i=0; i < gridbase->getN(); i++) {
			printf("%g", d->getData(i));
			if (i < gridbase->getN()-1)
				printf(", ");
			else 
				printf(" ;\n");
			if (i > 0 && i % dpr==0)
				printf("\n");
		}
	}	

	return 0;
}