Ejemplo n.º 1
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());
}
Ejemplo n.º 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;
		}
	}
}
Ejemplo n.º 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;
        }
    }
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
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();
        }
    }
}
Ejemplo n.º 6
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;
		} 
	} 
}