Exemple #1
0
MeshLib::Mesh* VtkMeshConverter::convertImgToMesh(const double* img,
        const double origin[3],
        const size_t imgHeight,
        const size_t imgWidth,
        const double &scalingFactor,
        MeshElemType elem_type,
        UseIntensityAs intensity_type)
{
    const size_t incHeight = imgHeight+1;
    const size_t incWidth  = imgWidth+1;
    double* pixVal (new double[incHeight * incWidth]);
    bool* visNodes(new bool[incWidth * incHeight]);
    int* node_idx_map(new int[incWidth * incHeight]);

    double noDataValue = getExistingValue(img, imgWidth*imgHeight);

    for (size_t j = 0; j < imgHeight; j++)
    {
        pixVal[j]=0;
        visNodes[j]=false;
        node_idx_map[j]=-1;
    }
    for (size_t i = 0; i < imgWidth; i++)
    {
        for (size_t j = 0; j < imgHeight; j++)
        {
            const size_t img_idx = i * imgHeight + j;
            const size_t index = (i+1) * incHeight + j;
            if (img[img_idx] == -9999)
            {
                visNodes[index] = false;
                pixVal[index] = noDataValue;
            }
            else
            {
                pixVal[index] = img[img_idx];
                visNodes[index] = true;
            }

            node_idx_map[index]=-1;
        }
        pixVal[(i+2)*incHeight-1]=0;
        visNodes[(i+2)*incHeight-1]=false;
        node_idx_map[(i+2)*incHeight-1]=-1;
    }

    MeshLib::Mesh* mesh = constructMesh(pixVal, node_idx_map, visNodes, origin, imgHeight, imgWidth, scalingFactor, elem_type, intensity_type);

    delete [] pixVal;
    delete [] visNodes;
    delete [] node_idx_map;

    return mesh;
}
Exemple #2
0
MeshLib::Mesh* ConvertRasterToMesh::execute() const
{
	const size_t height(_raster.getNRows()+1);
	const size_t width(_raster.getNCols()+1);
	const size_t size(height*width);
	double* pix_vals(new double[size]);
	bool* vis_nodes(new bool[size]);

	// determine a valid value for substitution of no data values
	double substitution(getExistingValue(_raster.begin(), _raster.end()));

	// fill first row with non visual nodes
	for (size_t j = 0; j < _raster.getNCols(); j++) {
		pix_vals[j] = 0;
		vis_nodes[j] = false;
	}

	GeoLib::Raster::const_iterator raster_it(_raster.begin());
	for (size_t i = 0; i < _raster.getNRows(); ++i) {
		for (size_t j = 0; j < _raster.getNCols(); ++j) {
			const size_t index = (i+1) * width + j;
			if (*raster_it == _raster.getNoDataValue()) {
				pix_vals[index] = substitution;
				vis_nodes[index] = false;
			} else {
				pix_vals[index] = *raster_it;
				vis_nodes[index] = true;
			}
			++raster_it;
		}
		// fill last column with non-visual nodes
		pix_vals[(i + 2) * width - 1] = 0;
		vis_nodes[(i + 2) * width - 1] = false;
	}

	MeshLib::Mesh* mesh = constructMesh(pix_vals, vis_nodes);

	delete [] pix_vals;
	delete [] vis_nodes;

	return mesh;
}