Example #1
0
int main(int argc, char *argv[]) {
  double xSemiaxis(2. * cm);
  double ySemiAxis(2. * cm);
  double zHeight(2. * cm);
  std::string name("fred1");

  //
  // 1. Box:
  //
  std::cout << "\n\nBox tests\n" << std::endl;
  doBox(name, xSemiaxis, ySemiAxis, zHeight);
  std::cout << std::endl;

  //
  // 2. Cylindrical Section or Tube:
  //
  std::cout << "\n\nTub tests\n" << std::endl;
  double rIn = 10. * cm;
  double rOut = 15. * cm;
  double zhalf = 20. * cm;
  double startPhi = 0. * deg;
  double deltaPhi = 90. * deg;
  doTubs(name, rIn, rOut, zhalf, startPhi, deltaPhi);
  std::cout << std::endl;

  //
  // 3. Cone or Conical section:
  //
  std::cout << "\n\nCons tests\n" << std::endl;
  double rIn2 = 20. * cm;
  double rOut2 = 25. * cm;
  doCons(name, rIn, rOut, rIn2, rOut2, zhalf, startPhi, deltaPhi);
  std::cout << std::endl;

  //
  // 5. Trapezoid:
  //
  std::cout << "\n\nTrapezoid tests\n" << std::endl;
  double dx1 = 10. * cm;
  double dx2 = 30. * cm;
  double dy1 = 15. * cm;
  double dy2 = 30. * cm;
  double dz = 60. * cm;
  doTrd(name, dx1, dx2, dy1, dy2, dz);
  std::cout << std::endl;

  //
  // 6. Generic Trapezoid:
  //
  std::cout << "\n\nGeneric Trapezoid tests\n" << std::endl;
  double pTheta = 0. * deg;
  double pPhi = 0. * deg;
  double pDy1 = 30. * cm;
  double pDx1 = 30. * cm;
  double pDx2 = 30. * cm;
  double pAlp1 = 0. * deg;
  double pDy2 = 15. * cm;
  double pDx3 = 10. * cm;
  double pDx4 = 10. * cm;
  double pAlp2 = 0. * deg;
  doTrap(name, dz, pTheta, pPhi, pDy1, pDx1, pDx2, pAlp1, pDy2, pDx3, pDx4, pAlp2);
  std::cout << std::endl;

  //
  // 7. Sphere or Spherical Shell Section:
  //
  std::cout << "\n\nSphere tests\n" << std::endl;
  std::cout << "This next should be the same as a 2cm ball: " << std::endl;
  doSphere("fred1", 0.0 * cm, 2.0 * cm, 0. * deg, 360. * deg, 0., 180. * deg);
  std::cout << "Manual computation gives: " << 4. / 3. * Geom::pi() * 2.0 * cm * 2.0 * cm * 2.0 * cm / cm3 << std::endl;
  std::cout << "If you mess up phi and theta you get: " << std::endl;
  doSphere("fred1", 0.0 * cm, 2.0 * cm, 0. * deg, 180. * deg, 0., 360. * deg);
  std::cout << "\n1 cm thick shell: " << std::endl;
  doSphere("fred1", 2.0 * cm, 3.0 * cm, 0. * deg, 360. * deg, 0., 180. * deg);
  std::cout << "Manual computation gives: "
            << 4. / 3. * Geom::pi() * 3.0 * cm * 3.0 * cm * 3.0 * cm / cm3 -
                   4. / 3. * Geom::pi() * 2.0 * cm * 2.0 * cm * 2.0 * cm / cm3
            << std::endl;
  std::cout << "\nHALF of the above 1 cm thick shell: " << std::endl;
  doSphere("fred1", 2.0 * cm, 3.0 * cm, 0. * deg, 180. * deg, 0., 180. * deg);
  std::cout << "Manual computation gives: "
            << (4. / 3. * Geom::pi() * 3.0 * cm * 3.0 * cm * 3.0 * cm / cm3 -
                4. / 3. * Geom::pi() * 2.0 * cm * 2.0 * cm * 2.0 * cm / cm3) /
                   2.
            << std::endl;
  std::cout << "\n30 degree span in theta; full phi \"top\" hemisphere" << std::endl;
  doSphere("fred1", 2.0 * cm, 3.0 * cm, 0. * deg, 360. * deg, 10. * deg, 30. * deg);
  std::cout << "\n30 degree span in theta; full phi \"bottom\" hemisphere; "
               "mirror of above, so should be same."
            << std::endl;
  doSphere("fred1", 2.0 * cm, 3.0 * cm, 0. * deg, 360. * deg, 140. * deg, 30. * deg);
  std::cout << "\n30 degree span in theta; full phi around equator (should be "
               "bigger than above)"
            << std::endl;
  doSphere("fred1", 2.0 * cm, 3.0 * cm, 0. * deg, 360. * deg, 75. * deg, 30. * deg);

  //
  // 9. Torus:
  //
  std::cout << "\n\nTorus tests\n" << std::endl;
  double radius = 200. * cm;
  doTorus(name, rIn, rOut, radius, startPhi, deltaPhi);
  std::cout << std::endl;

  //
  // 10. Polycons:
  //
  std::cout << "\n\nPolycons tests\n" << std::endl;
  double phiStart = 45. * deg;
  double phiTotal = 325. * deg;
  double inner[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
  std::vector<double> rInner(inner, inner + sizeof(inner) / sizeof(double));
  double outer[] = {0, 10, 10, 5, 5, 10, 10, 2, 2};
  std::vector<double> rOuter(outer, outer + sizeof(outer) / sizeof(double));
  double pl[] = {5, 7, 9, 11, 25, 27, 29, 31, 35};
  std::vector<double> z(pl, pl + sizeof(pl) / sizeof(double));
  doPolycone1(name, phiStart, phiTotal, z, rInner, rOuter);
  std::cout << std::endl;

  doPolycone2(name, phiStart, phiTotal, z, rOuter);
  std::cout << std::endl;

  //
  // 11. Polyhedra (PGON):
  //
  std::cout << "\n\nPolyhedra tests\n" << std::endl;
  int sides = 3;
  doPolyhedra1(name, sides, phiStart, phiTotal, z, rInner, rOuter);
  std::cout << std::endl;

  doPolyhedra2(name, sides, phiStart, phiTotal, z, rOuter);
  std::cout << std::endl;

  //
  // 12. Tube with an elliptical cross section:
  //

  std::cout << "\n\nElliptical Tube tests\n" << std::endl;
  doEllipticalTube(name, xSemiaxis, ySemiAxis, zHeight);
  std::cout << std::endl;
  ySemiAxis = 3. * cm;
  doEllipticalTube(name, xSemiaxis, ySemiAxis, zHeight);
  std::cout << std::endl;
  xSemiaxis = 3. * cm;
  ySemiAxis = 2. * cm;
  zHeight = 10. * cm;
  doEllipticalTube(name, xSemiaxis, ySemiAxis, zHeight);
  std::cout << std::endl;
  xSemiaxis = 300. * cm;
  ySemiAxis = 400. * cm;
  zHeight = 3000. * cm;
  doEllipticalTube(name, xSemiaxis, ySemiAxis, zHeight);

  //
  // 14. Cone with Elliptical Cross Section:
  //

  //
  // 15. Paraboloid, a solid with parabolic profile:
  //

  //
  // 16. Tube with Hyperbolic Profile:
  //

  //
  // 17. Tetrahedra:
  //

  //
  // 18. Extruded Polygon:
  //

  //
  // 19. Box Twisted:
  //

  //
  // 20. Trapezoid Twisted along One Axis:
  //

  //
  // 21. Twisted Trapezoid with x and y dimensions varying along z:
  //

  //
  // 22. Generic trapezoid with optionally collapsing vertices:
  //

  //
  // 23. Tube Section Twisted along Its Axis:
  //

  //
  // 24. Cylindrical Cut Section or Cut Tube:
  //
  std::cout << "\n\nCutTub tests\n" << std::endl;
  std::array<double, 3> lowNorm = {{0, -0.7, -0.71}};
  std::array<double, 3> highNorm = {{0.7, 0, 0.71}};

  doCutTubs(name, rIn, rOut, zhalf, startPhi, deltaPhi, lowNorm, highNorm);
  std::cout << std::endl;

  //
  // 25. Extruded Polygon:
  //
  // The extrusion of an arbitrary polygon (extruded solid)
  // with fixed outline in the defined Z sections can be defined as follows
  // (in a general way, or as special construct with two Z sections):
  //
  //    G4ExtrudedSolid(const G4String& pName,
  //                    std::vector<G4TwoVector> polygon,
  //                    std::vector<ZSection> zsections)
  //
  std::cout << "\n\nExtruded Polygon tests\n" << std::endl;
  std::vector<double> x = {-300, -300, 300, 300, 150, 150, -150, -150};
  std::vector<double> y = {-300, 300, 300, -300, -300, 150, 150, -300};
  std::vector<double> epz = {-600, -150, 100, 600};
  std::vector<double> zx = {0, 0, 0, 0};
  std::vector<double> zy = {300, -300, 0, 300};
  std::vector<double> zscale = {8, 10, 6, 12};

  doExtrudedPgon(name, x, y, epz, zx, zy, zscale);
  std::cout << std::endl;

  return EXIT_SUCCESS;
}
bool SceneLoader::buildScene(string filename)
{
    buildEndlineTable(filename);

    ifstream file(filename.c_str());
    string line;
    int lastPos = 0;
    while (findOpenParen(file))
    {
        cout << "found open paren" << endl;
        file.tellg();
        if (readCommand(file, line)) {
            if (line == "Include")
            {
                string instName;
                if (doInclude(file, instName))
                {
                    cout << "included " << instName << endl;
                }
                else
                {
                    cout << "mangled include at ";
                    curPos(cout, file.tellg());
                    cout << endl;
                }
            }
            else if (line == "Sphere")
            {
                string gname;
                if (doSphere(file, gname))
                {
                    cout << "read sphere " << gname << endl;
                }
                else
                {
                    *err << "mangled sphere command at ";
                    errLine(file.tellg());
                }
            }
            else if (line == "Material")
            {
                string gname;
                if (doMaterial(file, gname))
                {
                    cout << "read material " << gname << endl;
                }
                else
                {
                    *err << "mangled material command at ";
                    errLine(file.tellg());
                }
            }
            else if (line == "Light")
            {
                string gname;
                if (doLight(file, gname))
                {
                    cout << "read light " << gname << endl;
                }
                else
                {
                    *err << "mangled light command at ";
                    errLine(file.tellg());
                }
            }
            else if (line == "Camera")
            {
                string gname;
                if (doCamera(file, gname))
                {
                    cout << "read camera " << gname << endl;
                }
                else
                {
                    *err << "mangled camera command at ";
                    errLine(file.tellg());
                }
            }
            else if (line == "I")
            {
                *err << "Error: Instance commands must belong to a group, but I found in global scope at ";
                errLine(file.tellg());
                /*string iname; // code to handle I at global scope (doesn't make much sense now that instance names skip the names table)
                if (doI(file, iname))
                {
                    cout << "got an instance named " << iname << endl;
                }*/
            }
            else if (line == "G")
            {
                string iname;
                if (doG(file, iname))
                {
                    cout << "got a group named " << iname << endl;
                }
            }
            else if (line == "Render")
            {
                string iname;
                if (doRender(file, iname))
                {
                    cout << "did render " << iname << endl;
                }
            }
            else
            {
                *err << "command not recognized: " << line << endl;
            }
            findCloseParen(file);
        } else {

        }

        lastPos = file.tellg();
    }

    return true;
}
Example #3
0
static void vrml_ellipse(GVJ_t * job, pointf * A, int filled)
{
    FILE *out = job->output_file;
    obj_state_t *obj = job->obj;
    node_t *n;
    edge_t *e;
    double z = obj->z;
    double rx, ry;
    int dx, dy;
    pointf npf, nqf;
    point np;
    int pen;
    gdImagePtr brush = NULL;

    rx = A[1].x - A[0].x;
    ry = A[1].y - A[0].y;

    switch (obj->type) {
    case ROOTGRAPH_OBJTYPE:
    case CLUSTER_OBJTYPE:
	break;
    case NODE_OBJTYPE:
	n = obj->u.n;
	if (shapeOf(n) == SH_POINT) {
	    doSphere (job, n, A[0], z, rx, ry);
	    return;
	}
	pen = set_penstyle(job, im, brush);

	npf = vrml_node_point(job, n, A[0]);
	nqf = vrml_node_point(job, n, A[1]);

	dx = ROUND(2 * (nqf.x - npf.x));
	dy = ROUND(2 * (nqf.y - npf.y));

	PF2P(npf, np);

	if (filled)
	    gdImageFilledEllipse(im, np.x, np.y, dx, dy, color_index(im, obj->fillcolor));
	gdImageArc(im, np.x, np.y, dx, dy, 0, 360, pen);

	if (brush)
	    gdImageDestroy(brush);

	fprintf(out, "Transform {\n");
	fprintf(out, "  translation %.3f %.3f %.3f\n", A[0].x, A[0].y, z);
	fprintf(out, "  scale %.3f %.3f 1\n", rx, ry);
	fprintf(out, "  children [\n");
	fprintf(out, "    Transform {\n");
	fprintf(out, "      rotation 1 0 0   1.57\n");
	fprintf(out, "      children [\n");
	fprintf(out, "        Shape {\n");
	fprintf(out, "          geometry Cylinder { side FALSE }\n");
	fprintf(out, "          appearance Appearance {\n");
	fprintf(out, "            material Material {\n");
	fprintf(out, "              ambientIntensity 0.33\n");
	fprintf(out, "              diffuseColor 1 1 1\n");
	fprintf(out, "            }\n");
	fprintf(out, "            texture ImageTexture { url \"node%d.png\" }\n", n->id);
	fprintf(out, "          }\n");
	fprintf(out, "        }\n");
	fprintf(out, "      ]\n");
	fprintf(out, "    }\n");
	fprintf(out, "  ]\n");
	fprintf(out, "}\n");
	break;
    case EDGE_OBJTYPE:
	e = obj->u.e;
	/* this is gruesome, but how else can we get z coord */
	if (DIST2(A[0], ND_coord_i(e->tail)) < DIST2(A[0], ND_coord_i(e->head)))
	    z = obj->tail_z;
	else
	    z = obj->head_z;

	fprintf(out, "Transform {\n");
	fprintf(out, "  translation %.3f %.3f %.3f\n", A[0].x, A[0].y, z);
	fprintf(out, "  children [\n");
	fprintf(out, "    Shape {\n");
	fprintf(out, "      geometry Sphere {radius %.3f }\n", (double) rx);
	fprintf(out, "      appearance USE E%d\n", e->id);
	fprintf(out, "    }\n");
	fprintf(out, "  ]\n");
	fprintf(out, "}\n");
    }
}
Example #4
0
int
main( int argc, char *argv[] )
{
  double xSemiaxis(2.*cm);
  double ySemiAxis(2.*cm);
  double zHeight(2.*cm);
  std::string name("fred1");

//
// 1. Box:
//
  std::cout << "\n\nBox tests\n" << std::endl;
  doBox( name, xSemiaxis, ySemiAxis, zHeight );
  std::cout << std::endl;
  
//
// 2. Cylindrical Section or Tube:
//
  std::cout << "\n\nTub tests\n" << std::endl;
  double rIn = 10.*cm;
  double rOut = 15.*cm;
  double zhalf = 20.*cm;
  double startPhi = 0.*deg;
  double deltaPhi = 90.*deg;
  doTubs( name, rIn, rOut, zhalf, startPhi, deltaPhi );
  std::cout << std::endl;

//
// 3. Cone or Conical section:
//
  std::cout << "\n\nCons tests\n" << std::endl;
  double rIn2 = 20.*cm;
  double rOut2 = 25.*cm;
  doCons( name, rIn, rOut, rIn2, rOut2, zhalf, startPhi, deltaPhi );
  std::cout << std::endl;

//
// 4. Parallelepiped:
//
  std::cout << "\n\nParallelepiped tests\n" << std::endl;
  std::cout << "This next should be the same as a xhalf=5cm, yhalf=6cm, zhalf=7cm, alpha=15deg, theta=30deg, phi=45deg" << std::endl;
  doPara("fred1", 5.*cm, 6.*cm, 7.*cm, 15*deg, 30*deg, 45*deg);

//
// 5. Trapezoid:
//
  std::cout << "\n\nTrapezoid tests\n" << std::endl;
  double dx1 = 10.*cm;
  double dx2 = 30.*cm;
  double dy1 = 15.*cm;
  double dy2 = 30.*cm;
  double dz = 60.*cm;
  doTrd( name, dx1, dx2, dy1, dy2, dz );
  std::cout << std::endl;

//
// 6. Generic Trapezoid:
//
  std::cout << "\n\nGeneric Trapezoid tests\n" << std::endl;
  double pTheta = 0.*deg;
  double pPhi = 0.*deg;
  double pDy1 = 30.*cm;
  double pDx1 = 30.*cm;
  double pDx2 = 30.*cm;
  double pAlp1 = 0.*deg;
  double pDy2 = 15.*cm;
  double pDx3 = 10.*cm;
  double pDx4 = 10.*cm;
  double pAlp2 = 0.*deg;
  doTrap( name, dz, pTheta, pPhi, pDy1, pDx1, pDx2, pAlp1, pDy2, pDx3, pDx4, pAlp2 );
  std::cout << std::endl;

//
// 7. Sphere or Spherical Shell Section:
//
  std::cout << "\n\nSphere tests\n" << std::endl;
  std::cout << "This next should be the same as a 2cm ball: " << std::endl;
  doSphere("fred1", 0.0*cm, 2.0*cm, 0.*deg, 360.*deg, 0., 180.*deg);
  std::cout << "Manual computation gives: " 
	    << 4./3. * Geom::pi() * 2.0*cm * 2.0*cm *2.0*cm / cm3
	    <<std::endl;
  std::cout << "If you mess up phi and theta you get: " << std::endl;
  doSphere("fred1", 0.0*cm, 2.0*cm, 0.*deg, 180.*deg, 0., 360.*deg);
  std::cout << "\n1 cm thick shell: " << std::endl;
  doSphere("fred1", 2.0*cm, 3.0*cm, 0.*deg, 360.*deg, 0., 180.*deg);
  std::cout << "Manual computation gives: "
	    << 4./3. * Geom::pi() * 3.0*cm * 3.0*cm *3.0*cm / cm3 - 4./3. * Geom::pi() * 2.0*cm * 2.0*cm *2.0*cm / cm3
	    <<std::endl;
  std::cout << "\nHALF of the above 1 cm thick shell: " << std::endl;
  doSphere("fred1", 2.0*cm, 3.0*cm, 0.*deg, 180.*deg, 0., 180.*deg);
  std::cout << "Manual computation gives: "
	    << (4./3. * Geom::pi() * 3.0*cm * 3.0*cm *3.0*cm / cm3 - 4./3. * Geom::pi() * 2.0*cm * 2.0*cm *2.0*cm / cm3) / 2.
	    <<std::endl;
  std::cout << "\n30 degree span in theta; full phi \"top\" hemisphere" << std::endl;
  doSphere("fred1", 2.0*cm, 3.0*cm, 0.*deg, 360.*deg, 10.*deg, 30.*deg);
  std::cout << "\n30 degree span in theta; full phi \"bottom\" hemisphere; mirror of above, so should be same." << std::endl;
  doSphere("fred1", 2.0*cm, 3.0*cm, 0.*deg, 360.*deg, 140.*deg, 30.*deg);
  std::cout << "\n30 degree span in theta; full phi around equator (should be bigger than above)" << std::endl;
  doSphere("fred1", 2.0*cm, 3.0*cm, 0.*deg, 360.*deg, 75.*deg, 30.*deg);

//
// 8. Full Solid Sphere:
//
  std::cout << "\n\nOrb\n" << std::endl;
  std::cout << "This next should be the same as a 2cm ball (also the sphere above): " << std::endl;
  doOrb("fred1", 2.0*cm);
  
//
// 9. Torus:
//
  std::cout << "\n\nTorus tests\n" << std::endl;
  double radius = 200.*cm;
  doTorus( name, rIn, rOut, radius, startPhi, deltaPhi );
  std::cout << std::endl;

// 
// 10. Polycons:
//
  std::cout << "\n\nPolycons tests\n" << std::endl;
  double phiStart = 45.*deg;
  double phiTotal = 325.*deg;
  double inner[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  std::vector<double> rInner( inner, inner + sizeof( inner ) / sizeof( double ));
  double outer[] = { 0, 10, 10, 5, 5, 10, 10, 2, 2 };
  std::vector<double> rOuter( outer, outer + sizeof( outer ) / sizeof( double ));
  double pl[] = { 5, 7, 9, 11, 25, 27, 29, 31, 35 };
  std::vector<double> z( pl, pl + sizeof( pl ) / sizeof( double ));
  doPolycone1( name, phiStart, phiTotal, z, rInner, rOuter );
  std::cout << std::endl;

  doPolycone2( name, phiStart, phiTotal, z, rOuter);
  std::cout << std::endl;

//
// 11. Polyhedra (PGON):
//
  std::cout << "\n\nPolyhedra tests\n" << std::endl;
  int sides = 3;
  doPolyhedra1( name, sides, phiStart, phiTotal, z, rInner, rOuter );
  std::cout << std::endl;

  doPolyhedra2( name, sides, phiStart, phiTotal, z, rOuter );
  std::cout << std::endl;

//
// 12. Tube with an elliptical cross section:
//  
  
  std::cout << "\n\nElliptical Tube tests\n" << std::endl;
  doEllipticalTube(name, xSemiaxis, ySemiAxis, zHeight);
  std::cout << std::endl;
  ySemiAxis = 3.*cm;
  doEllipticalTube(name, xSemiaxis, ySemiAxis, zHeight);
  std::cout << std::endl;
  xSemiaxis = 3.* cm;
  ySemiAxis = 2.* cm;
  zHeight = 10.* cm;
  doEllipticalTube(name, xSemiaxis, ySemiAxis, zHeight);
  std::cout << std::endl;
  xSemiaxis = 300.* cm;
  ySemiAxis = 400.* cm;
  zHeight = 3000. * cm;
  doEllipticalTube(name, xSemiaxis, ySemiAxis, zHeight);

//
// 13. General Ellipsoid:
//
  std::cout << "\n\nEllipsoid tests\n" << std::endl;
  std::cout << "This next should be the same as a x = 3cm; y = 2cm; and z = 5cm " << std::endl;
  doEllipsoid("fred1", 3.0*cm, 2.0*cm, 5.*cm, 0.*cm, 0.*cm);
  std::cout << "\nThis one has a top cut off at z=1cm  and should be half of the above + some bit." << std::endl;
  doEllipsoid("fred1", 3.0*cm, 2.0*cm, 5.*cm, 0.*cm, 1.*cm);
  std::cout << "\nThis has a bottom cut off at z= -1cm  and should be the same as the above (symmetric)" << std::endl;
  doEllipsoid("fred1", 3.0*cm, 2.0*cm, 5.*cm, -1.*cm, 0.*cm);
  std::cout << "\nThis has a bottom cut off at z= -1cm  and top cut at z=1cm and should be smaller (just the fat bit around the middle)." << std::endl;
  doEllipsoid("fred1", 3.0*cm, 2.0*cm, 5.*cm, -1.*cm, 1.*cm);

//
// 14. Cone with Elliptical Cross Section:
//

//
// 15. Paraboloid, a solid with parabolic profile:
//

//
// 16. Tube with Hyperbolic Profile:
//
  
//
// 17. Tetrahedra:
//

//
// 18. Extruded Polygon:
//

//
// 19. Box Twisted:
//

//
// 20. Trapezoid Twisted along One Axis:
//

//
// 21. Twisted Trapezoid with x and y dimensions varying along z:
//

//
// 22. Generic trapezoid with optionally collapsing vertices:
//

//
// 23. Tube Section Twisted along Its Axis: 
//   
  
  return EXIT_SUCCESS;
}