cgma
GfxPreview.cpp
Go to the documentation of this file.
00001 
00002 
00003 #include "GfxPreview.hpp"
00004 #include "GMem.hpp"
00005 #include "CubitVector.hpp"
00006 #include "Curve.hpp"
00007 #include "Surface.hpp"
00008 #include "GeometryQueryEngine.hpp"
00009 #include "Point.hpp"
00010 #include <assert.h>
00011 #include "DrawingToolDefines.h"
00012 
00013 GfxPreview* GfxPreview::mInstance = 0;
00014 
00015 GfxPreview::GfxPreview()
00016 {
00017   if(mInstance)
00018   {
00019     assert(0);
00020     // if you want a new instance in place of a previous one,
00021     // delete the previous one first
00022   }
00023   mInstance = this;
00024 }
00025 
00026 GfxPreview::~GfxPreview()
00027 {
00028   mInstance = 0;
00029 }
00030 
00031 
00032 // This clears preview data ONLY
00033 void GfxPreview::clear()
00034 {
00035   if(!mInstance) return;
00036   mInstance->p_clear();
00037 }
00038 
00039 // causes the current window to be redrawn
00040 void GfxPreview::flush()
00041 {
00042   if(!mInstance) return;
00043   mInstance->p_flush();
00044 }
00045 
00046 // Geometry Drawing Functions
00047     
00048 void GfxPreview::draw_ref_entity(RefEntity* entity, int color, CubitTransformMatrix* mat)
00049 {
00050   if(!mInstance) return;
00051   mInstance->p_draw_ref_entity(entity, color, mat);
00052 }
00053 
00054 void GfxPreview::draw_ref_vertex(RefVertex* entity, int color)
00055 {
00056   if(!mInstance) return;
00057   mInstance->p_draw_ref_vertex(entity, color);
00058 }
00059 
00060 void GfxPreview::draw_ref_edge(RefEdge* entity, int color)
00061 {
00062   if(!mInstance) return;
00063   mInstance->p_draw_ref_edge(entity, color);
00064 }
00065 
00066 void GfxPreview::draw_ref_face(RefFace* entity, int color)
00067 {
00068   if(!mInstance) return;
00069   mInstance->p_draw_ref_face(entity, color);
00070 }
00071 
00072 void GfxPreview::draw_ref_face_edges(RefFace* entity, int color)
00073 {
00074   if(!mInstance) return;
00075   mInstance->p_draw_ref_face_edges(entity, color);
00076 }
00077 
00078 void GfxPreview::draw_ref_volume(RefVolume* entity, int color, int mode)
00079 {
00080   if(!mInstance) return;
00081   mInstance->p_draw_ref_volume(entity, color, mode);
00082 }
00083 
00084 void GfxPreview::draw_ref_volume_edges(RefVolume* entity, int color)
00085 {
00086   if(!mInstance) return;
00087   mInstance->p_draw_ref_volume_edges(entity, color);
00088 }
00089 
00090 void GfxPreview::draw_ref_body(Body* entity, int color, int mode)
00091 {
00092   if(!mInstance) return;
00093   mInstance->p_draw_ref_body(entity, color, mode);
00094 }
00095 
00096 // Generic Primitive Drawing Functions
00097 
00098 void GfxPreview::draw_box(CubitBox& box, int color)
00099 {
00100   if(!mInstance) return;
00101   mInstance->p_draw_box(box, color);
00102 }
00103 
00104 // draw point x,y,z of color
00105 void GfxPreview::draw_point(float x, float y, float z, int color)
00106 {
00107   if(!mInstance) return;
00108   mInstance->p_draw_point(x, y, z, color);
00109 }
00110 
00111 void GfxPreview::draw_point(const CubitVector& vector, int color)
00112 {
00113   if(!mInstance) return;
00114   mInstance->p_draw_point(vector, color);
00115 }
00116 
00117 void GfxPreview::draw_point(CubitVector* vector, int color)
00118 {
00119   if(!mInstance) return;
00120   mInstance->p_draw_point(*vector, color);
00121 }
00122 
00123 // draw line of points {x,y,z}, {x,y,z} of color
00124 void GfxPreview::draw_line(float x1, float y1, float z1, float x2, float y2, float z2, int color)
00125 {
00126   if(!mInstance) return;
00127   mInstance->p_draw_line(x1, y1, z1, x2, y2, z2, color);
00128 }
00129 
00130 void GfxPreview::draw_line(const CubitVector& x, const CubitVector& y, int color)
00131 {
00132   if(!mInstance) return;
00133   mInstance->p_draw_line(x, y, color);
00134 }
00135 
00136 // draw a polyline with a number of points of a color
00137 void GfxPreview::draw_polyline(const GPoint* points, int num_points, int color)
00138 {
00139   if(!mInstance) return;
00140   mInstance->p_draw_polyline(points, num_points, color);
00141 }
00142 
00143 // draw polygons given the coordinates and the connectivity.  Note that the
00144 // connectivity (face_list) is given as the number of points in the polygon 
00145 // followed by the point ids for that polygon.  So, the num_face_points is
00146 // the total number of data points in the face_list such that
00147 // num_face_points = number of points + number of polygons
00148 void GfxPreview::draw_polygons(int num_points, const double* xyzs, int num_face_points,
00149                                const int* face_list, int color, int mode )
00150 {
00151   if (!mInstance) 
00152     return;
00153   mInstance->p_draw_polygons( num_points, xyzs, num_face_points, face_list, color, mode);
00154 }
00155 
00156 // draw a polyline with a number of points of a color
00157 void GfxPreview::draw_polygon(const GPoint* points, int num_points, int color, int border_color, bool filled)
00158 {
00159   if(!mInstance) return;
00160   mInstance->p_draw_polygon(points, num_points, color, border_color, filled);
00161 }
00162 
00163 // draw a quad of a color
00164 void GfxPreview::draw_quad(const GPoint* points, int color)
00165 {
00166   if(!mInstance) return;
00167   mInstance->p_draw_quad(points, color);
00168 }
00169 
00170 // draw a tri of a color
00171 void GfxPreview::draw_tri(const GPoint* points, int color)
00172 {
00173   if(!mInstance) return;
00174   mInstance->p_draw_tri(points, color);
00175 }
00176 
00177 void GfxPreview::draw_vector(const CubitVector& tail, const CubitVector& head, int color)
00178 {
00179   if(!mInstance) return;
00180   mInstance->p_draw_vector(tail, head, color);
00181 }
00182 
00183 void GfxPreview::draw_vector(const GPoint* tail, const GPoint* head, int color)
00184 {
00185   if(!mInstance) return;
00186   mInstance->p_draw_vector(CubitVector(tail->x, tail->y, tail->z), CubitVector(head->x, head->y, head->z), color);
00187 }
00188 
00189 // draw a label at position x,y,z of color
00190 void GfxPreview::draw_label(const char* label, float x, float y, float z, int color)
00191 {
00192   if(!mInstance) return;
00193   mInstance->p_draw_label(label, x, y, z, color);
00194 }
00195 void GfxPreview::draw_label(int label, float x, float y, float z, int color)
00196 {
00197   if(!mInstance) return;
00198   mInstance->p_draw_label(label, x, y, z, color);
00199 }
00200 
00201 void GfxPreview:: draw_cylinder(const CubitVector& axis, const CubitVector& origin, 
00202                                  CubitBox& bounding_box, float radius, int color)
00203 {
00204   if(!mInstance) return;
00205   mInstance->p_draw_cylinder(axis, origin, bounding_box, radius, color);
00206 }
00207 
00208 void GfxPreview:: draw_frustum( const CubitVector axis , const CubitVector origin1, const CubitVector origin2,double dRad1 , double dRad2,
00209                                CubitBox& bounding_box ,int color)
00210 {
00211   if(!mInstance) return;
00212   mInstance->p_draw_frustum( axis , origin1, origin2, dRad1 , dRad2 , bounding_box, color);
00213 }
00214 
00215 void GfxPreview::draw_point(TBPoint *pt, int color)
00216 {
00217   CubitVector v = pt->coordinates();
00218   draw_point(v, color);
00219   flush();
00220 }
00221 
00222 void GfxPreview::draw_curve(Curve *curve, int color)
00223 {
00224   int num_divs = 20;
00225   double lo, hi;
00226   curve->get_param_range(lo, hi);
00227   double dv = (hi-lo)/(double)num_divs;
00228   int i;
00229   double param = lo;
00230   for(i=0; i<num_divs; i++)
00231   {
00232     CubitVector p1, p2;
00233     curve->position_from_u(param, p1);
00234     param += dv;
00235     curve->position_from_u(param, p2);
00236     draw_line(p1.x(), p1.y(), p1.z(), p2.x(), p2.y(), p2.z(), color);
00237   }
00238   flush();
00239   DLIList<TBPoint*> pts;
00240   curve->points(pts);
00241   for(i=pts.size(); i>0; i--)
00242   {
00243     TBPoint *cur_pt = pts.get_and_step();
00244     draw_point(cur_pt, color);
00245   }
00246 }
00247 
00248 void GfxPreview::draw_surface(Surface *surf, int color)
00249 {
00250   int num_divs = 20;
00251   double ulo, uhi, vlo, vhi;
00252   surf->get_param_range_U(ulo, uhi);
00253   surf->get_param_range_V(vlo, vhi);
00254   double du = (uhi-ulo)/(double)num_divs;
00255   double dv = (vhi-vlo)/(double)num_divs;
00256   int i, j;
00257   double uparam, vparam;
00258   uparam = ulo;
00259   for(i=0; i<num_divs; i++)
00260   {
00261     vparam = vlo;
00262     for(j=0; j<num_divs; j++)
00263     {
00264       CubitVector p1, p2;
00265       p1 = surf->position_from_u_v(uparam, vparam);
00266       vparam += dv;
00267       p2 = surf->position_from_u_v(uparam, vparam);
00268       draw_line(p1.x(), p1.y(), p1.z(), p2.x(), p2.y(), p2.z(), color);
00269     }
00270     uparam += du;
00271   }
00272   vparam = vlo;
00273   for(i=0; i<num_divs; i++)
00274   {
00275     uparam = ulo;
00276     for(j=0; j<num_divs; j++)
00277     {
00278       CubitVector p1, p2;
00279       p1 = surf->position_from_u_v(uparam, vparam);
00280       uparam += du;
00281       p2 = surf->position_from_u_v(uparam, vparam);
00282       draw_line(p1.x(), p1.y(), p1.z(), p2.x(), p2.y(), p2.z(), color);
00283     }
00284     vparam += dv;
00285   }
00286   flush();
00287 }
00288 
00289 void GfxPreview::draw_surface_facets_shaded(Surface *surf, int color)
00290 {
00291   GMem g_mem;
00292 
00293   surf->get_geometry_query_engine()->get_graphics(surf, &g_mem);
00294 
00295   const float* xyzs = reinterpret_cast<const float*>(g_mem.point_list());
00296   std::vector<double> dcoords(xyzs, xyzs+g_mem.pointListCount*3);
00297   GfxPreview::draw_polygons(g_mem.pointListCount, &dcoords[0],
00298                             g_mem.fListCount, g_mem.facet_list(),
00299                             color, CUBIT_SMOOTH_SHADING);
00300   flush();
00301 }
00302 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines