Node: Getting Shapes Solids, Previous: Getting Shape Centers Solids, Up: Returning Elements and Information Solids



Getting Shapes

The functions in this section all return const pointers to Shape, or one of its derived classes. Therefore, they must be invoked in such a way, that the const qualifier is not discarded. See the description of get_reg_polygon_ptr() below, for an example.

Shape* get_shape_ptr (const unsigned short shape_type, const unsigned short s) const virtual function
Copies one of the objects belonging to the Solid, and returns a pointer to Shape that points to the copy. The object is found by dereferencing one of the pointers on one of the vectors of pointers belonging to the Solid. Currently, these vectors are circles, ellipses, paths, rectangles, and reg_polygons. The argument shape_type specifies the vector, and the argument s specifies which element of the vector should be accessed. The following public static const data members of Solid can (and probably should) be passed as the shape_type argument: CIRCLE, ELLIPSE, PATH, RECTANGLE, and REG_POLYGON.

This function was originally intended to be called within the more specialized functions in this section, namely: get_circle_ptr(), get_ellipse_ptr(), get_path_ptr(), get_rectangle_ptr, and get_reg_polygon_ptr. However, these functions no longer use get_shape_ptr(), so this function is probably no longer needed.

          Icosahedron I(origin, 3);
          I.filldraw();
          Reg_Polygon* t =
          static_cast<Reg_Polygon*>(I.get_shape_ptr(Solid::REG_POLYGON, 9));
          t->fill(gray);
          


[Figure 184. Not displayed.]

Fig. 184.

const Reg_Polygon* get_circle_ptr (const unsigned short s) const virtual functions
const Reg_Polygon* get_ellipse_ptr (const unsigned short s)
const Reg_Polygon* get_path_ptr (const unsigned short s)
const Reg_Polygon* get_rectangle_ptr (const unsigned short s)
const Reg_Polygon* get_reg_polygon_ptr (const unsigned short s)
Each of these functions returns a pointer from one of the vectors of Shape pointers belonging to the Solid. The argument s specifies which element of the appropriate vector should be returned. For example, get_reg_polygon_ptr(2) returns the Reg_Polygon* in reg_polygons[2].

Since these functions return const pointers, they must be invoked in such a way, that the const qualifier is not discarded, as noted at the beginning of this section. The following example demonstrates two ways of invoking get_reg_polygon_ptr():

          Dodecahedron d(origin, 3);
          d.draw();
          const Reg_Polygon* ptr = d.get_reg_polygon_ptr(0);
          ptr->draw(black, "evenly scaled 4", "pencircle scaled 1mm");
          Reg_Polygon A = *d.get_reg_polygon_ptr(5);
          A.fill(gray);
          


[Figure 185. Not displayed.]

Fig. 185.