int main (void)
{
  int size = 600; 			    // allocate size x size raster image
  MpImage image(size,size);
  
  Scene scene;				          // define scene for 3d drawing

  int nu = 25, nv = 25,  su = 2, sv = 2,  periodic = 0;
  double u0 = 5, u1 = -5, v0 = -5, v1 = 5;
  ParametricSurface(scene, mod_sqr, u0,u1,nu,su, v0,v1,nv,sv, 
		    periodic, Identity, phase_color);

  scene.BoxRatios(1,0.5,1);   // scale scene to box with x : y : z = 1 : 0.5 : 1

  float dist = 1.6;			                   // distance parameter
  scene.Look(Vector3D( 1.6*dist, 1.5*dist, 1*dist),    // camera position vector
	     Vector3D(-1.6*dist,-1.7*dist,-1*dist),     // look direction vector
	     FieldOfView(45), 			// field of view angle in degree
	     0);		            // "twist your head" angle in degree

  scene.SetGlobalShading(Facet::Gouraud); 
                                   // surface shading (None, Flat, Gouraud, ...)
  scene.SetGlobalEdgeLines(Facet::Individual); 	      // edgeline drawing option

  // Setting per-vertex coloring is the best choice to get smoothly changing
  // colors on the surface. This requires Gouraud or Phong shading to be
  // switched on. If you use per-facet coloring then the facet edges are still
  // visible. Try it by uncommenting the corresponding line below!
  scene.SetColoring(Scene::PerVertex);
  //scene.SetColoring(Scene::PerFacet);

  // Define ambient light, RGB color, and specular light and exponent
  // If per-vertex coloring or per-facet coloring is set, then only the ambient
  // light factor and the specular light factor and exponent are in effect.
  Material material(0.6, ColorF(1.,0.8,0.), 0.3,1.8); 
  scene.SetFacetMaterial(material);		   // set all facets to material

  scene.Open(image);			       // direct drawing to raster image
  scene.SetBackground(ColorF(0.3,0.6,0.9));    // draw background with RGB color
  scene.SetColor(ColorF(0,0,0));		  // define color for edge lines
  scene.Show();						   // render the surface
  scene.Close();				      // call always after close

  int d = 2*Mp.FrameWidth;
  MpFrame Main("Electron Scattering",size+d,size+30+d); // main window on screen
  new MpScrollImageWindow(Main,image,size+d,size+d,0,30); // scroll image window
  new MpQuitButton(Main,"Quit",60,30,0,0);	            // and a quit button
  new MpLabel(Main,
	      "Wave function of electron scattered at delta-potential",
	      size+d-60,30, 60,0, Mp.theBigFont,MpLabel::Embossed);
  Main.EventLoop();				      // finally start eventloop
}
示例#2
0
int main (void)
{
  MpImage image(size,size);		     // allocate size x size raster image

  MpImage backimg;			                 // read background image
  if (back_image) {
    if ( ! backimg.ReadAnyFile(back_image) )
      Matpack.Error("Can't read \"%s\"",back_image);
  }

  // read potential matrix
  ifstream pot_stream("pot");
  if ( ! pot_stream) Matpack.Error("Can't open pot data file \"%s\"","pot");
  pot_stream >> pot;
  pot_stream.close();

  for (int i = 0; i <= 175; i += 5) {  			   // loop through frames

    fprintf(stdout,"\rframe %d...",i); fflush(stdout);         // what's going on

    // read complex wave function
    char file_name[200], pipe_name[200], output_name[200];
    sprintf(file_name,"psi%d.gz",i);		           // generate input data file name
    sprintf(pipe_name,"gunzip -c %s > psi.dat",file_name); // decompress data file 
    sprintf(output_name,"psi%03d.jpg",i);                  // generate output file name

    system(pipe_name);
    ifstream data_stream("psi.dat");
    if ( ! data_stream) Matpack.Error("Can't open data file psi.dat");
    data_stream >> psi;
    data_stream.close();
    unlink("psi.dat");

    // consistency checks
    if ( pot.Rlo() != psi.Rlo() || pot.Rhi() != psi.Rhi() || 
	 pot.Clo() != psi.Clo() || pot.Chi() != psi.Chi() )
      Matpack.Error("non-conformant index range of potential and wave function");

    Scene scene;				   // define scene for 3d drawing

    // create surface
    double u0 = psi.Clo(), u1 = psi.Chi(), 
           v0 = psi.Rlo(), v1 = psi.Rhi();
    int    nu = psi.Chi()-psi.Clo(), nv = psi.Rhi()-psi.Rlo(),  
           su = 0, sv = 0,  periodic = 0;
    ParametricSurface(scene, height_fcn, u0,u1,nu,su, v0,v1,nv,sv, 
		      periodic, Identity, color_fcn);

    scene.BoxRatios(1,z_aspect,1);               // scale scene to box with x:y:z

    float dist = 1.6;			                    // distance parameter
    scene.Look(Vector3D( 1.1*dist, 1.5*dist, 1.4*dist), // camera position vector
	       Vector3D(-1.1*dist,-1.65*dist,-1.4*dist), // look direction vector
	       FieldOfView(45), 		 // field of view angle in degree
	       0);		             // "twist your head" angle in degree

    scene.SetGlobalShading(Facet::Gouraud);   
                                       // shading (None, Flat, Gouraud, Phong...)
    scene.SetHiddenSurface(preview ? Scene::DepthSort : Scene::TopoSort);

    // edgeline drawing option (None,...)
    scene.SetGlobalEdgeLines(show_grid ? Facet::Individual : None);

    // Setting per-vertex coloring is the best choice to get smoothly changing
    // colors on the surface. This requires Gouraud or Phong shading to be
    // switched on. If you use per-facet coloring then the facet edges are still
    // slightly visible ("Scene::PerFacet")
    scene.SetColoring(Scene::PerVertex);

    // Define ambient light, RGB color, and specular light and exponent
    // If per-vertex coloring or per-facet coloring is set, then only the ambient
    // light factor and the specular light factor and exponent are in effect, and
    // the diffuse color is ignored (the vertex or facet color is used instead)
    Material material(0.6, ColorF(1.,0.8,0.), 0.3,1.8); 
    scene.SetFacetMaterial(material);		    // set all facets to material

    scene.Open(image);			        // direct drawing to raster image
    if (back_image)
      image.InsertTiled(backimg);
    else
      scene.SetBackground(back_color); 	        // draw background with RGB color
    scene.SetColor(edge_color);		           // define color for edge lines
    scene.Show();			  		    // render the surface
    scene.Close();				       // call always after close

    image.WriteJpegFile(output_name,jpeg_quality,jpeg_smooth);// write JPEG image

    // write GIF image, if you prefer that
    //image.WriteGifFile(output_name);     // write image as GIF

  }

  cout << "\nfinished" << endl;
}