2

I'm trying to write a 3D image in fortran 90.

The code for the object I want in the image:

Here is a code of a cube in fortran:

       PROGRAM myimage
       integer xmax,ymax,zmax
       parameter (xmax=10,ymax=10,zmax=10)
       INTEGER mytable(1:xmax,1:ymax,1:zmax)

       do 1 i1=1,xmax
       do 2 i2=1,ymax
       do 3 i3=1,zmax
           mytable(i1,i2,i3)=0
           if ((i1.ge.3).and.(i1.le.6).and.(i2.ge.3).and.(i2.le.6).and.(i3.ge.3).and.(i3.le.6)) then 
           mytable(i1,i2,i3)=1
           endif
    3  continue
    2  continue
    1  continue

       end

The type of image I'd like to get:

The type of image I want is like this :

enter image description here

The cube would be my pixels mytable=1 and around it there would be pixels : mytable=0

What I tried:

I first tried to write a code to make the image directly in fortran, but it turned out that the image issued was not a 3D image as I wanted (see Appendix 1).

The question:

Could you explain me how to view that type of object in 3D please ?

For instance, following the comment of Vladimir F, I downloaded Paraview. I found this question that is quite similar to where I stand now.

But I don't understand what exactly I have to write in the file, if I choose to write it in the format UCD. I didn't find explanations on the internet and the link that is brought in the question there does not work.

Appendix 1:

Here is a code for a 2D image and for the 3D image I tried to code.

I first wrote a 2D image that works. I tried to generalize it to 3D. I'd like to view the object where mytable=1 in 3D.

       subroutine image2d(mytable,xmax,ymax,zmax)
       integer xmax,ymax,zmax,mytable(1:xmax,1:ymax,1:zmax)
       character*15 fname

       WRITE(fname,'(a)')'myimage2d.ppm' 
           open (100,file=fname,form='formatted')
           write(100,'(a)') 'P3'
           write(100,*) '#'
           write(100,*) xmax,ymax
           write(100,*) 2

       do 10 i10=1,xmax
       do 20 i20=1,ymax

                if (mytable(i10,i20,5).eq.0) then
                write(100,*) '2 2 2'
                else if (mytable(i10,i20,5).eq.1) then
                write(100,*) '0 0 0'
                end if
20   continue
10   continue

       end

       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

       subroutine image3d(mytable,xmax,ymax,zmax)
       integer xmax,ymax,zmax,mytable(1:xmax,1:ymax,1:zmax)
       character*15 fname

       WRITE(fname,'(a)')'myimage3d.ppm' 
           open (200,file=fname,form='formatted')
           write(200,'(a)') 'P3'
           write(200,*) '#'
           write(200,*) xmax,ymax,zmax
           write(200,*) 3

       do 11 i10=1,xmax
       do 21 i20=1,ymax
       do 31 i30=1,ymax
                if (mytable(i10,i20,i30).eq.0) then
                write(200,*) '2 2 2'
                else if (mytable(i10,i20,i30).eq.1) then
                write(200,*) '0 1 2'
                end if
31   continue
21   continue
11   continue          

           end
JoA
  • 53
  • 6
  • 1
    What does it mean "3D image"? I just do not get it. Where is the documentation for such a file format in 3D? Where does someone say that GIMP should be able to open such a 3D file? – Vladimir F Героям слава Feb 13 '20 at 13:56
  • I'm trying to make an image of an object as seen in 3D. But I have to say I didn't find any documentation on how to do it. I just saw that in some articles people did it with fortran – JoA Feb 13 '20 at 14:09
  • Would you have an idea where to look at how to make an image of a matrix where `0` pixels are transparent and `1` are black ? – JoA Feb 13 '20 at 14:23
  • 3
    That is a hopeless effort. First you have to decide about some file format. You need to know about some tool that can vizualize your data. Alas, in Paraview you can open even a textfile with x y z and other values data. You can make the data in Excel, in Fortran, wherever, but you have to learn something about data first, ONLY THEN trying to program something. Try some examples that are on the internet. OR if you want a 2D surface, read about mesh file formats. Like STL, OFF, OBJ and many other formats used for 3D printing. – Vladimir F Героям слава Feb 13 '20 at 14:46
  • 1
    You may want to try using python if you know it. You can use VPython for 3-d graphics. – Natsfan Feb 13 '20 at 23:32

0 Answers0