diff --git a/include/openmc/plot.h b/include/openmc/plot.h index b3c2236ac..2b37869e8 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -67,9 +67,8 @@ namespace openmc { }; -extern "C" void output_ppm(ObjectPlot* pl, - const std::vector< std::vector< std::vector > > &data); - +void output_ppm(ObjectPlot* pl, + std::vector< std::vector< std::vector > > data); extern "C" void create_ppm(ObjectPlot* pl); diff --git a/src/plot.F90 b/src/plot.F90 index 7465df4f3..adc91c72d 100644 --- a/src/plot.F90 +++ b/src/plot.F90 @@ -71,86 +71,6 @@ contains err = 0 end function openmc_plot_geometry -!=============================================================================== -! CREATE_PPM creates an image based on user input from a plots.xml -! specification in the portable pixmap format (PPM) -!=============================================================================== - -! subroutine create_ppm(pl) -! type(ObjectPlot), intent(in) :: pl - -! integer :: in_i -! integer :: out_i -! integer :: x, y ! pixel location -! integer :: rgb(3) ! colors (red, green, blue) from 0-255 -! integer :: id -! integer :: height, width -! real(8) :: in_pixel -! real(8) :: out_pixel -! real(8) :: xyz(3) -! integer, allocatable :: data(:,:,:) -! type(Particle) :: p - -! width = pl % pixels(1) -! height = pl % pixels(2) - -! in_pixel = pl % width(1)/dble(width) -! out_pixel = pl % width(2)/dble(height) - -! ! Allocate and initialize results array -! allocate(data(3, width, height)) -! data(:,:,:) = 0 - -! if (pl % basis == PLOT_BASIS_XY) then -! in_i = 1 -! out_i = 2 -! xyz(1) = pl % origin(1) - pl % width(1) / TWO -! xyz(2) = pl % origin(2) + pl % width(2) / TWO -! xyz(3) = pl % origin(3) -! else if (pl % basis == PLOT_BASIS_XZ) then -! in_i = 1 -! out_i = 3 -! xyz(1) = pl % origin(1) - pl % width(1) / TWO -! xyz(2) = pl % origin(2) -! xyz(3) = pl % origin(3) + pl % width(2) / TWO -! else if (pl % basis == PLOT_BASIS_YZ) then -! in_i = 2 -! out_i = 3 -! xyz(1) = pl % origin(1) -! xyz(2) = pl % origin(2) - pl % width(1) / TWO -! xyz(3) = pl % origin(3) + pl % width(2) / TWO -! end if - -! ! allocate and initialize particle -! call particle_initialize(p) -! p % coord(1) % xyz = xyz -! p % coord(1) % uvw = [ HALF, HALF, HALF ] -! p % coord(1) % universe = root_universe - -! !$omp parallel do firstprivate(p) private(x, rgb, id) reduction(+ : data) -! do y = 1, height -! ! Set y coordinate -! p % coord(1) % xyz(out_i) = xyz(out_i) - out_pixel*(y - 1) -! do x = 1, width -! ! Set x coordinate -! p % coord(1) % xyz(in_i) = xyz(in_i) + in_pixel*(x - 1) - -! ! get pixel color -! call position_rgb(p, pl, rgb, id) -! ! Create a pixel at (x,y) with color (r,g,b) -! data(:, x, y) = rgb -! end do -! end do -! !$omp end parallel do - -! ! Draw tally mesh boundaries on the image if requested -! if (pl % index_meshlines_mesh >= 0) call draw_mesh_lines(pl, data) - -! ! Write out the ppm to a file -! call output_ppm(pl, data) - -! end subroutine create_ppm - !=============================================================================== ! DRAW_MESH_LINES draws mesh line boundaries on an image !=============================================================================== diff --git a/src/plot.cpp b/src/plot.cpp index d846676b4..589883113 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1,6 +1,4 @@ #include -#include -#include #include "openmc/plot.h" #include "openmc/constants.h" @@ -64,7 +62,7 @@ void create_ppm(ObjectPlot* pl) { double in_pixel = (pl->width[0])/double(width); double out_pixel = (pl->width[1])/double(height); - std::vector< std::vector< std::vector>> data; + std::vector< std::vector< std::vector > > data; data.resize(width); for (auto & i : data) { @@ -80,23 +78,23 @@ void create_ppm(ObjectPlot* pl) { in_i = 0; out_i = 1; xyz[0] = pl->origin[0] - pl->width[0] / TWO; - xyz[1] = pl->origin[1] - pl->width[1] / TWO; + xyz[1] = pl->origin[1] + pl->width[1] / TWO; xyz[2] = pl->origin[2]; } else if (PLOT_BASIS::XZ == pl->basis) { in_i = 0; out_i = 2; xyz[0] = pl->origin[0] - pl->width[0] / TWO; xyz[1] = pl->origin[1]; - xyz[2] = pl->origin[2] - pl->width[1] / TWO; + xyz[2] = pl->origin[2] + pl->width[1] / TWO; } else if (PLOT_BASIS::YZ == pl->basis) { in_i = 1; out_i = 2; xyz[0] = pl->origin[0]; xyz[1] = pl->origin[1] - pl->width[0] / TWO; - xyz[2] = pl->origin[2] - pl->width[1] / TWO; + xyz[2] = pl->origin[2] + pl->width[1] / TWO; } - double dir[3]; + double dir[3] = {HALF, HALF, HALF}; Particle *p = new Particle(); p->initialize(); std::copy(xyz, xyz+3, p->coord[0].xyz); @@ -110,7 +108,7 @@ void create_ppm(ObjectPlot* pl) { p->coord[0].xyz[out_i] = xyz[out_i] - out_pixel*(y); for (int x = 0; x < width; x++) { p->coord[0].xyz[in_i] = xyz[in_i] + in_pixel*(x); - // position_rgb(p, pl, rgb, id); + position_rgb(p, pl, rgb, id); data[x][y][0] = rgb[0]; data[x][y][1] = rgb[1]; data[x][y][2] = rgb[2]; @@ -188,30 +186,34 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { //=============================================================================== void output_ppm(ObjectPlot* pl, - const std::vector< std::vector< std::vector > > &data) + std::vector< std::vector< std::vector > > data) { // Open PPM file for writing std::string fname = std::string(pl->path_plot); fname = strtrim(fname); - std::ofstream of(fname); + std::ofstream of; + + of.open(fname); // Write header of << "P6" << std::endl; of << pl->pixels[0] << " " << pl->pixels[1] << std::endl; of << "255" << std::endl; + of.close(); + of.open(fname, std::ios::binary | std::ios::app); // Write color for each pixel for (int y = 0; y < pl->pixels[1]; y++) { for (int x = 0; x < pl->pixels[0]; x++) { std::vector rgb = data[x][y]; - of << (char)rgb[0] << (char)rgb[1] << (char)rgb[2]; + of.write((char*)&rgb[0], 1); + of.write((char*)&rgb[1], 1); + of.write((char*)&rgb[2], 1); } } - // Close file of.close(); - } void