int main (void) { const char *mpath = getenv("MATPACK"); if (!mpath) Matpack.Error("Environment variable MATPACK is not set to Matpack home directory"); char logopath[256]; strcpy(logopath,mpath); #if defined( WIN32 ) strcat(logopath,"\\images\\etc\\maticon.gif"); #else strcat(logopath,"/images/etc/maticon.gif"); #endif // load GIF image into RGB raster image MpImage logo; logo.ReadGifFile(logopath); if (! logo) Matpack.Error("Can't load image"); // Open to draw a Postscript plot with format 100mm x 100mm (margin 10x10) Scene scene (PostScriptPortrait, "example-3.ps", 10,10, 100,100); // Define 2D coordinate system which corresponds to a scale in millimeters scene.Scale(0,100,0,100); // Draw a 10 mm grid for (int i = 0; i <= 100; i += 10) scene.Line(i,0,i,100); for (int j = 0; j <= 100; j += 10) scene.Line(0,j,100,j); // Draw image with original scaling. As default a resolution of 150 dpi is // assumed. That means 150 pixel of the image are mapped to 1 inch. scene.MoveTo(10,90); scene.PutImage(logo); // Now define a different mapping of pixel to millimeter. The image is now // scaled to 20mm x 20mm (changing the aspect ratio). The sizes are given in // units of 1/1000 millimeter (micrometer). scene.MoveTo(30,60); logo.SetSizeMM(20000,20000); scene.PutImage(logo); // Now the aspect ratio will preserved and the width of the image // is set to 20mm. The length has to be calculated accordingly. scene.MoveTo(60,30); logo.SetSizeMM(20000, 20000*logo.GetLength()/logo.GetWidth() ); scene.PutImage(logo); // close the scene scene.Close(); cout << "The Postscript file \"example-3.ps\" has been created" << endl; }
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 }
static void hook (MpParametricSurfaceDef &def, Scene &scene, void *ptr) { // the viewing window is passed as argument ViewWindow &view = *(ViewWindow*)ptr; Material gold(0.3, ColorF(1.0,0.84,0.0), 0.5, 1.8); scene.SetFacetMaterial(gold); cout << scene.GetNumFacets() << " Facets, " // print some memory information << 0.001*scene.GetMemoryUsage() << " KByte allocated" << endl; float x0,x1,y0,y1,z0,z1; // get extent of scene in space scene.Extent(x0,x1,y0,y1,z0,z1); float dist = MpMax(x1-x0,y1-y0,z1-z0), // distance parameter ax = (x1+x0)/2, ay = (y1+y0)/2, az = (z1+z0)/2, cx = 1.4*dist+ax, cy = 1.2*dist+ay, cz = 1.0*dist+az; scene.Look(Vector3D(cx,cy,cz), // camera position vector Vector3D(-cx+ax,-cy+ay,-cz+az), // look direction vector FieldOfView(40), // field of view angle in degree 0); // "twist your head" angle in degree MpImage& image = *(view.canvas->image); // access scroll window's image scene.Open(image); // direct drawing to raster image //scene.SetViewPort(30,30,size-60,size-60); // if omitted viewport is whole image scene.SetGlobalShading(Facet::Gouraud); // surface shading (None, Flat, Gouraud, ...) scene.SetGlobalEdgeLines(Facet::Individual); // edgeline drawing option 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 view.MpScrollImageWindow::Configure(image); // update new scroll window image // to make our image visible }
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; }